[openwrt/openwrt] mac80211: rename phy according to board.json entries on bringup
LEDE Commits
lede-commits at lists.infradead.org
Fri Oct 14 04:18:59 PDT 2022
nbd pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/4d323303e7e5743f541e3b41dfb2ac1627e8d96d
commit 4d323303e7e5743f541e3b41dfb2ac1627e8d96d
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Fri Sep 30 20:14:05 2022 +0200
mac80211: rename phy according to board.json entries on bringup
This allows phy names specified in board.json to be used directly instead of
the path option
Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
.../mac80211/files/lib/netifd/wireless/mac80211.sh | 68 +++++++++++++++++++++-
1 file changed, 65 insertions(+), 3 deletions(-)
diff --git a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
index e05a5b8fee..ed2805213e 100644
--- a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
+++ b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
@@ -581,15 +581,77 @@ mac80211_generate_mac() {
$(( (0x$6 + $id) % 0x100 ))
}
+get_board_phy_name() (
+ local path="$1"
+ local fallback_phy=""
+
+ __check_phy() {
+ local val="$1"
+ local key="$2"
+ local ref_path="$3"
+
+ json_select "$key"
+ json_get_values path
+ json_select ..
+
+ [ "${ref_path%+*}" = "$path" ] && fallback_phy=$key
+ [ "$ref_path" = "$path" ] || return 0
+
+ echo "$key"
+ exit
+ }
+
+ json_load_file /etc/board.json
+ json_for_each_item __check_phy wlan "$path"
+ [ -n "$fallback_phy" ] && echo "${fallback_phy}.${path##*+}"
+)
+
+rename_board_phy_by_path() {
+ local path="$1"
+
+ local new_phy="$(get_board_phy_name "$path")"
+ [ -z "$new_phy" -o "$new_phy" = "$phy" ] && return
+
+ iw "$phy" set name "$new_phy" && phy="$new_phy"
+}
+
+rename_board_phy_by_name() (
+ local phy="$1"
+ local suffix="${phy##*.}"
+ [ "$suffix" = "$phy" ] && suffix=
+
+ json_load_file /etc/board.json
+ json_select wlan
+ json_select "${phy%.*}" || return 0
+ json_get_values path
+
+ prev_phy="$(iwinfo nl80211 phyname "path=$path${suffix:++$suffix}")"
+ [ -n "$prev_phy" ] || return 0
+
+ [ "$prev_phy" = "$phy" ] && return 0
+
+ iw "$prev_phy" set name "$phy"
+)
+
find_phy() {
- [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
+ [ -n "$phy" ] && {
+ rename_board_phy_by_name "$phy"
+ [ -d /sys/class/ieee80211/$phy ] && return 0
+ }
[ -n "$path" ] && {
phy="$(iwinfo nl80211 phyname "path=$path")"
- [ -n "$phy" ] && return 0
+ [ -n "$phy" ] && {
+ rename_board_phy_by_path "$path"
+ return 0
+ }
}
[ -n "$macaddr" ] && {
for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
- grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
+ grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && {
+ path="$(iwinfo nl80211 path "$phy")"
+ rename_board_phy_by_path "$path"
+ return 0
+ }
done
}
return 1
More information about the lede-commits
mailing list