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