@@ -26,6 +26,7 @@ drv_mac80211_init_device_config() {
2626 hostapd_common_add_device_config
2727
2828 config_add_string path phy ' macaddr:macaddr'
29+ config_add_int radio
2930 config_add_string tx_burst
3031 config_add_string distance
3132 config_add_int beacon_int chanbw frag rts
@@ -554,7 +555,7 @@ mac80211_hostapd_setup_bss() {
554555 }
555556 [ " $staidx " -gt 0 -o " $start_disabled " -eq 1 ] && append hostapd_cfg " start_disabled=1" " $N "
556557
557- cat >> /var/run/hostapd- $phy .conf << EOF
558+ cat >> " $hostapd_conf_file " << EOF
558559$hostapd_cfg
559560bssid=$macaddr
560561${dtim_period: +dtim_period=$dtim_period }
@@ -630,6 +631,15 @@ find_phy() {
630631 return 1
631632}
632633
634+ mac80211_get_state_key() {
635+ local phy="$1 "
636+ local radio="$2 "
637+ local key="$phy "
638+
639+ [ -n "$radio " ] && key="${key} _r${radio} "
640+ printf '%s' "$key " | tr -c 'A-Za-z0-9_' '_'
641+ }
642+
633643mac80211_check_ap() {
634644 has_ap=1
635645}
@@ -639,17 +649,21 @@ mac80211_iw_interface_add() {
639649 local ifname="$2 "
640650 local type="$3 "
641651 local wdsflag="$4 "
652+ local radio="$5 "
642653 local rc
643654 local oldifname
655+ local radioflag=
644656
645- iw phy "$phy " interface add "$ifname " type "$type " $wdsflag >/dev/null 2>&1
657+ [ -n "$radio " ] && radioflag="radios $radio "
658+
659+ iw phy "$phy " interface add "$ifname " type "$type " $wdsflag $radioflag >/dev/null 2>&1
646660 rc="$? "
647661
648662 [ "$rc " = 233 ] && {
649663 # Device might have just been deleted, give the kernel some time to finish cleaning it up
650664 sleep 1
651665
652- iw phy "$phy " interface add "$ifname " type "$type " $wdsflag >/dev/null 2>&1
666+ iw phy "$phy " interface add "$ifname " type "$type " $wdsflag $radioflag >/dev/null 2>&1
653667 rc="$? "
654668 }
655669
@@ -680,7 +694,7 @@ mac80211_iw_interface_add() {
680694 [ "$? " = 0 ] && {
681695 sleep 1
682696
683- iw phy "$phy " interface add "$ifname " type "$type " $wdsflag >/dev/null 2>&1
697+ iw phy "$phy " interface add "$ifname " type "$type " $wdsflag $radioflag >/dev/null 2>&1
684698 rc="$? "
685699 }
686700 }
@@ -707,7 +721,13 @@ mac80211_prepare_vif() {
707721
708722 json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
709723
710- [ -n "$ifname " ] || ifname="wlan${phy# phy}${if_idx: +-$if_idx } "
724+ [ -n "$ifname " ] || {
725+ if [ -n "$radio " ]; then
726+ ifname="wlan${phy# phy} -${radio}${if_idx: +-$if_idx } "
727+ else
728+ ifname="wlan${phy# phy}${if_idx: +-$if_idx } "
729+ fi
730+ }
711731 if_idx=$(( ${if_idx:- 0} + 1 ))
712732
713733 set_default wds 0
@@ -736,7 +756,7 @@ mac80211_prepare_vif() {
736756 # It is far easier to delete and create the desired interface
737757 case "$mode " in
738758 adhoc)
739- mac80211_iw_interface_add "$phy " "$ifname " adhoc || return
759+ mac80211_iw_interface_add "$phy " "$ifname " adhoc "" " $radio " || return
740760 ;;
741761 ap)
742762 # Hostapd will handle recreating the interface and
@@ -756,16 +776,16 @@ mac80211_prepare_vif() {
756776 }
757777 ;;
758778 mesh)
759- mac80211_iw_interface_add "$phy " "$ifname " mp || return
779+ mac80211_iw_interface_add "$phy " "$ifname " mp "" " $radio " || return
760780 ;;
761781 monitor)
762- mac80211_iw_interface_add "$phy " "$ifname " monitor || return
782+ mac80211_iw_interface_add "$phy " "$ifname " monitor "" " $radio " || return
763783 ;;
764784 sta)
765785 local wdsflag=
766786 [ "$enable " = 0 ] || staidx="$(( $staidx + 1 )) "
767787 [ "$wds " -gt 0 ] && wdsflag="4addr on"
768- mac80211_iw_interface_add "$phy " "$ifname " managed "$wdsflag " || return
788+ mac80211_iw_interface_add "$phy " "$ifname " managed "$wdsflag " " $radio " || return
769789 if [ "$wds " -gt 0 ]; then
770790 iw "$ifname " set 4addr on
771791 else
@@ -824,13 +844,13 @@ mac80211_setup_supplicant() {
824844 [ -z "$spobj " ] && add_sp=1
825845
826846 NEW_MD5_SP=$( test -e " ${_config} " && md5sum ${_config} )
827- OLD_MD5_SP=$( uci -q -P /var/state get wireless._${phy } .md5_${ifname} )
847+ OLD_MD5_SP=$( uci -q -P /var/state get wireless._${state_key } .md5_${ifname} )
828848 if [ "$add_sp " = "1" ]; then
829849 wpa_supplicant_run "$ifname " "$hostapd_ctrl "
830850 else
831851 [ "${NEW_MD5_SP} " == "${OLD_MD5_SP} " ] || ubus call $spobj reload
832852 fi
833- uci -q -P /var/state set wireless._${phy } .md5_${ifname} ="${NEW_MD5_SP} "
853+ uci -q -P /var/state set wireless._${state_key } .md5_${ifname} ="${NEW_MD5_SP} "
834854 return 0
835855}
836856
@@ -1069,12 +1089,14 @@ mac80211_vap_cleanup() {
10691089
10701090mac80211_interface_cleanup() {
10711091 local phy="$1 "
1072- local primary_ap=$( uci -q -P /var/state get wireless._${phy} .aplist)
1092+ local state_key="$2 "
1093+ local state="wireless._${state_key} "
1094+ local primary_ap=$( uci -q -P /var/state get ${state} .aplist)
10731095 primary_ap=${primary_ap%% * }
10741096
10751097 mac80211_vap_cleanup hostapd "${primary_ap} "
1076- mac80211_vap_cleanup wpa_supplicant "$( uci -q -P /var/state get wireless._ ${phy } .splist) "
1077- mac80211_vap_cleanup none "$( uci -q -P /var/state get wireless._ ${phy } .umlist) "
1098+ mac80211_vap_cleanup wpa_supplicant "$( uci -q -P /var/state get ${state } .splist) "
1099+ mac80211_vap_cleanup none "$( uci -q -P /var/state get ${state } .umlist) "
10781100}
10791101
10801102mac80211_set_noscan() {
@@ -1088,7 +1110,7 @@ drv_mac80211_cleanup() {
10881110drv_mac80211_setup() {
10891111 json_select config
10901112 json_get_vars \
1091- phy macaddr path \
1113+ phy macaddr path radio \
10921114 country chanbw distance \
10931115 txpower antenna_gain \
10941116 rxantenna txantenna \
@@ -1103,30 +1125,35 @@ drv_mac80211_setup() {
11031125 return 1
11041126 }
11051127
1106- wireless_set_data phy ="$phy "
1107- [ -z " $( uci -q -P /var/ state show wireless._ ${phy} ) " ] && uci -q -P /var/state set wireless._${phy} =phy
1128+ state_key ="$( mac80211_get_state_key " $ phy" " $radio " ) "
1129+ state=" wireless._${state_key} "
11081130
1109- OLDAPLIST=$( uci -q -P /var/state get wireless._${phy} .aplist)
1110- OLDSPLIST=$( uci -q -P /var/state get wireless._${phy} .splist)
1111- OLDUMLIST=$( uci -q -P /var/state get wireless._${phy} .umlist)
1131+ wireless_set_data phy="$phy " radio="$radio " state_key="$state_key "
1132+ [ -z "$( uci -q -P /var/state show ${state} ) " ] && uci -q -P /var/state set ${state} =phy
1133+
1134+ OLDAPLIST=$( uci -q -P /var/state get ${state} .aplist)
1135+ OLDSPLIST=$( uci -q -P /var/state get ${state} .splist)
1136+ OLDUMLIST=$( uci -q -P /var/state get ${state} .umlist)
11121137
11131138 local wdev
11141139 local cwdev
11151140 local found
11161141
1117- for wdev in $( list_phy_interfaces " $phy " ) ; do
1118- found=0
1119- for cwdev in $OLDAPLIST $OLDSPLIST $OLDUMLIST ; do
1120- if [ "$wdev " = "$cwdev " ]; then
1121- found=1
1122- break
1142+ [ -n "$radio " ] || {
1143+ for wdev in $( list_phy_interfaces " $phy " ) ; do
1144+ found=0
1145+ for cwdev in $OLDAPLIST $OLDSPLIST $OLDUMLIST ; do
1146+ if [ "$wdev " = "$cwdev " ]; then
1147+ found=1
1148+ break
1149+ fi
1150+ done
1151+ if [ "$found " = "0" ]; then
1152+ ip link set dev "$wdev " down
1153+ iw dev "$wdev " del
11231154 fi
11241155 done
1125- if [ "$found " = "0" ]; then
1126- ip link set dev "$wdev " down
1127- iw dev "$wdev " del
1128- fi
1129- done
1156+ }
11301157
11311158 # convert channel to frequency
11321159 [ "$auto_channel " -gt 0 ] || freq="$( get_freq " $phy " " $channel " " $band " ) "
@@ -1138,9 +1165,13 @@ drv_mac80211_setup() {
11381165 }
11391166 }
11401167
1141- hostapd_conf_file="/var/run/hostapd-$phy .conf"
1168+ if [ -n "$radio " ]; then
1169+ hostapd_conf_file="/var/run/hostapd-${phy} .${radio} .conf"
1170+ else
1171+ hostapd_conf_file="/var/run/hostapd-${phy} .conf"
1172+ fi
11421173
1143- macidx=0
1174+ macidx=" ${radio :- 0} "
11441175 staidx=0
11451176
11461177 [ -n "$chanbw " ] && {
@@ -1186,11 +1217,11 @@ drv_mac80211_setup() {
11861217 NEWAPLIST=
11871218 for_each_interface "ap" mac80211_prepare_vif
11881219 NEW_MD5=$( test -e " ${hostapd_conf_file} " && md5sum ${hostapd_conf_file} )
1189- OLD_MD5=$( uci -q -P /var/state get wireless._ ${phy } .md5)
1220+ OLD_MD5=$( uci -q -P /var/state get ${state } .md5)
11901221 if [ "${NEWAPLIST} " != "${OLDAPLIST} " ]; then
11911222 mac80211_vap_cleanup hostapd "${OLDAPLIST} "
11921223 fi
1193- [ -n "${NEWAPLIST} " ] && mac80211_iw_interface_add "$phy " "${NEWAPLIST%% * } " __ap
1224+ [ -n "${NEWAPLIST} " ] && mac80211_iw_interface_add "$phy " "${NEWAPLIST%% * } " __ap "" " $radio "
11941225 local add_ap=0
11951226 local primary_ap=${NEWAPLIST%% * }
11961227 [ -n "$hostapd_ctrl " ] && {
@@ -1202,10 +1233,10 @@ drv_mac80211_setup() {
12021233 no_reload=$?
12031234 if [ "$no_reload " != "0" ]; then
12041235 mac80211_vap_cleanup hostapd "${OLDAPLIST} "
1205- mac80211_vap_cleanup wpa_supplicant "$( uci -q -P /var/state get wireless._ ${phy } .splist) "
1206- mac80211_vap_cleanup none "$( uci -q -P /var/state get wireless._ ${phy } .umlist) "
1236+ mac80211_vap_cleanup wpa_supplicant "$( uci -q -P /var/state get ${state } .splist) "
1237+ mac80211_vap_cleanup none "$( uci -q -P /var/state get ${state } .umlist) "
12071238 sleep 2
1208- mac80211_iw_interface_add "$phy " "${NEWAPLIST%% * } " __ap
1239+ mac80211_iw_interface_add "$phy " "${NEWAPLIST%% * } " __ap "" " $radio "
12091240 for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
12101241 fi
12111242 }
@@ -1222,8 +1253,8 @@ drv_mac80211_setup() {
12221253 wireless_add_process "$( jsonfilter -s " $hostapd_res " -l 1 -e @.pid) " "/usr/sbin/hostapd" 1 1
12231254 fi
12241255 }
1225- uci -q -P /var/state set wireless._ ${phy } .aplist="${NEWAPLIST} "
1226- uci -q -P /var/state set wireless._ ${phy } .md5="${NEW_MD5} "
1256+ uci -q -P /var/state set ${state } .aplist="${NEWAPLIST} "
1257+ uci -q -P /var/state set ${state } .md5="${NEW_MD5} "
12271258
12281259 [ "${add_ap} " = 1 ] && sleep 1
12291260 for_each_interface "ap" mac80211_setup_vif
@@ -1233,8 +1264,8 @@ drv_mac80211_setup() {
12331264
12341265 for_each_interface "sta adhoc mesh monitor" mac80211_setup_vif
12351266
1236- uci -q -P /var/state set wireless._ ${phy } .splist="${NEWSPLIST} "
1237- uci -q -P /var/state set wireless._ ${phy } .umlist="${NEWUMLIST} "
1267+ uci -q -P /var/state set ${state } .splist="${NEWSPLIST} "
1268+ uci -q -P /var/state set ${state } .umlist="${NEWUMLIST} "
12381269
12391270 local foundvap
12401271 local dropvap=""
@@ -1269,15 +1300,16 @@ list_phy_interfaces() {
12691300
12701301drv_mac80211_teardown() {
12711302 json_select data
1272- json_get_vars phy
1303+ json_get_vars phy radio state_key
12731304 json_select ..
12741305 [ -n "$phy " ] || {
12751306 echo "Bug: PHY is undefined for device '$1 '"
12761307 return 1
12771308 }
12781309
1279- mac80211_interface_cleanup "$phy "
1280- uci -q -P /var/state revert wireless._${phy}
1310+ [ -n "$state_key " ] || state_key="$( mac80211_get_state_key " $phy " " $radio " ) "
1311+ mac80211_interface_cleanup "$phy " "$state_key "
1312+ uci -q -P /var/state revert wireless._${state_key}
12811313}
12821314
12831315add_driver mac80211
0 commit comments