mac80211: fix disabling HT in IBSS mode (#21340)
[openwrt/openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index d2641a49c49c7facf2868f8e3902a058f58a62fa..71b96aa425e942b79831358ee3313f99a3063eb3 100644 (file)
@@ -21,8 +21,9 @@ drv_mac80211_init_device_config() {
        config_add_string hwmode
        config_add_int beacon_int chanbw frag rts
        config_add_int rxantenna txantenna antenna_gain txpower distance
-       config_add_boolean noscan
+       config_add_boolean noscan ht_coex
        config_add_array ht_capab
+       config_add_array channels
        config_add_boolean \
                rxldpc \
                short_gi_80 \
@@ -89,8 +90,9 @@ mac80211_hostapd_setup_base() {
        json_select config
 
        [ "$auto_channel" -gt 0 ] && channel=acs_survey
+       [ "$auto_channel" -gt 0 ] && json_get_values channel_list channels
 
-       json_get_vars noscan
+       json_get_vars noscan ht_coex
        json_get_values ht_capab_list ht_capab
 
        ieee80211n=1
@@ -127,6 +129,9 @@ mac80211_hostapd_setup_base() {
        [ -n "$ieee80211n" ] && {
                append base_cfg "ieee80211n=1" "$N"
 
+               set_default ht_coex 0
+               append base_cfg "ht_coex=$ht_coex" "$N"
+
                json_get_vars \
                        ldpc:1 \
                        greenfield:0 \
@@ -298,6 +303,7 @@ mac80211_hostapd_setup_base() {
        hostapd_prepare_device_config "$hostapd_conf_file" nl80211
        cat >> "$hostapd_conf_file" <<EOF
 ${channel:+channel=$channel}
+${channel_list:+chanlist=$channel_list}
 ${noscan:+noscan=$noscan}
 $base_cfg
 
@@ -447,17 +453,12 @@ mac80211_prepare_vif() {
                        mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
 
                        [ -n "$hostapd_ctrl" ] || {
-                               iw phy "$phy" interface add "$ifname" type managed
+                               iw phy "$phy" interface add "$ifname" type __ap
                                hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
                        }
                ;;
                mesh)
-                       json_get_vars key mesh_id
-                       if [ -n "$key" ]; then
-                               iw phy "$phy" interface add "$ifname" type mp
-                       else
-                               iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
-                       fi
+                       iw phy "$phy" interface add "$ifname" type mp
                ;;
                monitor)
                        iw phy "$phy" interface add "$ifname" type monitor
@@ -483,7 +484,7 @@ mac80211_prepare_vif() {
                # All interfaces must have unique mac addresses
                # which can either be explicitly set in the device
                # section, or automatically generated
-               ifconfig "$ifname" hw ether "$macaddr"
+               ip link set dev "$ifname" address "$macaddr"
        fi
 
        json_select ..
@@ -498,7 +499,7 @@ mac80211_setup_supplicant() {
 mac80211_setup_adhoc_htmode() {
        case "$htmode" in
                VHT20|HT20) ibss_htmode=HT20;;
-               HT40*|VHT40|VHT80|VHT160)
+               HT40*|VHT40|VHT160)
                        case "$hwmode" in
                                a)
                                        case "$(( ($channel / 4) % 2 ))" in
@@ -522,6 +523,12 @@ mac80211_setup_adhoc_htmode() {
                        esac
                        [ "$auto_channel" -gt 0 ] && ibss_htmode="HT40+"
                ;;
+               VHT80)
+                       ibss_htmode="80Mhz"
+               ;;
+               NONE|NOHT)
+                       ibss_htmode="NOHT"
+               ;;
                *) ibss_htmode="" ;;
        esac
 
@@ -579,7 +586,7 @@ mac80211_setup_vif() {
        json_get_vars mode
        json_get_var vif_txpower txpower
 
-       ifconfig "$ifname" up || {
+       ip link set dev "$ifname" up || {
                wireless_setup_vif_failed IFUP_ERROR
                json_select ..
                return
@@ -590,11 +597,6 @@ mac80211_setup_vif() {
 
        case "$mode" in
                mesh)
-                       for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
-                               json_get_var mp_val "$var"
-                               [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"
-                       done
-
                        # authsae or wpa_supplicant
                        json_get_vars key
                        if [ -n "$key" ]; then
@@ -605,7 +607,19 @@ mac80211_setup_vif() {
                                        wireless_vif_parse_encryption
                                        mac80211_setup_supplicant || failed=1
                                fi
+                       else
+                               json_get_vars mesh_id mcast_rate
+
+                               mcval=
+                               [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
+
+                               iw dev "$ifname" mesh join "$mesh_id" ${mcval:+mcast-rate $mcval}
                        fi
+
+                       for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
+                               json_get_var mp_val "$var"
+                               [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"
+                       done
                ;;
                adhoc)
                        wireless_vif_parse_encryption
@@ -635,7 +649,7 @@ mac80211_interface_cleanup() {
        local phy="$1"
 
        for wdev in $(list_phy_interfaces "$phy"); do
-               ifconfig "$wdev" down 2>/dev/null
+               ip link set dev "$wdev" down 2>/dev/null
                iw dev "$wdev" del
        done
 }