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