2 * hostapd / Configuration file
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #ifndef CONFIG_NATIVE_WINDOWS
18 #endif /* CONFIG_NATIVE_WINDOWS */
21 #include "crypto/sha1.h"
22 #include "drivers/driver.h"
23 #include "radius/radius_client.h"
24 #include "common/ieee802_11_defs.h"
25 #include "common/wpa_common.h"
26 #include "eap_common/eap_wsc_common.h"
27 #include "eap_server/eap.h"
35 #define MAX_STA_COUNT 2007
37 extern struct wpa_driver_ops *wpa_drivers[];
40 #ifndef CONFIG_NO_VLAN
41 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
45 char buf[128], *pos, *pos2;
46 int line = 0, vlan_id;
47 struct hostapd_vlan *vlan;
49 f = fopen(fname, "r");
51 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
55 while (fgets(buf, sizeof(buf), f)) {
61 while (*pos != '\0') {
72 vlan_id = VLAN_ID_WILDCARD;
75 vlan_id = strtol(buf, &pos, 10);
76 if (buf == pos || vlan_id < 1 ||
77 vlan_id > MAX_VLAN_ID) {
78 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
79 "line %d in '%s'", line, fname);
85 while (*pos == ' ' || *pos == '\t')
88 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
91 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
92 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
93 "in '%s'", line, fname);
98 vlan = os_malloc(sizeof(*vlan));
100 wpa_printf(MSG_ERROR, "Out of memory while reading "
101 "VLAN interfaces from '%s'", fname);
106 os_memset(vlan, 0, sizeof(*vlan));
107 vlan->vlan_id = vlan_id;
108 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
110 bss->vlan_tail->next = vlan;
113 bss->vlan_tail = vlan;
120 #endif /* CONFIG_NO_VLAN */
123 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
125 struct hostapd_vlan *vlan, *prev;
139 /* convert floats with one decimal place to value*10 int, i.e.,
140 * "1.5" will return 15 */
141 static int hostapd_config_read_int10(const char *value)
147 pos = os_strchr(value, '.');
151 if (*pos >= '0' && *pos <= '9')
159 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
161 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
162 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
163 bss->logger_syslog = (unsigned int) -1;
164 bss->logger_stdout = (unsigned int) -1;
166 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
168 bss->wep_rekeying_period = 300;
169 /* use key0 in individual key and key1 in broadcast key */
170 bss->broadcast_key_idx_min = 1;
171 bss->broadcast_key_idx_max = 2;
172 bss->eap_reauth_period = 3600;
174 bss->wpa_group_rekey = 600;
175 bss->wpa_gmk_rekey = 86400;
176 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
177 bss->wpa_pairwise = WPA_CIPHER_TKIP;
178 bss->wpa_group = WPA_CIPHER_TKIP;
179 bss->rsn_pairwise = 0;
181 bss->max_num_sta = MAX_STA_COUNT;
183 bss->dtim_period = 2;
185 bss->radius_server_auth_port = 1812;
186 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
187 bss->eapol_version = EAPOL_VERSION;
189 bss->max_listen_interval = 65535;
191 #ifdef CONFIG_IEEE80211W
192 bss->assoc_sa_query_max_timeout = 1000;
193 bss->assoc_sa_query_retry_timeout = 201;
194 #endif /* CONFIG_IEEE80211W */
195 #ifdef EAP_SERVER_FAST
196 /* both anonymous and authenticated provisioning */
197 bss->eap_fast_prov = 3;
198 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
199 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
200 #endif /* EAP_SERVER_FAST */
204 struct hostapd_config * hostapd_config_defaults(void)
206 struct hostapd_config *conf;
207 struct hostapd_bss_config *bss;
209 const int aCWmin = 15, aCWmax = 1024;
210 const struct hostapd_wmm_ac_params ac_bk =
211 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
212 const struct hostapd_wmm_ac_params ac_be =
213 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
214 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
215 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
216 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
217 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
219 conf = os_zalloc(sizeof(*conf));
220 bss = os_zalloc(sizeof(*bss));
221 if (conf == NULL || bss == NULL) {
222 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
223 "configuration data.");
229 /* set default driver based on configuration */
230 conf->driver = wpa_drivers[0];
231 if (conf->driver == NULL) {
232 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
238 bss->radius = os_zalloc(sizeof(*bss->radius));
239 if (bss->radius == NULL) {
245 hostapd_config_defaults_bss(bss);
250 conf->beacon_int = 100;
251 conf->rts_threshold = -1; /* use driver default: 2347 */
252 conf->fragm_threshold = -1; /* user driver default: 2346 */
253 conf->send_probe_response = 1;
255 for (i = 0; i < NUM_TX_QUEUES; i++)
256 conf->tx_queue[i].aifs = -1; /* use hw default */
258 conf->wmm_ac_params[0] = ac_be;
259 conf->wmm_ac_params[1] = ac_bk;
260 conf->wmm_ac_params[2] = ac_vi;
261 conf->wmm_ac_params[3] = ac_vo;
263 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
269 int hostapd_mac_comp(const void *a, const void *b)
271 return os_memcmp(a, b, sizeof(macaddr));
275 int hostapd_mac_comp_empty(const void *a)
277 macaddr empty = { 0 };
278 return os_memcmp(a, empty, sizeof(macaddr));
282 static int hostapd_acl_comp(const void *a, const void *b)
284 const struct mac_acl_entry *aa = a;
285 const struct mac_acl_entry *bb = b;
286 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
290 static int hostapd_config_read_maclist(const char *fname,
291 struct mac_acl_entry **acl, int *num)
297 struct mac_acl_entry *newacl;
303 f = fopen(fname, "r");
305 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
309 while (fgets(buf, sizeof(buf), f)) {
315 while (*pos != '\0') {
325 if (hwaddr_aton(buf, addr)) {
326 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
327 "line %d in '%s'", buf, line, fname);
334 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
336 while (*pos == ' ' || *pos == '\t')
341 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
342 if (newacl == NULL) {
343 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
349 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
350 (*acl)[*num].vlan_id = vlan_id;
356 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
362 static int hostapd_config_read_wpa_psk(const char *fname,
363 struct hostapd_ssid *ssid)
367 int line = 0, ret = 0, len, ok;
369 struct hostapd_wpa_psk *psk;
374 f = fopen(fname, "r");
376 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
380 while (fgets(buf, sizeof(buf), f)) {
386 while (*pos != '\0') {
396 if (hwaddr_aton(buf, addr)) {
397 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
398 "line %d in '%s'", buf, line, fname);
403 psk = os_zalloc(sizeof(*psk));
405 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
409 if (is_zero_ether_addr(addr))
412 os_memcpy(psk->addr, addr, ETH_ALEN);
416 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
425 len = os_strlen(pos);
426 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
428 else if (len >= 8 && len < 64) {
429 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
430 4096, psk->psk, PMK_LEN);
434 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
435 "'%s'", pos, line, fname);
441 psk->next = ssid->wpa_psk;
451 static int hostapd_derive_psk(struct hostapd_ssid *ssid)
453 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
454 if (ssid->wpa_psk == NULL) {
455 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
458 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
459 (u8 *) ssid->ssid, ssid->ssid_len);
460 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
461 (u8 *) ssid->wpa_passphrase,
462 os_strlen(ssid->wpa_passphrase));
463 pbkdf2_sha1(ssid->wpa_passphrase,
464 ssid->ssid, ssid->ssid_len,
465 4096, ssid->wpa_psk->psk, PMK_LEN);
466 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
467 ssid->wpa_psk->psk, PMK_LEN);
472 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
474 struct hostapd_ssid *ssid = &conf->ssid;
476 if (ssid->wpa_passphrase != NULL) {
477 if (ssid->wpa_psk != NULL) {
478 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
479 "instead of passphrase");
481 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
483 if (hostapd_derive_psk(ssid) < 0)
486 ssid->wpa_psk->group = 1;
489 if (ssid->wpa_psk_file) {
490 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
500 static int hostapd_config_read_eap_user(const char *fname,
501 struct hostapd_bss_config *conf)
504 char buf[512], *pos, *start, *pos2;
505 int line = 0, ret = 0, num_methods;
506 struct hostapd_eap_user *user, *tail = NULL;
511 f = fopen(fname, "r");
513 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
517 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
518 while (fgets(buf, sizeof(buf), f)) {
524 while (*pos != '\0') {
536 if (buf[0] != '"' && buf[0] != '*') {
537 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
538 "start) on line %d in '%s'", line, fname);
542 user = os_zalloc(sizeof(*user));
544 wpa_printf(MSG_ERROR, "EAP user allocation failed");
547 user->force_version = -1;
554 while (*pos != '"' && *pos != '\0')
557 wpa_printf(MSG_ERROR, "Invalid EAP identity "
558 "(no \" in end) on line %d in '%s'",
563 user->identity = os_malloc(pos - start);
564 if (user->identity == NULL) {
565 wpa_printf(MSG_ERROR, "Failed to allocate "
566 "memory for EAP identity");
569 os_memcpy(user->identity, start, pos - start);
570 user->identity_len = pos - start;
572 if (pos[0] == '"' && pos[1] == '*') {
573 user->wildcard_prefix = 1;
578 while (*pos == ' ' || *pos == '\t')
582 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
583 "'%s'", line, fname);
588 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
598 char *pos3 = os_strchr(start, ',');
602 user->methods[num_methods].method =
605 &user->methods[num_methods].vendor);
606 if (user->methods[num_methods].vendor ==
608 user->methods[num_methods].method == EAP_TYPE_NONE)
610 if (os_strcmp(start, "TTLS-PAP") == 0) {
611 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
614 if (os_strcmp(start, "TTLS-CHAP") == 0) {
615 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
618 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
620 EAP_TTLS_AUTH_MSCHAP;
623 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
625 EAP_TTLS_AUTH_MSCHAPV2;
628 wpa_printf(MSG_ERROR, "Unsupported EAP type "
629 "'%s' on line %d in '%s'",
635 if (num_methods >= EAP_USER_MAX_METHODS)
642 if (num_methods == 0 && user->ttls_auth == 0) {
643 wpa_printf(MSG_ERROR, "No EAP types configured on "
644 "line %d in '%s'", line, fname);
651 while (*pos == ' ' || *pos == '\t')
656 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
657 user->force_version = 0;
661 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
662 user->force_version = 1;
666 if (os_strncmp(pos, "[2]", 3) == 0) {
674 while (*pos != '"' && *pos != '\0')
677 wpa_printf(MSG_ERROR, "Invalid EAP password "
678 "(no \" in end) on line %d in '%s'",
683 user->password = os_malloc(pos - start);
684 if (user->password == NULL) {
685 wpa_printf(MSG_ERROR, "Failed to allocate "
686 "memory for EAP password");
689 os_memcpy(user->password, start, pos - start);
690 user->password_len = pos - start;
693 } else if (os_strncmp(pos, "hash:", 5) == 0) {
696 while (*pos2 != '\0' && *pos2 != ' ' &&
697 *pos2 != '\t' && *pos2 != '#')
699 if (pos2 - pos != 32) {
700 wpa_printf(MSG_ERROR, "Invalid password hash "
701 "on line %d in '%s'", line, fname);
704 user->password = os_malloc(16);
705 if (user->password == NULL) {
706 wpa_printf(MSG_ERROR, "Failed to allocate "
707 "memory for EAP password hash");
710 if (hexstr2bin(pos, user->password, 16) < 0) {
711 wpa_printf(MSG_ERROR, "Invalid hash password "
712 "on line %d in '%s'", line, fname);
715 user->password_len = 16;
716 user->password_hash = 1;
720 while (*pos2 != '\0' && *pos2 != ' ' &&
721 *pos2 != '\t' && *pos2 != '#')
723 if ((pos2 - pos) & 1) {
724 wpa_printf(MSG_ERROR, "Invalid hex password "
725 "on line %d in '%s'", line, fname);
728 user->password = os_malloc((pos2 - pos) / 2);
729 if (user->password == NULL) {
730 wpa_printf(MSG_ERROR, "Failed to allocate "
731 "memory for EAP password");
734 if (hexstr2bin(pos, user->password,
735 (pos2 - pos) / 2) < 0) {
736 wpa_printf(MSG_ERROR, "Invalid hex password "
737 "on line %d in '%s'", line, fname);
740 user->password_len = (pos2 - pos) / 2;
744 while (*pos == ' ' || *pos == '\t')
746 if (os_strncmp(pos, "[2]", 3) == 0) {
752 tail = conf->eap_user = user;
761 os_free(user->password);
762 os_free(user->identity);
773 #endif /* EAP_SERVER */
776 #ifndef CONFIG_NO_RADIUS
778 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
779 int *num_server, const char *val, int def_port,
780 struct hostapd_radius_server **curr_serv)
782 struct hostapd_radius_server *nserv;
784 static int server_index = 1;
786 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
791 nserv = &nserv[*num_server];
793 (*curr_serv) = nserv;
795 os_memset(nserv, 0, sizeof(*nserv));
796 nserv->port = def_port;
797 ret = hostapd_parse_ip_addr(val, &nserv->addr);
798 nserv->index = server_index++;
802 #endif /* CONFIG_NO_RADIUS */
805 static int hostapd_config_parse_key_mgmt(int line, const char *value)
808 char *start, *end, *buf;
810 buf = os_strdup(value);
815 while (*start != '\0') {
816 while (*start == ' ' || *start == '\t')
821 while (*end != ' ' && *end != '\t' && *end != '\0')
825 if (os_strcmp(start, "WPA-PSK") == 0)
826 val |= WPA_KEY_MGMT_PSK;
827 else if (os_strcmp(start, "WPA-EAP") == 0)
828 val |= WPA_KEY_MGMT_IEEE8021X;
829 #ifdef CONFIG_IEEE80211R
830 else if (os_strcmp(start, "FT-PSK") == 0)
831 val |= WPA_KEY_MGMT_FT_PSK;
832 else if (os_strcmp(start, "FT-EAP") == 0)
833 val |= WPA_KEY_MGMT_FT_IEEE8021X;
834 #endif /* CONFIG_IEEE80211R */
835 #ifdef CONFIG_IEEE80211W
836 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
837 val |= WPA_KEY_MGMT_PSK_SHA256;
838 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
839 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
840 #endif /* CONFIG_IEEE80211W */
842 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
855 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
856 "configured.", line);
864 static int hostapd_config_parse_cipher(int line, const char *value)
867 char *start, *end, *buf;
869 buf = os_strdup(value);
874 while (*start != '\0') {
875 while (*start == ' ' || *start == '\t')
880 while (*end != ' ' && *end != '\t' && *end != '\0')
884 if (os_strcmp(start, "CCMP") == 0)
885 val |= WPA_CIPHER_CCMP;
886 else if (os_strcmp(start, "TKIP") == 0)
887 val |= WPA_CIPHER_TKIP;
888 else if (os_strcmp(start, "WEP104") == 0)
889 val |= WPA_CIPHER_WEP104;
890 else if (os_strcmp(start, "WEP40") == 0)
891 val |= WPA_CIPHER_WEP40;
892 else if (os_strcmp(start, "NONE") == 0)
893 val |= WPA_CIPHER_NONE;
895 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
908 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
916 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
917 struct hostapd_config *conf)
919 if (bss->ieee802_1x && !bss->eap_server &&
920 !bss->radius->auth_servers) {
921 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
922 "EAP authenticator configured).");
926 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
927 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
928 bss->ssid.wpa_psk_file == NULL) {
929 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
930 "is not configured.");
934 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
937 for (i = 0; i < conf->num_bss; i++) {
938 if ((&conf->bss[i] != bss) &&
939 (hostapd_mac_comp(conf->bss[i].bssid,
941 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
942 " on interface '%s' and '%s'.",
944 conf->bss[i].iface, bss->iface);
950 #ifdef CONFIG_IEEE80211R
951 if ((bss->wpa_key_mgmt &
952 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
953 (bss->nas_identifier == NULL ||
954 os_strlen(bss->nas_identifier) < 1 ||
955 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
956 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
957 "nas_identifier to be configured as a 1..48 octet "
961 #endif /* CONFIG_IEEE80211R */
963 #ifdef CONFIG_IEEE80211N
964 if (conf->ieee80211n && bss->wpa &&
965 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
966 !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
967 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
968 "requires CCMP to be enabled");
971 #endif /* CONFIG_IEEE80211N */
977 static int hostapd_config_check(struct hostapd_config *conf)
981 if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
982 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
983 "setting the country_code");
987 for (i = 0; i < conf->num_bss; i++) {
988 if (hostapd_config_check_bss(&conf->bss[i], conf))
996 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
999 size_t len = os_strlen(val);
1001 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
1004 if (val[0] == '"') {
1005 if (len < 2 || val[len - 1] != '"')
1008 wep->key[keyidx] = os_malloc(len);
1009 if (wep->key[keyidx] == NULL)
1011 os_memcpy(wep->key[keyidx], val + 1, len);
1012 wep->len[keyidx] = len;
1017 wep->key[keyidx] = os_malloc(len);
1018 if (wep->key[keyidx] == NULL)
1020 wep->len[keyidx] = len;
1021 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1031 static int hostapd_parse_rates(int **rate_list, char *val)
1037 os_free(*rate_list);
1042 while (*pos != '\0') {
1048 list = os_malloc(sizeof(int) * (count + 2));
1053 while (*pos != '\0') {
1054 end = os_strchr(pos, ' ');
1058 list[count++] = atoi(pos);
1070 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1072 struct hostapd_bss_config *bss;
1074 if (*ifname == '\0')
1077 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1078 sizeof(struct hostapd_bss_config));
1080 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1086 bss = &(conf->bss[conf->num_bss]);
1087 os_memset(bss, 0, sizeof(*bss));
1088 bss->radius = os_zalloc(sizeof(*bss->radius));
1089 if (bss->radius == NULL) {
1090 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1091 "multi-BSS RADIUS data");
1096 conf->last_bss = bss;
1098 hostapd_config_defaults_bss(bss);
1099 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1100 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1106 static int valid_cw(int cw)
1108 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1109 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1114 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1115 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1116 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1117 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1118 IEEE80211_TX_QUEUE_DATA4 = 4,
1119 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1120 IEEE80211_TX_QUEUE_BEACON = 7
1123 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1128 struct hostapd_tx_queue_params *queue;
1130 /* skip 'tx_queue_' prefix */
1132 if (os_strncmp(pos, "data", 4) == 0 &&
1133 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1136 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1137 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1139 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1140 num = IEEE80211_TX_QUEUE_BEACON;
1143 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1147 queue = &conf->tx_queue[num];
1149 if (os_strcmp(pos, "aifs") == 0) {
1150 queue->aifs = atoi(val);
1151 if (queue->aifs < 0 || queue->aifs > 255) {
1152 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1156 } else if (os_strcmp(pos, "cwmin") == 0) {
1157 queue->cwmin = atoi(val);
1158 if (!valid_cw(queue->cwmin)) {
1159 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1163 } else if (os_strcmp(pos, "cwmax") == 0) {
1164 queue->cwmax = atoi(val);
1165 if (!valid_cw(queue->cwmax)) {
1166 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1170 } else if (os_strcmp(pos, "burst") == 0) {
1171 queue->burst = hostapd_config_read_int10(val);
1173 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1177 queue->configured = 1;
1183 static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
1188 struct hostapd_wmm_ac_params *ac;
1190 /* skip 'wme_ac_' or 'wmm_ac_' prefix */
1192 if (os_strncmp(pos, "be_", 3) == 0) {
1195 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1198 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1201 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1205 wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
1209 ac = &conf->wmm_ac_params[num];
1211 if (os_strcmp(pos, "aifs") == 0) {
1213 if (v < 1 || v > 255) {
1214 wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
1218 } else if (os_strcmp(pos, "cwmin") == 0) {
1220 if (v < 0 || v > 12) {
1221 wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
1225 } else if (os_strcmp(pos, "cwmax") == 0) {
1227 if (v < 0 || v > 12) {
1228 wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
1232 } else if (os_strcmp(pos, "txop_limit") == 0) {
1234 if (v < 0 || v > 0xffff) {
1235 wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
1239 } else if (os_strcmp(pos, "acm") == 0) {
1241 if (v < 0 || v > 1) {
1242 wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
1245 ac->admission_control_mandatory = v;
1247 wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
1255 #ifdef CONFIG_IEEE80211R
1256 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1258 struct ft_remote_r0kh *r0kh;
1261 r0kh = os_zalloc(sizeof(*r0kh));
1265 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1267 next = os_strchr(pos, ' ');
1270 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1271 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1277 next = os_strchr(pos, ' ');
1280 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1281 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1285 r0kh->id_len = next - pos - 1;
1286 os_memcpy(r0kh->id, pos, r0kh->id_len);
1289 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1290 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1295 r0kh->next = bss->r0kh_list;
1296 bss->r0kh_list = r0kh;
1302 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1304 struct ft_remote_r1kh *r1kh;
1307 r1kh = os_zalloc(sizeof(*r1kh));
1311 /* 02:01:02:03:04:05 02:01:02:03:04:05
1312 * 000102030405060708090a0b0c0d0e0f */
1314 next = os_strchr(pos, ' ');
1317 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1318 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1324 next = os_strchr(pos, ' ');
1327 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1328 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1334 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1335 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1340 r1kh->next = bss->r1kh_list;
1341 bss->r1kh_list = r1kh;
1345 #endif /* CONFIG_IEEE80211R */
1348 #ifdef CONFIG_IEEE80211N
1349 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1352 if (os_strstr(capab, "[LDPC]"))
1353 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1354 if (os_strstr(capab, "[HT40-]")) {
1355 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1356 conf->secondary_channel = -1;
1358 if (os_strstr(capab, "[HT40+]")) {
1359 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1360 conf->secondary_channel = 1;
1362 if (os_strstr(capab, "[SMPS-STATIC]")) {
1363 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1364 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1366 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1367 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1368 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1370 if (os_strstr(capab, "[GF]"))
1371 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1372 if (os_strstr(capab, "[SHORT-GI-20]"))
1373 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1374 if (os_strstr(capab, "[SHORT-GI-40]"))
1375 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1376 if (os_strstr(capab, "[TX-STBC]"))
1377 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1378 if (os_strstr(capab, "[RX-STBC1]")) {
1379 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1380 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1382 if (os_strstr(capab, "[RX-STBC12]")) {
1383 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1384 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1386 if (os_strstr(capab, "[RX-STBC123]")) {
1387 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1388 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1390 if (os_strstr(capab, "[DELAYED-BA]"))
1391 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1392 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1393 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1394 if (os_strstr(capab, "[DSSS_CCK-40]"))
1395 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1396 if (os_strstr(capab, "[PSMP]"))
1397 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1398 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1399 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1403 #endif /* CONFIG_IEEE80211N */
1407 * hostapd_config_read - Read and parse a configuration file
1408 * @fname: Configuration file name (including path, if needed)
1409 * Returns: Allocated configuration data structure
1411 struct hostapd_config * hostapd_config_read(const char *fname)
1413 struct hostapd_config *conf;
1414 struct hostapd_bss_config *bss;
1416 char buf[256], *pos;
1422 f = fopen(fname, "r");
1424 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
1425 "for reading.", fname);
1429 conf = hostapd_config_defaults();
1434 bss = conf->last_bss = conf->bss;
1436 while (fgets(buf, sizeof(buf), f)) {
1437 bss = conf->last_bss;
1443 while (*pos != '\0') {
1453 pos = os_strchr(buf, '=');
1455 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
1463 if (os_strcmp(buf, "interface") == 0) {
1464 os_strlcpy(conf->bss[0].iface, pos,
1465 sizeof(conf->bss[0].iface));
1466 } else if (os_strcmp(buf, "bridge") == 0) {
1467 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1468 } else if (os_strcmp(buf, "driver") == 0) {
1470 /* clear to get error below if setting is invalid */
1471 conf->driver = NULL;
1472 for (j = 0; wpa_drivers[j]; j++) {
1473 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
1475 conf->driver = wpa_drivers[j];
1479 if (conf->driver == NULL) {
1480 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1481 "unknown driver '%s'", line, pos);
1484 } else if (os_strcmp(buf, "debug") == 0) {
1485 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1486 "configuration variable is not used "
1488 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1489 bss->logger_syslog_level = atoi(pos);
1490 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1491 bss->logger_stdout_level = atoi(pos);
1492 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1493 bss->logger_syslog = atoi(pos);
1494 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1495 bss->logger_stdout = atoi(pos);
1496 } else if (os_strcmp(buf, "dump_file") == 0) {
1497 bss->dump_log_name = os_strdup(pos);
1498 } else if (os_strcmp(buf, "ssid") == 0) {
1499 bss->ssid.ssid_len = os_strlen(pos);
1500 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1501 bss->ssid.ssid_len < 1) {
1502 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1506 os_memcpy(bss->ssid.ssid, pos,
1507 bss->ssid.ssid_len);
1508 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1509 bss->ssid.ssid_set = 1;
1511 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1512 bss->macaddr_acl = atoi(pos);
1513 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1514 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1515 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1516 wpa_printf(MSG_ERROR, "Line %d: unknown "
1518 line, bss->macaddr_acl);
1520 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1521 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1522 &bss->num_accept_mac))
1524 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1525 "read accept_mac_file '%s'",
1529 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1530 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1531 &bss->num_deny_mac)) {
1532 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1533 "read deny_mac_file '%s'",
1537 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1538 bss->ap_max_inactivity = atoi(pos);
1539 } else if (os_strcmp(buf, "country_code") == 0) {
1540 os_memcpy(conf->country, pos, 2);
1541 /* FIX: make this configurable */
1542 conf->country[2] = ' ';
1543 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1544 conf->ieee80211d = atoi(pos);
1545 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1546 bss->ieee802_1x = atoi(pos);
1547 } else if (os_strcmp(buf, "eapol_version") == 0) {
1548 bss->eapol_version = atoi(pos);
1549 if (bss->eapol_version < 1 ||
1550 bss->eapol_version > 2) {
1551 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1552 "version (%d): '%s'.",
1553 line, bss->eapol_version, pos);
1556 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1557 bss->eapol_version);
1559 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1560 bss->eap_server = atoi(pos);
1561 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1562 "eap_authenticator used; this has been "
1563 "renamed to eap_server", line);
1564 } else if (os_strcmp(buf, "eap_server") == 0) {
1565 bss->eap_server = atoi(pos);
1566 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1567 if (hostapd_config_read_eap_user(pos, bss))
1569 } else if (os_strcmp(buf, "ca_cert") == 0) {
1570 os_free(bss->ca_cert);
1571 bss->ca_cert = os_strdup(pos);
1572 } else if (os_strcmp(buf, "server_cert") == 0) {
1573 os_free(bss->server_cert);
1574 bss->server_cert = os_strdup(pos);
1575 } else if (os_strcmp(buf, "private_key") == 0) {
1576 os_free(bss->private_key);
1577 bss->private_key = os_strdup(pos);
1578 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1579 os_free(bss->private_key_passwd);
1580 bss->private_key_passwd = os_strdup(pos);
1581 } else if (os_strcmp(buf, "check_crl") == 0) {
1582 bss->check_crl = atoi(pos);
1583 } else if (os_strcmp(buf, "dh_file") == 0) {
1584 os_free(bss->dh_file);
1585 bss->dh_file = os_strdup(pos);
1586 #ifdef EAP_SERVER_FAST
1587 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1588 os_free(bss->pac_opaque_encr_key);
1589 bss->pac_opaque_encr_key = os_malloc(16);
1590 if (bss->pac_opaque_encr_key == NULL) {
1591 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1592 "pac_opaque_encr_key", line);
1594 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1596 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1597 "pac_opaque_encr_key", line);
1600 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1601 size_t idlen = os_strlen(pos);
1603 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1604 "eap_fast_a_id", line);
1607 os_free(bss->eap_fast_a_id);
1608 bss->eap_fast_a_id = os_malloc(idlen / 2);
1609 if (bss->eap_fast_a_id == NULL ||
1610 hexstr2bin(pos, bss->eap_fast_a_id,
1612 wpa_printf(MSG_ERROR, "Line %d: "
1614 "eap_fast_a_id", line);
1617 bss->eap_fast_a_id_len = idlen / 2;
1619 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1620 os_free(bss->eap_fast_a_id_info);
1621 bss->eap_fast_a_id_info = os_strdup(pos);
1622 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1623 bss->eap_fast_prov = atoi(pos);
1624 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1625 bss->pac_key_lifetime = atoi(pos);
1626 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1627 bss->pac_key_refresh_time = atoi(pos);
1628 #endif /* EAP_SERVER_FAST */
1629 #ifdef EAP_SERVER_SIM
1630 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1631 os_free(bss->eap_sim_db);
1632 bss->eap_sim_db = os_strdup(pos);
1633 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1634 bss->eap_sim_aka_result_ind = atoi(pos);
1635 #endif /* EAP_SERVER_SIM */
1636 #ifdef EAP_SERVER_TNC
1637 } else if (os_strcmp(buf, "tnc") == 0) {
1638 bss->tnc = atoi(pos);
1639 #endif /* EAP_SERVER_TNC */
1640 #endif /* EAP_SERVER */
1641 } else if (os_strcmp(buf, "eap_message") == 0) {
1643 bss->eap_req_id_text = os_strdup(pos);
1644 if (bss->eap_req_id_text == NULL) {
1645 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1646 "allocate memory for "
1647 "eap_req_id_text", line);
1651 bss->eap_req_id_text_len =
1652 os_strlen(bss->eap_req_id_text);
1653 term = os_strstr(bss->eap_req_id_text, "\\0");
1656 os_memmove(term, term + 1,
1657 bss->eap_req_id_text_len -
1658 (term - bss->eap_req_id_text) - 1);
1659 bss->eap_req_id_text_len--;
1661 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1662 bss->default_wep_key_len = atoi(pos);
1663 if (bss->default_wep_key_len > 13) {
1664 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1665 "key len %lu (= %lu bits)", line,
1667 bss->default_wep_key_len,
1669 bss->default_wep_key_len * 8);
1672 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1673 bss->individual_wep_key_len = atoi(pos);
1674 if (bss->individual_wep_key_len < 0 ||
1675 bss->individual_wep_key_len > 13) {
1676 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1677 "key len %d (= %d bits)", line,
1678 bss->individual_wep_key_len,
1679 bss->individual_wep_key_len * 8);
1682 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1683 bss->wep_rekeying_period = atoi(pos);
1684 if (bss->wep_rekeying_period < 0) {
1685 wpa_printf(MSG_ERROR, "Line %d: invalid "
1687 line, bss->wep_rekeying_period);
1690 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1691 bss->eap_reauth_period = atoi(pos);
1692 if (bss->eap_reauth_period < 0) {
1693 wpa_printf(MSG_ERROR, "Line %d: invalid "
1695 line, bss->eap_reauth_period);
1698 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1699 bss->eapol_key_index_workaround = atoi(pos);
1701 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1702 bss->ieee802_11f = 1;
1703 os_strlcpy(bss->iapp_iface, pos,
1704 sizeof(bss->iapp_iface));
1705 #endif /* CONFIG_IAPP */
1706 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1707 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1708 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1709 "address '%s'", line, pos);
1712 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1713 bss->nas_identifier = os_strdup(pos);
1714 #ifndef CONFIG_NO_RADIUS
1715 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1716 if (hostapd_config_read_radius_addr(
1717 &bss->radius->auth_servers,
1718 &bss->radius->num_auth_servers, pos, 1812,
1719 &bss->radius->auth_server)) {
1720 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1721 "address '%s'", line, pos);
1724 } else if (bss->radius->auth_server &&
1725 os_strcmp(buf, "auth_server_port") == 0) {
1726 bss->radius->auth_server->port = atoi(pos);
1727 } else if (bss->radius->auth_server &&
1728 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1729 int len = os_strlen(pos);
1731 /* RFC 2865, Ch. 3 */
1732 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1733 "secret is not allowed.", line);
1736 bss->radius->auth_server->shared_secret =
1737 (u8 *) os_strdup(pos);
1738 bss->radius->auth_server->shared_secret_len = len;
1739 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1740 if (hostapd_config_read_radius_addr(
1741 &bss->radius->acct_servers,
1742 &bss->radius->num_acct_servers, pos, 1813,
1743 &bss->radius->acct_server)) {
1744 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1745 "address '%s'", line, pos);
1748 } else if (bss->radius->acct_server &&
1749 os_strcmp(buf, "acct_server_port") == 0) {
1750 bss->radius->acct_server->port = atoi(pos);
1751 } else if (bss->radius->acct_server &&
1752 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1753 int len = os_strlen(pos);
1755 /* RFC 2865, Ch. 3 */
1756 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1757 "secret is not allowed.", line);
1760 bss->radius->acct_server->shared_secret =
1761 (u8 *) os_strdup(pos);
1762 bss->radius->acct_server->shared_secret_len = len;
1763 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1765 bss->radius->retry_primary_interval = atoi(pos);
1766 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1768 bss->acct_interim_interval = atoi(pos);
1769 #endif /* CONFIG_NO_RADIUS */
1770 } else if (os_strcmp(buf, "auth_algs") == 0) {
1771 bss->auth_algs = atoi(pos);
1772 if (bss->auth_algs == 0) {
1773 wpa_printf(MSG_ERROR, "Line %d: no "
1774 "authentication algorithms allowed",
1778 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1779 bss->max_num_sta = atoi(pos);
1780 if (bss->max_num_sta < 0 ||
1781 bss->max_num_sta > MAX_STA_COUNT) {
1782 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1783 "max_num_sta=%d; allowed range "
1784 "0..%d", line, bss->max_num_sta,
1788 } else if (os_strcmp(buf, "wpa") == 0) {
1789 bss->wpa = atoi(pos);
1790 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1791 bss->wpa_group_rekey = atoi(pos);
1792 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1793 bss->wpa_strict_rekey = atoi(pos);
1794 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1795 bss->wpa_gmk_rekey = atoi(pos);
1796 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1797 bss->wpa_ptk_rekey = atoi(pos);
1798 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1799 int len = os_strlen(pos);
1800 if (len < 8 || len > 63) {
1801 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1802 "passphrase length %d (expected "
1803 "8..63)", line, len);
1806 os_free(bss->ssid.wpa_passphrase);
1807 bss->ssid.wpa_passphrase = os_strdup(pos);
1809 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1810 os_free(bss->ssid.wpa_psk);
1812 os_zalloc(sizeof(struct hostapd_wpa_psk));
1813 if (bss->ssid.wpa_psk == NULL)
1815 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1817 pos[PMK_LEN * 2] != '\0') {
1818 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1819 "'%s'.", line, pos);
1822 bss->ssid.wpa_psk->group = 1;
1824 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1825 os_free(bss->ssid.wpa_psk_file);
1826 bss->ssid.wpa_psk_file = os_strdup(pos);
1827 if (!bss->ssid.wpa_psk_file) {
1828 wpa_printf(MSG_ERROR, "Line %d: allocation "
1832 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1834 hostapd_config_parse_key_mgmt(line, pos);
1835 if (bss->wpa_key_mgmt == -1)
1837 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1839 hostapd_config_parse_cipher(line, pos);
1840 if (bss->wpa_pairwise == -1 ||
1841 bss->wpa_pairwise == 0)
1843 else if (bss->wpa_pairwise &
1844 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1845 WPA_CIPHER_WEP104)) {
1846 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1847 "pairwise cipher suite '%s'",
1848 bss->wpa_pairwise, pos);
1851 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1853 hostapd_config_parse_cipher(line, pos);
1854 if (bss->rsn_pairwise == -1 ||
1855 bss->rsn_pairwise == 0)
1857 else if (bss->rsn_pairwise &
1858 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1859 WPA_CIPHER_WEP104)) {
1860 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1861 "pairwise cipher suite '%s'",
1862 bss->rsn_pairwise, pos);
1865 #ifdef CONFIG_RSN_PREAUTH
1866 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1867 bss->rsn_preauth = atoi(pos);
1868 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1869 bss->rsn_preauth_interfaces = os_strdup(pos);
1870 #endif /* CONFIG_RSN_PREAUTH */
1871 #ifdef CONFIG_PEERKEY
1872 } else if (os_strcmp(buf, "peerkey") == 0) {
1873 bss->peerkey = atoi(pos);
1874 #endif /* CONFIG_PEERKEY */
1875 #ifdef CONFIG_IEEE80211R
1876 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1877 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1878 hexstr2bin(pos, bss->mobility_domain,
1879 MOBILITY_DOMAIN_ID_LEN) != 0) {
1880 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1881 "mobility_domain '%s'", line, pos);
1885 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1886 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1887 hexstr2bin(pos, bss->r1_key_holder,
1888 FT_R1KH_ID_LEN) != 0) {
1889 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1890 "r1_key_holder '%s'", line, pos);
1894 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1895 bss->r0_key_lifetime = atoi(pos);
1896 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1897 bss->reassociation_deadline = atoi(pos);
1898 } else if (os_strcmp(buf, "r0kh") == 0) {
1899 if (add_r0kh(bss, pos) < 0) {
1900 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1901 "r0kh '%s'", line, pos);
1905 } else if (os_strcmp(buf, "r1kh") == 0) {
1906 if (add_r1kh(bss, pos) < 0) {
1907 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1908 "r1kh '%s'", line, pos);
1912 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1913 bss->pmk_r1_push = atoi(pos);
1914 #endif /* CONFIG_IEEE80211R */
1915 #ifndef CONFIG_NO_CTRL_IFACE
1916 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1917 os_free(bss->ctrl_interface);
1918 bss->ctrl_interface = os_strdup(pos);
1919 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1920 #ifndef CONFIG_NATIVE_WINDOWS
1923 const char *group = pos;
1925 grp = getgrnam(group);
1927 bss->ctrl_interface_gid = grp->gr_gid;
1928 bss->ctrl_interface_gid_set = 1;
1929 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1930 " (from group name '%s')",
1931 bss->ctrl_interface_gid, group);
1935 /* Group name not found - try to parse this as gid */
1936 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1937 if (*group == '\0' || *endp != '\0') {
1938 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1939 "'%s'", line, group);
1943 bss->ctrl_interface_gid_set = 1;
1944 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1945 bss->ctrl_interface_gid);
1946 #endif /* CONFIG_NATIVE_WINDOWS */
1947 #endif /* CONFIG_NO_CTRL_IFACE */
1948 #ifdef RADIUS_SERVER
1949 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1950 os_free(bss->radius_server_clients);
1951 bss->radius_server_clients = os_strdup(pos);
1952 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1953 bss->radius_server_auth_port = atoi(pos);
1954 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1955 bss->radius_server_ipv6 = atoi(pos);
1956 #endif /* RADIUS_SERVER */
1957 } else if (os_strcmp(buf, "test_socket") == 0) {
1958 os_free(bss->test_socket);
1959 bss->test_socket = os_strdup(pos);
1960 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1961 bss->use_pae_group_addr = atoi(pos);
1962 } else if (os_strcmp(buf, "hw_mode") == 0) {
1963 if (os_strcmp(pos, "a") == 0)
1964 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1965 else if (os_strcmp(pos, "b") == 0)
1966 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1967 else if (os_strcmp(pos, "g") == 0)
1968 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1970 wpa_printf(MSG_ERROR, "Line %d: unknown "
1971 "hw_mode '%s'", line, pos);
1974 } else if (os_strcmp(buf, "channel") == 0) {
1975 conf->channel = atoi(pos);
1976 } else if (os_strcmp(buf, "beacon_int") == 0) {
1977 int val = atoi(pos);
1978 /* MIB defines range as 1..65535, but very small values
1979 * cause problems with the current implementation.
1980 * Since it is unlikely that this small numbers are
1981 * useful in real life scenarios, do not allow beacon
1982 * period to be set below 15 TU. */
1983 if (val < 15 || val > 65535) {
1984 wpa_printf(MSG_ERROR, "Line %d: invalid "
1985 "beacon_int %d (expected "
1986 "15..65535)", line, val);
1989 conf->beacon_int = val;
1990 } else if (os_strcmp(buf, "dtim_period") == 0) {
1991 bss->dtim_period = atoi(pos);
1992 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1993 wpa_printf(MSG_ERROR, "Line %d: invalid "
1995 line, bss->dtim_period);
1998 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1999 conf->rts_threshold = atoi(pos);
2000 if (conf->rts_threshold < 0 ||
2001 conf->rts_threshold > 2347) {
2002 wpa_printf(MSG_ERROR, "Line %d: invalid "
2004 line, conf->rts_threshold);
2007 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2008 conf->fragm_threshold = atoi(pos);
2009 if (conf->fragm_threshold < 256 ||
2010 conf->fragm_threshold > 2346) {
2011 wpa_printf(MSG_ERROR, "Line %d: invalid "
2012 "fragm_threshold %d",
2013 line, conf->fragm_threshold);
2016 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2017 int val = atoi(pos);
2018 if (val != 0 && val != 1) {
2019 wpa_printf(MSG_ERROR, "Line %d: invalid "
2020 "send_probe_response %d (expected "
2021 "0 or 1)", line, val);
2023 conf->send_probe_response = val;
2024 } else if (os_strcmp(buf, "supported_rates") == 0) {
2025 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2026 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2030 } else if (os_strcmp(buf, "basic_rates") == 0) {
2031 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2032 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2036 } else if (os_strcmp(buf, "preamble") == 0) {
2038 conf->preamble = SHORT_PREAMBLE;
2040 conf->preamble = LONG_PREAMBLE;
2041 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2042 bss->ignore_broadcast_ssid = atoi(pos);
2043 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2044 bss->ssid.wep.idx = atoi(pos);
2045 if (bss->ssid.wep.idx > 3) {
2046 wpa_printf(MSG_ERROR, "Invalid "
2047 "wep_default_key index %d",
2051 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2052 os_strcmp(buf, "wep_key1") == 0 ||
2053 os_strcmp(buf, "wep_key2") == 0 ||
2054 os_strcmp(buf, "wep_key3") == 0) {
2055 if (hostapd_config_read_wep(&bss->ssid.wep,
2056 buf[7] - '0', pos)) {
2057 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2058 "key '%s'", line, buf);
2061 #ifndef CONFIG_NO_VLAN
2062 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2063 bss->ssid.dynamic_vlan = atoi(pos);
2064 } else if (os_strcmp(buf, "vlan_file") == 0) {
2065 if (hostapd_config_read_vlan_file(bss, pos)) {
2066 wpa_printf(MSG_ERROR, "Line %d: failed to "
2067 "read VLAN file '%s'", line, pos);
2070 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2071 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2072 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2073 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2074 #endif /* CONFIG_NO_VLAN */
2075 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2076 conf->ap_table_max_size = atoi(pos);
2077 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2078 conf->ap_table_expiration_time = atoi(pos);
2079 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2080 if (hostapd_config_tx_queue(conf, buf, pos)) {
2081 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2082 "queue item", line);
2085 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2086 os_strcmp(buf, "wmm_enabled") == 0) {
2087 bss->wmm_enabled = atoi(pos);
2088 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2089 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2090 if (hostapd_config_wmm_ac(conf, buf, pos)) {
2091 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2095 } else if (os_strcmp(buf, "bss") == 0) {
2096 if (hostapd_config_bss(conf, pos)) {
2097 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2101 } else if (os_strcmp(buf, "bssid") == 0) {
2102 if (hwaddr_aton(pos, bss->bssid)) {
2103 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2107 #ifdef CONFIG_IEEE80211W
2108 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2109 bss->ieee80211w = atoi(pos);
2110 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2111 bss->assoc_sa_query_max_timeout = atoi(pos);
2112 if (bss->assoc_sa_query_max_timeout == 0) {
2113 wpa_printf(MSG_ERROR, "Line %d: invalid "
2114 "assoc_sa_query_max_timeout", line);
2117 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2119 bss->assoc_sa_query_retry_timeout = atoi(pos);
2120 if (bss->assoc_sa_query_retry_timeout == 0) {
2121 wpa_printf(MSG_ERROR, "Line %d: invalid "
2122 "assoc_sa_query_retry_timeout",
2126 #endif /* CONFIG_IEEE80211W */
2127 #ifdef CONFIG_IEEE80211N
2128 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2129 conf->ieee80211n = atoi(pos);
2130 } else if (os_strcmp(buf, "ht_capab") == 0) {
2131 if (hostapd_config_ht_capab(conf, pos) < 0) {
2132 wpa_printf(MSG_ERROR, "Line %d: invalid "
2136 #endif /* CONFIG_IEEE80211N */
2137 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2138 bss->max_listen_interval = atoi(pos);
2139 } else if (os_strcmp(buf, "okc") == 0) {
2140 bss->okc = atoi(pos);
2142 } else if (os_strcmp(buf, "wps_state") == 0) {
2143 bss->wps_state = atoi(pos);
2144 if (bss->wps_state < 0 || bss->wps_state > 2) {
2145 wpa_printf(MSG_ERROR, "Line %d: invalid "
2149 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2150 bss->ap_setup_locked = atoi(pos);
2151 } else if (os_strcmp(buf, "uuid") == 0) {
2152 if (uuid_str2bin(pos, bss->uuid)) {
2153 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2157 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2158 os_free(bss->wps_pin_requests);
2159 bss->wps_pin_requests = os_strdup(pos);
2160 } else if (os_strcmp(buf, "device_name") == 0) {
2161 if (os_strlen(pos) > 32) {
2162 wpa_printf(MSG_ERROR, "Line %d: Too long "
2163 "device_name", line);
2166 os_free(bss->device_name);
2167 bss->device_name = os_strdup(pos);
2168 } else if (os_strcmp(buf, "manufacturer") == 0) {
2169 if (os_strlen(pos) > 64) {
2170 wpa_printf(MSG_ERROR, "Line %d: Too long "
2171 "manufacturer", line);
2174 os_free(bss->manufacturer);
2175 bss->manufacturer = os_strdup(pos);
2176 } else if (os_strcmp(buf, "model_name") == 0) {
2177 if (os_strlen(pos) > 32) {
2178 wpa_printf(MSG_ERROR, "Line %d: Too long "
2179 "model_name", line);
2182 os_free(bss->model_name);
2183 bss->model_name = os_strdup(pos);
2184 } else if (os_strcmp(buf, "model_number") == 0) {
2185 if (os_strlen(pos) > 32) {
2186 wpa_printf(MSG_ERROR, "Line %d: Too long "
2187 "model_number", line);
2190 os_free(bss->model_number);
2191 bss->model_number = os_strdup(pos);
2192 } else if (os_strcmp(buf, "serial_number") == 0) {
2193 if (os_strlen(pos) > 32) {
2194 wpa_printf(MSG_ERROR, "Line %d: Too long "
2195 "serial_number", line);
2198 os_free(bss->serial_number);
2199 bss->serial_number = os_strdup(pos);
2200 } else if (os_strcmp(buf, "device_type") == 0) {
2201 os_free(bss->device_type);
2202 bss->device_type = os_strdup(pos);
2203 } else if (os_strcmp(buf, "config_methods") == 0) {
2204 os_free(bss->config_methods);
2205 bss->config_methods = os_strdup(pos);
2206 } else if (os_strcmp(buf, "os_version") == 0) {
2207 if (hexstr2bin(pos, bss->os_version, 4)) {
2208 wpa_printf(MSG_ERROR, "Line %d: invalid "
2209 "os_version", line);
2212 } else if (os_strcmp(buf, "ap_pin") == 0) {
2213 os_free(bss->ap_pin);
2214 bss->ap_pin = os_strdup(pos);
2215 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2216 bss->skip_cred_build = atoi(pos);
2217 } else if (os_strcmp(buf, "extra_cred") == 0) {
2218 os_free(bss->extra_cred);
2220 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2221 if (bss->extra_cred == NULL) {
2222 wpa_printf(MSG_ERROR, "Line %d: could not "
2223 "read Credentials from '%s'",
2227 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2228 bss->wps_cred_processing = atoi(pos);
2229 } else if (os_strcmp(buf, "ap_settings") == 0) {
2230 os_free(bss->ap_settings);
2232 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2233 if (bss->ap_settings == NULL) {
2234 wpa_printf(MSG_ERROR, "Line %d: could not "
2235 "read AP Settings from '%s'",
2239 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2240 bss->upnp_iface = os_strdup(pos);
2241 } else if (os_strcmp(buf, "friendly_name") == 0) {
2242 os_free(bss->friendly_name);
2243 bss->friendly_name = os_strdup(pos);
2244 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2245 os_free(bss->manufacturer_url);
2246 bss->manufacturer_url = os_strdup(pos);
2247 } else if (os_strcmp(buf, "model_description") == 0) {
2248 os_free(bss->model_description);
2249 bss->model_description = os_strdup(pos);
2250 } else if (os_strcmp(buf, "model_url") == 0) {
2251 os_free(bss->model_url);
2252 bss->model_url = os_strdup(pos);
2253 } else if (os_strcmp(buf, "upc") == 0) {
2255 bss->upc = os_strdup(pos);
2256 #endif /* CONFIG_WPS */
2258 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2259 "item '%s'", line, buf);
2266 for (i = 0; i < conf->num_bss; i++) {
2267 bss = &conf->bss[i];
2269 if (bss->individual_wep_key_len == 0) {
2270 /* individual keys are not use; can use key idx0 for
2272 bss->broadcast_key_idx_min = 0;
2275 /* Select group cipher based on the enabled pairwise cipher
2279 pairwise |= bss->wpa_pairwise;
2281 if (bss->rsn_pairwise == 0)
2282 bss->rsn_pairwise = bss->wpa_pairwise;
2283 pairwise |= bss->rsn_pairwise;
2285 if (pairwise & WPA_CIPHER_TKIP)
2286 bss->wpa_group = WPA_CIPHER_TKIP;
2288 bss->wpa_group = WPA_CIPHER_CCMP;
2290 bss->radius->auth_server = bss->radius->auth_servers;
2291 bss->radius->acct_server = bss->radius->acct_servers;
2293 if (bss->wpa && bss->ieee802_1x) {
2294 bss->ssid.security_policy = SECURITY_WPA;
2295 } else if (bss->wpa) {
2296 bss->ssid.security_policy = SECURITY_WPA_PSK;
2297 } else if (bss->ieee802_1x) {
2298 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2299 bss->ssid.wep.default_len = bss->default_wep_key_len;
2300 } else if (bss->ssid.wep.keys_set)
2301 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2303 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2306 if (hostapd_config_check(conf))
2310 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2311 "'%s'", errors, fname);
2312 hostapd_config_free(conf);
2320 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2324 if (a->idx != b->idx || a->default_len != b->default_len)
2326 for (i = 0; i < NUM_WEP_KEYS; i++)
2327 if (a->len[i] != b->len[i] ||
2328 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2334 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2339 for (i = 0; i < num_servers; i++) {
2340 os_free(servers[i].shared_secret);
2346 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2348 os_free(user->identity);
2349 os_free(user->password);
2354 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2357 for (i = 0; i < NUM_WEP_KEYS; i++) {
2358 os_free(keys->key[i]);
2359 keys->key[i] = NULL;
2364 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2366 struct hostapd_wpa_psk *psk, *prev;
2367 struct hostapd_eap_user *user, *prev_user;
2372 psk = conf->ssid.wpa_psk;
2379 os_free(conf->ssid.wpa_passphrase);
2380 os_free(conf->ssid.wpa_psk_file);
2381 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2382 os_free(conf->ssid.vlan_tagged_interface);
2383 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2385 user = conf->eap_user;
2389 hostapd_config_free_eap_user(prev_user);
2392 os_free(conf->dump_log_name);
2393 os_free(conf->eap_req_id_text);
2394 os_free(conf->accept_mac);
2395 os_free(conf->deny_mac);
2396 os_free(conf->nas_identifier);
2397 hostapd_config_free_radius(conf->radius->auth_servers,
2398 conf->radius->num_auth_servers);
2399 hostapd_config_free_radius(conf->radius->acct_servers,
2400 conf->radius->num_acct_servers);
2401 os_free(conf->rsn_preauth_interfaces);
2402 os_free(conf->ctrl_interface);
2403 os_free(conf->ca_cert);
2404 os_free(conf->server_cert);
2405 os_free(conf->private_key);
2406 os_free(conf->private_key_passwd);
2407 os_free(conf->dh_file);
2408 os_free(conf->pac_opaque_encr_key);
2409 os_free(conf->eap_fast_a_id);
2410 os_free(conf->eap_fast_a_id_info);
2411 os_free(conf->eap_sim_db);
2412 os_free(conf->radius_server_clients);
2413 os_free(conf->test_socket);
2414 os_free(conf->radius);
2415 hostapd_config_free_vlan(conf);
2416 if (conf->ssid.dyn_vlan_keys) {
2417 struct hostapd_ssid *ssid = &conf->ssid;
2419 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2420 if (ssid->dyn_vlan_keys[i] == NULL)
2422 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2423 os_free(ssid->dyn_vlan_keys[i]);
2425 os_free(ssid->dyn_vlan_keys);
2426 ssid->dyn_vlan_keys = NULL;
2429 #ifdef CONFIG_IEEE80211R
2431 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2432 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2434 r0kh = conf->r0kh_list;
2435 conf->r0kh_list = NULL;
2442 r1kh = conf->r1kh_list;
2443 conf->r1kh_list = NULL;
2450 #endif /* CONFIG_IEEE80211R */
2453 os_free(conf->wps_pin_requests);
2454 os_free(conf->device_name);
2455 os_free(conf->manufacturer);
2456 os_free(conf->model_name);
2457 os_free(conf->model_number);
2458 os_free(conf->serial_number);
2459 os_free(conf->device_type);
2460 os_free(conf->config_methods);
2461 os_free(conf->ap_pin);
2462 os_free(conf->extra_cred);
2463 os_free(conf->ap_settings);
2464 os_free(conf->upnp_iface);
2465 os_free(conf->friendly_name);
2466 os_free(conf->manufacturer_url);
2467 os_free(conf->model_description);
2468 os_free(conf->model_url);
2470 #endif /* CONFIG_WPS */
2475 * hostapd_config_free - Free hostapd configuration
2476 * @conf: Configuration data from hostapd_config_read().
2478 void hostapd_config_free(struct hostapd_config *conf)
2485 for (i = 0; i < conf->num_bss; i++)
2486 hostapd_config_free_bss(&conf->bss[i]);
2494 * hostapd_maclist_found - Find a MAC address from a list
2495 * @list: MAC address list
2496 * @num_entries: Number of addresses in the list
2497 * @addr: Address to search for
2498 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
2499 * Returns: 1 if address is in the list or 0 if not.
2501 * Perform a binary search for given MAC address from a pre-sorted list.
2503 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2504 const u8 *addr, int *vlan_id)
2506 int start, end, middle, res;
2509 end = num_entries - 1;
2511 while (start <= end) {
2512 middle = (start + end) / 2;
2513 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2516 *vlan_id = list[middle].vlan_id;
2529 int hostapd_rate_found(int *list, int rate)
2536 for (i = 0; list[i] >= 0; i++)
2537 if (list[i] == rate)
2544 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2546 struct hostapd_vlan *v = vlan;
2548 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2556 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2557 const u8 *addr, const u8 *prev_psk)
2559 struct hostapd_wpa_psk *psk;
2560 int next_ok = prev_psk == NULL;
2562 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2564 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2567 if (psk->psk == prev_psk)
2575 const struct hostapd_eap_user *
2576 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2577 size_t identity_len, int phase2)
2579 struct hostapd_eap_user *user = conf->eap_user;
2582 if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
2583 os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
2584 static struct hostapd_eap_user wsc_enrollee;
2585 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
2586 wsc_enrollee.methods[0].method = eap_server_get_type(
2587 "WSC", &wsc_enrollee.methods[0].vendor);
2588 return &wsc_enrollee;
2591 if (conf->wps_state && conf->ap_pin &&
2592 identity_len == WSC_ID_REGISTRAR_LEN &&
2593 os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
2594 static struct hostapd_eap_user wsc_registrar;
2595 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
2596 wsc_registrar.methods[0].method = eap_server_get_type(
2597 "WSC", &wsc_registrar.methods[0].vendor);
2598 wsc_registrar.password = (u8 *) conf->ap_pin;
2599 wsc_registrar.password_len = os_strlen(conf->ap_pin);
2600 return &wsc_registrar;
2602 #endif /* CONFIG_WPS */
2605 if (!phase2 && user->identity == NULL) {
2606 /* Wildcard match */
2610 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2611 identity_len >= user->identity_len &&
2612 os_memcmp(user->identity, identity, user->identity_len) ==
2614 /* Wildcard prefix match */
2618 if (user->phase2 == !!phase2 &&
2619 user->identity_len == identity_len &&
2620 os_memcmp(user->identity, identity, identity_len) == 0)