wifi-scripts: ucode: fix client mode scan list support
- fix the variable name in the configuration file - provide a default scan list in case the user did not configure it (MLO preparation) Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
009a9e0478
commit
b11a6a1c5a
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as libubus from 'ubus';
|
||||
import * as nl80211 from 'nl80211';
|
||||
import * as fs from 'fs';
|
||||
|
||||
global.ubus = libubus.connect();
|
||||
@ -8,6 +9,25 @@ global.ubus = libubus.connect();
|
||||
let config_data = '';
|
||||
let network_data = '';
|
||||
|
||||
const nl80211_bands = [ '2g', '5g', '60g', '6g' ];
|
||||
|
||||
export function wiphy_info(phy) {
|
||||
let idx = +fs.readfile(`/sys/class/ieee80211/${phy}/index`);
|
||||
|
||||
return nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, nl80211.const.NLM_F_DUMP, {
|
||||
wiphy: idx,
|
||||
split_wiphy_dump: true
|
||||
});
|
||||
};
|
||||
|
||||
export function wiphy_band(info, band) {
|
||||
let band_idx = index(nl80211_bands, band);
|
||||
if (band_idx < 0 || !info)
|
||||
return;
|
||||
|
||||
return info.wiphy_bands[band_idx];
|
||||
};
|
||||
|
||||
export function log(msg) {
|
||||
printf(`wifi-scripts: ${msg}\n`);
|
||||
};
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
import { append, append_raw, append_vars, dump_config, flush_config, set_default } from 'wifi.common';
|
||||
import {
|
||||
append, append_raw, append_vars, dump_config, flush_config, set_default,
|
||||
wiphy_info, wiphy_band
|
||||
} from 'wifi.common';
|
||||
import { validate } from 'wifi.validate';
|
||||
import * as netifd from 'wifi.netifd';
|
||||
import * as iface from 'wifi.iface';
|
||||
@ -11,7 +14,6 @@ import * as fs from 'fs';
|
||||
const NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER = 33;
|
||||
const NL80211_EXT_FEATURE_RADAR_BACKGROUND = 61;
|
||||
|
||||
const nl80211_bands = [ '2g', '5g', '60g', '6g' ];
|
||||
let phy_features = {};
|
||||
let phy_capabilities = {};
|
||||
|
||||
@ -439,18 +441,9 @@ function device_extended_features(data, flag) {
|
||||
|
||||
function device_capabilities(config) {
|
||||
let phy = config.phy;
|
||||
let idx = +fs.readfile(`/sys/class/ieee80211/${phy}/index`);
|
||||
phy = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, nl80211.const.NLM_F_DUMP, { wiphy: idx, split_wiphy_dump: true });
|
||||
if (!phy)
|
||||
return;
|
||||
|
||||
let band_idx = index(nl80211_bands, config.band);
|
||||
if (band_idx < 0)
|
||||
return;
|
||||
|
||||
let band = phy.wiphy_bands[band_idx];
|
||||
if (!band)
|
||||
return;
|
||||
phy = wiphy_info(phy);
|
||||
let band = wiphy_band(phy, config.band);
|
||||
|
||||
phy_capabilities.ht_capa = band.ht_capa ?? 0;
|
||||
phy_capabilities.vht_capa = band.vht_capa ?? 0;
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
import { append, append_raw, append_vars, network_append, network_append_raw, network_append_vars,
|
||||
network_append_string_vars, set_default, dump_network, flush_network } from 'wifi.common';
|
||||
import {
|
||||
append, append_raw, append_vars, network_append, network_append_raw, network_append_vars,
|
||||
network_append_string_vars, set_default, dump_network, flush_network,
|
||||
wiphy_info, wiphy_band
|
||||
} from 'wifi.common';
|
||||
import * as netifd from 'wifi.netifd';
|
||||
import * as iface from 'wifi.iface';
|
||||
import * as fs from 'fs';
|
||||
@ -179,6 +182,39 @@ function setup_sta(data, config) {
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
function freq_in_range(freq_ranges, freq)
|
||||
{
|
||||
if (!freq_ranges)
|
||||
return true;
|
||||
|
||||
freq *= 1000;
|
||||
for (let range in freq_ranges)
|
||||
if (freq >= range.start && freq <= range.end)
|
||||
return true;
|
||||
}
|
||||
|
||||
function wiphy_frequencies(phy, band, radio) {
|
||||
phy = wiphy_info(phy);
|
||||
band = wiphy_band(phy, band);
|
||||
if (!band)
|
||||
return;
|
||||
|
||||
let ranges;
|
||||
for (let r in phy.radios)
|
||||
if (r.index == radio)
|
||||
ranges = r.freq_ranges;
|
||||
|
||||
let freqs = [];
|
||||
for (let chan in band.freqs)
|
||||
if (!chan.disabled && freq_in_range(ranges, chan.freq))
|
||||
push(freqs, chan.freq);
|
||||
|
||||
if (length(freqs) > 0)
|
||||
return freqs;
|
||||
}
|
||||
|
||||
|
||||
export function generate(config_list, data, interface) {
|
||||
flush_network();
|
||||
|
||||
@ -191,10 +227,13 @@ export function generate(config_list, data, interface) {
|
||||
|
||||
interface.config.country = data.config.country_code;
|
||||
interface.config.beacon_int = data.config.beacon_int;
|
||||
if (data.config.scan_list)
|
||||
interface.config.scan_list = join(" ", data.config.scan_list);
|
||||
if (!data.config.scan_list)
|
||||
data.config.scan_list = wiphy_frequencies(data.phy, data.config.band, data.config.radio);
|
||||
|
||||
append_vars(interface.config, [ 'country', 'beacon_int', 'scan_list' ]);
|
||||
if (data.config.scan_list)
|
||||
interface.config.freq_list = join(" ", data.config.scan_list);
|
||||
|
||||
append_vars(interface.config, [ 'country', 'beacon_int', 'freq_list' ]);
|
||||
|
||||
setup_sta(data.config, interface.config);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user