2007-10-05 17:56:15 +00:00
|
|
|
#!/bin/sh
|
2019-10-31 11:36:55 +00:00
|
|
|
. /lib/netifd/mac80211.sh
|
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
append DRIVERS "mac80211"
|
|
|
|
|
2012-10-18 00:09:55 +00:00
|
|
|
lookup_phy() {
|
|
|
|
[ -n "$phy" ] && {
|
2012-10-18 11:42:42 +00:00
|
|
|
[ -d /sys/class/ieee80211/$phy ] && return
|
2012-10-18 00:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local devpath
|
|
|
|
config_get devpath "$device" path
|
2014-07-29 09:48:07 +00:00
|
|
|
[ -n "$devpath" ] && {
|
2019-10-31 11:36:55 +00:00
|
|
|
phy="$(mac80211_path_to_phy "$devpath")"
|
|
|
|
[ -n "$phy" ] && return
|
2012-10-18 00:09:55 +00:00
|
|
|
}
|
2009-10-02 15:18:44 +00:00
|
|
|
|
|
|
|
local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
|
2012-10-18 00:09:55 +00:00
|
|
|
[ -n "$macaddr" ] && {
|
2014-10-09 09:04:24 +00:00
|
|
|
for _phy in /sys/class/ieee80211/*; do
|
|
|
|
[ -e "$_phy" ] || continue
|
|
|
|
|
|
|
|
[ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
|
|
|
|
phy="${_phy##*/}"
|
2012-10-18 00:09:55 +00:00
|
|
|
return
|
2009-10-02 15:18:44 +00:00
|
|
|
done
|
|
|
|
}
|
2012-10-18 00:09:55 +00:00
|
|
|
phy=
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
find_mac80211_phy() {
|
|
|
|
local device="$1"
|
|
|
|
|
|
|
|
config_get phy "$device" phy
|
|
|
|
lookup_phy
|
2009-10-02 15:18:44 +00:00
|
|
|
[ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
|
|
|
|
echo "PHY for wifi device $1 not found"
|
|
|
|
return 1
|
|
|
|
}
|
2012-10-18 00:09:55 +00:00
|
|
|
config_set "$device" phy "$phy"
|
|
|
|
|
|
|
|
config_get macaddr "$device" macaddr
|
2009-10-02 15:18:44 +00:00
|
|
|
[ -z "$macaddr" ] && {
|
|
|
|
config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
|
|
|
|
}
|
2012-10-18 00:09:55 +00:00
|
|
|
|
2009-10-02 15:18:44 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-03-15 00:44:02 +00:00
|
|
|
check_mac80211_device() {
|
2009-10-02 15:18:44 +00:00
|
|
|
config_get phy "$1" phy
|
|
|
|
[ -z "$phy" ] && {
|
2009-12-22 21:45:08 +00:00
|
|
|
find_mac80211_phy "$1" >/dev/null || return 0
|
2009-10-02 15:18:44 +00:00
|
|
|
config_get phy "$1" phy
|
|
|
|
}
|
|
|
|
[ "$phy" = "$dev" ] && found=1
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
if (vht) mode="VHT80"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
$0 ~ "VHT Capabilities:" {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
detect_mac80211() {
|
2009-10-02 15:18:44 +00:00
|
|
|
devidx=0
|
|
|
|
config_load wireless
|
2009-11-28 18:00:59 +00:00
|
|
|
while :; do
|
2009-12-03 18:35:31 +00:00
|
|
|
config_get type "radio$devidx" type
|
2009-11-28 18:00:59 +00:00
|
|
|
[ -n "$type" ] || break
|
|
|
|
devidx=$(($devidx + 1))
|
|
|
|
done
|
2014-10-09 09:04:24 +00:00
|
|
|
|
|
|
|
for _dev in /sys/class/ieee80211/*; do
|
|
|
|
[ -e "$_dev" ] || continue
|
|
|
|
|
|
|
|
dev="${_dev##*/}"
|
|
|
|
|
2009-10-02 15:18:44 +00:00
|
|
|
found=0
|
2011-03-15 00:44:02 +00:00
|
|
|
config_foreach check_mac80211_device wifi-device
|
2009-10-02 15:18:44 +00:00
|
|
|
[ "$found" -gt 0 ] && continue
|
|
|
|
|
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
|
|
|
|
2019-10-31 11:36:55 +00:00
|
|
|
path="$(mac80211_phy_to_path "$dev")"
|
2015-01-28 12:07:08 +00:00
|
|
|
if [ -n "$path" ]; then
|
2016-10-17 13:59:13 +00:00
|
|
|
dev_id="set wireless.radio${devidx}.path='$path'"
|
2012-10-18 00:09:55 +00:00
|
|
|
else
|
2016-10-17 13:59:13 +00:00
|
|
|
dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
|
2012-10-18 00:09:55 +00:00
|
|
|
fi
|
|
|
|
|
2016-10-17 13:59:13 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set wireless.radio${devidx}=wifi-device
|
|
|
|
set wireless.radio${devidx}.type=mac80211
|
|
|
|
${dev_id}
|
2021-05-24 12:56:02 +00:00
|
|
|
set wireless.radio${devidx}.channel=${channel}
|
|
|
|
set wireless.radio${devidx}.band=${mode_band}
|
|
|
|
set wireless.radio${devidx}.htmode=$htmode
|
2016-10-17 13:59:13 +00:00
|
|
|
set wireless.radio${devidx}.disabled=1
|
|
|
|
|
|
|
|
set wireless.default_radio${devidx}=wifi-iface
|
|
|
|
set wireless.default_radio${devidx}.device=radio${devidx}
|
|
|
|
set wireless.default_radio${devidx}.network=lan
|
|
|
|
set wireless.default_radio${devidx}.mode=ap
|
2017-11-07 08:45:53 +00:00
|
|
|
set wireless.default_radio${devidx}.ssid=OpenWrt
|
2016-10-17 13:59:13 +00:00
|
|
|
set wireless.default_radio${devidx}.encryption=none
|
2007-10-05 17:56:15 +00:00
|
|
|
EOF
|
2016-10-17 13:59:13 +00:00
|
|
|
uci -q commit wireless
|
|
|
|
|
|
|
|
devidx=$(($devidx + 1))
|
2007-10-05 17:56:15 +00:00
|
|
|
done
|
|
|
|
}
|