]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/ap/ap_config.c
HE: Make the basic NSS/MCS configurable
[thirdparty/hostap.git] / src / ap / ap_config.c
index a29f4d0e0b87c4659fa17b2f2f1849ba95e32c1c..eecd215af278a3072d03427dd7d4cb74eedc1c48 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd / Configuration helper functions
- * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
 
 #include "utils/common.h"
 #include "crypto/sha1.h"
+#include "crypto/tls.h"
 #include "radius/radius_client.h"
 #include "common/ieee802_11_defs.h"
 #include "common/eapol_common.h"
+#include "common/dhcp.h"
 #include "eap_common/eap_wsc_common.h"
 #include "eap_server/eap.h"
 #include "wpa_auth.h"
 #include "sta_info.h"
+#include "airtime_policy.h"
 #include "ap_config.h"
 
 
@@ -36,8 +39,14 @@ static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
 }
 
 
+#ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
+#define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
+#endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
+
 void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
 {
+       dl_list_init(&bss->anqp_elem);
+
        bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
        bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
        bss->logger_syslog = (unsigned int) -1;
@@ -53,6 +62,10 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
 
        bss->wpa_group_rekey = 600;
        bss->wpa_gmk_rekey = 86400;
+       bss->wpa_group_update_count = 4;
+       bss->wpa_pairwise_update_count = 4;
+       bss->wpa_disable_eapol_key_retries =
+               DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
        bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
        bss->wpa_pairwise = WPA_CIPHER_TKIP;
        bss->wpa_group = WPA_CIPHER_TKIP;
@@ -63,6 +76,7 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
        bss->dtim_period = 2;
 
        bss->radius_server_auth_port = 1812;
+       bss->eap_sim_db_timeout = 1;
        bss->ap_max_inactivity = AP_MAX_INACTIVITY;
        bss->eapol_version = EAPOL_VERSION;
 
@@ -73,6 +87,7 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
 #ifdef CONFIG_IEEE80211W
        bss->assoc_sa_query_max_timeout = 1000;
        bss->assoc_sa_query_retry_timeout = 201;
+       bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
 #endif /* CONFIG_IEEE80211W */
 #ifdef EAP_SERVER_FAST
         /* both anonymous and authenticated provisioning */
@@ -84,13 +99,48 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
        /* Set to -1 as defaults depends on HT in setup */
        bss->wmm_enabled = -1;
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
        bss->ft_over_ds = 1;
-#endif /* CONFIG_IEEE80211R */
+       bss->rkh_pos_timeout = 86400;
+       bss->rkh_neg_timeout = 60;
+       bss->rkh_pull_timeout = 1000;
+       bss->rkh_pull_retries = 4;
+       bss->r0_key_lifetime = 1209600;
+#endif /* CONFIG_IEEE80211R_AP */
 
        bss->radius_das_time_window = 300;
 
        bss->sae_anti_clogging_threshold = 5;
+       bss->sae_sync = 5;
+
+       bss->gas_frag_limit = 1400;
+
+#ifdef CONFIG_FILS
+       dl_list_init(&bss->fils_realms);
+       bss->fils_hlp_wait_time = 30;
+       bss->dhcp_server_port = DHCP_SERVER_PORT;
+       bss->dhcp_relay_port = DHCP_SERVER_PORT;
+#endif /* CONFIG_FILS */
+
+       bss->broadcast_deauth = 1;
+
+#ifdef CONFIG_MBO
+       bss->mbo_cell_data_conn_pref = -1;
+#endif /* CONFIG_MBO */
+
+       /* Disable TLS v1.3 by default for now to avoid interoperability issue.
+        * This can be enabled by default once the implementation has been fully
+        * completed and tested with other implementations. */
+       bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
+
+       bss->send_probe_response = 1;
+
+#ifdef CONFIG_HS20
+       bss->hs20_release = (HS20_VERSION >> 4) + 1;
+#endif /* CONFIG_HS20 */
+
+       /* Default to strict CRL checking. */
+       bss->check_crl_strict = 1;
 }
 
 
@@ -106,9 +156,9 @@ struct hostapd_config * hostapd_config_defaults(void)
        const struct hostapd_wmm_ac_params ac_be =
                { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
        const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
-               { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
+               { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
        const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
-               { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
+               { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
        const struct hostapd_tx_queue_params txq_bk =
                { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
        const struct hostapd_tx_queue_params txq_be =
@@ -140,6 +190,7 @@ struct hostapd_config * hostapd_config_defaults(void)
 
        bss->radius = os_zalloc(sizeof(*bss->radius));
        if (bss->radius == NULL) {
+               os_free(conf->bss);
                os_free(conf);
                os_free(bss);
                return NULL;
@@ -150,9 +201,10 @@ struct hostapd_config * hostapd_config_defaults(void)
        conf->num_bss = 1;
 
        conf->beacon_int = 100;
-       conf->rts_threshold = -1; /* use driver default: 2347 */
-       conf->fragm_threshold = -1; /* user driver default: 2346 */
-       conf->send_probe_response = 1;
+       conf->rts_threshold = -2; /* use driver default: 2347 */
+       conf->fragm_threshold = -2; /* user driver default: 2346 */
+       /* Set to invalid value means do not add Power Constraint IE */
+       conf->local_pwr_constraint = -1;
 
        conf->wmm_ac_params[0] = ac_be;
        conf->wmm_ac_params[1] = ac_bk;
@@ -168,19 +220,42 @@ struct hostapd_config * hostapd_config_defaults(void)
 
        conf->ap_table_max_size = 255;
        conf->ap_table_expiration_time = 60;
+       conf->track_sta_max_age = 180;
 
 #ifdef CONFIG_TESTING_OPTIONS
-       conf->ignore_probe_probability = 0.0d;
-       conf->ignore_auth_probability = 0.0d;
-       conf->ignore_assoc_probability = 0.0d;
-       conf->ignore_reassoc_probability = 0.0d;
-       conf->corrupt_gtk_rekey_mic_probability = 0.0d;
+       conf->ignore_probe_probability = 0.0;
+       conf->ignore_auth_probability = 0.0;
+       conf->ignore_assoc_probability = 0.0;
+       conf->ignore_reassoc_probability = 0.0;
+       conf->corrupt_gtk_rekey_mic_probability = 0.0;
+       conf->ecsa_ie_only = 0;
 #endif /* CONFIG_TESTING_OPTIONS */
 
+       conf->acs = 0;
+       conf->acs_ch_list.num = 0;
 #ifdef CONFIG_ACS
        conf->acs_num_scans = 5;
 #endif /* CONFIG_ACS */
 
+#ifdef CONFIG_IEEE80211AX
+       conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
+               HE_OPERATION_RTS_THRESHOLD_OFFSET;
+       /* Set default basic MCS/NSS set to single stream MCS 0-7 */
+       conf->he_op.he_basic_mcs_nss_set = 0xfffc;
+#endif /* CONFIG_IEEE80211AX */
+
+       /* The third octet of the country string uses an ASCII space character
+        * by default to indicate that the regulations encompass all
+        * environments for the current frequency band in the country. */
+       conf->country[2] = ' ';
+
+       conf->rssi_reject_assoc_rssi = 0;
+       conf->rssi_reject_assoc_timeout = 30;
+
+#ifdef CONFIG_AIRTIME_POLICY
+       conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
+#endif /* CONFIG_AIRTIME_POLICY */
+
        return conf;
 }
 
@@ -191,18 +266,17 @@ int hostapd_mac_comp(const void *a, const void *b)
 }
 
 
-int hostapd_mac_comp_empty(const void *a)
-{
-       macaddr empty = { 0 };
-       return os_memcmp(a, empty, sizeof(macaddr));
-}
-
-
 static int hostapd_config_read_wpa_psk(const char *fname,
                                       struct hostapd_ssid *ssid)
 {
        FILE *f;
        char buf[128], *pos;
+       const char *keyid;
+       char *context;
+       char *context2;
+       char *token;
+       char *name;
+       char *value;
        int line = 0, ret = 0, len, ok;
        u8 addr[ETH_ALEN];
        struct hostapd_wpa_psk *psk;
@@ -217,6 +291,8 @@ static int hostapd_config_read_wpa_psk(const char *fname,
        }
 
        while (fgets(buf, sizeof(buf), f)) {
+               int vlan_id = 0;
+
                line++;
 
                if (buf[0] == '#')
@@ -232,9 +308,39 @@ static int hostapd_config_read_wpa_psk(const char *fname,
                if (buf[0] == '\0')
                        continue;
 
-               if (hwaddr_aton(buf, addr)) {
+               context = NULL;
+               keyid = NULL;
+               while ((token = str_token(buf, " ", &context))) {
+                       if (!os_strchr(token, '='))
+                               break;
+                       context2 = NULL;
+                       name = str_token(token, "=", &context2);
+                       if (!name)
+                               break;
+                       value = str_token(token, "", &context2);
+                       if (!value)
+                               value = "";
+                       if (!os_strcmp(name, "keyid")) {
+                               keyid = value;
+                       } else if (!os_strcmp(name, "vlanid")) {
+                               vlan_id = atoi(value);
+                       } else {
+                               wpa_printf(MSG_ERROR,
+                                          "Unrecognized '%s=%s' on line %d in '%s'",
+                                          name, value, line, fname);
+                               ret = -1;
+                               break;
+                       }
+               }
+
+               if (ret == -1)
+                       break;
+
+               if (!token)
+                       token = "";
+               if (hwaddr_aton(token, addr)) {
                        wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
-                                  "line %d in '%s'", buf, line, fname);
+                                  "line %d in '%s'", token, line, fname);
                        ret = -1;
                        break;
                }
@@ -245,20 +351,20 @@ static int hostapd_config_read_wpa_psk(const char *fname,
                        ret = -1;
                        break;
                }
+               psk->vlan_id = vlan_id;
                if (is_zero_ether_addr(addr))
                        psk->group = 1;
                else
                        os_memcpy(psk->addr, addr, ETH_ALEN);
 
-               pos = buf + 17;
-               if (*pos == '\0') {
+               pos = str_token(buf, "", &context);
+               if (!pos) {
                        wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
                                   line, fname);
                        os_free(psk);
                        ret = -1;
                        break;
                }
-               pos++;
 
                ok = 0;
                len = os_strlen(pos);
@@ -277,6 +383,18 @@ static int hostapd_config_read_wpa_psk(const char *fname,
                        break;
                }
 
+               if (keyid) {
+                       len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
+                       if ((size_t) len >= sizeof(psk->keyid)) {
+                               wpa_printf(MSG_ERROR,
+                                          "PSK keyid too long on line %d in '%s'",
+                                          line, fname);
+                               os_free(psk);
+                               ret = -1;
+                               break;
+                       }
+               }
+
                psk->next = ssid->wpa_psk;
                ssid->wpa_psk = psk;
        }
@@ -325,27 +443,7 @@ int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
                ssid->wpa_psk->group = 1;
        }
 
-       if (ssid->wpa_psk_file) {
-               if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
-                                               &conf->ssid))
-                       return -1;
-       }
-
-       return 0;
-}
-
-
-int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
-{
-       int i;
-
-       if (a->idx != b->idx || a->default_len != b->default_len)
-               return 1;
-       for (i = 0; i < NUM_WEP_KEYS; i++)
-               if (a->len[i] != b->len[i] ||
-                   os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
-                       return 1;
-       return 0;
+       return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
 }
 
 
@@ -385,55 +483,127 @@ static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
 }
 
 
-static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
+void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
 {
+       hostapd_config_free_radius_attr(user->accept_attr);
        os_free(user->identity);
-       os_free(user->password);
+       bin_clear_free(user->password, user->password_len);
+       bin_clear_free(user->salt, user->salt_len);
        os_free(user);
 }
 
 
+void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
+{
+       struct hostapd_eap_user *prev_user;
+
+       while (user) {
+               prev_user = user;
+               user = user->next;
+               hostapd_config_free_eap_user(prev_user);
+       }
+}
+
+
 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
 {
        int i;
        for (i = 0; i < NUM_WEP_KEYS; i++) {
-               os_free(keys->key[i]);
+               bin_clear_free(keys->key[i], keys->len[i]);
                keys->key[i] = NULL;
        }
 }
 
 
-void hostapd_config_free_bss(struct hostapd_bss_config *conf)
+void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
 {
-       struct hostapd_wpa_psk *psk, *prev;
-       struct hostapd_eap_user *user, *prev_user;
+       struct hostapd_wpa_psk *psk, *tmp;
 
-       if (conf == NULL)
-               return;
-
-       psk = conf->ssid.wpa_psk;
-       while (psk) {
-               prev = psk;
+       for (psk = *l; psk;) {
+               tmp = psk;
                psk = psk->next;
+               bin_clear_free(tmp, sizeof(*tmp));
+       }
+       *l = NULL;
+}
+
+
+static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
+{
+       struct anqp_element *elem;
+
+       while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
+                                    list))) {
+               dl_list_del(&elem->list);
+               wpabuf_free(elem->payload);
+               os_free(elem);
+       }
+}
+
+
+static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
+{
+#ifdef CONFIG_FILS
+       struct fils_realm *realm;
+
+       while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
+                                     list))) {
+               dl_list_del(&realm->list);
+               os_free(realm);
+       }
+#endif /* CONFIG_FILS */
+}
+
+
+static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
+{
+       struct sae_password_entry *pw, *tmp;
+
+       pw = conf->sae_passwords;
+       conf->sae_passwords = NULL;
+       while (pw) {
+               tmp = pw;
+               pw = pw->next;
+               str_clear_free(tmp->password);
+               os_free(tmp->identifier);
+               os_free(tmp);
+       }
+}
+
+
+#ifdef CONFIG_DPP2
+static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
+{
+       struct dpp_controller_conf *prev;
+
+       while (conf) {
+               prev = conf;
+               conf = conf->next;
                os_free(prev);
        }
+}
+#endif /* CONFIG_DPP2 */
 
-       os_free(conf->ssid.wpa_passphrase);
+
+void hostapd_config_free_bss(struct hostapd_bss_config *conf)
+{
+       if (conf == NULL)
+               return;
+
+       hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
+
+       str_clear_free(conf->ssid.wpa_passphrase);
        os_free(conf->ssid.wpa_psk_file);
        hostapd_config_free_wep(&conf->ssid.wep);
 #ifdef CONFIG_FULL_DYNAMIC_VLAN
        os_free(conf->ssid.vlan_tagged_interface);
 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
-       user = conf->eap_user;
-       while (user) {
-               prev_user = user;
-               user = user->next;
-               hostapd_config_free_eap_user(prev_user);
-       }
+       hostapd_config_free_eap_users(conf->eap_user);
        os_free(conf->eap_user_sqlite);
 
        os_free(conf->eap_req_id_text);
+       os_free(conf->erp_domain);
        os_free(conf->accept_mac);
        os_free(conf->deny_mac);
        os_free(conf->nas_identifier);
@@ -451,20 +621,23 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->server_cert);
        os_free(conf->private_key);
        os_free(conf->private_key_passwd);
+       os_free(conf->check_cert_subject);
        os_free(conf->ocsp_stapling_response);
+       os_free(conf->ocsp_stapling_response_multi);
        os_free(conf->dh_file);
+       os_free(conf->openssl_ciphers);
+       os_free(conf->openssl_ecdh_curves);
        os_free(conf->pac_opaque_encr_key);
        os_free(conf->eap_fast_a_id);
        os_free(conf->eap_fast_a_id_info);
        os_free(conf->eap_sim_db);
        os_free(conf->radius_server_clients);
-       os_free(conf->test_socket);
        os_free(conf->radius);
        os_free(conf->radius_das_shared_secret);
        hostapd_config_free_vlan(conf);
        os_free(conf->time_zone);
 
-#ifdef CONFIG_IEEE80211R
+#ifdef CONFIG_IEEE80211R_AP
        {
                struct ft_remote_r0kh *r0kh, *r0kh_prev;
                struct ft_remote_r1kh *r1kh, *r1kh_prev;
@@ -485,7 +658,7 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
                        os_free(r1kh_prev);
                }
        }
-#endif /* CONFIG_IEEE80211R */
+#endif /* CONFIG_IEEE80211R_AP */
 
 #ifdef CONFIG_WPS
        os_free(conf->wps_pin_requests);
@@ -498,12 +671,20 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->ap_pin);
        os_free(conf->extra_cred);
        os_free(conf->ap_settings);
+       hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
+       str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
        os_free(conf->upnp_iface);
        os_free(conf->friendly_name);
        os_free(conf->manufacturer_url);
        os_free(conf->model_description);
        os_free(conf->model_url);
        os_free(conf->upc);
+       {
+               unsigned int i;
+
+               for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
+                       wpabuf_free(conf->wps_vendor_ext[i]);
+       }
        wpabuf_free(conf->wps_nfc_dh_pubkey);
        wpabuf_free(conf->wps_nfc_dh_privkey);
        wpabuf_free(conf->wps_nfc_dev_pw);
@@ -511,10 +692,12 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
 
        os_free(conf->roaming_consortium);
        os_free(conf->venue_name);
+       os_free(conf->venue_url);
        os_free(conf->nai_realm_data);
        os_free(conf->network_auth_type);
        os_free(conf->anqp_3gpp_cell_net);
        os_free(conf->domain_name);
+       hostapd_config_free_anqp_elem(conf);
 
 #ifdef CONFIG_RADIUS_TEST
        os_free(conf->dump_msk_file);
@@ -525,14 +708,85 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->hs20_wan_metrics);
        os_free(conf->hs20_connection_capability);
        os_free(conf->hs20_operating_class);
+       os_free(conf->hs20_icons);
+       if (conf->hs20_osu_providers) {
+               size_t i;
+               for (i = 0; i < conf->hs20_osu_providers_count; i++) {
+                       struct hs20_osu_provider *p;
+                       size_t j;
+                       p = &conf->hs20_osu_providers[i];
+                       os_free(p->friendly_name);
+                       os_free(p->server_uri);
+                       os_free(p->method_list);
+                       for (j = 0; j < p->icons_count; j++)
+                               os_free(p->icons[j]);
+                       os_free(p->icons);
+                       os_free(p->osu_nai);
+                       os_free(p->osu_nai2);
+                       os_free(p->service_desc);
+               }
+               os_free(conf->hs20_osu_providers);
+       }
+       if (conf->hs20_operator_icon) {
+               size_t i;
+
+               for (i = 0; i < conf->hs20_operator_icon_count; i++)
+                       os_free(conf->hs20_operator_icon[i]);
+               os_free(conf->hs20_operator_icon);
+       }
+       os_free(conf->subscr_remediation_url);
+       os_free(conf->hs20_sim_provisioning_url);
+       os_free(conf->t_c_filename);
+       os_free(conf->t_c_server_url);
 #endif /* CONFIG_HS20 */
 
        wpabuf_free(conf->vendor_elements);
+       wpabuf_free(conf->assocresp_elements);
 
        os_free(conf->sae_groups);
+#ifdef CONFIG_OWE
+       os_free(conf->owe_groups);
+#endif /* CONFIG_OWE */
+
+       os_free(conf->wowlan_triggers);
 
        os_free(conf->server_id);
 
+#ifdef CONFIG_TESTING_OPTIONS
+       wpabuf_free(conf->own_ie_override);
+       wpabuf_free(conf->sae_commit_override);
+#endif /* CONFIG_TESTING_OPTIONS */
+
+       os_free(conf->no_probe_resp_if_seen_on);
+       os_free(conf->no_auth_if_seen_on);
+
+       hostapd_config_free_fils_realms(conf);
+
+#ifdef CONFIG_DPP
+       os_free(conf->dpp_connector);
+       wpabuf_free(conf->dpp_netaccesskey);
+       wpabuf_free(conf->dpp_csign);
+#ifdef CONFIG_DPP2
+       hostapd_dpp_controller_conf_free(conf->dpp_controller);
+#endif /* CONFIG_DPP2 */
+#endif /* CONFIG_DPP */
+
+       hostapd_config_free_sae_passwords(conf);
+
+#ifdef CONFIG_AIRTIME_POLICY
+       {
+               struct airtime_sta_weight *wt, *wt_prev;
+
+               wt = conf->airtime_weight_list;
+               conf->airtime_weight_list = NULL;
+               while (wt) {
+                       wt_prev = wt;
+                       wt = wt->next;
+                       os_free(wt_prev);
+               }
+       }
+#endif /* CONFIG_AIRTIME_POLICY */
+
        os_free(conf);
 }
 
@@ -553,6 +807,13 @@ void hostapd_config_free(struct hostapd_config *conf)
        os_free(conf->bss);
        os_free(conf->supported_rates);
        os_free(conf->basic_rates);
+       os_free(conf->acs_ch_list.range);
+       os_free(conf->driver_params);
+#ifdef CONFIG_ACS
+       os_free(conf->acs_chan_bias);
+#endif /* CONFIG_ACS */
+       wpabuf_free(conf->lci);
+       wpabuf_free(conf->civic);
 
        os_free(conf);
 }
@@ -569,7 +830,7 @@ void hostapd_config_free(struct hostapd_config *conf)
  * Perform a binary search for given MAC address from a pre-sorted list.
  */
 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
-                         const u8 *addr, int *vlan_id)
+                         const u8 *addr, struct vlan_description *vlan_id)
 {
        int start, end, middle, res;
 
@@ -609,11 +870,26 @@ int hostapd_rate_found(int *list, int rate)
 }
 
 
-int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
+int hostapd_vlan_valid(struct hostapd_vlan *vlan,
+                      struct vlan_description *vlan_desc)
 {
        struct hostapd_vlan *v = vlan;
+       int i;
+
+       if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
+           vlan_desc->untagged > MAX_VLAN_ID)
+               return 0;
+       for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
+               if (vlan_desc->tagged[i] < 0 ||
+                   vlan_desc->tagged[i] > MAX_VLAN_ID)
+                       return 0;
+       }
+       if (!vlan_desc->untagged && !vlan_desc->tagged[0])
+               return 0;
+
        while (v) {
-               if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
+               if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
+                   v->vlan_id == VLAN_ID_WILDCARD)
                        return 1;
                v = v->next;
        }
@@ -635,17 +911,19 @@ const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
 
 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
                           const u8 *addr, const u8 *p2p_dev_addr,
-                          const u8 *prev_psk)
+                          const u8 *prev_psk, int *vlan_id)
 {
        struct hostapd_wpa_psk *psk;
        int next_ok = prev_psk == NULL;
 
-       if (p2p_dev_addr) {
+       if (vlan_id)
+               *vlan_id = 0;
+
+       if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
                wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
                           " p2p_dev_addr=" MACSTR " prev_psk=%p",
                           MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
-               if (!is_zero_ether_addr(p2p_dev_addr))
-                       addr = NULL; /* Use P2P Device Address for matching */
+               addr = NULL; /* Use P2P Device Address for matching */
        } else {
                wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
                           " prev_psk=%p",
@@ -658,8 +936,11 @@ const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
                     (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
                     (!addr && p2p_dev_addr &&
                      os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
-                     0)))
+                     0))) {
+                       if (vlan_id)
+                               *vlan_id = psk->vlan_id;
                        return psk->psk;
+               }
 
                if (psk->psk == prev_psk)
                        next_ok = 1;
@@ -670,9 +951,10 @@ const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
 
 
 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
-                                   struct hostapd_config *conf)
+                                   struct hostapd_config *conf,
+                                   int full_config)
 {
-       if (bss->ieee802_1x && !bss->eap_server &&
+       if (full_config && bss->ieee802_1x && !bss->eap_server &&
            !bss->radius->auth_servers) {
                wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
                           "EAP authenticator configured).");
@@ -697,14 +979,15 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                }
        }
 
-       if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
+       if (full_config && bss->wpa &&
+           bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
            bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
                wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
                           "RADIUS checking (macaddr_acl=2) enabled.");
                return -1;
        }
 
-       if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
+       if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
            bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
            bss->ssid.wpa_psk_file == NULL &&
            (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
@@ -714,7 +997,7 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                return -1;
        }
 
-       if (hostapd_mac_comp_empty(bss->bssid) != 0) {
+       if (full_config && !is_zero_ether_addr(bss->bssid)) {
                size_t i;
 
                for (i = 0; i < conf->num_bss; i++) {
@@ -730,8 +1013,8 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                }
        }
 
-#ifdef CONFIG_IEEE80211R
-       if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
+#ifdef CONFIG_IEEE80211R_AP
+       if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
            (bss->nas_identifier == NULL ||
             os_strlen(bss->nas_identifier) < 1 ||
             os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
@@ -740,23 +1023,24 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                           "string");
                return -1;
        }
-#endif /* CONFIG_IEEE80211R */
+#endif /* CONFIG_IEEE80211R_AP */
 
 #ifdef CONFIG_IEEE80211N
-       if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
+       if (full_config && conf->ieee80211n &&
+           conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
                bss->disable_11n = 1;
                wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
-                          "allowed, disabling HT capabilites");
+                          "allowed, disabling HT capabilities");
        }
 
-       if (conf->ieee80211n &&
+       if (full_config && conf->ieee80211n &&
            bss->ssid.security_policy == SECURITY_STATIC_WEP) {
                bss->disable_11n = 1;
                wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
                           "allowed, disabling HT capabilities");
        }
 
-       if (conf->ieee80211n && bss->wpa &&
+       if (full_config && conf->ieee80211n && bss->wpa &&
            !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
            !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
                                   WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
@@ -768,30 +1052,52 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
        }
 #endif /* CONFIG_IEEE80211N */
 
-#ifdef CONFIG_WPS2
-       if (bss->wps_state && bss->ignore_broadcast_ssid) {
+#ifdef CONFIG_IEEE80211AC
+       if (full_config && conf->ieee80211ac &&
+           bss->ssid.security_policy == SECURITY_STATIC_WEP) {
+               bss->disable_11ac = 1;
+               wpa_printf(MSG_ERROR,
+                          "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
+       }
+
+       if (full_config && conf->ieee80211ac && bss->wpa &&
+           !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
+           !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
+                                  WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
+       {
+               bss->disable_11ac = 1;
+               wpa_printf(MSG_ERROR,
+                          "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
+       }
+#endif /* CONFIG_IEEE80211AC */
+
+#ifdef CONFIG_WPS
+       if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
                wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
                           "configuration forced WPS to be disabled");
                bss->wps_state = 0;
        }
 
-       if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
+       if (full_config && bss->wps_state &&
+           bss->ssid.wep.keys_set && bss->wpa == 0) {
                wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
                           "disabled");
                bss->wps_state = 0;
        }
 
-       if (bss->wps_state && bss->wpa &&
+       if (full_config && bss->wps_state && bss->wpa &&
            (!(bss->wpa & 2) ||
-            !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
+            !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
+                                   WPA_CIPHER_CCMP_256 |
+                                   WPA_CIPHER_GCMP_256)))) {
                wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
-                          "WPA2/CCMP forced WPS to be disabled");
+                          "WPA2/CCMP/GCMP forced WPS to be disabled");
                bss->wps_state = 0;
        }
-#endif /* CONFIG_WPS2 */
+#endif /* CONFIG_WPS */
 
 #ifdef CONFIG_HS20
-       if (bss->hs20 &&
+       if (full_config && bss->hs20 &&
            (!(bss->wpa & 2) ||
             !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
                                    WPA_CIPHER_CCMP_256 |
@@ -803,28 +1109,94 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
        }
 #endif /* CONFIG_HS20 */
 
+#ifdef CONFIG_MBO
+       if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
+           bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
+               wpa_printf(MSG_ERROR,
+                          "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
+               return -1;
+       }
+#endif /* CONFIG_MBO */
+
+#ifdef CONFIG_OCV
+       if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
+           bss->ocv) {
+               wpa_printf(MSG_ERROR,
+                          "OCV: PMF needs to be enabled whenever using OCV");
+               return -1;
+       }
+#endif /* CONFIG_OCV */
+
        return 0;
 }
 
 
-int hostapd_config_check(struct hostapd_config *conf)
+static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
+{
+       int tx_cwmin = conf->tx_queue[queue].cwmin;
+       int tx_cwmax = conf->tx_queue[queue].cwmax;
+       int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
+       int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
+
+       if (tx_cwmin > tx_cwmax) {
+               wpa_printf(MSG_ERROR,
+                          "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
+                          tx_cwmin, tx_cwmax);
+               return -1;
+       }
+       if (ac_cwmin > ac_cwmax) {
+               wpa_printf(MSG_ERROR,
+                          "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
+                          ac_cwmin, ac_cwmax);
+               return -1;
+       }
+       return 0;
+}
+
+
+int hostapd_config_check(struct hostapd_config *conf, int full_config)
 {
        size_t i;
 
-       if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
+       if (full_config && conf->ieee80211d &&
+           (!conf->country[0] || !conf->country[1])) {
                wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
                           "setting the country_code");
                return -1;
        }
 
-       if (conf->ieee80211h && !conf->ieee80211d) {
+       if (full_config && conf->ieee80211h && !conf->ieee80211d) {
                wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
                           "IEEE 802.11d enabled");
                return -1;
        }
 
+       if (full_config && conf->local_pwr_constraint != -1 &&
+           !conf->ieee80211d) {
+               wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
+               return -1;
+       }
+
+       if (full_config && conf->spectrum_mgmt_required &&
+           conf->local_pwr_constraint == -1) {
+               wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
+               return -1;
+       }
+
+#ifdef CONFIG_AIRTIME_POLICY
+       if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
+           !conf->airtime_update_interval) {
+               wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
+               return -1;
+       }
+#endif /* CONFIG_AIRTIME_POLICY */
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               if (hostapd_config_check_cw(conf, i))
+                       return -1;
+       }
+
        for (i = 0; i < conf->num_bss; i++) {
-               if (hostapd_config_check_bss(conf->bss[i], conf))
+               if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
                        return -1;
        }
 
@@ -832,7 +1204,8 @@ int hostapd_config_check(struct hostapd_config *conf)
 }
 
 
-void hostapd_set_security_params(struct hostapd_bss_config *bss)
+void hostapd_set_security_params(struct hostapd_bss_config *bss,
+                                int full_config)
 {
        if (bss->individual_wep_key_len == 0) {
                /* individual keys are not use; can use key idx0 for
@@ -842,11 +1215,20 @@ void hostapd_set_security_params(struct hostapd_bss_config *bss)
 
        if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
                bss->rsn_pairwise = bss->wpa_pairwise;
-       bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
-                                                   bss->rsn_pairwise);
-
-       bss->radius->auth_server = bss->radius->auth_servers;
-       bss->radius->acct_server = bss->radius->acct_servers;
+       if (bss->group_cipher)
+               bss->wpa_group = bss->group_cipher;
+       else
+               bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
+                                                           bss->wpa_pairwise,
+                                                           bss->rsn_pairwise);
+       if (!bss->wpa_group_rekey_set)
+               bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
+                       600 : 86400;
+
+       if (full_config) {
+               bss->radius->auth_server = bss->radius->auth_servers;
+               bss->radius->acct_server = bss->radius->acct_servers;
+       }
 
        if (bss->wpa && bss->ieee802_1x) {
                bss->ssid.security_policy = SECURITY_WPA;
@@ -856,12 +1238,20 @@ void hostapd_set_security_params(struct hostapd_bss_config *bss)
                int cipher = WPA_CIPHER_NONE;
                bss->ssid.security_policy = SECURITY_IEEE_802_1X;
                bss->ssid.wep.default_len = bss->default_wep_key_len;
-               if (bss->default_wep_key_len)
+               if (full_config && bss->default_wep_key_len) {
                        cipher = bss->default_wep_key_len >= 13 ?
                                WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
+               } else if (full_config && bss->ssid.wep.keys_set) {
+                       if (bss->ssid.wep.len[0] >= 13)
+                               cipher = WPA_CIPHER_WEP104;
+                       else
+                               cipher = WPA_CIPHER_WEP40;
+               }
                bss->wpa_group = cipher;
                bss->wpa_pairwise = cipher;
                bss->rsn_pairwise = cipher;
+               if (full_config)
+                       bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
        } else if (bss->ssid.wep.keys_set) {
                int cipher = WPA_CIPHER_WEP40;
                if (bss->ssid.wep.len[0] >= 13)
@@ -870,10 +1260,43 @@ void hostapd_set_security_params(struct hostapd_bss_config *bss)
                bss->wpa_group = cipher;
                bss->wpa_pairwise = cipher;
                bss->rsn_pairwise = cipher;
+               if (full_config)
+                       bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
+       } else if (bss->osen) {
+               bss->ssid.security_policy = SECURITY_OSEN;
+               bss->wpa_group = WPA_CIPHER_CCMP;
+               bss->wpa_pairwise = 0;
+               bss->rsn_pairwise = WPA_CIPHER_CCMP;
        } else {
                bss->ssid.security_policy = SECURITY_PLAINTEXT;
-               bss->wpa_group = WPA_CIPHER_NONE;
-               bss->wpa_pairwise = WPA_CIPHER_NONE;
-               bss->rsn_pairwise = WPA_CIPHER_NONE;
+               if (full_config) {
+                       bss->wpa_group = WPA_CIPHER_NONE;
+                       bss->wpa_pairwise = WPA_CIPHER_NONE;
+                       bss->rsn_pairwise = WPA_CIPHER_NONE;
+                       bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
+               }
        }
 }
+
+
+int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
+{
+       int with_id = 0, without_id = 0;
+       struct sae_password_entry *pw;
+
+       if (conf->ssid.wpa_passphrase)
+               without_id = 1;
+
+       for (pw = conf->sae_passwords; pw; pw = pw->next) {
+               if (pw->identifier)
+                       with_id = 1;
+               else
+                       without_id = 1;
+               if (with_id && without_id)
+                       break;
+       }
+
+       if (with_id && !without_id)
+               return 2;
+       return with_id;
+}