blob: 7eeb74e9846cacb605184bbede4f8b1154bb1dc8 [file] [log] [blame]
developer8556ff22022-11-10 11:58:51 +08001. /lib/functions/network.sh
2. /lib/functions.sh
3
4wpa_supplicant_add_rate() {
5 local var="$1"
6 local val="$(($2 / 1000))"
7 local sub="$((($2 / 100) % 10))"
8 append $var "$val" ","
9 [ $sub -gt 0 ] && append $var "."
10}
11
12hostapd_add_rate() {
13 local var="$1"
14 local val="$(($2 / 100))"
15 append $var "$val" " "
16}
17
18hostapd_append_wep_key() {
19 local var="$1"
20
21 wep_keyidx=0
22 set_default key 1
23 case "$key" in
24 [1234])
25 for idx in 1 2 3 4; do
26 local zidx
27 zidx=$(($idx - 1))
28 json_get_var ckey "key${idx}"
29 [ -n "$ckey" ] && \
30 append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T"
31 done
32 wep_keyidx=$((key - 1))
33 ;;
34 *)
35 append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T"
36 ;;
37 esac
38}
39
40hostapd_append_wpa_key_mgmt() {
41 local auth_type_l="$(echo $auth_type | tr 'a-z' 'A-Z')"
42
43 case "$auth_type" in
44 psk|eap)
45 append wpa_key_mgmt "WPA-$auth_type_l"
46 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type_l}"
47 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type_l}-SHA256"
48 ;;
49 eap192)
50 append wpa_key_mgmt "WPA-EAP-SUITE-B-192"
51 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP-SHA384"
52 ;;
53 eap-eap192)
54 append wpa_key_mgmt "WPA-EAP-SUITE-B-192"
55 append wpa_key_mgmt "WPA-EAP"
56 [ "${ieee80211r:-0}" -gt 0 ] && {
57 append wpa_key_mgmt "FT-EAP-SHA384"
58 append wpa_key_mgmt "FT-EAP"
59 }
60 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-EAP-SHA256"
61 ;;
62 sae)
63 append wpa_key_mgmt "SAE"
64 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE"
65 ;;
66 psk-sae)
67 append wpa_key_mgmt "WPA-PSK"
68 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-PSK"
69 [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-PSK-SHA256"
70 append wpa_key_mgmt "SAE"
71 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE"
72 ;;
73 owe)
74 append wpa_key_mgmt "OWE"
75 ;;
76 esac
77
78 [ "$fils" -gt 0 ] && {
79 case "$auth_type" in
80 eap*)
81 append wpa_key_mgmt FILS-SHA256
82 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt FT-FILS-SHA256
83 ;;
84 esac
85 }
86
87 [ "$auth_osen" = "1" ] && append wpa_key_mgmt "OSEN"
88}
89
90hostapd_add_log_config() {
91 config_add_boolean \
92 log_80211 \
93 log_8021x \
94 log_radius \
95 log_wpa \
96 log_driver \
97 log_iapp \
98 log_mlme
99
100 config_add_int log_level
101}
102
103hostapd_common_add_device_config() {
104 config_add_array basic_rate
105 config_add_array supported_rates
106 config_add_string beacon_rate
107
108 config_add_string country country3
109 config_add_boolean country_ie doth
110 config_add_boolean spectrum_mgmt_required
111 config_add_int local_pwr_constraint
112 config_add_string require_mode
113 config_add_boolean legacy_rates
114 config_add_int cell_density
115 config_add_int rts_threshold
116 config_add_int rssi_reject_assoc_rssi
117 config_add_int rssi_ignore_probe_request
118 config_add_int maxassoc
119
120 config_add_string acs_chan_bias
121 config_add_array hostapd_options
122
123 config_add_int airtime_mode
124
125 hostapd_add_log_config
126}
127
128hostapd_prepare_device_config() {
129 local config="$1"
130 local driver="$2"
131
132 local base_cfg=
133
134 json_get_vars country country3 country_ie beacon_int:100 dtim_period:2 doth require_mode legacy_rates \
135 acs_chan_bias local_pwr_constraint spectrum_mgmt_required airtime_mode cell_density \
136 rts_threshold beacon_rate rssi_reject_assoc_rssi rssi_ignore_probe_request maxassoc
137
138 hostapd_set_log_options base_cfg
139
140 set_default country_ie 1
141 set_default spectrum_mgmt_required 0
142 set_default doth 1
143 set_default legacy_rates 0
144 set_default airtime_mode 0
145 set_default cell_density 0
146
147 [ -n "$country" ] && {
148 append base_cfg "country_code=$country" "$N"
149 [ -n "$country3" ] && append base_cfg "country3=$country3" "$N"
150
151 [ "$country_ie" -gt 0 ] && {
152 append base_cfg "ieee80211d=1" "$N"
153 [ -n "$local_pwr_constraint" ] && append base_cfg "local_pwr_constraint=$local_pwr_constraint" "$N"
154 [ "$spectrum_mgmt_required" -gt 0 ] && append base_cfg "spectrum_mgmt_required=$spectrum_mgmt_required" "$N"
155 }
156 [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N"
157 }
158
159 [ -n "$acs_chan_bias" ] && append base_cfg "acs_chan_bias=$acs_chan_bias" "$N"
160
161 local brlist= br
162 json_get_values basic_rate_list basic_rate
163 local rlist= r
164 json_get_values rate_list supported_rates
165
166 [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N"
167 if [ "$hwmode" = "g" ] || [ "$hwmode" = "a" ]; then
168 [ -n "$require_mode" ] && legacy_rates=0
169 case "$require_mode" in
170 n) append base_cfg "require_ht=1" "$N";;
171 ac) append base_cfg "require_vht=1" "$N";;
172 esac
173 fi
174 case "$hwmode" in
175 b)
176 if [ "$cell_density" -eq 1 ]; then
177 set_default rate_list "5500 11000"
178 set_default basic_rate_list "5500 11000"
179 elif [ "$cell_density" -ge 2 ]; then
180 set_default rate_list "11000"
181 set_default basic_rate_list "11000"
182 fi
183 ;;
184 g)
185 if [ "$cell_density" -eq 0 ] || [ "$cell_density" -eq 1 ]; then
186 if [ "$legacy_rates" -eq 0 ]; then
187 set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000"
188 set_default basic_rate_list "6000 12000 24000"
189 elif [ "$cell_density" -eq 1 ]; then
190 set_default rate_list "5500 6000 9000 11000 12000 18000 24000 36000 48000 54000"
191 set_default basic_rate_list "5500 11000"
192 fi
193 elif [ "$cell_density" -ge 3 ] && [ "$legacy_rates" -ne 0 ] || [ "$cell_density" -eq 2 ]; then
194 if [ "$legacy_rates" -eq 0 ]; then
195 set_default rate_list "12000 18000 24000 36000 48000 54000"
196 set_default basic_rate_list "12000 24000"
197 else
198 set_default rate_list "11000 12000 18000 24000 36000 48000 54000"
199 set_default basic_rate_list "11000"
200 fi
201 elif [ "$cell_density" -ge 3 ]; then
202 set_default rate_list "24000 36000 48000 54000"
203 set_default basic_rate_list "24000"
204 fi
205 ;;
206 a)
207 if [ "$cell_density" -eq 1 ]; then
208 set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000"
209 set_default basic_rate_list "6000 12000 24000"
210 elif [ "$cell_density" -eq 2 ]; then
211 set_default rate_list "12000 18000 24000 36000 48000 54000"
212 set_default basic_rate_list "12000 24000"
213 elif [ "$cell_density" -ge 3 ]; then
214 set_default rate_list "24000 36000 48000 54000"
215 set_default basic_rate_list "24000"
216 fi
217 ;;
218 esac
219
220 for r in $rate_list; do
221 hostapd_add_rate rlist "$r"
222 done
223
224 for br in $basic_rate_list; do
225 hostapd_add_rate brlist "$br"
226 done
227
228 [ -n "$rssi_reject_assoc_rssi" ] && append base_cfg "rssi_reject_assoc_rssi=$rssi_reject_assoc_rssi" "$N"
229 [ -n "$rssi_ignore_probe_request" ] && append base_cfg "rssi_ignore_probe_request=$rssi_ignore_probe_request" "$N"
230 [ -n "$beacon_rate" ] && append base_cfg "beacon_rate=$beacon_rate" "$N"
231 [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N"
232 [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N"
233 append base_cfg "beacon_int=$beacon_int" "$N"
234 [ -n "$rts_threshold" ] && append base_cfg "rts_threshold=$rts_threshold" "$N"
235 append base_cfg "dtim_period=$dtim_period" "$N"
236 [ "$airtime_mode" -gt 0 ] && append base_cfg "airtime_mode=$airtime_mode" "$N"
237 [ -n "$maxassoc" ] && append base_cfg "iface_max_num_sta=$maxassoc" "$N"
238
239 json_get_values opts hostapd_options
240 for val in $opts; do
241 append base_cfg "$val" "$N"
242 done
243
244 cat > "$config" <<EOF
245driver=$driver
246$base_cfg
247EOF
248}
249
250hostapd_common_add_bss_config() {
251 config_add_string 'bssid:macaddr' 'ssid:string'
252 config_add_boolean wds wmm uapsd hidden utf8_ssid ppsk
253
254 config_add_int maxassoc max_inactivity
255 config_add_boolean disassoc_low_ack isolate short_preamble skip_inactivity_poll
256
257 config_add_int \
258 wep_rekey eap_reauth_period \
259 wpa_group_rekey wpa_pair_rekey wpa_master_rekey
260 config_add_boolean wpa_strict_rekey
261 config_add_boolean wpa_disable_eapol_key_retries
262
263 config_add_boolean tdls_prohibit
264
265 config_add_boolean rsn_preauth auth_cache
266 config_add_int ieee80211w
267 config_add_int eapol_version
268
269 config_add_string 'auth_server:host' 'server:host'
270 config_add_string auth_secret key
271 config_add_int 'auth_port:port' 'port:port'
272
273 config_add_string acct_server
274 config_add_string acct_secret
275 config_add_int acct_port
276 config_add_int acct_interval
277
278 config_add_int bss_load_update_period chan_util_avg_period
279
280 config_add_string dae_client
281 config_add_string dae_secret
282 config_add_int dae_port
283
284 config_add_string nasid
285 config_add_string ownip
286 config_add_string radius_client_addr
287 config_add_string iapp_interface
288 config_add_string eap_type ca_cert client_cert identity anonymous_identity auth priv_key priv_key_pwd
289 config_add_boolean ca_cert_usesystem ca_cert2_usesystem
290 config_add_string subject_match subject_match2
291 config_add_array altsubject_match altsubject_match2
292 config_add_array domain_match domain_match2 domain_suffix_match domain_suffix_match2
293 config_add_string ieee80211w_mgmt_cipher
294
295 config_add_int dynamic_vlan vlan_naming vlan_no_bridge
296 config_add_string vlan_tagged_interface vlan_bridge
297 config_add_string vlan_file
298
299 config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey'
300
301 config_add_string wpa_psk_file
302
303 config_add_int multi_ap
304
305 config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1
306 config_add_int wps_ap_setup_locked wps_independent
307 config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin
308 config_add_string multi_ap_backhaul_ssid multi_ap_backhaul_key
309
310 config_add_boolean wnm_sleep_mode wnm_sleep_mode_no_keys bss_transition mbo
311 config_add_int time_advertisement
312 config_add_string time_zone
313 config_add_string vendor_elements
314
315 config_add_boolean ieee80211k rrm_neighbor_report rrm_beacon_report
316
317 config_add_boolean ftm_responder stationary_ap
318 config_add_string lci civic
319
320 config_add_boolean ieee80211r pmk_r1_push ft_psk_generate_local ft_over_ds
321 config_add_int r0_key_lifetime reassociation_deadline
322 config_add_string mobility_domain r1_key_holder
323 config_add_array r0kh r1kh
324
325 config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout
326
327 config_add_string macfilter 'macfile:file'
328 config_add_array 'maclist:list(macaddr)'
329
330 config_add_array bssid_blacklist
331 config_add_array bssid_whitelist
332
333 config_add_int mcast_rate
334 config_add_array basic_rate
335 config_add_array supported_rates
336
337 config_add_boolean sae_require_mfp
338 config_add_int sae_pwe
339
340 config_add_string 'owe_transition_bssid:macaddr' 'owe_transition_ssid:string'
341 config_add_string owe_transition_ifname
342
343 config_add_boolean iw_enabled iw_internet iw_asra iw_esr iw_uesa
344 config_add_int iw_access_network_type iw_venue_group iw_venue_type
345 config_add_int iw_ipaddr_type_availability iw_gas_address3
346 config_add_string iw_hessid iw_network_auth_type iw_qos_map_set
347 config_add_array iw_roaming_consortium iw_domain_name iw_anqp_3gpp_cell_net iw_nai_realm
348 config_add_array iw_anqp_elem iw_venue_name iw_venue_url
349
350 config_add_boolean hs20 disable_dgaf osen
351 config_add_int anqp_domain_id
352 config_add_int hs20_deauth_req_timeout
353 config_add_array hs20_oper_friendly_name
354 config_add_array osu_provider
355 config_add_array operator_icon
356 config_add_array hs20_conn_capab
357 config_add_string osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp
358
359 config_add_string hs20_t_c_server_url
360
361 config_add_array airtime_sta_weight
362 config_add_int airtime_bss_weight airtime_bss_limit
363
364 config_add_boolean multicast_to_unicast multicast_to_unicast_all proxy_arp per_sta_vif
365
366 config_add_array hostapd_bss_options
367 config_add_boolean default_disabled
368
369 config_add_boolean request_cui
370 config_add_array radius_auth_req_attr
371 config_add_array radius_acct_req_attr
372
373 config_add_int eap_server
374 config_add_string eap_user_file ca_cert server_cert private_key private_key_passwd server_id
375
376 config_add_boolean fils
377 config_add_string fils_dhcp
378
379 config_add_int ocv
380}
381
382hostapd_set_vlan_file() {
383 local ifname="$1"
384 local vlan="$2"
385 json_get_vars name vid
386 echo "${vid} ${ifname}-${name}" >> /var/run/hostapd-${ifname}.vlan
387 wireless_add_vlan "${vlan}" "${ifname}-${name}"
388}
389
390hostapd_set_vlan() {
391 local ifname="$1"
392
393 rm -f /var/run/hostapd-${ifname}.vlan
394 for_each_vlan hostapd_set_vlan_file ${ifname}
395}
396
397hostapd_set_psk_file() {
398 local ifname="$1"
399 local vlan="$2"
400 local vlan_id=""
401
402 json_get_vars mac vid key
403 set_default mac "00:00:00:00:00:00"
404 [ -n "$vid" ] && vlan_id="vlanid=$vid "
405 echo "${vlan_id} ${mac} ${key}" >> /var/run/hostapd-${ifname}.psk
406}
407
408hostapd_set_psk() {
409 local ifname="$1"
410
411 rm -f /var/run/hostapd-${ifname}.psk
412 for_each_station hostapd_set_psk_file ${ifname}
413}
414
415append_iw_roaming_consortium() {
416 [ -n "$1" ] && append bss_conf "roaming_consortium=$1" "$N"
417}
418
419append_iw_domain_name() {
420 if [ -z "$iw_domain_name_conf" ]; then
421 iw_domain_name_conf="$1"
422 else
423 iw_domain_name_conf="$iw_domain_name_conf,$1"
424 fi
425}
426
427append_iw_anqp_3gpp_cell_net() {
428 if [ -z "$iw_anqp_3gpp_cell_net_conf" ]; then
429 iw_anqp_3gpp_cell_net_conf="$1"
430 else
431 iw_anqp_3gpp_cell_net_conf="$iw_anqp_3gpp_cell_net_conf:$1"
432 fi
433}
434
435append_iw_anqp_elem() {
436 [ -n "$1" ] && append bss_conf "anqp_elem=$1" "$N"
437}
438
439append_iw_nai_realm() {
440 [ -n "$1" ] && append bss_conf "nai_realm=$1" "$N"
441}
442
443append_iw_venue_name() {
444 append bss_conf "venue_name=$1" "$N"
445}
446
447append_iw_venue_url() {
448 append bss_conf "venue_url=$1" "$N"
449}
450
451append_hs20_oper_friendly_name() {
452 append bss_conf "hs20_oper_friendly_name=$1" "$N"
453}
454
455append_osu_provider_friendly_name() {
456 append bss_conf "osu_friendly_name=$1" "$N"
457}
458
459append_osu_provider_service_desc() {
460 append bss_conf "osu_service_desc=$1" "$N"
461}
462
463append_hs20_icon() {
464 local width height lang type path
465 config_get width "$1" width
466 config_get height "$1" height
467 config_get lang "$1" lang
468 config_get type "$1" type
469 config_get path "$1" path
470
471 append bss_conf "hs20_icon=$width:$height:$lang:$type:$1:$path" "$N"
472}
473
474append_hs20_icons() {
475 config_load wireless
476 config_foreach append_hs20_icon hs20-icon
477}
478
479append_operator_icon() {
480 append bss_conf "operator_icon=$1" "$N"
481}
482
483append_osu_icon() {
484 append bss_conf "osu_icon=$1" "$N"
485}
486
487append_osu_provider() {
488 local cfgtype osu_server_uri osu_friendly_name osu_nai osu_nai2 osu_method_list
489
490 config_load wireless
491 config_get cfgtype "$1" TYPE
492 [ "$cfgtype" != "osu-provider" ] && return
493
494 append bss_conf "# provider $1" "$N"
495 config_get osu_server_uri "$1" osu_server_uri
496 config_get osu_nai "$1" osu_nai
497 config_get osu_nai2 "$1" osu_nai2
498 config_get osu_method_list "$1" osu_method
499
500 append bss_conf "osu_server_uri=$osu_server_uri" "$N"
501 append bss_conf "osu_nai=$osu_nai" "$N"
502 append bss_conf "osu_nai2=$osu_nai2" "$N"
503 append bss_conf "osu_method_list=$osu_method_list" "$N"
504
505 config_list_foreach "$1" osu_service_desc append_osu_provider_service_desc
506 config_list_foreach "$1" osu_friendly_name append_osu_friendly_name
507 config_list_foreach "$1" osu_icon append_osu_icon
508
509 append bss_conf "$N"
510}
511
512append_hs20_conn_capab() {
513 [ -n "$1" ] && append bss_conf "hs20_conn_capab=$1" "$N"
514}
515
516append_radius_acct_req_attr() {
517 [ -n "$1" ] && append bss_conf "radius_acct_req_attr=$1" "$N"
518}
519
520append_radius_auth_req_attr() {
521 [ -n "$1" ] && append bss_conf "radius_auth_req_attr=$1" "$N"
522}
523
524append_airtime_sta_weight() {
525 [ -n "$1" ] && append bss_conf "airtime_sta_weight=$1" "$N"
526}
527
528hostapd_set_bss_options() {
529 local var="$1"
530 local phy="$2"
531 local vif="$3"
532
533 wireless_vif_parse_encryption
534
535 local bss_conf bss_md5sum ft_key
536 local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt
537
538 json_get_vars \
539 wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_strict_rekey \
540 wpa_disable_eapol_key_retries tdls_prohibit \
541 maxassoc max_inactivity disassoc_low_ack isolate auth_cache \
542 wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 wps_ap_setup_locked \
543 wps_independent wps_device_type wps_device_name wps_manufacturer wps_pin \
544 macfilter ssid utf8_ssid wmm uapsd hidden short_preamble rsn_preauth \
545 iapp_interface eapol_version dynamic_vlan ieee80211w nasid \
546 acct_server acct_secret acct_port acct_interval \
547 bss_load_update_period chan_util_avg_period sae_require_mfp sae_pwe \
548 multi_ap multi_ap_backhaul_ssid multi_ap_backhaul_key skip_inactivity_poll \
549 ppsk airtime_bss_weight airtime_bss_limit airtime_sta_weight \
550 multicast_to_unicast_all proxy_arp per_sta_vif \
551 eap_server eap_user_file ca_cert server_cert private_key private_key_passwd server_id \
552 vendor_elements fils ocv
553
554 set_default fils 0
555 set_default isolate 0
556 set_default maxassoc 0
557 set_default max_inactivity 0
558 set_default short_preamble 1
559 set_default disassoc_low_ack 1
560 set_default skip_inactivity_poll 0
561 set_default hidden 0
562 set_default wmm 1
563 set_default uapsd 1
564 set_default wpa_disable_eapol_key_retries 0
565 set_default tdls_prohibit 0
566 set_default eapol_version $((wpa & 1))
567 set_default acct_port 1813
568 set_default bss_load_update_period 60
569 set_default chan_util_avg_period 600
570 set_default utf8_ssid 1
571 set_default multi_ap 0
572 set_default ppsk 0
573 set_default airtime_bss_weight 0
574 set_default airtime_bss_limit 0
575 set_default eap_server 0
576
577 /usr/sbin/hostapd -vfils || fils=0
578
579 append bss_conf "ctrl_interface=/var/run/hostapd"
580 if [ "$isolate" -gt 0 ]; then
581 append bss_conf "ap_isolate=$isolate" "$N"
582 fi
583 if [ "$maxassoc" -gt 0 ]; then
584 append bss_conf "max_num_sta=$maxassoc" "$N"
585 fi
586 if [ "$max_inactivity" -gt 0 ]; then
587 append bss_conf "ap_max_inactivity=$max_inactivity" "$N"
588 fi
589
590 [ "$airtime_bss_weight" -gt 0 ] && append bss_conf "airtime_bss_weight=$airtime_bss_weight" "$N"
591 [ "$airtime_bss_limit" -gt 0 ] && append bss_conf "airtime_bss_limit=$airtime_bss_limit" "$N"
592 json_for_each_item append_airtime_sta_weight airtime_sta_weight
593
594 append bss_conf "bss_load_update_period=$bss_load_update_period" "$N"
595 append bss_conf "chan_util_avg_period=$chan_util_avg_period" "$N"
596 append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N"
597 append bss_conf "skip_inactivity_poll=$skip_inactivity_poll" "$N"
598 append bss_conf "preamble=$short_preamble" "$N"
599 append bss_conf "wmm_enabled=$wmm" "$N"
600 append bss_conf "ignore_broadcast_ssid=$hidden" "$N"
601 append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N"
602 append bss_conf "utf8_ssid=$utf8_ssid" "$N"
603 append bss_conf "multi_ap=$multi_ap" "$N"
604 [ -n "$vendor_elements" ] && append bss_conf "vendor_elements=$vendor_elements" "$N"
605
606 [ "$tdls_prohibit" -gt 0 ] && append bss_conf "tdls_prohibit=$tdls_prohibit" "$N"
607
608 [ "$wpa" -gt 0 ] && {
609 [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N"
610 [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
611 [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N"
612 [ -n "$wpa_strict_rekey" ] && append bss_conf "wpa_strict_rekey=$wpa_strict_rekey" "$N"
613 }
614
615 [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N"
616 [ -n "$acct_server" ] && {
617 append bss_conf "acct_server_addr=$acct_server" "$N"
618 append bss_conf "acct_server_port=$acct_port" "$N"
619 [ -n "$acct_secret" ] && \
620 append bss_conf "acct_server_shared_secret=$acct_secret" "$N"
621 [ -n "$acct_interval" ] && \
622 append bss_conf "radius_acct_interim_interval=$acct_interval" "$N"
623 json_for_each_item append_radius_acct_req_attr radius_acct_req_attr
624 }
625
626 [ -n "$ocv" ] && append bss_conf "ocv=$ocv" "$N"
627
628 case "$auth_type" in
629 sae|owe|eap192|eap-eap192)
630 set_default ieee80211w 2
631 set_default sae_require_mfp 1
632 set_default sae_pwe 2
633 ;;
634 psk-sae)
635 set_default ieee80211w 1
636 set_default sae_require_mfp 1
637 set_default sae_pwe 2
638 ;;
639 esac
640 [ -n "$sae_require_mfp" ] && append bss_conf "sae_require_mfp=$sae_require_mfp" "$N"
641 [ -n "$sae_pwe" ] && append bss_conf "sae_pwe=$sae_pwe" "$N"
642
643 local vlan_possible=""
644
645 case "$auth_type" in
646 none|owe)
647 json_get_vars owe_transition_bssid owe_transition_ssid owe_transition_ifname
648
649 [ -n "$owe_transition_ssid" ] && append bss_conf "owe_transition_ssid=\"$owe_transition_ssid\"" "$N"
650 [ -n "$owe_transition_bssid" ] && append bss_conf "owe_transition_bssid=$owe_transition_bssid" "$N"
651 [ -n "$owe_transition_ifname" ] && append bss_conf "owe_transition_ifname=$owe_transition_ifname" "$N"
652
653 wps_possible=1
654 # Here we make the assumption that if we're in open mode
655 # with WPS enabled, we got to be in unconfigured state.
656 wps_not_configured=1
657 ;;
658 psk|sae|psk-sae)
659 json_get_vars key wpa_psk_file
660 if [ "$auth_type" = "psk" ] && [ "$ppsk" -ne 0 ] ; then
661 json_get_vars auth_server auth_secret auth_port
662 set_default auth_port 1812
663 append bss_conf "auth_server_addr=$auth_server" "$N"
664 append bss_conf "auth_server_port=$auth_port" "$N"
665 append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
666 append bss_conf "macaddr_acl=2" "$N"
667 append bss_conf "wpa_psk_radius=2" "$N"
668 elif [ ${#key} -eq 64 ]; then
669 append bss_conf "wpa_psk=$key" "$N"
670 elif [ ${#key} -ge 8 ] && [ ${#key} -le 63 ]; then
671 append bss_conf "wpa_passphrase=$key" "$N"
672 elif [ -n "$key" ] || [ -z "$wpa_psk_file" ]; then
673 wireless_setup_vif_failed INVALID_WPA_PSK
674 return 1
675 fi
676 [ -z "$wpa_psk_file" ] && set_default wpa_psk_file /var/run/hostapd-$ifname.psk
677 [ -n "$wpa_psk_file" ] && {
678 [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file"
679 append bss_conf "wpa_psk_file=$wpa_psk_file" "$N"
680 }
681 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
682
683 set_default dynamic_vlan 0
684 vlan_possible=1
685 wps_possible=1
686 ;;
687 eap|eap192|eap-eap192)
688 json_get_vars \
689 auth_server auth_secret auth_port \
690 dae_client dae_secret dae_port \
691 ownip radius_client_addr \
692 eap_reauth_period request_cui \
693 erp_domain mobility_domain \
694 fils_realm fils_dhcp
695
696 # radius can provide VLAN ID for clients
697 vlan_possible=1
698
699 # legacy compatibility
700 [ -n "$auth_server" ] || json_get_var auth_server server
701 [ -n "$auth_port" ] || json_get_var auth_port port
702 [ -n "$auth_secret" ] || json_get_var auth_secret key
703
704 [ "$fils" -gt 0 ] && {
705 set_default erp_domain "$mobility_domain"
706 set_default erp_domain "$(echo "$ssid" | md5sum | head -c 8)"
707 set_default fils_realm "$erp_domain"
708
709 append bss_conf "erp_send_reauth_start=1" "$N"
710 append bss_conf "erp_domain=$erp_domain" "$N"
711 append bss_conf "fils_realm=$fils_realm" "$N"
712 append bss_conf "fils_cache_id=$(echo "$fils_realm" | md5sum | head -c 4)" "$N"
713
714 [ "$fils_dhcp" = "*" ] && {
715 json_get_values network network
716 fils_dhcp=
717 for net in $network; do
718 fils_dhcp="$(ifstatus "$net" | jsonfilter -e '@.data.dhcpserver')"
719 [ -n "$fils_dhcp" ] && break
720 done
721
722 [ -z "$fils_dhcp" -a -n "$network_bridge" -a -n "$network_ifname" ] && \
723 fils_dhcp="$(udhcpc -B -n -q -s /lib/netifd/dhcp-get-server.sh -t 1 -i "$network_ifname" 2>/dev/null)"
724 }
725 [ -n "$fils_dhcp" ] && append bss_conf "dhcp_server=$fils_dhcp" "$N"
726 }
727
728 set_default auth_port 1812
729 set_default dae_port 3799
730 set_default request_cui 0
731
732 [ "$eap_server" -eq 0 ] && {
733 append bss_conf "auth_server_addr=$auth_server" "$N"
734 append bss_conf "auth_server_port=$auth_port" "$N"
735 append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
736 }
737
738 [ "$request_cui" -gt 0 ] && append bss_conf "radius_request_cui=$request_cui" "$N"
739 [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N"
740
741 [ -n "$dae_client" -a -n "$dae_secret" ] && {
742 append bss_conf "radius_das_port=$dae_port" "$N"
743 append bss_conf "radius_das_client=$dae_client $dae_secret" "$N"
744 }
745 json_for_each_item append_radius_auth_req_attr radius_auth_req_attr
746
747 [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N"
748 [ -n "$radius_client_addr" ] && append bss_conf "radius_client_addr=$radius_client_addr" "$N"
749 append bss_conf "eapol_key_index_workaround=1" "$N"
750 append bss_conf "ieee8021x=1" "$N"
751
752 [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
753 ;;
754 wep)
755 local wep_keyidx=0
756 json_get_vars key
757 hostapd_append_wep_key bss_conf
758 append bss_conf "wep_default_key=$wep_keyidx" "$N"
759 [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N"
760 ;;
761 esac
762
763 case "$auth_type" in
764 none|owe|psk|sae|psk-sae|wep)
765 json_get_vars \
766 auth_server auth_port auth_secret \
767 ownip radius_client_addr
768
769 [ -n "$auth_server" ] && {
770 set_default auth_port 1812
771
772 append bss_conf "auth_server_addr=$auth_server" "$N"
773 append bss_conf "auth_server_port=$auth_port" "$N"
774 [ -n "$auth_secret" ] && append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
775 [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N"
776 [ -n "$radius_client_addr" ] && append bss_conf "radius_client_addr=$radius_client_addr" "$N"
777 append bss_conf "macaddr_acl=2" "$N"
778 }
779 ;;
780 esac
781
782 local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open))
783 append bss_conf "auth_algs=${auth_algs:-1}" "$N"
784 append bss_conf "wpa=$wpa" "$N"
785 [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N"
786
787 set_default wps_pushbutton 0
788 set_default wps_label 0
789 set_default wps_pbc_in_m1 0
790
791 config_methods=
792 [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button
793 [ "$wps_label" -gt 0 ] && append config_methods label
794
795 # WPS not possible on Multi-AP backhaul-only SSID
796 [ "$multi_ap" = 1 ] && wps_possible=
797
798 [ -n "$wps_possible" -a -n "$config_methods" ] && {
799 set_default ext_registrar 0
800 set_default wps_device_type "6-0050F204-1"
801 set_default wps_device_name "OpenWrt AP"
802 set_default wps_manufacturer "www.openwrt.org"
803 set_default wps_independent 1
804
805 wps_state=2
806 [ -n "$wps_not_configured" ] && wps_state=1
807
808 [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N"
809
810 append bss_conf "eap_server=1" "$N"
811 [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N"
812 append bss_conf "wps_state=$wps_state" "$N"
813 append bss_conf "device_type=$wps_device_type" "$N"
814 append bss_conf "device_name=$wps_device_name" "$N"
815 append bss_conf "manufacturer=$wps_manufacturer" "$N"
816 append bss_conf "config_methods=$config_methods" "$N"
817 append bss_conf "wps_independent=$wps_independent" "$N"
818 [ -n "$wps_ap_setup_locked" ] && append bss_conf "ap_setup_locked=$wps_ap_setup_locked" "$N"
819 [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N"
820 [ "$multi_ap" -gt 0 ] && [ -n "$multi_ap_backhaul_ssid" ] && {
821 append bss_conf "multi_ap_backhaul_ssid=\"$multi_ap_backhaul_ssid\"" "$N"
822 if [ -z "$multi_ap_backhaul_key" ]; then
823 :
824 elif [ ${#multi_ap_backhaul_key} -lt 8 ]; then
825 wireless_setup_vif_failed INVALID_WPA_PSK
826 return 1
827 elif [ ${#multi_ap_backhaul_key} -eq 64 ]; then
828 append bss_conf "multi_ap_backhaul_wpa_psk=$multi_ap_backhaul_key" "$N"
829 else
830 append bss_conf "multi_ap_backhaul_wpa_passphrase=$multi_ap_backhaul_key" "$N"
831 fi
832 }
833 }
834
835 append bss_conf "ssid=$ssid" "$N"
836 [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge${N}wds_bridge=" "$N"
837 [ -n "$network_ifname" ] && append bss_conf "snoop_iface=$network_ifname" "$N"
838 [ -n "$iapp_interface" ] && {
839 local ifname
840 network_get_device ifname "$iapp_interface" || ifname="$iapp_interface"
841 append bss_conf "iapp_interface=$ifname" "$N"
842 }
843
844 json_get_vars time_advertisement time_zone wnm_sleep_mode wnm_sleep_mode_no_keys bss_transition mbo
845 set_default bss_transition 0
846 set_default wnm_sleep_mode 0
847 set_default wnm_sleep_mode_no_keys 0
848 set_default mbo 0
849
850 [ -n "$time_advertisement" ] && append bss_conf "time_advertisement=$time_advertisement" "$N"
851 [ -n "$time_zone" ] && append bss_conf "time_zone=$time_zone" "$N"
852 if [ "$wnm_sleep_mode" -eq "1" ]; then
853 append bss_conf "wnm_sleep_mode=1" "$N"
854 [ "$wnm_sleep_mode_no_keys" -eq "1" ] && append bss_conf "wnm_sleep_mode_no_keys=1" "$N"
855 fi
856 [ "$bss_transition" -eq "1" ] && append bss_conf "bss_transition=1" "$N"
857 [ "$mbo" -eq 1 ] && append bss_conf "mbo=1" "$N"
858
859 json_get_vars ieee80211k rrm_neighbor_report rrm_beacon_report
860 set_default ieee80211k 0
861 if [ "$ieee80211k" -eq "1" ]; then
862 set_default rrm_neighbor_report 1
863 set_default rrm_beacon_report 1
864 else
865 set_default rrm_neighbor_report 0
866 set_default rrm_beacon_report 0
867 fi
868
869 [ "$rrm_neighbor_report" -eq "1" ] && append bss_conf "rrm_neighbor_report=1" "$N"
870 [ "$rrm_beacon_report" -eq "1" ] && append bss_conf "rrm_beacon_report=1" "$N"
871
872 json_get_vars ftm_responder stationary_ap lci civic
873 set_default ftm_responder 0
874 if [ "$ftm_responder" -eq "1" ]; then
875 set_default stationary_ap 0
876 iw phy "$phy" info | grep -q "ENABLE_FTM_RESPONDER" && {
877 append bss_conf "ftm_responder=1" "$N"
878 [ "$stationary_ap" -eq "1" ] && append bss_conf "stationary_ap=1" "$N"
879 [ -n "$lci" ] && append bss_conf "lci=$lci" "$N"
880 [ -n "$civic" ] && append bss_conf "civic=$civic" "$N"
881 }
882 fi
883
884 if [ "$wpa" -ge "1" ]; then
885 json_get_vars ieee80211r
886 set_default ieee80211r 0
887
888 if [ "$ieee80211r" -gt "0" ]; then
889 json_get_vars mobility_domain ft_psk_generate_local ft_over_ds reassociation_deadline
890
891 set_default mobility_domain "$(echo "$ssid" | md5sum | head -c 4)"
892 set_default ft_over_ds 0
893 set_default reassociation_deadline 1000
894
895 case "$auth_type" in
896 psk|sae|psk-sae)
897 set_default ft_psk_generate_local 1
898 ;;
899 *)
900 set_default ft_psk_generate_local 0
901 ;;
902 esac
903
904 [ -n "$network_ifname" ] && append bss_conf "ft_iface=$network_ifname" "$N"
905 append bss_conf "mobility_domain=$mobility_domain" "$N"
906 append bss_conf "ft_psk_generate_local=$ft_psk_generate_local" "$N"
907 append bss_conf "ft_over_ds=$ft_over_ds" "$N"
908 append bss_conf "reassociation_deadline=$reassociation_deadline" "$N"
909 [ -n "$nasid" ] || append bss_conf "nas_identifier=${macaddr//\:}" "$N"
910
911 if [ "$ft_psk_generate_local" -eq "0" ]; then
912 json_get_vars r0_key_lifetime r1_key_holder pmk_r1_push
913 json_get_values r0kh r0kh
914 json_get_values r1kh r1kh
915
916 set_default r0_key_lifetime 10000
917 set_default pmk_r1_push 0
918
919 [ -n "$r0kh" -a -n "$r1kh" ] || {
920 ft_key=`echo -n "$mobility_domain/${auth_secret:-${key}}" | md5sum | awk '{print $1}'`
921
922 set_default r0kh "ff:ff:ff:ff:ff:ff,*,$ft_key"
923 set_default r1kh "00:00:00:00:00:00,00:00:00:00:00:00,$ft_key"
924 }
925
926 [ -n "$r1_key_holder" ] && append bss_conf "r1_key_holder=$r1_key_holder" "$N"
927 append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N"
928 append bss_conf "pmk_r1_push=$pmk_r1_push" "$N"
929
930 for kh in $r0kh; do
931 append bss_conf "r0kh=${kh//,/ }" "$N"
932 done
933 for kh in $r1kh; do
934 append bss_conf "r1kh=${kh//,/ }" "$N"
935 done
936 fi
937 fi
938 if [ "$fils" -gt 0 ]; then
939 json_get_vars fils_realm
940 set_default fils_realm "$(echo "$ssid" | md5sum | head -c 8)"
941 fi
942
943 append bss_conf "wpa_disable_eapol_key_retries=$wpa_disable_eapol_key_retries" "$N"
944
945 hostapd_append_wpa_key_mgmt
946 [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N"
947 fi
948
949 if [ "$wpa" -ge "2" ]; then
950 if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then
951 set_default auth_cache 1
952 append bss_conf "rsn_preauth=1" "$N"
953 append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N"
954 else
955 case "$auth_type" in
956 sae|psk-sae|owe)
957 set_default auth_cache 1
958 ;;
959 *)
960 set_default auth_cache 0
961 ;;
962 esac
963 fi
964
965 append bss_conf "okc=$auth_cache" "$N"
966 [ "$auth_cache" = 0 -a "$fils" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N"
967
968 # RSN -> allow management frame protection
969 case "$ieee80211w" in
970 [012])
971 json_get_vars ieee80211w_mgmt_cipher ieee80211w_max_timeout ieee80211w_retry_timeout
972 append bss_conf "ieee80211w=$ieee80211w" "$N"
973 [ "$ieee80211w" -gt "0" ] && {
974 if [ "$auth_type" = "eap192" ]; then
975 append bss_conf "group_mgmt_cipher=BIP-GMAC-256" "$N"
976 else
977 append bss_conf "group_mgmt_cipher=${ieee80211w_mgmt_cipher:-AES-128-CMAC}" "$N"
978 fi
979 [ -n "$ieee80211w_max_timeout" ] && \
980 append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
981 [ -n "$ieee80211w_retry_timeout" ] && \
982 append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
983 }
984 ;;
985 esac
986 fi
987
988 _macfile="/var/run/hostapd-$ifname.maclist"
989 case "$macfilter" in
990 allow)
991 append bss_conf "macaddr_acl=1" "$N"
992 append bss_conf "accept_mac_file=$_macfile" "$N"
993 # accept_mac_file can be used to set MAC to VLAN ID mapping
994 vlan_possible=1
995 ;;
996 deny)
997 append bss_conf "macaddr_acl=0" "$N"
998 append bss_conf "deny_mac_file=$_macfile" "$N"
999 ;;
1000 *)
1001 _macfile=""
1002 ;;
1003 esac
1004
1005 [ -n "$_macfile" ] && {
1006 json_get_vars macfile
1007 json_get_values maclist maclist
1008
1009 rm -f "$_macfile"
1010 (
1011 for mac in $maclist; do
1012 echo "$mac"
1013 done
1014 [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile"
1015 ) > "$_macfile"
1016 }
1017
1018 [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && {
1019 json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file vlan_no_bridge
1020 set_default vlan_naming 1
1021 [ -z "$vlan_file" ] && set_default vlan_file /var/run/hostapd-$ifname.vlan
1022 append bss_conf "dynamic_vlan=$dynamic_vlan" "$N"
1023 append bss_conf "vlan_naming=$vlan_naming" "$N"
1024 if [ -n "$vlan_bridge" ]; then
1025 append bss_conf "vlan_bridge=$vlan_bridge" "$N"
1026 else
1027 set_default vlan_no_bridge 1
1028 fi
1029 append bss_conf "vlan_no_bridge=$vlan_no_bridge" "$N"
1030 [ -n "$vlan_tagged_interface" ] && \
1031 append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N"
1032 [ -n "$vlan_file" ] && {
1033 [ -e "$vlan_file" ] || touch "$vlan_file"
1034 append bss_conf "vlan_file=$vlan_file" "$N"
1035 }
1036 }
1037
1038 json_get_vars iw_enabled iw_internet iw_asra iw_esr iw_uesa iw_access_network_type
1039 json_get_vars iw_hessid iw_venue_group iw_venue_type iw_network_auth_type
1040 json_get_vars iw_roaming_consortium iw_domain_name iw_anqp_3gpp_cell_net iw_nai_realm
1041 json_get_vars iw_anqp_elem iw_qos_map_set iw_ipaddr_type_availability iw_gas_address3
1042 json_get_vars iw_venue_name iw_venue_url
1043
1044 set_default iw_enabled 0
1045 if [ "$iw_enabled" = "1" ]; then
1046 append bss_conf "interworking=1" "$N"
1047 set_default iw_internet 1
1048 set_default iw_asra 0
1049 set_default iw_esr 0
1050 set_default iw_uesa 0
1051
1052 append bss_conf "internet=$iw_internet" "$N"
1053 append bss_conf "asra=$iw_asra" "$N"
1054 append bss_conf "esr=$iw_esr" "$N"
1055 append bss_conf "uesa=$iw_uesa" "$N"
1056
1057 [ -n "$iw_access_network_type" ] && \
1058 append bss_conf "access_network_type=$iw_access_network_type" "$N"
1059 [ -n "$iw_hessid" ] && append bss_conf "hessid=$iw_hessid" "$N"
1060 [ -n "$iw_venue_group" ] && \
1061 append bss_conf "venue_group=$iw_venue_group" "$N"
1062 [ -n "$iw_venue_type" ] && append bss_conf "venue_type=$iw_venue_type" "$N"
1063 [ -n "$iw_network_auth_type" ] && \
1064 append bss_conf "network_auth_type=$iw_network_auth_type" "$N"
1065 [ -n "$iw_gas_address3" ] && append bss_conf "gas_address3=$iw_gas_address3" "$N"
1066
1067 json_for_each_item append_iw_roaming_consortium iw_roaming_consortium
1068 json_for_each_item append_iw_anqp_elem iw_anqp_elem
1069 json_for_each_item append_iw_nai_realm iw_nai_realm
1070 json_for_each_item append_iw_venue_name iw_venue_name
1071 json_for_each_item append_iw_venue_url iw_venue_url
1072
1073 iw_domain_name_conf=
1074 json_for_each_item append_iw_domain_name iw_domain_name
1075 [ -n "$iw_domain_name_conf" ] && \
1076 append bss_conf "domain_name=$iw_domain_name_conf" "$N"
1077
1078 iw_anqp_3gpp_cell_net_conf=
1079 json_for_each_item append_iw_anqp_3gpp_cell_net iw_anqp_3gpp_cell_net
1080 [ -n "$iw_anqp_3gpp_cell_net_conf" ] && \
1081 append bss_conf "anqp_3gpp_cell_net=$iw_anqp_3gpp_cell_net_conf" "$N"
1082 fi
1083
1084 set_default iw_qos_map_set 0,0,2,16,1,1,255,255,18,22,24,38,40,40,44,46,48,56
1085 case "$iw_qos_map_set" in
1086 *,*);;
1087 *) iw_qos_map_set="";;
1088 esac
1089 [ -n "$iw_qos_map_set" ] && append bss_conf "qos_map_set=$iw_qos_map_set" "$N"
1090
1091 local hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
1092 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp \
1093 hs20_t_c_server_url
1094 json_get_vars hs20 disable_dgaf osen anqp_domain_id hs20_deauth_req_timeout \
1095 osu_ssid hs20_wan_metrics hs20_operating_class hs20_t_c_filename hs20_t_c_timestamp \
1096 hs20_t_c_server_url
1097
1098 set_default hs20 0
1099 set_default disable_dgaf $hs20
1100 set_default osen 0
1101 set_default anqp_domain_id 0
1102 set_default hs20_deauth_req_timeout 60
1103 if [ "$hs20" = "1" ]; then
1104 append bss_conf "hs20=1" "$N"
1105 append_hs20_icons
1106 append bss_conf "disable_dgaf=$disable_dgaf" "$N"
1107 append bss_conf "osen=$osen" "$N"
1108 append bss_conf "anqp_domain_id=$anqp_domain_id" "$N"
1109 append bss_conf "hs20_deauth_req_timeout=$hs20_deauth_req_timeout" "$N"
1110 [ -n "$osu_ssid" ] && append bss_conf "osu_ssid=$osu_ssid" "$N"
1111 [ -n "$hs20_wan_metrics" ] && append bss_conf "hs20_wan_metrics=$hs20_wan_metrics" "$N"
1112 [ -n "$hs20_operating_class" ] && append bss_conf "hs20_operating_class=$hs20_operating_class" "$N"
1113 [ -n "$hs20_t_c_filename" ] && append bss_conf "hs20_t_c_filename=$hs20_t_c_filename" "$N"
1114 [ -n "$hs20_t_c_timestamp" ] && append bss_conf "hs20_t_c_timestamp=$hs20_t_c_timestamp" "$N"
1115 [ -n "$hs20_t_c_server_url" ] && append bss_conf "hs20_t_c_server_url=$hs20_t_c_server_url" "$N"
1116 json_for_each_item append_hs20_oper_friendly_name hs20_oper_friendly_name
1117 json_for_each_item append_hs20_conn_capab hs20_conn_capab
1118 json_for_each_item append_osu_provider osu_provider
1119 json_for_each_item append_operator_icon operator_icon
1120 fi
1121
1122 if [ "$eap_server" = "1" ]; then
1123 append bss_conf "eap_server=1" "$N"
1124 append bss_conf "eap_server_erp=1" "$N"
1125 [ -n "$eap_user_file" ] && append bss_conf "eap_user_file=$eap_user_file" "$N"
1126 [ -n "$ca_cert" ] && append bss_conf "ca_cert=$ca_cert" "$N"
1127 [ -n "$server_cert" ] && append bss_conf "server_cert=$server_cert" "$N"
1128 [ -n "$private_key" ] && append bss_conf "private_key=$private_key" "$N"
1129 [ -n "$private_key_passwd" ] && append bss_conf "private_key_passwd=$private_key_passwd" "$N"
1130 [ -n "$server_id" ] && append bss_conf "server_id=$server_id" "$N"
1131 fi
1132
1133 set_default multicast_to_unicast_all 0
1134 if [ "$multicast_to_unicast_all" -gt 0 ]; then
1135 append bss_conf "multicast_to_unicast=$multicast_to_unicast_all" "$N"
1136 fi
1137 set_default proxy_arp 0
1138 if [ "$proxy_arp" -gt 0 ]; then
1139 append bss_conf "proxy_arp=$proxy_arp" "$N"
1140 fi
1141
1142 set_default per_sta_vif 0
1143 if [ "$per_sta_vif" -gt 0 ]; then
1144 append bss_conf "per_sta_vif=$per_sta_vif" "$N"
1145 fi
1146
1147 json_get_values opts hostapd_bss_options
1148 for val in $opts; do
1149 append bss_conf "$val" "$N"
1150 done
1151
1152 bss_md5sum=$(echo $bss_conf | md5sum | cut -d" " -f1)
1153 append bss_conf "config_id=$bss_md5sum" "$N"
1154
1155 append "$var" "$bss_conf" "$N"
1156 return 0
1157}
1158
1159hostapd_set_log_options() {
1160 local var="$1"
1161
1162 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
1163 json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
1164
1165 set_default log_level 2
1166 set_default log_80211 1
1167 set_default log_8021x 1
1168 set_default log_radius 1
1169 set_default log_wpa 1
1170 set_default log_driver 1
1171 set_default log_iapp 1
1172 set_default log_mlme 1
1173
1174 local log_mask=$(( \
1175 ($log_80211 << 0) | \
1176 ($log_8021x << 1) | \
1177 ($log_radius << 2) | \
1178 ($log_wpa << 3) | \
1179 ($log_driver << 4) | \
1180 ($log_iapp << 5) | \
1181 ($log_mlme << 6) \
1182 ))
1183
1184 append "$var" "logger_syslog=$log_mask" "$N"
1185 append "$var" "logger_syslog_level=$log_level" "$N"
1186 append "$var" "logger_stdout=$log_mask" "$N"
1187 append "$var" "logger_stdout_level=$log_level" "$N"
1188
1189 return 0
1190}
1191
1192_wpa_supplicant_common() {
1193 local ifname="$1"
1194
1195 _rpath="/var/run/wpa_supplicant"
1196 _config="${_rpath}-$ifname.conf"
1197}
1198
1199wpa_supplicant_teardown_interface() {
1200 _wpa_supplicant_common "$1"
1201 rm -rf "$_rpath/$1" "$_config"
1202}
1203
1204wpa_supplicant_prepare_interface() {
1205 local ifname="$1"
1206 _w_driver="$2"
1207
1208 _wpa_supplicant_common "$1"
1209
1210 json_get_vars mode wds multi_ap
1211
1212 [ -n "$network_bridge" ] && {
1213 fail=
1214 case "$mode" in
1215 adhoc)
1216 fail=1
1217 ;;
1218 sta)
1219 [ "$wds" = 1 -o "$multi_ap" = 1 ] || fail=1
1220 ;;
1221 esac
1222
1223 [ -n "$fail" ] && {
1224 wireless_setup_vif_failed BRIDGE_NOT_ALLOWED
1225 return 1
1226 }
1227 }
1228
1229 local ap_scan=
1230
1231 _w_mode="$mode"
1232
1233 [ "$mode" = adhoc ] && {
1234 ap_scan="ap_scan=2"
1235 }
1236
1237 local country_str=
1238 [ -n "$country" ] && {
1239 country_str="country=$country"
1240 }
1241
1242 multiap_flag_file="${_config}.is_multiap"
1243 if [ "$multi_ap" = "1" ]; then
1244 touch "$multiap_flag_file"
1245 else
1246 [ -e "$multiap_flag_file" ] && rm "$multiap_flag_file"
1247 fi
1248 wpa_supplicant_teardown_interface "$ifname"
1249 cat > "$_config" <<EOF
1250${scan_list:+freq_list=$scan_list}
1251$ap_scan
1252$country_str
1253EOF
1254 return 0
1255}
1256
1257wpa_supplicant_set_fixed_freq() {
1258 local freq="$1"
1259 local htmode="$2"
1260
1261 append network_data "fixed_freq=1" "$N$T"
1262 append network_data "frequency=$freq" "$N$T"
1263 case "$htmode" in
1264 NOHT) append network_data "disable_ht=1" "$N$T";;
1265 HE20|HT20|VHT20) append network_data "disable_ht40=1" "$N$T";;
1266 HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160) append network_data "ht40=1" "$N$T";;
1267 esac
1268 case "$htmode" in
1269 VHT*) append network_data "vht=1" "$N$T";;
1270 esac
1271 case "$htmode" in
1272 HE80|VHT80) append network_data "max_oper_chwidth=1" "$N$T";;
1273 HE160|VHT160) append network_data "max_oper_chwidth=2" "$N$T";;
1274 HE20|HE40|VHT20|VHT40) append network_data "max_oper_chwidth=0" "$N$T";;
1275 *) append network_data "disable_vht=1" "$N$T";;
1276 esac
1277}
1278
1279wpa_supplicant_add_network() {
1280 local ifname="$1"
1281 local freq="$2"
1282 local htmode="$3"
1283 local noscan="$4"
1284
1285 _wpa_supplicant_common "$1"
1286 wireless_vif_parse_encryption
1287
1288 json_get_vars \
1289 ssid bssid key \
1290 basic_rate mcast_rate \
1291 ieee80211w ieee80211r fils ocv \
1292 multi_ap \
1293 default_disabled
1294
1295 case "$auth_type" in
1296 sae|owe|eap192|eap-eap192)
1297 set_default ieee80211w 2
1298 ;;
1299 psk-sae)
1300 set_default ieee80211w 1
1301 ;;
1302 esac
1303
1304 set_default ieee80211r 0
1305 set_default multi_ap 0
1306 set_default default_disabled 0
1307
1308 local key_mgmt='NONE'
1309 local network_data=
1310 local T=" "
1311
1312 local scan_ssid="scan_ssid=1"
1313 local freq wpa_key_mgmt
1314
1315 [ "$_w_mode" = "adhoc" ] && {
1316 append network_data "mode=1" "$N$T"
1317 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
1318 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
1319
1320 scan_ssid="scan_ssid=0"
1321
1322 [ "$_w_driver" = "nl80211" ] || append wpa_key_mgmt "WPA-NONE"
1323 }
1324
1325 [ "$_w_mode" = "mesh" ] && {
1326 json_get_vars mesh_id mesh_fwding mesh_rssi_threshold
1327 [ -n "$mesh_id" ] && ssid="${mesh_id}"
1328
1329 append network_data "mode=5" "$N$T"
1330 [ -n "$mesh_fwding" ] && append network_data "mesh_fwding=${mesh_fwding}" "$N$T"
1331 [ -n "$mesh_rssi_threshold" ] && append network_data "mesh_rssi_threshold=${mesh_rssi_threshold}" "$N$T"
1332 [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode"
1333 [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T"
1334 append wpa_key_mgmt "SAE"
1335 scan_ssid=""
1336 }
1337
1338 [ "$_w_mode" = "sta" ] && {
1339 [ "$multi_ap" = 1 ] && append network_data "multi_ap_backhaul_sta=1" "$N$T"
1340 [ "$default_disabled" = 1 ] && append network_data "disabled=1" "$N$T"
1341 }
1342
1343 [ -n "$ocv" ] && append network_data "ocv=$ocv" "$N$T"
1344
1345 case "$auth_type" in
1346 none) ;;
1347 owe)
1348 hostapd_append_wpa_key_mgmt
1349 key_mgmt="$wpa_key_mgmt"
1350 ;;
1351 wep)
1352 local wep_keyidx=0
1353 hostapd_append_wep_key network_data
1354 append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T"
1355 ;;
1356 wps)
1357 key_mgmt='WPS'
1358 ;;
1359 psk|sae|psk-sae)
1360 local passphrase
1361
1362 if [ "$_w_mode" != "mesh" ]; then
1363 hostapd_append_wpa_key_mgmt
1364 fi
1365
1366 key_mgmt="$wpa_key_mgmt"
1367
1368 if [ ${#key} -eq 64 ]; then
1369 passphrase="psk=${key}"
1370 else
1371 if [ "$_w_mode" = "mesh" ]; then
1372 passphrase="sae_password=\"${key}\""
1373 else
1374 passphrase="psk=\"${key}\""
1375 fi
1376 fi
1377 append network_data "$passphrase" "$N$T"
1378 ;;
1379 eap|eap192|eap-eap192)
1380 hostapd_append_wpa_key_mgmt
1381 key_mgmt="$wpa_key_mgmt"
1382
1383 json_get_vars eap_type identity anonymous_identity ca_cert ca_cert_usesystem
1384
1385 [ "$fils" -gt 0 ] && append network_data "erp=1" "$N$T"
1386 if [ "$ca_cert_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1387 append network_data "ca_cert=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1388 else
1389 [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T"
1390 fi
1391 [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T"
1392 [ -n "$anonymous_identity" ] && append network_data "anonymous_identity=\"$anonymous_identity\"" "$N$T"
1393 case "$eap_type" in
1394 tls)
1395 json_get_vars client_cert priv_key priv_key_pwd
1396 append network_data "client_cert=\"$client_cert\"" "$N$T"
1397 append network_data "private_key=\"$priv_key\"" "$N$T"
1398 append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T"
1399
1400 json_get_vars subject_match
1401 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1402
1403 json_get_values altsubject_match altsubject_match
1404 if [ -n "$altsubject_match" ]; then
1405 local list=
1406 for x in $altsubject_match; do
1407 append list "$x" ";"
1408 done
1409 append network_data "altsubject_match=\"$list\"" "$N$T"
1410 fi
1411
1412 json_get_values domain_match domain_match
1413 if [ -n "$domain_match" ]; then
1414 local list=
1415 for x in $domain_match; do
1416 append list "$x" ";"
1417 done
1418 append network_data "domain_match=\"$list\"" "$N$T"
1419 fi
1420
1421 json_get_values domain_suffix_match domain_suffix_match
1422 if [ -n "$domain_suffix_match" ]; then
1423 local list=
1424 for x in $domain_suffix_match; do
1425 append list "$x" ";"
1426 done
1427 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1428 fi
1429 ;;
1430 fast|peap|ttls)
1431 json_get_vars auth password ca_cert2 ca_cert2_usesystem client_cert2 priv_key2 priv_key2_pwd
1432 set_default auth MSCHAPV2
1433
1434 if [ "$auth" = "EAP-TLS" ]; then
1435 if [ "$ca_cert2_usesystem" -eq "1" -a -f "/etc/ssl/certs/ca-certificates.crt" ]; then
1436 append network_data "ca_cert2=\"/etc/ssl/certs/ca-certificates.crt\"" "$N$T"
1437 else
1438 [ -n "$ca_cert2" ] && append network_data "ca_cert2=\"$ca_cert2\"" "$N$T"
1439 fi
1440 append network_data "client_cert2=\"$client_cert2\"" "$N$T"
1441 append network_data "private_key2=\"$priv_key2\"" "$N$T"
1442 append network_data "private_key2_passwd=\"$priv_key2_pwd\"" "$N$T"
1443 else
1444 append network_data "password=\"$password\"" "$N$T"
1445 fi
1446
1447 json_get_vars subject_match
1448 [ -n "$subject_match" ] && append network_data "subject_match=\"$subject_match\"" "$N$T"
1449
1450 json_get_values altsubject_match altsubject_match
1451 if [ -n "$altsubject_match" ]; then
1452 local list=
1453 for x in $altsubject_match; do
1454 append list "$x" ";"
1455 done
1456 append network_data "altsubject_match=\"$list\"" "$N$T"
1457 fi
1458
1459 json_get_values domain_match domain_match
1460 if [ -n "$domain_match" ]; then
1461 local list=
1462 for x in $domain_match; do
1463 append list "$x" ";"
1464 done
1465 append network_data "domain_match=\"$list\"" "$N$T"
1466 fi
1467
1468 json_get_values domain_suffix_match domain_suffix_match
1469 if [ -n "$domain_suffix_match" ]; then
1470 local list=
1471 for x in $domain_suffix_match; do
1472 append list "$x" ";"
1473 done
1474 append network_data "domain_suffix_match=\"$list\"" "$N$T"
1475 fi
1476
1477 phase2proto="auth="
1478 case "$auth" in
1479 "auth"*)
1480 phase2proto=""
1481 ;;
1482 "EAP-"*)
1483 auth="$(echo $auth | cut -b 5- )"
1484 [ "$eap_type" = "ttls" ] &&
1485 phase2proto="autheap="
1486 json_get_vars subject_match2
1487 [ -n "$subject_match2" ] && append network_data "subject_match2=\"$subject_match2\"" "$N$T"
1488
1489 json_get_values altsubject_match2 altsubject_match2
1490 if [ -n "$altsubject_match2" ]; then
1491 local list=
1492 for x in $altsubject_match2; do
1493 append list "$x" ";"
1494 done
1495 append network_data "altsubject_match2=\"$list\"" "$N$T"
1496 fi
1497
1498 json_get_values domain_match2 domain_match2
1499 if [ -n "$domain_match2" ]; then
1500 local list=
1501 for x in $domain_match2; do
1502 append list "$x" ";"
1503 done
1504 append network_data "domain_match2=\"$list\"" "$N$T"
1505 fi
1506
1507 json_get_values domain_suffix_match2 domain_suffix_match2
1508 if [ -n "$domain_suffix_match2" ]; then
1509 local list=
1510 for x in $domain_suffix_match2; do
1511 append list "$x" ";"
1512 done
1513 append network_data "domain_suffix_match2=\"$list\"" "$N$T"
1514 fi
1515 ;;
1516 esac
1517 append network_data "phase2=\"$phase2proto$auth\"" "$N$T"
1518 ;;
1519 esac
1520 append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T"
1521 ;;
1522 esac
1523
1524 [ "$wpa_cipher" = GCMP ] && {
1525 append network_data "pairwise=GCMP" "$N$T"
1526 append network_data "group=GCMP" "$N$T"
1527 }
1528
1529 [ "$mode" = mesh ] || {
1530 case "$wpa" in
1531 1)
1532 append network_data "proto=WPA" "$N$T"
1533 ;;
1534 2)
1535 append network_data "proto=RSN" "$N$T"
1536 ;;
1537 esac
1538
1539 case "$ieee80211w" in
1540 [012])
1541 [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T"
1542 ;;
1543 esac
1544 }
1545 [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T"
1546 [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T"
1547
1548 local bssid_blacklist bssid_whitelist
1549 json_get_values bssid_blacklist bssid_blacklist
1550 json_get_values bssid_whitelist bssid_whitelist
1551
1552 [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T"
1553 [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T"
1554
1555 [ -n "$basic_rate" ] && {
1556 local br rate_list=
1557 for br in $basic_rate; do
1558 wpa_supplicant_add_rate rate_list "$br"
1559 done
1560 [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T"
1561 }
1562
1563 [ -n "$mcast_rate" ] && {
1564 local mc_rate=
1565 wpa_supplicant_add_rate mc_rate "$mcast_rate"
1566 append network_data "mcast_rate=$mc_rate" "$N$T"
1567 }
1568
1569 if [ "$key_mgmt" = "WPS" ]; then
1570 echo "wps_cred_processing=1" >> "$_config"
1571 else
1572 cat >> "$_config" <<EOF
1573network={
1574 $scan_ssid
1575 ssid="$ssid"
1576 key_mgmt=$key_mgmt
1577 $network_data
1578}
1579EOF
1580 fi
1581 return 0
1582}
1583
1584wpa_supplicant_run() {
1585 local ifname="$1"
1586 local hostapd_ctrl="$2"
1587
1588 _wpa_supplicant_common "$ifname"
1589
1590 ubus wait_for wpa_supplicant
1591 local supplicant_res="$(ubus call wpa_supplicant config_add "{ \
1592 \"driver\": \"${_w_driver:-wext}\", \"ctrl\": \"$_rpath\", \
1593 \"iface\": \"$ifname\", \"config\": \"$_config\" \
1594 ${network_bridge:+, \"bridge\": \"$network_bridge\"} \
1595 ${hostapd_ctrl:+, \"hostapd_ctrl\": \"$hostapd_ctrl\"} \
1596 }")"
1597
1598 ret="$?"
1599
1600 [ "$ret" != 0 -o -z "$supplicant_res" ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
1601
1602 wireless_add_process "$(jsonfilter -s "$supplicant_res" -l 1 -e @.pid)" "/usr/sbin/wpa_supplicant" 1 1
1603
1604 return $ret
1605}
1606
1607hostapd_common_cleanup() {
1608 killall meshd-nl80211
1609}