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, "wds_sta") == 0) {
1538 bss->wds_sta = atoi(pos);
1539 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1540 bss->ap_max_inactivity = atoi(pos);
1541 } else if (os_strcmp(buf, "country_code") == 0) {
1542 os_memcpy(conf->country, pos, 2);
1543 /* FIX: make this configurable */
1544 conf->country[2] = ' ';
1545 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1546 conf->ieee80211d = atoi(pos);
1547 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1548 bss->ieee802_1x = atoi(pos);
1549 } else if (os_strcmp(buf, "eapol_version") == 0) {
1550 bss->eapol_version = atoi(pos);
1551 if (bss->eapol_version < 1 ||
1552 bss->eapol_version > 2) {
1553 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1554 "version (%d): '%s'.",
1555 line, bss->eapol_version, pos);
1558 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1559 bss->eapol_version);
1561 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1562 bss->eap_server = atoi(pos);
1563 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1564 "eap_authenticator used; this has been "
1565 "renamed to eap_server", line);
1566 } else if (os_strcmp(buf, "eap_server") == 0) {
1567 bss->eap_server = atoi(pos);
1568 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1569 if (hostapd_config_read_eap_user(pos, bss))
1571 } else if (os_strcmp(buf, "ca_cert") == 0) {
1572 os_free(bss->ca_cert);
1573 bss->ca_cert = os_strdup(pos);
1574 } else if (os_strcmp(buf, "server_cert") == 0) {
1575 os_free(bss->server_cert);
1576 bss->server_cert = os_strdup(pos);
1577 } else if (os_strcmp(buf, "private_key") == 0) {
1578 os_free(bss->private_key);
1579 bss->private_key = os_strdup(pos);
1580 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1581 os_free(bss->private_key_passwd);
1582 bss->private_key_passwd = os_strdup(pos);
1583 } else if (os_strcmp(buf, "check_crl") == 0) {
1584 bss->check_crl = atoi(pos);
1585 } else if (os_strcmp(buf, "dh_file") == 0) {
1586 os_free(bss->dh_file);
1587 bss->dh_file = os_strdup(pos);
1588 #ifdef EAP_SERVER_FAST
1589 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1590 os_free(bss->pac_opaque_encr_key);
1591 bss->pac_opaque_encr_key = os_malloc(16);
1592 if (bss->pac_opaque_encr_key == NULL) {
1593 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1594 "pac_opaque_encr_key", line);
1596 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1598 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1599 "pac_opaque_encr_key", line);
1602 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1603 size_t idlen = os_strlen(pos);
1605 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1606 "eap_fast_a_id", line);
1609 os_free(bss->eap_fast_a_id);
1610 bss->eap_fast_a_id = os_malloc(idlen / 2);
1611 if (bss->eap_fast_a_id == NULL ||
1612 hexstr2bin(pos, bss->eap_fast_a_id,
1614 wpa_printf(MSG_ERROR, "Line %d: "
1616 "eap_fast_a_id", line);
1619 bss->eap_fast_a_id_len = idlen / 2;
1621 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1622 os_free(bss->eap_fast_a_id_info);
1623 bss->eap_fast_a_id_info = os_strdup(pos);
1624 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1625 bss->eap_fast_prov = atoi(pos);
1626 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1627 bss->pac_key_lifetime = atoi(pos);
1628 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1629 bss->pac_key_refresh_time = atoi(pos);
1630 #endif /* EAP_SERVER_FAST */
1631 #ifdef EAP_SERVER_SIM
1632 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1633 os_free(bss->eap_sim_db);
1634 bss->eap_sim_db = os_strdup(pos);
1635 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1636 bss->eap_sim_aka_result_ind = atoi(pos);
1637 #endif /* EAP_SERVER_SIM */
1638 #ifdef EAP_SERVER_TNC
1639 } else if (os_strcmp(buf, "tnc") == 0) {
1640 bss->tnc = atoi(pos);
1641 #endif /* EAP_SERVER_TNC */
1642 #endif /* EAP_SERVER */
1643 } else if (os_strcmp(buf, "eap_message") == 0) {
1645 bss->eap_req_id_text = os_strdup(pos);
1646 if (bss->eap_req_id_text == NULL) {
1647 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1648 "allocate memory for "
1649 "eap_req_id_text", line);
1653 bss->eap_req_id_text_len =
1654 os_strlen(bss->eap_req_id_text);
1655 term = os_strstr(bss->eap_req_id_text, "\\0");
1658 os_memmove(term, term + 1,
1659 bss->eap_req_id_text_len -
1660 (term - bss->eap_req_id_text) - 1);
1661 bss->eap_req_id_text_len--;
1663 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1664 bss->default_wep_key_len = atoi(pos);
1665 if (bss->default_wep_key_len > 13) {
1666 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1667 "key len %lu (= %lu bits)", line,
1669 bss->default_wep_key_len,
1671 bss->default_wep_key_len * 8);
1674 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1675 bss->individual_wep_key_len = atoi(pos);
1676 if (bss->individual_wep_key_len < 0 ||
1677 bss->individual_wep_key_len > 13) {
1678 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1679 "key len %d (= %d bits)", line,
1680 bss->individual_wep_key_len,
1681 bss->individual_wep_key_len * 8);
1684 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1685 bss->wep_rekeying_period = atoi(pos);
1686 if (bss->wep_rekeying_period < 0) {
1687 wpa_printf(MSG_ERROR, "Line %d: invalid "
1689 line, bss->wep_rekeying_period);
1692 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1693 bss->eap_reauth_period = atoi(pos);
1694 if (bss->eap_reauth_period < 0) {
1695 wpa_printf(MSG_ERROR, "Line %d: invalid "
1697 line, bss->eap_reauth_period);
1700 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1701 bss->eapol_key_index_workaround = atoi(pos);
1703 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1704 bss->ieee802_11f = 1;
1705 os_strlcpy(bss->iapp_iface, pos,
1706 sizeof(bss->iapp_iface));
1707 #endif /* CONFIG_IAPP */
1708 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1709 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1710 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1711 "address '%s'", line, pos);
1714 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1715 bss->nas_identifier = os_strdup(pos);
1716 #ifndef CONFIG_NO_RADIUS
1717 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1718 if (hostapd_config_read_radius_addr(
1719 &bss->radius->auth_servers,
1720 &bss->radius->num_auth_servers, pos, 1812,
1721 &bss->radius->auth_server)) {
1722 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1723 "address '%s'", line, pos);
1726 } else if (bss->radius->auth_server &&
1727 os_strcmp(buf, "auth_server_port") == 0) {
1728 bss->radius->auth_server->port = atoi(pos);
1729 } else if (bss->radius->auth_server &&
1730 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1731 int len = os_strlen(pos);
1733 /* RFC 2865, Ch. 3 */
1734 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1735 "secret is not allowed.", line);
1738 bss->radius->auth_server->shared_secret =
1739 (u8 *) os_strdup(pos);
1740 bss->radius->auth_server->shared_secret_len = len;
1741 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1742 if (hostapd_config_read_radius_addr(
1743 &bss->radius->acct_servers,
1744 &bss->radius->num_acct_servers, pos, 1813,
1745 &bss->radius->acct_server)) {
1746 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1747 "address '%s'", line, pos);
1750 } else if (bss->radius->acct_server &&
1751 os_strcmp(buf, "acct_server_port") == 0) {
1752 bss->radius->acct_server->port = atoi(pos);
1753 } else if (bss->radius->acct_server &&
1754 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1755 int len = os_strlen(pos);
1757 /* RFC 2865, Ch. 3 */
1758 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1759 "secret is not allowed.", line);
1762 bss->radius->acct_server->shared_secret =
1763 (u8 *) os_strdup(pos);
1764 bss->radius->acct_server->shared_secret_len = len;
1765 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1767 bss->radius->retry_primary_interval = atoi(pos);
1768 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1770 bss->acct_interim_interval = atoi(pos);
1771 #endif /* CONFIG_NO_RADIUS */
1772 } else if (os_strcmp(buf, "auth_algs") == 0) {
1773 bss->auth_algs = atoi(pos);
1774 if (bss->auth_algs == 0) {
1775 wpa_printf(MSG_ERROR, "Line %d: no "
1776 "authentication algorithms allowed",
1780 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1781 bss->max_num_sta = atoi(pos);
1782 if (bss->max_num_sta < 0 ||
1783 bss->max_num_sta > MAX_STA_COUNT) {
1784 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1785 "max_num_sta=%d; allowed range "
1786 "0..%d", line, bss->max_num_sta,
1790 } else if (os_strcmp(buf, "wpa") == 0) {
1791 bss->wpa = atoi(pos);
1792 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1793 bss->wpa_group_rekey = atoi(pos);
1794 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1795 bss->wpa_strict_rekey = atoi(pos);
1796 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1797 bss->wpa_gmk_rekey = atoi(pos);
1798 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1799 bss->wpa_ptk_rekey = atoi(pos);
1800 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1801 int len = os_strlen(pos);
1802 if (len < 8 || len > 63) {
1803 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1804 "passphrase length %d (expected "
1805 "8..63)", line, len);
1808 os_free(bss->ssid.wpa_passphrase);
1809 bss->ssid.wpa_passphrase = os_strdup(pos);
1811 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1812 os_free(bss->ssid.wpa_psk);
1814 os_zalloc(sizeof(struct hostapd_wpa_psk));
1815 if (bss->ssid.wpa_psk == NULL)
1817 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1819 pos[PMK_LEN * 2] != '\0') {
1820 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1821 "'%s'.", line, pos);
1824 bss->ssid.wpa_psk->group = 1;
1826 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1827 os_free(bss->ssid.wpa_psk_file);
1828 bss->ssid.wpa_psk_file = os_strdup(pos);
1829 if (!bss->ssid.wpa_psk_file) {
1830 wpa_printf(MSG_ERROR, "Line %d: allocation "
1834 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1836 hostapd_config_parse_key_mgmt(line, pos);
1837 if (bss->wpa_key_mgmt == -1)
1839 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1841 hostapd_config_parse_cipher(line, pos);
1842 if (bss->wpa_pairwise == -1 ||
1843 bss->wpa_pairwise == 0)
1845 else if (bss->wpa_pairwise &
1846 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1847 WPA_CIPHER_WEP104)) {
1848 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1849 "pairwise cipher suite '%s'",
1850 bss->wpa_pairwise, pos);
1853 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1855 hostapd_config_parse_cipher(line, pos);
1856 if (bss->rsn_pairwise == -1 ||
1857 bss->rsn_pairwise == 0)
1859 else if (bss->rsn_pairwise &
1860 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1861 WPA_CIPHER_WEP104)) {
1862 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1863 "pairwise cipher suite '%s'",
1864 bss->rsn_pairwise, pos);
1867 #ifdef CONFIG_RSN_PREAUTH
1868 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1869 bss->rsn_preauth = atoi(pos);
1870 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1871 bss->rsn_preauth_interfaces = os_strdup(pos);
1872 #endif /* CONFIG_RSN_PREAUTH */
1873 #ifdef CONFIG_PEERKEY
1874 } else if (os_strcmp(buf, "peerkey") == 0) {
1875 bss->peerkey = atoi(pos);
1876 #endif /* CONFIG_PEERKEY */
1877 #ifdef CONFIG_IEEE80211R
1878 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1879 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1880 hexstr2bin(pos, bss->mobility_domain,
1881 MOBILITY_DOMAIN_ID_LEN) != 0) {
1882 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1883 "mobility_domain '%s'", line, pos);
1887 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1888 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1889 hexstr2bin(pos, bss->r1_key_holder,
1890 FT_R1KH_ID_LEN) != 0) {
1891 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1892 "r1_key_holder '%s'", line, pos);
1896 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1897 bss->r0_key_lifetime = atoi(pos);
1898 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1899 bss->reassociation_deadline = atoi(pos);
1900 } else if (os_strcmp(buf, "r0kh") == 0) {
1901 if (add_r0kh(bss, pos) < 0) {
1902 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1903 "r0kh '%s'", line, pos);
1907 } else if (os_strcmp(buf, "r1kh") == 0) {
1908 if (add_r1kh(bss, pos) < 0) {
1909 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1910 "r1kh '%s'", line, pos);
1914 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1915 bss->pmk_r1_push = atoi(pos);
1916 #endif /* CONFIG_IEEE80211R */
1917 #ifndef CONFIG_NO_CTRL_IFACE
1918 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1919 os_free(bss->ctrl_interface);
1920 bss->ctrl_interface = os_strdup(pos);
1921 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1922 #ifndef CONFIG_NATIVE_WINDOWS
1925 const char *group = pos;
1927 grp = getgrnam(group);
1929 bss->ctrl_interface_gid = grp->gr_gid;
1930 bss->ctrl_interface_gid_set = 1;
1931 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1932 " (from group name '%s')",
1933 bss->ctrl_interface_gid, group);
1937 /* Group name not found - try to parse this as gid */
1938 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1939 if (*group == '\0' || *endp != '\0') {
1940 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1941 "'%s'", line, group);
1945 bss->ctrl_interface_gid_set = 1;
1946 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1947 bss->ctrl_interface_gid);
1948 #endif /* CONFIG_NATIVE_WINDOWS */
1949 #endif /* CONFIG_NO_CTRL_IFACE */
1950 #ifdef RADIUS_SERVER
1951 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1952 os_free(bss->radius_server_clients);
1953 bss->radius_server_clients = os_strdup(pos);
1954 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1955 bss->radius_server_auth_port = atoi(pos);
1956 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1957 bss->radius_server_ipv6 = atoi(pos);
1958 #endif /* RADIUS_SERVER */
1959 } else if (os_strcmp(buf, "test_socket") == 0) {
1960 os_free(bss->test_socket);
1961 bss->test_socket = os_strdup(pos);
1962 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1963 bss->use_pae_group_addr = atoi(pos);
1964 } else if (os_strcmp(buf, "hw_mode") == 0) {
1965 if (os_strcmp(pos, "a") == 0)
1966 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1967 else if (os_strcmp(pos, "b") == 0)
1968 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1969 else if (os_strcmp(pos, "g") == 0)
1970 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1972 wpa_printf(MSG_ERROR, "Line %d: unknown "
1973 "hw_mode '%s'", line, pos);
1976 } else if (os_strcmp(buf, "channel") == 0) {
1977 conf->channel = atoi(pos);
1978 } else if (os_strcmp(buf, "beacon_int") == 0) {
1979 int val = atoi(pos);
1980 /* MIB defines range as 1..65535, but very small values
1981 * cause problems with the current implementation.
1982 * Since it is unlikely that this small numbers are
1983 * useful in real life scenarios, do not allow beacon
1984 * period to be set below 15 TU. */
1985 if (val < 15 || val > 65535) {
1986 wpa_printf(MSG_ERROR, "Line %d: invalid "
1987 "beacon_int %d (expected "
1988 "15..65535)", line, val);
1991 conf->beacon_int = val;
1992 } else if (os_strcmp(buf, "dtim_period") == 0) {
1993 bss->dtim_period = atoi(pos);
1994 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1995 wpa_printf(MSG_ERROR, "Line %d: invalid "
1997 line, bss->dtim_period);
2000 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2001 conf->rts_threshold = atoi(pos);
2002 if (conf->rts_threshold < 0 ||
2003 conf->rts_threshold > 2347) {
2004 wpa_printf(MSG_ERROR, "Line %d: invalid "
2006 line, conf->rts_threshold);
2009 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2010 conf->fragm_threshold = atoi(pos);
2011 if (conf->fragm_threshold < 256 ||
2012 conf->fragm_threshold > 2346) {
2013 wpa_printf(MSG_ERROR, "Line %d: invalid "
2014 "fragm_threshold %d",
2015 line, conf->fragm_threshold);
2018 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2019 int val = atoi(pos);
2020 if (val != 0 && val != 1) {
2021 wpa_printf(MSG_ERROR, "Line %d: invalid "
2022 "send_probe_response %d (expected "
2023 "0 or 1)", line, val);
2025 conf->send_probe_response = val;
2026 } else if (os_strcmp(buf, "supported_rates") == 0) {
2027 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2028 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2032 } else if (os_strcmp(buf, "basic_rates") == 0) {
2033 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2034 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2038 } else if (os_strcmp(buf, "preamble") == 0) {
2040 conf->preamble = SHORT_PREAMBLE;
2042 conf->preamble = LONG_PREAMBLE;
2043 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2044 bss->ignore_broadcast_ssid = atoi(pos);
2045 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2046 bss->ssid.wep.idx = atoi(pos);
2047 if (bss->ssid.wep.idx > 3) {
2048 wpa_printf(MSG_ERROR, "Invalid "
2049 "wep_default_key index %d",
2053 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2054 os_strcmp(buf, "wep_key1") == 0 ||
2055 os_strcmp(buf, "wep_key2") == 0 ||
2056 os_strcmp(buf, "wep_key3") == 0) {
2057 if (hostapd_config_read_wep(&bss->ssid.wep,
2058 buf[7] - '0', pos)) {
2059 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2060 "key '%s'", line, buf);
2063 #ifndef CONFIG_NO_VLAN
2064 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2065 bss->ssid.dynamic_vlan = atoi(pos);
2066 } else if (os_strcmp(buf, "vlan_file") == 0) {
2067 if (hostapd_config_read_vlan_file(bss, pos)) {
2068 wpa_printf(MSG_ERROR, "Line %d: failed to "
2069 "read VLAN file '%s'", line, pos);
2072 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2073 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2074 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2075 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2076 #endif /* CONFIG_NO_VLAN */
2077 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2078 conf->ap_table_max_size = atoi(pos);
2079 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2080 conf->ap_table_expiration_time = atoi(pos);
2081 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2082 if (hostapd_config_tx_queue(conf, buf, pos)) {
2083 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2084 "queue item", line);
2087 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2088 os_strcmp(buf, "wmm_enabled") == 0) {
2089 bss->wmm_enabled = atoi(pos);
2090 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2091 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2092 if (hostapd_config_wmm_ac(conf, buf, pos)) {
2093 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2097 } else if (os_strcmp(buf, "bss") == 0) {
2098 if (hostapd_config_bss(conf, pos)) {
2099 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2103 } else if (os_strcmp(buf, "bssid") == 0) {
2104 if (hwaddr_aton(pos, bss->bssid)) {
2105 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2109 #ifdef CONFIG_IEEE80211W
2110 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2111 bss->ieee80211w = atoi(pos);
2112 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2113 bss->assoc_sa_query_max_timeout = atoi(pos);
2114 if (bss->assoc_sa_query_max_timeout == 0) {
2115 wpa_printf(MSG_ERROR, "Line %d: invalid "
2116 "assoc_sa_query_max_timeout", line);
2119 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2121 bss->assoc_sa_query_retry_timeout = atoi(pos);
2122 if (bss->assoc_sa_query_retry_timeout == 0) {
2123 wpa_printf(MSG_ERROR, "Line %d: invalid "
2124 "assoc_sa_query_retry_timeout",
2128 #endif /* CONFIG_IEEE80211W */
2129 #ifdef CONFIG_IEEE80211N
2130 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2131 conf->ieee80211n = atoi(pos);
2132 } else if (os_strcmp(buf, "ht_capab") == 0) {
2133 if (hostapd_config_ht_capab(conf, pos) < 0) {
2134 wpa_printf(MSG_ERROR, "Line %d: invalid "
2138 #endif /* CONFIG_IEEE80211N */
2139 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2140 bss->max_listen_interval = atoi(pos);
2141 } else if (os_strcmp(buf, "okc") == 0) {
2142 bss->okc = atoi(pos);
2144 } else if (os_strcmp(buf, "wps_state") == 0) {
2145 bss->wps_state = atoi(pos);
2146 if (bss->wps_state < 0 || bss->wps_state > 2) {
2147 wpa_printf(MSG_ERROR, "Line %d: invalid "
2151 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2152 bss->ap_setup_locked = atoi(pos);
2153 } else if (os_strcmp(buf, "uuid") == 0) {
2154 if (uuid_str2bin(pos, bss->uuid)) {
2155 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2159 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2160 os_free(bss->wps_pin_requests);
2161 bss->wps_pin_requests = os_strdup(pos);
2162 } else if (os_strcmp(buf, "device_name") == 0) {
2163 if (os_strlen(pos) > 32) {
2164 wpa_printf(MSG_ERROR, "Line %d: Too long "
2165 "device_name", line);
2168 os_free(bss->device_name);
2169 bss->device_name = os_strdup(pos);
2170 } else if (os_strcmp(buf, "manufacturer") == 0) {
2171 if (os_strlen(pos) > 64) {
2172 wpa_printf(MSG_ERROR, "Line %d: Too long "
2173 "manufacturer", line);
2176 os_free(bss->manufacturer);
2177 bss->manufacturer = os_strdup(pos);
2178 } else if (os_strcmp(buf, "model_name") == 0) {
2179 if (os_strlen(pos) > 32) {
2180 wpa_printf(MSG_ERROR, "Line %d: Too long "
2181 "model_name", line);
2184 os_free(bss->model_name);
2185 bss->model_name = os_strdup(pos);
2186 } else if (os_strcmp(buf, "model_number") == 0) {
2187 if (os_strlen(pos) > 32) {
2188 wpa_printf(MSG_ERROR, "Line %d: Too long "
2189 "model_number", line);
2192 os_free(bss->model_number);
2193 bss->model_number = os_strdup(pos);
2194 } else if (os_strcmp(buf, "serial_number") == 0) {
2195 if (os_strlen(pos) > 32) {
2196 wpa_printf(MSG_ERROR, "Line %d: Too long "
2197 "serial_number", line);
2200 os_free(bss->serial_number);
2201 bss->serial_number = os_strdup(pos);
2202 } else if (os_strcmp(buf, "device_type") == 0) {
2203 os_free(bss->device_type);
2204 bss->device_type = os_strdup(pos);
2205 } else if (os_strcmp(buf, "config_methods") == 0) {
2206 os_free(bss->config_methods);
2207 bss->config_methods = os_strdup(pos);
2208 } else if (os_strcmp(buf, "os_version") == 0) {
2209 if (hexstr2bin(pos, bss->os_version, 4)) {
2210 wpa_printf(MSG_ERROR, "Line %d: invalid "
2211 "os_version", line);
2214 } else if (os_strcmp(buf, "ap_pin") == 0) {
2215 os_free(bss->ap_pin);
2216 bss->ap_pin = os_strdup(pos);
2217 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2218 bss->skip_cred_build = atoi(pos);
2219 } else if (os_strcmp(buf, "extra_cred") == 0) {
2220 os_free(bss->extra_cred);
2222 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2223 if (bss->extra_cred == NULL) {
2224 wpa_printf(MSG_ERROR, "Line %d: could not "
2225 "read Credentials from '%s'",
2229 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2230 bss->wps_cred_processing = atoi(pos);
2231 } else if (os_strcmp(buf, "ap_settings") == 0) {
2232 os_free(bss->ap_settings);
2234 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2235 if (bss->ap_settings == NULL) {
2236 wpa_printf(MSG_ERROR, "Line %d: could not "
2237 "read AP Settings from '%s'",
2241 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2242 bss->upnp_iface = os_strdup(pos);
2243 } else if (os_strcmp(buf, "friendly_name") == 0) {
2244 os_free(bss->friendly_name);
2245 bss->friendly_name = os_strdup(pos);
2246 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2247 os_free(bss->manufacturer_url);
2248 bss->manufacturer_url = os_strdup(pos);
2249 } else if (os_strcmp(buf, "model_description") == 0) {
2250 os_free(bss->model_description);
2251 bss->model_description = os_strdup(pos);
2252 } else if (os_strcmp(buf, "model_url") == 0) {
2253 os_free(bss->model_url);
2254 bss->model_url = os_strdup(pos);
2255 } else if (os_strcmp(buf, "upc") == 0) {
2257 bss->upc = os_strdup(pos);
2258 #endif /* CONFIG_WPS */
2260 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2261 "item '%s'", line, buf);
2268 for (i = 0; i < conf->num_bss; i++) {
2269 bss = &conf->bss[i];
2271 if (bss->individual_wep_key_len == 0) {
2272 /* individual keys are not use; can use key idx0 for
2274 bss->broadcast_key_idx_min = 0;
2277 /* Select group cipher based on the enabled pairwise cipher
2281 pairwise |= bss->wpa_pairwise;
2283 if (bss->rsn_pairwise == 0)
2284 bss->rsn_pairwise = bss->wpa_pairwise;
2285 pairwise |= bss->rsn_pairwise;
2287 if (pairwise & WPA_CIPHER_TKIP)
2288 bss->wpa_group = WPA_CIPHER_TKIP;
2290 bss->wpa_group = WPA_CIPHER_CCMP;
2292 bss->radius->auth_server = bss->radius->auth_servers;
2293 bss->radius->acct_server = bss->radius->acct_servers;
2295 if (bss->wpa && bss->ieee802_1x) {
2296 bss->ssid.security_policy = SECURITY_WPA;
2297 } else if (bss->wpa) {
2298 bss->ssid.security_policy = SECURITY_WPA_PSK;
2299 } else if (bss->ieee802_1x) {
2300 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2301 bss->ssid.wep.default_len = bss->default_wep_key_len;
2302 } else if (bss->ssid.wep.keys_set)
2303 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2305 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2308 if (hostapd_config_check(conf))
2312 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2313 "'%s'", errors, fname);
2314 hostapd_config_free(conf);
2322 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2326 if (a->idx != b->idx || a->default_len != b->default_len)
2328 for (i = 0; i < NUM_WEP_KEYS; i++)
2329 if (a->len[i] != b->len[i] ||
2330 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2336 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2341 for (i = 0; i < num_servers; i++) {
2342 os_free(servers[i].shared_secret);
2348 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2350 os_free(user->identity);
2351 os_free(user->password);
2356 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2359 for (i = 0; i < NUM_WEP_KEYS; i++) {
2360 os_free(keys->key[i]);
2361 keys->key[i] = NULL;
2366 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2368 struct hostapd_wpa_psk *psk, *prev;
2369 struct hostapd_eap_user *user, *prev_user;
2374 psk = conf->ssid.wpa_psk;
2381 os_free(conf->ssid.wpa_passphrase);
2382 os_free(conf->ssid.wpa_psk_file);
2383 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2384 os_free(conf->ssid.vlan_tagged_interface);
2385 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2387 user = conf->eap_user;
2391 hostapd_config_free_eap_user(prev_user);
2394 os_free(conf->dump_log_name);
2395 os_free(conf->eap_req_id_text);
2396 os_free(conf->accept_mac);
2397 os_free(conf->deny_mac);
2398 os_free(conf->nas_identifier);
2399 hostapd_config_free_radius(conf->radius->auth_servers,
2400 conf->radius->num_auth_servers);
2401 hostapd_config_free_radius(conf->radius->acct_servers,
2402 conf->radius->num_acct_servers);
2403 os_free(conf->rsn_preauth_interfaces);
2404 os_free(conf->ctrl_interface);
2405 os_free(conf->ca_cert);
2406 os_free(conf->server_cert);
2407 os_free(conf->private_key);
2408 os_free(conf->private_key_passwd);
2409 os_free(conf->dh_file);
2410 os_free(conf->pac_opaque_encr_key);
2411 os_free(conf->eap_fast_a_id);
2412 os_free(conf->eap_fast_a_id_info);
2413 os_free(conf->eap_sim_db);
2414 os_free(conf->radius_server_clients);
2415 os_free(conf->test_socket);
2416 os_free(conf->radius);
2417 hostapd_config_free_vlan(conf);
2418 if (conf->ssid.dyn_vlan_keys) {
2419 struct hostapd_ssid *ssid = &conf->ssid;
2421 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2422 if (ssid->dyn_vlan_keys[i] == NULL)
2424 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2425 os_free(ssid->dyn_vlan_keys[i]);
2427 os_free(ssid->dyn_vlan_keys);
2428 ssid->dyn_vlan_keys = NULL;
2431 #ifdef CONFIG_IEEE80211R
2433 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2434 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2436 r0kh = conf->r0kh_list;
2437 conf->r0kh_list = NULL;
2444 r1kh = conf->r1kh_list;
2445 conf->r1kh_list = NULL;
2452 #endif /* CONFIG_IEEE80211R */
2455 os_free(conf->wps_pin_requests);
2456 os_free(conf->device_name);
2457 os_free(conf->manufacturer);
2458 os_free(conf->model_name);
2459 os_free(conf->model_number);
2460 os_free(conf->serial_number);
2461 os_free(conf->device_type);
2462 os_free(conf->config_methods);
2463 os_free(conf->ap_pin);
2464 os_free(conf->extra_cred);
2465 os_free(conf->ap_settings);
2466 os_free(conf->upnp_iface);
2467 os_free(conf->friendly_name);
2468 os_free(conf->manufacturer_url);
2469 os_free(conf->model_description);
2470 os_free(conf->model_url);
2472 #endif /* CONFIG_WPS */
2477 * hostapd_config_free - Free hostapd configuration
2478 * @conf: Configuration data from hostapd_config_read().
2480 void hostapd_config_free(struct hostapd_config *conf)
2487 for (i = 0; i < conf->num_bss; i++)
2488 hostapd_config_free_bss(&conf->bss[i]);
2490 os_free(conf->supported_rates);
2491 os_free(conf->basic_rates);
2498 * hostapd_maclist_found - Find a MAC address from a list
2499 * @list: MAC address list
2500 * @num_entries: Number of addresses in the list
2501 * @addr: Address to search for
2502 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
2503 * Returns: 1 if address is in the list or 0 if not.
2505 * Perform a binary search for given MAC address from a pre-sorted list.
2507 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2508 const u8 *addr, int *vlan_id)
2510 int start, end, middle, res;
2513 end = num_entries - 1;
2515 while (start <= end) {
2516 middle = (start + end) / 2;
2517 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2520 *vlan_id = list[middle].vlan_id;
2533 int hostapd_rate_found(int *list, int rate)
2540 for (i = 0; list[i] >= 0; i++)
2541 if (list[i] == rate)
2548 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2550 struct hostapd_vlan *v = vlan;
2552 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2560 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2561 const u8 *addr, const u8 *prev_psk)
2563 struct hostapd_wpa_psk *psk;
2564 int next_ok = prev_psk == NULL;
2566 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2568 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2571 if (psk->psk == prev_psk)
2579 const struct hostapd_eap_user *
2580 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2581 size_t identity_len, int phase2)
2583 struct hostapd_eap_user *user = conf->eap_user;
2586 if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
2587 os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
2588 static struct hostapd_eap_user wsc_enrollee;
2589 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
2590 wsc_enrollee.methods[0].method = eap_server_get_type(
2591 "WSC", &wsc_enrollee.methods[0].vendor);
2592 return &wsc_enrollee;
2595 if (conf->wps_state && conf->ap_pin &&
2596 identity_len == WSC_ID_REGISTRAR_LEN &&
2597 os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
2598 static struct hostapd_eap_user wsc_registrar;
2599 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
2600 wsc_registrar.methods[0].method = eap_server_get_type(
2601 "WSC", &wsc_registrar.methods[0].vendor);
2602 wsc_registrar.password = (u8 *) conf->ap_pin;
2603 wsc_registrar.password_len = os_strlen(conf->ap_pin);
2604 return &wsc_registrar;
2606 #endif /* CONFIG_WPS */
2609 if (!phase2 && user->identity == NULL) {
2610 /* Wildcard match */
2614 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2615 identity_len >= user->identity_len &&
2616 os_memcmp(user->identity, identity, user->identity_len) ==
2618 /* Wildcard prefix match */
2622 if (user->phase2 == !!phase2 &&
2623 user->identity_len == identity_len &&
2624 os_memcmp(user->identity, identity, identity_len) == 0)