Remove experimental non-AP STA code from hostapd
[wpasupplicant] / hostapd / config.c
index dd805c1..2e890b4 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * hostapd / Configuration file
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2008, Intel Corporation
  *
  * 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
@@ -180,6 +181,17 @@ static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
        bss->eapol_version = EAPOL_VERSION;
 
        bss->max_listen_interval = 65535;
+
+#ifdef CONFIG_IEEE80211W
+       bss->assoc_ping_timeout = 1000;
+       bss->assoc_ping_attempts = 3;
+#endif /* CONFIG_IEEE80211W */
+#ifdef EAP_FAST
+        /* both anonymous and authenticated provisioning */
+       bss->eap_fast_prov = 3;
+       bss->pac_key_lifetime = 7 * 24 * 60 * 60;
+       bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
+#endif /* EAP_FAST */
 }
 
 
@@ -244,6 +256,14 @@ static struct hostapd_config * hostapd_config_defaults(void)
        conf->wme_ac_params[2] = ac_vi;
        conf->wme_ac_params[3] = ac_vo;
 
+#ifdef CONFIG_IEEE80211N
+       SET_2BIT_LE16(&conf->ht_capab,
+                     HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
+                     MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
+
+       conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
+#endif /* CONFIG_IEEE80211N */
+
        return conf;
 }
 
@@ -261,14 +281,23 @@ int hostapd_mac_comp_empty(const void *a)
 }
 
 
-static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
-                                      int *num)
+static int hostapd_acl_comp(const void *a, const void *b)
+{
+       const struct mac_acl_entry *aa = a;
+       const struct mac_acl_entry *bb = b;
+       return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
+}
+
+
+static int hostapd_config_read_maclist(const char *fname,
+                                      struct mac_acl_entry **acl, int *num)
 {
        FILE *f;
        char buf[128], *pos;
        int line = 0;
        u8 addr[ETH_ALEN];
-       macaddr *newacl;
+       struct mac_acl_entry *newacl;
+       int vlan_id;
 
        if (!fname)
                return 0;
@@ -302,7 +331,16 @@ static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
                        return -1;
                }
 
-               newacl = os_realloc(*acl, (*num + 1) * ETH_ALEN);
+               vlan_id = 0;
+               pos = buf;
+               while (*pos != '\0' && *pos != ' ' && *pos != '\t')
+                       pos++;
+               while (*pos == ' ' || *pos == '\t')
+                       pos++;
+               if (*pos != '\0')
+                       vlan_id = atoi(pos);
+
+               newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
                if (newacl == NULL) {
                        printf("MAC list reallocation failed\n");
                        fclose(f);
@@ -310,13 +348,14 @@ static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
                }
 
                *acl = newacl;
-               os_memcpy((*acl)[*num], addr, ETH_ALEN);
+               os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
+               (*acl)[*num].vlan_id = vlan_id;
                (*num)++;
        }
 
        fclose(f);
 
-       qsort(*acl, *num, sizeof(macaddr), hostapd_mac_comp);
+       qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
 
        return 0;
 }
@@ -784,6 +823,12 @@ static int hostapd_config_parse_key_mgmt(int line, const char *value)
                else if (os_strcmp(start, "FT-EAP") == 0)
                        val |= WPA_KEY_MGMT_FT_IEEE8021X;
 #endif /* CONFIG_IEEE80211R */
+#ifdef CONFIG_IEEE80211W
+               else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
+                       val |= WPA_KEY_MGMT_PSK_SHA256;
+               else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
+                       val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
+#endif /* CONFIG_IEEE80211W */
                else {
                        printf("Line %d: invalid key_mgmt '%s'\n",
                               line, start);
@@ -1400,15 +1445,6 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        conf->country[2] = ' ';
                } else if (os_strcmp(buf, "ieee80211d") == 0) {
                        conf->ieee80211d = atoi(pos);
-               } else if (os_strcmp(buf, "ieee80211h") == 0) {
-                       conf->ieee80211h = atoi(pos);
-               } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
-                       if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
-                               printf("Line %d: invalid MAC address '%s'\n",
-                                      line, pos);
-                               errors++;
-                       }
-                       bss->assoc_ap = 1;
                } else if (os_strcmp(buf, "ieee8021x") == 0) {
                        bss->ieee802_1x = atoi(pos);
                } else if (os_strcmp(buf, "eapol_version") == 0) {
@@ -1464,8 +1500,32 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                errors++;
                        }
                } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
-                       os_free(bss->eap_fast_a_id);
-                       bss->eap_fast_a_id = os_strdup(pos);
+                       size_t idlen = os_strlen(pos);
+                       if (idlen & 1) {
+                               printf("Line %d: Invalid eap_fast_a_id\n",
+                                      line);
+                               errors++;
+                       } else {
+                               os_free(bss->eap_fast_a_id);
+                               bss->eap_fast_a_id = os_malloc(idlen / 2);
+                               if (bss->eap_fast_a_id == NULL ||
+                                   hexstr2bin(pos, bss->eap_fast_a_id,
+                                              idlen / 2)) {
+                                       printf("Line %d: Failed to parse "
+                                              "eap_fast_a_id\n", line);
+                                       errors++;
+                               } else
+                                       bss->eap_fast_a_id_len = idlen / 2;
+                       }
+               } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
+                       os_free(bss->eap_fast_a_id_info);
+                       bss->eap_fast_a_id_info = os_strdup(pos);
+               } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
+                       bss->eap_fast_prov = atoi(pos);
+               } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
+                       bss->pac_key_lifetime = atoi(pos);
+               } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
+                       bss->pac_key_refresh_time = atoi(pos);
 #endif /* EAP_FAST */
 #ifdef EAP_SIM
                } else if (os_strcmp(buf, "eap_sim_db") == 0) {
@@ -1628,6 +1688,8 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        bss->wpa_strict_rekey = atoi(pos);
                } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
                        bss->wpa_gmk_rekey = atoi(pos);
+               } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
+                       bss->wpa_ptk_rekey = atoi(pos);
                } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
                        int len = os_strlen(pos);
                        if (len < 8 || len > 63) {
@@ -1856,6 +1918,11 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                printf("Line %d: invalid rate list\n", line);
                                errors++;
                        }
+               } else if (os_strcmp(buf, "preamble") == 0) {
+                       if (atoi(pos))
+                               conf->preamble = SHORT_PREAMBLE;
+                       else
+                               conf->preamble = LONG_PREAMBLE;
                } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
                        bss->ignore_broadcast_ssid = atoi(pos);
                } else if (os_strcmp(buf, "bridge_packets") == 0) {
@@ -1932,9 +1999,30 @@ struct hostapd_config * hostapd_config_read(const char *fname)
 #ifdef CONFIG_IEEE80211W
                } else if (os_strcmp(buf, "ieee80211w") == 0) {
                        bss->ieee80211w = atoi(pos);
+               } else if (os_strcmp(buf, "assoc_ping_timeout") == 0) {
+                       bss->assoc_ping_timeout = atoi(pos);
+                       if (bss->assoc_ping_timeout == 0) {
+                               printf("Line %d: invalid assoc_ping_timeout\n",
+                                       line);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "assoc_ping_attempts") == 0) {
+                       bss->assoc_ping_timeout = atoi(pos);
+                       if (bss->assoc_ping_timeout == 0) {
+                               printf("Line %d: invalid assoc_ping_attempts "
+                                      "(valid range: 1..255)\n",
+                                      line);
+                               errors++;
+                       }
 #endif /* CONFIG_IEEE80211W */
+#ifdef CONFIG_IEEE80211N
+               } else if (os_strcmp(buf, "ieee80211n") == 0) {
+                       conf->ieee80211n = atoi(pos);
+#endif /* CONFIG_IEEE80211N */
                } else if (os_strcmp(buf, "max_listen_interval") == 0) {
                        bss->max_listen_interval = atoi(pos);
+               } else if (os_strcmp(buf, "okc") == 0) {
+                       bss->okc = atoi(pos);
                } else {
                        printf("Line %d: unknown configuration item '%s'\n",
                               line, buf);
@@ -2087,6 +2175,7 @@ static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->dh_file);
        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);
@@ -2147,7 +2236,8 @@ void hostapd_config_free(struct hostapd_config *conf)
 
 /* Perform a binary search for given MAC address from a pre-sorted list.
  * Returns 1 if address is in the list or 0 if not. */
-int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
+int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
+                         const u8 *addr, int *vlan_id)
 {
        int start, end, middle, res;
 
@@ -2156,9 +2246,12 @@ int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
 
        while (start <= end) {
                middle = (start + end) / 2;
-               res = os_memcmp(list[middle], addr, ETH_ALEN);
-               if (res == 0)
+               res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
+               if (res == 0) {
+                       if (vlan_id)
+                               *vlan_id = list[middle].vlan_id;
                        return 1;
+               }
                if (res < 0)
                        start = middle + 1;
                else