ath10k-firmware: update qca9984 firmware
[openwrt/openwrt.git] / package / network / services / hostapd / files / netifd.sh
1 . /lib/functions/network.sh
2
3 wpa_supplicant_add_rate() {
4 local var="$1"
5 local val="$(($2 / 1000))"
6 local sub="$((($2 / 100) % 10))"
7 append $var "$val" ","
8 [ $sub -gt 0 ] && append $var "."
9 }
10
11 hostapd_add_rate() {
12 local var="$1"
13 local val="$(($2 / 100))"
14 append $var "$val" " "
15 }
16
17 hostapd_append_wep_key() {
18 local var="$1"
19
20 wep_keyidx=0
21 set_default key 1
22 case "$key" in
23 [1234])
24 for idx in 1 2 3 4; do
25 local zidx
26 zidx=$(($idx - 1))
27 json_get_var ckey "key${idx}"
28 [ -n "$ckey" ] && \
29 append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T"
30 done
31 wep_keyidx=$((key - 1))
32 ;;
33 *)
34 append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T"
35 ;;
36 esac
37 }
38
39 hostapd_append_wpa_key_mgmt() {
40 local auth_type="$(echo $auth_type | tr 'a-z' 'A-Z')"
41
42 append wpa_key_mgmt "WPA-$auth_type"
43 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type}"
44 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type}-SHA256"
45 }
46
47 hostapd_add_log_config() {
48 config_add_boolean \
49 log_80211 \
50 log_8021x \
51 log_radius \
52 log_wpa \
53 log_driver \
54 log_iapp \
55 log_mlme
56
57 config_add_int log_level
58 }
59
60 hostapd_common_add_device_config() {
61 config_add_array basic_rate
62 config_add_array supported_rates
63
64 config_add_string country
65 config_add_boolean country_ie doth
66 config_add_string require_mode
67
68 hostapd_add_log_config
69 }
70
71 hostapd_prepare_device_config() {
72 local config="$1"
73 local driver="$2"
74
75 local base="${config%%.conf}"
76 local base_cfg=
77
78 json_get_vars country country_ie beacon_int doth require_mode
79
80 hostapd_set_log_options base_cfg
81
82 set_default country_ie 1
83 set_default doth 1
84
85 [ -n "$country" ] && {
86 append base_cfg "country_code=$country" "$N"
87
88 [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N"
89 [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N"
90 }
91 [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N"
92
93 local brlist= br
94 json_get_values basic_rate_list basic_rate
95 for br in $basic_rate_list; do
96 hostapd_add_rate brlist "$br"
97 done
98 case "$require_mode" in
99 g) brlist="60 120 240" ;;
100 n) append base_cfg "require_ht=1" "$N";;
101 ac) append base_cfg "require_vht=1" "$N";;
102 esac
103
104 local rlist= r
105 json_get_values rate_list supported_rates
106 for r in $rate_list; do
107 hostapd_add_rate rlist "$r"
108 done
109
110 [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N"
111 [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N"
112 [ -n "$beacon_int" ] && append base_cfg "beacon_int=$beacon_int" "$N"
113
114 cat > "$config" <<EOF
115 driver=$driver
116 $base_cfg
117 EOF
118 }
119
120 hostapd_common_add_bss_config() {
121 config_add_string 'bssid:macaddr' 'ssid:string'
122 config_add_boolean wds wmm uapsd hidden
123
124 config_add_int maxassoc max_inactivity
125 config_add_boolean disassoc_low_ack isolate short_preamble
126
127 config_add_int \
128 wep_rekey eap_reauth_period \
129 wpa_group_rekey wpa_pair_rekey wpa_master_rekey
130
131 config_add_boolean rsn_preauth auth_cache
132 config_add_int ieee80211w
133 config_add_int eapol_version
134
135 config_add_string 'auth_server:host' 'server:host'
136 config_add_string auth_secret
137 config_add_int 'auth_port:port' 'port:port'
138
139 config_add_string acct_server
140 config_add_string acct_secret
141 config_add_int acct_port
142
143 config_add_string dae_client
144 config_add_string dae_secret
145 config_add_int dae_port
146
147 config_add_string nasid
148 config_add_string ownip
149 config_add_string iapp_interface
150 config_add_string eap_type ca_cert client_cert identity anonymous_identity auth priv_key priv_key_pwd
151
152 config_add_int dynamic_vlan vlan_naming
153 config_add_string vlan_tagged_interface vlan_bridge
154 config_add_string vlan_file
155
156 config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey'
157
158 config_add_string wpa_psk_file
159
160 config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1
161 config_add_int wps_ap_setup_locked wps_independent
162 config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin
163
164 config_add_boolean ieee80211r pmk_r1_push
165 config_add_int r0_key_lifetime reassociation_deadline
166 config_add_string mobility_domain r1_key_holder
167 config_add_array r0kh r1kh
168
169 config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout
170
171 config_add_string macfilter 'macfile:file'
172 config_add_array 'maclist:list(macaddr)'
173
174 config_add_array bssid_blacklist
175 config_add_array bssid_whitelist
176
177 config_add_int mcast_rate
178 config_add_array basic_rate
179 config_add_array supported_rates
180 }
181
182 hostapd_set_bss_options() {
183 local var="$1"
184 local phy="$2"
185 local vif="$3"
186
187 wireless_vif_parse_encryption
188
189 local bss_conf
190 local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt
191
192 json_get_vars \
193 wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey \
194 maxassoc max_inactivity disassoc_low_ack isolate auth_cache \
195 wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 wps_ap_setup_locked \
196 wps_independent wps_device_type wps_device_name wps_manufacturer wps_pin \
197 macfilter ssid wmm uapsd hidden short_preamble rsn_preauth \
198 iapp_interface eapol_version acct_server acct_secret acct_port \
199 dynamic_vlan ieee80211w
200
201 set_default isolate 0
202 set_default maxassoc 0
203 set_default max_inactivity 0
204 set_default short_preamble 1
205 set_default disassoc_low_ack 1
206 set_default hidden 0
207 set_default wmm 1
208 set_default uapsd 1
209 set_default eapol_version 0
210 set_default acct_port 1813
211
212 append bss_conf "ctrl_interface=/var/run/hostapd"
213 if [ "$isolate" -gt 0 ]; then
214 append bss_conf "ap_isolate=$isolate" "$N"
215 fi
216 if [ "$maxassoc" -gt 0 ]; then
217 append bss_conf "max_num_sta=$maxassoc" "$N"
218 fi
219 if [ "$max_inactivity" -gt 0 ]; then
220 append bss_conf "ap_max_inactivity=$max_inactivity" "$N"
221 fi
222
223 append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N"
224 append bss_conf "preamble=$short_preamble" "$N"
225 append bss_conf "wmm_enabled=$wmm" "$N"
226 append bss_conf "ignore_broadcast_ssid=$hidden" "$N"
227 append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N"
228
229 [ "$wpa" -gt 0 ] && {
230 [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N"
231 [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
232 [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N"
233 }
234
235 [ -n "$acct_server" ] && {
236 append bss_conf "acct_server_addr=$acct_server" "$N"
237 append bss_conf "acct_server_port=$acct_port" "$N"
238 [ -n "$acct_secret" ] && \
239 append bss_conf "acct_server_shared_secret=$acct_secret" "$N"
240 }
241
242 local vlan_possible=""
243
244 case "$auth_type" in
245 none)
246 wps_possible=1
247 # Here we make the assumption that if we're in open mode
248 # with WPS enabled, we got to be in unconfigured state.
249 wps_not_configured=1
250 ;;
251 psk)
252 json_get_vars key wpa_psk_file
253 if [ ${#key} -lt 8 ]; then
254 wireless_setup_vif_failed INVALID_WPA_PSK
255 return 1
256 elif [ ${#key} -eq 64 ]; then
257 append bss_conf "wpa_psk=$key" "$N"
258 else
259 append bss_conf "wpa_passphrase=$key" "$N"
260 fi
261 [ -n "$wpa_psk_file" ] && {
262 [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file"
263 append bss_conf "wpa_psk_file=$wpa_psk_file" "$N"
264 }
265 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
266
267 wps_possible=1
268 ;;
269 eap)
270 json_get_vars \
271 auth_server auth_secret auth_port \
272 dae_client dae_secret dae_port \
273 ownip \
274 eap_reauth_period
275
276 # radius can provide VLAN ID for clients
277 vlan_possible=1
278
279 # legacy compatibility
280 [ -n "$auth_server" ] || json_get_var auth_server server
281 [ -n "$auth_port" ] || json_get_var auth_port port
282 [ -n "$auth_secret" ] || json_get_var auth_secret key
283
284 set_default auth_port 1812
285 set_default dae_port 3799
286
287
288 append bss_conf "auth_server_addr=$auth_server" "$N"
289 append bss_conf "auth_server_port=$auth_port" "$N"
290 append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
291
292 [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N"
293
294 [ -n "$dae_client" -a -n "$dae_secret" ] && {
295 append bss_conf "radius_das_port=$dae_port" "$N"
296 append bss_conf "radius_das_client=$dae_client $dae_secret" "$N"
297 }
298
299 [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N"
300 append bss_conf "eapol_key_index_workaround=1" "$N"
301 append bss_conf "ieee8021x=1" "$N"
302
303 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
304 ;;
305 wep)
306 local wep_keyidx=0
307 json_get_vars key
308 hostapd_append_wep_key bss_conf
309 append bss_conf "wep_default_key=$wep_keyidx" "$N"
310 [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N"
311 ;;
312 esac
313
314 local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open))
315 append bss_conf "auth_algs=${auth_algs:-1}" "$N"
316 append bss_conf "wpa=$wpa" "$N"
317 [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N"
318
319 set_default wps_pushbutton 0
320 set_default wps_label 0
321 set_default wps_pbc_in_m1 0
322
323 config_methods=
324 [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button
325 [ "$wps_label" -gt 0 ] && append config_methods label
326
327 [ -n "$wps_possible" -a -n "$config_methods" ] && {
328 set_default ext_registrar 0
329 set_default wps_device_type "6-0050F204-1"
330 set_default wps_device_name "Lede AP"
331 set_default wps_manufacturer "www.lede-project.org"
332 set_default wps_independent 1
333
334 wps_state=2
335 [ -n "$wps_configured" ] && wps_state=1
336
337 [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N"
338
339 append bss_conf "eap_server=1" "$N"
340 [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N"
341 append bss_conf "wps_state=$wps_state" "$N"
342 append bss_conf "device_type=$wps_device_type" "$N"
343 append bss_conf "device_name=$wps_device_name" "$N"
344 append bss_conf "manufacturer=$wps_manufacturer" "$N"
345 append bss_conf "config_methods=$config_methods" "$N"
346 append bss_conf "wps_independent=$wps_independent" "$N"
347 [ -n "$wps_ap_setup_locked" ] && append bss_conf "ap_setup_locked=$wps_ap_setup_locked" "$N"
348 [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N"
349 }
350
351 append bss_conf "ssid=$ssid" "$N"
352 [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge" "$N"
353 [ -n "$iapp_interface" ] && {
354 local ifname
355 network_get_device ifname "$iapp_interface" || ifname = "$iapp_interface"
356 append bss_conf "iapp_interface=$ifname" "$N"
357 }
358
359 if [ "$wpa" -ge "1" ]; then
360 json_get_vars nasid ieee80211r
361 set_default ieee80211r 0
362 [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N"
363
364 if [ "$ieee80211r" -gt "0" ]; then
365 json_get_vars mobility_domain r0_key_lifetime r1_key_holder \
366 reassociation_deadline pmk_r1_push
367 json_get_values r0kh r0kh
368 json_get_values r1kh r1kh
369
370 set_default mobility_domain "4f57"
371 set_default r0_key_lifetime 10000
372 set_default r1_key_holder "00004f577274"
373 set_default reassociation_deadline 1000
374 set_default pmk_r1_push 0
375
376 append bss_conf "mobility_domain=$mobility_domain" "$N"
377 append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N"
378 append bss_conf "r1_key_holder=$r1_key_holder" "$N"
379 append bss_conf "reassociation_deadline=$reassociation_deadline" "$N"
380 append bss_conf "pmk_r1_push=$pmk_r1_push" "$N"
381
382 for kh in $r0kh; do
383 append bss_conf "r0kh=${kh//,/ }" "$N"
384 done
385 for kh in $r1kh; do
386 append bss_conf "r1kh=${kh//,/ }" "$N"
387 done
388 fi
389
390 hostapd_append_wpa_key_mgmt
391 [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N"
392 fi
393
394 if [ "$wpa" -ge "2" ]; then
395 if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then
396 set_default auth_cache 1
397 append bss_conf "rsn_preauth=1" "$N"
398 append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N"
399 else
400 set_default auth_cache 0
401 fi
402
403 append bss_conf "okc=$auth_cache" "$N"
404 [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N"
405
406 # RSN -> allow management frame protection
407 case "$ieee80211w" in
408 [012])
409 json_get_vars ieee80211w_max_timeout ieee80211w_retry_timeout
410 append bss_conf "ieee80211w=$ieee80211w" "$N"
411 [ "$ieee80211w" -gt "0" ] && {
412 [ -n "$ieee80211w_max_timeout" ] && \
413 append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
414 [ -n "$ieee80211w_retry_timeout" ] && \
415 append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
416 }
417 ;;
418 esac
419 fi
420
421 _macfile="/var/run/hostapd-$ifname.maclist"
422 case "$macfilter" in
423 allow)
424 append bss_conf "macaddr_acl=1" "$N"
425 append bss_conf "accept_mac_file=$_macfile" "$N"
426 # accept_mac_file can be used to set MAC to VLAN ID mapping
427 vlan_possible=1
428 ;;
429 deny)
430 append bss_conf "macaddr_acl=0" "$N"
431 append bss_conf "deny_mac_file=$_macfile" "$N"
432 ;;
433 *)
434 _macfile=""
435 ;;
436 esac
437
438 [ -n "$_macfile" ] && {
439 json_get_vars macfile
440 json_get_values maclist maclist
441
442 rm -f "$_macfile"
443 (
444 for mac in $maclist; do
445 echo "$mac"
446 done
447 [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile"
448 ) > "$_macfile"
449 }
450
451 [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && {
452 json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file
453 set_default vlan_naming 1
454 append bss_conf "dynamic_vlan=$dynamic_vlan" "$N"
455 append bss_conf "vlan_naming=$vlan_naming" "$N"
456 [ -n "$vlan_bridge" ] && \
457 append bss_conf "vlan_bridge=$vlan_bridge" "$N"
458 [ -n "$vlan_tagged_interface" ] && \
459 append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N"
460 [ -n "$vlan_file" ] && {
461 [ -e "$vlan_file" ] || touch "$vlan_file"
462 append bss_conf "vlan_file=$vlan_file" "$N"
463 }
464 }
465
466 append "$var" "$bss_conf" "$N"
467 return 0
468 }
469
470 hostapd_set_log_options() {
471 local var="$1"
472
473 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
474 json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
475
476 set_default log_level 2
477 set_default log_80211 1
478 set_default log_8021x 1
479 set_default log_radius 1
480 set_default log_wpa 1
481 set_default log_driver 1
482 set_default log_iapp 1
483 set_default log_mlme 1
484
485 local log_mask=$(( \
486 ($log_80211 << 0) | \
487 ($log_8021x << 1) | \
488 ($log_radius << 2) | \
489 ($log_wpa << 3) | \
490 ($log_driver << 4) | \
491 ($log_iapp << 5) | \
492 ($log_mlme << 6) \
493 ))
494
495 append "$var" "logger_syslog=$log_mask" "$N"
496 append "$var" "logger_syslog_level=$log_level" "$N"
497 append "$var" "logger_stdout=$log_mask" "$N"
498 append "$var" "logger_stdout_level=$log_level" "$N"
499
500 return 0
501 }
502
503 _wpa_supplicant_common() {
504 local ifname="$1"
505
506 _rpath="/var/run/wpa_supplicant"
507 _config="${_rpath}-$ifname.conf"
508 }
509
510 wpa_supplicant_teardown_interface() {
511 _wpa_supplicant_common "$1"
512 rm -rf "$_rpath/$1" "$_config"
513 }
514
515 wpa_supplicant_prepare_interface() {
516 local ifname="$1"
517 _w_driver="$2"
518
519 _wpa_supplicant_common "$1"
520
521 json_get_vars mode wds
522
523 [ -n "$network_bridge" ] && {
524 fail=
525 case "$mode" in
526 adhoc)
527 fail=1
528 ;;
529 sta)
530 [ "$wds" = 1 ] || fail=1
531 ;;
532 esac
533
534 [ -n "$fail" ] && {
535 wireless_setup_vif_failed BRIDGE_NOT_ALLOWED
536 return 1
537 }
538 }
539
540 local ap_scan=
541
542 _w_mode="$mode"
543 _w_modestr=
544
545 [[ "$mode" = adhoc ]] && {
546 ap_scan="ap_scan=2"
547
548 _w_modestr="mode=1"
549 }
550
551 local country_str=
552 [ -n "$country" ] && {
553 country_str="country=$country"
554 }
555
556 wpa_supplicant_teardown_interface "$ifname"
557 cat > "$_config" <<EOF
558 $ap_scan
559 $country_str
560 EOF
561 return 0
562 }
563
564 wpa_supplicant_add_network() {
565 local ifname="$1"
566
567 _wpa_supplicant_common "$1"
568 wireless_vif_parse_encryption
569
570 json_get_vars \
571 ssid bssid key \
572 basic_rate mcast_rate \
573 ieee80211w ieee80211r
574
575 set_default ieee80211r 0
576
577 local key_mgmt='NONE'
578 local enc_str=
579 local network_data=
580 local T=" "
581
582 local scan_ssid="scan_ssid=1"
583 local freq wpa_key_mgmt
584
585 [[ "$_w_mode" = "adhoc" ]] && {
586 append network_data "mode=1" "$N$T"
587 [ -n "$channel" ] && {
588 freq="$(get_freq "$phy" "$channel")"
589 append network_data "fixed_freq=1" "$N$T"
590 append network_data "frequency=$freq" "$N$T"
591 }
592
593 scan_ssid="scan_ssid=0"
594
595 [ "$_w_driver" = "nl80211" ] || append wpa_key_mgmt "WPA-NONE"
596 }
597
598 [[ "$_w_mode" = "mesh" ]] && {
599 json_get_vars mesh_id
600 ssid="${mesh_id}"
601
602 append network_data "mode=5" "$N$T"
603 [ -n "$channel" ] && {
604 freq="$(get_freq "$phy" "$channel")"
605 append network_data "frequency=$freq" "$N$T"
606 }
607 append wpa_key_mgmt "SAE"
608 scan_ssid=""
609 }
610
611 [[ "$_w_mode" = "adhoc" -o "$_w_mode" = "mesh" ]] && append network_data "$_w_modestr" "$N$T"
612
613 case "$auth_type" in
614 none) ;;
615 wep)
616 local wep_keyidx=0
617 hostapd_append_wep_key network_data
618 append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T"
619 ;;
620 psk)
621 local passphrase
622
623 if [ "$_w_mode" != "mesh" ]; then
624 hostapd_append_wpa_key_mgmt
625 fi
626
627 key_mgmt="$wpa_key_mgmt"
628
629 if [ ${#key} -eq 64 ]; then
630 passphrase="psk=${key}"
631 else
632 passphrase="psk=\"${key}\""
633 fi
634 append network_data "$passphrase" "$N$T"
635 ;;
636 eap)
637 hostapd_append_wpa_key_mgmt
638 key_mgmt="$wpa_key_mgmt"
639
640 json_get_vars eap_type identity anonymous_identity ca_cert
641 [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T"
642 [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T"
643 [ -n "$anonymous_identity" ] && append network_data "anonymous_identity=\"$anonymous_identity\"" "$N$T"
644 case "$eap_type" in
645 tls)
646 json_get_vars client_cert priv_key priv_key_pwd
647 append network_data "client_cert=\"$client_cert\"" "$N$T"
648 append network_data "private_key=\"$priv_key\"" "$N$T"
649 append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T"
650 ;;
651 fast|peap|ttls)
652 json_get_vars auth password ca_cert2 client_cert2 priv_key2 priv_key2_pwd
653 set_default auth MSCHAPV2
654
655 if [ "$auth" = "EAP-TLS" ]; then
656 [ -n "$ca_cert2" ] &&
657 append network_data "ca_cert2=\"$ca_cert2\"" "$N$T"
658 append network_data "client_cert2=\"$client_cert2\"" "$N$T"
659 append network_data "private_key2=\"$priv_key2\"" "$N$T"
660 append network_data "private_key2_passwd=\"$priv_key2_pwd\"" "$N$T"
661 else
662 append network_data "password=\"$password\"" "$N$T"
663 fi
664
665 phase2proto="auth="
666 case "$auth" in
667 "auth"*)
668 phase2proto=""
669 ;;
670 "EAP-"*)
671 auth="$(echo $auth | cut -b 5- )"
672 [ "$eap_type" = "ttls" ] &&
673 phase2proto="autheap="
674 ;;
675 esac
676 append network_data "phase2=\"$phase2proto$auth\"" "$N$T"
677 ;;
678 esac
679 append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T"
680 ;;
681 esac
682
683 [ "$mode" = mesh ] || {
684 case "$wpa" in
685 1)
686 append network_data "proto=WPA" "$N$T"
687 ;;
688 2)
689 append network_data "proto=RSN" "$N$T"
690 ;;
691 esac
692
693 case "$ieee80211w" in
694 [012])
695 [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T"
696 ;;
697 esac
698 }
699 local beacon_int brates mrate
700 [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T"
701 [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T"
702
703 local bssid_blacklist bssid_whitelist
704 json_get_values bssid_blacklist bssid_blacklist
705 json_get_values bssid_whitelist bssid_whitelist
706
707 [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T"
708 [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T"
709
710 [ -n "$basic_rate" ] && {
711 local br rate_list=
712 for br in $basic_rate; do
713 wpa_supplicant_add_rate rate_list "$br"
714 done
715 [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T"
716 }
717
718 [ -n "$mcast_rate" ] && {
719 local mc_rate=
720 wpa_supplicant_add_rate mc_rate "$mcast_rate"
721 append network_data "mcast_rate=$mc_rate" "$N$T"
722 }
723
724 local ht_str
725 [[ "$_w_mode" = adhoc ]] || ibss_htmode=
726 [ -n "$ibss_htmode" ] && append network_data "htmode=$ibss_htmode" "$N$T"
727
728 cat >> "$_config" <<EOF
729 network={
730 $scan_ssid
731 ssid="$ssid"
732 key_mgmt=$key_mgmt
733 $network_data
734 }
735 EOF
736 return 0
737 }
738
739 wpa_supplicant_run() {
740 local ifname="$1"; shift
741
742 _wpa_supplicant_common "$ifname"
743
744 /usr/sbin/wpa_supplicant -B \
745 ${network_bridge:+-b $network_bridge} \
746 -P "/var/run/wpa_supplicant-${ifname}.pid" \
747 -D ${_w_driver:-wext} \
748 -i "$ifname" \
749 -c "$_config" \
750 -C "$_rpath" \
751 "$@"
752
753 ret="$?"
754 wireless_add_process "$(cat "/var/run/wpa_supplicant-${ifname}.pid")" /usr/sbin/wpa_supplicant 1
755
756 [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
757
758 return $ret
759 }
760
761 hostapd_common_cleanup() {
762 killall hostapd wpa_supplicant meshd-nl80211
763 }