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