mac80211: clean up ht capability handling, drop the use of the ht_capab list, use...
[openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index c5d3482..4f859a7 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"
 
@@ -67,55 +86,73 @@ mac80211_hostapd_setup_base() {
                json_get_vars noscan htmode
                json_get_values ht_capab_list ht_capab
 
-               append base_cfg "ieee80211n=1" "$N"
-
+               ieee80211n=1
                ht_capab=
                case "$htmode" in
-                       HT20|HT40-|HT40+) ht_capab="[$htmode]";;
-                       VHT40|VHT80|VHT160)
-                               case "$channel" in
-                                       36|44|52|60|100|108|116|124|132|140|149|157) ht_capab="[HT40+]";;
-                                       40|48|56|64|104|112|120|128|136|144|153|161) ht_capab="[HT40-]";;
+                       HT20;;
+                       HT40*|VHT40|VHT80|VHT160)
+                               case "$(( ($channel / 4) % 2 ))" in
+                                       1) ht_capab="[HT40+]";;
+                                       0) ht_capab="[HT40-]";;
                                esac
-                               ;;
+                       ;;
+                       *) ieee80211n= ;;
                esac
-               for cap in $ht_capab_list; do
-                       ht_capab="$ht_capab[$cap]"
-               done
 
-               [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
+               [ -n "$ieee80211n" ] && {
+                       append base_cfg "ieee80211n=1" "$N"
+
+                       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
+
+                       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
                idx="$channel"
                case "$htmode" in
                        VHT40)
-                               case "$channel" in
-                                       36|40) idx=38;;
-                                       44|48) idx=42;;
-                                       52|56) idx=54;;
-                                       60|64) idx=58;;
-                                       100|104) idx=102;;
-                                       108|112) idx=110;;
-                                       116|120) idx=118;;
-                                       124|128) idx=126;;
-                                       132|136) idx=134;;
-                                       140|144) idx=142;;
-                                       149|153) idx=151;;
-                                       157|161) idx=159;;
+                               case "$(( ($channel / 4) % 2 ))" in
+                                       1) idx=$(($channel + 2));;
+                                       0) idx=$(($channel - 2));;
                                esac
                                enable_ac=1
                                append base_cfg "vht_oper_chwidth=0" "$N"
                                append base_cfg "vht_oper_centr_freq_seg0_idx=$idx" "$N"
                        ;;
                        VHT80)
-                               case "$channel" in
-                                       36|40|44|48) idx=42;;
-                                       52|56|60|64) idx=58;;
-                                       100|104|108|112) idx=106;;
-                                       116|120|124|128) idx=122;;
-                                       132|136|140|144) idx=138;;
-                                       149|153|157|161) idx=155;;
+                               case "$(( ($channel / 4) % 2 ))" in
+                                       1) idx=$(($channel + 6));;
+                                       2) idx=$(($channel + 2));;
+                                       3) idx=$(($channel - 2));;
+                                       0) idx=$(($channel - 6));;
                                esac
                                enable_ac=1
                                append base_cfg "vht_oper_chwidth=1" "$N"
@@ -449,6 +486,7 @@ mac80211_setup_adhoc() {
 
 mac80211_setup_vif() {
        local name="$1"
+       local failed
 
        json_select data
        json_get_vars ifname
@@ -473,7 +511,19 @@ mac80211_setup_vif() {
                                json_get_var mp_val "$var"
                                [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"
                        done
-                       # todo: authsae
+
+                       # authsae
+                       json_get_vars key
+                       if [ -n "$key" ]; then
+                               if [ -e "/lib/wifi/authsae.sh" ]; then
+                                       . /lib/wifi/authsae.sh
+                                       authsae_start_interface || failed=1
+                               else
+                                       wireless_setup_vif_failed AUTHSAE_NOT_INSTALLED
+                                       json_select ..
+                                       return
+                               fi
+                       fi
                ;;
                adhoc)
                        wireless_vif_parse_encryption