blob: a6d1abac612c8a405b610b7f138cf77136547ccd [file] [log] [blame]
From 85f654326e723173bc1c8329624ecbf75a0f98be Mon Sep 17 00:00:00 2001
From: mtk27745 <rex.lu@mediatek.com>
Date: Wed, 25 Oct 2023 16:20:01 +0800
Subject: [PATCH] rdkb uc script support
---
common.uc | 22 ++++++++++++----------
hostapd.uc | 6 +++---
wdev.uc | 20 ++++++++++----------
wpa_supplicant.uc | 4 ++--
4 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/common.uc b/common.uc
index ccffe3e..2b48d3e 100644
--- a/common.uc
+++ b/common.uc
@@ -1,6 +1,6 @@
import * as nl80211 from "nl80211";
import * as rtnl from "rtnl";
-import { readfile, glob, basename, readlink } from "fs";
+import * as fs from "fs";
const iftypes = {
ap: nl80211.const.NL80211_IFTYPE_AP,
@@ -19,12 +19,14 @@ function __phy_is_fullmac(phyidx)
{
let data = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, 0, { wiphy: phyidx });
+ if (data == null)
+ return 1;
return !data.software_iftypes.ap_vlan;
}
function phy_is_fullmac(phy)
{
- let phyidx = int(trim(readfile(`/sys/class/ieee80211/${phy}/index`)));
+ let phyidx = int(trim(fs.readfile(`/sys/class/ieee80211/${phy}/index`)));
return __phy_is_fullmac(phyidx);
}
@@ -39,14 +41,14 @@ function find_reusable_wdev(phyidx)
nl80211.const.NLM_F_DUMP,
{ wiphy: phyidx });
for (let res in data)
- if (trim(readfile(`/sys/class/net/${res.ifname}/operstate`)) == "down")
+ if (trim(fs.readfile(`/sys/class/net/${res.ifname}/operstate`)) == "down")
return res.ifname;
return null;
}
function wdev_create(phy, name, data)
{
- let phyidx = int(readfile(`/sys/class/ieee80211/${phy}/index`));
+ let phyidx = int(fs.readfile(`/sys/class/ieee80211/${phy}/index`));
wdev_remove(name);
@@ -96,7 +98,7 @@ function wdev_create(phy, name, data)
function phy_sysfs_file(phy, name)
{
- return trim(readfile(`/sys/class/ieee80211/${phy}/${name}`));
+ return trim(fs.readfile(`/sys/class/ieee80211/${phy}/${name}`));
}
function macaddr_split(str)
@@ -111,7 +113,7 @@ function macaddr_join(addr)
function wdev_macaddr(wdev)
{
- return trim(readfile(`/sys/class/net/${wdev}/address`));
+ return trim(fs.readfile(`/sys/class/net/${wdev}/address`));
}
const phy_proto = {
@@ -221,10 +223,10 @@ const phy_proto = {
},
for_each_wdev: function(cb) {
- let wdevs = glob(`/sys/class/ieee80211/${this.name}/device/net/*`);
- wdevs = map(wdevs, (arg) => basename(arg));
+ let wdevs = fs.glob(`/sys/class/ieee80211/${this.name}/device/net/*`);
+ wdevs = map(wdevs, (arg) => fs.basename(arg));
for (let wdev in wdevs) {
- if (basename(readlink(`/sys/class/net/${wdev}/phy80211`)) != this.name)
+ if (fs.basename(fs.readlink(`/sys/class/net/${wdev}/phy80211`)) != this.name)
continue;
cb(wdev);
@@ -234,7 +236,7 @@ const phy_proto = {
function phy_open(phy)
{
- let phyidx = readfile(`/sys/class/ieee80211/${phy}/index`);
+ let phyidx = fs.readfile(`/sys/class/ieee80211/${phy}/index`);
if (!phyidx)
return null;
diff --git a/hostapd.uc b/hostapd.uc
index 1bce754..5f5ca35 100644
--- a/hostapd.uc
+++ b/hostapd.uc
@@ -1,5 +1,5 @@
let libubus = require("ubus");
-import { open, readfile } from "fs";
+import * as fs from "fs";
import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac, phy_open } from "common";
let ubus = libubus.connect();
@@ -562,7 +562,7 @@ function config_add_bss(config, name)
function iface_load_config(filename)
{
- let f = open(filename, "r");
+ let f = fs.open(filename, "r");
if (!f)
return null;
@@ -620,7 +620,7 @@ function iface_load_config(filename)
}
if (hostapd.data.file_fields[val[0]])
- bss.hash[val[0]] = hostapd.sha1(readfile(val[1]));
+ bss.hash[val[0]] = hostapd.sha1(fs.readfile(val[1]));
push(bss.data, line);
}
diff --git a/wdev.uc b/wdev.uc
index cf438f7..5eb5e3c 100644
--- a/wdev.uc
+++ b/wdev.uc
@@ -1,7 +1,7 @@
#!/usr/bin/env ucode
'use strict';
import { vlist_new, is_equal, wdev_create, wdev_remove, phy_open } from "/usr/share/hostap/common.uc";
-import { readfile, writefile, basename, readlink, glob } from "fs";
+import * as fs from "fs";
let libubus = require("ubus");
let keep_devices = {};
@@ -32,7 +32,7 @@ function iface_start(wdev)
{
let ifname = wdev.ifname;
- if (readfile(`/sys/class/net/${ifname}/ifindex`)) {
+ if (fs.readfile(`/sys/class/net/${ifname}/ifindex`)) {
system([ "ip", "link", "set", "dev", ifname, "down" ]);
wdev_remove(ifname);
}
@@ -89,7 +89,7 @@ function iface_cb(new_if, old_if)
function drop_inactive(config)
{
for (let key in config) {
- if (!readfile(`/sys/class/net/${key}/ifindex`))
+ if (!fs.readfile(`/sys/class/net/${key}/ifindex`))
delete config[key];
}
}
@@ -108,23 +108,23 @@ function delete_ifname(config)
function add_existing(phy, config)
{
- let wdevs = glob(`/sys/class/ieee80211/${phy}/device/net/*`);
- wdevs = map(wdevs, (arg) => basename(arg));
+ let wdevs = fs.glob(`/sys/class/ieee80211/${phy}/device/net/*`);
+ wdevs = map(wdevs, (arg) => fs.basename(arg));
for (let wdev in wdevs) {
if (config[wdev])
continue;
- if (basename(readlink(`/sys/class/net/${wdev}/phy80211`)) != phy)
+ if (fs.basename(fs.readlink(`/sys/class/net/${wdev}/phy80211`)) != phy)
continue;
- if (trim(readfile(`/sys/class/net/${wdev}/operstate`)) == "down")
+ if (trim(fs.readfile(`/sys/class/net/${wdev}/operstate`)) == "down")
config[wdev] = {};
}
}
function usage()
{
- warn(`Usage: ${basename(sourcepath())} <phy> <command> [<arguments>]
+ warn(`Usage: ${fs.basename(sourcepath())} <phy> <command> [<arguments>]
Commands:
set_config <config> [<device]...] - set phy configuration
@@ -150,7 +150,7 @@ const commands = {
exit(1);
}
- let old_config = readfile(statefile);
+ let old_config = fs.readfile(statefile);
if (old_config)
old_config = json(old_config);
@@ -175,7 +175,7 @@ const commands = {
drop_inactive(config.data);
delete_ifname(config.data);
- writefile(statefile, sprintf("%J", config.data));
+ fs.writefile(statefile, sprintf("%J", config.data));
},
get_macaddr: function(args) {
let data = {};
diff --git a/wpa_supplicant.uc b/wpa_supplicant.uc
index 2a9de67..cd149dc 100644
--- a/wpa_supplicant.uc
+++ b/wpa_supplicant.uc
@@ -1,5 +1,5 @@
let libubus = require("ubus");
-import { open, readfile } from "fs";
+import * as fs from "fs";
import { wdev_create, wdev_remove, is_equal, vlist_new, phy_open } from "common";
let ubus = libubus.connect();
@@ -62,7 +62,7 @@ function iface_cb(new_if, old_if)
function prepare_config(config)
{
- config.config_data = readfile(config.config);
+ config.config_data = fs.readfile(config.config);
return { config: config };
}
--
2.18.0