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