mac80211: only add the mbssid option to the config when set
[openwrt/openwrt.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
index 81c08b00bbc77e6fa5ac781da6170681f52348db..860609305f4539e33eec7a9d3460e7552ef02566 100644 (file)
@@ -26,7 +26,8 @@ drv_mac80211_init_device_config() {
        config_add_string tx_burst
        config_add_string distance
        config_add_int beacon_int chanbw frag rts
-       config_add_int rxantenna txantenna antenna_gain txpower min_tx_power
+       config_add_int rxantenna txantenna txpower min_tx_power
+       config_add_int num_global_macaddr multiple_bssid
        config_add_boolean noscan ht_coex acs_exclude_dfs background_radar
        config_add_array ht_capab
        config_add_array channels
@@ -487,12 +488,12 @@ ${channel:+channel=$channel}
 ${channel_list:+chanlist=$channel_list}
 ${hostapd_noscan:+noscan=1}
 ${tx_burst:+tx_queue_data2_burst=$tx_burst}
+${multiple_bssid:+mbssid=$multiple_bssid}
+#num_global_macaddr=$num_global_macaddr
 $base_cfg
 
 EOF
        json_select ..
-       radio_md5sum=$(md5sum $hostapd_conf_file | cut -d" " -f1)
-       echo "radio_config_id=${radio_md5sum}" >> $hostapd_conf_file
 }
 
 mac80211_hostapd_setup_bss() {
@@ -519,6 +520,7 @@ mac80211_hostapd_setup_bss() {
        cat >> /var/run/hostapd-$phy.conf <<EOF
 $hostapd_cfg
 bssid=$macaddr
+${default_macaddr:+#default_macaddr}
 ${dtim_period:+dtim_period=$dtim_period}
 ${max_listen_int:+max_listen_interval=$max_listen_int}
 EOF
@@ -535,47 +537,7 @@ mac80211_generate_mac() {
        local phy="$1"
        local id="${macidx:-0}"
 
-       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";
-
-               [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt $id ] && {
-                       addr="$(mac80211_get_addr "$phy" "$id")"
-                       [ -n "$addr" ] && {
-                               echo "$addr"
-                               return
-                       }
-               }
-       }
-
-       local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
-
-       local mask1=$1
-       local mask6=$6
-
-       local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
-
-       macidx=$(($id + 1))
-       [ "$((0x$mask1))" -gt 0 ] && {
-               b1="0x$1"
-               [ "$id" -gt 0 ] && \
-                       b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
-               printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
-               return
-       }
-
-       [ "$((0x$mask6))" -lt 255 ] && {
-               printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
-               return
-       }
-
-       off2=$(( (0x$6 + $id) / 0x100 ))
-       printf "%s:%s:%s:%s:%02x:%02x" \
-               $1 $2 $3 $4 \
-               $(( (0x$5 + $off2) % 0x100 )) \
-               $(( (0x$6 + $id) % 0x100 ))
+       wdev_tool "$phy" get_macaddr id=$id num_global=$num_global_macaddr mbssid=${multiple_bssid:-0}
 }
 
 get_board_phy_name() (
@@ -686,13 +648,16 @@ mac80211_prepare_vif() {
        set_default powersave 0
        json_add_string _ifname "$ifname"
 
+       default_macaddr=
        if [ -z "$macaddr" ]; then
                macaddr="$(mac80211_generate_mac $phy)"
                macidx="$(($macidx + 1))"
+               default_macaddr=1
        elif [ "$macaddr" = 'random' ]; then
                macaddr="$(macaddr_random)"
        fi
        json_add_string _macaddr "$macaddr"
+       json_add_string _default_macaddr "$default_macaddr"
        json_select ..
 
 
@@ -816,7 +781,7 @@ mac80211_setup_adhoc() {
 
        json_add_object "$ifname"
        json_add_string mode adhoc
-       json_add_string macaddr "$macaddr"
+       [ -n "$default_macaddr" ] || json_add_string macaddr "$macaddr"
        json_add_string ssid "$ssid"
        json_add_string freq "$freq"
        json_add_string htmode "$iw_htmode"
@@ -842,7 +807,7 @@ mac80211_setup_mesh() {
 
        json_add_object "$ifname"
        json_add_string mode mesh
-       json_add_string macaddr "$macaddr"
+       [ -n "$default_macaddr" ] || json_add_string macaddr "$macaddr"
        json_add_string ssid "$ssid"
        json_add_string freq "$freq"
        json_add_string htmode "$iw_htmode"
@@ -891,7 +856,6 @@ wpa_supplicant_init_config() {
 wpa_supplicant_add_interface() {
        local ifname="$1"
        local mode="$2"
-       local hostapd_ctrl="$3"
        local prev
 
        _wpa_supplicant_common "$ifname"
@@ -903,9 +867,8 @@ wpa_supplicant_add_interface() {
        json_add_string iface "$ifname"
        json_add_string mode "$mode"
        json_add_string config "$_config"
-       json_add_string macaddr "$macaddr"
+       [ -n "$default_macaddr" ] || json_add_string macaddr "$macaddr"
        [ -n "$network_bridge" ] && json_add_string bridge "$network_bridge"
-       [ -n "$hostapd_ctrl" ] && json_add_string hostapd_ctrl "$hostapd_ctrl"
        [ -n "$wds" ] && json_add_boolean 4addr "$wds"
        json_add_boolean powersave "$powersave"
        [ "$mode" = "mesh" ] && mac80211_add_mesh_params
@@ -980,7 +943,7 @@ mac80211_setup_supplicant() {
                wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
        fi
 
-       wpa_supplicant_add_interface "$ifname" "$mode" "$hostapd_ctrl"
+       wpa_supplicant_add_interface "$ifname" "$mode"
 
        return 0
 }
@@ -992,6 +955,7 @@ mac80211_setup_vif() {
        json_select config
        json_get_var ifname _ifname
        json_get_var macaddr _macaddr
+       json_get_var default_macaddr _default_macaddr
        json_get_vars mode wds powersave
 
        set_default powersave 0
@@ -1074,7 +1038,7 @@ mac80211_reset_config() {
        hostapd_conf_file="/var/run/hostapd-$phy.conf"
        ubus call hostapd config_set '{ "phy": "'"$phy"'", "config": "", "prev_config": "'"$hostapd_conf_file"'" }' > /dev/null
        ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'", "config": [] }' > /dev/null
-       wdev_tool "$phy" '{}'
+       wdev_tool "$phy" set_config '{}'
 }
 
 drv_mac80211_setup() {
@@ -1082,9 +1046,10 @@ drv_mac80211_setup() {
        json_get_vars \
                phy macaddr path \
                country chanbw distance \
-               txpower antenna_gain \
+               txpower \
                rxantenna txantenna \
-               frag rts beacon_int:100 htmode
+               frag rts beacon_int:100 htmode \
+               num_global_macaddr:1 multiple_bssid
        json_get_values basic_rate_list basic_rate
        json_get_values scan_list scan_list
        json_select ..
@@ -1129,7 +1094,6 @@ drv_mac80211_setup() {
        set_default rxantenna 0xffffffff
        set_default txantenna 0xffffffff
        set_default distance 0
-       set_default antenna_gain 0
 
        [ "$txantenna" = "all" ] && txantenna=0xffffffff
        [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
@@ -1138,7 +1102,6 @@ drv_mac80211_setup() {
        wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna"
 
        iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
-       iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1
        iw phy "$phy" set distance "$distance" >/dev/null 2>&1
 
        if [ -n "$txpower" ]; then
@@ -1180,7 +1143,7 @@ drv_mac80211_setup() {
        [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy"
 
        json_set_namespace wdev_uc prev
-       wdev_tool "$phy" "$(json_dump)" $active_ifnames
+       wdev_tool "$phy" set_config "$(json_dump)" $active_ifnames
        json_set_namespace "$prev"
 
        for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower