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