mac80211/hostapd: fix HT mode setup for RSN ad-hoc networks
[15.05/openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index d8fa07e..1a85d15 100644 (file)
@@ -88,7 +88,7 @@ mac80211_hostapd_setup_base() {
 
        [ "$auto_channel" -gt 0 ] && channel=acs_survey
 
-       json_get_vars noscan htmode
+       json_get_vars noscan
        json_get_values ht_capab_list ht_capab
 
        ieee80211n=1
@@ -490,6 +490,38 @@ mac80211_setup_supplicant() {
        wpa_supplicant_run "$ifname" ${hostapd_ctrl:+-H $hostapd_ctrl}
 }
 
+mac80211_setup_adhoc_htmode() {
+       case "$htmode" in
+               VHT20|HT20) ibss_htmode=HT20;;
+               HT40*|VHT40|VHT80|VHT160)
+                       case "$hwmode" in
+                               a)
+                                       case "$(( ($channel / 4) % 2 ))" in
+                                               1) ibss_htmode="HT40+" ;;
+                                               0) ibss_htmode="HT40-";;
+                                       esac
+                               ;;
+                               *)
+                                       case "$htmode" in
+                                               HT40+) ibss_htmode="HT40+";;
+                                               HT40-) ibss_htmode="HT40-";;
+                                               *)
+                                                       if [ "$channel" -lt 7 ]; then
+                                                               ibss_htmode="HT40+"
+                                                       else
+                                                               ibss_htmode="HT40-"
+                                                       fi
+                                               ;;
+                                       esac
+                               ;;
+                       esac
+                       [ "$auto_channel" -gt 0 ] && ibss_htmode="HT40+"
+               ;;
+               *) ibss_htmode="" ;;
+       esac
+
+}
+
 mac80211_setup_adhoc() {
        json_get_vars bssid ssid key mcast_rate
 
@@ -517,13 +549,13 @@ mac80211_setup_adhoc() {
 
        brstr=
        for br in $basic_rate_list; do
-               hostapd_add_rate brstr "$br"
+               wpa_supplicant_add_rate brstr "$br"
        done
 
        mcval=
-       [ -n "$mcast_rate" ] && hostapd_add_rate mcval "$mcast_rate"
+       [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
 
-       iw dev "$ifname" ibss join "$ssid" $freq $htmode fixed-freq $bssid \
+       iw dev "$ifname" ibss join "$ssid" $freq $ibss_htmode fixed-freq $bssid \
                ${beacon_int:+beacon-interval $beacon_int} \
                ${brstr:+basic-rates $brstr} \
                ${mcval:+mcast-rate $mcval} \
@@ -573,6 +605,7 @@ mac80211_setup_vif() {
                ;;
                adhoc)
                        wireless_vif_parse_encryption
+                       mac80211_setup_adhoc_htmode
                        if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
                                mac80211_setup_supplicant || failed=1
                        else
@@ -614,7 +647,7 @@ drv_mac80211_setup() {
                country chanbw distance \
                txpower antenna_gain \
                rxantenna txantenna \
-               frag rts beacon_int
+               frag rts beacon_int htmode
        json_get_values basic_rate_list basic_rate
        json_select ..