hostapd: add support for querying bss config parameters via ubus

Supports reading the same parameters currently being used by iwinfo.
Preparation for replacing iwinfo with a rewrite in ucode.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau
2024-10-22 10:59:55 +02:00
parent efb8764a69
commit ed484caa03
3 changed files with 108 additions and 0 deletions

View File

@@ -30,6 +30,23 @@ hostapd.data.iface_fields = {
iapp_interface: true,
};
hostapd.data.bss_info_fields = {
// radio
hw_mode: true,
channel: true,
ieee80211ac: true,
ieee80211ax: true,
// bss
bssid: true,
ssid: true,
wpa: true,
wpa_key_mgmt: true,
wpa_pairwise: true,
auth_algs: true,
ieee80211w: true,
};
function iface_remove(cfg)
{
if (!cfg || !cfg.bss || !cfg.bss[0] || !cfg.bss[0].ifname)
@@ -752,6 +769,17 @@ function ex_wrap(func) {
};
}
function bss_config(bss_name) {
for (let phy, config in hostapd.data.config) {
if (!config)
continue;
for (let bss in config.bss)
if (bss.ifname == bss_name)
return [ config, bss ];
}
}
let main_obj = {
reload: {
args: {
@@ -896,6 +924,32 @@ let main_obj = {
return 0;
})
},
bss_info: {
args: {
iface: ""
},
call: ex_wrap(function(req) {
if (!req.args.iface)
return libubus.STATUS_INVALID_ARGUMENT;
let config = bss_config(req.args.iface);
if (!config)
return libubus.STATUS_NOT_FOUND;
let bss = config[1];
config = config[0];
let ret = {};
for (let line in [ ...config.radio.data, ...bss.data ]) {
let fields = split(line, "=", 2);
let name = fields[0];
if (hostapd.data.bss_info_fields[name])
ret[name] = fields[1];
}
return ret;
})
},
};
hostapd.data.ubus = ubus;

View File

@@ -245,6 +245,33 @@ let main_obj = {
return 0;
}
},
bss_info: {
args: {
iface: "",
},
call: function(req) {
let ifname = req.args.iface;
if (!ifname)
return libubus.STATUS_INVALID_ARGUMENT;
let iface = wpas.interfaces[ifname];
if (!iface)
return libubus.STATUS_NOT_FOUND;
let status = iface.ctrl("STATUS");
if (!status)
return libubus.STATUS_NOT_FOUND;
let ret = {};
status = split(status, "\n");
for (let line in status) {
line = split(line, "=", 2);
ret[line[0]] = line[1];
}
return ret;
}
},
};
wpas.data.ubus = ubus;