]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
wifi-scripts: ucode: fix client mode scan list support
authorFelix Fietkau <nbd@nbd.name>
Sat, 20 Sep 2025 15:14:47 +0000 (17:14 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 24 Sep 2025 11:45:40 +0000 (13:45 +0200)
- 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>
package/network/config/wifi-scripts/files-ucode/usr/share/ucode/wifi/common.uc
package/network/config/wifi-scripts/files-ucode/usr/share/ucode/wifi/hostapd.uc
package/network/config/wifi-scripts/files-ucode/usr/share/ucode/wifi/supplicant.uc

index 0418fe8b76d6afee3920e0e67c53002e6cb3d182..de939b0c2f1385c2c7c1076f44ada6fdfbcf5b7c 100644 (file)
@@ -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`);
 };
index 216b41a6c271f37ec2387a21517bb89f26931e14..9efa0d4fc2e8afa7a896c6ffe20c59b2a61f1cbc 100644 (file)
@@ -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;
index 2739a09e4c97cfcad3e703405230c58db856144f..30e196ddce6318566907df67e6235c50415fbef4 100644 (file)
@@ -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)
+               data.config.scan_list = wiphy_frequencies(data.phy, data.config.band, data.config.radio);
+
        if (data.config.scan_list)
-               interface.config.scan_list = join(" ", data.config.scan_list);
+               interface.config.freq_list = join(" ", data.config.scan_list);
 
-       append_vars(interface.config, [ 'country', 'beacon_int', 'scan_list' ]);
+       append_vars(interface.config, [ 'country', 'beacon_int', 'freq_list' ]);
 
        setup_sta(data.config, interface.config);