base-files: wifi: add random MAC support for wifi-iface
[openwrt/staging/xback.git] / package / kernel / mac80211 / files / lib / netifd / wireless / mac80211.sh
1 #!/bin/sh
2 . /lib/netifd/netifd-wireless.sh
3 . /lib/netifd/hostapd.sh
4 . /lib/functions/system.sh
5
6 init_wireless_driver "$@"
7
8 MP_CONFIG_INT="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh_max_peer_links
9 mesh_max_retries mesh_ttl mesh_element_ttl mesh_hwmp_max_preq_retries
10 mesh_path_refresh_time mesh_min_discovery_timeout mesh_hwmp_active_path_timeout
11 mesh_hwmp_preq_min_interval mesh_hwmp_net_diameter_traversal_time mesh_hwmp_rootmode
12 mesh_hwmp_rann_interval mesh_gate_announcements mesh_sync_offset_max_neighor
13 mesh_rssi_threshold mesh_hwmp_active_path_to_root_timeout mesh_hwmp_root_interval
14 mesh_hwmp_confirmation_interval mesh_awake_window mesh_plink_timeout"
15 MP_CONFIG_BOOL="mesh_auto_open_plinks mesh_fwding"
16 MP_CONFIG_STRING="mesh_power_mode"
17
18 NEWAPLIST=
19 OLDAPLIST=
20 NEWSPLIST=
21 OLDSPLIST=
22 NEWUMLIST=
23 OLDUMLIST=
24
25 drv_mac80211_init_device_config() {
26 hostapd_common_add_device_config
27
28 config_add_string path phy 'macaddr:macaddr'
29 config_add_string tx_burst
30 config_add_string distance
31 config_add_int beacon_int chanbw frag rts
32 config_add_int rxantenna txantenna antenna_gain txpower min_tx_power
33 config_add_boolean noscan ht_coex acs_exclude_dfs background_radar
34 config_add_array ht_capab
35 config_add_array channels
36 config_add_array scan_list
37 config_add_boolean \
38 rxldpc \
39 short_gi_80 \
40 short_gi_160 \
41 tx_stbc_2by1 \
42 su_beamformer \
43 su_beamformee \
44 mu_beamformer \
45 mu_beamformee \
46 he_su_beamformer \
47 he_su_beamformee \
48 he_mu_beamformer \
49 vht_txop_ps \
50 htc_vht \
51 rx_antenna_pattern \
52 tx_antenna_pattern \
53 he_spr_sr_control \
54 he_twt_required
55 config_add_int \
56 beamformer_antennas \
57 beamformee_antennas \
58 vht_max_a_mpdu_len_exp \
59 vht_max_mpdu \
60 vht_link_adapt \
61 vht160 \
62 rx_stbc \
63 tx_stbc \
64 he_bss_color \
65 he_spr_non_srg_obss_pd_max_offset
66 config_add_boolean \
67 ldpc \
68 greenfield \
69 short_gi_20 \
70 short_gi_40 \
71 max_amsdu \
72 dsss_cck_40
73 }
74
75 drv_mac80211_init_iface_config() {
76 hostapd_common_add_bss_config
77
78 config_add_string 'macaddr:macaddr' ifname
79
80 config_add_boolean wds powersave enable
81 config_add_string wds_bridge
82 config_add_int maxassoc
83 config_add_int max_listen_int
84 config_add_int dtim_period
85 config_add_int start_disabled
86
87 # mesh
88 config_add_string mesh_id
89 config_add_int $MP_CONFIG_INT
90 config_add_boolean $MP_CONFIG_BOOL
91 config_add_string $MP_CONFIG_STRING
92 }
93
94 mac80211_add_capabilities() {
95 local __var="$1"; shift
96 local __mask="$1"; shift
97 local __out= oifs
98
99 oifs="$IFS"
100 IFS=:
101 for capab in "$@"; do
102 set -- $capab
103
104 [ "$(($4))" -gt 0 ] || continue
105 [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] || continue
106 __out="$__out[$1]"
107 done
108 IFS="$oifs"
109
110 export -n -- "$__var=$__out"
111 }
112
113 mac80211_add_he_capabilities() {
114 local __out= oifs
115
116 oifs="$IFS"
117 IFS=:
118 for capab in "$@"; do
119 set -- $capab
120 [ "$(($4))" -gt 0 ] || continue
121 [ "$(((0x$2) & $3))" -gt 0 ] || {
122 eval "$1=0"
123 continue
124 }
125 append base_cfg "$1=1" "$N"
126 done
127 IFS="$oifs"
128 }
129
130 mac80211_hostapd_setup_base() {
131 local phy="$1"
132
133 json_select config
134
135 [ "$auto_channel" -gt 0 ] && channel=acs_survey
136
137 [ "$auto_channel" -gt 0 ] && json_get_vars acs_exclude_dfs
138 [ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
139 append base_cfg "acs_exclude_dfs=1" "$N"
140
141 json_get_vars noscan ht_coex min_tx_power:0
142 json_get_values ht_capab_list ht_capab tx_burst
143 json_get_values channel_list channels
144
145 [ "$auto_channel" = 0 ] && [ -z "$channel_list" ] && \
146 channel_list="$channel"
147
148 [ "$min_tx_power" -gt 0 ] && append base_cfg "min_tx_power=$min_tx_power"
149
150 set_default noscan 0
151
152 [ "$noscan" -gt 0 ] && hostapd_noscan=1
153 [ "$tx_burst" = 0 ] && tx_burst=
154
155 chan_ofs=0
156 [ "$band" = "6g" ] && chan_ofs=1
157
158 ieee80211n=1
159 ht_capab=
160 case "$htmode" in
161 VHT20|HT20|HE20) ;;
162 HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160)
163 case "$hwmode" in
164 a)
165 case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
166 1) ht_capab="[HT40+]";;
167 0) ht_capab="[HT40-]";;
168 esac
169 ;;
170 *)
171 case "$htmode" in
172 HT40+) ht_capab="[HT40+]";;
173 HT40-) ht_capab="[HT40-]";;
174 *)
175 if [ "$channel" -lt 7 ]; then
176 ht_capab="[HT40+]"
177 else
178 ht_capab="[HT40-]"
179 fi
180 ;;
181 esac
182 ;;
183 esac
184 [ "$auto_channel" -gt 0 ] && ht_capab="[HT40+]"
185 ;;
186 *) ieee80211n= ;;
187 esac
188
189 [ -n "$ieee80211n" ] && {
190 append base_cfg "ieee80211n=1" "$N"
191
192 set_default ht_coex 0
193 append base_cfg "ht_coex=$ht_coex" "$N"
194
195 json_get_vars \
196 ldpc:1 \
197 greenfield:0 \
198 short_gi_20:1 \
199 short_gi_40:1 \
200 tx_stbc:1 \
201 rx_stbc:3 \
202 max_amsdu:1 \
203 dsss_cck_40:1
204
205 ht_cap_mask=0
206 for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do
207 ht_cap_mask="$(($ht_cap_mask | $cap))"
208 done
209
210 cap_rx_stbc=$((($ht_cap_mask >> 8) & 3))
211 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
212 ht_cap_mask="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
213
214 mac80211_add_capabilities ht_capab_flags $ht_cap_mask \
215 LDPC:0x1::$ldpc \
216 GF:0x10::$greenfield \
217 SHORT-GI-20:0x20::$short_gi_20 \
218 SHORT-GI-40:0x40::$short_gi_40 \
219 TX-STBC:0x80::$tx_stbc \
220 RX-STBC1:0x300:0x100:1 \
221 RX-STBC12:0x300:0x200:1 \
222 RX-STBC123:0x300:0x300:1 \
223 MAX-AMSDU-7935:0x800::$max_amsdu \
224 DSSS_CCK-40:0x1000::$dsss_cck_40
225
226 ht_capab="$ht_capab$ht_capab_flags"
227 [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
228 }
229
230 # 802.11ac
231 enable_ac=0
232 vht_oper_chwidth=0
233 vht_center_seg0=
234
235 idx="$channel"
236 case "$htmode" in
237 VHT20|HE20) enable_ac=1;;
238 VHT40|HE40)
239 case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
240 1) idx=$(($channel + 2));;
241 0) idx=$(($channel - 2));;
242 esac
243 enable_ac=1
244 vht_center_seg0=$idx
245 ;;
246 VHT80|HE80)
247 case "$(( (($channel / 4) + $chan_ofs) % 4 ))" in
248 1) idx=$(($channel + 6));;
249 2) idx=$(($channel + 2));;
250 3) idx=$(($channel - 2));;
251 0) idx=$(($channel - 6));;
252 esac
253 enable_ac=1
254 vht_oper_chwidth=1
255 vht_center_seg0=$idx
256 ;;
257 VHT160|HE160)
258 if [ "$band" = "6g" ]; then
259 case "$channel" in
260 1|5|9|13|17|21|25|29) idx=15;;
261 33|37|41|45|49|53|57|61) idx=47;;
262 65|69|73|77|81|85|89|93) idx=79;;
263 97|101|105|109|113|117|121|125) idx=111;;
264 129|133|137|141|145|149|153|157) idx=143;;
265 161|165|169|173|177|181|185|189) idx=175;;
266 193|197|201|205|209|213|217|221) idx=207;;
267 esac
268 else
269 case "$channel" in
270 36|40|44|48|52|56|60|64) idx=50;;
271 100|104|108|112|116|120|124|128) idx=114;;
272 esac
273 fi
274 enable_ac=1
275 vht_oper_chwidth=2
276 vht_center_seg0=$idx
277 ;;
278 esac
279 [ "$band" = "5g" ] && {
280 json_get_vars background_radar:0
281
282 [ "$background_radar" -eq 1 ] && append base_cfg "enable_background_radar=1" "$N"
283 }
284 [ "$band" = "6g" ] && {
285 op_class=
286 case "$htmode" in
287 HE20) op_class=131;;
288 HE*) op_class=$((132 + $vht_oper_chwidth))
289 esac
290 [ -n "$op_class" ] && append base_cfg "op_class=$op_class" "$N"
291 }
292 [ "$hwmode" = "a" ] || enable_ac=0
293
294 if [ "$enable_ac" != "0" ]; then
295 json_get_vars \
296 rxldpc:1 \
297 short_gi_80:1 \
298 short_gi_160:1 \
299 tx_stbc_2by1:1 \
300 su_beamformer:1 \
301 su_beamformee:1 \
302 mu_beamformer:1 \
303 mu_beamformee:1 \
304 vht_txop_ps:1 \
305 htc_vht:1 \
306 beamformee_antennas:4 \
307 beamformer_antennas:4 \
308 rx_antenna_pattern:1 \
309 tx_antenna_pattern:1 \
310 vht_max_a_mpdu_len_exp:7 \
311 vht_max_mpdu:11454 \
312 rx_stbc:4 \
313 vht_link_adapt:3 \
314 vht160:2
315
316 set_default tx_burst 2.0
317 append base_cfg "ieee80211ac=1" "$N"
318 vht_cap=0
319 for cap in $(iw phy "$phy" info | awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
320 vht_cap="$(($vht_cap | $cap))"
321 done
322
323 append base_cfg "vht_oper_chwidth=$vht_oper_chwidth" "$N"
324 append base_cfg "vht_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
325
326 cap_rx_stbc=$((($vht_cap >> 8) & 7))
327 [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
328 vht_cap="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
329
330 mac80211_add_capabilities vht_capab $vht_cap \
331 RXLDPC:0x10::$rxldpc \
332 SHORT-GI-80:0x20::$short_gi_80 \
333 SHORT-GI-160:0x40::$short_gi_160 \
334 TX-STBC-2BY1:0x80::$tx_stbc_2by1 \
335 SU-BEAMFORMER:0x800::$su_beamformer \
336 SU-BEAMFORMEE:0x1000::$su_beamformee \
337 MU-BEAMFORMER:0x80000::$mu_beamformer \
338 MU-BEAMFORMEE:0x100000::$mu_beamformee \
339 VHT-TXOP-PS:0x200000::$vht_txop_ps \
340 HTC-VHT:0x400000::$htc_vht \
341 RX-ANTENNA-PATTERN:0x10000000::$rx_antenna_pattern \
342 TX-ANTENNA-PATTERN:0x20000000::$tx_antenna_pattern \
343 RX-STBC-1:0x700:0x100:1 \
344 RX-STBC-12:0x700:0x200:1 \
345 RX-STBC-123:0x700:0x300:1 \
346 RX-STBC-1234:0x700:0x400:1 \
347
348 [ "$(($vht_cap & 0x800))" -gt 0 -a "$su_beamformer" -gt 0 ] && {
349 cap_ant="$(( ( ($vht_cap >> 16) & 3 ) + 1 ))"
350 [ "$cap_ant" -gt "$beamformer_antennas" ] && cap_ant="$beamformer_antennas"
351 [ "$cap_ant" -gt 1 ] && vht_capab="$vht_capab[SOUNDING-DIMENSION-$cap_ant]"
352 }
353
354 [ "$(($vht_cap & 0x1000))" -gt 0 -a "$su_beamformee" -gt 0 ] && {
355 cap_ant="$(( ( ($vht_cap >> 13) & 3 ) + 1 ))"
356 [ "$cap_ant" -gt "$beamformee_antennas" ] && cap_ant="$beamformee_antennas"
357 [ "$cap_ant" -gt 1 ] && vht_capab="$vht_capab[BF-ANTENNA-$cap_ant]"
358 }
359
360 # supported Channel widths
361 vht160_hw=0
362 [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
363 vht160_hw=1
364 [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
365 vht160_hw=2
366 [ "$vht160_hw" = 1 ] && vht_capab="$vht_capab[VHT160]"
367 [ "$vht160_hw" = 2 ] && vht_capab="$vht_capab[VHT160-80PLUS80]"
368
369 # maximum MPDU length
370 vht_max_mpdu_hw=3895
371 [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
372 vht_max_mpdu_hw=7991
373 [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
374 vht_max_mpdu_hw=11454
375 [ "$vht_max_mpdu_hw" != 3895 ] && \
376 vht_capab="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
377
378 # maximum A-MPDU length exponent
379 vht_max_a_mpdu_len_exp_hw=0
380 [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
381 vht_max_a_mpdu_len_exp_hw=1
382 [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
383 vht_max_a_mpdu_len_exp_hw=2
384 [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
385 vht_max_a_mpdu_len_exp_hw=3
386 [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
387 vht_max_a_mpdu_len_exp_hw=4
388 [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
389 vht_max_a_mpdu_len_exp_hw=5
390 [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
391 vht_max_a_mpdu_len_exp_hw=6
392 [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
393 vht_max_a_mpdu_len_exp_hw=7
394 vht_capab="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
395
396 # whether or not the STA supports link adaptation using VHT variant
397 vht_link_adapt_hw=0
398 [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
399 vht_link_adapt_hw=2
400 [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
401 vht_link_adapt_hw=3
402 [ "$vht_link_adapt_hw" != 0 ] && \
403 vht_capab="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
404
405 [ -n "$vht_capab" ] && append base_cfg "vht_capab=$vht_capab" "$N"
406 fi
407
408 # 802.11ax
409 enable_ax=0
410 case "$htmode" in
411 HE*) enable_ax=1 ;;
412 esac
413
414 if [ "$enable_ax" != "0" ]; then
415 json_get_vars \
416 he_su_beamformer:1 \
417 he_su_beamformee:0 \
418 he_mu_beamformer:1 \
419 he_twt_required:0 \
420 he_spr_sr_control:0 \
421 he_spr_non_srg_obss_pd_max_offset:1 \
422 he_bss_color
423
424 he_phy_cap=$(iw phy "$phy" info | awk -F "[()]" '/HE PHY Capabilities/ { print $2 }' | head -1)
425 he_phy_cap=${he_phy_cap:2}
426 he_mac_cap=$(iw phy "$phy" info | awk -F "[()]" '/HE MAC Capabilities/ { print $2 }' | head -1)
427 he_mac_cap=${he_mac_cap:2}
428
429 append base_cfg "ieee80211ax=1" "$N"
430 [ "$hwmode" = "a" ] && {
431 append base_cfg "he_oper_chwidth=$vht_oper_chwidth" "$N"
432 append base_cfg "he_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
433 }
434
435 set_default he_bss_color 128
436 append base_cfg "he_bss_color=$he_bss_color" "$N"
437
438 mac80211_add_he_capabilities \
439 he_su_beamformer:${he_phy_cap:6:2}:0x80:$he_su_beamformer \
440 he_su_beamformee:${he_phy_cap:8:2}:0x1:$he_su_beamformee \
441 he_mu_beamformer:${he_phy_cap:8:2}:0x2:$he_mu_beamformer \
442 he_spr_sr_control:${he_phy_cap:14:2}:0x1:$he_spr_sr_control \
443 he_twt_required:${he_mac_cap:0:2}:0x6:$he_twt_required
444
445 [ "$he_spr_sr_control" -gt 0 ] && append base_cfg "he_spr_non_srg_obss_pd_max_offset=$he_spr_non_srg_obss_pd_max_offset" "$N"
446
447 append base_cfg "he_default_pe_duration=4" "$N"
448 append base_cfg "he_rts_threshold=1023" "$N"
449 append base_cfg "he_mu_edca_qos_info_param_count=0" "$N"
450 append base_cfg "he_mu_edca_qos_info_q_ack=0" "$N"
451 append base_cfg "he_mu_edca_qos_info_queue_request=0" "$N"
452 append base_cfg "he_mu_edca_qos_info_txop_request=0" "$N"
453 append base_cfg "he_mu_edca_ac_be_aifsn=8" "$N"
454 append base_cfg "he_mu_edca_ac_be_aci=0" "$N"
455 append base_cfg "he_mu_edca_ac_be_ecwmin=9" "$N"
456 append base_cfg "he_mu_edca_ac_be_ecwmax=10" "$N"
457 append base_cfg "he_mu_edca_ac_be_timer=255" "$N"
458 append base_cfg "he_mu_edca_ac_bk_aifsn=15" "$N"
459 append base_cfg "he_mu_edca_ac_bk_aci=1" "$N"
460 append base_cfg "he_mu_edca_ac_bk_ecwmin=9" "$N"
461 append base_cfg "he_mu_edca_ac_bk_ecwmax=10" "$N"
462 append base_cfg "he_mu_edca_ac_bk_timer=255" "$N"
463 append base_cfg "he_mu_edca_ac_vi_ecwmin=5" "$N"
464 append base_cfg "he_mu_edca_ac_vi_ecwmax=7" "$N"
465 append base_cfg "he_mu_edca_ac_vi_aifsn=5" "$N"
466 append base_cfg "he_mu_edca_ac_vi_aci=2" "$N"
467 append base_cfg "he_mu_edca_ac_vi_timer=255" "$N"
468 append base_cfg "he_mu_edca_ac_vo_aifsn=5" "$N"
469 append base_cfg "he_mu_edca_ac_vo_aci=3" "$N"
470 append base_cfg "he_mu_edca_ac_vo_ecwmin=5" "$N"
471 append base_cfg "he_mu_edca_ac_vo_ecwmax=7" "$N"
472 append base_cfg "he_mu_edca_ac_vo_timer=255" "$N"
473 fi
474
475 hostapd_prepare_device_config "$hostapd_conf_file" nl80211
476 cat >> "$hostapd_conf_file" <<EOF
477 ${channel:+channel=$channel}
478 ${channel_list:+chanlist=$channel_list}
479 ${hostapd_noscan:+noscan=1}
480 ${tx_burst:+tx_queue_data2_burst=$tx_burst}
481 $base_cfg
482
483 EOF
484 json_select ..
485 radio_md5sum=$(md5sum $hostapd_conf_file | cut -d" " -f1)
486 echo "radio_config_id=${radio_md5sum}" >> $hostapd_conf_file
487 }
488
489 mac80211_hostapd_setup_bss() {
490 local phy="$1"
491 local ifname="$2"
492 local macaddr="$3"
493 local type="$4"
494
495 hostapd_cfg=
496 append hostapd_cfg "$type=$ifname" "$N"
497
498 hostapd_set_bss_options hostapd_cfg "$phy" "$vif" || return 1
499 json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
500
501 set_default wds 0
502 set_default start_disabled 0
503
504 [ "$wds" -gt 0 ] && {
505 append hostapd_cfg "wds_sta=1" "$N"
506 [ -n "$wds_bridge" ] && append hostapd_cfg "wds_bridge=$wds_bridge" "$N"
507 }
508 [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg "start_disabled=1" "$N"
509
510 cat >> /var/run/hostapd-$phy.conf <<EOF
511 $hostapd_cfg
512 bssid=$macaddr
513 ${dtim_period:+dtim_period=$dtim_period}
514 ${max_listen_int:+max_listen_interval=$max_listen_int}
515 EOF
516 }
517
518 mac80211_get_addr() {
519 local phy="$1"
520 local idx="$(($2 + 1))"
521
522 head -n $idx /sys/class/ieee80211/${phy}/addresses | tail -n1
523 }
524
525 mac80211_generate_mac() {
526 local phy="$1"
527 local id="${macidx:-0}"
528
529 local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)"
530 local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)"
531
532 [ "$mask" = "00:00:00:00:00:00" ] && {
533 mask="ff:ff:ff:ff:ff:ff";
534
535 [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt $id ] && {
536 addr="$(mac80211_get_addr "$phy" "$id")"
537 [ -n "$addr" ] && {
538 echo "$addr"
539 return
540 }
541 }
542 }
543
544 local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
545
546 local mask1=$1
547 local mask6=$6
548
549 local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
550
551 macidx=$(($id + 1))
552 [ "$((0x$mask1))" -gt 0 ] && {
553 b1="0x$1"
554 [ "$id" -gt 0 ] && \
555 b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
556 printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
557 return
558 }
559
560 [ "$((0x$mask6))" -lt 255 ] && {
561 printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
562 return
563 }
564
565 off2=$(( (0x$6 + $id) / 0x100 ))
566 printf "%s:%s:%s:%s:%02x:%02x" \
567 $1 $2 $3 $4 \
568 $(( (0x$5 + $off2) % 0x100 )) \
569 $(( (0x$6 + $id) % 0x100 ))
570 }
571
572 find_phy() {
573 [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0
574 [ -n "$path" ] && {
575 phy="$(iwinfo nl80211 phyname "path=$path")"
576 [ -n "$phy" ] && return 0
577 }
578 [ -n "$macaddr" ] && {
579 for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
580 grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0
581 done
582 }
583 return 1
584 }
585
586 mac80211_check_ap() {
587 has_ap=1
588 }
589
590 mac80211_iw_interface_add() {
591 local phy="$1"
592 local ifname="$2"
593 local type="$3"
594 local wdsflag="$4"
595 local rc
596 local oldifname
597
598 iw phy "$phy" interface add "$ifname" type "$type" $wdsflag >/dev/null 2>&1
599 rc="$?"
600
601 [ "$rc" = 233 ] && {
602 # Device might have just been deleted, give the kernel some time to finish cleaning it up
603 sleep 1
604
605 iw phy "$phy" interface add "$ifname" type "$type" $wdsflag >/dev/null 2>&1
606 rc="$?"
607 }
608
609 [ "$rc" = 233 ] && {
610 # Keep matching pre-existing interface
611 [ -d "/sys/class/ieee80211/${phy}/device/net/${ifname}" ] && \
612 case "$(iw dev $ifname info | grep "^\ttype" | cut -d' ' -f2- 2>/dev/null)" in
613 "AP")
614 [ "$type" = "__ap" ] && rc=0
615 ;;
616 "IBSS")
617 [ "$type" = "adhoc" ] && rc=0
618 ;;
619 "managed")
620 [ "$type" = "managed" ] && rc=0
621 ;;
622 "mesh point")
623 [ "$type" = "mp" ] && rc=0
624 ;;
625 "monitor")
626 [ "$type" = "monitor" ] && rc=0
627 ;;
628 esac
629 }
630
631 [ "$rc" = 233 ] && {
632 iw dev "$ifname" del >/dev/null 2>&1
633 [ "$?" = 0 ] && {
634 sleep 1
635
636 iw phy "$phy" interface add "$ifname" type "$type" $wdsflag >/dev/null 2>&1
637 rc="$?"
638 }
639 }
640
641 [ "$rc" != 0 ] && {
642 # Device might not support virtual interfaces, so the interface never got deleted in the first place.
643 # Check if the interface already exists, and avoid failing in this case.
644 [ -d "/sys/class/ieee80211/${phy}/device/net/${ifname}" ] && rc=0
645 }
646
647 [ "$rc" != 0 ] && {
648 # Device doesn't support virtual interfaces and may have existing interface other than ifname.
649 oldifname="$(basename "/sys/class/ieee80211/${phy}/device/net"/* 2>/dev/null)"
650 [ "$oldifname" ] && ip link set "$oldifname" name "$ifname" 1>/dev/null 2>&1
651 rc="$?"
652 }
653
654 [ "$rc" != 0 ] && echo "Failed to create interface $ifname"
655 return $rc
656 }
657
658 mac80211_prepare_vif() {
659 json_select config
660
661 json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
662
663 [ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}"
664 if_idx=$((${if_idx:-0} + 1))
665
666 set_default wds 0
667 set_default powersave 0
668
669 json_select ..
670
671 if [ -z "$macaddr" ]; then
672 macaddr="$(mac80211_generate_mac $phy)"
673 macidx="$(($macidx + 1))"
674 elif [ "$macaddr" = 'random' ]; then
675 macaddr="$(macaddr_random)"
676 fi
677
678 json_add_object data
679 json_add_string ifname "$ifname"
680 json_close_object
681
682 [ "$mode" == "ap" ] && {
683 [ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
684 [ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
685 }
686
687 json_select config
688
689 # It is far easier to delete and create the desired interface
690 case "$mode" in
691 adhoc)
692 mac80211_iw_interface_add "$phy" "$ifname" adhoc || return
693 ;;
694 ap)
695 # Hostapd will handle recreating the interface and
696 # subsequent virtual APs belonging to the same PHY
697 if [ -n "$hostapd_ctrl" ]; then
698 type=bss
699 else
700 type=interface
701 fi
702
703 mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
704
705 NEWAPLIST="${NEWAPLIST}$ifname "
706 [ -n "$hostapd_ctrl" ] || {
707 ap_ifname="${ifname}"
708 hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
709 }
710 ;;
711 mesh)
712 mac80211_iw_interface_add "$phy" "$ifname" mp || return
713 ;;
714 monitor)
715 mac80211_iw_interface_add "$phy" "$ifname" monitor || return
716 ;;
717 sta)
718 local wdsflag=
719 [ "$enable" = 0 ] || staidx="$(($staidx + 1))"
720 [ "$wds" -gt 0 ] && wdsflag="4addr on"
721 mac80211_iw_interface_add "$phy" "$ifname" managed "$wdsflag" || return
722 if [ "$wds" -gt 0 ]; then
723 iw "$ifname" set 4addr on
724 else
725 iw "$ifname" set 4addr off
726 fi
727 [ "$powersave" -gt 0 ] && powersave="on" || powersave="off"
728 iw "$ifname" set power_save "$powersave"
729 ;;
730 esac
731
732 case "$mode" in
733 monitor|mesh)
734 [ "$auto_channel" -gt 0 ] || iw dev "$ifname" set channel "$channel" $iw_htmode
735 ;;
736 esac
737
738 if [ "$mode" != "ap" ]; then
739 # ALL ap functionality will be passed to hostapd
740 # All interfaces must have unique mac addresses
741 # which can either be explicitly set in the device
742 # section, or automatically generated
743 ip link set dev "$ifname" address "$macaddr"
744 fi
745
746 json_select ..
747 }
748
749 mac80211_setup_supplicant() {
750 local enable=$1
751 local add_sp=0
752 local spobj="$(ubus -S list | grep wpa_supplicant.${ifname})"
753
754 [ "$enable" = 0 ] && {
755 ubus call wpa_supplicant.${phy} config_remove "{\"iface\":\"$ifname\"}"
756 ip link set dev "$ifname" down
757 iw dev "$ifname" del
758 return 0
759 }
760
761 wpa_supplicant_prepare_interface "$ifname" nl80211 || {
762 iw dev "$ifname" del
763 return 1
764 }
765 if [ "$mode" = "sta" ]; then
766 wpa_supplicant_add_network "$ifname"
767 else
768 wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
769 fi
770
771 NEWSPLIST="${NEWSPLIST}$ifname "
772
773 if [ "${NEWAPLIST%% *}" != "${OLDAPLIST%% *}" ]; then
774 [ "$spobj" ] && ubus call wpa_supplicant config_remove "{\"iface\":\"$ifname\"}"
775 add_sp=1
776 fi
777 [ -z "$spobj" ] && add_sp=1
778
779 NEW_MD5_SP=$(test -e "${_config}" && md5sum ${_config})
780 OLD_MD5_SP=$(uci -q -P /var/state get wireless._${phy}.md5_${ifname})
781 if [ "$add_sp" = "1" ]; then
782 wpa_supplicant_run "$ifname" "$hostapd_ctrl"
783 else
784 [ "${NEW_MD5_SP}" == "${OLD_MD5_SP}" ] || ubus call $spobj reload
785 fi
786 uci -q -P /var/state set wireless._${phy}.md5_${ifname}="${NEW_MD5_SP}"
787 return 0
788 }
789
790 mac80211_setup_supplicant_noctl() {
791 local enable=$1
792 local spobj="$(ubus -S list | grep wpa_supplicant.${ifname})"
793 wpa_supplicant_prepare_interface "$ifname" nl80211 || {
794 iw dev "$ifname" del
795 return 1
796 }
797
798 wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
799
800 NEWSPLIST="${NEWSPLIST}$ifname "
801 [ "$enable" = 0 ] && {
802 ubus call wpa_supplicant config_remove "{\"iface\":\"$ifname\"}"
803 ip link set dev "$ifname" down
804 return 0
805 }
806 if [ -z "$spobj" ]; then
807 wpa_supplicant_run "$ifname"
808 else
809 ubus call $spobj reload
810 fi
811 }
812
813 mac80211_prepare_iw_htmode() {
814 case "$htmode" in
815 VHT20|HT20) iw_htmode=HT20;;
816 HT40*|VHT40|VHT160)
817 case "$band" in
818 2g)
819 case "$htmode" in
820 HT40+) iw_htmode="HT40+";;
821 HT40-) iw_htmode="HT40-";;
822 *)
823 if [ "$channel" -lt 7 ]; then
824 iw_htmode="HT40+"
825 else
826 iw_htmode="HT40-"
827 fi
828 ;;
829 esac
830 ;;
831 *)
832 case "$(( ($channel / 4) % 2 ))" in
833 1) iw_htmode="HT40+" ;;
834 0) iw_htmode="HT40-";;
835 esac
836 ;;
837 esac
838 [ "$auto_channel" -gt 0 ] && iw_htmode="HT40+"
839 ;;
840 VHT80)
841 iw_htmode="80MHZ"
842 ;;
843 NONE|NOHT)
844 iw_htmode="NOHT"
845 ;;
846 *) iw_htmode="" ;;
847 esac
848 }
849
850 mac80211_setup_adhoc() {
851 local enable=$1
852 json_get_vars bssid ssid key mcast_rate
853
854 NEWUMLIST="${NEWUMLIST}$ifname "
855
856 [ "$enable" = 0 ] && {
857 ip link set dev "$ifname" down
858 return 0
859 }
860
861 keyspec=
862 [ "$auth_type" = "wep" ] && {
863 set_default key 1
864 case "$key" in
865 [1234])
866 local idx
867 for idx in 1 2 3 4; do
868 json_get_var ikey "key$idx"
869
870 [ -n "$ikey" ] && {
871 ikey="$(($idx - 1)):$(prepare_key_wep "$ikey")"
872 [ $idx -eq $key ] && ikey="d:$ikey"
873 append keyspec "$ikey"
874 }
875 done
876 ;;
877 *)
878 append keyspec "d:0:$(prepare_key_wep "$key")"
879 ;;
880 esac
881 }
882
883 brstr=
884 for br in $basic_rate_list; do
885 wpa_supplicant_add_rate brstr "$br"
886 done
887
888 mcval=
889 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
890
891 iw dev "$ifname" set type ibss
892 iw dev "$ifname" ibss join "$ssid" $freq $iw_htmode fixed-freq $bssid \
893 beacon-interval $beacon_int \
894 ${brstr:+basic-rates $brstr} \
895 ${mcval:+mcast-rate $mcval} \
896 ${keyspec:+keys $keyspec}
897 }
898
899 mac80211_setup_mesh() {
900 local enable=$1
901 json_get_vars ssid mesh_id mcast_rate
902
903 NEWUMLIST="${NEWUMLIST}$ifname "
904
905 [ "$enable" = 0 ] && {
906 ip link set dev "$ifname" down
907 return 0
908 }
909
910 mcval=
911 [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
912 [ -n "$mesh_id" ] && ssid="$mesh_id"
913
914 iw dev "$ifname" mesh join "$ssid" freq $freq $iw_htmode \
915 ${mcval:+mcast-rate $mcval} \
916 beacon-interval $beacon_int
917 }
918
919 mac80211_setup_vif() {
920 local name="$1"
921 local failed
922 local action=up
923
924 json_select data
925 json_get_vars ifname
926 json_select ..
927
928 json_select config
929 json_get_vars mode
930 json_get_var vif_txpower
931 json_get_var vif_enable enable 1
932
933 [ "$vif_enable" = 1 ] || action=down
934 if [ "$mode" != "ap" ] || [ "$ifname" = "$ap_ifname" ]; then
935 ip link set dev "$ifname" "$action" || {
936 wireless_setup_vif_failed IFUP_ERROR
937 json_select ..
938 return
939 }
940 [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
941 fi
942
943 case "$mode" in
944 mesh)
945 wireless_vif_parse_encryption
946 [ -z "$htmode" ] && htmode="NOHT";
947 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ] || chan_is_dfs "$phy" "$channel"; then
948 mac80211_setup_supplicant $vif_enable || failed=1
949 else
950 mac80211_setup_mesh $vif_enable
951 fi
952 for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
953 json_get_var mp_val "$var"
954 [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val"
955 done
956 ;;
957 adhoc)
958 wireless_vif_parse_encryption
959 if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
960 mac80211_setup_supplicant_noctl $vif_enable || failed=1
961 else
962 mac80211_setup_adhoc $vif_enable
963 fi
964 ;;
965 sta)
966 mac80211_setup_supplicant $vif_enable || failed=1
967 ;;
968 esac
969
970 json_select ..
971 [ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
972 }
973
974 get_freq() {
975 local phy="$1"
976 local channel="$2"
977 local band="$3"
978
979 case "$band" in
980 2g) band="1:";;
981 5g) band="2:";;
982 60g) band="3:";;
983 6g) band="4:";;
984 esac
985
986 iw "$phy" info | awk -v band="$band" -v channel="[$channel]" '
987
988 $1 ~ /Band/ {
989 band_match = band == $2
990 }
991
992 band_match && $3 == "MHz" && $4 == channel {
993 print $2
994 exit
995 }
996 '
997 }
998
999
1000 chan_is_dfs() {
1001 local phy="$1"
1002 local chan="$2"
1003 iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep -q "MHz.*radar detection"
1004 return $!
1005 }
1006
1007 mac80211_vap_cleanup() {
1008 local service="$1"
1009 local vaps="$2"
1010
1011 for wdev in $vaps; do
1012 [ "$service" != "none" ] && ubus call ${service} config_remove "{\"iface\":\"$wdev\"}"
1013 ip link set dev "$wdev" down 2>/dev/null
1014 iw dev "$wdev" del
1015 done
1016 }
1017
1018 mac80211_interface_cleanup() {
1019 local phy="$1"
1020 local primary_ap=$(uci -q -P /var/state get wireless._${phy}.aplist)
1021 primary_ap=${primary_ap%% *}
1022
1023 mac80211_vap_cleanup hostapd "${primary_ap}"
1024 mac80211_vap_cleanup wpa_supplicant "$(uci -q -P /var/state get wireless._${phy}.splist)"
1025 mac80211_vap_cleanup none "$(uci -q -P /var/state get wireless._${phy}.umlist)"
1026 }
1027
1028 mac80211_set_noscan() {
1029 hostapd_noscan=1
1030 }
1031
1032 drv_mac80211_cleanup() {
1033 hostapd_common_cleanup
1034 }
1035
1036 drv_mac80211_setup() {
1037 json_select config
1038 json_get_vars \
1039 phy macaddr path \
1040 country chanbw distance \
1041 txpower antenna_gain \
1042 rxantenna txantenna \
1043 frag rts beacon_int:100 htmode
1044 json_get_values basic_rate_list basic_rate
1045 json_get_values scan_list scan_list
1046 json_select ..
1047
1048 find_phy || {
1049 echo "Could not find PHY for device '$1'"
1050 wireless_set_retry 0
1051 return 1
1052 }
1053
1054 wireless_set_data phy="$phy"
1055 [ -z "$(uci -q -P /var/state show wireless._${phy})" ] && uci -q -P /var/state set wireless._${phy}=phy
1056
1057 OLDAPLIST=$(uci -q -P /var/state get wireless._${phy}.aplist)
1058 OLDSPLIST=$(uci -q -P /var/state get wireless._${phy}.splist)
1059 OLDUMLIST=$(uci -q -P /var/state get wireless._${phy}.umlist)
1060
1061 local wdev
1062 local cwdev
1063 local found
1064
1065 for wdev in $(list_phy_interfaces "$phy"); do
1066 found=0
1067 for cwdev in $OLDAPLIST $OLDSPLIST $OLDUMLIST; do
1068 if [ "$wdev" = "$cwdev" ]; then
1069 found=1
1070 break
1071 fi
1072 done
1073 if [ "$found" = "0" ]; then
1074 ip link set dev "$wdev" down
1075 iw dev "$wdev" del
1076 fi
1077 done
1078
1079 # convert channel to frequency
1080 [ "$auto_channel" -gt 0 ] || freq="$(get_freq "$phy" "$channel" "$band")"
1081
1082 [ -n "$country" ] && {
1083 iw reg get | grep -q "^country $country:" || {
1084 iw reg set "$country"
1085 sleep 1
1086 }
1087 }
1088
1089 hostapd_conf_file="/var/run/hostapd-$phy.conf"
1090
1091 no_ap=1
1092 macidx=0
1093 staidx=0
1094
1095 [ -n "$chanbw" ] && {
1096 for file in /sys/kernel/debug/ieee80211/$phy/ath9k*/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
1097 [ -f "$file" ] && echo "$chanbw" > "$file"
1098 done
1099 }
1100
1101 set_default rxantenna 0xffffffff
1102 set_default txantenna 0xffffffff
1103 set_default distance 0
1104 set_default antenna_gain 0
1105
1106 [ "$txantenna" = "all" ] && txantenna=0xffffffff
1107 [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
1108
1109 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
1110 iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1
1111 iw phy "$phy" set distance "$distance" >/dev/null 2>&1
1112
1113 if [ -n "$txpower" ]; then
1114 iw phy "$phy" set txpower fixed "${txpower%%.*}00"
1115 else
1116 iw phy "$phy" set txpower auto
1117 fi
1118
1119 [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
1120 [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
1121
1122 has_ap=
1123 hostapd_ctrl=
1124 ap_ifname=
1125 hostapd_noscan=
1126 for_each_interface "ap" mac80211_check_ap
1127
1128 rm -f "$hostapd_conf_file"
1129
1130 for_each_interface "sta adhoc mesh" mac80211_set_noscan
1131 [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
1132
1133 mac80211_prepare_iw_htmode
1134 for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
1135 NEWAPLIST=
1136 for_each_interface "ap" mac80211_prepare_vif
1137 NEW_MD5=$(test -e "${hostapd_conf_file}" && md5sum ${hostapd_conf_file})
1138 OLD_MD5=$(uci -q -P /var/state get wireless._${phy}.md5)
1139 if [ "${NEWAPLIST}" != "${OLDAPLIST}" ]; then
1140 mac80211_vap_cleanup hostapd "${OLDAPLIST}"
1141 fi
1142 [ -n "${NEWAPLIST}" ] && mac80211_iw_interface_add "$phy" "${NEWAPLIST%% *}" __ap
1143 local add_ap=0
1144 local primary_ap=${NEWAPLIST%% *}
1145 [ -n "$hostapd_ctrl" ] && {
1146 local no_reload=1
1147 if [ -n "$(ubus list | grep hostapd.$primary_ap)" ]; then
1148 no_reload=0
1149 [ "${NEW_MD5}" = "${OLD_MD5}" ] || {
1150 ubus call hostapd.$primary_ap reload
1151 no_reload=$?
1152 if [ "$no_reload" != "0" ]; then
1153 mac80211_vap_cleanup hostapd "${OLDAPLIST}"
1154 mac80211_vap_cleanup wpa_supplicant "$(uci -q -P /var/state get wireless._${phy}.splist)"
1155 mac80211_vap_cleanup none "$(uci -q -P /var/state get wireless._${phy}.umlist)"
1156 sleep 2
1157 mac80211_iw_interface_add "$phy" "${NEWAPLIST%% *}" __ap
1158 for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
1159 fi
1160 }
1161 fi
1162 if [ "$no_reload" != "0" ]; then
1163 add_ap=1
1164 ubus wait_for hostapd
1165 local hostapd_res="$(ubus call hostapd config_add "{\"iface\":\"$primary_ap\", \"config\":\"${hostapd_conf_file}\"}")"
1166 ret="$?"
1167 [ "$ret" != 0 -o -z "$hostapd_res" ] && {
1168 wireless_setup_failed HOSTAPD_START_FAILED
1169 return
1170 }
1171 wireless_add_process "$(jsonfilter -s "$hostapd_res" -l 1 -e @.pid)" "/usr/sbin/hostapd" 1 1
1172 fi
1173 }
1174 uci -q -P /var/state set wireless._${phy}.aplist="${NEWAPLIST}"
1175 uci -q -P /var/state set wireless._${phy}.md5="${NEW_MD5}"
1176
1177 [ "${add_ap}" = 1 ] && sleep 1
1178 for_each_interface "ap" mac80211_setup_vif
1179
1180 NEWSPLIST=
1181 NEWUMLIST=
1182
1183 for_each_interface "sta adhoc mesh monitor" mac80211_setup_vif
1184
1185 uci -q -P /var/state set wireless._${phy}.splist="${NEWSPLIST}"
1186 uci -q -P /var/state set wireless._${phy}.umlist="${NEWUMLIST}"
1187
1188 local foundvap
1189 local dropvap=""
1190 for oldvap in $OLDSPLIST; do
1191 foundvap=0
1192 for newvap in $NEWSPLIST; do
1193 [ "$oldvap" = "$newvap" ] && foundvap=1
1194 done
1195 [ "$foundvap" = "0" ] && dropvap="$dropvap $oldvap"
1196 done
1197 [ -n "$dropvap" ] && mac80211_vap_cleanup wpa_supplicant "$dropvap"
1198 wireless_set_up
1199 }
1200
1201 _list_phy_interfaces() {
1202 local phy="$1"
1203 if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
1204 ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
1205 else
1206 ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g'
1207 fi
1208 }
1209
1210 list_phy_interfaces() {
1211 local phy="$1"
1212
1213 for dev in $(_list_phy_interfaces "$phy"); do
1214 readlink "/sys/class/net/${dev}/phy80211" | grep -q "/${phy}\$" || continue
1215 echo "$dev"
1216 done
1217 }
1218
1219 drv_mac80211_teardown() {
1220 json_select data
1221 json_get_vars phy
1222 json_select ..
1223 [ -n "$phy" ] || {
1224 echo "Bug: PHY is undefined for device '$1'"
1225 return 1
1226 }
1227
1228 mac80211_interface_cleanup "$phy"
1229 uci -q -P /var/state revert wireless._${phy}
1230 }
1231
1232 add_driver mac80211