aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2022-09-30 20:14:05 +0200
committerFelix Fietkau <nbd@nbd.name>2022-10-14 13:12:42 +0200
commit4d323303e7e5743f541e3b41dfb2ac1627e8d96d (patch)
treec8f72c38a04f15fffaff996e9e48eb0122989575 /package
parent6603748e0ca697f484adfc16a0d49d35ed36954d (diff)
downloadupstream-4d323303e7e5743f541e3b41dfb2ac1627e8d96d.tar.gz
upstream-4d323303e7e5743f541e3b41dfb2ac1627e8d96d.tar.bz2
upstream-4d323303e7e5743f541e3b41dfb2ac1627e8d96d.zip
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@nbd.name>
Diffstat (limited to 'package')
-rw-r--r--package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh68
1 files 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