2007-10-05 17:56:15 +00:00
|
|
|
#!/bin/sh
|
2019-10-31 11:36:55 +00:00
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
append DRIVERS "mac80211"
|
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
check_mac80211_device() {
|
2012-10-18 00:09:55 +00:00
|
|
|
local device="$1"
|
2022-10-01 14:04:03 +00:00
|
|
|
local path="$2"
|
|
|
|
local macaddr="$3"
|
2012-10-18 00:09:55 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
[ -n "$found" ] && return 0
|
|
|
|
|
|
|
|
phy_path=
|
2012-10-18 00:09:55 +00:00
|
|
|
config_get phy "$device" phy
|
2022-10-01 14:04:03 +00:00
|
|
|
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
|
2009-10-02 15:18:44 +00:00
|
|
|
}
|
2012-10-18 00:09:55 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
config_get dev_macaddr "$device" macaddr
|
2012-10-18 00:09:55 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
[ -n "$macaddr" -a "$dev_macaddr" = "$macaddr" ] && found=1
|
2009-10-02 15:18:44 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
return 0
|
2009-10-02 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 12:56:02 +00:00
|
|
|
|
|
|
|
__get_band_defaults() {
|
|
|
|
local phy="$1"
|
|
|
|
|
|
|
|
( iw phy "$phy" info; echo ) | awk '
|
|
|
|
BEGIN {
|
|
|
|
bands = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
($1 == "Band" || $1 == "") && band {
|
|
|
|
if (channel) {
|
|
|
|
mode="NOHT"
|
|
|
|
if (ht) mode="HT20"
|
2021-06-03 03:38:53 +00:00
|
|
|
if (vht && band != "1:") mode="VHT80"
|
2021-05-24 12:56:02 +00:00
|
|
|
if (he) mode="HE80"
|
|
|
|
if (he && band == "1:") mode="HE20"
|
|
|
|
sub("\\[", "", channel)
|
|
|
|
sub("\\]", "", channel)
|
|
|
|
bands = bands band channel ":" mode " "
|
|
|
|
}
|
|
|
|
band=""
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "Band" {
|
|
|
|
band = $2
|
|
|
|
channel = ""
|
|
|
|
vht = ""
|
|
|
|
ht = ""
|
|
|
|
he = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
$0 ~ "Capabilities:" {
|
|
|
|
ht=1
|
|
|
|
}
|
|
|
|
|
2021-06-02 05:42:40 +00:00
|
|
|
$0 ~ "VHT Capabilities" {
|
2021-05-24 12:56:02 +00:00
|
|
|
vht=1
|
|
|
|
}
|
|
|
|
|
|
|
|
$0 ~ "HE Iftypes" {
|
|
|
|
he=1
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "*" && $3 == "MHz" && $0 !~ /disabled/ && band && !channel {
|
|
|
|
channel = $4
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
print bands
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
|
|
|
get_band_defaults() {
|
|
|
|
local phy="$1"
|
|
|
|
|
|
|
|
for c in $(__get_band_defaults "$phy"); do
|
|
|
|
local band="${c%%:*}"
|
|
|
|
c="${c#*:}"
|
|
|
|
local chan="${c%%:*}"
|
|
|
|
c="${c#*:}"
|
|
|
|
local mode="${c%%:*}"
|
|
|
|
|
|
|
|
case "$band" in
|
|
|
|
1) band=2g;;
|
|
|
|
2) band=5g;;
|
|
|
|
3) band=60g;;
|
|
|
|
4) band=6g;;
|
|
|
|
*) band="";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$band" ] || continue
|
|
|
|
[ -n "$mode_band" -a "$band" = "6g" ] && return
|
|
|
|
|
|
|
|
mode_band="$band"
|
|
|
|
channel="$chan"
|
|
|
|
htmode="$mode"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-10-10 11:26:32 +00:00
|
|
|
check_devidx() {
|
|
|
|
case "$1" in
|
|
|
|
radio[0-9]*)
|
|
|
|
local idx="${1#radio}"
|
|
|
|
[ "$devidx" -ge "${1#radio}" ] && devidx=$((idx + 1))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
detect_mac80211() {
|
2009-10-02 15:18:44 +00:00
|
|
|
devidx=0
|
|
|
|
config_load wireless
|
2022-10-10 11:26:32 +00:00
|
|
|
config_foreach check_devidx wifi-device
|
2014-10-09 09:04:24 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
json_load_file /etc/board.json
|
|
|
|
|
2014-10-09 09:04:24 +00:00
|
|
|
for _dev in /sys/class/ieee80211/*; do
|
|
|
|
[ -e "$_dev" ] || continue
|
|
|
|
|
|
|
|
dev="${_dev##*/}"
|
|
|
|
|
2021-05-24 12:56:02 +00:00
|
|
|
mode_band=""
|
|
|
|
channel=""
|
2014-02-03 13:31:44 +00:00
|
|
|
htmode=""
|
2014-05-06 15:43:08 +00:00
|
|
|
ht_capab=""
|
2014-02-03 13:31:44 +00:00
|
|
|
|
2021-05-24 12:56:02 +00:00
|
|
|
get_band_defaults "$dev"
|
2014-02-03 13:31:44 +00:00
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
path="$(iwinfo nl80211 path "$dev")"
|
|
|
|
macaddr="$(cat /sys/class/ieee80211/${dev}/macaddress)"
|
2022-12-16 10:37:30 +00:00
|
|
|
|
|
|
|
# work around phy rename related race condition
|
|
|
|
[ -n "$path" -o -n "$macaddr" ] || continue
|
|
|
|
|
2022-10-01 14:04:03 +00:00
|
|
|
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
|
|
|
|
|
2022-09-23 12:39:59 +00:00
|
|
|
name="radio${devidx}"
|
|
|
|
devidx=$(($devidx + 1))
|
|
|
|
case "$dev" in
|
|
|
|
phy*)
|
|
|
|
if [ -n "$path" ]; then
|
|
|
|
dev_id="set wireless.${name}.path='$path'"
|
|
|
|
else
|
2022-10-01 14:04:03 +00:00
|
|
|
dev_id="set wireless.${name}.macaddr='$macaddr'"
|
2022-09-23 12:39:59 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
dev_id="set wireless.${name}.phy='$dev'"
|
|
|
|
;;
|
|
|
|
esac
|
2012-10-18 00:09:55 +00:00
|
|
|
|
2016-10-17 13:59:13 +00:00
|
|
|
uci -q batch <<-EOF
|
2022-09-23 12:39:59 +00:00
|
|
|
set wireless.${name}=wifi-device
|
|
|
|
set wireless.${name}.type=mac80211
|
2016-10-17 13:59:13 +00:00
|
|
|
${dev_id}
|
2022-09-23 12:39:59 +00:00
|
|
|
set wireless.${name}.channel=${channel}
|
|
|
|
set wireless.${name}.band=${mode_band}
|
|
|
|
set wireless.${name}.htmode=$htmode
|
|
|
|
set wireless.${name}.disabled=1
|
|
|
|
|
|
|
|
set wireless.default_${name}=wifi-iface
|
|
|
|
set wireless.default_${name}.device=${name}
|
|
|
|
set wireless.default_${name}.network=lan
|
|
|
|
set wireless.default_${name}.mode=ap
|
|
|
|
set wireless.default_${name}.ssid=OpenWrt
|
|
|
|
set wireless.default_${name}.encryption=none
|
2007-10-05 17:56:15 +00:00
|
|
|
EOF
|
2016-10-17 13:59:13 +00:00
|
|
|
uci -q commit wireless
|
2007-10-05 17:56:15 +00:00
|
|
|
done
|
|
|
|
}
|