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