]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - hostapd/config_file.c
WNM: Additional BSS Transition Management capability
[thirdparty/hostap.git] / hostapd / config_file.c
index f4cd26308cb03c8c358d5fd256870b40966ac611..2ba7cc1272599fe338f678f954ebc6e9db84199a 100644 (file)
@@ -1,15 +1,9 @@
 /*
  * hostapd / Configuration file parser
- * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "utils/includes.h"
@@ -173,7 +167,7 @@ static int hostapd_config_read_maclist(const char *fname,
                if (*pos != '\0')
                        vlan_id = atoi(pos);
 
-               newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
+               newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
                if (newacl == NULL) {
                        wpa_printf(MSG_ERROR, "MAC list reallocation failed");
                        fclose(f);
@@ -206,6 +200,12 @@ static int hostapd_config_read_eap_user(const char *fname,
        if (!fname)
                return 0;
 
+       if (os_strncmp(fname, "sqlite:", 7) == 0) {
+               os_free(conf->eap_user_sqlite);
+               conf->eap_user_sqlite = os_strdup(fname + 7);
+               return 0;
+       }
+
        f = fopen(fname, "r");
        if (!f) {
                wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
@@ -330,7 +330,7 @@ static int hostapd_config_read_eap_user(const char *fname,
                        }
 
                        num_methods++;
-                       if (num_methods >= EAP_USER_MAX_METHODS)
+                       if (num_methods >= EAP_MAX_METHODS)
                                break;
                skip_eap:
                        if (pos3 == NULL)
@@ -481,7 +481,7 @@ hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
        int ret;
        static int server_index = 1;
 
-       nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
+       nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
        if (nserv == NULL)
                return -1;
 
@@ -497,6 +497,100 @@ hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
 
        return ret;
 }
+
+
+static struct hostapd_radius_attr *
+hostapd_parse_radius_attr(const char *value)
+{
+       const char *pos;
+       char syntax;
+       struct hostapd_radius_attr *attr;
+       size_t len;
+
+       attr = os_zalloc(sizeof(*attr));
+       if (attr == NULL)
+               return NULL;
+
+       attr->type = atoi(value);
+
+       pos = os_strchr(value, ':');
+       if (pos == NULL) {
+               attr->val = wpabuf_alloc(1);
+               if (attr->val == NULL) {
+                       os_free(attr);
+                       return NULL;
+               }
+               wpabuf_put_u8(attr->val, 0);
+               return attr;
+       }
+
+       pos++;
+       if (pos[0] == '\0' || pos[1] != ':') {
+               os_free(attr);
+               return NULL;
+       }
+       syntax = *pos++;
+       pos++;
+
+       switch (syntax) {
+       case 's':
+               attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
+               break;
+       case 'x':
+               len = os_strlen(pos);
+               if (len & 1)
+                       break;
+               len /= 2;
+               attr->val = wpabuf_alloc(len);
+               if (attr->val == NULL)
+                       break;
+               if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
+                       wpabuf_free(attr->val);
+                       os_free(attr);
+                       return NULL;
+               }
+               break;
+       case 'd':
+               attr->val = wpabuf_alloc(4);
+               if (attr->val)
+                       wpabuf_put_be32(attr->val, atoi(pos));
+               break;
+       default:
+               os_free(attr);
+               return NULL;
+       }
+
+       if (attr->val == NULL) {
+               os_free(attr);
+               return NULL;
+       }
+
+       return attr;
+}
+
+
+static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
+                                   const char *val)
+{
+       char *secret;
+
+       secret = os_strchr(val, ' ');
+       if (secret == NULL)
+               return -1;
+
+       secret++;
+
+       if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
+               return -1;
+
+       os_free(bss->radius_das_shared_secret);
+       bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
+       if (bss->radius_das_shared_secret == NULL)
+               return -1;
+       bss->radius_das_shared_secret_len = os_strlen(secret);
+
+       return 0;
+}
 #endif /* CONFIG_NO_RADIUS */
 
 
@@ -536,6 +630,12 @@ static int hostapd_config_parse_key_mgmt(int line, const char *value)
                else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
                        val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
 #endif /* CONFIG_IEEE80211W */
+#ifdef CONFIG_SAE
+               else if (os_strcmp(start, "SAE") == 0)
+                       val |= WPA_KEY_MGMT_SAE;
+               else if (os_strcmp(start, "FT-SAE") == 0)
+                       val |= WPA_KEY_MGMT_FT_SAE;
+#endif /* CONFIG_SAE */
                else {
                        wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
                                   line, start);
@@ -581,6 +681,8 @@ static int hostapd_config_parse_cipher(int line, const char *value)
                *end = '\0';
                if (os_strcmp(start, "CCMP") == 0)
                        val |= WPA_CIPHER_CCMP;
+               else if (os_strcmp(start, "GCMP") == 0)
+                       val |= WPA_CIPHER_GCMP;
                else if (os_strcmp(start, "TKIP") == 0)
                        val |= WPA_CIPHER_TKIP;
                else if (os_strcmp(start, "WEP104") == 0)
@@ -692,8 +794,8 @@ static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
        if (*ifname == '\0')
                return -1;
 
-       bss = os_realloc(conf->bss, (conf->num_bss + 1) *
-                        sizeof(struct hostapd_bss_config));
+       bss = os_realloc_array(conf->bss, conf->num_bss + 1,
+                              sizeof(struct hostapd_bss_config));
        if (bss == NULL) {
                wpa_printf(MSG_ERROR, "Failed to allocate memory for "
                           "multi-BSS entry");
@@ -817,78 +919,6 @@ static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
 }
 
 
-static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
-                                char *val)
-{
-       int num, v;
-       char *pos;
-       struct hostapd_wmm_ac_params *ac;
-
-       /* skip 'wme_ac_' or 'wmm_ac_' prefix */
-       pos = name + 7;
-       if (os_strncmp(pos, "be_", 3) == 0) {
-               num = 0;
-               pos += 3;
-       } else if (os_strncmp(pos, "bk_", 3) == 0) {
-               num = 1;
-               pos += 3;
-       } else if (os_strncmp(pos, "vi_", 3) == 0) {
-               num = 2;
-               pos += 3;
-       } else if (os_strncmp(pos, "vo_", 3) == 0) {
-               num = 3;
-               pos += 3;
-       } else {
-               wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
-               return -1;
-       }
-
-       ac = &conf->wmm_ac_params[num];
-
-       if (os_strcmp(pos, "aifs") == 0) {
-               v = atoi(val);
-               if (v < 1 || v > 255) {
-                       wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
-                       return -1;
-               }
-               ac->aifs = v;
-       } else if (os_strcmp(pos, "cwmin") == 0) {
-               v = atoi(val);
-               if (v < 0 || v > 12) {
-                       wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
-                       return -1;
-               }
-               ac->cwmin = v;
-       } else if (os_strcmp(pos, "cwmax") == 0) {
-               v = atoi(val);
-               if (v < 0 || v > 12) {
-                       wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
-                       return -1;
-               }
-               ac->cwmax = v;
-       } else if (os_strcmp(pos, "txop_limit") == 0) {
-               v = atoi(val);
-               if (v < 0 || v > 0xffff) {
-                       wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
-                       return -1;
-               }
-               ac->txop_limit = v;
-       } else if (os_strcmp(pos, "acm") == 0) {
-               v = atoi(val);
-               if (v < 0 || v > 1) {
-                       wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
-                       return -1;
-               }
-               ac->admission_control_mandatory = v;
-       } else {
-               wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
-               return -1;
-       }
-
-       return 0;
-}
-
-
 #ifdef CONFIG_IEEE80211R
 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
 {
@@ -1040,6 +1070,71 @@ static int hostapd_config_ht_capab(struct hostapd_config *conf,
 #endif /* CONFIG_IEEE80211N */
 
 
+#ifdef CONFIG_IEEE80211AC
+static int hostapd_config_vht_capab(struct hostapd_config *conf,
+                                   const char *capab)
+{
+       if (os_strstr(capab, "[MAX-MPDU-7991]"))
+               conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
+       if (os_strstr(capab, "[MAX-MPDU-11454]"))
+               conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
+       if (os_strstr(capab, "[VHT160]"))
+               conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
+       if (os_strstr(capab, "[VHT160-80PLUS80]"))
+               conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
+       if (os_strstr(capab, "[VHT160-80PLUS80]"))
+               conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
+       if (os_strstr(capab, "[RXLDPC]"))
+               conf->vht_capab |= VHT_CAP_RXLDPC;
+       if (os_strstr(capab, "[SHORT-GI-80]"))
+               conf->vht_capab |= VHT_CAP_SHORT_GI_80;
+       if (os_strstr(capab, "[SHORT-GI-160]"))
+               conf->vht_capab |= VHT_CAP_SHORT_GI_160;
+       if (os_strstr(capab, "[TX-STBC-2BY1]"))
+               conf->vht_capab |= VHT_CAP_TXSTBC;
+       if (os_strstr(capab, "[RX-STBC-1]"))
+               conf->vht_capab |= VHT_CAP_RXSTBC_1;
+       if (os_strstr(capab, "[RX-STBC-12]"))
+               conf->vht_capab |= VHT_CAP_RXSTBC_2;
+       if (os_strstr(capab, "[RX-STBC-123]"))
+               conf->vht_capab |= VHT_CAP_RXSTBC_3;
+       if (os_strstr(capab, "[RX-STBC-1234]"))
+               conf->vht_capab |= VHT_CAP_RXSTBC_4;
+       if (os_strstr(capab, "[SU-BEAMFORMER]"))
+               conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
+       if (os_strstr(capab, "[SU-BEAMFORMEE]"))
+               conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+       if (os_strstr(capab, "[BF-ANTENNA-2]") &&
+           (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
+               conf->vht_capab |= VHT_CAP_BEAMFORMER_ANTENNAS_MAX;
+       if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
+           (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
+               conf->vht_capab |= VHT_CAP_SOUNDING_DIMENTION_MAX;
+       if (os_strstr(capab, "[MU-BEAMFORMER]"))
+               conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
+       if (os_strstr(capab, "[MU-BEAMFORMEE]"))
+               conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+       if (os_strstr(capab, "[VHT-TXOP-PS]"))
+               conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
+       if (os_strstr(capab, "[HTC-VHT]"))
+               conf->vht_capab |= VHT_CAP_HTC_VHT;
+       if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
+               conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
+       if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
+           (conf->vht_capab & VHT_CAP_HTC_VHT))
+               conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
+       if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
+           (conf->vht_capab & VHT_CAP_HTC_VHT))
+               conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
+       if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
+               conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
+       if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
+               conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
+       return 0;
+}
+#endif /* CONFIG_IEEE80211AC */
+
+
 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                                    struct hostapd_config *conf)
 {
@@ -1050,9 +1145,18 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                return -1;
        }
 
+       if (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) &&
            bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
-           bss->ssid.wpa_psk_file == NULL) {
+           bss->ssid.wpa_psk_file == NULL &&
+           (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
+            bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
                wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
                           "is not configured.");
                return -1;
@@ -1075,8 +1179,7 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
        }
 
 #ifdef CONFIG_IEEE80211R
-       if ((bss->wpa_key_mgmt &
-            (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
+       if (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)) {
@@ -1088,19 +1191,26 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
 #endif /* CONFIG_IEEE80211R */
 
 #ifdef CONFIG_IEEE80211N
+       if (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");
+       }
+
        if (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");
-               return -1;
+                          "allowed, disabling HT capabilities");
        }
 
        if (conf->ieee80211n && bss->wpa &&
            !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
-           !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
+           !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP))) {
+               bss->disable_11n = 1;
                wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
-                          "requires CCMP to be enabled");
-               return -1;
+                          "requires CCMP/GCMP to be enabled, disabling HT "
+                          "capabilities");
        }
 #endif /* CONFIG_IEEE80211N */
 
@@ -1116,8 +1226,27 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                           "disabled");
                bss->wps_state = 0;
        }
+
+       if (bss->wps_state && bss->wpa &&
+           (!(bss->wpa & 2) ||
+            !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
+               wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
+                          "WPA2/CCMP forced WPS to be disabled");
+               bss->wps_state = 0;
+       }
 #endif /* CONFIG_WPS2 */
 
+#ifdef CONFIG_HS20
+       if (bss->hs20 &&
+           (!(bss->wpa & 2) ||
+            !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
+               wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
+                          "configuration is required for Hotspot 2.0 "
+                          "functionality");
+               return -1;
+       }
+#endif /* CONFIG_HS20 */
+
        return 0;
 }
 
@@ -1141,73 +1270,452 @@ static int hostapd_config_check(struct hostapd_config *conf)
 }
 
 
-/**
- * hostapd_config_read - Read and parse a configuration file
- * @fname: Configuration file name (including path, if needed)
- * Returns: Allocated configuration data structure
- */
-struct hostapd_config * hostapd_config_read(const char *fname)
+#ifdef CONFIG_INTERWORKING
+static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
+                                   int line)
 {
-       struct hostapd_config *conf;
-       struct hostapd_bss_config *bss;
-       FILE *f;
-       char buf[256], *pos;
-       int line = 0;
-       int errors = 0;
-       int pairwise;
-       size_t i;
+       size_t len = os_strlen(pos);
+       u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
 
-       f = fopen(fname, "r");
-       if (f == NULL) {
-               wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
-                          "for reading.", fname);
-               return NULL;
+       struct hostapd_roaming_consortium *rc;
+
+       if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
+           hexstr2bin(pos, oi, len / 2)) {
+               wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
+                          "'%s'", line, pos);
+               return -1;
        }
+       len /= 2;
 
-       conf = hostapd_config_defaults();
-       if (conf == NULL) {
-               fclose(f);
-               return NULL;
+       rc = os_realloc_array(bss->roaming_consortium,
+                             bss->roaming_consortium_count + 1,
+                             sizeof(struct hostapd_roaming_consortium));
+       if (rc == NULL)
+               return -1;
+
+       os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
+       rc[bss->roaming_consortium_count].len = len;
+
+       bss->roaming_consortium = rc;
+       bss->roaming_consortium_count++;
+
+       return 0;
+}
+
+
+static int parse_lang_string(struct hostapd_lang_string **array,
+                            unsigned int *count, char *pos)
+{
+       char *sep;
+       size_t clen, nlen;
+       struct hostapd_lang_string *ls;
+
+       sep = os_strchr(pos, ':');
+       if (sep == NULL)
+               return -1;
+       *sep++ = '\0';
+
+       clen = os_strlen(pos);
+       if (clen < 2)
+               return -1;
+       nlen = os_strlen(sep);
+       if (nlen > 252)
+               return -1;
+
+       ls = os_realloc_array(*array, *count + 1,
+                             sizeof(struct hostapd_lang_string));
+       if (ls == NULL)
+               return -1;
+
+       *array = ls;
+       ls = &(*array)[*count];
+       (*count)++;
+
+       os_memset(ls->lang, 0, sizeof(ls->lang));
+       os_memcpy(ls->lang, pos, clen);
+       ls->name_len = nlen;
+       os_memcpy(ls->name, sep, nlen);
+
+       return 0;
+}
+
+
+static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
+                           int line)
+{
+       if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
+               wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
+                          line, pos);
+               return -1;
        }
+       return 0;
+}
 
-       /* set default driver based on configuration */
-       conf->driver = wpa_drivers[0];
-       if (conf->driver == NULL) {
-               wpa_printf(MSG_ERROR, "No driver wrappers registered!");
-               hostapd_config_free(conf);
-               fclose(f);
-               return NULL;
+
+static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
+                              int line)
+{
+       size_t count;
+       char *pos;
+       u8 *info = NULL, *ipos;
+
+       /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
+
+       count = 1;
+       for (pos = buf; *pos; pos++) {
+               if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
+                       goto fail;
+               if (*pos == ';')
+                       count++;
        }
+       if (1 + count * 3 > 0x7f)
+               goto fail;
 
-       bss = conf->last_bss = conf->bss;
+       info = os_zalloc(2 + 3 + count * 3);
+       if (info == NULL)
+               return -1;
 
-       while (fgets(buf, sizeof(buf), f)) {
-               bss = conf->last_bss;
-               line++;
+       ipos = info;
+       *ipos++ = 0; /* GUD - Version 1 */
+       *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
+       *ipos++ = 0; /* PLMN List IEI */
+       /* ext(b8) | Length of PLMN List value contents(b7..1) */
+       *ipos++ = 1 + count * 3;
+       *ipos++ = count; /* Number of PLMNs */
+
+       pos = buf;
+       while (pos && *pos) {
+               char *mcc, *mnc;
+               size_t mnc_len;
+
+               mcc = pos;
+               mnc = os_strchr(pos, ',');
+               if (mnc == NULL)
+                       goto fail;
+               *mnc++ = '\0';
+               pos = os_strchr(mnc, ';');
+               if (pos)
+                       *pos++ = '\0';
+
+               mnc_len = os_strlen(mnc);
+               if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
+                       goto fail;
+
+               /* BC coded MCC,MNC */
+               /* MCC digit 2 | MCC digit 1 */
+               *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
+               /* MNC digit 3 | MCC digit 3 */
+               *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
+                       (mcc[2] - '0');
+               /* MNC digit 2 | MNC digit 1 */
+               *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
+       }
 
-               if (buf[0] == '#')
-                       continue;
-               pos = buf;
-               while (*pos != '\0') {
-                       if (*pos == '\n') {
-                               *pos = '\0';
+       os_free(bss->anqp_3gpp_cell_net);
+       bss->anqp_3gpp_cell_net = info;
+       bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
+       wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
+                   bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
+
+       return 0;
+
+fail:
+       wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
+                  line, buf);
+       os_free(info);
+       return -1;
+}
+
+
+static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
+{
+       struct hostapd_nai_realm_data *realm;
+       size_t i, j, len;
+       int *offsets;
+       char *pos, *end, *rpos;
+
+       offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
+                           sizeof(int));
+       if (offsets == NULL)
+               return -1;
+
+       for (i = 0; i < bss->nai_realm_count; i++) {
+               realm = &bss->nai_realm_data[i];
+               for (j = 0; j < MAX_NAI_REALMS; j++) {
+                       offsets[i * MAX_NAI_REALMS + j] =
+                               realm->realm[j] ?
+                               realm->realm[j] - realm->realm_buf : -1;
+               }
+       }
+
+       realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
+                                sizeof(struct hostapd_nai_realm_data));
+       if (realm == NULL) {
+               os_free(offsets);
+               return -1;
+       }
+       bss->nai_realm_data = realm;
+
+       /* patch the pointers after realloc */
+       for (i = 0; i < bss->nai_realm_count; i++) {
+               realm = &bss->nai_realm_data[i];
+               for (j = 0; j < MAX_NAI_REALMS; j++) {
+                       int offs = offsets[i * MAX_NAI_REALMS + j];
+                       if (offs >= 0)
+                               realm->realm[j] = realm->realm_buf + offs;
+                       else
+                               realm->realm[j] = NULL;
+               }
+       }
+       os_free(offsets);
+
+       realm = &bss->nai_realm_data[bss->nai_realm_count];
+       os_memset(realm, 0, sizeof(*realm));
+
+       pos = buf;
+       realm->encoding = atoi(pos);
+       pos = os_strchr(pos, ',');
+       if (pos == NULL)
+               goto fail;
+       pos++;
+
+       end = os_strchr(pos, ',');
+       if (end) {
+               len = end - pos;
+               *end = '\0';
+       } else {
+               len = os_strlen(pos);
+       }
+
+       if (len > MAX_NAI_REALMLEN) {
+               wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
+                          "characters)", (int) len, MAX_NAI_REALMLEN);
+               goto fail;
+       }
+       os_memcpy(realm->realm_buf, pos, len);
+
+       if (end)
+               pos = end + 1;
+       else
+               pos = NULL;
+
+       while (pos && *pos) {
+               struct hostapd_nai_realm_eap *eap;
+
+               if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
+                       wpa_printf(MSG_ERROR, "Too many EAP methods");
+                       goto fail;
+               }
+
+               eap = &realm->eap_method[realm->eap_method_count];
+               realm->eap_method_count++;
+
+               end = os_strchr(pos, ',');
+               if (end == NULL)
+                       end = pos + os_strlen(pos);
+
+               eap->eap_method = atoi(pos);
+               for (;;) {
+                       pos = os_strchr(pos, '[');
+                       if (pos == NULL || pos > end)
                                break;
-                       }
                        pos++;
+                       if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
+                               wpa_printf(MSG_ERROR, "Too many auth params");
+                               goto fail;
+                       }
+                       eap->auth_id[eap->num_auths] = atoi(pos);
+                       pos = os_strchr(pos, ':');
+                       if (pos == NULL || pos > end)
+                               goto fail;
+                       pos++;
+                       eap->auth_val[eap->num_auths] = atoi(pos);
+                       pos = os_strchr(pos, ']');
+                       if (pos == NULL || pos > end)
+                               goto fail;
+                       pos++;
+                       eap->num_auths++;
                }
-               if (buf[0] == '\0')
-                       continue;
 
-               pos = os_strchr(buf, '=');
-               if (pos == NULL) {
-                       wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
-                                  line, buf);
-                       errors++;
-                       continue;
+               if (*end != ',')
+                       break;
+
+               pos = end + 1;
+       }
+
+       /* Split realm list into null terminated realms */
+       rpos = realm->realm_buf;
+       i = 0;
+       while (*rpos) {
+               if (i >= MAX_NAI_REALMS) {
+                       wpa_printf(MSG_ERROR, "Too many realms");
+                       goto fail;
                }
-               *pos = '\0';
-               pos++;
+               realm->realm[i++] = rpos;
+               rpos = os_strchr(rpos, ';');
+               if (rpos == NULL)
+                       break;
+               *rpos++ = '\0';
+       }
+
+       bss->nai_realm_count++;
+
+       return 0;
+
+fail:
+       wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
+       return -1;
+}
+
+#endif /* CONFIG_INTERWORKING */
 
+
+#ifdef CONFIG_HS20
+static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
+                                int line)
+{
+       u8 *conn_cap;
+       char *pos;
+
+       if (bss->hs20_connection_capability_len >= 0xfff0)
+               return -1;
+
+       conn_cap = os_realloc(bss->hs20_connection_capability,
+                             bss->hs20_connection_capability_len + 4);
+       if (conn_cap == NULL)
+               return -1;
+
+       bss->hs20_connection_capability = conn_cap;
+       conn_cap += bss->hs20_connection_capability_len;
+       pos = buf;
+       conn_cap[0] = atoi(pos);
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               return -1;
+       pos++;
+       WPA_PUT_LE16(conn_cap + 1, atoi(pos));
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               return -1;
+       pos++;
+       conn_cap[3] = atoi(pos);
+       bss->hs20_connection_capability_len += 4;
+
+       return 0;
+}
+
+
+static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
+                                 int line)
+{
+       u8 *wan_metrics;
+       char *pos;
+
+       /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
+
+       wan_metrics = os_zalloc(13);
+       if (wan_metrics == NULL)
+               return -1;
+
+       pos = buf;
+       /* WAN Info */
+       if (hexstr2bin(pos, wan_metrics, 1) < 0)
+               goto fail;
+       pos += 2;
+       if (*pos != ':')
+               goto fail;
+       pos++;
+
+       /* Downlink Speed */
+       WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               goto fail;
+       pos++;
+
+       /* Uplink Speed */
+       WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               goto fail;
+       pos++;
+
+       /* Downlink Load */
+       wan_metrics[9] = atoi(pos);
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               goto fail;
+       pos++;
+
+       /* Uplink Load */
+       wan_metrics[10] = atoi(pos);
+       pos = os_strchr(pos, ':');
+       if (pos == NULL)
+               goto fail;
+       pos++;
+
+       /* LMD */
+       WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
+
+       os_free(bss->hs20_wan_metrics);
+       bss->hs20_wan_metrics = wan_metrics;
+
+       return 0;
+
+fail:
+       wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
+                  line, pos);
+       os_free(wan_metrics);
+       return -1;
+}
+
+
+static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
+                                        char *pos, int line)
+{
+       if (parse_lang_string(&bss->hs20_oper_friendly_name,
+                             &bss->hs20_oper_friendly_name_count, pos)) {
+               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                          "hs20_oper_friendly_name '%s'", line, pos);
+               return -1;
+       }
+       return 0;
+}
+#endif /* CONFIG_HS20 */
+
+
+#ifdef CONFIG_WPS_NFC
+static struct wpabuf * hostapd_parse_bin(const char *buf)
+{
+       size_t len;
+       struct wpabuf *ret;
+
+       len = os_strlen(buf);
+       if (len & 0x01)
+               return NULL;
+       len /= 2;
+
+       ret = wpabuf_alloc(len);
+       if (ret == NULL)
+               return NULL;
+
+       if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
+               wpabuf_free(ret);
+               return NULL;
+       }
+
+       return ret;
+}
+#endif /* CONFIG_WPS_NFC */
+
+
+static int hostapd_config_fill(struct hostapd_config *conf,
+                              struct hostapd_bss_config *bss,
+                              char *buf, char *pos, int line)
+{
+       int errors = 0;
+
+       {
                if (os_strcmp(buf, "interface") == 0) {
                        os_strlcpy(conf->bss[0].iface, pos,
                                   sizeof(conf->bss[0].iface));
@@ -1256,9 +1764,24 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        } else {
                                os_memcpy(bss->ssid.ssid, pos,
                                          bss->ssid.ssid_len);
-                               bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
                                bss->ssid.ssid_set = 1;
                        }
+               } else if (os_strcmp(buf, "ssid2") == 0) {
+                       size_t slen;
+                       char *str = wpa_config_parse_string(pos, &slen);
+                       if (str == NULL || slen < 1 ||
+                                  slen > HOSTAPD_MAX_SSID_LEN) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
+                                          "'%s'", line, pos);
+                               errors++;
+                       } else {
+                               os_memcpy(bss->ssid.ssid, str, slen);
+                               bss->ssid.ssid_len = slen;
+                               bss->ssid.ssid_set = 1;
+                       }
+                       os_free(str);
+               } else if (os_strcmp(buf, "utf8_ssid") == 0) {
+                       bss->ssid.utf8_ssid = atoi(pos) > 0;
                } else if (os_strcmp(buf, "macaddr_acl") == 0) {
                        bss->macaddr_acl = atoi(pos);
                        if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
@@ -1291,6 +1814,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        bss->isolate = atoi(pos);
                } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
                        bss->ap_max_inactivity = atoi(pos);
+               } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
+                       bss->skip_inactivity_poll = atoi(pos);
                } else if (os_strcmp(buf, "country_code") == 0) {
                        os_memcpy(conf->country, pos, 2);
                        /* FIX: make this configurable */
@@ -1407,7 +1932,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "allocate memory for "
                                           "eap_req_id_text", line);
                                errors++;
-                               continue;
+                               return errors;
                        }
                        bss->eap_req_id_text_len =
                                os_strlen(bss->eap_req_id_text);
@@ -1527,6 +2052,51 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
                {
                        bss->acct_interim_interval = atoi(pos);
+               } else if (os_strcmp(buf, "radius_request_cui") == 0) {
+                       bss->radius_request_cui = atoi(pos);
+               } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
+                       struct hostapd_radius_attr *attr, *a;
+                       attr = hostapd_parse_radius_attr(pos);
+                       if (attr == NULL) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "radius_auth_req_attr", line);
+                               errors++;
+                       } else if (bss->radius_auth_req_attr == NULL) {
+                               bss->radius_auth_req_attr = attr;
+                       } else {
+                               a = bss->radius_auth_req_attr;
+                               while (a->next)
+                                       a = a->next;
+                               a->next = attr;
+                       }
+               } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
+                       struct hostapd_radius_attr *attr, *a;
+                       attr = hostapd_parse_radius_attr(pos);
+                       if (attr == NULL) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "radius_acct_req_attr", line);
+                               errors++;
+                       } else if (bss->radius_acct_req_attr == NULL) {
+                               bss->radius_acct_req_attr = attr;
+                       } else {
+                               a = bss->radius_acct_req_attr;
+                               while (a->next)
+                                       a = a->next;
+                               a->next = attr;
+                       }
+               } else if (os_strcmp(buf, "radius_das_port") == 0) {
+                       bss->radius_das_port = atoi(pos);
+               } else if (os_strcmp(buf, "radius_das_client") == 0) {
+                       if (hostapd_parse_das_client(bss, pos) < 0) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "DAS client", line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
+                       bss->radius_das_time_window = atoi(pos);
+               } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
+                          == 0) {
+                       bss->radius_das_require_event_timestamp = atoi(pos);
 #endif /* CONFIG_NO_RADIUS */
                } else if (os_strcmp(buf, "auth_algs") == 0) {
                        bss->auth_algs = atoi(pos);
@@ -1566,6 +2136,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        } else {
                                os_free(bss->ssid.wpa_passphrase);
                                bss->ssid.wpa_passphrase = os_strdup(pos);
+                               os_free(bss->ssid.wpa_psk);
+                               bss->ssid.wpa_psk = NULL;
                        }
                } else if (os_strcmp(buf, "wpa_psk") == 0) {
                        os_free(bss->ssid.wpa_psk);
@@ -1581,6 +2153,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                errors++;
                        } else {
                                bss->ssid.wpa_psk->group = 1;
+                               os_free(bss->ssid.wpa_passphrase);
+                               bss->ssid.wpa_passphrase = NULL;
                        }
                } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
                        os_free(bss->ssid.wpa_psk_file);
@@ -1595,6 +2169,16 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                hostapd_config_parse_key_mgmt(line, pos);
                        if (bss->wpa_key_mgmt == -1)
                                errors++;
+               } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
+                       bss->wpa_psk_radius = atoi(pos);
+                       if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
+                           bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
+                           bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
+                               wpa_printf(MSG_ERROR, "Line %d: unknown "
+                                          "wpa_psk_radius %d",
+                                          line, bss->wpa_psk_radius);
+                               errors++;
+                       }
                } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
                        bss->wpa_pairwise =
                                hostapd_config_parse_cipher(line, pos);
@@ -1641,7 +2225,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                wpa_printf(MSG_DEBUG, "Line %d: Invalid "
                                           "mobility_domain '%s'", line, pos);
                                errors++;
-                               continue;
+                               return errors;
                        }
                } else if (os_strcmp(buf, "r1_key_holder") == 0) {
                        if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
@@ -1650,7 +2234,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                wpa_printf(MSG_DEBUG, "Line %d: Invalid "
                                           "r1_key_holder '%s'", line, pos);
                                errors++;
-                               continue;
+                               return errors;
                        }
                } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
                        bss->r0_key_lifetime = atoi(pos);
@@ -1661,17 +2245,19 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                wpa_printf(MSG_DEBUG, "Line %d: Invalid "
                                           "r0kh '%s'", line, pos);
                                errors++;
-                               continue;
+                               return errors;
                        }
                } else if (os_strcmp(buf, "r1kh") == 0) {
                        if (add_r1kh(bss, pos) < 0) {
                                wpa_printf(MSG_DEBUG, "Line %d: Invalid "
                                           "r1kh '%s'", line, pos);
                                errors++;
-                               continue;
+                               return errors;
                        }
                } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
                        bss->pmk_r1_push = atoi(pos);
+               } else if (os_strcmp(buf, "ft_over_ds") == 0) {
+                       bss->ft_over_ds = atoi(pos);
 #endif /* CONFIG_IEEE80211R */
 #ifndef CONFIG_NO_CTRL_IFACE
                } else if (os_strcmp(buf, "ctrl_interface") == 0) {
@@ -1690,7 +2276,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
                                           " (from group name '%s')",
                                           bss->ctrl_interface_gid, group);
-                               continue;
+                               return errors;
                        }
 
                        /* Group name not found - try to parse this as gid */
@@ -1699,7 +2285,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
                                           "'%s'", line, group);
                                errors++;
-                               continue;
+                               return errors;
                        }
                        bss->ctrl_interface_gid_set = 1;
                        wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
@@ -1727,11 +2313,28 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
                        else if (os_strcmp(pos, "g") == 0)
                                conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
+                       else if (os_strcmp(pos, "ad") == 0)
+                               conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
                        else {
                                wpa_printf(MSG_ERROR, "Line %d: unknown "
                                           "hw_mode '%s'", line, pos);
                                errors++;
                        }
+               } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
+                       if (os_strcmp(pos, "a") == 0)
+                               bss->wps_rf_bands = WPS_RF_50GHZ;
+                       else if (os_strcmp(pos, "g") == 0 ||
+                                os_strcmp(pos, "b") == 0)
+                               bss->wps_rf_bands = WPS_RF_24GHZ;
+                       else if (os_strcmp(pos, "ag") == 0 ||
+                                os_strcmp(pos, "ga") == 0)
+                               bss->wps_rf_bands =
+                                       WPS_RF_24GHZ | WPS_RF_50GHZ;
+                       else {
+                               wpa_printf(MSG_ERROR, "Line %d: unknown "
+                                          "wps_rf_band '%s'", line, pos);
+                               errors++;
+                       }
                } else if (os_strcmp(buf, "channel") == 0) {
                        conf->channel = atoi(pos);
                } else if (os_strcmp(buf, "beacon_int") == 0) {
@@ -1828,6 +2431,15 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "read VLAN file '%s'", line, pos);
                                errors++;
                        }
+               } else if (os_strcmp(buf, "vlan_naming") == 0) {
+                       bss->ssid.vlan_naming = atoi(pos);
+                       if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
+                           bss->ssid.vlan_naming < 0) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "naming scheme %d", line,
+                                           bss->ssid.vlan_naming);
+                               errors++;
+                        }
 #ifdef CONFIG_FULL_DYNAMIC_VLAN
                } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
                        bss->ssid.vlan_tagged_interface = os_strdup(pos);
@@ -1850,7 +2462,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        bss->wmm_uapsd = atoi(pos);
                } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
                           os_strncmp(buf, "wmm_ac_", 7) == 0) {
-                       if (hostapd_config_wmm_ac(conf, buf, pos)) {
+                       if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
+                                                 pos)) {
                                wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
                                           "ac item", line);
                                errors++;
@@ -1899,8 +2512,30 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "require_ht") == 0) {
                        conf->require_ht = atoi(pos);
 #endif /* CONFIG_IEEE80211N */
+#ifdef CONFIG_IEEE80211AC
+               } else if (os_strcmp(buf, "ieee80211ac") == 0) {
+                       conf->ieee80211ac = atoi(pos);
+               } else if (os_strcmp(buf, "vht_capab") == 0) {
+                       if (hostapd_config_vht_capab(conf, pos) < 0) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "vht_capab", line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "require_vht") == 0) {
+                       conf->require_vht = atoi(pos);
+               } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
+                       conf->vht_oper_chwidth = atoi(pos);
+               } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
+               {
+                       conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
+               } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
+               {
+                       conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
+#endif /* CONFIG_IEEE80211AC */
                } else if (os_strcmp(buf, "max_listen_interval") == 0) {
                        bss->max_listen_interval = atoi(pos);
+               } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
+                       bss->disable_pmksa_caching = atoi(pos);
                } else if (os_strcmp(buf, "okc") == 0) {
                        bss->okc = atoi(pos);
 #ifdef CONFIG_WPS
@@ -1963,8 +2598,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        os_free(bss->serial_number);
                        bss->serial_number = os_strdup(pos);
                } else if (os_strcmp(buf, "device_type") == 0) {
-                       os_free(bss->device_type);
-                       bss->device_type = os_strdup(pos);
+                       if (wps_dev_type_str2bin(pos, bss->device_type))
+                               errors++;
                } else if (os_strcmp(buf, "config_methods") == 0) {
                        os_free(bss->config_methods);
                        bss->config_methods = os_strdup(pos);
@@ -2018,6 +2653,27 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "upc") == 0) {
                        os_free(bss->upc);
                        bss->upc = os_strdup(pos);
+               } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
+                       bss->pbc_in_m1 = atoi(pos);
+#ifdef CONFIG_WPS_NFC
+               } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
+                       bss->wps_nfc_dev_pw_id = atoi(pos);
+                       if (bss->wps_nfc_dev_pw_id < 0x10 ||
+                           bss->wps_nfc_dev_pw_id > 0xffff) {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "wps_nfc_dev_pw_id value", line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
+                       wpabuf_free(bss->wps_nfc_dh_pubkey);
+                       bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
+               } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
+                       wpabuf_free(bss->wps_nfc_dh_privkey);
+                       bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
+               } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
+                       wpabuf_free(bss->wps_nfc_dev_pw);
+                       bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
+#endif /* CONFIG_WPS_NFC */
 #endif /* CONFIG_WPS */
 #ifdef CONFIG_P2P_MANAGER
                } else if (os_strcmp(buf, "manage_p2p") == 0) {
@@ -2046,6 +2702,239 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
                        else
                                bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
+#ifdef CONFIG_RSN_TESTING
+               } else if (os_strcmp(buf, "rsn_testing") == 0) {
+                       extern int rsn_testing;
+                       rsn_testing = atoi(pos);
+#endif /* CONFIG_RSN_TESTING */
+               } else if (os_strcmp(buf, "time_advertisement") == 0) {
+                       bss->time_advertisement = atoi(pos);
+               } else if (os_strcmp(buf, "time_zone") == 0) {
+                       size_t tz_len = os_strlen(pos);
+                       if (tz_len < 4 || tz_len > 255) {
+                               wpa_printf(MSG_DEBUG, "Line %d: invalid "
+                                          "time_zone", line);
+                               errors++;
+                               return errors;
+                       }
+                       os_free(bss->time_zone);
+                       bss->time_zone = os_strdup(pos);
+                       if (bss->time_zone == NULL)
+                               errors++;
+#ifdef CONFIG_WNM
+               } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
+                       bss->wnm_sleep_mode = atoi(pos);
+               } else if (os_strcmp(buf, "bss_transition") == 0) {
+                       bss->bss_transition = atoi(pos);
+#endif /* CONFIG_WNM */
+#ifdef CONFIG_INTERWORKING
+               } else if (os_strcmp(buf, "interworking") == 0) {
+                       bss->interworking = atoi(pos);
+               } else if (os_strcmp(buf, "access_network_type") == 0) {
+                       bss->access_network_type = atoi(pos);
+                       if (bss->access_network_type < 0 ||
+                           bss->access_network_type > 15) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "access_network_type", line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "internet") == 0) {
+                       bss->internet = atoi(pos);
+               } else if (os_strcmp(buf, "asra") == 0) {
+                       bss->asra = atoi(pos);
+               } else if (os_strcmp(buf, "esr") == 0) {
+                       bss->esr = atoi(pos);
+               } else if (os_strcmp(buf, "uesa") == 0) {
+                       bss->uesa = atoi(pos);
+               } else if (os_strcmp(buf, "venue_group") == 0) {
+                       bss->venue_group = atoi(pos);
+                       bss->venue_info_set = 1;
+               } else if (os_strcmp(buf, "venue_type") == 0) {
+                       bss->venue_type = atoi(pos);
+                       bss->venue_info_set = 1;
+               } else if (os_strcmp(buf, "hessid") == 0) {
+                       if (hwaddr_aton(pos, bss->hessid)) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid "
+                                          "hessid", line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "roaming_consortium") == 0) {
+                       if (parse_roaming_consortium(bss, pos, line) < 0)
+                               errors++;
+               } else if (os_strcmp(buf, "venue_name") == 0) {
+                       if (parse_venue_name(bss, pos, line) < 0)
+                               errors++;
+               } else if (os_strcmp(buf, "network_auth_type") == 0) {
+                       u8 auth_type;
+                       u16 redirect_url_len;
+                       if (hexstr2bin(pos, &auth_type, 1)) {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "network_auth_type '%s'",
+                                          line, pos);
+                               errors++;
+                               return errors;
+                       }
+                       if (auth_type == 0 || auth_type == 2)
+                               redirect_url_len = os_strlen(pos + 2);
+                       else
+                               redirect_url_len = 0;
+                       os_free(bss->network_auth_type);
+                       bss->network_auth_type =
+                               os_malloc(redirect_url_len + 3 + 1);
+                       if (bss->network_auth_type == NULL) {
+                               errors++;
+                               return errors;
+                       }
+                       *bss->network_auth_type = auth_type;
+                       WPA_PUT_LE16(bss->network_auth_type + 1,
+                                    redirect_url_len);
+                       if (redirect_url_len)
+                               os_memcpy(bss->network_auth_type + 3,
+                                         pos + 2, redirect_url_len);
+                       bss->network_auth_type_len = 3 + redirect_url_len;
+               } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
+                       if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
+                       {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "ipaddr_type_availability '%s'",
+                                          line, pos);
+                               bss->ipaddr_type_configured = 0;
+                               errors++;
+                               return errors;
+                       }
+                       bss->ipaddr_type_configured = 1;
+               } else if (os_strcmp(buf, "domain_name") == 0) {
+                       int j, num_domains, domain_len, domain_list_len = 0;
+                       char *tok_start, *tok_prev;
+                       u8 *domain_list, *domain_ptr;
+
+                       domain_list_len = os_strlen(pos) + 1;
+                       domain_list = os_malloc(domain_list_len);
+                       if (domain_list == NULL) {
+                               errors++;
+                               return errors;
+                       }
+
+                       domain_ptr = domain_list;
+                       tok_prev = pos;
+                       num_domains = 1;
+                       while ((tok_prev = os_strchr(tok_prev, ','))) {
+                               num_domains++;
+                               tok_prev++;
+                       }
+                       tok_prev = pos;
+                       for (j = 0; j < num_domains; j++) {
+                               tok_start = os_strchr(tok_prev, ',');
+                               if (tok_start) {
+                                       domain_len = tok_start - tok_prev;
+                                       *domain_ptr = domain_len;
+                                       os_memcpy(domain_ptr + 1, tok_prev,
+                                                 domain_len);
+                                       domain_ptr += domain_len + 1;
+                                       tok_prev = ++tok_start;
+                               } else {
+                                       domain_len = os_strlen(tok_prev);
+                                       *domain_ptr = domain_len;
+                                       os_memcpy(domain_ptr + 1, tok_prev,
+                                                 domain_len);
+                                       domain_ptr += domain_len + 1;
+                               }
+                       }
+
+                       os_free(bss->domain_name);
+                       bss->domain_name = domain_list;
+                       bss->domain_name_len = domain_list_len;
+               } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
+                       if (parse_3gpp_cell_net(bss, pos, line) < 0)
+                               errors++;
+               } else if (os_strcmp(buf, "nai_realm") == 0) {
+                       if (parse_nai_realm(bss, pos, line) < 0)
+                               errors++;
+               } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
+                       bss->gas_frag_limit = atoi(pos);
+               } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
+                       bss->gas_comeback_delay = atoi(pos);
+#endif /* CONFIG_INTERWORKING */
+#ifdef CONFIG_RADIUS_TEST
+               } else if (os_strcmp(buf, "dump_msk_file") == 0) {
+                       os_free(bss->dump_msk_file);
+                       bss->dump_msk_file = os_strdup(pos);
+#endif /* CONFIG_RADIUS_TEST */
+#ifdef CONFIG_HS20
+               } else if (os_strcmp(buf, "hs20") == 0) {
+                       bss->hs20 = atoi(pos);
+               } else if (os_strcmp(buf, "disable_dgaf") == 0) {
+                       bss->disable_dgaf = atoi(pos);
+               } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
+                       if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
+                               errors++;
+               } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
+                       if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
+                               errors++;
+                               return errors;
+                       }
+               } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
+                       if (hs20_parse_conn_capab(bss, pos, line) < 0) {
+                               errors++;
+                               return errors;
+                       }
+               } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
+                       u8 *oper_class;
+                       size_t oper_class_len;
+                       oper_class_len = os_strlen(pos);
+                       if (oper_class_len < 2 || (oper_class_len & 0x01)) {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "hs20_operating_class '%s'",
+                                          line, pos);
+                               errors++;
+                               return errors;
+                       }
+                       oper_class_len /= 2;
+                       oper_class = os_malloc(oper_class_len);
+                       if (oper_class == NULL) {
+                               errors++;
+                               return errors;
+                       }
+                       if (hexstr2bin(pos, oper_class, oper_class_len)) {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "hs20_operating_class '%s'",
+                                          line, pos);
+                               os_free(oper_class);
+                               errors++;
+                               return errors;
+                       }
+                       os_free(bss->hs20_operating_class);
+                       bss->hs20_operating_class = oper_class;
+                       bss->hs20_operating_class_len = oper_class_len;
+#endif /* CONFIG_HS20 */
+               } else if (os_strcmp(buf, "vendor_elements") == 0) {
+                       struct wpabuf *elems;
+                       size_t len = os_strlen(pos);
+                       if (len & 0x01) {
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "vendor_elements '%s'", line, pos);
+                               return 1;
+                       }
+                       len /= 2;
+                       if (len == 0) {
+                               wpabuf_free(bss->vendor_elements);
+                               bss->vendor_elements = NULL;
+                               return 0;
+                       }
+
+                       elems = wpabuf_alloc(len);
+                       if (elems == NULL)
+                               return 1;
+
+                       if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
+                               wpabuf_free(elems);
+                               wpa_printf(MSG_ERROR, "Line %d: Invalid "
+                                          "vendor_elements '%s'", line, pos);
+                               return 1;
+                       }
+
+                       wpabuf_free(bss->vendor_elements);
+                       bss->vendor_elements = elems;
                } else {
                        wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
                                   "item '%s'", line, buf);
@@ -2053,48 +2942,145 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                }
        }
 
-       fclose(f);
+       return errors;
+}
 
-       for (i = 0; i < conf->num_bss; i++) {
-               bss = &conf->bss[i];
 
-               if (bss->individual_wep_key_len == 0) {
-                       /* individual keys are not use; can use key idx0 for
-                        * broadcast keys */
-                       bss->broadcast_key_idx_min = 0;
+static void hostapd_set_security_params(struct hostapd_bss_config *bss)
+{
+       int pairwise;
+
+       if (bss->individual_wep_key_len == 0) {
+               /* individual keys are not use; can use key idx0 for
+                * broadcast keys */
+               bss->broadcast_key_idx_min = 0;
+       }
+
+       /* Select group cipher based on the enabled pairwise cipher
+        * suites */
+       pairwise = 0;
+       if (bss->wpa & 1)
+               pairwise |= bss->wpa_pairwise;
+       if (bss->wpa & 2) {
+               if (bss->rsn_pairwise == 0)
+                       bss->rsn_pairwise = bss->wpa_pairwise;
+               pairwise |= bss->rsn_pairwise;
+       }
+       if (pairwise & WPA_CIPHER_TKIP)
+               bss->wpa_group = WPA_CIPHER_TKIP;
+       else if ((pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ==
+                WPA_CIPHER_GCMP)
+               bss->wpa_group = WPA_CIPHER_GCMP;
+       else
+               bss->wpa_group = WPA_CIPHER_CCMP;
+
+       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;
+       } else if (bss->wpa) {
+               bss->ssid.security_policy = SECURITY_WPA_PSK;
+       } else if (bss->ieee802_1x) {
+               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)
+                       cipher = bss->default_wep_key_len >= 13 ?
+                               WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
+               bss->wpa_group = cipher;
+               bss->wpa_pairwise = cipher;
+               bss->rsn_pairwise = cipher;
+       } else if (bss->ssid.wep.keys_set) {
+               int cipher = WPA_CIPHER_WEP40;
+               if (bss->ssid.wep.len[0] >= 13)
+                       cipher = WPA_CIPHER_WEP104;
+               bss->ssid.security_policy = SECURITY_STATIC_WEP;
+               bss->wpa_group = cipher;
+               bss->wpa_pairwise = cipher;
+               bss->rsn_pairwise = cipher;
+       } 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;
+       }
+}
+
+
+/**
+ * hostapd_config_read - Read and parse a configuration file
+ * @fname: Configuration file name (including path, if needed)
+ * Returns: Allocated configuration data structure
+ */
+struct hostapd_config * hostapd_config_read(const char *fname)
+{
+       struct hostapd_config *conf;
+       struct hostapd_bss_config *bss;
+       FILE *f;
+       char buf[512], *pos;
+       int line = 0;
+       int errors = 0;
+       size_t i;
+
+       f = fopen(fname, "r");
+       if (f == NULL) {
+               wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
+                          "for reading.", fname);
+               return NULL;
+       }
+
+       conf = hostapd_config_defaults();
+       if (conf == NULL) {
+               fclose(f);
+               return NULL;
+       }
+
+       /* set default driver based on configuration */
+       conf->driver = wpa_drivers[0];
+       if (conf->driver == NULL) {
+               wpa_printf(MSG_ERROR, "No driver wrappers registered!");
+               hostapd_config_free(conf);
+               fclose(f);
+               return NULL;
+       }
+
+       bss = conf->last_bss = conf->bss;
+
+       while (fgets(buf, sizeof(buf), f)) {
+               bss = conf->last_bss;
+               line++;
+
+               if (buf[0] == '#')
+                       continue;
+               pos = buf;
+               while (*pos != '\0') {
+                       if (*pos == '\n') {
+                               *pos = '\0';
+                               break;
+                       }
+                       pos++;
                }
+               if (buf[0] == '\0')
+                       continue;
 
-               /* Select group cipher based on the enabled pairwise cipher
-                * suites */
-               pairwise = 0;
-               if (bss->wpa & 1)
-                       pairwise |= bss->wpa_pairwise;
-               if (bss->wpa & 2) {
-                       if (bss->rsn_pairwise == 0)
-                               bss->rsn_pairwise = bss->wpa_pairwise;
-                       pairwise |= bss->rsn_pairwise;
+               pos = os_strchr(buf, '=');
+               if (pos == NULL) {
+                       wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
+                                  line, buf);
+                       errors++;
+                       continue;
                }
-               if (pairwise & WPA_CIPHER_TKIP)
-                       bss->wpa_group = WPA_CIPHER_TKIP;
-               else
-                       bss->wpa_group = WPA_CIPHER_CCMP;
-
-               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;
-               } else if (bss->wpa) {
-                       bss->ssid.security_policy = SECURITY_WPA_PSK;
-               } else if (bss->ieee802_1x) {
-                       bss->ssid.security_policy = SECURITY_IEEE_802_1X;
-                       bss->ssid.wep.default_len = bss->default_wep_key_len;
-               } else if (bss->ssid.wep.keys_set)
-                       bss->ssid.security_policy = SECURITY_STATIC_WEP;
-               else
-                       bss->ssid.security_policy = SECURITY_PLAINTEXT;
+               *pos = '\0';
+               pos++;
+               errors += hostapd_config_fill(conf, bss, buf, pos, line);
        }
 
+       fclose(f);
+
+       for (i = 0; i < conf->num_bss; i++)
+               hostapd_set_security_params(&conf->bss[i]);
+
        if (hostapd_config_check(conf))
                errors++;
 
@@ -2109,3 +3095,28 @@ struct hostapd_config * hostapd_config_read(const char *fname)
 
        return conf;
 }
+
+
+int hostapd_set_iface(struct hostapd_config *conf,
+                     struct hostapd_bss_config *bss, char *field, char *value)
+{
+       int errors;
+       size_t i;
+
+       errors = hostapd_config_fill(conf, bss, field, value, 0);
+       if (errors) {
+               wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
+                          "to value '%s'", field, value);
+               return -1;
+       }
+
+       for (i = 0; i < conf->num_bss; i++)
+               hostapd_set_security_params(&conf->bss[i]);
+
+       if (hostapd_config_check(conf)) {
+               wpa_printf(MSG_ERROR, "Configuration check failed");
+               return -1;
+       }
+
+       return 0;
+}