2007-10-05 17:56:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
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
|
|
|
|
[ -n "$devpath" -a -d "/sys/devices/$devpath/ieee80211" ] && {
|
|
|
|
phy="$(ls /sys/devices/$devpath/ieee80211 | grep -m 1 phy)"
|
|
|
|
[ -n "$phy" ] && return
|
|
|
|
}
|
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" ] && {
|
|
|
|
for _phy in $(ls /sys/class/ieee80211 2>/dev/null); do
|
|
|
|
[ "$macaddr" = "$(cat /sys/class/ieee80211/${_phy}/macaddress)" ] || continue
|
|
|
|
phy="$_phy"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
2009-10-02 15:18:44 +00:00
|
|
|
for dev in $(ls /sys/class/ieee80211); do
|
|
|
|
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
|
|
|
|
|
2009-10-02 19:41:04 +00:00
|
|
|
mode_11n=""
|
|
|
|
mode_band="g"
|
2010-10-13 12:22:48 +00:00
|
|
|
channel="11"
|
2009-11-09 00:58:39 +00:00
|
|
|
ht_cap=0
|
2010-01-15 02:55:29 +00:00
|
|
|
for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
|
2009-11-09 00:58:39 +00:00
|
|
|
ht_cap="$(($ht_cap | $cap))"
|
|
|
|
done
|
2009-11-04 21:53:49 +00:00
|
|
|
ht_capab="";
|
2009-11-09 00:58:39 +00:00
|
|
|
[ "$ht_cap" -gt 0 ] && {
|
2009-11-04 21:53:49 +00:00
|
|
|
mode_11n="n"
|
2010-01-20 02:26:05 +00:00
|
|
|
append ht_capab " option htmode HT20" "$N"
|
|
|
|
|
2009-11-04 21:53:49 +00:00
|
|
|
list=" list ht_capab"
|
2009-11-27 21:21:28 +00:00
|
|
|
[ "$(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC" "$N"
|
2010-10-27 15:04:29 +00:00
|
|
|
[ "$(($ht_cap & 16))" -eq 16 ] && append ht_capab "$list GF" "$N"
|
2009-11-04 21:53:49 +00:00
|
|
|
[ "$(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20" "$N"
|
|
|
|
[ "$(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40" "$N"
|
2010-05-02 22:03:44 +00:00
|
|
|
[ "$(($ht_cap & 128))" -eq 128 ] && append ht_capab "$list TX-STBC" "$N"
|
|
|
|
[ "$(($ht_cap & 768))" -eq 256 ] && append ht_capab "$list RX-STBC1" "$N"
|
|
|
|
[ "$(($ht_cap & 768))" -eq 512 ] && append ht_capab "$list RX-STBC12" "$N"
|
|
|
|
[ "$(($ht_cap & 768))" -eq 768 ] && append ht_capab "$list RX-STBC123" "$N"
|
2009-11-04 21:53:49 +00:00
|
|
|
[ "$(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40" "$N"
|
|
|
|
}
|
2009-11-28 13:49:14 +00:00
|
|
|
iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
|
2009-10-02 15:18:44 +00:00
|
|
|
|
2012-10-18 00:09:55 +00:00
|
|
|
if [ -x /usr/bin/readlink ]; then
|
|
|
|
path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
|
|
|
|
path="${path##/sys/devices/}"
|
|
|
|
dev_id=" option path '$path'"
|
|
|
|
else
|
|
|
|
dev_id=" option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)"
|
|
|
|
fi
|
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
cat <<EOF
|
2009-12-03 18:35:31 +00:00
|
|
|
config wifi-device radio$devidx
|
2007-10-05 17:56:15 +00:00
|
|
|
option type mac80211
|
2009-11-27 21:21:10 +00:00
|
|
|
option channel ${channel}
|
2009-10-02 19:41:04 +00:00
|
|
|
option hwmode 11${mode_11n}${mode_band}
|
2012-10-18 00:09:55 +00:00
|
|
|
$dev_id
|
2010-01-20 02:26:05 +00:00
|
|
|
$ht_capab
|
2007-10-05 17:56:15 +00:00
|
|
|
# REMOVE THIS LINE TO ENABLE WIFI:
|
|
|
|
option disabled 1
|
|
|
|
|
|
|
|
config wifi-iface
|
2009-12-03 18:35:31 +00:00
|
|
|
option device radio$devidx
|
2009-10-02 15:18:44 +00:00
|
|
|
option network lan
|
|
|
|
option mode ap
|
|
|
|
option ssid OpenWrt
|
2007-10-05 17:56:15 +00:00
|
|
|
option encryption none
|
2009-10-02 15:18:44 +00:00
|
|
|
|
2007-10-05 17:56:15 +00:00
|
|
|
EOF
|
2009-11-28 18:00:59 +00:00
|
|
|
devidx=$(($devidx + 1))
|
2007-10-05 17:56:15 +00:00
|
|
|
done
|
|
|
|
}
|
2009-10-02 15:18:44 +00:00
|
|
|
|