ubus: update to the latest version, adds a race fix for wait_for
[openwrt/openwrt.git] / package / kernel / mac80211 / files / lib / wifi / mac80211.sh
index e33b09abb2b3f84fc83d542873b921012c93fc74..9b15de55a8986fa9d354ccb5c92d65edf2b4f514 100644 (file)
@@ -8,16 +8,21 @@ lookup_phy() {
 
        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
+       [ -n "$devpath" ] && {
+               for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
+                       case "$(readlink -f /sys/class/ieee80211/$phy/device)" in
+                               *$devpath) return;;
+                       esac
+               done
        }
 
        local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
        [ -n "$macaddr" ] && {
-               for _phy in $(ls /sys/class/ieee80211 2>/dev/null); do
-                       [ "$macaddr" = "$(cat /sys/class/ieee80211/${_phy}/macaddress)" ] || continue
-                       phy="$_phy"
+               for _phy in /sys/class/ieee80211/*; do
+                       [ -e "$_phy" ] || continue
+
+                       [ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
+                       phy="${_phy##*/}"
                        return
                done
        }
@@ -61,39 +66,44 @@ detect_mac80211() {
                [ -n "$type" ] || break
                devidx=$(($devidx + 1))
        done
-       for dev in $(ls /sys/class/ieee80211); do
+
+       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_11n=""
                mode_band="g"
                channel="11"
-               ht_cap=0
-               for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
-                       ht_cap="$(($ht_cap | $cap))"
-               done
-               ht_capab="";
-               [ "$ht_cap" -gt 0 ] && {
-                       mode_11n="n"
-                       append ht_capab "       option htmode   HT20" "$N"
-
-                       list="  list ht_capab"
-                       [ "$(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list  LDPC" "$N"
-                       [ "$(($ht_cap & 16))" -eq 16 ] && append ht_capab "$list        GF" "$N"
-                       [ "$(($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"
-                       [ "$(($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"
-                       [ "$(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list    DSSS_CCK-40" "$N"
-               }
+               htmode=""
+               ht_capab=""
+
+               iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
                iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
 
-               if [ -x /usr/bin/readlink ]; then
+               vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities')
+               cap_5ghz=$(iw phy "$dev" info | grep -c "Band 2")
+               [ "$vht_cap" -gt 0 -a "$cap_5ghz" -gt 0 ] && {
+                       mode_band="a";
+                       channel="36"
+                       htmode="VHT80"
+               }
+
+               [ -n $htmode ] && append ht_capab "     option htmode   $htmode" "$N"
+
+               if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then
                        path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
+               else
+                       path=""
+               fi
+               if [ -n "$path" ]; then
                        path="${path##/sys/devices/}"
+                       case "$path" in
+                               platform*/pci*) path="${path##platform/}";;
+                       esac
                        dev_id="        option path     '$path'"
                else
                        dev_id="        option macaddr  $(cat /sys/class/ieee80211/${dev}/macaddress)"
@@ -103,7 +113,7 @@ detect_mac80211() {
 config wifi-device  radio$devidx
        option type     mac80211
        option channel  ${channel}
-       option hwmode   11${mode_11n}${mode_band}
+       option hwmode   11${mode_band}
 $dev_id
 $ht_capab
        # REMOVE THIS LINE TO ENABLE WIFI:
@@ -113,7 +123,7 @@ config wifi-iface
        option device   radio$devidx
        option network  lan
        option mode     ap
-       option ssid     OpenWrt
+       option ssid     LEDE
        option encryption none
 
 EOF