1e28a4053SRui Paulo /* 2e28a4053SRui Paulo * hostapd / Configuration helper functions 3*a90b9d01SCy Schubert * Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi> 4e28a4053SRui Paulo * 5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license. 6f05cddf9SRui Paulo * See README for more details. 7e28a4053SRui Paulo */ 8e28a4053SRui Paulo 9e28a4053SRui Paulo #include "utils/includes.h" 10e28a4053SRui Paulo 11e28a4053SRui Paulo #include "utils/common.h" 12e28a4053SRui Paulo #include "crypto/sha1.h" 1385732ac8SCy Schubert #include "crypto/tls.h" 14e28a4053SRui Paulo #include "radius/radius_client.h" 15e28a4053SRui Paulo #include "common/ieee802_11_defs.h" 16206b73d0SCy Schubert #include "common/ieee802_1x_defs.h" 17e28a4053SRui Paulo #include "common/eapol_common.h" 1885732ac8SCy Schubert #include "common/dhcp.h" 19c1d255d3SCy Schubert #include "common/sae.h" 20e28a4053SRui Paulo #include "eap_common/eap_wsc_common.h" 21e28a4053SRui Paulo #include "eap_server/eap.h" 22e28a4053SRui Paulo #include "wpa_auth.h" 23e28a4053SRui Paulo #include "sta_info.h" 24206b73d0SCy Schubert #include "airtime_policy.h" 25e28a4053SRui Paulo #include "ap_config.h" 26e28a4053SRui Paulo 27e28a4053SRui Paulo 28e28a4053SRui Paulo static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) 29e28a4053SRui Paulo { 30e28a4053SRui Paulo struct hostapd_vlan *vlan, *prev; 31e28a4053SRui Paulo 32e28a4053SRui Paulo vlan = bss->vlan; 33e28a4053SRui Paulo prev = NULL; 34e28a4053SRui Paulo while (vlan) { 35e28a4053SRui Paulo prev = vlan; 36e28a4053SRui Paulo vlan = vlan->next; 37e28a4053SRui Paulo os_free(prev); 38e28a4053SRui Paulo } 39e28a4053SRui Paulo 40e28a4053SRui Paulo bss->vlan = NULL; 41e28a4053SRui Paulo } 42e28a4053SRui Paulo 43e28a4053SRui Paulo 4485732ac8SCy Schubert #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 4585732ac8SCy Schubert #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0 4685732ac8SCy Schubert #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */ 4785732ac8SCy Schubert 48e28a4053SRui Paulo void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) 49e28a4053SRui Paulo { 50780fb4a2SCy Schubert dl_list_init(&bss->anqp_elem); 51780fb4a2SCy Schubert 52e28a4053SRui Paulo bss->logger_syslog_level = HOSTAPD_LEVEL_INFO; 53e28a4053SRui Paulo bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; 54e28a4053SRui Paulo bss->logger_syslog = (unsigned int) -1; 55e28a4053SRui Paulo bss->logger_stdout = (unsigned int) -1; 56e28a4053SRui Paulo 57c1d255d3SCy Schubert #ifdef CONFIG_WEP 58e28a4053SRui Paulo bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED; 59e28a4053SRui Paulo 60e28a4053SRui Paulo bss->wep_rekeying_period = 300; 61e28a4053SRui Paulo /* use key0 in individual key and key1 in broadcast key */ 62e28a4053SRui Paulo bss->broadcast_key_idx_min = 1; 63e28a4053SRui Paulo bss->broadcast_key_idx_max = 2; 64c1d255d3SCy Schubert #else /* CONFIG_WEP */ 65c1d255d3SCy Schubert bss->auth_algs = WPA_AUTH_ALG_OPEN; 66c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 67e28a4053SRui Paulo bss->eap_reauth_period = 3600; 68e28a4053SRui Paulo 69e28a4053SRui Paulo bss->wpa_group_rekey = 600; 70e28a4053SRui Paulo bss->wpa_gmk_rekey = 86400; 71c1d255d3SCy Schubert bss->wpa_deny_ptk0_rekey = PTK0_REKEY_ALLOW_ALWAYS; 7285732ac8SCy Schubert bss->wpa_group_update_count = 4; 7385732ac8SCy Schubert bss->wpa_pairwise_update_count = 4; 7485732ac8SCy Schubert bss->wpa_disable_eapol_key_retries = 7585732ac8SCy Schubert DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES; 76e28a4053SRui Paulo bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; 77c1d255d3SCy Schubert #ifdef CONFIG_NO_TKIP 78c1d255d3SCy Schubert bss->wpa_pairwise = WPA_CIPHER_CCMP; 79c1d255d3SCy Schubert bss->wpa_group = WPA_CIPHER_CCMP; 80c1d255d3SCy Schubert #else /* CONFIG_NO_TKIP */ 81e28a4053SRui Paulo bss->wpa_pairwise = WPA_CIPHER_TKIP; 82e28a4053SRui Paulo bss->wpa_group = WPA_CIPHER_TKIP; 83c1d255d3SCy Schubert #endif /* CONFIG_NO_TKIP */ 84e28a4053SRui Paulo bss->rsn_pairwise = 0; 85e28a4053SRui Paulo 86e28a4053SRui Paulo bss->max_num_sta = MAX_STA_COUNT; 87e28a4053SRui Paulo 88e28a4053SRui Paulo bss->dtim_period = 2; 89e28a4053SRui Paulo 90e28a4053SRui Paulo bss->radius_server_auth_port = 1812; 91780fb4a2SCy Schubert bss->eap_sim_db_timeout = 1; 92206b73d0SCy Schubert bss->eap_sim_id = 3; 93*a90b9d01SCy Schubert bss->eap_sim_aka_fast_reauth_limit = 1000; 94e28a4053SRui Paulo bss->ap_max_inactivity = AP_MAX_INACTIVITY; 95*a90b9d01SCy Schubert bss->bss_max_idle = 1; 96e28a4053SRui Paulo bss->eapol_version = EAPOL_VERSION; 97e28a4053SRui Paulo 98e28a4053SRui Paulo bss->max_listen_interval = 65535; 99e28a4053SRui Paulo 100f05cddf9SRui Paulo bss->pwd_group = 19; /* ECC: GF(p=256) */ 101f05cddf9SRui Paulo 102e28a4053SRui Paulo bss->assoc_sa_query_max_timeout = 1000; 103e28a4053SRui Paulo bss->assoc_sa_query_retry_timeout = 201; 1045b9c547cSRui Paulo bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC; 105e28a4053SRui Paulo #ifdef EAP_SERVER_FAST 106e28a4053SRui Paulo /* both anonymous and authenticated provisioning */ 107e28a4053SRui Paulo bss->eap_fast_prov = 3; 108e28a4053SRui Paulo bss->pac_key_lifetime = 7 * 24 * 60 * 60; 109e28a4053SRui Paulo bss->pac_key_refresh_time = 1 * 24 * 60 * 60; 110e28a4053SRui Paulo #endif /* EAP_SERVER_FAST */ 111f05cddf9SRui Paulo 112f05cddf9SRui Paulo /* Set to -1 as defaults depends on HT in setup */ 113f05cddf9SRui Paulo bss->wmm_enabled = -1; 114f05cddf9SRui Paulo 11585732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP 116f05cddf9SRui Paulo bss->ft_over_ds = 1; 11785732ac8SCy Schubert bss->rkh_pos_timeout = 86400; 11885732ac8SCy Schubert bss->rkh_neg_timeout = 60; 11985732ac8SCy Schubert bss->rkh_pull_timeout = 1000; 12085732ac8SCy Schubert bss->rkh_pull_retries = 4; 12185732ac8SCy Schubert bss->r0_key_lifetime = 1209600; 12285732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */ 123f05cddf9SRui Paulo 124f05cddf9SRui Paulo bss->radius_das_time_window = 300; 125*a90b9d01SCy Schubert bss->radius_require_message_authenticator = 1; 1265b9c547cSRui Paulo 127c1d255d3SCy Schubert bss->anti_clogging_threshold = 5; 128*a90b9d01SCy Schubert bss->sae_sync = 3; 12985732ac8SCy Schubert 13085732ac8SCy Schubert bss->gas_frag_limit = 1400; 13185732ac8SCy Schubert 13285732ac8SCy Schubert #ifdef CONFIG_FILS 13385732ac8SCy Schubert dl_list_init(&bss->fils_realms); 13485732ac8SCy Schubert bss->fils_hlp_wait_time = 30; 13585732ac8SCy Schubert bss->dhcp_server_port = DHCP_SERVER_PORT; 13685732ac8SCy Schubert bss->dhcp_relay_port = DHCP_SERVER_PORT; 137c1d255d3SCy Schubert bss->fils_discovery_min_int = 20; 13885732ac8SCy Schubert #endif /* CONFIG_FILS */ 13985732ac8SCy Schubert 14085732ac8SCy Schubert bss->broadcast_deauth = 1; 14185732ac8SCy Schubert 14285732ac8SCy Schubert #ifdef CONFIG_MBO 14385732ac8SCy Schubert bss->mbo_cell_data_conn_pref = -1; 14485732ac8SCy Schubert #endif /* CONFIG_MBO */ 14585732ac8SCy Schubert 14685732ac8SCy Schubert /* Disable TLS v1.3 by default for now to avoid interoperability issue. 14785732ac8SCy Schubert * This can be enabled by default once the implementation has been fully 14885732ac8SCy Schubert * completed and tested with other implementations. */ 14985732ac8SCy Schubert bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3; 1504bc52338SCy Schubert 151c1d255d3SCy Schubert bss->max_auth_rounds = 100; 152c1d255d3SCy Schubert bss->max_auth_rounds_short = 50; 153c1d255d3SCy Schubert 1544bc52338SCy Schubert bss->send_probe_response = 1; 1554bc52338SCy Schubert 1564bc52338SCy Schubert #ifdef CONFIG_HS20 1574bc52338SCy Schubert bss->hs20_release = (HS20_VERSION >> 4) + 1; 1584bc52338SCy Schubert #endif /* CONFIG_HS20 */ 1594bc52338SCy Schubert 160206b73d0SCy Schubert #ifdef CONFIG_MACSEC 161206b73d0SCy Schubert bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER; 162206b73d0SCy Schubert bss->macsec_port = 1; 163206b73d0SCy Schubert #endif /* CONFIG_MACSEC */ 164206b73d0SCy Schubert 1654bc52338SCy Schubert /* Default to strict CRL checking. */ 1664bc52338SCy Schubert bss->check_crl_strict = 1; 167c1d255d3SCy Schubert 168*a90b9d01SCy Schubert bss->multi_ap_profile = MULTI_AP_PROFILE_2; 169*a90b9d01SCy Schubert 170c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS 171c1d255d3SCy Schubert bss->sae_commit_status = -1; 172*a90b9d01SCy Schubert bss->test_assoc_comeback_type = -1; 173c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */ 174c1d255d3SCy Schubert 175c1d255d3SCy Schubert #ifdef CONFIG_PASN 176c1d255d3SCy Schubert /* comeback after 10 TUs */ 177c1d255d3SCy Schubert bss->pasn_comeback_after = 10; 178*a90b9d01SCy Schubert bss->pasn_noauth = 1; 179c1d255d3SCy Schubert #endif /* CONFIG_PASN */ 180e28a4053SRui Paulo } 181e28a4053SRui Paulo 182e28a4053SRui Paulo 183e28a4053SRui Paulo struct hostapd_config * hostapd_config_defaults(void) 184e28a4053SRui Paulo { 185f05cddf9SRui Paulo #define ecw2cw(ecw) ((1 << (ecw)) - 1) 186f05cddf9SRui Paulo 187e28a4053SRui Paulo struct hostapd_config *conf; 188e28a4053SRui Paulo struct hostapd_bss_config *bss; 189e28a4053SRui Paulo const int aCWmin = 4, aCWmax = 10; 190e28a4053SRui Paulo const struct hostapd_wmm_ac_params ac_bk = 191e28a4053SRui Paulo { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */ 192e28a4053SRui Paulo const struct hostapd_wmm_ac_params ac_be = 193e28a4053SRui Paulo { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */ 194e28a4053SRui Paulo const struct hostapd_wmm_ac_params ac_vi = /* video traffic */ 1955b9c547cSRui Paulo { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 }; 196e28a4053SRui Paulo const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */ 1975b9c547cSRui Paulo { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 }; 198f05cddf9SRui Paulo const struct hostapd_tx_queue_params txq_bk = 199f05cddf9SRui Paulo { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 }; 200f05cddf9SRui Paulo const struct hostapd_tx_queue_params txq_be = 201f05cddf9SRui Paulo { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0}; 202f05cddf9SRui Paulo const struct hostapd_tx_queue_params txq_vi = 203f05cddf9SRui Paulo { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30}; 204f05cddf9SRui Paulo const struct hostapd_tx_queue_params txq_vo = 205f05cddf9SRui Paulo { 1, (ecw2cw(aCWmin) + 1) / 4 - 1, 206f05cddf9SRui Paulo (ecw2cw(aCWmin) + 1) / 2 - 1, 15}; 207f05cddf9SRui Paulo 208f05cddf9SRui Paulo #undef ecw2cw 209e28a4053SRui Paulo 210e28a4053SRui Paulo conf = os_zalloc(sizeof(*conf)); 211e28a4053SRui Paulo bss = os_zalloc(sizeof(*bss)); 212e28a4053SRui Paulo if (conf == NULL || bss == NULL) { 213e28a4053SRui Paulo wpa_printf(MSG_ERROR, "Failed to allocate memory for " 214e28a4053SRui Paulo "configuration data."); 215e28a4053SRui Paulo os_free(conf); 216e28a4053SRui Paulo os_free(bss); 217e28a4053SRui Paulo return NULL; 218e28a4053SRui Paulo } 2195b9c547cSRui Paulo conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *)); 2205b9c547cSRui Paulo if (conf->bss == NULL) { 2215b9c547cSRui Paulo os_free(conf); 2225b9c547cSRui Paulo os_free(bss); 2235b9c547cSRui Paulo return NULL; 2245b9c547cSRui Paulo } 2255b9c547cSRui Paulo conf->bss[0] = bss; 226e28a4053SRui Paulo 227e28a4053SRui Paulo bss->radius = os_zalloc(sizeof(*bss->radius)); 228e28a4053SRui Paulo if (bss->radius == NULL) { 2295b9c547cSRui Paulo os_free(conf->bss); 230e28a4053SRui Paulo os_free(conf); 231e28a4053SRui Paulo os_free(bss); 232e28a4053SRui Paulo return NULL; 233e28a4053SRui Paulo } 234e28a4053SRui Paulo 235e28a4053SRui Paulo hostapd_config_defaults_bss(bss); 236e28a4053SRui Paulo 237e28a4053SRui Paulo conf->num_bss = 1; 238e28a4053SRui Paulo 239e28a4053SRui Paulo conf->beacon_int = 100; 2404bc52338SCy Schubert conf->rts_threshold = -2; /* use driver default: 2347 */ 2414bc52338SCy Schubert conf->fragm_threshold = -2; /* user driver default: 2346 */ 2425b9c547cSRui Paulo /* Set to invalid value means do not add Power Constraint IE */ 2435b9c547cSRui Paulo conf->local_pwr_constraint = -1; 244e28a4053SRui Paulo 245e28a4053SRui Paulo conf->wmm_ac_params[0] = ac_be; 246e28a4053SRui Paulo conf->wmm_ac_params[1] = ac_bk; 247e28a4053SRui Paulo conf->wmm_ac_params[2] = ac_vi; 248e28a4053SRui Paulo conf->wmm_ac_params[3] = ac_vo; 249e28a4053SRui Paulo 250f05cddf9SRui Paulo conf->tx_queue[0] = txq_vo; 251f05cddf9SRui Paulo conf->tx_queue[1] = txq_vi; 252f05cddf9SRui Paulo conf->tx_queue[2] = txq_be; 253f05cddf9SRui Paulo conf->tx_queue[3] = txq_bk; 254f05cddf9SRui Paulo 255e28a4053SRui Paulo conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED; 256e28a4053SRui Paulo 257f05cddf9SRui Paulo conf->ap_table_max_size = 255; 258f05cddf9SRui Paulo conf->ap_table_expiration_time = 60; 259325151a3SRui Paulo conf->track_sta_max_age = 180; 260f05cddf9SRui Paulo 2615b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS 2625b9c547cSRui Paulo conf->ignore_probe_probability = 0.0; 2635b9c547cSRui Paulo conf->ignore_auth_probability = 0.0; 2645b9c547cSRui Paulo conf->ignore_assoc_probability = 0.0; 2655b9c547cSRui Paulo conf->ignore_reassoc_probability = 0.0; 2665b9c547cSRui Paulo conf->corrupt_gtk_rekey_mic_probability = 0.0; 267780fb4a2SCy Schubert conf->ecsa_ie_only = 0; 2685b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */ 2695b9c547cSRui Paulo 270325151a3SRui Paulo conf->acs = 0; 271325151a3SRui Paulo conf->acs_ch_list.num = 0; 2725b9c547cSRui Paulo #ifdef CONFIG_ACS 2735b9c547cSRui Paulo conf->acs_num_scans = 5; 2745b9c547cSRui Paulo #endif /* CONFIG_ACS */ 2755b9c547cSRui Paulo 276206b73d0SCy Schubert #ifdef CONFIG_IEEE80211AX 277206b73d0SCy Schubert conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >> 278206b73d0SCy Schubert HE_OPERATION_RTS_THRESHOLD_OFFSET; 279206b73d0SCy Schubert /* Set default basic MCS/NSS set to single stream MCS 0-7 */ 280206b73d0SCy Schubert conf->he_op.he_basic_mcs_nss_set = 0xfffc; 281c1d255d3SCy Schubert conf->he_op.he_bss_color_disabled = 1; 282c1d255d3SCy Schubert conf->he_op.he_bss_color_partial = 0; 2834b72b91aSCy Schubert conf->he_op.he_bss_color = os_random() % 63 + 1; 284c1d255d3SCy Schubert conf->he_op.he_twt_responder = 1; 285c1d255d3SCy Schubert conf->he_6ghz_max_mpdu = 2; 286c1d255d3SCy Schubert conf->he_6ghz_max_ampdu_len_exp = 7; 287c1d255d3SCy Schubert conf->he_6ghz_rx_ant_pat = 1; 288c1d255d3SCy Schubert conf->he_6ghz_tx_ant_pat = 1; 289*a90b9d01SCy Schubert conf->he_6ghz_reg_pwr_type = HE_REG_INFO_6GHZ_AP_TYPE_VLP; 290*a90b9d01SCy Schubert conf->reg_def_cli_eirp_psd = -1; 291*a90b9d01SCy Schubert conf->reg_sub_cli_eirp_psd = -1; 292*a90b9d01SCy Schubert conf->reg_def_cli_eirp = -1; 293206b73d0SCy Schubert #endif /* CONFIG_IEEE80211AX */ 294206b73d0SCy Schubert 29585732ac8SCy Schubert /* The third octet of the country string uses an ASCII space character 29685732ac8SCy Schubert * by default to indicate that the regulations encompass all 29785732ac8SCy Schubert * environments for the current frequency band in the country. */ 29885732ac8SCy Schubert conf->country[2] = ' '; 29985732ac8SCy Schubert 3004bc52338SCy Schubert conf->rssi_reject_assoc_rssi = 0; 3014bc52338SCy Schubert conf->rssi_reject_assoc_timeout = 30; 3024bc52338SCy Schubert 303206b73d0SCy Schubert #ifdef CONFIG_AIRTIME_POLICY 304206b73d0SCy Schubert conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL; 305206b73d0SCy Schubert #endif /* CONFIG_AIRTIME_POLICY */ 306206b73d0SCy Schubert 307*a90b9d01SCy Schubert hostapd_set_and_check_bw320_offset(conf, 0); 308*a90b9d01SCy Schubert 309e28a4053SRui Paulo return conf; 310e28a4053SRui Paulo } 311e28a4053SRui Paulo 312e28a4053SRui Paulo 313e28a4053SRui Paulo int hostapd_mac_comp(const void *a, const void *b) 314e28a4053SRui Paulo { 315e28a4053SRui Paulo return os_memcmp(a, b, sizeof(macaddr)); 316e28a4053SRui Paulo } 317e28a4053SRui Paulo 318e28a4053SRui Paulo 319e28a4053SRui Paulo static int hostapd_config_read_wpa_psk(const char *fname, 320e28a4053SRui Paulo struct hostapd_ssid *ssid) 321e28a4053SRui Paulo { 322e28a4053SRui Paulo FILE *f; 323e28a4053SRui Paulo char buf[128], *pos; 3244bc52338SCy Schubert const char *keyid; 3254bc52338SCy Schubert char *context; 3264bc52338SCy Schubert char *context2; 3274bc52338SCy Schubert char *token; 3284bc52338SCy Schubert char *name; 3294bc52338SCy Schubert char *value; 330e28a4053SRui Paulo int line = 0, ret = 0, len, ok; 331e28a4053SRui Paulo u8 addr[ETH_ALEN]; 332e28a4053SRui Paulo struct hostapd_wpa_psk *psk; 333e28a4053SRui Paulo 334e28a4053SRui Paulo if (!fname) 335e28a4053SRui Paulo return 0; 336e28a4053SRui Paulo 337e28a4053SRui Paulo f = fopen(fname, "r"); 338e28a4053SRui Paulo if (!f) { 339e28a4053SRui Paulo wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname); 340e28a4053SRui Paulo return -1; 341e28a4053SRui Paulo } 342e28a4053SRui Paulo 343e28a4053SRui Paulo while (fgets(buf, sizeof(buf), f)) { 3444bc52338SCy Schubert int vlan_id = 0; 345c1d255d3SCy Schubert int wps = 0; 3464bc52338SCy Schubert 347e28a4053SRui Paulo line++; 348e28a4053SRui Paulo 349e28a4053SRui Paulo if (buf[0] == '#') 350e28a4053SRui Paulo continue; 351e28a4053SRui Paulo pos = buf; 352e28a4053SRui Paulo while (*pos != '\0') { 353e28a4053SRui Paulo if (*pos == '\n') { 354e28a4053SRui Paulo *pos = '\0'; 355e28a4053SRui Paulo break; 356e28a4053SRui Paulo } 357e28a4053SRui Paulo pos++; 358e28a4053SRui Paulo } 359e28a4053SRui Paulo if (buf[0] == '\0') 360e28a4053SRui Paulo continue; 361e28a4053SRui Paulo 3624bc52338SCy Schubert context = NULL; 3634bc52338SCy Schubert keyid = NULL; 3644bc52338SCy Schubert while ((token = str_token(buf, " ", &context))) { 3654bc52338SCy Schubert if (!os_strchr(token, '=')) 3664bc52338SCy Schubert break; 3674bc52338SCy Schubert context2 = NULL; 3684bc52338SCy Schubert name = str_token(token, "=", &context2); 3694bc52338SCy Schubert if (!name) 3704bc52338SCy Schubert break; 3714bc52338SCy Schubert value = str_token(token, "", &context2); 3724bc52338SCy Schubert if (!value) 3734bc52338SCy Schubert value = ""; 3744bc52338SCy Schubert if (!os_strcmp(name, "keyid")) { 3754bc52338SCy Schubert keyid = value; 376c1d255d3SCy Schubert } else if (!os_strcmp(name, "wps")) { 377c1d255d3SCy Schubert wps = atoi(value); 3784bc52338SCy Schubert } else if (!os_strcmp(name, "vlanid")) { 3794bc52338SCy Schubert vlan_id = atoi(value); 3804bc52338SCy Schubert } else { 3814bc52338SCy Schubert wpa_printf(MSG_ERROR, 3824bc52338SCy Schubert "Unrecognized '%s=%s' on line %d in '%s'", 3834bc52338SCy Schubert name, value, line, fname); 3844bc52338SCy Schubert ret = -1; 3854bc52338SCy Schubert break; 3864bc52338SCy Schubert } 3874bc52338SCy Schubert } 3884bc52338SCy Schubert 3894bc52338SCy Schubert if (ret == -1) 3904bc52338SCy Schubert break; 3914bc52338SCy Schubert 3924bc52338SCy Schubert if (!token) 3934bc52338SCy Schubert token = ""; 3944bc52338SCy Schubert if (hwaddr_aton(token, addr)) { 395c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 396c1d255d3SCy Schubert "Invalid MAC address '%s' on line %d in '%s'", 397c1d255d3SCy Schubert token, line, fname); 398e28a4053SRui Paulo ret = -1; 399e28a4053SRui Paulo break; 400e28a4053SRui Paulo } 401e28a4053SRui Paulo 402e28a4053SRui Paulo psk = os_zalloc(sizeof(*psk)); 403e28a4053SRui Paulo if (psk == NULL) { 404e28a4053SRui Paulo wpa_printf(MSG_ERROR, "WPA PSK allocation failed"); 405e28a4053SRui Paulo ret = -1; 406e28a4053SRui Paulo break; 407e28a4053SRui Paulo } 4084bc52338SCy Schubert psk->vlan_id = vlan_id; 409e28a4053SRui Paulo if (is_zero_ether_addr(addr)) 410e28a4053SRui Paulo psk->group = 1; 411e28a4053SRui Paulo else 412e28a4053SRui Paulo os_memcpy(psk->addr, addr, ETH_ALEN); 413e28a4053SRui Paulo 4144bc52338SCy Schubert pos = str_token(buf, "", &context); 4154bc52338SCy Schubert if (!pos) { 416e28a4053SRui Paulo wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", 417e28a4053SRui Paulo line, fname); 418e28a4053SRui Paulo os_free(psk); 419e28a4053SRui Paulo ret = -1; 420e28a4053SRui Paulo break; 421e28a4053SRui Paulo } 422e28a4053SRui Paulo 423e28a4053SRui Paulo ok = 0; 424e28a4053SRui Paulo len = os_strlen(pos); 425c1d255d3SCy Schubert if (len == 2 * PMK_LEN && 426c1d255d3SCy Schubert hexstr2bin(pos, psk->psk, PMK_LEN) == 0) 427e28a4053SRui Paulo ok = 1; 428c1d255d3SCy Schubert else if (len >= 8 && len < 64 && 429e28a4053SRui Paulo pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, 430c1d255d3SCy Schubert 4096, psk->psk, PMK_LEN) == 0) 431e28a4053SRui Paulo ok = 1; 432e28a4053SRui Paulo if (!ok) { 433c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 434c1d255d3SCy Schubert "Invalid PSK '%s' on line %d in '%s'", 435c1d255d3SCy Schubert pos, line, fname); 436e28a4053SRui Paulo os_free(psk); 437e28a4053SRui Paulo ret = -1; 438e28a4053SRui Paulo break; 439e28a4053SRui Paulo } 440e28a4053SRui Paulo 4414bc52338SCy Schubert if (keyid) { 4424bc52338SCy Schubert len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid)); 4434bc52338SCy Schubert if ((size_t) len >= sizeof(psk->keyid)) { 4444bc52338SCy Schubert wpa_printf(MSG_ERROR, 4454bc52338SCy Schubert "PSK keyid too long on line %d in '%s'", 4464bc52338SCy Schubert line, fname); 4474bc52338SCy Schubert os_free(psk); 4484bc52338SCy Schubert ret = -1; 4494bc52338SCy Schubert break; 4504bc52338SCy Schubert } 4514bc52338SCy Schubert } 4524bc52338SCy Schubert 453c1d255d3SCy Schubert psk->wps = wps; 454c1d255d3SCy Schubert 455e28a4053SRui Paulo psk->next = ssid->wpa_psk; 456e28a4053SRui Paulo ssid->wpa_psk = psk; 457e28a4053SRui Paulo } 458e28a4053SRui Paulo 459e28a4053SRui Paulo fclose(f); 460e28a4053SRui Paulo 461e28a4053SRui Paulo return ret; 462e28a4053SRui Paulo } 463e28a4053SRui Paulo 464e28a4053SRui Paulo 465e28a4053SRui Paulo static int hostapd_derive_psk(struct hostapd_ssid *ssid) 466e28a4053SRui Paulo { 467e28a4053SRui Paulo ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); 468e28a4053SRui Paulo if (ssid->wpa_psk == NULL) { 469e28a4053SRui Paulo wpa_printf(MSG_ERROR, "Unable to alloc space for PSK"); 470e28a4053SRui Paulo return -1; 471e28a4053SRui Paulo } 472e28a4053SRui Paulo wpa_hexdump_ascii(MSG_DEBUG, "SSID", 473e28a4053SRui Paulo (u8 *) ssid->ssid, ssid->ssid_len); 474e28a4053SRui Paulo wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)", 475e28a4053SRui Paulo (u8 *) ssid->wpa_passphrase, 476e28a4053SRui Paulo os_strlen(ssid->wpa_passphrase)); 477*a90b9d01SCy Schubert if (pbkdf2_sha1(ssid->wpa_passphrase, 478e28a4053SRui Paulo ssid->ssid, ssid->ssid_len, 479*a90b9d01SCy Schubert 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) { 480*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()"); 481*a90b9d01SCy Schubert return -1; 482*a90b9d01SCy Schubert } 483e28a4053SRui Paulo wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)", 484e28a4053SRui Paulo ssid->wpa_psk->psk, PMK_LEN); 485e28a4053SRui Paulo return 0; 486e28a4053SRui Paulo } 487e28a4053SRui Paulo 488e28a4053SRui Paulo 489c1d255d3SCy Schubert int hostapd_setup_sae_pt(struct hostapd_bss_config *conf) 490c1d255d3SCy Schubert { 491c1d255d3SCy Schubert #ifdef CONFIG_SAE 492c1d255d3SCy Schubert struct hostapd_ssid *ssid = &conf->ssid; 493c1d255d3SCy Schubert struct sae_password_entry *pw; 494c1d255d3SCy Schubert 495*a90b9d01SCy Schubert if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK && 496*a90b9d01SCy Schubert !hostapd_sae_pw_id_in_use(conf) && 497*a90b9d01SCy Schubert !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) && 498c1d255d3SCy Schubert !hostapd_sae_pk_in_use(conf)) || 499*a90b9d01SCy Schubert conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK || 500c1d255d3SCy Schubert !wpa_key_mgmt_sae(conf->wpa_key_mgmt)) 501c1d255d3SCy Schubert return 0; /* PT not needed */ 502c1d255d3SCy Schubert 503c1d255d3SCy Schubert sae_deinit_pt(ssid->pt); 504c1d255d3SCy Schubert ssid->pt = NULL; 505c1d255d3SCy Schubert if (ssid->wpa_passphrase) { 506c1d255d3SCy Schubert ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid, 507c1d255d3SCy Schubert ssid->ssid_len, 508c1d255d3SCy Schubert (const u8 *) ssid->wpa_passphrase, 509c1d255d3SCy Schubert os_strlen(ssid->wpa_passphrase), 510c1d255d3SCy Schubert NULL); 511c1d255d3SCy Schubert if (!ssid->pt) 512c1d255d3SCy Schubert return -1; 513c1d255d3SCy Schubert } 514c1d255d3SCy Schubert 515c1d255d3SCy Schubert for (pw = conf->sae_passwords; pw; pw = pw->next) { 516c1d255d3SCy Schubert sae_deinit_pt(pw->pt); 517c1d255d3SCy Schubert pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid, 518c1d255d3SCy Schubert ssid->ssid_len, 519c1d255d3SCy Schubert (const u8 *) pw->password, 520c1d255d3SCy Schubert os_strlen(pw->password), 521c1d255d3SCy Schubert pw->identifier); 522c1d255d3SCy Schubert if (!pw->pt) 523c1d255d3SCy Schubert return -1; 524c1d255d3SCy Schubert } 525c1d255d3SCy Schubert #endif /* CONFIG_SAE */ 526c1d255d3SCy Schubert 527c1d255d3SCy Schubert return 0; 528c1d255d3SCy Schubert } 529c1d255d3SCy Schubert 530c1d255d3SCy Schubert 531e28a4053SRui Paulo int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) 532e28a4053SRui Paulo { 533e28a4053SRui Paulo struct hostapd_ssid *ssid = &conf->ssid; 534e28a4053SRui Paulo 535c1d255d3SCy Schubert if (hostapd_setup_sae_pt(conf) < 0) 536c1d255d3SCy Schubert return -1; 537c1d255d3SCy Schubert 538e28a4053SRui Paulo if (ssid->wpa_passphrase != NULL) { 539e28a4053SRui Paulo if (ssid->wpa_psk != NULL) { 540e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK " 541e28a4053SRui Paulo "instead of passphrase"); 542e28a4053SRui Paulo } else { 543e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on " 544e28a4053SRui Paulo "passphrase"); 545e28a4053SRui Paulo if (hostapd_derive_psk(ssid) < 0) 546e28a4053SRui Paulo return -1; 547e28a4053SRui Paulo } 548e28a4053SRui Paulo ssid->wpa_psk->group = 1; 549e28a4053SRui Paulo } 550e28a4053SRui Paulo 55185732ac8SCy Schubert return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid); 552e28a4053SRui Paulo } 553e28a4053SRui Paulo 554e28a4053SRui Paulo 555e28a4053SRui Paulo static void hostapd_config_free_radius(struct hostapd_radius_server *servers, 556e28a4053SRui Paulo int num_servers) 557e28a4053SRui Paulo { 558e28a4053SRui Paulo int i; 559e28a4053SRui Paulo 560e28a4053SRui Paulo for (i = 0; i < num_servers; i++) { 561e28a4053SRui Paulo os_free(servers[i].shared_secret); 562*a90b9d01SCy Schubert os_free(servers[i].ca_cert); 563*a90b9d01SCy Schubert os_free(servers[i].client_cert); 564*a90b9d01SCy Schubert os_free(servers[i].private_key); 565*a90b9d01SCy Schubert os_free(servers[i].private_key_passwd); 566e28a4053SRui Paulo } 567e28a4053SRui Paulo os_free(servers); 568e28a4053SRui Paulo } 569e28a4053SRui Paulo 570e28a4053SRui Paulo 571f05cddf9SRui Paulo struct hostapd_radius_attr * 572f05cddf9SRui Paulo hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) 573f05cddf9SRui Paulo { 574f05cddf9SRui Paulo for (; attr; attr = attr->next) { 575f05cddf9SRui Paulo if (attr->type == type) 576f05cddf9SRui Paulo return attr; 577f05cddf9SRui Paulo } 578f05cddf9SRui Paulo return NULL; 579f05cddf9SRui Paulo } 580f05cddf9SRui Paulo 581f05cddf9SRui Paulo 582206b73d0SCy Schubert struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value) 583206b73d0SCy Schubert { 584206b73d0SCy Schubert const char *pos; 585206b73d0SCy Schubert char syntax; 586206b73d0SCy Schubert struct hostapd_radius_attr *attr; 587206b73d0SCy Schubert size_t len; 588206b73d0SCy Schubert 589206b73d0SCy Schubert attr = os_zalloc(sizeof(*attr)); 590206b73d0SCy Schubert if (!attr) 591206b73d0SCy Schubert return NULL; 592206b73d0SCy Schubert 593206b73d0SCy Schubert attr->type = atoi(value); 594206b73d0SCy Schubert 595206b73d0SCy Schubert pos = os_strchr(value, ':'); 596206b73d0SCy Schubert if (!pos) { 597206b73d0SCy Schubert attr->val = wpabuf_alloc(1); 598206b73d0SCy Schubert if (!attr->val) { 599206b73d0SCy Schubert os_free(attr); 600206b73d0SCy Schubert return NULL; 601206b73d0SCy Schubert } 602206b73d0SCy Schubert wpabuf_put_u8(attr->val, 0); 603206b73d0SCy Schubert return attr; 604206b73d0SCy Schubert } 605206b73d0SCy Schubert 606206b73d0SCy Schubert pos++; 607206b73d0SCy Schubert if (pos[0] == '\0' || pos[1] != ':') { 608206b73d0SCy Schubert os_free(attr); 609206b73d0SCy Schubert return NULL; 610206b73d0SCy Schubert } 611206b73d0SCy Schubert syntax = *pos++; 612206b73d0SCy Schubert pos++; 613206b73d0SCy Schubert 614206b73d0SCy Schubert switch (syntax) { 615206b73d0SCy Schubert case 's': 616206b73d0SCy Schubert attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); 617206b73d0SCy Schubert break; 618206b73d0SCy Schubert case 'x': 619206b73d0SCy Schubert len = os_strlen(pos); 620206b73d0SCy Schubert if (len & 1) 621206b73d0SCy Schubert break; 622206b73d0SCy Schubert len /= 2; 623206b73d0SCy Schubert attr->val = wpabuf_alloc(len); 624206b73d0SCy Schubert if (!attr->val) 625206b73d0SCy Schubert break; 626206b73d0SCy Schubert if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { 627206b73d0SCy Schubert wpabuf_free(attr->val); 628206b73d0SCy Schubert os_free(attr); 629206b73d0SCy Schubert return NULL; 630206b73d0SCy Schubert } 631206b73d0SCy Schubert break; 632206b73d0SCy Schubert case 'd': 633206b73d0SCy Schubert attr->val = wpabuf_alloc(4); 634206b73d0SCy Schubert if (attr->val) 635206b73d0SCy Schubert wpabuf_put_be32(attr->val, atoi(pos)); 636206b73d0SCy Schubert break; 637206b73d0SCy Schubert default: 638206b73d0SCy Schubert os_free(attr); 639206b73d0SCy Schubert return NULL; 640206b73d0SCy Schubert } 641206b73d0SCy Schubert 642206b73d0SCy Schubert if (!attr->val) { 643206b73d0SCy Schubert os_free(attr); 644206b73d0SCy Schubert return NULL; 645206b73d0SCy Schubert } 646206b73d0SCy Schubert 647206b73d0SCy Schubert return attr; 648206b73d0SCy Schubert } 649206b73d0SCy Schubert 650206b73d0SCy Schubert 651206b73d0SCy Schubert void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) 652f05cddf9SRui Paulo { 653f05cddf9SRui Paulo struct hostapd_radius_attr *prev; 654f05cddf9SRui Paulo 655f05cddf9SRui Paulo while (attr) { 656f05cddf9SRui Paulo prev = attr; 657f05cddf9SRui Paulo attr = attr->next; 658f05cddf9SRui Paulo wpabuf_free(prev->val); 659f05cddf9SRui Paulo os_free(prev); 660f05cddf9SRui Paulo } 661f05cddf9SRui Paulo } 662f05cddf9SRui Paulo 663f05cddf9SRui Paulo 6645b9c547cSRui Paulo void hostapd_config_free_eap_user(struct hostapd_eap_user *user) 665e28a4053SRui Paulo { 6665b9c547cSRui Paulo hostapd_config_free_radius_attr(user->accept_attr); 667e28a4053SRui Paulo os_free(user->identity); 6685b9c547cSRui Paulo bin_clear_free(user->password, user->password_len); 66985732ac8SCy Schubert bin_clear_free(user->salt, user->salt_len); 670e28a4053SRui Paulo os_free(user); 671e28a4053SRui Paulo } 672e28a4053SRui Paulo 673e28a4053SRui Paulo 67485732ac8SCy Schubert void hostapd_config_free_eap_users(struct hostapd_eap_user *user) 67585732ac8SCy Schubert { 67685732ac8SCy Schubert struct hostapd_eap_user *prev_user; 67785732ac8SCy Schubert 67885732ac8SCy Schubert while (user) { 67985732ac8SCy Schubert prev_user = user; 68085732ac8SCy Schubert user = user->next; 68185732ac8SCy Schubert hostapd_config_free_eap_user(prev_user); 68285732ac8SCy Schubert } 68385732ac8SCy Schubert } 68485732ac8SCy Schubert 68585732ac8SCy Schubert 686c1d255d3SCy Schubert #ifdef CONFIG_WEP 687e28a4053SRui Paulo static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) 688e28a4053SRui Paulo { 689e28a4053SRui Paulo int i; 690e28a4053SRui Paulo for (i = 0; i < NUM_WEP_KEYS; i++) { 6915b9c547cSRui Paulo bin_clear_free(keys->key[i], keys->len[i]); 692e28a4053SRui Paulo keys->key[i] = NULL; 693e28a4053SRui Paulo } 694e28a4053SRui Paulo } 695c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 696e28a4053SRui Paulo 697e28a4053SRui Paulo 6985b9c547cSRui Paulo void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l) 699e28a4053SRui Paulo { 7005b9c547cSRui Paulo struct hostapd_wpa_psk *psk, *tmp; 7015b9c547cSRui Paulo 7025b9c547cSRui Paulo for (psk = *l; psk;) { 7035b9c547cSRui Paulo tmp = psk; 7045b9c547cSRui Paulo psk = psk->next; 7055b9c547cSRui Paulo bin_clear_free(tmp, sizeof(*tmp)); 7065b9c547cSRui Paulo } 7075b9c547cSRui Paulo *l = NULL; 7085b9c547cSRui Paulo } 7095b9c547cSRui Paulo 7105b9c547cSRui Paulo 711*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211R_AP 712*a90b9d01SCy Schubert 713*a90b9d01SCy Schubert void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf) 714*a90b9d01SCy Schubert { 715*a90b9d01SCy Schubert struct ft_remote_r0kh *r0kh, *r0kh_prev; 716*a90b9d01SCy Schubert struct ft_remote_r1kh *r1kh, *r1kh_prev; 717*a90b9d01SCy Schubert 718*a90b9d01SCy Schubert r0kh = conf->r0kh_list; 719*a90b9d01SCy Schubert conf->r0kh_list = NULL; 720*a90b9d01SCy Schubert while (r0kh) { 721*a90b9d01SCy Schubert r0kh_prev = r0kh; 722*a90b9d01SCy Schubert r0kh = r0kh->next; 723*a90b9d01SCy Schubert os_free(r0kh_prev); 724*a90b9d01SCy Schubert } 725*a90b9d01SCy Schubert 726*a90b9d01SCy Schubert r1kh = conf->r1kh_list; 727*a90b9d01SCy Schubert conf->r1kh_list = NULL; 728*a90b9d01SCy Schubert while (r1kh) { 729*a90b9d01SCy Schubert r1kh_prev = r1kh; 730*a90b9d01SCy Schubert r1kh = r1kh->next; 731*a90b9d01SCy Schubert os_free(r1kh_prev); 732*a90b9d01SCy Schubert } 733*a90b9d01SCy Schubert } 734*a90b9d01SCy Schubert 735*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211R_AP */ 736*a90b9d01SCy Schubert 737*a90b9d01SCy Schubert 738780fb4a2SCy Schubert static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf) 739780fb4a2SCy Schubert { 740780fb4a2SCy Schubert struct anqp_element *elem; 741780fb4a2SCy Schubert 742780fb4a2SCy Schubert while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element, 743780fb4a2SCy Schubert list))) { 744780fb4a2SCy Schubert dl_list_del(&elem->list); 745780fb4a2SCy Schubert wpabuf_free(elem->payload); 746780fb4a2SCy Schubert os_free(elem); 747780fb4a2SCy Schubert } 748780fb4a2SCy Schubert } 749780fb4a2SCy Schubert 750780fb4a2SCy Schubert 75185732ac8SCy Schubert static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf) 75285732ac8SCy Schubert { 75385732ac8SCy Schubert #ifdef CONFIG_FILS 75485732ac8SCy Schubert struct fils_realm *realm; 75585732ac8SCy Schubert 75685732ac8SCy Schubert while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm, 75785732ac8SCy Schubert list))) { 75885732ac8SCy Schubert dl_list_del(&realm->list); 75985732ac8SCy Schubert os_free(realm); 76085732ac8SCy Schubert } 76185732ac8SCy Schubert #endif /* CONFIG_FILS */ 76285732ac8SCy Schubert } 76385732ac8SCy Schubert 76485732ac8SCy Schubert 76585732ac8SCy Schubert static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf) 76685732ac8SCy Schubert { 76785732ac8SCy Schubert struct sae_password_entry *pw, *tmp; 76885732ac8SCy Schubert 76985732ac8SCy Schubert pw = conf->sae_passwords; 77085732ac8SCy Schubert conf->sae_passwords = NULL; 77185732ac8SCy Schubert while (pw) { 77285732ac8SCy Schubert tmp = pw; 77385732ac8SCy Schubert pw = pw->next; 77485732ac8SCy Schubert str_clear_free(tmp->password); 77585732ac8SCy Schubert os_free(tmp->identifier); 776c1d255d3SCy Schubert #ifdef CONFIG_SAE 777c1d255d3SCy Schubert sae_deinit_pt(tmp->pt); 778c1d255d3SCy Schubert #endif /* CONFIG_SAE */ 779c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK 780c1d255d3SCy Schubert sae_deinit_pk(tmp->pk); 781c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */ 78285732ac8SCy Schubert os_free(tmp); 78385732ac8SCy Schubert } 78485732ac8SCy Schubert } 78585732ac8SCy Schubert 78685732ac8SCy Schubert 787206b73d0SCy Schubert #ifdef CONFIG_DPP2 788206b73d0SCy Schubert static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf) 789206b73d0SCy Schubert { 790206b73d0SCy Schubert struct dpp_controller_conf *prev; 791206b73d0SCy Schubert 792206b73d0SCy Schubert while (conf) { 793206b73d0SCy Schubert prev = conf; 794206b73d0SCy Schubert conf = conf->next; 795206b73d0SCy Schubert os_free(prev); 796206b73d0SCy Schubert } 797206b73d0SCy Schubert } 798206b73d0SCy Schubert #endif /* CONFIG_DPP2 */ 799206b73d0SCy Schubert 800206b73d0SCy Schubert 8015b9c547cSRui Paulo void hostapd_config_free_bss(struct hostapd_bss_config *conf) 8025b9c547cSRui Paulo { 803206b73d0SCy Schubert #if defined(CONFIG_WPS) || defined(CONFIG_HS20) 804206b73d0SCy Schubert size_t i; 805206b73d0SCy Schubert #endif 806206b73d0SCy Schubert 807e28a4053SRui Paulo if (conf == NULL) 808e28a4053SRui Paulo return; 809e28a4053SRui Paulo 8105b9c547cSRui Paulo hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk); 811e28a4053SRui Paulo 8125b9c547cSRui Paulo str_clear_free(conf->ssid.wpa_passphrase); 813e28a4053SRui Paulo os_free(conf->ssid.wpa_psk_file); 814c1d255d3SCy Schubert #ifdef CONFIG_WEP 815e28a4053SRui Paulo hostapd_config_free_wep(&conf->ssid.wep); 816c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 817e28a4053SRui Paulo #ifdef CONFIG_FULL_DYNAMIC_VLAN 818e28a4053SRui Paulo os_free(conf->ssid.vlan_tagged_interface); 819e28a4053SRui Paulo #endif /* CONFIG_FULL_DYNAMIC_VLAN */ 820c1d255d3SCy Schubert #ifdef CONFIG_SAE 821c1d255d3SCy Schubert sae_deinit_pt(conf->ssid.pt); 822c1d255d3SCy Schubert #endif /* CONFIG_SAE */ 823e28a4053SRui Paulo 82485732ac8SCy Schubert hostapd_config_free_eap_users(conf->eap_user); 825f05cddf9SRui Paulo os_free(conf->eap_user_sqlite); 826e28a4053SRui Paulo 827e28a4053SRui Paulo os_free(conf->eap_req_id_text); 8285b9c547cSRui Paulo os_free(conf->erp_domain); 829e28a4053SRui Paulo os_free(conf->accept_mac); 830e28a4053SRui Paulo os_free(conf->deny_mac); 831e28a4053SRui Paulo os_free(conf->nas_identifier); 8325b9c547cSRui Paulo if (conf->radius) { 833e28a4053SRui Paulo hostapd_config_free_radius(conf->radius->auth_servers, 834e28a4053SRui Paulo conf->radius->num_auth_servers); 835e28a4053SRui Paulo hostapd_config_free_radius(conf->radius->acct_servers, 836e28a4053SRui Paulo conf->radius->num_acct_servers); 837c1d255d3SCy Schubert os_free(conf->radius->force_client_dev); 8385b9c547cSRui Paulo } 839f05cddf9SRui Paulo hostapd_config_free_radius_attr(conf->radius_auth_req_attr); 840f05cddf9SRui Paulo hostapd_config_free_radius_attr(conf->radius_acct_req_attr); 841206b73d0SCy Schubert os_free(conf->radius_req_attr_sqlite); 842e28a4053SRui Paulo os_free(conf->rsn_preauth_interfaces); 843e28a4053SRui Paulo os_free(conf->ctrl_interface); 844*a90b9d01SCy Schubert os_free(conf->config_id); 845e28a4053SRui Paulo os_free(conf->ca_cert); 846e28a4053SRui Paulo os_free(conf->server_cert); 847206b73d0SCy Schubert os_free(conf->server_cert2); 848e28a4053SRui Paulo os_free(conf->private_key); 849206b73d0SCy Schubert os_free(conf->private_key2); 850e28a4053SRui Paulo os_free(conf->private_key_passwd); 851206b73d0SCy Schubert os_free(conf->private_key_passwd2); 8524bc52338SCy Schubert os_free(conf->check_cert_subject); 8535b9c547cSRui Paulo os_free(conf->ocsp_stapling_response); 854780fb4a2SCy Schubert os_free(conf->ocsp_stapling_response_multi); 855e28a4053SRui Paulo os_free(conf->dh_file); 8565b9c547cSRui Paulo os_free(conf->openssl_ciphers); 8574bc52338SCy Schubert os_free(conf->openssl_ecdh_curves); 858e28a4053SRui Paulo os_free(conf->pac_opaque_encr_key); 859e28a4053SRui Paulo os_free(conf->eap_fast_a_id); 860e28a4053SRui Paulo os_free(conf->eap_fast_a_id_info); 861e28a4053SRui Paulo os_free(conf->eap_sim_db); 862*a90b9d01SCy Schubert os_free(conf->imsi_privacy_key); 863e28a4053SRui Paulo os_free(conf->radius_server_clients); 864e28a4053SRui Paulo os_free(conf->radius); 865f05cddf9SRui Paulo os_free(conf->radius_das_shared_secret); 866e28a4053SRui Paulo hostapd_config_free_vlan(conf); 867f05cddf9SRui Paulo os_free(conf->time_zone); 868f05cddf9SRui Paulo 86985732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP 870*a90b9d01SCy Schubert hostapd_config_clear_rxkhs(conf); 871*a90b9d01SCy Schubert os_free(conf->rxkh_file); 872*a90b9d01SCy Schubert conf->rxkh_file = NULL; 87385732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */ 874e28a4053SRui Paulo 875e28a4053SRui Paulo #ifdef CONFIG_WPS 876e28a4053SRui Paulo os_free(conf->wps_pin_requests); 877e28a4053SRui Paulo os_free(conf->device_name); 878e28a4053SRui Paulo os_free(conf->manufacturer); 879e28a4053SRui Paulo os_free(conf->model_name); 880e28a4053SRui Paulo os_free(conf->model_number); 881e28a4053SRui Paulo os_free(conf->serial_number); 882e28a4053SRui Paulo os_free(conf->config_methods); 883e28a4053SRui Paulo os_free(conf->ap_pin); 884e28a4053SRui Paulo os_free(conf->extra_cred); 885e28a4053SRui Paulo os_free(conf->ap_settings); 8864bc52338SCy Schubert hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk); 8874bc52338SCy Schubert str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase); 888e28a4053SRui Paulo os_free(conf->upnp_iface); 889e28a4053SRui Paulo os_free(conf->friendly_name); 890e28a4053SRui Paulo os_free(conf->manufacturer_url); 891e28a4053SRui Paulo os_free(conf->model_description); 892e28a4053SRui Paulo os_free(conf->model_url); 893e28a4053SRui Paulo os_free(conf->upc); 8945b9c547cSRui Paulo for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) 8955b9c547cSRui Paulo wpabuf_free(conf->wps_vendor_ext[i]); 896c1d255d3SCy Schubert wpabuf_free(conf->wps_application_ext); 897f05cddf9SRui Paulo wpabuf_free(conf->wps_nfc_dh_pubkey); 898f05cddf9SRui Paulo wpabuf_free(conf->wps_nfc_dh_privkey); 899f05cddf9SRui Paulo wpabuf_free(conf->wps_nfc_dev_pw); 900e28a4053SRui Paulo #endif /* CONFIG_WPS */ 901f05cddf9SRui Paulo 902f05cddf9SRui Paulo os_free(conf->roaming_consortium); 903f05cddf9SRui Paulo os_free(conf->venue_name); 90485732ac8SCy Schubert os_free(conf->venue_url); 905f05cddf9SRui Paulo os_free(conf->nai_realm_data); 906f05cddf9SRui Paulo os_free(conf->network_auth_type); 907f05cddf9SRui Paulo os_free(conf->anqp_3gpp_cell_net); 908f05cddf9SRui Paulo os_free(conf->domain_name); 909780fb4a2SCy Schubert hostapd_config_free_anqp_elem(conf); 910f05cddf9SRui Paulo 911f05cddf9SRui Paulo #ifdef CONFIG_RADIUS_TEST 912f05cddf9SRui Paulo os_free(conf->dump_msk_file); 913f05cddf9SRui Paulo #endif /* CONFIG_RADIUS_TEST */ 914f05cddf9SRui Paulo 915f05cddf9SRui Paulo #ifdef CONFIG_HS20 916f05cddf9SRui Paulo os_free(conf->hs20_oper_friendly_name); 917f05cddf9SRui Paulo os_free(conf->hs20_wan_metrics); 918f05cddf9SRui Paulo os_free(conf->hs20_connection_capability); 919f05cddf9SRui Paulo os_free(conf->hs20_operating_class); 9205b9c547cSRui Paulo os_free(conf->hs20_icons); 9215b9c547cSRui Paulo if (conf->hs20_osu_providers) { 9225b9c547cSRui Paulo for (i = 0; i < conf->hs20_osu_providers_count; i++) { 9235b9c547cSRui Paulo struct hs20_osu_provider *p; 9245b9c547cSRui Paulo size_t j; 9255b9c547cSRui Paulo p = &conf->hs20_osu_providers[i]; 9265b9c547cSRui Paulo os_free(p->friendly_name); 9275b9c547cSRui Paulo os_free(p->server_uri); 9285b9c547cSRui Paulo os_free(p->method_list); 9295b9c547cSRui Paulo for (j = 0; j < p->icons_count; j++) 9305b9c547cSRui Paulo os_free(p->icons[j]); 9315b9c547cSRui Paulo os_free(p->icons); 9325b9c547cSRui Paulo os_free(p->osu_nai); 93385732ac8SCy Schubert os_free(p->osu_nai2); 9345b9c547cSRui Paulo os_free(p->service_desc); 9355b9c547cSRui Paulo } 9365b9c547cSRui Paulo os_free(conf->hs20_osu_providers); 9375b9c547cSRui Paulo } 93885732ac8SCy Schubert if (conf->hs20_operator_icon) { 93985732ac8SCy Schubert for (i = 0; i < conf->hs20_operator_icon_count; i++) 94085732ac8SCy Schubert os_free(conf->hs20_operator_icon[i]); 94185732ac8SCy Schubert os_free(conf->hs20_operator_icon); 94285732ac8SCy Schubert } 9435b9c547cSRui Paulo os_free(conf->subscr_remediation_url); 9444bc52338SCy Schubert os_free(conf->hs20_sim_provisioning_url); 94585732ac8SCy Schubert os_free(conf->t_c_filename); 94685732ac8SCy Schubert os_free(conf->t_c_server_url); 947f05cddf9SRui Paulo #endif /* CONFIG_HS20 */ 948f05cddf9SRui Paulo 949f05cddf9SRui Paulo wpabuf_free(conf->vendor_elements); 950780fb4a2SCy Schubert wpabuf_free(conf->assocresp_elements); 9515b9c547cSRui Paulo 9525b9c547cSRui Paulo os_free(conf->sae_groups); 95385732ac8SCy Schubert #ifdef CONFIG_OWE 95485732ac8SCy Schubert os_free(conf->owe_groups); 95585732ac8SCy Schubert #endif /* CONFIG_OWE */ 9565b9c547cSRui Paulo 9575b9c547cSRui Paulo os_free(conf->wowlan_triggers); 9585b9c547cSRui Paulo 9595b9c547cSRui Paulo os_free(conf->server_id); 9605b9c547cSRui Paulo 961325151a3SRui Paulo #ifdef CONFIG_TESTING_OPTIONS 962325151a3SRui Paulo wpabuf_free(conf->own_ie_override); 96385732ac8SCy Schubert wpabuf_free(conf->sae_commit_override); 964c1d255d3SCy Schubert wpabuf_free(conf->rsne_override_eapol); 965c1d255d3SCy Schubert wpabuf_free(conf->rsnxe_override_eapol); 966c1d255d3SCy Schubert wpabuf_free(conf->rsne_override_ft); 967c1d255d3SCy Schubert wpabuf_free(conf->rsnxe_override_ft); 968c1d255d3SCy Schubert wpabuf_free(conf->gtk_rsc_override); 969c1d255d3SCy Schubert wpabuf_free(conf->igtk_rsc_override); 970*a90b9d01SCy Schubert wpabuf_free(conf->eapol_m1_elements); 971*a90b9d01SCy Schubert wpabuf_free(conf->eapol_m3_elements); 972*a90b9d01SCy Schubert wpabuf_free(conf->presp_elements); 973325151a3SRui Paulo #endif /* CONFIG_TESTING_OPTIONS */ 974325151a3SRui Paulo 975325151a3SRui Paulo os_free(conf->no_probe_resp_if_seen_on); 976325151a3SRui Paulo os_free(conf->no_auth_if_seen_on); 977325151a3SRui Paulo 97885732ac8SCy Schubert hostapd_config_free_fils_realms(conf); 97985732ac8SCy Schubert 98085732ac8SCy Schubert #ifdef CONFIG_DPP 981c1d255d3SCy Schubert os_free(conf->dpp_name); 982c1d255d3SCy Schubert os_free(conf->dpp_mud_url); 983*a90b9d01SCy Schubert os_free(conf->dpp_extra_conf_req_name); 984*a90b9d01SCy Schubert os_free(conf->dpp_extra_conf_req_value); 98585732ac8SCy Schubert os_free(conf->dpp_connector); 98685732ac8SCy Schubert wpabuf_free(conf->dpp_netaccesskey); 98785732ac8SCy Schubert wpabuf_free(conf->dpp_csign); 988206b73d0SCy Schubert #ifdef CONFIG_DPP2 989206b73d0SCy Schubert hostapd_dpp_controller_conf_free(conf->dpp_controller); 990206b73d0SCy Schubert #endif /* CONFIG_DPP2 */ 99185732ac8SCy Schubert #endif /* CONFIG_DPP */ 99285732ac8SCy Schubert 99385732ac8SCy Schubert hostapd_config_free_sae_passwords(conf); 99485732ac8SCy Schubert 995206b73d0SCy Schubert #ifdef CONFIG_AIRTIME_POLICY 996206b73d0SCy Schubert { 997206b73d0SCy Schubert struct airtime_sta_weight *wt, *wt_prev; 998206b73d0SCy Schubert 999206b73d0SCy Schubert wt = conf->airtime_weight_list; 1000206b73d0SCy Schubert conf->airtime_weight_list = NULL; 1001206b73d0SCy Schubert while (wt) { 1002206b73d0SCy Schubert wt_prev = wt; 1003206b73d0SCy Schubert wt = wt->next; 1004206b73d0SCy Schubert os_free(wt_prev); 1005206b73d0SCy Schubert } 1006206b73d0SCy Schubert } 1007206b73d0SCy Schubert #endif /* CONFIG_AIRTIME_POLICY */ 1008206b73d0SCy Schubert 1009c1d255d3SCy Schubert #ifdef CONFIG_PASN 1010c1d255d3SCy Schubert os_free(conf->pasn_groups); 1011c1d255d3SCy Schubert #endif /* CONFIG_PASN */ 1012c1d255d3SCy Schubert 10135b9c547cSRui Paulo os_free(conf); 1014e28a4053SRui Paulo } 1015e28a4053SRui Paulo 1016e28a4053SRui Paulo 1017e28a4053SRui Paulo /** 1018e28a4053SRui Paulo * hostapd_config_free - Free hostapd configuration 1019e28a4053SRui Paulo * @conf: Configuration data from hostapd_config_read(). 1020e28a4053SRui Paulo */ 1021e28a4053SRui Paulo void hostapd_config_free(struct hostapd_config *conf) 1022e28a4053SRui Paulo { 1023e28a4053SRui Paulo size_t i; 1024e28a4053SRui Paulo 1025e28a4053SRui Paulo if (conf == NULL) 1026e28a4053SRui Paulo return; 1027e28a4053SRui Paulo 1028e28a4053SRui Paulo for (i = 0; i < conf->num_bss; i++) 10295b9c547cSRui Paulo hostapd_config_free_bss(conf->bss[i]); 1030e28a4053SRui Paulo os_free(conf->bss); 1031e28a4053SRui Paulo os_free(conf->supported_rates); 1032e28a4053SRui Paulo os_free(conf->basic_rates); 1033325151a3SRui Paulo os_free(conf->acs_ch_list.range); 1034c1d255d3SCy Schubert os_free(conf->acs_freq_list.range); 10355b9c547cSRui Paulo os_free(conf->driver_params); 10365b9c547cSRui Paulo #ifdef CONFIG_ACS 10375b9c547cSRui Paulo os_free(conf->acs_chan_bias); 10385b9c547cSRui Paulo #endif /* CONFIG_ACS */ 1039780fb4a2SCy Schubert wpabuf_free(conf->lci); 1040780fb4a2SCy Schubert wpabuf_free(conf->civic); 1041e28a4053SRui Paulo 1042e28a4053SRui Paulo os_free(conf); 1043e28a4053SRui Paulo } 1044e28a4053SRui Paulo 1045e28a4053SRui Paulo 1046e28a4053SRui Paulo /** 1047e28a4053SRui Paulo * hostapd_maclist_found - Find a MAC address from a list 1048e28a4053SRui Paulo * @list: MAC address list 1049e28a4053SRui Paulo * @num_entries: Number of addresses in the list 1050e28a4053SRui Paulo * @addr: Address to search for 1051e28a4053SRui Paulo * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed 1052e28a4053SRui Paulo * Returns: 1 if address is in the list or 0 if not. 1053e28a4053SRui Paulo * 1054e28a4053SRui Paulo * Perform a binary search for given MAC address from a pre-sorted list. 1055e28a4053SRui Paulo */ 1056e28a4053SRui Paulo int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries, 1057780fb4a2SCy Schubert const u8 *addr, struct vlan_description *vlan_id) 1058e28a4053SRui Paulo { 1059e28a4053SRui Paulo int start, end, middle, res; 1060e28a4053SRui Paulo 1061e28a4053SRui Paulo start = 0; 1062e28a4053SRui Paulo end = num_entries - 1; 1063e28a4053SRui Paulo 1064e28a4053SRui Paulo while (start <= end) { 1065e28a4053SRui Paulo middle = (start + end) / 2; 1066e28a4053SRui Paulo res = os_memcmp(list[middle].addr, addr, ETH_ALEN); 1067e28a4053SRui Paulo if (res == 0) { 1068e28a4053SRui Paulo if (vlan_id) 1069e28a4053SRui Paulo *vlan_id = list[middle].vlan_id; 1070e28a4053SRui Paulo return 1; 1071e28a4053SRui Paulo } 1072e28a4053SRui Paulo if (res < 0) 1073e28a4053SRui Paulo start = middle + 1; 1074e28a4053SRui Paulo else 1075e28a4053SRui Paulo end = middle - 1; 1076e28a4053SRui Paulo } 1077e28a4053SRui Paulo 1078e28a4053SRui Paulo return 0; 1079e28a4053SRui Paulo } 1080e28a4053SRui Paulo 1081e28a4053SRui Paulo 1082e28a4053SRui Paulo int hostapd_rate_found(int *list, int rate) 1083e28a4053SRui Paulo { 1084e28a4053SRui Paulo int i; 1085e28a4053SRui Paulo 1086e28a4053SRui Paulo if (list == NULL) 1087e28a4053SRui Paulo return 0; 1088e28a4053SRui Paulo 1089e28a4053SRui Paulo for (i = 0; list[i] >= 0; i++) 1090e28a4053SRui Paulo if (list[i] == rate) 1091e28a4053SRui Paulo return 1; 1092e28a4053SRui Paulo 1093e28a4053SRui Paulo return 0; 1094e28a4053SRui Paulo } 1095e28a4053SRui Paulo 1096e28a4053SRui Paulo 1097780fb4a2SCy Schubert int hostapd_vlan_valid(struct hostapd_vlan *vlan, 1098780fb4a2SCy Schubert struct vlan_description *vlan_desc) 1099e28a4053SRui Paulo { 1100e28a4053SRui Paulo struct hostapd_vlan *v = vlan; 1101780fb4a2SCy Schubert int i; 1102780fb4a2SCy Schubert 1103780fb4a2SCy Schubert if (!vlan_desc->notempty || vlan_desc->untagged < 0 || 1104780fb4a2SCy Schubert vlan_desc->untagged > MAX_VLAN_ID) 1105780fb4a2SCy Schubert return 0; 1106780fb4a2SCy Schubert for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) { 1107780fb4a2SCy Schubert if (vlan_desc->tagged[i] < 0 || 1108780fb4a2SCy Schubert vlan_desc->tagged[i] > MAX_VLAN_ID) 1109780fb4a2SCy Schubert return 0; 1110780fb4a2SCy Schubert } 1111780fb4a2SCy Schubert if (!vlan_desc->untagged && !vlan_desc->tagged[0]) 1112780fb4a2SCy Schubert return 0; 1113780fb4a2SCy Schubert 1114e28a4053SRui Paulo while (v) { 1115780fb4a2SCy Schubert if (!vlan_compare(&v->vlan_desc, vlan_desc) || 1116780fb4a2SCy Schubert v->vlan_id == VLAN_ID_WILDCARD) 11175b9c547cSRui Paulo return 1; 11185b9c547cSRui Paulo v = v->next; 11195b9c547cSRui Paulo } 11205b9c547cSRui Paulo return 0; 11215b9c547cSRui Paulo } 11225b9c547cSRui Paulo 11235b9c547cSRui Paulo 11245b9c547cSRui Paulo const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) 11255b9c547cSRui Paulo { 11265b9c547cSRui Paulo struct hostapd_vlan *v = vlan; 11275b9c547cSRui Paulo while (v) { 11285b9c547cSRui Paulo if (v->vlan_id == vlan_id) 1129e28a4053SRui Paulo return v->ifname; 1130e28a4053SRui Paulo v = v->next; 1131e28a4053SRui Paulo } 1132e28a4053SRui Paulo return NULL; 1133e28a4053SRui Paulo } 1134e28a4053SRui Paulo 1135e28a4053SRui Paulo 1136e28a4053SRui Paulo const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, 11375b9c547cSRui Paulo const u8 *addr, const u8 *p2p_dev_addr, 11384bc52338SCy Schubert const u8 *prev_psk, int *vlan_id) 1139e28a4053SRui Paulo { 1140e28a4053SRui Paulo struct hostapd_wpa_psk *psk; 1141e28a4053SRui Paulo int next_ok = prev_psk == NULL; 1142e28a4053SRui Paulo 11434bc52338SCy Schubert if (vlan_id) 11444bc52338SCy Schubert *vlan_id = 0; 11454bc52338SCy Schubert 11465b9c547cSRui Paulo if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) { 11475b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR 11485b9c547cSRui Paulo " p2p_dev_addr=" MACSTR " prev_psk=%p", 11495b9c547cSRui Paulo MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk); 11505b9c547cSRui Paulo addr = NULL; /* Use P2P Device Address for matching */ 11515b9c547cSRui Paulo } else { 11525b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR 11535b9c547cSRui Paulo " prev_psk=%p", 11545b9c547cSRui Paulo MAC2STR(addr), prev_psk); 11555b9c547cSRui Paulo } 11565b9c547cSRui Paulo 1157e28a4053SRui Paulo for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { 1158e28a4053SRui Paulo if (next_ok && 11595b9c547cSRui Paulo (psk->group || 1160*a90b9d01SCy Schubert (addr && ether_addr_equal(psk->addr, addr)) || 11615b9c547cSRui Paulo (!addr && p2p_dev_addr && 1162*a90b9d01SCy Schubert ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) { 11634bc52338SCy Schubert if (vlan_id) 11644bc52338SCy Schubert *vlan_id = psk->vlan_id; 1165e28a4053SRui Paulo return psk->psk; 11664bc52338SCy Schubert } 1167e28a4053SRui Paulo 1168e28a4053SRui Paulo if (psk->psk == prev_psk) 1169e28a4053SRui Paulo next_ok = 1; 1170e28a4053SRui Paulo } 1171e28a4053SRui Paulo 1172e28a4053SRui Paulo return NULL; 1173e28a4053SRui Paulo } 11745b9c547cSRui Paulo 11755b9c547cSRui Paulo 1176c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK 1177c1d255d3SCy Schubert static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss) 1178c1d255d3SCy Schubert { 1179c1d255d3SCy Schubert struct sae_password_entry *pw; 1180c1d255d3SCy Schubert bool res = false; 1181c1d255d3SCy Schubert 1182c1d255d3SCy Schubert if (bss->ssid.wpa_passphrase && 1183c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS 1184c1d255d3SCy Schubert !bss->sae_pk_password_check_skip && 1185c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */ 1186c1d255d3SCy Schubert sae_pk_valid_password(bss->ssid.wpa_passphrase)) 1187c1d255d3SCy Schubert res = true; 1188c1d255d3SCy Schubert 1189c1d255d3SCy Schubert for (pw = bss->sae_passwords; pw; pw = pw->next) { 1190c1d255d3SCy Schubert if (!pw->pk && 1191c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS 1192c1d255d3SCy Schubert !bss->sae_pk_password_check_skip && 1193c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */ 1194c1d255d3SCy Schubert sae_pk_valid_password(pw->password)) 1195c1d255d3SCy Schubert return true; 1196c1d255d3SCy Schubert 1197c1d255d3SCy Schubert if (bss->ssid.wpa_passphrase && res && pw->pk && 1198c1d255d3SCy Schubert os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0) 1199c1d255d3SCy Schubert res = false; 1200c1d255d3SCy Schubert } 1201c1d255d3SCy Schubert 1202c1d255d3SCy Schubert return res; 1203c1d255d3SCy Schubert } 1204c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */ 1205c1d255d3SCy Schubert 1206c1d255d3SCy Schubert 1207c1d255d3SCy Schubert static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss) 1208c1d255d3SCy Schubert { 1209c1d255d3SCy Schubert if (bss->wpa != WPA_PROTO_RSN) { 1210c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1211c1d255d3SCy Schubert "Pre-RSNA security methods are not allowed in 6 GHz"); 1212c1d255d3SCy Schubert return false; 1213c1d255d3SCy Schubert } 1214c1d255d3SCy Schubert 1215c1d255d3SCy Schubert if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) { 1216c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1217c1d255d3SCy Schubert "Management frame protection is required in 6 GHz"); 1218c1d255d3SCy Schubert return false; 1219c1d255d3SCy Schubert } 1220c1d255d3SCy Schubert 1221c1d255d3SCy Schubert if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK | 1222c1d255d3SCy Schubert WPA_KEY_MGMT_FT_PSK | 1223c1d255d3SCy Schubert WPA_KEY_MGMT_PSK_SHA256)) { 1224c1d255d3SCy Schubert wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz"); 1225c1d255d3SCy Schubert return false; 1226c1d255d3SCy Schubert } 1227c1d255d3SCy Schubert 1228c1d255d3SCy Schubert if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 | 1229c1d255d3SCy Schubert WPA_CIPHER_WEP104 | 1230c1d255d3SCy Schubert WPA_CIPHER_TKIP)) { 1231c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1232c1d255d3SCy Schubert "Invalid pairwise cipher suite for 6 GHz"); 1233c1d255d3SCy Schubert return false; 1234c1d255d3SCy Schubert } 1235c1d255d3SCy Schubert 1236c1d255d3SCy Schubert if (bss->wpa_group & (WPA_CIPHER_WEP40 | 1237c1d255d3SCy Schubert WPA_CIPHER_WEP104 | 1238c1d255d3SCy Schubert WPA_CIPHER_TKIP)) { 1239c1d255d3SCy Schubert wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz"); 1240c1d255d3SCy Schubert return false; 1241c1d255d3SCy Schubert } 1242c1d255d3SCy Schubert 1243*a90b9d01SCy Schubert #ifdef CONFIG_SAE 1244*a90b9d01SCy Schubert if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && 1245*a90b9d01SCy Schubert bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) { 1246*a90b9d01SCy Schubert wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz"); 1247*a90b9d01SCy Schubert bss->sae_pwe = SAE_PWE_BOTH; 1248*a90b9d01SCy Schubert } 1249*a90b9d01SCy Schubert #endif /* CONFIG_SAE */ 1250*a90b9d01SCy Schubert 1251c1d255d3SCy Schubert return true; 1252c1d255d3SCy Schubert } 1253c1d255d3SCy Schubert 1254c1d255d3SCy Schubert 12555b9c547cSRui Paulo static int hostapd_config_check_bss(struct hostapd_bss_config *bss, 12565b9c547cSRui Paulo struct hostapd_config *conf, 12575b9c547cSRui Paulo int full_config) 12585b9c547cSRui Paulo { 1259c1d255d3SCy Schubert if (full_config && is_6ghz_op_class(conf->op_class) && 1260c1d255d3SCy Schubert !hostapd_config_check_bss_6g(bss)) 1261c1d255d3SCy Schubert return -1; 1262c1d255d3SCy Schubert 12635b9c547cSRui Paulo if (full_config && bss->ieee802_1x && !bss->eap_server && 12645b9c547cSRui Paulo !bss->radius->auth_servers) { 12655b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no " 12665b9c547cSRui Paulo "EAP authenticator configured)."); 12675b9c547cSRui Paulo return -1; 12685b9c547cSRui Paulo } 12695b9c547cSRui Paulo 1270c1d255d3SCy Schubert #ifdef CONFIG_WEP 12715b9c547cSRui Paulo if (bss->wpa) { 12725b9c547cSRui Paulo int wep, i; 12735b9c547cSRui Paulo 12745b9c547cSRui Paulo wep = bss->default_wep_key_len > 0 || 12755b9c547cSRui Paulo bss->individual_wep_key_len > 0; 12765b9c547cSRui Paulo for (i = 0; i < NUM_WEP_KEYS; i++) { 12775b9c547cSRui Paulo if (bss->ssid.wep.keys_set) { 12785b9c547cSRui Paulo wep = 1; 12795b9c547cSRui Paulo break; 12805b9c547cSRui Paulo } 12815b9c547cSRui Paulo } 12825b9c547cSRui Paulo 12835b9c547cSRui Paulo if (wep) { 12845b9c547cSRui Paulo wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported"); 12855b9c547cSRui Paulo return -1; 12865b9c547cSRui Paulo } 12875b9c547cSRui Paulo } 1288c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 12895b9c547cSRui Paulo 12905b9c547cSRui Paulo if (full_config && bss->wpa && 12915b9c547cSRui Paulo bss->wpa_psk_radius != PSK_RADIUS_IGNORED && 1292*a90b9d01SCy Schubert bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS && 12935b9c547cSRui Paulo bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) { 12945b9c547cSRui Paulo wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no " 12955b9c547cSRui Paulo "RADIUS checking (macaddr_acl=2) enabled."); 12965b9c547cSRui Paulo return -1; 12975b9c547cSRui Paulo } 12985b9c547cSRui Paulo 1299*a90b9d01SCy Schubert if (full_config && bss->wpa && 1300*a90b9d01SCy Schubert wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) && 13015b9c547cSRui Paulo bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL && 13025b9c547cSRui Paulo bss->ssid.wpa_psk_file == NULL && 1303*a90b9d01SCy Schubert bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS && 13045b9c547cSRui Paulo (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED || 13055b9c547cSRui Paulo bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) { 13065b9c547cSRui Paulo wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase " 13075b9c547cSRui Paulo "is not configured."); 13085b9c547cSRui Paulo return -1; 13095b9c547cSRui Paulo } 13105b9c547cSRui Paulo 1311780fb4a2SCy Schubert if (full_config && !is_zero_ether_addr(bss->bssid)) { 13125b9c547cSRui Paulo size_t i; 13135b9c547cSRui Paulo 13145b9c547cSRui Paulo for (i = 0; i < conf->num_bss; i++) { 13155b9c547cSRui Paulo if (conf->bss[i] != bss && 13165b9c547cSRui Paulo (hostapd_mac_comp(conf->bss[i]->bssid, 13175b9c547cSRui Paulo bss->bssid) == 0)) { 13185b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR 13195b9c547cSRui Paulo " on interface '%s' and '%s'.", 13205b9c547cSRui Paulo MAC2STR(bss->bssid), 13215b9c547cSRui Paulo conf->bss[i]->iface, bss->iface); 13225b9c547cSRui Paulo return -1; 13235b9c547cSRui Paulo } 13245b9c547cSRui Paulo } 13255b9c547cSRui Paulo } 13265b9c547cSRui Paulo 132785732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP 13285b9c547cSRui Paulo if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) && 13295b9c547cSRui Paulo (bss->nas_identifier == NULL || 13305b9c547cSRui Paulo os_strlen(bss->nas_identifier) < 1 || 13315b9c547cSRui Paulo os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) { 13325b9c547cSRui Paulo wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires " 13335b9c547cSRui Paulo "nas_identifier to be configured as a 1..48 octet " 13345b9c547cSRui Paulo "string"); 13355b9c547cSRui Paulo return -1; 13365b9c547cSRui Paulo } 133785732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */ 13385b9c547cSRui Paulo 13395b9c547cSRui Paulo if (full_config && conf->ieee80211n && 13405b9c547cSRui Paulo conf->hw_mode == HOSTAPD_MODE_IEEE80211B) { 1341c1d255d3SCy Schubert bss->disable_11n = true; 13425b9c547cSRui Paulo wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not " 13435b9c547cSRui Paulo "allowed, disabling HT capabilities"); 13445b9c547cSRui Paulo } 13455b9c547cSRui Paulo 1346c1d255d3SCy Schubert #ifdef CONFIG_WEP 13475b9c547cSRui Paulo if (full_config && conf->ieee80211n && 13485b9c547cSRui Paulo bss->ssid.security_policy == SECURITY_STATIC_WEP) { 1349c1d255d3SCy Schubert bss->disable_11n = true; 13505b9c547cSRui Paulo wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not " 13515b9c547cSRui Paulo "allowed, disabling HT capabilities"); 13525b9c547cSRui Paulo } 1353c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 13545b9c547cSRui Paulo 13555b9c547cSRui Paulo if (full_config && conf->ieee80211n && bss->wpa && 13565b9c547cSRui Paulo !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && 13575b9c547cSRui Paulo !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | 13585b9c547cSRui Paulo WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) 13595b9c547cSRui Paulo { 1360c1d255d3SCy Schubert bss->disable_11n = true; 13615b9c547cSRui Paulo wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 " 13625b9c547cSRui Paulo "requires CCMP/GCMP to be enabled, disabling HT " 13635b9c547cSRui Paulo "capabilities"); 13645b9c547cSRui Paulo } 13655b9c547cSRui Paulo 1366780fb4a2SCy Schubert #ifdef CONFIG_IEEE80211AC 1367c1d255d3SCy Schubert #ifdef CONFIG_WEP 1368780fb4a2SCy Schubert if (full_config && conf->ieee80211ac && 1369780fb4a2SCy Schubert bss->ssid.security_policy == SECURITY_STATIC_WEP) { 1370c1d255d3SCy Schubert bss->disable_11ac = true; 1371780fb4a2SCy Schubert wpa_printf(MSG_ERROR, 1372780fb4a2SCy Schubert "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities"); 1373780fb4a2SCy Schubert } 1374c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 137585732ac8SCy Schubert 137685732ac8SCy Schubert if (full_config && conf->ieee80211ac && bss->wpa && 137785732ac8SCy Schubert !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && 137885732ac8SCy Schubert !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | 137985732ac8SCy Schubert WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) 138085732ac8SCy Schubert { 1381c1d255d3SCy Schubert bss->disable_11ac = true; 138285732ac8SCy Schubert wpa_printf(MSG_ERROR, 138385732ac8SCy Schubert "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities"); 138485732ac8SCy Schubert } 1385780fb4a2SCy Schubert #endif /* CONFIG_IEEE80211AC */ 1386780fb4a2SCy Schubert 1387c1d255d3SCy Schubert #ifdef CONFIG_IEEE80211AX 1388c1d255d3SCy Schubert #ifdef CONFIG_WEP 1389c1d255d3SCy Schubert if (full_config && conf->ieee80211ax && 1390c1d255d3SCy Schubert bss->ssid.security_policy == SECURITY_STATIC_WEP) { 1391c1d255d3SCy Schubert bss->disable_11ax = true; 1392c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1393c1d255d3SCy Schubert "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities"); 1394c1d255d3SCy Schubert } 1395c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 1396c1d255d3SCy Schubert 1397c1d255d3SCy Schubert if (full_config && conf->ieee80211ax && bss->wpa && 1398c1d255d3SCy Schubert !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && 1399c1d255d3SCy Schubert !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | 1400c1d255d3SCy Schubert WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) 1401c1d255d3SCy Schubert { 1402c1d255d3SCy Schubert bss->disable_11ax = true; 1403c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1404c1d255d3SCy Schubert "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities"); 1405c1d255d3SCy Schubert } 1406c1d255d3SCy Schubert #endif /* CONFIG_IEEE80211AX */ 1407c1d255d3SCy Schubert 14085b9c547cSRui Paulo #ifdef CONFIG_WPS 14095b9c547cSRui Paulo if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) { 14105b9c547cSRui Paulo wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid " 14115b9c547cSRui Paulo "configuration forced WPS to be disabled"); 14125b9c547cSRui Paulo bss->wps_state = 0; 14135b9c547cSRui Paulo } 14145b9c547cSRui Paulo 1415c1d255d3SCy Schubert #ifdef CONFIG_WEP 14165b9c547cSRui Paulo if (full_config && bss->wps_state && 14175b9c547cSRui Paulo bss->ssid.wep.keys_set && bss->wpa == 0) { 14185b9c547cSRui Paulo wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be " 14195b9c547cSRui Paulo "disabled"); 14205b9c547cSRui Paulo bss->wps_state = 0; 14215b9c547cSRui Paulo } 1422c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 14235b9c547cSRui Paulo 14245b9c547cSRui Paulo if (full_config && bss->wps_state && bss->wpa && 14255b9c547cSRui Paulo (!(bss->wpa & 2) || 142685732ac8SCy Schubert !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | 142785732ac8SCy Schubert WPA_CIPHER_CCMP_256 | 142885732ac8SCy Schubert WPA_CIPHER_GCMP_256)))) { 14295b9c547cSRui Paulo wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without " 1430325151a3SRui Paulo "WPA2/CCMP/GCMP forced WPS to be disabled"); 14315b9c547cSRui Paulo bss->wps_state = 0; 14325b9c547cSRui Paulo } 14335b9c547cSRui Paulo #endif /* CONFIG_WPS */ 14345b9c547cSRui Paulo 14355b9c547cSRui Paulo #ifdef CONFIG_HS20 14365b9c547cSRui Paulo if (full_config && bss->hs20 && 14375b9c547cSRui Paulo (!(bss->wpa & 2) || 14385b9c547cSRui Paulo !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | 14395b9c547cSRui Paulo WPA_CIPHER_CCMP_256 | 14405b9c547cSRui Paulo WPA_CIPHER_GCMP_256)))) { 14415b9c547cSRui Paulo wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP " 14425b9c547cSRui Paulo "configuration is required for Hotspot 2.0 " 14435b9c547cSRui Paulo "functionality"); 14445b9c547cSRui Paulo return -1; 14455b9c547cSRui Paulo } 14465b9c547cSRui Paulo #endif /* CONFIG_HS20 */ 14475b9c547cSRui Paulo 1448780fb4a2SCy Schubert #ifdef CONFIG_MBO 1449780fb4a2SCy Schubert if (full_config && bss->mbo_enabled && (bss->wpa & 2) && 1450780fb4a2SCy Schubert bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) { 1451780fb4a2SCy Schubert wpa_printf(MSG_ERROR, 1452780fb4a2SCy Schubert "MBO: PMF needs to be enabled whenever using WPA2 with MBO"); 1453780fb4a2SCy Schubert return -1; 1454780fb4a2SCy Schubert } 1455780fb4a2SCy Schubert #endif /* CONFIG_MBO */ 1456780fb4a2SCy Schubert 14574bc52338SCy Schubert #ifdef CONFIG_OCV 14584bc52338SCy Schubert if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION && 14594bc52338SCy Schubert bss->ocv) { 14604bc52338SCy Schubert wpa_printf(MSG_ERROR, 14614bc52338SCy Schubert "OCV: PMF needs to be enabled whenever using OCV"); 14624bc52338SCy Schubert return -1; 14634bc52338SCy Schubert } 14644bc52338SCy Schubert #endif /* CONFIG_OCV */ 14654bc52338SCy Schubert 1466c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK 1467c1d255d3SCy Schubert if (full_config && hostapd_sae_pk_in_use(bss) && 1468c1d255d3SCy Schubert hostapd_sae_pk_password_without_pk(bss)) { 1469c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 1470c1d255d3SCy Schubert "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured"); 1471c1d255d3SCy Schubert return -1; 1472c1d255d3SCy Schubert } 1473c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */ 1474c1d255d3SCy Schubert 14754b72b91aSCy Schubert #ifdef CONFIG_FILS 1476*a90b9d01SCy Schubert if (full_config && bss->fils_discovery_max_int && 1477*a90b9d01SCy Schubert (!conf->ieee80211ax || bss->disable_11ax)) { 1478*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, 1479*a90b9d01SCy Schubert "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission."); 1480*a90b9d01SCy Schubert return -1; 1481*a90b9d01SCy Schubert } 1482*a90b9d01SCy Schubert 1483*a90b9d01SCy Schubert if (full_config && bss->fils_discovery_max_int && 14844b72b91aSCy Schubert bss->unsol_bcast_probe_resp_interval) { 14854b72b91aSCy Schubert wpa_printf(MSG_ERROR, 14864b72b91aSCy Schubert "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time"); 14874b72b91aSCy Schubert return -1; 14884b72b91aSCy Schubert } 14894b72b91aSCy Schubert #endif /* CONFIG_FILS */ 14904b72b91aSCy Schubert 1491*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE 1492*a90b9d01SCy Schubert if (full_config && !bss->disable_11be && bss->disable_11ax) { 1493*a90b9d01SCy Schubert bss->disable_11be = true; 1494*a90b9d01SCy Schubert wpa_printf(MSG_INFO, 1495*a90b9d01SCy Schubert "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS"); 1496*a90b9d01SCy Schubert } 1497*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */ 1498*a90b9d01SCy Schubert 1499*a90b9d01SCy Schubert if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) { 1500*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, 1501*a90b9d01SCy Schubert "Hidden SSID is not suppored when MBSSID is enabled"); 1502*a90b9d01SCy Schubert return -1; 1503*a90b9d01SCy Schubert } 1504*a90b9d01SCy Schubert 15055b9c547cSRui Paulo return 0; 15065b9c547cSRui Paulo } 15075b9c547cSRui Paulo 15085b9c547cSRui Paulo 1509325151a3SRui Paulo static int hostapd_config_check_cw(struct hostapd_config *conf, int queue) 1510325151a3SRui Paulo { 1511325151a3SRui Paulo int tx_cwmin = conf->tx_queue[queue].cwmin; 1512325151a3SRui Paulo int tx_cwmax = conf->tx_queue[queue].cwmax; 1513325151a3SRui Paulo int ac_cwmin = conf->wmm_ac_params[queue].cwmin; 1514325151a3SRui Paulo int ac_cwmax = conf->wmm_ac_params[queue].cwmax; 1515325151a3SRui Paulo 1516325151a3SRui Paulo if (tx_cwmin > tx_cwmax) { 1517325151a3SRui Paulo wpa_printf(MSG_ERROR, 1518325151a3SRui Paulo "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", 1519325151a3SRui Paulo tx_cwmin, tx_cwmax); 1520325151a3SRui Paulo return -1; 1521325151a3SRui Paulo } 1522325151a3SRui Paulo if (ac_cwmin > ac_cwmax) { 1523325151a3SRui Paulo wpa_printf(MSG_ERROR, 1524325151a3SRui Paulo "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", 1525325151a3SRui Paulo ac_cwmin, ac_cwmax); 1526325151a3SRui Paulo return -1; 1527325151a3SRui Paulo } 1528325151a3SRui Paulo return 0; 1529325151a3SRui Paulo } 1530325151a3SRui Paulo 1531325151a3SRui Paulo 15325b9c547cSRui Paulo int hostapd_config_check(struct hostapd_config *conf, int full_config) 15335b9c547cSRui Paulo { 15345b9c547cSRui Paulo size_t i; 15355b9c547cSRui Paulo 1536*a90b9d01SCy Schubert if (full_config && is_6ghz_op_class(conf->op_class) && 1537*a90b9d01SCy Schubert !conf->hw_mode_set) { 1538*a90b9d01SCy Schubert /* Use the appropriate hw_mode value automatically when the 1539*a90b9d01SCy Schubert * op_class parameter has been set, but hw_mode was not. */ 1540*a90b9d01SCy Schubert conf->hw_mode = HOSTAPD_MODE_IEEE80211A; 1541*a90b9d01SCy Schubert } 1542*a90b9d01SCy Schubert 15435b9c547cSRui Paulo if (full_config && conf->ieee80211d && 15445b9c547cSRui Paulo (!conf->country[0] || !conf->country[1])) { 15455b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without " 15465b9c547cSRui Paulo "setting the country_code"); 15475b9c547cSRui Paulo return -1; 15485b9c547cSRui Paulo } 15495b9c547cSRui Paulo 15505b9c547cSRui Paulo if (full_config && conf->ieee80211h && !conf->ieee80211d) { 15515b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without " 15525b9c547cSRui Paulo "IEEE 802.11d enabled"); 15535b9c547cSRui Paulo return -1; 15545b9c547cSRui Paulo } 15555b9c547cSRui Paulo 15565b9c547cSRui Paulo if (full_config && conf->local_pwr_constraint != -1 && 15575b9c547cSRui Paulo !conf->ieee80211d) { 15585b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element"); 15595b9c547cSRui Paulo return -1; 15605b9c547cSRui Paulo } 15615b9c547cSRui Paulo 15625b9c547cSRui Paulo if (full_config && conf->spectrum_mgmt_required && 15635b9c547cSRui Paulo conf->local_pwr_constraint == -1) { 15645b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements"); 15655b9c547cSRui Paulo return -1; 15665b9c547cSRui Paulo } 15675b9c547cSRui Paulo 1568206b73d0SCy Schubert #ifdef CONFIG_AIRTIME_POLICY 1569206b73d0SCy Schubert if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC && 1570206b73d0SCy Schubert !conf->airtime_update_interval) { 1571206b73d0SCy Schubert wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero"); 1572206b73d0SCy Schubert return -1; 1573206b73d0SCy Schubert } 1574206b73d0SCy Schubert #endif /* CONFIG_AIRTIME_POLICY */ 1575325151a3SRui Paulo for (i = 0; i < NUM_TX_QUEUES; i++) { 1576325151a3SRui Paulo if (hostapd_config_check_cw(conf, i)) 1577325151a3SRui Paulo return -1; 1578325151a3SRui Paulo } 1579325151a3SRui Paulo 1580*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE 1581*a90b9d01SCy Schubert if (full_config && conf->ieee80211be && !conf->ieee80211ax) { 1582*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, 1583*a90b9d01SCy Schubert "Cannot set ieee80211be without ieee80211ax"); 1584*a90b9d01SCy Schubert return -1; 1585*a90b9d01SCy Schubert } 1586*a90b9d01SCy Schubert 1587*a90b9d01SCy Schubert if (full_config) 1588*a90b9d01SCy Schubert hostapd_set_and_check_bw320_offset(conf, 1589*a90b9d01SCy Schubert conf->eht_bw320_offset); 1590*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */ 1591*a90b9d01SCy Schubert 1592*a90b9d01SCy Schubert if (full_config && conf->mbssid && !conf->ieee80211ax) { 1593*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, 1594*a90b9d01SCy Schubert "Cannot enable multiple BSSID support without ieee80211ax"); 1595*a90b9d01SCy Schubert return -1; 1596*a90b9d01SCy Schubert } 1597*a90b9d01SCy Schubert 15985b9c547cSRui Paulo for (i = 0; i < conf->num_bss; i++) { 15995b9c547cSRui Paulo if (hostapd_config_check_bss(conf->bss[i], conf, full_config)) 16005b9c547cSRui Paulo return -1; 16015b9c547cSRui Paulo } 16025b9c547cSRui Paulo 16035b9c547cSRui Paulo return 0; 16045b9c547cSRui Paulo } 16055b9c547cSRui Paulo 16065b9c547cSRui Paulo 16075b9c547cSRui Paulo void hostapd_set_security_params(struct hostapd_bss_config *bss, 16085b9c547cSRui Paulo int full_config) 16095b9c547cSRui Paulo { 1610c1d255d3SCy Schubert #ifdef CONFIG_WEP 16115b9c547cSRui Paulo if (bss->individual_wep_key_len == 0) { 16125b9c547cSRui Paulo /* individual keys are not use; can use key idx0 for 16135b9c547cSRui Paulo * broadcast keys */ 16145b9c547cSRui Paulo bss->broadcast_key_idx_min = 0; 16155b9c547cSRui Paulo } 1616c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 16175b9c547cSRui Paulo 16185b9c547cSRui Paulo if ((bss->wpa & 2) && bss->rsn_pairwise == 0) 16195b9c547cSRui Paulo bss->rsn_pairwise = bss->wpa_pairwise; 162085732ac8SCy Schubert if (bss->group_cipher) 162185732ac8SCy Schubert bss->wpa_group = bss->group_cipher; 162285732ac8SCy Schubert else 162385732ac8SCy Schubert bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, 162485732ac8SCy Schubert bss->wpa_pairwise, 16255b9c547cSRui Paulo bss->rsn_pairwise); 162685732ac8SCy Schubert if (!bss->wpa_group_rekey_set) 162785732ac8SCy Schubert bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ? 162885732ac8SCy Schubert 600 : 86400; 16295b9c547cSRui Paulo 16305b9c547cSRui Paulo if (full_config) { 16315b9c547cSRui Paulo bss->radius->auth_server = bss->radius->auth_servers; 16325b9c547cSRui Paulo bss->radius->acct_server = bss->radius->acct_servers; 16335b9c547cSRui Paulo } 16345b9c547cSRui Paulo 16355b9c547cSRui Paulo if (bss->wpa && bss->ieee802_1x) { 16365b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_WPA; 16375b9c547cSRui Paulo } else if (bss->wpa) { 16385b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_WPA_PSK; 16395b9c547cSRui Paulo } else if (bss->ieee802_1x) { 16405b9c547cSRui Paulo int cipher = WPA_CIPHER_NONE; 16415b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_IEEE_802_1X; 1642c1d255d3SCy Schubert #ifdef CONFIG_WEP 16435b9c547cSRui Paulo bss->ssid.wep.default_len = bss->default_wep_key_len; 16445b9c547cSRui Paulo if (full_config && bss->default_wep_key_len) { 16455b9c547cSRui Paulo cipher = bss->default_wep_key_len >= 13 ? 16465b9c547cSRui Paulo WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; 16475b9c547cSRui Paulo } else if (full_config && bss->ssid.wep.keys_set) { 16485b9c547cSRui Paulo if (bss->ssid.wep.len[0] >= 13) 16495b9c547cSRui Paulo cipher = WPA_CIPHER_WEP104; 16505b9c547cSRui Paulo else 16515b9c547cSRui Paulo cipher = WPA_CIPHER_WEP40; 16525b9c547cSRui Paulo } 1653c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 16545b9c547cSRui Paulo bss->wpa_group = cipher; 16555b9c547cSRui Paulo bss->wpa_pairwise = cipher; 16565b9c547cSRui Paulo bss->rsn_pairwise = cipher; 16575b9c547cSRui Paulo if (full_config) 16585b9c547cSRui Paulo bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; 1659c1d255d3SCy Schubert #ifdef CONFIG_WEP 16605b9c547cSRui Paulo } else if (bss->ssid.wep.keys_set) { 16615b9c547cSRui Paulo int cipher = WPA_CIPHER_WEP40; 16625b9c547cSRui Paulo if (bss->ssid.wep.len[0] >= 13) 16635b9c547cSRui Paulo cipher = WPA_CIPHER_WEP104; 16645b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_STATIC_WEP; 16655b9c547cSRui Paulo bss->wpa_group = cipher; 16665b9c547cSRui Paulo bss->wpa_pairwise = cipher; 16675b9c547cSRui Paulo bss->rsn_pairwise = cipher; 16685b9c547cSRui Paulo if (full_config) 16695b9c547cSRui Paulo bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; 1670c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 16715b9c547cSRui Paulo } else if (bss->osen) { 16725b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_OSEN; 16735b9c547cSRui Paulo bss->wpa_group = WPA_CIPHER_CCMP; 16745b9c547cSRui Paulo bss->wpa_pairwise = 0; 16755b9c547cSRui Paulo bss->rsn_pairwise = WPA_CIPHER_CCMP; 16765b9c547cSRui Paulo } else { 16775b9c547cSRui Paulo bss->ssid.security_policy = SECURITY_PLAINTEXT; 1678325151a3SRui Paulo if (full_config) { 16795b9c547cSRui Paulo bss->wpa_group = WPA_CIPHER_NONE; 16805b9c547cSRui Paulo bss->wpa_pairwise = WPA_CIPHER_NONE; 16815b9c547cSRui Paulo bss->rsn_pairwise = WPA_CIPHER_NONE; 16825b9c547cSRui Paulo bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; 16835b9c547cSRui Paulo } 16845b9c547cSRui Paulo } 1685325151a3SRui Paulo } 16864bc52338SCy Schubert 16874bc52338SCy Schubert 16884bc52338SCy Schubert int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf) 16894bc52338SCy Schubert { 16904bc52338SCy Schubert int with_id = 0, without_id = 0; 16914bc52338SCy Schubert struct sae_password_entry *pw; 16924bc52338SCy Schubert 16934bc52338SCy Schubert if (conf->ssid.wpa_passphrase) 16944bc52338SCy Schubert without_id = 1; 16954bc52338SCy Schubert 16964bc52338SCy Schubert for (pw = conf->sae_passwords; pw; pw = pw->next) { 16974bc52338SCy Schubert if (pw->identifier) 16984bc52338SCy Schubert with_id = 1; 16994bc52338SCy Schubert else 17004bc52338SCy Schubert without_id = 1; 17014bc52338SCy Schubert if (with_id && without_id) 17024bc52338SCy Schubert break; 17034bc52338SCy Schubert } 17044bc52338SCy Schubert 17054bc52338SCy Schubert if (with_id && !without_id) 17064bc52338SCy Schubert return 2; 17074bc52338SCy Schubert return with_id; 17084bc52338SCy Schubert } 1709c1d255d3SCy Schubert 1710c1d255d3SCy Schubert 1711c1d255d3SCy Schubert bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf) 1712c1d255d3SCy Schubert { 1713c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK 1714c1d255d3SCy Schubert struct sae_password_entry *pw; 1715c1d255d3SCy Schubert 1716c1d255d3SCy Schubert for (pw = conf->sae_passwords; pw; pw = pw->next) { 1717c1d255d3SCy Schubert if (pw->pk) 1718c1d255d3SCy Schubert return true; 1719c1d255d3SCy Schubert } 1720c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */ 1721c1d255d3SCy Schubert 1722c1d255d3SCy Schubert return false; 1723c1d255d3SCy Schubert } 1724c1d255d3SCy Schubert 1725c1d255d3SCy Schubert 1726c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK 1727c1d255d3SCy Schubert bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf) 1728c1d255d3SCy Schubert { 1729c1d255d3SCy Schubert bool with_pk = false; 1730c1d255d3SCy Schubert struct sae_password_entry *pw; 1731c1d255d3SCy Schubert 1732c1d255d3SCy Schubert if (conf->ssid.wpa_passphrase) 1733c1d255d3SCy Schubert return false; 1734c1d255d3SCy Schubert 1735c1d255d3SCy Schubert for (pw = conf->sae_passwords; pw; pw = pw->next) { 1736c1d255d3SCy Schubert if (!pw->pk) 1737c1d255d3SCy Schubert return false; 1738c1d255d3SCy Schubert with_pk = true; 1739c1d255d3SCy Schubert } 1740c1d255d3SCy Schubert 1741c1d255d3SCy Schubert return with_pk; 1742c1d255d3SCy Schubert } 1743c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */ 1744*a90b9d01SCy Schubert 1745*a90b9d01SCy Schubert 1746*a90b9d01SCy Schubert int hostapd_acl_comp(const void *a, const void *b) 1747*a90b9d01SCy Schubert { 1748*a90b9d01SCy Schubert const struct mac_acl_entry *aa = a; 1749*a90b9d01SCy Schubert const struct mac_acl_entry *bb = b; 1750*a90b9d01SCy Schubert return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); 1751*a90b9d01SCy Schubert } 1752*a90b9d01SCy Schubert 1753*a90b9d01SCy Schubert 1754*a90b9d01SCy Schubert int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num, 1755*a90b9d01SCy Schubert int vlan_id, const u8 *addr) 1756*a90b9d01SCy Schubert { 1757*a90b9d01SCy Schubert struct mac_acl_entry *newacl; 1758*a90b9d01SCy Schubert 1759*a90b9d01SCy Schubert newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); 1760*a90b9d01SCy Schubert if (!newacl) { 1761*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, "MAC list reallocation failed"); 1762*a90b9d01SCy Schubert return -1; 1763*a90b9d01SCy Schubert } 1764*a90b9d01SCy Schubert 1765*a90b9d01SCy Schubert *acl = newacl; 1766*a90b9d01SCy Schubert os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); 1767*a90b9d01SCy Schubert os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id)); 1768*a90b9d01SCy Schubert (*acl)[*num].vlan_id.untagged = vlan_id; 1769*a90b9d01SCy Schubert (*acl)[*num].vlan_id.notempty = !!vlan_id; 1770*a90b9d01SCy Schubert (*num)++; 1771*a90b9d01SCy Schubert 1772*a90b9d01SCy Schubert return 0; 1773*a90b9d01SCy Schubert } 1774*a90b9d01SCy Schubert 1775*a90b9d01SCy Schubert 1776*a90b9d01SCy Schubert void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num, 1777*a90b9d01SCy Schubert const u8 *addr) 1778*a90b9d01SCy Schubert { 1779*a90b9d01SCy Schubert int i = 0; 1780*a90b9d01SCy Schubert 1781*a90b9d01SCy Schubert while (i < *num) { 1782*a90b9d01SCy Schubert if (ether_addr_equal((*acl)[i].addr, addr)) { 1783*a90b9d01SCy Schubert os_remove_in_array(*acl, *num, sizeof(**acl), i); 1784*a90b9d01SCy Schubert (*num)--; 1785*a90b9d01SCy Schubert } else { 1786*a90b9d01SCy Schubert i++; 1787*a90b9d01SCy Schubert } 1788*a90b9d01SCy Schubert } 1789*a90b9d01SCy Schubert } 1790