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