[openwrt/openwrt] mac80211: use board.json provided phy names in generated default config
LEDE Commits
lede-commits at lists.infradead.org
Fri Oct 14 04:19:02 PDT 2022
nbd pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/a7ca1b2314cee3cd1d9ee28c7852b6d73258e229
commit a7ca1b2314cee3cd1d9ee28c7852b6d73258e229
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Sat Oct 1 16:04:03 2022 +0200
mac80211: use board.json provided phy names in generated default config
The phy will be automatically renamed on setup
Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
package/kernel/mac80211/files/lib/wifi/mac80211.sh | 113 +++++++++++----------
1 file changed, 62 insertions(+), 51 deletions(-)
diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
index 7166f3a12c..3ecd932228 100644
--- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
@@ -2,58 +2,46 @@
append DRIVERS "mac80211"
-lookup_phy() {
- [ -n "$phy" ] && {
- [ -d /sys/class/ieee80211/$phy ] && return
- }
-
- local devpath
- config_get devpath "$device" path
- [ -n "$devpath" ] && {
- phy="$(iwinfo nl80211 phyname "path=$devpath")"
- [ -n "$phy" ] && return
- }
-
- local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
- [ -n "$macaddr" ] && {
- for _phy in /sys/class/ieee80211/*; do
- [ -e "$_phy" ] || continue
-
- [ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
- phy="${_phy##*/}"
- return
- done
- }
- phy=
- return
-}
-
-find_mac80211_phy() {
+check_mac80211_device() {
local device="$1"
+ local path="$2"
+ local macaddr="$3"
+ [ -n "$found" ] && return 0
+
+ phy_path=
config_get phy "$device" phy
- lookup_phy
- [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
- echo "PHY for wifi device $1 not found"
- return 1
+ json_select wlan
+ [ -n "$phy" ] && case "$phy" in
+ phy*)
+ [ -d /sys/class/ieee80211/$phy ] && \
+ phy_path="$(iwinfo nl80211 path "$dev")"
+ ;;
+ *)
+ if json_is_a "$phy" object; then
+ json_select "$phy"
+ json_get_var phy_path path
+ json_select ..
+ elif json_is_a "${phy%.*}" object; then
+ json_select "${phy%.*}"
+ json_get_var phy_path path
+ json_select ..
+ phy_path="$phy_path+${phy##*.}"
+ fi
+ ;;
+ esac
+ json_select ..
+ [ -n "$phy_path" ] || config_get phy_path "$device" path
+ [ -n "$path" -a "$phy_path" = "$path" ] && {
+ found=1
+ return 0
}
- config_set "$device" phy "$phy"
- config_get macaddr "$device" macaddr
- [ -z "$macaddr" ] && {
- config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
- }
+ config_get dev_macaddr "$device" macaddr
- return 0
-}
+ [ -n "$macaddr" -a "$dev_macaddr" = "$macaddr" ] && found=1
-check_mac80211_device() {
- config_get phy "$1" phy
- [ -z "$phy" ] && {
- find_mac80211_phy "$1" >/dev/null || return 0
- config_get phy "$1" phy
- }
- [ "$phy" = "$dev" ] && found=1
+ return 0
}
@@ -144,20 +132,32 @@ check_devidx() {
esac
}
+check_board_phy() {
+ local name="$2"
+
+ json_select "$name"
+ json_get_var phy_path path
+ json_select ..
+
+ if [ "$path" = "$phy_path" ]; then
+ board_dev="$name"
+ elif [ "${path%+*}" = "$phy_path" ]; then
+ fallback_board_dev="$name.${path#*+}"
+ fi
+}
+
detect_mac80211() {
devidx=0
config_load wireless
config_foreach check_devidx wifi-device
+ json_load_file /etc/board.json
+
for _dev in /sys/class/ieee80211/*; do
[ -e "$_dev" ] || continue
dev="${_dev##*/}"
- found=0
- config_foreach check_mac80211_device wifi-device
- [ "$found" -gt 0 ] && continue
-
mode_band=""
channel=""
htmode=""
@@ -165,15 +165,26 @@ detect_mac80211() {
get_band_defaults "$dev"
+ path="$(iwinfo nl80211 path "$dev")"
+ macaddr="$(cat /sys/class/ieee80211/${dev}/macaddress)"
+ board_dev=
+ fallback_board_dev=
+ json_for_each_item check_board_phy wlan
+ [ -n "$board_dev" ] || board_dev="$fallback_board_dev"
+ [ -n "$board_dev" ] && dev="$board_dev"
+
+ found=
+ config_foreach check_mac80211_device wifi-device "$path" "$macaddr"
+ [ -n "$found" ] && continue
+
name="radio${devidx}"
devidx=$(($devidx + 1))
case "$dev" in
phy*)
- path="$(iwinfo nl80211 path "$dev")"
if [ -n "$path" ]; then
dev_id="set wireless.${name}.path='$path'"
else
- dev_id="set wireless.${name}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
+ dev_id="set wireless.${name}.macaddr='$macaddr'"
fi
;;
*)
More information about the lede-commits
mailing list