mac80211: try to get interface addresses from wiphy sysfs 'addresses' if no mask...
[openwrt/openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index 00c2108bbf82953c8df6cbe2178b049977d8b7a9..d8fa07e2250b48d73a21c4f338452d5388edd916 100644 (file)
@@ -36,7 +36,13 @@ drv_mac80211_init_device_config() {
                htc_vht \
                rx_antenna_pattern \
                tx_antenna_pattern
-       config_add_int vht_max_mpdu vht_max_rx_stbc vht_link_adapt vht160
+       config_add_int vht_max_a_mpdu_len_exp vht_max_mpdu vht_link_adapt vht160 rx_stbc tx_stbc
+       config_add_boolean \
+               ldpc \
+               greenfield \
+               short_gi_20 \
+               short_gi_40 \
+               dsss_cck_40
 }
 
 drv_mac80211_init_iface_config() {
@@ -47,7 +53,7 @@ drv_mac80211_init_iface_config() {
        config_add_boolean wds powersave
        config_add_int maxassoc
        config_add_int max_listen_int
-       config_add_int dtim_interval
+       config_add_int dtim_period
 
        # mesh
        config_add_string mesh_id
@@ -121,7 +127,7 @@ mac80211_hostapd_setup_base() {
 
                json_get_vars \
                        ldpc:1 \
-                       greenfield:1 \
+                       greenfield:0 \
                        short_gi_20:1 \
                        short_gi_40:1 \
                        tx_stbc:1 \
@@ -142,13 +148,14 @@ mac80211_hostapd_setup_base() {
                        GF:0x10::$greenfield \
                        SHORT-GI-20:0x20::$short_gi_20 \
                        SHORT-GI-40:0x40::$short_gi_40 \
-                       TX-STBC:0x80::$max_tx_stbc \
+                       TX-STBC:0x80::$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"
+               ht_capab="$ht_capab$ht_capab_flags"
+               [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
        }
 
        # 802.11ac
@@ -166,7 +173,7 @@ mac80211_hostapd_setup_base() {
                        append base_cfg "vht_oper_centr_freq_seg0_idx=$idx" "$N"
                ;;
                VHT80)
-                       case "$(( ($channel / 4) % 2 ))" in
+                       case "$(( ($channel / 4) % 4 ))" in
                                1) idx=$(($channel + 6));;
                                2) idx=$(($channel + 2));;
                                3) idx=$(($channel - 2));;
@@ -201,8 +208,10 @@ mac80211_hostapd_setup_base() {
                        htc_vht:1 \
                        rx_antenna_pattern:1 \
                        tx_antenna_pattern:1 \
+                       vht_max_a_mpdu_len_exp:7 \
                        vht_max_mpdu:11454 \
                        rx_stbc:4 \
+                       tx_stbc:4 \
                        vht_link_adapt:3 \
                        vht160:2
 
@@ -251,6 +260,24 @@ mac80211_hostapd_setup_base() {
                        vht_max_mpdu_hw=11454
                [ "$vht_max_mpdu_hw" != 3895 ] && \
                        vht_capab="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
+                       
+               # maximum A-MPDU length exponent
+               vht_max_a_mpdu_len_exp_hw=0
+               [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=1
+               [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=2
+               [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=3
+               [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=4
+               [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=5
+               [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=6
+               [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
+                       vht_max_a_mpdu_len_exp_hw=7
+               vht_capab="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
 
                # whether or not the STA supports link adaptation using VHT variant
                vht_link_adapt_hw=0
@@ -299,6 +326,13 @@ ${max_listen_int:+max_listen_interval=$max_listen_int}
 EOF
 }
 
+mac80211_get_addr() {
+       local phy="$1"
+       local idx="$(($2 + 1))"
+
+       head -n $(($macidx + 1)) /sys/class/ieee80211/${phy}/addresses | tail -n1
+}
+
 mac80211_generate_mac() {
        local phy="$1"
        local id="${macidx:-0}"
@@ -306,7 +340,18 @@ mac80211_generate_mac() {
        local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)"
        local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)"
 
-       [ "$mask" = "00:00:00:00:00:00" ] && mask="ff:ff:ff:ff:ff:ff";
+       [ "$mask" = "00:00:00:00:00:00" ] && {
+               mask="ff:ff:ff:ff:ff:ff";
+
+               [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt 1 ] && {
+                       addr="$(mac80211_get_addr "$phy" "$id")"
+                       [ -n "$addr" ] && {
+                               echo "$addr"
+                               return
+                       }
+               }
+       }
+
        local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
 
        local mask1=$1
@@ -337,9 +382,13 @@ mac80211_generate_mac() {
 
 find_phy() {
        [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
-       [ -n "$path" -a -d "/sys/devices/$path/ieee80211" ] && {
-               phy="$(ls /sys/devices/$path/ieee80211 | grep -m 1 phy)"
-               [ -n "$phy" ] && return 0
+       [ -n "$path" ] && {
+               for phy in /sys/devices/$path/ieee80211/phy*; do
+                       [ -e "$phy" ] && {
+                               phy="${phy##*/}"
+                               return 0
+                       }
+               done
        }
        [ -n "$macaddr" ] && {
                for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
@@ -445,7 +494,7 @@ mac80211_setup_adhoc() {
        json_get_vars bssid ssid key mcast_rate
 
        keyspec=
-       [ "$auth_type" == "wep" ] && {
+       [ "$auth_type" = "wep" ] && {
                set_default key 1
                case "$key" in
                        [1234])