Fix UNIX domain socket address handling to be more portable
[wpasupplicant] / hostapd / config.c
index e578c7f..8575255 100644 (file)
@@ -34,6 +34,7 @@
 extern struct wpa_driver_ops *hostapd_drivers[];
 
 
+#ifndef CONFIG_NO_VLAN
 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
                                         const char *fname)
 {
@@ -113,6 +114,7 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
 
        return 0;
 }
+#endif /* CONFIG_NO_VLAN */
 
 
 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
@@ -202,13 +204,13 @@ static struct hostapd_config * hostapd_config_defaults(void)
        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));
@@ -248,15 +250,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;
@@ -474,11 +474,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) {
@@ -973,6 +968,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;
@@ -1169,14 +1170,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;
@@ -1191,11 +1192,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);
@@ -1224,7 +1225,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) {
@@ -1233,7 +1234,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;
        }
 
@@ -1518,8 +1519,9 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "deny_mac_file") == 0) {
                        if (hostapd_config_read_maclist(pos, &bss->deny_mac,
                                                        &bss->num_deny_mac)) {
-                               wpa_printf(MSG_ERROR "Line %d: Failed to read "
-                                          "deny_mac_file '%s'", line, pos);
+                               wpa_printf(MSG_ERROR, "Line %d: Failed to "
+                                          "read deny_mac_file '%s'",
+                                          line, pos);
                                errors++;
                        }
                } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
@@ -1900,6 +1902,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
                        bss->pmk_r1_push = atoi(pos);
 #endif /* CONFIG_IEEE80211R */
+#ifndef CONFIG_NO_CTRL_IFACE
                } else if (os_strcmp(buf, "ctrl_interface") == 0) {
                        os_free(bss->ctrl_interface);
                        bss->ctrl_interface = os_strdup(pos);
@@ -1931,6 +1934,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                        wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
                                   bss->ctrl_interface_gid);
 #endif /* CONFIG_NATIVE_WINDOWS */
+#endif /* CONFIG_NO_CTRL_IFACE */
 #ifdef RADIUS_SERVER
                } else if (os_strcmp(buf, "radius_server_clients") == 0) {
                        os_free(bss->radius_server_clients);
@@ -2046,6 +2050,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "key '%s'", line, buf);
                                errors++;
                        }
+#ifndef CONFIG_NO_VLAN
                } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
                        bss->ssid.dynamic_vlan = atoi(pos);
                } else if (os_strcmp(buf, "vlan_file") == 0) {
@@ -2058,6 +2063,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
                        bss->ssid.vlan_tagged_interface = os_strdup(pos);
 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
+#endif /* CONFIG_NO_VLAN */
                } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
                        conf->passive_scan_interval = atoi(pos);
                } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
@@ -2074,11 +2080,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++;
                        }
@@ -2151,6 +2159,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                errors++;
                        }
                } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
+                       os_free(bss->wps_pin_requests);
                        bss->wps_pin_requests = os_strdup(pos);
                } else if (os_strcmp(buf, "device_name") == 0) {
                        if (os_strlen(pos) > 32) {
@@ -2158,6 +2167,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "device_name", line);
                                errors++;
                        }
+                       os_free(bss->device_name);
                        bss->device_name = os_strdup(pos);
                } else if (os_strcmp(buf, "manufacturer") == 0) {
                        if (os_strlen(pos) > 64) {
@@ -2165,6 +2175,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "manufacturer", line);
                                errors++;
                        }
+                       os_free(bss->manufacturer);
                        bss->manufacturer = os_strdup(pos);
                } else if (os_strcmp(buf, "model_name") == 0) {
                        if (os_strlen(pos) > 32) {
@@ -2172,6 +2183,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "model_name", line);
                                errors++;
                        }
+                       os_free(bss->model_name);
                        bss->model_name = os_strdup(pos);
                } else if (os_strcmp(buf, "model_number") == 0) {
                        if (os_strlen(pos) > 32) {
@@ -2179,6 +2191,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "model_number", line);
                                errors++;
                        }
+                       os_free(bss->model_number);
                        bss->model_number = os_strdup(pos);
                } else if (os_strcmp(buf, "serial_number") == 0) {
                        if (os_strlen(pos) > 32) {
@@ -2186,10 +2199,13 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                           "serial_number", line);
                                errors++;
                        }
+                       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);
                } else if (os_strcmp(buf, "config_methods") == 0) {
+                       os_free(bss->config_methods);
                        bss->config_methods = os_strdup(pos);
                } else if (os_strcmp(buf, "os_version") == 0) {
                        if (hexstr2bin(pos, bss->os_version, 4)) {
@@ -2198,7 +2214,49 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                                errors++;
                        }
                } else if (os_strcmp(buf, "ap_pin") == 0) {
+                       os_free(bss->ap_pin);
                        bss->ap_pin = os_strdup(pos);
+               } else if (os_strcmp(buf, "skip_cred_build") == 0) {
+                       bss->skip_cred_build = atoi(pos);
+               } else if (os_strcmp(buf, "extra_cred") == 0) {
+                       os_free(bss->extra_cred);
+                       bss->extra_cred =
+                               (u8 *) os_readfile(pos, &bss->extra_cred_len);
+                       if (bss->extra_cred == NULL) {
+                               wpa_printf(MSG_ERROR, "Line %d: could not "
+                                          "read Credentials from '%s'",
+                                          line, pos);
+                               errors++;
+                       }
+               } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
+                       bss->wps_cred_processing = atoi(pos);
+               } else if (os_strcmp(buf, "ap_settings") == 0) {
+                       os_free(bss->ap_settings);
+                       bss->ap_settings =
+                               (u8 *) os_readfile(pos, &bss->ap_settings_len);
+                       if (bss->ap_settings == NULL) {
+                               wpa_printf(MSG_ERROR, "Line %d: could not "
+                                          "read AP Settings from '%s'",
+                                          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 "
@@ -2404,6 +2462,14 @@ static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->device_type);
        os_free(conf->config_methods);
        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 */
 }