Merge wpa_supplicant and hostapd driver wrapper implementations
[wpasupplicant] / hostapd / config.c
index 5097f4d..fae4444 100644 (file)
@@ -19,7 +19,7 @@
 #endif /* CONFIG_NATIVE_WINDOWS */
 
 #include "hostapd.h"
-#include "driver.h"
+#include "drivers/driver.h"
 #include "sha1.h"
 #include "eap_server/eap.h"
 #include "radius/radius_client.h"
 #include "wpa.h"
 #include "uuid.h"
 #include "eap_common/eap_wsc_common.h"
+#include "sta_info.h"
+#include "config.h"
 
 
 #define MAX_STA_COUNT 2007
 
-extern struct wpa_driver_ops *hostapd_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 
 #ifndef CONFIG_NO_VLAN
@@ -189,28 +191,28 @@ static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
        bss->assoc_sa_query_max_timeout = 1000;
        bss->assoc_sa_query_retry_timeout = 201;
 #endif /* CONFIG_IEEE80211W */
-#ifdef EAP_FAST
+#ifdef EAP_SERVER_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 */
+#endif /* EAP_SERVER_FAST */
 }
 
 
-static struct hostapd_config * hostapd_config_defaults(void)
+struct hostapd_config * hostapd_config_defaults(void)
 {
        struct hostapd_config *conf;
        struct hostapd_bss_config *bss;
        int i;
        const int aCWmin = 15, aCWmax = 1024;
-       const struct hostapd_wme_ac_params ac_bk =
+       const struct hostapd_wmm_ac_params ac_bk =
                { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
-       const struct hostapd_wme_ac_params ac_be =
+       const struct hostapd_wmm_ac_params ac_be =
                { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
-       const struct hostapd_wme_ac_params ac_vi = /* video traffic */
+       const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
                { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
-       const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
+       const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
                { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
 
        conf = os_zalloc(sizeof(*conf));
@@ -224,7 +226,7 @@ static struct hostapd_config * hostapd_config_defaults(void)
        }
 
        /* set default driver based on configuration */
-       conf->driver = hostapd_drivers[0];
+       conf->driver = wpa_drivers[0];
        if (conf->driver == NULL) {
                wpa_printf(MSG_ERROR, "No driver wrappers registered!");
                os_free(conf);
@@ -250,15 +252,13 @@ static struct hostapd_config * hostapd_config_defaults(void)
        conf->send_probe_response = 1;
        conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
 
-       os_memcpy(conf->country, "US ", 3);
-
        for (i = 0; i < NUM_TX_QUEUES; i++)
                conf->tx_queue[i].aifs = -1; /* use hw default */
 
-       conf->wme_ac_params[0] = ac_be;
-       conf->wme_ac_params[1] = ac_bk;
-       conf->wme_ac_params[2] = ac_vi;
-       conf->wme_ac_params[3] = ac_vo;
+       conf->wmm_ac_params[0] = ac_be;
+       conf->wmm_ac_params[1] = ac_bk;
+       conf->wmm_ac_params[2] = ac_vi;
+       conf->wmm_ac_params[3] = ac_vo;
 
 #ifdef CONFIG_IEEE80211N
        conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
@@ -476,11 +476,6 @@ int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
                wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
                            ssid->wpa_psk->psk, PMK_LEN);
                ssid->wpa_psk->group = 1;
-
-               os_memset(ssid->wpa_passphrase, 0,
-                         os_strlen(ssid->wpa_passphrase));
-               os_free(ssid->wpa_passphrase);
-               ssid->wpa_passphrase = NULL;
        }
 
        if (ssid->wpa_psk_file) {
@@ -975,6 +970,12 @@ static int hostapd_config_check(struct hostapd_config *conf)
 {
        size_t i;
 
+       if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
+               wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
+                          "setting the country_code");
+               return -1;
+       }
+
        for (i = 0; i < conf->num_bss; i++) {
                if (hostapd_config_check_bss(&conf->bss[i], conf))
                        return -1;
@@ -1171,14 +1172,14 @@ static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
 }
 
 
-static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
-                                  char *val)
+static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
+                                char *val)
 {
        int num, v;
        char *pos;
-       struct hostapd_wme_ac_params *ac;
+       struct hostapd_wmm_ac_params *ac;
 
-       /* skip 'wme_ac_' prefix */
+       /* skip 'wme_ac_' or 'wmm_ac_' prefix */
        pos = name + 7;
        if (os_strncmp(pos, "be_", 3) == 0) {
                num = 0;
@@ -1193,11 +1194,11 @@ static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
                num = 3;
                pos += 3;
        } else {
-               wpa_printf(MSG_ERROR, "Unknown wme name '%s'", pos);
+               wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
                return -1;
        }
 
-       ac = &conf->wme_ac_params[num];
+       ac = &conf->wmm_ac_params[num];
 
        if (os_strcmp(pos, "aifs") == 0) {
                v = atoi(val);
@@ -1226,7 +1227,7 @@ static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
                        wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
                        return -1;
                }
-               ac->txopLimit = v;
+               ac->txop_limit = v;
        } else if (os_strcmp(pos, "acm") == 0) {
                v = atoi(val);
                if (v < 0 || v > 1) {
@@ -1235,7 +1236,7 @@ static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
                }
                ac->admission_control_mandatory = v;
        } else {
-               wpa_printf(MSG_ERROR, "Unknown wme_ac_ field '%s'", pos);
+               wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
                return -1;
        }
 
@@ -1457,13 +1458,13 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "bridge") == 0) {
                        os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
                } else if (os_strcmp(buf, "driver") == 0) {
-                       int i;
+                       int j;
                        /* clear to get error below if setting is invalid */
                        conf->driver = NULL;
-                       for (i = 0; hostapd_drivers[i]; i++) {
-                               if (os_strcmp(pos, hostapd_drivers[i]->name) ==
-                                   0) {
-                                       conf->driver = hostapd_drivers[i];
+                       for (j = 0; wpa_drivers[j]; j++) {
+                               if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
+                               {
+                                       conf->driver = wpa_drivers[j];
                                        break;
                                }
                        }
@@ -1574,7 +1575,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "dh_file") == 0) {
                        os_free(bss->dh_file);
                        bss->dh_file = os_strdup(pos);
-#ifdef EAP_FAST
+#ifdef EAP_SERVER_FAST
                } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
                        os_free(bss->pac_opaque_encr_key);
                        bss->pac_opaque_encr_key = os_malloc(16);
@@ -1616,18 +1617,18 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        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
+#endif /* EAP_SERVER_FAST */
+#ifdef EAP_SERVER_SIM
                } else if (os_strcmp(buf, "eap_sim_db") == 0) {
                        os_free(bss->eap_sim_db);
                        bss->eap_sim_db = os_strdup(pos);
                } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
                        bss->eap_sim_aka_result_ind = atoi(pos);
-#endif /* EAP_SIM */
-#ifdef EAP_TNC
+#endif /* EAP_SERVER_SIM */
+#ifdef EAP_SERVER_TNC
                } else if (os_strcmp(buf, "tnc") == 0) {
                        bss->tnc = atoi(pos);
-#endif /* EAP_TNC */
+#endif /* EAP_SERVER_TNC */
 #endif /* EAP_SERVER */
                } else if (os_strcmp(buf, "eap_message") == 0) {
                        char *term;
@@ -2081,11 +2082,13 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "queue item", line);
                                errors++;
                        }
-               } else if (os_strcmp(buf, "wme_enabled") == 0) {
-                       bss->wme_enabled = atoi(pos);
-               } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
-                       if (hostapd_config_wme_ac(conf, buf, pos)) {
-                               wpa_printf(MSG_ERROR, "Line %d: invalid wme "
+               } else if (os_strcmp(buf, "wme_enabled") == 0 ||
+                          os_strcmp(buf, "wmm_enabled") == 0) {
+                       bss->wmm_enabled = 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)) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
                                           "ac item", line);
                                errors++;
                        }
@@ -2239,6 +2242,23 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           line, pos);
                                errors++;
                        }
+               } else if (os_strcmp(buf, "upnp_iface") == 0) {
+                       bss->upnp_iface = os_strdup(pos);
+               } else if (os_strcmp(buf, "friendly_name") == 0) {
+                       os_free(bss->friendly_name);
+                       bss->friendly_name = os_strdup(pos);
+               } else if (os_strcmp(buf, "manufacturer_url") == 0) {
+                       os_free(bss->manufacturer_url);
+                       bss->manufacturer_url = os_strdup(pos);
+               } else if (os_strcmp(buf, "model_description") == 0) {
+                       os_free(bss->model_description);
+                       bss->model_description = os_strdup(pos);
+               } else if (os_strcmp(buf, "model_url") == 0) {
+                       os_free(bss->model_url);
+                       bss->model_url = os_strdup(pos);
+               } else if (os_strcmp(buf, "upc") == 0) {
+                       os_free(bss->upc);
+                       bss->upc = os_strdup(pos);
 #endif /* CONFIG_WPS */
                } else {
                        wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
@@ -2249,29 +2269,30 @@ struct hostapd_config * hostapd_config_read(const char *fname)
 
        fclose(f);
 
-       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
-               bss->wpa_group = WPA_CIPHER_CCMP;
-
        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;
+               }
+
+               /* 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
+                       bss->wpa_group = WPA_CIPHER_CCMP;
+
                bss->radius->auth_server = bss->radius->auth_servers;
                bss->radius->acct_server = bss->radius->acct_servers;
 
@@ -2446,6 +2467,12 @@ static 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);
+       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);
 #endif /* CONFIG_WPS */
 }