3290358ed21ea571ac7b7683f6900b749064b1b9
[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
629 set_default ieee80211k 0
630 if [ "$ieee80211k" -eq "1" ]; then
631 json_get_vars rrm_neighbor_report rrm_beacon_report
632
633 set_default rrm_neighbor_report 1
634 set_default rrm_beacon_report 1
635 append bss_conf "rrm_neighbor_report=$rrm_neighbor_report" "$N"
636 append bss_conf "rrm_beacon_report=$rrm_beacon_report" "$N"
637 fi
638
639 if [ "$wpa" -ge "1" ]; then
640 json_get_vars ieee80211r
641 set_default ieee80211r 0
642
643 if [ "$ieee80211r" -gt "0" ]; then
644 json_get_vars mobility_domain ft_psk_generate_local ft_over_ds reassociation_deadline
645
646 set_default mobility_domain "$(echo "$ssid" | md5sum | head -c 4)"
647 set_default ft_over_ds 1
648 set_default reassociation_deadline 1000
649
650 case "$auth_type" in
651 psk|sae|psk-sae)
652 set_default ft_psk_generate_local 1
653 ;;
654 *)
655 set_default ft_psk_generate_local 0
656 ;;
657 esac
658
659 append bss_conf "mobility_domain=$mobility_domain" "$N"
660 append bss_conf "ft_psk_generate_local=$ft_psk_generate_local" "$N"
661 append bss_conf "ft_over_ds=$ft_over_ds" "$N"
662 append bss_conf "reassociation_deadline=$reassociation_deadline" "$N"
663 [ -n "$nasid" ] || append bss_conf "nas_identifier=${macaddr//\:}" "$N"
664
665 if [ "$ft_psk_generate_local" -eq "0" ]; then
666 json_get_vars r0_key_lifetime r1_key_holder pmk_r1_push
667 json_get_values r0kh r0kh
668 json_get_values r1kh r1kh
669
670 set_default r0_key_lifetime 10000
671 set_default pmk_r1_push 0
672
673 [ -n "$r1_key_holder" ] && append bss_conf "r1_key_holder=$r1_key_holder" "$N"
674 append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N"
675 append bss_conf "pmk_r1_push=$pmk_r1_push" "$N"
676
677 for kh in $r0kh; do
678 append bss_conf "r0kh=${kh//,/ }" "$N"
679 done
680 for kh in $r1kh; do
681 append bss_conf "r1kh=${kh//,/ }" "$N"
682 done
683 fi
684 fi
685
686 append bss_conf "wpa_disable_eapol_key_retries=$wpa_disable_eapol_key_retries" "$N"
687
688 hostapd_append_wpa_key_mgmt
689 [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N"
690 fi
691
692 if [ "$wpa" -ge "2" ]; then
693 if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then
694 set_default auth_cache 1
695 append bss_conf "rsn_preauth=1" "$N"
696 append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N"
697 else
698 case "$auth_type" in
699 sae|psk-sae|owe)
700 set_default auth_cache 1
701 ;;
702 *)
703 set_default auth_cache 0
704 ;;
705 esac
706 fi
707
708 append bss_conf "okc=$auth_cache" "$N"
709 [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N"
710
711 # RSN -> allow management frame protection
712 case "$ieee80211w" in
713 [012])
714 json_get_vars ieee80211w_mgmt_cipher ieee80211w_max_timeout ieee80211w_retry_timeout
715 append bss_conf "ieee80211w=$ieee80211w" "$N"
716 [ "$ieee80211w" -gt "0" ] && {
717 append bss_conf "group_mgmt_cipher=${ieee80211w_mgmt_cipher:-AES-128-CMAC}" "$N"
718 [ -n "$ieee80211w_max_timeout" ] && \
719 append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
720 [ -n "$ieee80211w_retry_timeout" ] && \
721 append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
722 }
723 ;;
724 esac
725 fi
726
727 _macfile="/var/run/hostapd-$ifname.maclist"
728 case "$macfilter" in
729 allow)
730 append bss_conf "macaddr_acl=1" "$N"
731 append bss_conf "accept_mac_file=$_macfile" "$N"
732 # accept_mac_file can be used to set MAC to VLAN ID mapping
733 vlan_possible=1
734 ;;
735 deny)
736 append bss_conf "macaddr_acl=0" "$N"
737 append bss_conf "deny_mac_file=$_macfile" "$N"
738 ;;
739 *)
740 _macfile=""
741 ;;
742 esac
743
744 [ -n "$_macfile" ] && {
745 json_get_vars macfile
746 json_get_values maclist maclist
747
748 rm -f "$_macfile"
749 (
750 for mac in $maclist; do
751 echo "$mac"
752 done
753 [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile"
754 ) > "$_macfile"
755 }
756
757 [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && {
758 json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file
759 set_default vlan_naming 1
760 [ -z "$vlan_file" ] && set_default vlan_file /var/run/hostapd-$ifname.vlan
761 append bss_conf "dynamic_vlan=$dynamic_vlan" "$N"
762 append bss_conf "vlan_naming=$vlan_naming" "$N"
763 [ -n "$vlan_bridge" ] && \
764 append bss_conf "vlan_bridge=$vlan_bridge" "$N"
765 [ -n "$vlan_tagged_interface" ] && \
766 append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N"
767 [ -n "$vlan_file" ] && {
768 [ -e "$vlan_file" ] || touch "$vlan_file"
769 append bss_conf "vlan_file=$vlan_file" "$N"
770 }
771 }
772
773 local hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
774 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
775 json_get_vars hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
776 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
777
778 set_default hs20 0
779 set_default disable_dgaf $hs20
780 set_default osen 0
781 set_default anqp_domain_id 0
782 set_default hs20_deauth_req_timeout 60
783 if [ "$hs20" = "1" ]; then
784 append bss_conf "hs20=1" "$N"
785 append_hs20_icons
786 append bss_conf "disable_dgaf=$disable_dgaf" "$N"
787 append bss_conf "osen=$osen" "$N"
788 append bss_conf "anqp_domain_id=$anqp_domain_id" "$N"
789 append bss_conf "hs20_deauth_req_timeout=$hs20_deauth_req_timeout" "$N"
790 [ -n "$osu_ssid" ] && append bss_conf "osu_ssid=$osu_ssid" "$N"
791 [ -n "$hs20_wan_metrics" ] && append bss_conf "hs20_wan_metrics=$hs20_wan_metrics" "$N"
792 [ -n "$hs20_operating_class" ] && append bss_conf "hs20_operating_class=$hs20_operating_class" "$N"
793 [ -n "$hs20_t_c_filename" ] && append bss_conf "hs20_t_c_filename=$hs20_t_c_filename" "$N"
794 [ -n "$hs20_t_c_timestamp" ] && append bss_conf "hs20_t_c_timestamp=$hs20_t_c_timestamp" "$N"
795 json_for_each_item append_hs20_conn_capab hs20_conn_capab
796 json_for_each_item append_hs20_oper_friendly_name hs20_oper_friendly_name
797 json_for_each_item append_osu_provider osu_provider
798 json_for_each_item append_operator_icon operator_icon
799 fi
800
801 bss_md5sum=$(echo $bss_conf | md5sum | cut -d" " -f1)
802 append bss_conf "config_id=$bss_md5sum" "$N"
803
804 append "$var" "$bss_conf" "$N"
805 return 0
806 }
807
808 hostapd_set_log_options() {
809 local var="$1"
810
811 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
812 json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
813
814 set_default log_level 2
815 set_default log_80211 1
816 set_default log_8021x 1
817 set_default log_radius 1
818 set_default log_wpa 1
819 set_default log_driver 1
820 set_default log_iapp 1
821 set_default log_mlme 1
822
823 local log_mask=$(( \
824 ($log_80211 << 0) | \
825 ($log_8021x << 1) | \
826 ($log_radius << 2) | \
827 ($log_wpa << 3) | \
828 ($log_driver << 4) | \
829 ($log_iapp << 5) | \
830 ($log_mlme << 6) \
831 ))
832
833 append "$var" "logger_syslog=$log_mask" "$N"
834 append "$var" "logger_syslog_level=$log_level" "$N"
835 append "$var" "logger_stdout=$log_mask" "$N"
836 append "$var" "logger_stdout_level=$log_level" "$N"
837
838 return 0
839 }
840
841 _wpa_supplicant_common() {
842 local ifname="$1"
843
844 _rpath="/var/run/wpa_supplicant"
845 _config="${_rpath}-$ifname.conf"
846 }
847
848 wpa_supplicant_teardown_interface() {
849 _wpa_supplicant_common "$1"
850 rm -rf "$_rpath/$1" "$_config"
851 }
852
853 wpa_supplicant_prepare_interface() {
854 local ifname="$1"
855 _w_driver="$2"
856
857 _wpa_supplicant_common "$1"
858
859 json_get_vars mode wds multi_ap
860
861 [ -n "$network_bridge" ] && {
862 fail=
863 case "$mode" in
864 adhoc)
865 fail=1
866 ;;
867 sta)
868 [ "$wds" = 1 -o "$multi_ap" = 1 ] || fail=1
869 ;;
870 esac
871
872 [ -n "$fail" ] && {
873 wireless_setup_vif_failed BRIDGE_NOT_ALLOWED
874 return 1
875 }
876 }
877
878 local ap_scan=
879
880 _w_mode="$mode"
881
882 [ "$mode" = adhoc ] && {
883 ap_scan="ap_scan=2"
884 }
885
886 local country_str=
887 [ -n "$country" ] && {
888 country_str="country=$country"
889 }
890
891 multiap_flag_file="${_config}.is_multiap"
892 if [ "$multi_ap" = "1" ]; then
893 touch "$multiap_flag_file"
894 else
895 [ -e "$multiap_flag_file" ] && rm "$multiap_flag_file"
896 fi
897 wpa_supplicant_teardown_interface "$ifname"
898 cat > "$_config" <<EOF
899 ${scan_list:+freq_list=$scan_list}
900 $ap_scan
901 $country_str
902 EOF
903 return 0
904 }
905
906 wpa_supplicant_set_fixed_freq() {
907 local freq="$1"
908 local htmode="$2"
909
910 append network_data "fixed_freq=1" "$N$T"
911 append network_data "frequency=$freq" "$N$T"
912 case "$htmode" in
913 NOHT) append network_data "disable_ht=1" "$N$T";;
914 HT20|VHT20) append network_data "disable_ht40=1" "$N$T";;
915 HT40*|VHT40*|VHT80*|VHT160*) append network_data "ht40=1" "$N$T";;
916 esac
917 case "$htmode" in
918 VHT*) append network_data "vht=1" "$N$T";;
919 esac
920 case "$htmode" in
921 VHT80) append network_data "max_oper_chwidth=1" "$N$T";;
922 VHT160) append network_data "max_oper_chwidth=2" "$N$T";;
923 VHT20|VHT40) append network_data "max_oper_chwidth=0" "$N$T";;
924 *) append network_data "disable_vht=1" "$N$T";;
925 esac
926 }
927
928 wpa_supplicant_add_network() {
929 local ifname="$1"
930 local freq="$2"
931 local htmode="$3"
932 local noscan="$4"
933
934 _wpa_supplicant_common "$1"
935 wireless_vif_parse_encryption
936
937 json_get_vars \
938 ssid bssid key \
939 basic_rate mcast_rate \
940 ieee80211w ieee80211r \
941 multi_ap
942
943 case "$auth_type" in
944 sae|owe|eap192|eap-eap192)
945 set_default ieee80211w 2
946 ;;
947 psk-sae)
948 set_default ieee80211w 1
949 ;;
950 esac
951
952 set_default ieee80211r 0
953 set_default multi_ap 0
954
955 local key_mgmt='NONE'
956 local enc_str=
957 local network_data=
958 local T=" "
959
960 local scan_ssid="scan_ssid=1"
961 local freq wpa_key_mgmt
962
963 [ "$_w_mode" = "adhoc" ] && {
964 append network_data "mode=1" "$N$T"
965 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
966 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
967
968 scan_ssid="scan_ssid=0"
969
970 [ "$_w_driver" = "nl80211" ] || append wpa_key_mgmt "WPA-NONE"
971 }
972
973 [ "$_w_mode" = "mesh" ] && {
974 json_get_vars mesh_id mesh_fwding mesh_rssi_threshold
975 [ -n "$mesh_id" ] && ssid="${mesh_id}"
976
977 append network_data "mode=5" "$N$T"
978 [ -n "$mesh_fwding" ] && append network_data "mesh_fwding=${mesh_fwding}" "$N$T"
979 [ -n "$mesh_rssi_threshold" ] && append network_data "mesh_rssi_threshold=${mesh_rssi_threshold}" "$N$T"
980 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
981 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
982 append wpa_key_mgmt "SAE"
983 scan_ssid=""
984 }
985
986 [ "$multi_ap" = 1 -a "$_w_mode" = "sta" ] && append network_data "multi_ap_backhaul_sta=1" "$N$T"
987
988 case "$auth_type" in
989 none) ;;
990 owe)
991 hostapd_append_wpa_key_mgmt
992 key_mgmt="$wpa_key_mgmt"
993 ;;
994 wep)
995 local wep_keyidx=0
996 hostapd_append_wep_key network_data
997 append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T"
998 ;;
999 wps)
1000 key_mgmt='WPS'
1001 ;;
1002 psk|sae|psk-sae)
1003 local passphrase
1004
1005 if [ "$_w_mode" != "mesh" ]; then
1006 hostapd_append_wpa_key_mgmt
1007 fi
1008
1009 key_mgmt="$wpa_key_mgmt"
1010
1011 if [ ${#key} -eq 64 ]; then
1012 passphrase="psk=${key}"
1013 else
1014 if [ "$_w_mode" = "mesh" ]; then
1015 passphrase="sae_password=\"${key}\""
1016 else
1017 passphrase="psk=\"${key}\""
1018 fi
1019 fi
1020 append network_data "$passphrase" "$N$T"
1021 ;;
1022 eap|eap192|eap-eap192)
1023 hostapd_append_wpa_key_mgmt
1024 key_mgmt="$wpa_key_mgmt"
1025
1026 json_get_vars eap_type identity anonymous_identity ca_cert ca_cert_usesystem
1027
1028 if [ "$ca_cert_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1029 append network_data "ca_cert=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1030 else
1031 [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T"
1032 fi
1033 [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T"
1034 [ -n "$anonymous_identity" ] && append network_data "anonymous_identity=\"$anonymous_identity\"" "$N$T"
1035 case "$eap_type" in
1036 tls)
1037 json_get_vars client_cert priv_key priv_key_pwd
1038 append network_data "client_cert=\"$client_cert\"" "$N$T"
1039 append network_data "private_key=\"$priv_key\"" "$N$T"
1040 append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T"
1041
1042 json_get_vars subject_match
1043 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1044
1045 json_get_values altsubject_match altsubject_match
1046 if [ -n "$altsubject_match" ]; then
1047 local list=
1048 for x in $altsubject_match; do
1049 append list "$x" ";"
1050 done
1051 append network_data "altsubject_match=\"$list\"" "$N$T"
1052 fi
1053
1054 json_get_values domain_match domain_match
1055 if [ -n "$domain_match" ]; then
1056 local list=
1057 for x in $domain_match; do
1058 append list "$x" ";"
1059 done
1060 append network_data "domain_match=\"$list\"" "$N$T"
1061 fi
1062
1063 json_get_values domain_suffix_match domain_suffix_match
1064 if [ -n "$domain_suffix_match" ]; then
1065 local list=
1066 for x in $domain_suffix_match; do
1067 append list "$x" ";"
1068 done
1069 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1070 fi
1071 ;;
1072 fast|peap|ttls)
1073 json_get_vars auth password ca_cert2 ca_cert2_usesystem client_cert2 priv_key2 priv_key2_pwd
1074 set_default auth MSCHAPV2
1075
1076 if [ "$auth" = "EAP-TLS" ]; then
1077 if [ "$ca_cert2_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1078 append network_data "ca_cert2=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1079 else
1080 [ -n "$ca_cert2" ] && append network_data "ca_cert2=\"$ca_cert2\"" "$N$T"
1081 fi
1082 append network_data "client_cert2=\"$client_cert2\"" "$N$T"
1083 append network_data "private_key2=\"$priv_key2\"" "$N$T"
1084 append network_data "private_key2_passwd=\"$priv_key2_pwd\"" "$N$T"
1085 else
1086 append network_data "password=\"$password\"" "$N$T"
1087 fi
1088
1089 json_get_vars subject_match
1090 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1091
1092 json_get_values altsubject_match altsubject_match
1093 if [ -n "$altsubject_match" ]; then
1094 local list=
1095 for x in $altsubject_match; do
1096 append list "$x" ";"
1097 done
1098 append network_data "altsubject_match=\"$list\"" "$N$T"
1099 fi
1100
1101 json_get_values domain_match domain_match
1102 if [ -n "$domain_match" ]; then
1103 local list=
1104 for x in $domain_match; do
1105 append list "$x" ";"
1106 done
1107 append network_data "domain_match=\"$list\"" "$N$T"
1108 fi
1109
1110 json_get_values domain_suffix_match domain_suffix_match
1111 if [ -n "$domain_suffix_match" ]; then
1112 local list=
1113 for x in $domain_suffix_match; do
1114 append list "$x" ";"
1115 done
1116 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1117 fi
1118
1119 phase2proto="auth="
1120 case "$auth" in
1121 "auth"*)
1122 phase2proto=""
1123 ;;
1124 "EAP-"*)
1125 auth="$(echo $auth | cut -b 5- )"
1126 [ "$eap_type" = "ttls" ] &&
1127 phase2proto="autheap="
1128 json_get_vars subject_match2
1129 [ -n "$subject_match2" ] && append network_data "subject_match2=\"$subject_match2\"" "$N$T"
1130
1131 json_get_values altsubject_match2 altsubject_match2
1132 if [ -n "$altsubject_match2" ]; then
1133 local list=
1134 for x in $altsubject_match2; do
1135 append list "$x" ";"
1136 done
1137 append network_data "altsubject_match2=\"$list\"" "$N$T"
1138 fi
1139
1140 json_get_values domain_match2 domain_match2
1141 if [ -n "$domain_match2" ]; then
1142 local list=
1143 for x in $domain_match2; do
1144 append list "$x" ";"
1145 done
1146 append network_data "domain_match2=\"$list\"" "$N$T"
1147 fi
1148
1149 json_get_values domain_suffix_match2 domain_suffix_match2
1150 if [ -n "$domain_suffix_match2" ]; then
1151 local list=
1152 for x in $domain_suffix_match2; do
1153 append list "$x" ";"
1154 done
1155 append network_data "domain_suffix_match2=\"$list\"" "$N$T"
1156 fi
1157 ;;
1158 esac
1159 append network_data "phase2=\"$phase2proto$auth\"" "$N$T"
1160 ;;
1161 esac
1162 append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T"
1163 ;;
1164 esac
1165
1166 [ "$mode" = mesh ] || {
1167 case "$wpa" in
1168 1)
1169 append network_data "proto=WPA" "$N$T"
1170 ;;
1171 2)
1172 append network_data "proto=RSN" "$N$T"
1173 ;;
1174 esac
1175
1176 case "$ieee80211w" in
1177 [012])
1178 [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T"
1179 ;;
1180 esac
1181 }
1182 [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T"
1183 [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T"
1184
1185 local bssid_blacklist bssid_whitelist
1186 json_get_values bssid_blacklist bssid_blacklist
1187 json_get_values bssid_whitelist bssid_whitelist
1188
1189 [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T"
1190 [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T"
1191
1192 [ -n "$basic_rate" ] && {
1193 local br rate_list=
1194 for br in $basic_rate; do
1195 wpa_supplicant_add_rate rate_list "$br"
1196 done
1197 [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T"
1198 }
1199
1200 [ -n "$mcast_rate" ] && {
1201 local mc_rate=
1202 wpa_supplicant_add_rate mc_rate "$mcast_rate"
1203 append network_data "mcast_rate=$mc_rate" "$N$T"
1204 }
1205
1206 if [ "$key_mgnt" = "WPS" ]; then
1207 echo "wps_cred_processing=1" >> "$_config"
1208 else
1209 cat >> "$_config" <<EOF
1210 network={
1211 $scan_ssid
1212 ssid="$ssid"
1213 key_mgmt=$key_mgmt
1214 $network_data
1215 }
1216 EOF
1217 fi
1218 return 0
1219 }
1220
1221 wpa_supplicant_run() {
1222 local ifname="$1"
1223 local hostapd_ctrl="$2"
1224
1225 _wpa_supplicant_common "$ifname"
1226
1227 ubus wait_for wpa_supplicant
1228 ubus call wpa_supplicant config_add "{ \
1229 \"driver\": \"${_w_driver:-wext}\", \"ctrl\": \"$_rpath\", \
1230 \"iface\": \"$ifname\", \"config\": \"$_config\" \
1231 ${network_bridge:+, \"bridge\": \"$network_bridge\"} \
1232 ${hostapd_ctrl:+, \"hostapd_ctrl\": \"$hostapd_ctrl\"} \
1233 }"
1234
1235 ret="$?"
1236
1237 [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
1238
1239 local supplicant_pid=$(ubus call service list '{"name": "wpad"}' | jsonfilter -l 1 -e "@['wpad'].instances['supplicant'].pid")
1240 wireless_add_process "$supplicant_pid" "/usr/sbin/wpa_supplicant" 1
1241
1242 return $ret
1243 }
1244
1245 hostapd_common_cleanup() {
1246 killall meshd-nl80211
1247 }