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