[openwrt/openwrt] wifi-scripts: fix ucode support for referencing wifi devices by phy name

LEDE Commits lede-commits at lists.infradead.org
Sun Dec 8 05:11:55 PST 2024


nbd pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/ed34e337a959919048e393f4b80d22aceffc3218

commit ed34e337a959919048e393f4b80d22aceffc3218
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Sun Dec 8 13:55:33 2024 +0100

    wifi-scripts: fix ucode support for referencing wifi devices by phy name
    
    Rename phys according to board.json
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 .../files-ucode/lib/netifd/wireless/mac80211.sh    | 53 +++++++++++++++++++++-
 .../usr/share/schema/wireless.wifi-device.json     |  4 ++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/package/network/config/wifi-scripts/files-ucode/lib/netifd/wireless/mac80211.sh b/package/network/config/wifi-scripts/files-ucode/lib/netifd/wireless/mac80211.sh
index 8b55d01e7a..cfd7424061 100755
--- a/package/network/config/wifi-scripts/files-ucode/lib/netifd/wireless/mac80211.sh
+++ b/package/network/config/wifi-scripts/files-ucode/lib/netifd/wireless/mac80211.sh
@@ -8,6 +8,7 @@ import * as supplicant from 'wifi.supplicant';
 import * as hostapd from 'wifi.hostapd';
 import * as netifd from 'wifi.netifd';
 import * as iface from 'wifi.iface';
+import * as nl80211 from 'nl80211';
 import * as fs from 'fs';
 
 global.radio = ARGV[2];
@@ -57,7 +58,7 @@ function phy_path_match(phy, path) {
 	return substr(phy_path, -length(path)) == path;
 }
 
-function find_phy_by_path(phys, path) {
+function __find_phy_by_path(phys, path) {
 	if (!path)
 		return null;
 
@@ -73,7 +74,57 @@ function find_phy_by_macaddr(phys, macaddr) {
 	return filter(phys, (phy) => phy_file(phy, "macaddr") == macaddr)[0];
 }
 
+function rename_phy_by_name(phys, name) {
+	let data = json(fs.readfile("/etc/board.json")).wlan;
+	if (!data)
+		return;
+
+	data = data[name];
+	if (!data)
+		return;
+
+	let prev_name = __find_phy_by_path(phys, data.path);
+	if (!prev_name)
+		return;
+
+	let idx = phy_index(prev_name);
+	nl80211.request(nl80211.const.NL80211_CMD_SET_WIPHY, 0, {
+		wiphy: idx,
+		wiphy_name: name
+	});
+	return true;
+}
+
+function find_phy_by_path(phys, path) {
+	let name = __find_phy_by_path(phys, path);
+	if (!name)
+		return;
+
+	let data = json(fs.readfile("/etc/board.json")).wlan;
+	if (!data || data[name])
+		return name;
+
+	for (let cur_name, cur_data in data) {
+		if (!phy_path_match(name, cur_data.path))
+			continue;
+
+		let idx = phy_index(name);
+		nl80211.request(nl80211.const.NL80211_CMD_SET_WIPHY, 0, {
+			wiphy: idx,
+			wiphy_name: cur_name
+		});
+
+		return cur_name;
+	}
+
+	return name;
+}
+
 function find_phy_by_name(phys, name) {
+	if (index(phys, name) >= 0)
+		return name;
+
+	rename_phy_by_name(phys, name);
 	return index(phys, name) < 0 ? null : name;
 }
 
diff --git a/package/network/config/wifi-scripts/files-ucode/usr/share/schema/wireless.wifi-device.json b/package/network/config/wifi-scripts/files-ucode/usr/share/schema/wireless.wifi-device.json
index 0588401c99..65d33989fe 100644
--- a/package/network/config/wifi-scripts/files-ucode/usr/share/schema/wireless.wifi-device.json
+++ b/package/network/config/wifi-scripts/files-ucode/usr/share/schema/wireless.wifi-device.json
@@ -547,6 +547,10 @@
 			"description": "Alternative to phy used to identify the device based paths in /sys/devices",
 			"type": "string"
 		},
+		"phy": {
+			"description": "Name of the phy, as described in board.json",
+			"type": "string"
+		},
 		"radio": {
 			"description": "Index of the phy radio (for multi-radio PHYs)",
 			"type": "number",




More information about the lede-commits mailing list