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