hostapd: make rrm report independent of ieee80211k setting
[openwrt/openwrt.git] / package / network / services / hostapd / files / hostapd.sh
1 . /lib/functions/network.sh
2 . /lib/functions.sh
3
4 wpa_supplicant_add_rate() {
5 local var="$1"
6 local val="$(($2 / 1000))"
7 local sub="$((($2 / 100) % 10))"
8 append $var "$val" ","
9 [ $sub -gt 0 ] && append $var "."
10 }
11
12 hostapd_add_rate() {
13 local var="$1"
14 local val="$(($2 / 100))"
15 append $var "$val" " "
16 }
17
18 hostapd_append_wep_key() {
19 local var="$1"
20
21 wep_keyidx=0
22 set_default key 1
23 case "$key" in
24 [1234])
25 for idx in 1 2 3 4; do
26 local zidx
27 zidx=$(($idx - 1))
28 json_get_var ckey "key${idx}"
29 [ -n "$ckey" ] && \
30 append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T"
31 done
32 wep_keyidx=$((key - 1))
33 ;;
34 *)
35 append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T"
36 ;;
37 esac
38 }
39
40 hostapd_append_wpa_key_mgmt() {
41 local auth_type_l="$(echo $auth_type | tr 'a-z' 'A-Z')"
42
43 case "$auth_type" in
44 psk|eap)
45 append wpa_key_mgmt "WPA-$auth_type_l"
46 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type_l}"
47 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type_l}-SHA256"
48 ;;
49 eap192)
50 append wpa_key_mgmt "WPA-EAP-SUITE-B-192"
51 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP"
52 ;;
53 eap-eap192)
54 append wpa_key_mgmt "WPA-EAP-SUITE-B-192"
55 append wpa_key_mgmt "WPA-EAP"
56 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP"
57 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-EAP-SHA256"
58 ;;
59 sae)
60 append wpa_key_mgmt "SAE"
61 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE"
62 ;;
63 psk-sae)
64 append wpa_key_mgmt "WPA-PSK"
65 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-PSK"
66 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-PSK-SHA256"
67 append wpa_key_mgmt "SAE"
68 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE"
69 ;;
70 owe)
71 append wpa_key_mgmt "OWE"
72 ;;
73 esac
74
75 [ "$auth_osen" = "1" ] && append wpa_key_mgmt "OSEN"
76 }
77
78 hostapd_add_log_config() {
79 config_add_boolean \
80 log_80211 \
81 log_8021x \
82 log_radius \
83 log_wpa \
84 log_driver \
85 log_iapp \
86 log_mlme
87
88 config_add_int log_level
89 }
90
91 hostapd_common_add_device_config() {
92 config_add_array basic_rate
93 config_add_array supported_rates
94
95 config_add_string country
96 config_add_boolean country_ie doth
97 config_add_boolean spectrum_mgmt_required
98 config_add_int local_pwr_constraint
99 config_add_string require_mode
100 config_add_boolean legacy_rates
101
102 config_add_string acs_chan_bias
103 config_add_array hostapd_options
104
105 hostapd_add_log_config
106 }
107
108 hostapd_prepare_device_config() {
109 local config="$1"
110 local driver="$2"
111
112 local base="${config%%.conf}"
113 local base_cfg=
114
115 json_get_vars country country_ie beacon_int:100 dtim_period:2 doth require_mode legacy_rates \
116 acs_chan_bias local_pwr_constraint spectrum_mgmt_required airtime_mode
117
118 hostapd_set_log_options base_cfg
119
120 set_default country_ie 1
121 set_default spectrum_mgmt_required 0
122 set_default doth 1
123 set_default legacy_rates 1
124 set_default airtime_mode 0
125
126 [ "$hwmode" = "b" ] && legacy_rates=1
127
128 [ -n "$country" ] && {
129 append base_cfg "country_code=$country" "$N"
130
131 [ "$country_ie" -gt 0 ] && {
132 append base_cfg "ieee80211d=1" "$N"
133 [ -n "$local_pwr_constraint" ] && append base_cfg "local_pwr_constraint=$local_pwr_constraint" "$N"
134 [ "$spectrum_mgmt_required" -gt 0 ] && append base_cfg "spectrum_mgmt_required=$spectrum_mgmt_required" "$N"
135 }
136 [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N"
137 }
138
139 [ -n "$acs_chan_bias" ] && append base_cfg "acs_chan_bias=$acs_chan_bias" "$N"
140
141 local brlist= br
142 json_get_values basic_rate_list basic_rate
143 local rlist= r
144 json_get_values rate_list supported_rates
145
146 [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N"
147 [ "$legacy_rates" -eq 0 ] && set_default require_mode g
148
149 [ "$hwmode" = "g" ] && {
150 [ "$legacy_rates" -eq 0 ] && set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000"
151 [ -n "$require_mode" ] && set_default basic_rate_list "6000 12000 24000"
152 }
153
154 case "$require_mode" in
155 n) append base_cfg "require_ht=1" "$N";;
156 ac) append base_cfg "require_vht=1" "$N";;
157 esac
158
159 for r in $rate_list; do
160 hostapd_add_rate rlist "$r"
161 done
162
163 for br in $basic_rate_list; do
164 hostapd_add_rate brlist "$br"
165 done
166
167 [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N"
168 [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N"
169 append base_cfg "beacon_int=$beacon_int" "$N"
170 append base_cfg "dtim_period=$dtim_period" "$N"
171 [ "$airtime_mode" -gt 0 ] && append base_cfg "airtime_mode=$airtime_mode" "$N"
172
173 json_get_values opts hostapd_options
174 for val in $opts; do
175 append base_cfg "$val" "$N"
176 done
177
178 cat > "$config" <<EOF
179 driver=$driver
180 $base_cfg
181 EOF
182 }
183
184 hostapd_common_add_bss_config() {
185 config_add_string 'bssid:macaddr' 'ssid:string'
186 config_add_boolean wds wmm uapsd hidden utf8_ssid
187
188 config_add_int maxassoc max_inactivity
189 config_add_boolean disassoc_low_ack isolate short_preamble
190
191 config_add_int \
192 wep_rekey eap_reauth_period \
193 wpa_group_rekey wpa_pair_rekey wpa_master_rekey
194 config_add_boolean wpa_strict_rekey
195 config_add_boolean wpa_disable_eapol_key_retries
196
197 config_add_boolean tdls_prohibit
198
199 config_add_boolean rsn_preauth auth_cache
200 config_add_int ieee80211w
201 config_add_int eapol_version
202
203 config_add_string 'auth_server:host' 'server:host'
204 config_add_string auth_secret key
205 config_add_int 'auth_port:port' 'port:port'
206
207 config_add_string acct_server
208 config_add_string acct_secret
209 config_add_int acct_port
210 config_add_int acct_interval
211
212 config_add_string dae_client
213 config_add_string dae_secret
214 config_add_int dae_port
215
216 config_add_string nasid
217 config_add_string ownip
218 config_add_string radius_client_addr
219 config_add_string iapp_interface
220 config_add_string eap_type ca_cert client_cert identity anonymous_identity auth priv_key priv_key_pwd
221 config_add_boolean ca_cert_usesystem ca_cert2_usesystem
222 config_add_string subject_match subject_match2
223 config_add_array altsubject_match altsubject_match2
224 config_add_array domain_match domain_match2 domain_suffix_match domain_suffix_match2
225 config_add_string ieee80211w_mgmt_cipher
226
227 config_add_int dynamic_vlan vlan_naming
228 config_add_string vlan_tagged_interface vlan_bridge
229 config_add_string vlan_file
230
231 config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey'
232
233 config_add_string wpa_psk_file
234
235 config_add_int multi_ap
236
237 config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1
238 config_add_int wps_ap_setup_locked wps_independent
239 config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin
240 config_add_string multi_ap_backhaul_ssid multi_ap_backhaul_key
241
242 config_add_boolean ieee80211v wnm_sleep_mode bss_transition
243 config_add_int time_advertisement
244 config_add_string time_zone
245
246 config_add_boolean ieee80211k rrm_neighbor_report rrm_beacon_report
247
248 config_add_boolean ieee80211r pmk_r1_push ft_psk_generate_local ft_over_ds
249 config_add_int r0_key_lifetime reassociation_deadline
250 config_add_string mobility_domain r1_key_holder
251 config_add_array r0kh r1kh
252
253 config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout
254
255 config_add_string macfilter 'macfile:file'
256 config_add_array 'maclist:list(macaddr)'
257
258 config_add_array bssid_blacklist
259 config_add_array bssid_whitelist
260
261 config_add_int mcast_rate
262 config_add_array basic_rate
263 config_add_array supported_rates
264
265 config_add_boolean sae_require_mfp
266
267 config_add_string 'owe_transition_bssid:macaddr' 'owe_transition_ssid:string'
268
269 config_add_boolean hs20 disable_dgaf osen
270 config_add_int anqp_domain_id
271 config_add_int hs20_deauth_req_timeout
272 config_add_array hs20_oper_friendly_name
273 config_add_array osu_provider
274 config_add_array operator_icon
275 config_add_array hs20_conn_capab
276 config_add_string osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
277
278 config_add_int airtime_bss_weight airtime_bss_limit
279 }
280
281 hostapd_set_vlan_file() {
282 local ifname="$1"
283 local vlan="$2"
284 json_get_vars name vid
285 echo "${vid} ${ifname}-${name}" >> /var/run/hostapd-${ifname}.vlan
286 wireless_add_vlan "${vlan}" "${ifname}-${name}"
287 }
288
289 hostapd_set_vlan() {
290 local ifname="$1"
291
292 rm -f /var/run/hostapd-${ifname}.vlan
293 for_each_vlan hostapd_set_vlan_file ${ifname}
294 }
295
296 hostapd_set_psk_file() {
297 local ifname="$1"
298 local vlan="$2"
299 local vlan_id=""
300
301 json_get_vars mac vid key
302 set_default mac "00:00:00:00:00:00"
303 [ -n "$vid" ] && vlan_id="vlanid=$vid "
304 echo "${vlan_id} ${mac} ${key}" >> /var/run/hostapd-${ifname}.psk
305 }
306
307 hostapd_set_psk() {
308 local ifname="$1"
309
310 rm -f /var/run/hostapd-${ifname}.psk
311 for_each_station hostapd_set_psk_file ${ifname}
312 }
313
314 append_hs20_oper_friendly_name() {
315 append bss_conf "hs20_oper_friendly_name=$1" "$N"
316 }
317
318 append_osu_provider_service_desc() {
319 append bss_conf "osu_service_desc=$1" "$N"
320 }
321
322 append_hs20_icon() {
323 local width height lang type path
324 config_get width "$1" width
325 config_get height "$1" height
326 config_get lang "$1" lang
327 config_get type "$1" type
328 config_get path "$1" path
329
330 append bss_conf "hs20_icon=$width:$height:$lang:$type:$1:$path" "$N"
331 }
332
333 append_hs20_icons() {
334 config_load wireless
335 config_foreach append_hs20_icon hs20-icon
336 }
337
338 append_operator_icon() {
339 append bss_conf "operator_icon=$1" "$N"
340 }
341
342 append_osu_icon() {
343 append bss_conf "osu_icon=$1" "$N"
344 }
345
346 append_osu_provider() {
347 local cfgtype osu_server_uri osu_friendly_name osu_nai osu_nai2 osu_method_list
348
349 config_load wireless
350 config_get cfgtype "$1" TYPE
351 [ "$cfgtype" != "osu-provider" ] && return
352
353 append bss_conf "# provider $1" "$N"
354 config_get osu_server_uri "$1" osu_server_uri
355 config_get osu_nai "$1" osu_nai
356 config_get osu_nai2 "$1" osu_nai2
357 config_get osu_method_list "$1" osu_method
358
359 append bss_conf "osu_server_uri=$osu_server_uri" "$N"
360 append bss_conf "osu_nai=$osu_nai" "$N"
361 append bss_conf "osu_nai2=$osu_nai2" "$N"
362 append bss_conf "osu_method_list=$osu_method_list" "$N"
363
364 config_list_foreach "$1" osu_service_desc append_osu_provider_service_desc
365 config_list_foreach "$1" osu_icon append_osu_icon
366
367 append bss_conf "$N"
368 }
369
370 append_hs20_conn_capab() {
371 [ -n "$1" ] && append bss_conf "hs20_conn_capab=$1" "$N"
372 }
373
374 hostapd_set_bss_options() {
375 local var="$1"
376 local phy="$2"
377 local vif="$3"
378
379 wireless_vif_parse_encryption
380
381 local bss_conf bss_md5sum
382 local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt
383
384 json_get_vars \
385 wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_strict_rekey \
386 wpa_disable_eapol_key_retries tdls_prohibit \
387 maxassoc max_inactivity disassoc_low_ack isolate auth_cache \
388 wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 wps_ap_setup_locked \
389 wps_independent wps_device_type wps_device_name wps_manufacturer wps_pin \
390 macfilter ssid utf8_ssid wmm uapsd hidden short_preamble rsn_preauth \
391 iapp_interface eapol_version dynamic_vlan ieee80211w nasid \
392 acct_server acct_secret acct_port acct_interval \
393 bss_load_update_period chan_util_avg_period sae_require_mfp \
394 multi_ap multi_ap_backhaul_ssid multi_ap_backhaul_key \
395 airtime_bss_weight airtime_bss_limit
396
397 set_default isolate 0
398 set_default maxassoc 0
399 set_default max_inactivity 0
400 set_default short_preamble 1
401 set_default disassoc_low_ack 1
402 set_default hidden 0
403 set_default wmm 1
404 set_default uapsd 1
405 set_default wpa_disable_eapol_key_retries 0
406 set_default tdls_prohibit 0
407 set_default eapol_version 0
408 set_default acct_port 1813
409 set_default bss_load_update_period 60
410 set_default chan_util_avg_period 600
411 set_default utf8_ssid 1
412 set_default multi_ap 0
413 set_default airtime_bss_weight 0
414 set_default airtime_bss_limit 0
415
416 append bss_conf "ctrl_interface=/var/run/hostapd"
417 if [ "$isolate" -gt 0 ]; then
418 append bss_conf "ap_isolate=$isolate" "$N"
419 fi
420 if [ "$maxassoc" -gt 0 ]; then
421 append bss_conf "max_num_sta=$maxassoc" "$N"
422 fi
423 if [ "$max_inactivity" -gt 0 ]; then
424 append bss_conf "ap_max_inactivity=$max_inactivity" "$N"
425 fi
426
427 [ "$airtime_bss_weight" -gt 0 ] && append bss_conf "airtime_bss_weight=$airtime_bss_weight" "$N"
428 [ "$airtime_bss_limit" -gt 0 ] && append bss_conf "airtime_bss_limit=$airtime_bss_limit" "$N"
429
430 append bss_conf "bss_load_update_period=$bss_load_update_period" "$N"
431 append bss_conf "chan_util_avg_period=$chan_util_avg_period" "$N"
432 append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N"
433 append bss_conf "preamble=$short_preamble" "$N"
434 append bss_conf "wmm_enabled=$wmm" "$N"
435 append bss_conf "ignore_broadcast_ssid=$hidden" "$N"
436 append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N"
437 append bss_conf "utf8_ssid=$utf8_ssid" "$N"
438 append bss_conf "multi_ap=$multi_ap" "$N"
439
440 [ "$tdls_prohibit" -gt 0 ] && append bss_conf "tdls_prohibit=$tdls_prohibit" "$N"
441
442 [ "$wpa" -gt 0 ] && {
443 [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N"
444 [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
445 [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N"
446 [ -n "$wpa_strict_rekey" ] && append bss_conf "wpa_strict_rekey=$wpa_strict_rekey" "$N"
447 }
448
449 [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N"
450 [ -n "$acct_server" ] && {
451 append bss_conf "acct_server_addr=$acct_server" "$N"
452 append bss_conf "acct_server_port=$acct_port" "$N"
453 [ -n "$acct_secret" ] && \
454 append bss_conf "acct_server_shared_secret=$acct_secret" "$N"
455 [ -n "$acct_interval" ] && \
456 append bss_conf "radius_acct_interim_interval=$acct_interval" "$N"
457 }
458
459 case "$auth_type" in
460 sae|owe|eap192|eap-eap192)
461 set_default ieee80211w 2
462 set_default sae_require_mfp 1
463 ;;
464 psk-sae)
465 set_default ieee80211w 1
466 set_default sae_require_mfp 1
467 ;;
468 esac
469 [ -n "$sae_require_mfp" ] && append bss_conf "sae_require_mfp=$sae_require_mfp" "$N"
470
471 local vlan_possible=""
472
473 case "$auth_type" in
474 none|owe)
475 json_get_vars owe_transition_bssid owe_transition_ssid
476
477 [ -n "$owe_transition_ssid" ] && append bss_conf "owe_transition_ssid=\"$owe_transition_ssid\"" "$N"
478 [ -n "$owe_transition_bssid" ] && append bss_conf "owe_transition_bssid=$owe_transition_bssid" "$N"
479
480 wps_possible=1
481 # Here we make the assumption that if we're in open mode
482 # with WPS enabled, we got to be in unconfigured state.
483 wps_not_configured=1
484 ;;
485 psk|sae|psk-sae)
486 json_get_vars key wpa_psk_file
487 if [ ${#key} -eq 64 ]; then
488 append bss_conf "wpa_psk=$key" "$N"
489 elif [ ${#key} -ge 8 ] && [ ${#key} -le 63 ]; then
490 append bss_conf "wpa_passphrase=$key" "$N"
491 elif [ -n "$key" ] || [ -z "$wpa_psk_file" ]; then
492 wireless_setup_vif_failed INVALID_WPA_PSK
493 return 1
494 fi
495 [ -z "$wpa_psk_file" ] && set_default wpa_psk_file /var/run/hostapd-$ifname.psk
496 [ -n "$wpa_psk_file" ] && {
497 [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file"
498 append bss_conf "wpa_psk_file=$wpa_psk_file" "$N"
499 }
500 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
501
502 set_default dynamic_vlan 0
503 vlan_possible=1
504 wps_possible=1
505 ;;
506 eap|eap192|eap-eap192)
507 json_get_vars \
508 auth_server auth_secret auth_port \
509 dae_client dae_secret dae_port \
510 ownip radius_client_addr \
511 eap_reauth_period
512
513 # radius can provide VLAN ID for clients
514 vlan_possible=1
515
516 # legacy compatibility
517 [ -n "$auth_server" ] || json_get_var auth_server server
518 [ -n "$auth_port" ] || json_get_var auth_port port
519 [ -n "$auth_secret" ] || json_get_var auth_secret key
520
521 set_default auth_port 1812
522 set_default dae_port 3799
523
524
525 append bss_conf "auth_server_addr=$auth_server" "$N"
526 append bss_conf "auth_server_port=$auth_port" "$N"
527 append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
528
529 [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N"
530
531 [ -n "$dae_client" -a -n "$dae_secret" ] && {
532 append bss_conf "radius_das_port=$dae_port" "$N"
533 append bss_conf "radius_das_client=$dae_client $dae_secret" "$N"
534 }
535
536 [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N"
537 [ -n "$radius_client_addr" ] && append bss_conf "radius_client_addr=$radius_client_addr" "$N"
538 append bss_conf "eapol_key_index_workaround=1" "$N"
539 append bss_conf "ieee8021x=1" "$N"
540
541 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
542 ;;
543 wep)
544 local wep_keyidx=0
545 json_get_vars key
546 hostapd_append_wep_key bss_conf
547 append bss_conf "wep_default_key=$wep_keyidx" "$N"
548 [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N"
549 ;;
550 esac
551
552 local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open))
553 append bss_conf "auth_algs=${auth_algs:-1}" "$N"
554 append bss_conf "wpa=$wpa" "$N"
555 [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N"
556
557 set_default wps_pushbutton 0
558 set_default wps_label 0
559 set_default wps_pbc_in_m1 0
560
561 config_methods=
562 [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button
563 [ "$wps_label" -gt 0 ] && append config_methods label
564
565 # WPS not possible on Multi-AP backhaul-only SSID
566 [ "$multi_ap" = 1 ] && wps_possible=
567
568 [ -n "$wps_possible" -a -n "$config_methods" ] && {
569 set_default ext_registrar 0
570 set_default wps_device_type "6-0050F204-1"
571 set_default wps_device_name "OpenWrt AP"
572 set_default wps_manufacturer "www.openwrt.org"
573 set_default wps_independent 1
574
575 wps_state=2
576 [ -n "$wps_configured" ] && wps_state=1
577
578 [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N"
579
580 append bss_conf "eap_server=1" "$N"
581 [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N"
582 append bss_conf "wps_state=$wps_state" "$N"
583 append bss_conf "device_type=$wps_device_type" "$N"
584 append bss_conf "device_name=$wps_device_name" "$N"
585 append bss_conf "manufacturer=$wps_manufacturer" "$N"
586 append bss_conf "config_methods=$config_methods" "$N"
587 append bss_conf "wps_independent=$wps_independent" "$N"
588 [ -n "$wps_ap_setup_locked" ] && append bss_conf "ap_setup_locked=$wps_ap_setup_locked" "$N"
589 [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N"
590 [ "$multi_ap" -gt 0 ] && [ -n "$multi_ap_backhaul_ssid" ] && {
591 append bss_conf "multi_ap_backhaul_ssid=\"$multi_ap_backhaul_ssid\"" "$N"
592 if [ -z "$multi_ap_backhaul_key" ]; then
593 :
594 elif [ ${#multi_ap_backhaul_key} -lt 8 ]; then
595 wireless_setup_vif_failed INVALID_WPA_PSK
596 return 1
597 elif [ ${#multi_ap_backhaul_key} -eq 64 ]; then
598 append bss_conf "multi_ap_backhaul_wpa_psk=$multi_ap_backhaul_key" "$N"
599 else
600 append bss_conf "multi_ap_backhaul_wpa_passphrase=$multi_ap_backhaul_key" "$N"
601 fi
602 }
603 }
604
605 append bss_conf "ssid=$ssid" "$N"
606 [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge" "$N"
607 [ -n "$iapp_interface" ] && {
608 local ifname
609 network_get_device ifname "$iapp_interface" || ifname="$iapp_interface"
610 append bss_conf "iapp_interface=$ifname" "$N"
611 }
612
613 json_get_vars ieee80211v
614 set_default ieee80211v 0
615 if [ "$ieee80211v" -eq "1" ]; then
616 json_get_vars time_advertisement time_zone wnm_sleep_mode bss_transition
617
618 set_default time_advertisement 0
619 set_default wnm_sleep_mode 0
620 set_default bss_transition 0
621
622 append bss_conf "time_advertisement=$time_advertisement" "$N"
623 [ -n "$time_zone" ] && append bss_conf "time_zone=$time_zone" "$N"
624 append bss_conf "wnm_sleep_mode=$wnm_sleep_mode" "$N"
625 append bss_conf "bss_transition=$bss_transition" "$N"
626 fi
627
628 json_get_vars ieee80211k rrm_neighbor_report rrm_beacon_report
629 set_default ieee80211k 0
630 if [ "$ieee80211k" -eq "1" ]; then
631 set_default rrm_neighbor_report 1
632 set_default rrm_beacon_report 1
633 fi
634
635 [ "$rrm_neighbor_report" -eq "1" ] && append bss_conf "rrm_neighbor_report=1" "$N"
636 [ "$rrm_beacon_report" -eq "1" ] && append bss_conf "rrm_beacon_report=1" "$N"
637
638 if [ "$wpa" -ge "1" ]; then
639 json_get_vars ieee80211r
640 set_default ieee80211r 0
641
642 if [ "$ieee80211r" -gt "0" ]; then
643 json_get_vars mobility_domain ft_psk_generate_local ft_over_ds reassociation_deadline
644
645 set_default mobility_domain "$(echo "$ssid" | md5sum | head -c 4)"
646 set_default ft_over_ds 1
647 set_default reassociation_deadline 1000
648
649 case "$auth_type" in
650 psk|sae|psk-sae)
651 set_default ft_psk_generate_local 1
652 ;;
653 *)
654 set_default ft_psk_generate_local 0
655 ;;
656 esac
657
658 append bss_conf "mobility_domain=$mobility_domain" "$N"
659 append bss_conf "ft_psk_generate_local=$ft_psk_generate_local" "$N"
660 append bss_conf "ft_over_ds=$ft_over_ds" "$N"
661 append bss_conf "reassociation_deadline=$reassociation_deadline" "$N"
662 [ -n "$nasid" ] || append bss_conf "nas_identifier=${macaddr//\:}" "$N"
663
664 if [ "$ft_psk_generate_local" -eq "0" ]; then
665 json_get_vars r0_key_lifetime r1_key_holder pmk_r1_push
666 json_get_values r0kh r0kh
667 json_get_values r1kh r1kh
668
669 set_default r0_key_lifetime 10000
670 set_default pmk_r1_push 0
671
672 [ -n "$r1_key_holder" ] && append bss_conf "r1_key_holder=$r1_key_holder" "$N"
673 append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N"
674 append bss_conf "pmk_r1_push=$pmk_r1_push" "$N"
675
676 for kh in $r0kh; do
677 append bss_conf "r0kh=${kh//,/ }" "$N"
678 done
679 for kh in $r1kh; do
680 append bss_conf "r1kh=${kh//,/ }" "$N"
681 done
682 fi
683 fi
684
685 append bss_conf "wpa_disable_eapol_key_retries=$wpa_disable_eapol_key_retries" "$N"
686
687 hostapd_append_wpa_key_mgmt
688 [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N"
689 fi
690
691 if [ "$wpa" -ge "2" ]; then
692 if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then
693 set_default auth_cache 1
694 append bss_conf "rsn_preauth=1" "$N"
695 append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N"
696 else
697 case "$auth_type" in
698 sae|psk-sae|owe)
699 set_default auth_cache 1
700 ;;
701 *)
702 set_default auth_cache 0
703 ;;
704 esac
705 fi
706
707 append bss_conf "okc=$auth_cache" "$N"
708 [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N"
709
710 # RSN -> allow management frame protection
711 case "$ieee80211w" in
712 [012])
713 json_get_vars ieee80211w_mgmt_cipher ieee80211w_max_timeout ieee80211w_retry_timeout
714 append bss_conf "ieee80211w=$ieee80211w" "$N"
715 [ "$ieee80211w" -gt "0" ] && {
716 append bss_conf "group_mgmt_cipher=${ieee80211w_mgmt_cipher:-AES-128-CMAC}" "$N"
717 [ -n "$ieee80211w_max_timeout" ] && \
718 append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
719 [ -n "$ieee80211w_retry_timeout" ] && \
720 append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
721 }
722 ;;
723 esac
724 fi
725
726 _macfile="/var/run/hostapd-$ifname.maclist"
727 case "$macfilter" in
728 allow)
729 append bss_conf "macaddr_acl=1" "$N"
730 append bss_conf "accept_mac_file=$_macfile" "$N"
731 # accept_mac_file can be used to set MAC to VLAN ID mapping
732 vlan_possible=1
733 ;;
734 deny)
735 append bss_conf "macaddr_acl=0" "$N"
736 append bss_conf "deny_mac_file=$_macfile" "$N"
737 ;;
738 *)
739 _macfile=""
740 ;;
741 esac
742
743 [ -n "$_macfile" ] && {
744 json_get_vars macfile
745 json_get_values maclist maclist
746
747 rm -f "$_macfile"
748 (
749 for mac in $maclist; do
750 echo "$mac"
751 done
752 [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile"
753 ) > "$_macfile"
754 }
755
756 [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && {
757 json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file
758 set_default vlan_naming 1
759 [ -z "$vlan_file" ] && set_default vlan_file /var/run/hostapd-$ifname.vlan
760 append bss_conf "dynamic_vlan=$dynamic_vlan" "$N"
761 append bss_conf "vlan_naming=$vlan_naming" "$N"
762 [ -n "$vlan_bridge" ] && \
763 append bss_conf "vlan_bridge=$vlan_bridge" "$N"
764 [ -n "$vlan_tagged_interface" ] && \
765 append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N"
766 [ -n "$vlan_file" ] && {
767 [ -e "$vlan_file" ] || touch "$vlan_file"
768 append bss_conf "vlan_file=$vlan_file" "$N"
769 }
770 }
771
772 local hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
773 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
774 json_get_vars hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
775 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
776
777 set_default hs20 0
778 set_default disable_dgaf $hs20
779 set_default osen 0
780 set_default anqp_domain_id 0
781 set_default hs20_deauth_req_timeout 60
782 if [ "$hs20" = "1" ]; then
783 append bss_conf "hs20=1" "$N"
784 append_hs20_icons
785 append bss_conf "disable_dgaf=$disable_dgaf" "$N"
786 append bss_conf "osen=$osen" "$N"
787 append bss_conf "anqp_domain_id=$anqp_domain_id" "$N"
788 append bss_conf "hs20_deauth_req_timeout=$hs20_deauth_req_timeout" "$N"
789 [ -n "$osu_ssid" ] && append bss_conf "osu_ssid=$osu_ssid" "$N"
790 [ -n "$hs20_wan_metrics" ] && append bss_conf "hs20_wan_metrics=$hs20_wan_metrics" "$N"
791 [ -n "$hs20_operating_class" ] && append bss_conf "hs20_operating_class=$hs20_operating_class" "$N"
792 [ -n "$hs20_t_c_filename" ] && append bss_conf "hs20_t_c_filename=$hs20_t_c_filename" "$N"
793 [ -n "$hs20_t_c_timestamp" ] && append bss_conf "hs20_t_c_timestamp=$hs20_t_c_timestamp" "$N"
794 json_for_each_item append_hs20_conn_capab hs20_conn_capab
795 json_for_each_item append_hs20_oper_friendly_name hs20_oper_friendly_name
796 json_for_each_item append_osu_provider osu_provider
797 json_for_each_item append_operator_icon operator_icon
798 fi
799
800 bss_md5sum=$(echo $bss_conf | md5sum | cut -d" " -f1)
801 append bss_conf "config_id=$bss_md5sum" "$N"
802
803 append "$var" "$bss_conf" "$N"
804 return 0
805 }
806
807 hostapd_set_log_options() {
808 local var="$1"
809
810 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
811 json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
812
813 set_default log_level 2
814 set_default log_80211 1
815 set_default log_8021x 1
816 set_default log_radius 1
817 set_default log_wpa 1
818 set_default log_driver 1
819 set_default log_iapp 1
820 set_default log_mlme 1
821
822 local log_mask=$(( \
823 ($log_80211 << 0) | \
824 ($log_8021x << 1) | \
825 ($log_radius << 2) | \
826 ($log_wpa << 3) | \
827 ($log_driver << 4) | \
828 ($log_iapp << 5) | \
829 ($log_mlme << 6) \
830 ))
831
832 append "$var" "logger_syslog=$log_mask" "$N"
833 append "$var" "logger_syslog_level=$log_level" "$N"
834 append "$var" "logger_stdout=$log_mask" "$N"
835 append "$var" "logger_stdout_level=$log_level" "$N"
836
837 return 0
838 }
839
840 _wpa_supplicant_common() {
841 local ifname="$1"
842
843 _rpath="/var/run/wpa_supplicant"
844 _config="${_rpath}-$ifname.conf"
845 }
846
847 wpa_supplicant_teardown_interface() {
848 _wpa_supplicant_common "$1"
849 rm -rf "$_rpath/$1" "$_config"
850 }
851
852 wpa_supplicant_prepare_interface() {
853 local ifname="$1"
854 _w_driver="$2"
855
856 _wpa_supplicant_common "$1"
857
858 json_get_vars mode wds multi_ap
859
860 [ -n "$network_bridge" ] && {
861 fail=
862 case "$mode" in
863 adhoc)
864 fail=1
865 ;;
866 sta)
867 [ "$wds" = 1 -o "$multi_ap" = 1 ] || fail=1
868 ;;
869 esac
870
871 [ -n "$fail" ] && {
872 wireless_setup_vif_failed BRIDGE_NOT_ALLOWED
873 return 1
874 }
875 }
876
877 local ap_scan=
878
879 _w_mode="$mode"
880
881 [ "$mode" = adhoc ] && {
882 ap_scan="ap_scan=2"
883 }
884
885 local country_str=
886 [ -n "$country" ] && {
887 country_str="country=$country"
888 }
889
890 multiap_flag_file="${_config}.is_multiap"
891 if [ "$multi_ap" = "1" ]; then
892 touch "$multiap_flag_file"
893 else
894 [ -e "$multiap_flag_file" ] && rm "$multiap_flag_file"
895 fi
896 wpa_supplicant_teardown_interface "$ifname"
897 cat > "$_config" <<EOF
898 ${scan_list:+freq_list=$scan_list}
899 $ap_scan
900 $country_str
901 EOF
902 return 0
903 }
904
905 wpa_supplicant_set_fixed_freq() {
906 local freq="$1"
907 local htmode="$2"
908
909 append network_data "fixed_freq=1" "$N$T"
910 append network_data "frequency=$freq" "$N$T"
911 case "$htmode" in
912 NOHT) append network_data "disable_ht=1" "$N$T";;
913 HT20|VHT20) append network_data "disable_ht40=1" "$N$T";;
914 HT40*|VHT40*|VHT80*|VHT160*) append network_data "ht40=1" "$N$T";;
915 esac
916 case "$htmode" in
917 VHT*) append network_data "vht=1" "$N$T";;
918 esac
919 case "$htmode" in
920 VHT80) append network_data "max_oper_chwidth=1" "$N$T";;
921 VHT160) append network_data "max_oper_chwidth=2" "$N$T";;
922 VHT20|VHT40) append network_data "max_oper_chwidth=0" "$N$T";;
923 *) append network_data "disable_vht=1" "$N$T";;
924 esac
925 }
926
927 wpa_supplicant_add_network() {
928 local ifname="$1"
929 local freq="$2"
930 local htmode="$3"
931 local noscan="$4"
932
933 _wpa_supplicant_common "$1"
934 wireless_vif_parse_encryption
935
936 json_get_vars \
937 ssid bssid key \
938 basic_rate mcast_rate \
939 ieee80211w ieee80211r \
940 multi_ap
941
942 case "$auth_type" in
943 sae|owe|eap192|eap-eap192)
944 set_default ieee80211w 2
945 ;;
946 psk-sae)
947 set_default ieee80211w 1
948 ;;
949 esac
950
951 set_default ieee80211r 0
952 set_default multi_ap 0
953
954 local key_mgmt='NONE'
955 local enc_str=
956 local network_data=
957 local T=" "
958
959 local scan_ssid="scan_ssid=1"
960 local freq wpa_key_mgmt
961
962 [ "$_w_mode" = "adhoc" ] && {
963 append network_data "mode=1" "$N$T"
964 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
965 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
966
967 scan_ssid="scan_ssid=0"
968
969 [ "$_w_driver" = "nl80211" ] || append wpa_key_mgmt "WPA-NONE"
970 }
971
972 [ "$_w_mode" = "mesh" ] && {
973 json_get_vars mesh_id mesh_fwding mesh_rssi_threshold
974 [ -n "$mesh_id" ] && ssid="${mesh_id}"
975
976 append network_data "mode=5" "$N$T"
977 [ -n "$mesh_fwding" ] && append network_data "mesh_fwding=${mesh_fwding}" "$N$T"
978 [ -n "$mesh_rssi_threshold" ] && append network_data "mesh_rssi_threshold=${mesh_rssi_threshold}" "$N$T"
979 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
980 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
981 append wpa_key_mgmt "SAE"
982 scan_ssid=""
983 }
984
985 [ "$multi_ap" = 1 -a "$_w_mode" = "sta" ] && append network_data "multi_ap_backhaul_sta=1" "$N$T"
986
987 case "$auth_type" in
988 none) ;;
989 owe)
990 hostapd_append_wpa_key_mgmt
991 key_mgmt="$wpa_key_mgmt"
992 ;;
993 wep)
994 local wep_keyidx=0
995 hostapd_append_wep_key network_data
996 append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T"
997 ;;
998 wps)
999 key_mgmt='WPS'
1000 ;;
1001 psk|sae|psk-sae)
1002 local passphrase
1003
1004 if [ "$_w_mode" != "mesh" ]; then
1005 hostapd_append_wpa_key_mgmt
1006 fi
1007
1008 key_mgmt="$wpa_key_mgmt"
1009
1010 if [ ${#key} -eq 64 ]; then
1011 passphrase="psk=${key}"
1012 else
1013 if [ "$_w_mode" = "mesh" ]; then
1014 passphrase="sae_password=\"${key}\""
1015 else
1016 passphrase="psk=\"${key}\""
1017 fi
1018 fi
1019 append network_data "$passphrase" "$N$T"
1020 ;;
1021 eap|eap192|eap-eap192)
1022 hostapd_append_wpa_key_mgmt
1023 key_mgmt="$wpa_key_mgmt"
1024
1025 json_get_vars eap_type identity anonymous_identity ca_cert ca_cert_usesystem
1026
1027 if [ "$ca_cert_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1028 append network_data "ca_cert=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1029 else
1030 [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T"
1031 fi
1032 [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T"
1033 [ -n "$anonymous_identity" ] && append network_data "anonymous_identity=\"$anonymous_identity\"" "$N$T"
1034 case "$eap_type" in
1035 tls)
1036 json_get_vars client_cert priv_key priv_key_pwd
1037 append network_data "client_cert=\"$client_cert\"" "$N$T"
1038 append network_data "private_key=\"$priv_key\"" "$N$T"
1039 append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T"
1040
1041 json_get_vars subject_match
1042 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1043
1044 json_get_values altsubject_match altsubject_match
1045 if [ -n "$altsubject_match" ]; then
1046 local list=
1047 for x in $altsubject_match; do
1048 append list "$x" ";"
1049 done
1050 append network_data "altsubject_match=\"$list\"" "$N$T"
1051 fi
1052
1053 json_get_values domain_match domain_match
1054 if [ -n "$domain_match" ]; then
1055 local list=
1056 for x in $domain_match; do
1057 append list "$x" ";"
1058 done
1059 append network_data "domain_match=\"$list\"" "$N$T"
1060 fi
1061
1062 json_get_values domain_suffix_match domain_suffix_match
1063 if [ -n "$domain_suffix_match" ]; then
1064 local list=
1065 for x in $domain_suffix_match; do
1066 append list "$x" ";"
1067 done
1068 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1069 fi
1070 ;;
1071 fast|peap|ttls)
1072 json_get_vars auth password ca_cert2 ca_cert2_usesystem client_cert2 priv_key2 priv_key2_pwd
1073 set_default auth MSCHAPV2
1074
1075 if [ "$auth" = "EAP-TLS" ]; then
1076 if [ "$ca_cert2_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1077 append network_data "ca_cert2=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1078 else
1079 [ -n "$ca_cert2" ] && append network_data "ca_cert2=\"$ca_cert2\"" "$N$T"
1080 fi
1081 append network_data "client_cert2=\"$client_cert2\"" "$N$T"
1082 append network_data "private_key2=\"$priv_key2\"" "$N$T"
1083 append network_data "private_key2_passwd=\"$priv_key2_pwd\"" "$N$T"
1084 else
1085 append network_data "password=\"$password\"" "$N$T"
1086 fi
1087
1088 json_get_vars subject_match
1089 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1090
1091 json_get_values altsubject_match altsubject_match
1092 if [ -n "$altsubject_match" ]; then
1093 local list=
1094 for x in $altsubject_match; do
1095 append list "$x" ";"
1096 done
1097 append network_data "altsubject_match=\"$list\"" "$N$T"
1098 fi
1099
1100 json_get_values domain_match domain_match
1101 if [ -n "$domain_match" ]; then
1102 local list=
1103 for x in $domain_match; do
1104 append list "$x" ";"
1105 done
1106 append network_data "domain_match=\"$list\"" "$N$T"
1107 fi
1108
1109 json_get_values domain_suffix_match domain_suffix_match
1110 if [ -n "$domain_suffix_match" ]; then
1111 local list=
1112 for x in $domain_suffix_match; do
1113 append list "$x" ";"
1114 done
1115 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1116 fi
1117
1118 phase2proto="auth="
1119 case "$auth" in
1120 "auth"*)
1121 phase2proto=""
1122 ;;
1123 "EAP-"*)
1124 auth="$(echo $auth | cut -b 5- )"
1125 [ "$eap_type" = "ttls" ] &&
1126 phase2proto="autheap="
1127 json_get_vars subject_match2
1128 [ -n "$subject_match2" ] && append network_data "subject_match2=\"$subject_match2\"" "$N$T"
1129
1130 json_get_values altsubject_match2 altsubject_match2
1131 if [ -n "$altsubject_match2" ]; then
1132 local list=
1133 for x in $altsubject_match2; do
1134 append list "$x" ";"
1135 done
1136 append network_data "altsubject_match2=\"$list\"" "$N$T"
1137 fi
1138
1139 json_get_values domain_match2 domain_match2
1140 if [ -n "$domain_match2" ]; then
1141 local list=
1142 for x in $domain_match2; do
1143 append list "$x" ";"
1144 done
1145 append network_data "domain_match2=\"$list\"" "$N$T"
1146 fi
1147
1148 json_get_values domain_suffix_match2 domain_suffix_match2
1149 if [ -n "$domain_suffix_match2" ]; then
1150 local list=
1151 for x in $domain_suffix_match2; do
1152 append list "$x" ";"
1153 done
1154 append network_data "domain_suffix_match2=\"$list\"" "$N$T"
1155 fi
1156 ;;
1157 esac
1158 append network_data "phase2=\"$phase2proto$auth\"" "$N$T"
1159 ;;
1160 esac
1161 append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T"
1162 ;;
1163 esac
1164
1165 [ "$mode" = mesh ] || {
1166 case "$wpa" in
1167 1)
1168 append network_data "proto=WPA" "$N$T"
1169 ;;
1170 2)
1171 append network_data "proto=RSN" "$N$T"
1172 ;;
1173 esac
1174
1175 case "$ieee80211w" in
1176 [012])
1177 [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T"
1178 ;;
1179 esac
1180 }
1181 [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T"
1182 [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T"
1183
1184 local bssid_blacklist bssid_whitelist
1185 json_get_values bssid_blacklist bssid_blacklist
1186 json_get_values bssid_whitelist bssid_whitelist
1187
1188 [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T"
1189 [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T"
1190
1191 [ -n "$basic_rate" ] && {
1192 local br rate_list=
1193 for br in $basic_rate; do
1194 wpa_supplicant_add_rate rate_list "$br"
1195 done
1196 [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T"
1197 }
1198
1199 [ -n "$mcast_rate" ] && {
1200 local mc_rate=
1201 wpa_supplicant_add_rate mc_rate "$mcast_rate"
1202 append network_data "mcast_rate=$mc_rate" "$N$T"
1203 }
1204
1205 if [ "$key_mgnt" = "WPS" ]; then
1206 echo "wps_cred_processing=1" >> "$_config"
1207 else
1208 cat >> "$_config" <<EOF
1209 network={
1210 $scan_ssid
1211 ssid="$ssid"
1212 key_mgmt=$key_mgmt
1213 $network_data
1214 }
1215 EOF
1216 fi
1217 return 0
1218 }
1219
1220 wpa_supplicant_run() {
1221 local ifname="$1"
1222 local hostapd_ctrl="$2"
1223
1224 _wpa_supplicant_common "$ifname"
1225
1226 ubus wait_for wpa_supplicant
1227 ubus call wpa_supplicant config_add "{ \
1228 \"driver\": \"${_w_driver:-wext}\", \"ctrl\": \"$_rpath\", \
1229 \"iface\": \"$ifname\", \"config\": \"$_config\" \
1230 ${network_bridge:+, \"bridge\": \"$network_bridge\"} \
1231 ${hostapd_ctrl:+, \"hostapd_ctrl\": \"$hostapd_ctrl\"} \
1232 }"
1233
1234 ret="$?"
1235
1236 [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
1237
1238 local supplicant_pid=$(ubus call service list '{"name": "wpad"}' | jsonfilter -l 1 -e "@['wpad'].instances['supplicant'].pid")
1239 wireless_add_process "$supplicant_pid" "/usr/sbin/wpa_supplicant" 1
1240
1241 return $ret
1242 }
1243
1244 hostapd_common_cleanup() {
1245 killall meshd-nl80211
1246 }