mac80211: clean up ht capability handling, drop the use of the ht_capab list, use...
authorFelix Fietkau <nbd@openwrt.org>
Sat, 3 May 2014 18:38:20 +0000 (18:38 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 3 May 2014 18:38:20 +0000 (18:38 +0000)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
SVN-Revision: 40682

package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
package/kernel/mac80211/files/lib/wifi/mac80211.sh

index c96b4a353be25e01f67a482b1307e87bd75ceb2f..4f859a73e7e3e0fcc0239069940a74b5022ea62c 100644 (file)
@@ -56,6 +56,25 @@ drv_mac80211_init_iface_config() {
        config_add_string $MP_CONFIG_STRING
 }
 
+mac80211_add_capabilities() {
+       local __var="$1"; shift
+       local __mask="$1"; shift
+       local __out= oifs
+
+       oifs="$IFS"
+       IFS=:
+       for capab in "$@"; do
+               set -- $capab
+
+               [ "$(($4))" -gt 0 ] || continue
+               [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] || continue
+               __out="$__out[$1]"
+       done
+       IFS="$oifs"
+
+       export -n -- "$__var=$__out"
+}
+
 mac80211_hostapd_setup_base() {
        local phy="$1"
 
@@ -80,13 +99,40 @@ mac80211_hostapd_setup_base() {
                        *) ieee80211n= ;;
                esac
 
-               [ -n "$ieee80211n" ] && append base_cfg "ieee80211n=1" "$N"
+               [ -n "$ieee80211n" ] && {
+                       append base_cfg "ieee80211n=1" "$N"
 
-               for cap in $ht_capab_list; do
-                       ht_capab="$ht_capab[$cap]"
-               done
+                       json_get_vars \
+                               ldpc:1 \
+                               greenfield:1 \
+                               short_gi_20:1 \
+                               short_gi_40:1 \
+                               tx_stbc:1 \
+                               rx_stbc:3 \
+                               dsss_cck_40:1
+
+                       ht_cap_mask=0
+                       for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do
+                               ht_cap_mask="$(($ht_cap_mask | $cap))"
+                       done
 
-               [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
+                       cap_rx_stbc=$((($ht_cap_mask >> 8) & 3))
+                       [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
+                       ht_cap_mask="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
+
+                       mac80211_add_capabilities ht_capab_flags $ht_cap_mask \
+                               LDPC:0x1::$ldpc \
+                               GF:0x10::$greenfield \
+                               SHORT-GI-20:0x20::$short_gi_20 \
+                               SHORT-GI-40:0x40::$short_gi_40 \
+                               TX-STBC:0x80::$max_tx_stbc \
+                               RX-STBC1:0x300:0x100:1 \
+                               RX-STBC12:0x300:0x200:1 \
+                               RX-STBC123:0x300:0x300:1 \
+                               DSSS_CCK-40:0x1000::$dsss_cck_40
+
+                       [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab$ht_capab_flags" "$N"
+               }
 
                # 802.11ac
                enable_ac=0
index e299ab939fdd8543d81d9da3420b096179ee3349..1f69b47193a35d743286b685599eb03ba0cdc7be 100644 (file)
@@ -71,26 +71,7 @@ detect_mac80211() {
                channel="11"
                htmode=""
 
-               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"
-                       htmode="HT20"
-
-                       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"
-               }
+               iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
                iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
 
                vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities')