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