2 * hostapd / Configuration file
3 * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
17 #ifndef CONFIG_NATIVE_WINDOWS
19 #endif /* CONFIG_NATIVE_WINDOWS */
24 #include "eap_server/eap.h"
25 #include "radius/radius_client.h"
26 #include "wpa_common.h"
29 #include "eap_common/eap_wsc_common.h"
32 #define MAX_STA_COUNT 2007
34 extern struct wpa_driver_ops *hostapd_drivers[];
37 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
41 char buf[128], *pos, *pos2;
42 int line = 0, vlan_id;
43 struct hostapd_vlan *vlan;
45 f = fopen(fname, "r");
47 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
51 while (fgets(buf, sizeof(buf), f)) {
57 while (*pos != '\0') {
68 vlan_id = VLAN_ID_WILDCARD;
71 vlan_id = strtol(buf, &pos, 10);
72 if (buf == pos || vlan_id < 1 ||
73 vlan_id > MAX_VLAN_ID) {
74 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
75 "line %d in '%s'", line, fname);
81 while (*pos == ' ' || *pos == '\t')
84 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
87 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
88 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
89 "in '%s'", line, fname);
94 vlan = os_malloc(sizeof(*vlan));
96 wpa_printf(MSG_ERROR, "Out of memory while reading "
97 "VLAN interfaces from '%s'", fname);
102 os_memset(vlan, 0, sizeof(*vlan));
103 vlan->vlan_id = vlan_id;
104 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
106 bss->vlan_tail->next = vlan;
109 bss->vlan_tail = vlan;
118 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
120 struct hostapd_vlan *vlan, *prev;
134 /* convert floats with one decimal place to value*10 int, i.e.,
135 * "1.5" will return 15 */
136 static int hostapd_config_read_int10(const char *value)
142 pos = os_strchr(value, '.');
146 if (*pos >= '0' && *pos <= '9')
154 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
156 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
157 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
158 bss->logger_syslog = (unsigned int) -1;
159 bss->logger_stdout = (unsigned int) -1;
161 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
163 bss->wep_rekeying_period = 300;
164 /* use key0 in individual key and key1 in broadcast key */
165 bss->broadcast_key_idx_min = 1;
166 bss->broadcast_key_idx_max = 2;
167 bss->eap_reauth_period = 3600;
169 bss->wpa_group_rekey = 600;
170 bss->wpa_gmk_rekey = 86400;
171 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
172 bss->wpa_pairwise = WPA_CIPHER_TKIP;
173 bss->wpa_group = WPA_CIPHER_TKIP;
174 bss->rsn_pairwise = 0;
176 bss->max_num_sta = MAX_STA_COUNT;
178 bss->dtim_period = 2;
180 bss->radius_server_auth_port = 1812;
181 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
182 bss->eapol_version = EAPOL_VERSION;
184 bss->max_listen_interval = 65535;
186 #ifdef CONFIG_IEEE80211W
187 bss->assoc_sa_query_max_timeout = 1000;
188 bss->assoc_sa_query_retry_timeout = 201;
189 #endif /* CONFIG_IEEE80211W */
191 /* both anonymous and authenticated provisioning */
192 bss->eap_fast_prov = 3;
193 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
194 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
195 #endif /* EAP_FAST */
199 static struct hostapd_config * hostapd_config_defaults(void)
201 struct hostapd_config *conf;
202 struct hostapd_bss_config *bss;
204 const int aCWmin = 4, aCWmax = 10;
205 const struct hostapd_wmm_ac_params ac_bk =
206 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
207 const struct hostapd_wmm_ac_params ac_be =
208 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
209 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
210 { aCWmin - 1, aCWmin, 2, 3000 / 32, 1 };
211 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
212 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 1 };
214 conf = os_zalloc(sizeof(*conf));
215 bss = os_zalloc(sizeof(*bss));
216 if (conf == NULL || bss == NULL) {
217 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
218 "configuration data.");
224 /* set default driver based on configuration */
225 conf->driver = hostapd_drivers[0];
226 if (conf->driver == NULL) {
227 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
233 bss->radius = os_zalloc(sizeof(*bss->radius));
234 if (bss->radius == NULL) {
240 hostapd_config_defaults_bss(bss);
245 conf->beacon_int = 100;
246 conf->rts_threshold = -1; /* use driver default: 2347 */
247 conf->fragm_threshold = -1; /* user driver default: 2346 */
248 conf->send_probe_response = 1;
249 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
251 for (i = 0; i < NUM_TX_QUEUES; i++)
252 conf->tx_queue[i].aifs = -1; /* use hw default */
254 conf->wmm_ac_params[0] = ac_be;
255 conf->wmm_ac_params[1] = ac_bk;
256 conf->wmm_ac_params[2] = ac_vi;
257 conf->wmm_ac_params[3] = ac_vo;
259 #ifdef CONFIG_IEEE80211N
260 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
261 #endif /* CONFIG_IEEE80211N */
267 int hostapd_mac_comp(const void *a, const void *b)
269 return os_memcmp(a, b, sizeof(macaddr));
273 int hostapd_mac_comp_empty(const void *a)
275 macaddr empty = { 0 };
276 return os_memcmp(a, empty, sizeof(macaddr));
280 static int hostapd_acl_comp(const void *a, const void *b)
282 const struct mac_acl_entry *aa = a;
283 const struct mac_acl_entry *bb = b;
284 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
288 static int hostapd_config_read_maclist(const char *fname,
289 struct mac_acl_entry **acl, int *num)
295 struct mac_acl_entry *newacl;
301 f = fopen(fname, "r");
303 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
307 while (fgets(buf, sizeof(buf), f)) {
313 while (*pos != '\0') {
323 if (hwaddr_aton(buf, addr)) {
324 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
325 "line %d in '%s'", buf, line, fname);
332 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
334 while (*pos == ' ' || *pos == '\t')
339 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
340 if (newacl == NULL) {
341 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
347 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
348 (*acl)[*num].vlan_id = vlan_id;
354 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
360 static int hostapd_config_read_wpa_psk(const char *fname,
361 struct hostapd_ssid *ssid)
365 int line = 0, ret = 0, len, ok;
367 struct hostapd_wpa_psk *psk;
372 f = fopen(fname, "r");
374 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
378 while (fgets(buf, sizeof(buf), f)) {
384 while (*pos != '\0') {
394 if (hwaddr_aton(buf, addr)) {
395 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
396 "line %d in '%s'", buf, line, fname);
401 psk = os_zalloc(sizeof(*psk));
403 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
407 if (is_zero_ether_addr(addr))
410 os_memcpy(psk->addr, addr, ETH_ALEN);
414 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
423 len = os_strlen(pos);
424 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
426 else if (len >= 8 && len < 64) {
427 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
428 4096, psk->psk, PMK_LEN);
432 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
433 "'%s'", pos, line, fname);
439 psk->next = ssid->wpa_psk;
449 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
451 struct hostapd_ssid *ssid = &conf->ssid;
453 if (ssid->wpa_passphrase != NULL) {
454 if (ssid->wpa_psk != NULL) {
455 wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
456 "passphrase set. Using passphrase.");
457 os_free(ssid->wpa_psk);
459 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
460 if (ssid->wpa_psk == NULL) {
461 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
464 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
465 (u8 *) ssid->ssid, ssid->ssid_len);
466 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
467 (u8 *) ssid->wpa_passphrase,
468 os_strlen(ssid->wpa_passphrase));
469 pbkdf2_sha1(ssid->wpa_passphrase,
470 ssid->ssid, ssid->ssid_len,
471 4096, ssid->wpa_psk->psk, PMK_LEN);
472 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
473 ssid->wpa_psk->psk, PMK_LEN);
474 ssid->wpa_psk->group = 1;
477 if (ssid->wpa_psk_file) {
478 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
488 static int hostapd_config_read_eap_user(const char *fname,
489 struct hostapd_bss_config *conf)
492 char buf[512], *pos, *start, *pos2;
493 int line = 0, ret = 0, num_methods;
494 struct hostapd_eap_user *user, *tail = NULL;
499 f = fopen(fname, "r");
501 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
505 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
506 while (fgets(buf, sizeof(buf), f)) {
512 while (*pos != '\0') {
524 if (buf[0] != '"' && buf[0] != '*') {
525 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
526 "start) on line %d in '%s'", line, fname);
530 user = os_zalloc(sizeof(*user));
532 wpa_printf(MSG_ERROR, "EAP user allocation failed");
535 user->force_version = -1;
542 while (*pos != '"' && *pos != '\0')
545 wpa_printf(MSG_ERROR, "Invalid EAP identity "
546 "(no \" in end) on line %d in '%s'",
551 user->identity = os_malloc(pos - start);
552 if (user->identity == NULL) {
553 wpa_printf(MSG_ERROR, "Failed to allocate "
554 "memory for EAP identity");
557 os_memcpy(user->identity, start, pos - start);
558 user->identity_len = pos - start;
560 if (pos[0] == '"' && pos[1] == '*') {
561 user->wildcard_prefix = 1;
566 while (*pos == ' ' || *pos == '\t')
570 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
571 "'%s'", line, fname);
576 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
586 char *pos3 = os_strchr(start, ',');
590 user->methods[num_methods].method =
593 &user->methods[num_methods].vendor);
594 if (user->methods[num_methods].vendor ==
596 user->methods[num_methods].method == EAP_TYPE_NONE)
598 if (os_strcmp(start, "TTLS-PAP") == 0) {
599 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
602 if (os_strcmp(start, "TTLS-CHAP") == 0) {
603 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
606 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
608 EAP_TTLS_AUTH_MSCHAP;
611 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
613 EAP_TTLS_AUTH_MSCHAPV2;
616 wpa_printf(MSG_ERROR, "Unsupported EAP type "
617 "'%s' on line %d in '%s'",
623 if (num_methods >= EAP_USER_MAX_METHODS)
630 if (num_methods == 0 && user->ttls_auth == 0) {
631 wpa_printf(MSG_ERROR, "No EAP types configured on "
632 "line %d in '%s'", line, fname);
639 while (*pos == ' ' || *pos == '\t')
644 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
645 user->force_version = 0;
649 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
650 user->force_version = 1;
654 if (os_strncmp(pos, "[2]", 3) == 0) {
662 while (*pos != '"' && *pos != '\0')
665 wpa_printf(MSG_ERROR, "Invalid EAP password "
666 "(no \" in end) on line %d in '%s'",
671 user->password = os_malloc(pos - start);
672 if (user->password == NULL) {
673 wpa_printf(MSG_ERROR, "Failed to allocate "
674 "memory for EAP password");
677 os_memcpy(user->password, start, pos - start);
678 user->password_len = pos - start;
681 } else if (os_strncmp(pos, "hash:", 5) == 0) {
684 while (*pos2 != '\0' && *pos2 != ' ' &&
685 *pos2 != '\t' && *pos2 != '#')
687 if (pos2 - pos != 32) {
688 wpa_printf(MSG_ERROR, "Invalid password hash "
689 "on line %d in '%s'", line, fname);
692 user->password = os_malloc(16);
693 if (user->password == NULL) {
694 wpa_printf(MSG_ERROR, "Failed to allocate "
695 "memory for EAP password hash");
698 if (hexstr2bin(pos, user->password, 16) < 0) {
699 wpa_printf(MSG_ERROR, "Invalid hash password "
700 "on line %d in '%s'", line, fname);
703 user->password_len = 16;
704 user->password_hash = 1;
708 while (*pos2 != '\0' && *pos2 != ' ' &&
709 *pos2 != '\t' && *pos2 != '#')
711 if ((pos2 - pos) & 1) {
712 wpa_printf(MSG_ERROR, "Invalid hex password "
713 "on line %d in '%s'", line, fname);
716 user->password = os_malloc((pos2 - pos) / 2);
717 if (user->password == NULL) {
718 wpa_printf(MSG_ERROR, "Failed to allocate "
719 "memory for EAP password");
722 if (hexstr2bin(pos, user->password,
723 (pos2 - pos) / 2) < 0) {
724 wpa_printf(MSG_ERROR, "Invalid hex password "
725 "on line %d in '%s'", line, fname);
728 user->password_len = (pos2 - pos) / 2;
732 while (*pos == ' ' || *pos == '\t')
734 if (os_strncmp(pos, "[2]", 3) == 0) {
740 tail = conf->eap_user = user;
749 os_free(user->password);
750 os_free(user->identity);
761 #endif /* EAP_SERVER */
765 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
766 int *num_server, const char *val, int def_port,
767 struct hostapd_radius_server **curr_serv)
769 struct hostapd_radius_server *nserv;
771 static int server_index = 1;
773 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
778 nserv = &nserv[*num_server];
780 (*curr_serv) = nserv;
782 os_memset(nserv, 0, sizeof(*nserv));
783 nserv->port = def_port;
784 ret = hostapd_parse_ip_addr(val, &nserv->addr);
785 nserv->index = server_index++;
791 static int hostapd_config_parse_key_mgmt(int line, const char *value)
794 char *start, *end, *buf;
796 buf = os_strdup(value);
801 while (*start != '\0') {
802 while (*start == ' ' || *start == '\t')
807 while (*end != ' ' && *end != '\t' && *end != '\0')
811 if (os_strcmp(start, "WPA-PSK") == 0)
812 val |= WPA_KEY_MGMT_PSK;
813 else if (os_strcmp(start, "WPA-EAP") == 0)
814 val |= WPA_KEY_MGMT_IEEE8021X;
815 #ifdef CONFIG_IEEE80211R
816 else if (os_strcmp(start, "FT-PSK") == 0)
817 val |= WPA_KEY_MGMT_FT_PSK;
818 else if (os_strcmp(start, "FT-EAP") == 0)
819 val |= WPA_KEY_MGMT_FT_IEEE8021X;
820 #endif /* CONFIG_IEEE80211R */
821 #ifdef CONFIG_IEEE80211W
822 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
823 val |= WPA_KEY_MGMT_PSK_SHA256;
824 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
825 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
826 #endif /* CONFIG_IEEE80211W */
828 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
841 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
842 "configured.", line);
850 static int hostapd_config_parse_cipher(int line, const char *value)
853 char *start, *end, *buf;
855 buf = os_strdup(value);
860 while (*start != '\0') {
861 while (*start == ' ' || *start == '\t')
866 while (*end != ' ' && *end != '\t' && *end != '\0')
870 if (os_strcmp(start, "CCMP") == 0)
871 val |= WPA_CIPHER_CCMP;
872 else if (os_strcmp(start, "TKIP") == 0)
873 val |= WPA_CIPHER_TKIP;
874 else if (os_strcmp(start, "WEP104") == 0)
875 val |= WPA_CIPHER_WEP104;
876 else if (os_strcmp(start, "WEP40") == 0)
877 val |= WPA_CIPHER_WEP40;
878 else if (os_strcmp(start, "NONE") == 0)
879 val |= WPA_CIPHER_NONE;
881 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
894 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
902 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
903 struct hostapd_config *conf)
905 if (bss->ieee802_1x && !bss->eap_server &&
906 !bss->radius->auth_servers) {
907 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
908 "EAP authenticator configured).");
912 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
913 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
914 bss->ssid.wpa_psk_file == NULL) {
915 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
916 "is not configured.");
920 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
923 for (i = 0; i < conf->num_bss; i++) {
924 if ((&conf->bss[i] != bss) &&
925 (hostapd_mac_comp(conf->bss[i].bssid,
927 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
928 " on interface '%s' and '%s'.",
930 conf->bss[i].iface, bss->iface);
936 #ifdef CONFIG_IEEE80211R
937 if ((bss->wpa_key_mgmt &
938 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
939 (bss->nas_identifier == NULL ||
940 os_strlen(bss->nas_identifier) < 1 ||
941 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
942 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
943 "nas_identifier to be configured as a 1..48 octet "
947 #endif /* CONFIG_IEEE80211R */
949 #ifdef CONFIG_IEEE80211N
950 if (conf->ieee80211n && bss->wpa &&
951 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
952 !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
953 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
954 "requires CCMP to be enabled");
957 #endif /* CONFIG_IEEE80211N */
963 static int hostapd_config_check(struct hostapd_config *conf)
967 if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
968 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
969 "setting the country_code");
973 for (i = 0; i < conf->num_bss; i++) {
974 if (hostapd_config_check_bss(&conf->bss[i], conf))
982 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
985 size_t len = os_strlen(val);
987 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
991 if (len < 2 || val[len - 1] != '"')
994 wep->key[keyidx] = os_malloc(len);
995 if (wep->key[keyidx] == NULL)
997 os_memcpy(wep->key[keyidx], val + 1, len);
998 wep->len[keyidx] = len;
1003 wep->key[keyidx] = os_malloc(len);
1004 if (wep->key[keyidx] == NULL)
1006 wep->len[keyidx] = len;
1007 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1017 static int hostapd_parse_rates(int **rate_list, char *val)
1023 os_free(*rate_list);
1028 while (*pos != '\0') {
1034 list = os_malloc(sizeof(int) * (count + 2));
1039 while (*pos != '\0') {
1040 end = os_strchr(pos, ' ');
1044 list[count++] = atoi(pos);
1056 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1058 struct hostapd_bss_config *bss;
1060 if (*ifname == '\0')
1063 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1064 sizeof(struct hostapd_bss_config));
1066 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1072 bss = &(conf->bss[conf->num_bss]);
1073 os_memset(bss, 0, sizeof(*bss));
1074 bss->radius = os_zalloc(sizeof(*bss->radius));
1075 if (bss->radius == NULL) {
1076 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1077 "multi-BSS RADIUS data");
1082 conf->last_bss = bss;
1084 hostapd_config_defaults_bss(bss);
1085 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1086 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1092 static int valid_cw(int cw)
1094 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1095 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1100 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1101 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1102 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1103 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1104 IEEE80211_TX_QUEUE_DATA4 = 4,
1105 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1106 IEEE80211_TX_QUEUE_BEACON = 7
1109 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1114 struct hostapd_tx_queue_params *queue;
1116 /* skip 'tx_queue_' prefix */
1118 if (os_strncmp(pos, "data", 4) == 0 &&
1119 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1122 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1123 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1125 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1126 num = IEEE80211_TX_QUEUE_BEACON;
1129 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1133 queue = &conf->tx_queue[num];
1135 if (os_strcmp(pos, "aifs") == 0) {
1136 queue->aifs = atoi(val);
1137 if (queue->aifs < 0 || queue->aifs > 255) {
1138 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1142 } else if (os_strcmp(pos, "cwmin") == 0) {
1143 queue->cwmin = atoi(val);
1144 if (!valid_cw(queue->cwmin)) {
1145 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1149 } else if (os_strcmp(pos, "cwmax") == 0) {
1150 queue->cwmax = atoi(val);
1151 if (!valid_cw(queue->cwmax)) {
1152 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1156 } else if (os_strcmp(pos, "burst") == 0) {
1157 queue->burst = hostapd_config_read_int10(val);
1159 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1163 queue->configured = 1;
1169 static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
1174 struct hostapd_wmm_ac_params *ac;
1176 /* skip 'wme_ac_' or 'wmm_ac_' prefix */
1178 if (os_strncmp(pos, "be_", 3) == 0) {
1181 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1184 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1187 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1191 wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
1195 ac = &conf->wmm_ac_params[num];
1197 if (os_strcmp(pos, "aifs") == 0) {
1199 if (v < 1 || v > 255) {
1200 wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
1204 } else if (os_strcmp(pos, "cwmin") == 0) {
1206 if (v < 0 || v > 12) {
1207 wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
1211 } else if (os_strcmp(pos, "cwmax") == 0) {
1213 if (v < 0 || v > 12) {
1214 wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
1218 } else if (os_strcmp(pos, "txop_limit") == 0) {
1220 if (v < 0 || v > 0xffff) {
1221 wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
1225 } else if (os_strcmp(pos, "acm") == 0) {
1227 if (v < 0 || v > 1) {
1228 wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
1231 ac->admission_control_mandatory = v;
1233 wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
1241 #ifdef CONFIG_IEEE80211R
1242 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1244 struct ft_remote_r0kh *r0kh;
1247 r0kh = os_zalloc(sizeof(*r0kh));
1251 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1253 next = os_strchr(pos, ' ');
1256 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1257 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1263 next = os_strchr(pos, ' ');
1266 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1267 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1271 r0kh->id_len = next - pos - 1;
1272 os_memcpy(r0kh->id, pos, r0kh->id_len);
1275 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1276 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1281 r0kh->next = bss->r0kh_list;
1282 bss->r0kh_list = r0kh;
1288 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1290 struct ft_remote_r1kh *r1kh;
1293 r1kh = os_zalloc(sizeof(*r1kh));
1297 /* 02:01:02:03:04:05 02:01:02:03:04:05
1298 * 000102030405060708090a0b0c0d0e0f */
1300 next = os_strchr(pos, ' ');
1303 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1304 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1310 next = os_strchr(pos, ' ');
1313 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1314 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1320 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1321 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1326 r1kh->next = bss->r1kh_list;
1327 bss->r1kh_list = r1kh;
1331 #endif /* CONFIG_IEEE80211R */
1334 #ifdef CONFIG_IEEE80211N
1335 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1338 if (os_strstr(capab, "[LDPC]"))
1339 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1340 if (os_strstr(capab, "[HT40-]")) {
1341 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1342 conf->secondary_channel = -1;
1344 if (os_strstr(capab, "[HT40+]")) {
1345 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1346 conf->secondary_channel = 1;
1348 if (os_strstr(capab, "[SMPS-STATIC]")) {
1349 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1350 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1352 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1353 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1354 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1356 if (os_strstr(capab, "[GF]"))
1357 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1358 if (os_strstr(capab, "[SHORT-GI-20]"))
1359 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1360 if (os_strstr(capab, "[SHORT-GI-40]"))
1361 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1362 if (os_strstr(capab, "[TX-STBC]"))
1363 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1364 if (os_strstr(capab, "[RX-STBC1]")) {
1365 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1366 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1368 if (os_strstr(capab, "[RX-STBC12]")) {
1369 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1370 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1372 if (os_strstr(capab, "[RX-STBC123]")) {
1373 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1374 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1376 if (os_strstr(capab, "[DELAYED-BA]"))
1377 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1378 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1379 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1380 if (os_strstr(capab, "[DSSS_CCK-40]"))
1381 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1382 if (os_strstr(capab, "[PSMP]"))
1383 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1384 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1385 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1389 #endif /* CONFIG_IEEE80211N */
1393 * hostapd_config_read - Read and parse a configuration file
1394 * @fname: Configuration file name (including path, if needed)
1395 * Returns: Allocated configuration data structure
1397 struct hostapd_config * hostapd_config_read(const char *fname)
1399 struct hostapd_config *conf;
1400 struct hostapd_bss_config *bss;
1402 char buf[256], *pos;
1408 f = fopen(fname, "r");
1410 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
1411 "for reading.", fname);
1415 conf = hostapd_config_defaults();
1420 bss = conf->last_bss = conf->bss;
1422 while (fgets(buf, sizeof(buf), f)) {
1423 bss = conf->last_bss;
1429 while (*pos != '\0') {
1439 pos = os_strchr(buf, '=');
1441 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
1449 if (os_strcmp(buf, "interface") == 0) {
1450 os_strlcpy(conf->bss[0].iface, pos,
1451 sizeof(conf->bss[0].iface));
1452 } else if (os_strcmp(buf, "bridge") == 0) {
1453 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1454 } else if (os_strcmp(buf, "driver") == 0) {
1456 /* clear to get error below if setting is invalid */
1457 conf->driver = NULL;
1458 for (j = 0; hostapd_drivers[j]; j++) {
1459 if (os_strcmp(pos, hostapd_drivers[j]->name) ==
1461 conf->driver = hostapd_drivers[j];
1465 if (conf->driver == NULL) {
1466 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1467 "unknown driver '%s'", line, pos);
1470 } else if (os_strcmp(buf, "debug") == 0) {
1471 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1472 "configuration variable is not used "
1474 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1475 bss->logger_syslog_level = atoi(pos);
1476 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1477 bss->logger_stdout_level = atoi(pos);
1478 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1479 bss->logger_syslog = atoi(pos);
1480 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1481 bss->logger_stdout = atoi(pos);
1482 } else if (os_strcmp(buf, "dump_file") == 0) {
1483 bss->dump_log_name = os_strdup(pos);
1484 } else if (os_strcmp(buf, "ssid") == 0) {
1485 bss->ssid.ssid_len = os_strlen(pos);
1486 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1487 bss->ssid.ssid_len < 1) {
1488 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1492 os_memcpy(bss->ssid.ssid, pos,
1493 bss->ssid.ssid_len);
1494 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1495 bss->ssid.ssid_set = 1;
1497 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1498 bss->macaddr_acl = atoi(pos);
1499 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1500 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1501 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1502 wpa_printf(MSG_ERROR, "Line %d: unknown "
1504 line, bss->macaddr_acl);
1506 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1507 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1508 &bss->num_accept_mac))
1510 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1511 "read accept_mac_file '%s'",
1515 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1516 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1517 &bss->num_deny_mac)) {
1518 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1519 "read deny_mac_file '%s'",
1523 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1524 bss->ap_max_inactivity = atoi(pos);
1525 } else if (os_strcmp(buf, "country_code") == 0) {
1526 os_memcpy(conf->country, pos, 2);
1527 /* FIX: make this configurable */
1528 conf->country[2] = ' ';
1529 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1530 conf->ieee80211d = atoi(pos);
1531 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1532 bss->ieee802_1x = atoi(pos);
1533 } else if (os_strcmp(buf, "eapol_version") == 0) {
1534 bss->eapol_version = atoi(pos);
1535 if (bss->eapol_version < 1 ||
1536 bss->eapol_version > 2) {
1537 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1538 "version (%d): '%s'.",
1539 line, bss->eapol_version, pos);
1542 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1543 bss->eapol_version);
1545 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1546 bss->eap_server = atoi(pos);
1547 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1548 "eap_authenticator used; this has been "
1549 "renamed to eap_server", line);
1550 } else if (os_strcmp(buf, "eap_server") == 0) {
1551 bss->eap_server = atoi(pos);
1552 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1553 if (hostapd_config_read_eap_user(pos, bss))
1555 } else if (os_strcmp(buf, "ca_cert") == 0) {
1556 os_free(bss->ca_cert);
1557 bss->ca_cert = os_strdup(pos);
1558 } else if (os_strcmp(buf, "server_cert") == 0) {
1559 os_free(bss->server_cert);
1560 bss->server_cert = os_strdup(pos);
1561 } else if (os_strcmp(buf, "private_key") == 0) {
1562 os_free(bss->private_key);
1563 bss->private_key = os_strdup(pos);
1564 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1565 os_free(bss->private_key_passwd);
1566 bss->private_key_passwd = os_strdup(pos);
1567 } else if (os_strcmp(buf, "check_crl") == 0) {
1568 bss->check_crl = atoi(pos);
1569 } else if (os_strcmp(buf, "dh_file") == 0) {
1570 os_free(bss->dh_file);
1571 bss->dh_file = os_strdup(pos);
1573 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1574 os_free(bss->pac_opaque_encr_key);
1575 bss->pac_opaque_encr_key = os_malloc(16);
1576 if (bss->pac_opaque_encr_key == NULL) {
1577 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1578 "pac_opaque_encr_key", line);
1580 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1582 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1583 "pac_opaque_encr_key", line);
1586 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1587 size_t idlen = os_strlen(pos);
1589 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1590 "eap_fast_a_id", line);
1593 os_free(bss->eap_fast_a_id);
1594 bss->eap_fast_a_id = os_malloc(idlen / 2);
1595 if (bss->eap_fast_a_id == NULL ||
1596 hexstr2bin(pos, bss->eap_fast_a_id,
1598 wpa_printf(MSG_ERROR, "Line %d: "
1600 "eap_fast_a_id", line);
1603 bss->eap_fast_a_id_len = idlen / 2;
1605 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1606 os_free(bss->eap_fast_a_id_info);
1607 bss->eap_fast_a_id_info = os_strdup(pos);
1608 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1609 bss->eap_fast_prov = atoi(pos);
1610 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1611 bss->pac_key_lifetime = atoi(pos);
1612 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1613 bss->pac_key_refresh_time = atoi(pos);
1614 #endif /* EAP_FAST */
1616 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1617 os_free(bss->eap_sim_db);
1618 bss->eap_sim_db = os_strdup(pos);
1619 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1620 bss->eap_sim_aka_result_ind = atoi(pos);
1621 #endif /* EAP_SIM */
1623 } else if (os_strcmp(buf, "tnc") == 0) {
1624 bss->tnc = atoi(pos);
1625 #endif /* EAP_TNC */
1626 #endif /* EAP_SERVER */
1627 } else if (os_strcmp(buf, "eap_message") == 0) {
1629 bss->eap_req_id_text = os_strdup(pos);
1630 if (bss->eap_req_id_text == NULL) {
1631 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1632 "allocate memory for "
1633 "eap_req_id_text", line);
1637 bss->eap_req_id_text_len =
1638 os_strlen(bss->eap_req_id_text);
1639 term = os_strstr(bss->eap_req_id_text, "\\0");
1642 os_memmove(term, term + 1,
1643 bss->eap_req_id_text_len -
1644 (term - bss->eap_req_id_text) - 1);
1645 bss->eap_req_id_text_len--;
1647 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1648 bss->default_wep_key_len = atoi(pos);
1649 if (bss->default_wep_key_len > 13) {
1650 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1651 "key len %lu (= %lu bits)", line,
1653 bss->default_wep_key_len,
1655 bss->default_wep_key_len * 8);
1658 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1659 bss->individual_wep_key_len = atoi(pos);
1660 if (bss->individual_wep_key_len < 0 ||
1661 bss->individual_wep_key_len > 13) {
1662 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1663 "key len %d (= %d bits)", line,
1664 bss->individual_wep_key_len,
1665 bss->individual_wep_key_len * 8);
1668 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1669 bss->wep_rekeying_period = atoi(pos);
1670 if (bss->wep_rekeying_period < 0) {
1671 wpa_printf(MSG_ERROR, "Line %d: invalid "
1673 line, bss->wep_rekeying_period);
1676 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1677 bss->eap_reauth_period = atoi(pos);
1678 if (bss->eap_reauth_period < 0) {
1679 wpa_printf(MSG_ERROR, "Line %d: invalid "
1681 line, bss->eap_reauth_period);
1684 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1685 bss->eapol_key_index_workaround = atoi(pos);
1687 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1688 bss->ieee802_11f = 1;
1689 os_strlcpy(bss->iapp_iface, pos,
1690 sizeof(bss->iapp_iface));
1691 #endif /* CONFIG_IAPP */
1692 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1693 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1694 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1695 "address '%s'", line, pos);
1698 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1699 bss->nas_identifier = os_strdup(pos);
1700 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1701 if (hostapd_config_read_radius_addr(
1702 &bss->radius->auth_servers,
1703 &bss->radius->num_auth_servers, pos, 1812,
1704 &bss->radius->auth_server)) {
1705 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1706 "address '%s'", line, pos);
1709 } else if (bss->radius->auth_server &&
1710 os_strcmp(buf, "auth_server_port") == 0) {
1711 bss->radius->auth_server->port = atoi(pos);
1712 } else if (bss->radius->auth_server &&
1713 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1714 int len = os_strlen(pos);
1716 /* RFC 2865, Ch. 3 */
1717 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1718 "secret is not allowed.", line);
1721 bss->radius->auth_server->shared_secret =
1722 (u8 *) os_strdup(pos);
1723 bss->radius->auth_server->shared_secret_len = len;
1724 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1725 if (hostapd_config_read_radius_addr(
1726 &bss->radius->acct_servers,
1727 &bss->radius->num_acct_servers, pos, 1813,
1728 &bss->radius->acct_server)) {
1729 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1730 "address '%s'", line, pos);
1733 } else if (bss->radius->acct_server &&
1734 os_strcmp(buf, "acct_server_port") == 0) {
1735 bss->radius->acct_server->port = atoi(pos);
1736 } else if (bss->radius->acct_server &&
1737 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1738 int len = os_strlen(pos);
1740 /* RFC 2865, Ch. 3 */
1741 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1742 "secret is not allowed.", line);
1745 bss->radius->acct_server->shared_secret =
1746 (u8 *) os_strdup(pos);
1747 bss->radius->acct_server->shared_secret_len = len;
1748 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1750 bss->radius->retry_primary_interval = atoi(pos);
1751 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1753 bss->radius->acct_interim_interval = atoi(pos);
1754 } else if (os_strcmp(buf, "auth_algs") == 0) {
1755 bss->auth_algs = atoi(pos);
1756 if (bss->auth_algs == 0) {
1757 wpa_printf(MSG_ERROR, "Line %d: no "
1758 "authentication algorithms allowed",
1762 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1763 bss->max_num_sta = atoi(pos);
1764 if (bss->max_num_sta < 0 ||
1765 bss->max_num_sta > MAX_STA_COUNT) {
1766 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1767 "max_num_sta=%d; allowed range "
1768 "0..%d", line, bss->max_num_sta,
1772 } else if (os_strcmp(buf, "wpa") == 0) {
1773 bss->wpa = atoi(pos);
1774 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1775 bss->wpa_group_rekey = atoi(pos);
1776 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1777 bss->wpa_strict_rekey = atoi(pos);
1778 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1779 bss->wpa_gmk_rekey = atoi(pos);
1780 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1781 bss->wpa_ptk_rekey = atoi(pos);
1782 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1783 int len = os_strlen(pos);
1784 if (len < 8 || len > 63) {
1785 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1786 "passphrase length %d (expected "
1787 "8..63)", line, len);
1790 os_free(bss->ssid.wpa_passphrase);
1791 bss->ssid.wpa_passphrase = os_strdup(pos);
1793 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1794 os_free(bss->ssid.wpa_psk);
1796 os_zalloc(sizeof(struct hostapd_wpa_psk));
1797 if (bss->ssid.wpa_psk == NULL)
1799 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1801 pos[PMK_LEN * 2] != '\0') {
1802 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1803 "'%s'.", line, pos);
1806 bss->ssid.wpa_psk->group = 1;
1808 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1809 os_free(bss->ssid.wpa_psk_file);
1810 bss->ssid.wpa_psk_file = os_strdup(pos);
1811 if (!bss->ssid.wpa_psk_file) {
1812 wpa_printf(MSG_ERROR, "Line %d: allocation "
1816 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1818 hostapd_config_parse_key_mgmt(line, pos);
1819 if (bss->wpa_key_mgmt == -1)
1821 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1823 hostapd_config_parse_cipher(line, pos);
1824 if (bss->wpa_pairwise == -1 ||
1825 bss->wpa_pairwise == 0)
1827 else if (bss->wpa_pairwise &
1828 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1829 WPA_CIPHER_WEP104)) {
1830 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1831 "pairwise cipher suite '%s'",
1832 bss->wpa_pairwise, pos);
1835 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1837 hostapd_config_parse_cipher(line, pos);
1838 if (bss->rsn_pairwise == -1 ||
1839 bss->rsn_pairwise == 0)
1841 else if (bss->rsn_pairwise &
1842 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1843 WPA_CIPHER_WEP104)) {
1844 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1845 "pairwise cipher suite '%s'",
1846 bss->rsn_pairwise, pos);
1849 #ifdef CONFIG_RSN_PREAUTH
1850 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1851 bss->rsn_preauth = atoi(pos);
1852 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1853 bss->rsn_preauth_interfaces = os_strdup(pos);
1854 #endif /* CONFIG_RSN_PREAUTH */
1855 #ifdef CONFIG_PEERKEY
1856 } else if (os_strcmp(buf, "peerkey") == 0) {
1857 bss->peerkey = atoi(pos);
1858 #endif /* CONFIG_PEERKEY */
1859 #ifdef CONFIG_IEEE80211R
1860 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1861 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1862 hexstr2bin(pos, bss->mobility_domain,
1863 MOBILITY_DOMAIN_ID_LEN) != 0) {
1864 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1865 "mobility_domain '%s'", line, pos);
1869 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1870 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1871 hexstr2bin(pos, bss->r1_key_holder,
1872 FT_R1KH_ID_LEN) != 0) {
1873 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1874 "r1_key_holder '%s'", line, pos);
1878 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1879 bss->r0_key_lifetime = atoi(pos);
1880 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1881 bss->reassociation_deadline = atoi(pos);
1882 } else if (os_strcmp(buf, "r0kh") == 0) {
1883 if (add_r0kh(bss, pos) < 0) {
1884 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1885 "r0kh '%s'", line, pos);
1889 } else if (os_strcmp(buf, "r1kh") == 0) {
1890 if (add_r1kh(bss, pos) < 0) {
1891 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1892 "r1kh '%s'", line, pos);
1896 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1897 bss->pmk_r1_push = atoi(pos);
1898 #endif /* CONFIG_IEEE80211R */
1899 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1900 os_free(bss->ctrl_interface);
1901 bss->ctrl_interface = os_strdup(pos);
1902 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1903 #ifndef CONFIG_NATIVE_WINDOWS
1906 const char *group = pos;
1908 grp = getgrnam(group);
1910 bss->ctrl_interface_gid = grp->gr_gid;
1911 bss->ctrl_interface_gid_set = 1;
1912 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1913 " (from group name '%s')",
1914 bss->ctrl_interface_gid, group);
1918 /* Group name not found - try to parse this as gid */
1919 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1920 if (*group == '\0' || *endp != '\0') {
1921 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1922 "'%s'", line, group);
1926 bss->ctrl_interface_gid_set = 1;
1927 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1928 bss->ctrl_interface_gid);
1929 #endif /* CONFIG_NATIVE_WINDOWS */
1930 #ifdef RADIUS_SERVER
1931 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1932 os_free(bss->radius_server_clients);
1933 bss->radius_server_clients = os_strdup(pos);
1934 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1935 bss->radius_server_auth_port = atoi(pos);
1936 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1937 bss->radius_server_ipv6 = atoi(pos);
1938 #endif /* RADIUS_SERVER */
1939 } else if (os_strcmp(buf, "test_socket") == 0) {
1940 os_free(bss->test_socket);
1941 bss->test_socket = os_strdup(pos);
1942 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1943 bss->use_pae_group_addr = atoi(pos);
1944 } else if (os_strcmp(buf, "hw_mode") == 0) {
1945 if (os_strcmp(pos, "a") == 0)
1946 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1947 else if (os_strcmp(pos, "b") == 0)
1948 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1949 else if (os_strcmp(pos, "g") == 0)
1950 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1952 wpa_printf(MSG_ERROR, "Line %d: unknown "
1953 "hw_mode '%s'", line, pos);
1956 } else if (os_strcmp(buf, "channel") == 0) {
1957 conf->channel = atoi(pos);
1958 } else if (os_strcmp(buf, "beacon_int") == 0) {
1959 int val = atoi(pos);
1960 /* MIB defines range as 1..65535, but very small values
1961 * cause problems with the current implementation.
1962 * Since it is unlikely that this small numbers are
1963 * useful in real life scenarios, do not allow beacon
1964 * period to be set below 15 TU. */
1965 if (val < 15 || val > 65535) {
1966 wpa_printf(MSG_ERROR, "Line %d: invalid "
1967 "beacon_int %d (expected "
1968 "15..65535)", line, val);
1971 conf->beacon_int = val;
1972 } else if (os_strcmp(buf, "dtim_period") == 0) {
1973 bss->dtim_period = atoi(pos);
1974 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1975 wpa_printf(MSG_ERROR, "Line %d: invalid "
1977 line, bss->dtim_period);
1980 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1981 conf->rts_threshold = atoi(pos);
1982 if (conf->rts_threshold < 0 ||
1983 conf->rts_threshold > 2347) {
1984 wpa_printf(MSG_ERROR, "Line %d: invalid "
1986 line, conf->rts_threshold);
1989 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1990 conf->fragm_threshold = atoi(pos);
1991 if (conf->fragm_threshold < 256 ||
1992 conf->fragm_threshold > 2346) {
1993 wpa_printf(MSG_ERROR, "Line %d: invalid "
1994 "fragm_threshold %d",
1995 line, conf->fragm_threshold);
1998 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1999 int val = atoi(pos);
2000 if (val != 0 && val != 1) {
2001 wpa_printf(MSG_ERROR, "Line %d: invalid "
2002 "send_probe_response %d (expected "
2003 "0 or 1)", line, val);
2005 conf->send_probe_response = val;
2006 } else if (os_strcmp(buf, "supported_rates") == 0) {
2007 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2008 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2012 } else if (os_strcmp(buf, "basic_rates") == 0) {
2013 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2014 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2018 } else if (os_strcmp(buf, "preamble") == 0) {
2020 conf->preamble = SHORT_PREAMBLE;
2022 conf->preamble = LONG_PREAMBLE;
2023 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2024 bss->ignore_broadcast_ssid = atoi(pos);
2025 } else if (os_strcmp(buf, "bridge_packets") == 0) {
2026 conf->bridge_packets = atoi(pos);
2027 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2028 bss->ssid.wep.idx = atoi(pos);
2029 if (bss->ssid.wep.idx > 3) {
2030 wpa_printf(MSG_ERROR, "Invalid "
2031 "wep_default_key index %d",
2035 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2036 os_strcmp(buf, "wep_key1") == 0 ||
2037 os_strcmp(buf, "wep_key2") == 0 ||
2038 os_strcmp(buf, "wep_key3") == 0) {
2039 if (hostapd_config_read_wep(&bss->ssid.wep,
2040 buf[7] - '0', pos)) {
2041 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2042 "key '%s'", line, buf);
2045 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2046 bss->ssid.dynamic_vlan = atoi(pos);
2047 } else if (os_strcmp(buf, "vlan_file") == 0) {
2048 if (hostapd_config_read_vlan_file(bss, pos)) {
2049 wpa_printf(MSG_ERROR, "Line %d: failed to "
2050 "read VLAN file '%s'", line, pos);
2053 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2054 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2055 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2056 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2057 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
2058 conf->passive_scan_interval = atoi(pos);
2059 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
2060 conf->passive_scan_listen = atoi(pos);
2061 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
2062 conf->passive_scan_mode = atoi(pos);
2063 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2064 conf->ap_table_max_size = atoi(pos);
2065 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2066 conf->ap_table_expiration_time = atoi(pos);
2067 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2068 if (hostapd_config_tx_queue(conf, buf, pos)) {
2069 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2070 "queue item", line);
2073 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2074 os_strcmp(buf, "wmm_enabled") == 0) {
2075 bss->wmm_enabled = atoi(pos);
2076 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2077 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2078 if (hostapd_config_wmm_ac(conf, buf, pos)) {
2079 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2083 } else if (os_strcmp(buf, "bss") == 0) {
2084 if (hostapd_config_bss(conf, pos)) {
2085 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2089 } else if (os_strcmp(buf, "bssid") == 0) {
2090 if (bss == conf->bss &&
2091 (!conf->driver || !conf->driver->init_bssid)) {
2092 wpa_printf(MSG_ERROR, "Line %d: bssid item "
2093 "not allowed for the default "
2094 "interface and this driver", line);
2096 } else if (hwaddr_aton(pos, bss->bssid)) {
2097 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2101 #ifdef CONFIG_IEEE80211W
2102 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2103 bss->ieee80211w = atoi(pos);
2104 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2105 bss->assoc_sa_query_max_timeout = atoi(pos);
2106 if (bss->assoc_sa_query_max_timeout == 0) {
2107 wpa_printf(MSG_ERROR, "Line %d: invalid "
2108 "assoc_sa_query_max_timeout", line);
2111 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2113 bss->assoc_sa_query_retry_timeout = atoi(pos);
2114 if (bss->assoc_sa_query_retry_timeout == 0) {
2115 wpa_printf(MSG_ERROR, "Line %d: invalid "
2116 "assoc_sa_query_retry_timeout",
2120 #endif /* CONFIG_IEEE80211W */
2121 #ifdef CONFIG_IEEE80211N
2122 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2123 conf->ieee80211n = atoi(pos);
2124 } else if (os_strcmp(buf, "ht_capab") == 0) {
2125 if (hostapd_config_ht_capab(conf, pos) < 0) {
2126 wpa_printf(MSG_ERROR, "Line %d: invalid "
2130 #endif /* CONFIG_IEEE80211N */
2131 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2132 bss->max_listen_interval = atoi(pos);
2133 } else if (os_strcmp(buf, "okc") == 0) {
2134 bss->okc = atoi(pos);
2136 } else if (os_strcmp(buf, "wps_state") == 0) {
2137 bss->wps_state = atoi(pos);
2138 if (bss->wps_state < 0 || bss->wps_state > 2) {
2139 wpa_printf(MSG_ERROR, "Line %d: invalid "
2143 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2144 bss->ap_setup_locked = atoi(pos);
2145 } else if (os_strcmp(buf, "uuid") == 0) {
2146 if (uuid_str2bin(pos, bss->uuid)) {
2147 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2151 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2152 os_free(bss->wps_pin_requests);
2153 bss->wps_pin_requests = os_strdup(pos);
2154 } else if (os_strcmp(buf, "device_name") == 0) {
2155 if (os_strlen(pos) > 32) {
2156 wpa_printf(MSG_ERROR, "Line %d: Too long "
2157 "device_name", line);
2160 os_free(bss->device_name);
2161 bss->device_name = os_strdup(pos);
2162 } else if (os_strcmp(buf, "manufacturer") == 0) {
2163 if (os_strlen(pos) > 64) {
2164 wpa_printf(MSG_ERROR, "Line %d: Too long "
2165 "manufacturer", line);
2168 os_free(bss->manufacturer);
2169 bss->manufacturer = os_strdup(pos);
2170 } else if (os_strcmp(buf, "model_name") == 0) {
2171 if (os_strlen(pos) > 32) {
2172 wpa_printf(MSG_ERROR, "Line %d: Too long "
2173 "model_name", line);
2176 os_free(bss->model_name);
2177 bss->model_name = os_strdup(pos);
2178 } else if (os_strcmp(buf, "model_number") == 0) {
2179 if (os_strlen(pos) > 32) {
2180 wpa_printf(MSG_ERROR, "Line %d: Too long "
2181 "model_number", line);
2184 os_free(bss->model_number);
2185 bss->model_number = os_strdup(pos);
2186 } else if (os_strcmp(buf, "serial_number") == 0) {
2187 if (os_strlen(pos) > 32) {
2188 wpa_printf(MSG_ERROR, "Line %d: Too long "
2189 "serial_number", line);
2192 os_free(bss->serial_number);
2193 bss->serial_number = os_strdup(pos);
2194 } else if (os_strcmp(buf, "device_type") == 0) {
2195 os_free(bss->device_type);
2196 bss->device_type = os_strdup(pos);
2197 } else if (os_strcmp(buf, "config_methods") == 0) {
2198 os_free(bss->config_methods);
2199 bss->config_methods = os_strdup(pos);
2200 } else if (os_strcmp(buf, "os_version") == 0) {
2201 if (hexstr2bin(pos, bss->os_version, 4)) {
2202 wpa_printf(MSG_ERROR, "Line %d: invalid "
2203 "os_version", line);
2206 } else if (os_strcmp(buf, "ap_pin") == 0) {
2207 os_free(bss->ap_pin);
2208 bss->ap_pin = os_strdup(pos);
2209 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2210 bss->skip_cred_build = atoi(pos);
2211 } else if (os_strcmp(buf, "extra_cred") == 0) {
2212 os_free(bss->extra_cred);
2214 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2215 if (bss->extra_cred == NULL) {
2216 wpa_printf(MSG_ERROR, "Line %d: could not "
2217 "read Credentials from '%s'",
2221 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2222 bss->wps_cred_processing = atoi(pos);
2223 } else if (os_strcmp(buf, "ap_settings") == 0) {
2224 os_free(bss->ap_settings);
2226 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2227 if (bss->ap_settings == NULL) {
2228 wpa_printf(MSG_ERROR, "Line %d: could not "
2229 "read AP Settings from '%s'",
2233 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2234 bss->upnp_iface = os_strdup(pos);
2235 } else if (os_strcmp(buf, "friendly_name") == 0) {
2236 os_free(bss->friendly_name);
2237 bss->friendly_name = os_strdup(pos);
2238 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2239 os_free(bss->manufacturer_url);
2240 bss->manufacturer_url = os_strdup(pos);
2241 } else if (os_strcmp(buf, "model_description") == 0) {
2242 os_free(bss->model_description);
2243 bss->model_description = os_strdup(pos);
2244 } else if (os_strcmp(buf, "model_url") == 0) {
2245 os_free(bss->model_url);
2246 bss->model_url = os_strdup(pos);
2247 } else if (os_strcmp(buf, "upc") == 0) {
2249 bss->upc = os_strdup(pos);
2250 #endif /* CONFIG_WPS */
2252 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2253 "item '%s'", line, buf);
2260 for (i = 0; i < conf->num_bss; i++) {
2261 bss = &conf->bss[i];
2263 if (bss->individual_wep_key_len == 0) {
2264 /* individual keys are not use; can use key idx0 for
2266 bss->broadcast_key_idx_min = 0;
2269 /* Select group cipher based on the enabled pairwise cipher
2273 pairwise |= bss->wpa_pairwise;
2275 if (bss->rsn_pairwise == 0)
2276 bss->rsn_pairwise = bss->wpa_pairwise;
2277 pairwise |= bss->rsn_pairwise;
2279 if (pairwise & WPA_CIPHER_TKIP)
2280 bss->wpa_group = WPA_CIPHER_TKIP;
2282 bss->wpa_group = WPA_CIPHER_CCMP;
2284 bss->radius->auth_server = bss->radius->auth_servers;
2285 bss->radius->acct_server = bss->radius->acct_servers;
2287 if (bss->wpa && bss->ieee802_1x) {
2288 bss->ssid.security_policy = SECURITY_WPA;
2289 } else if (bss->wpa) {
2290 bss->ssid.security_policy = SECURITY_WPA_PSK;
2291 } else if (bss->ieee802_1x) {
2292 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2293 bss->ssid.wep.default_len = bss->default_wep_key_len;
2294 } else if (bss->ssid.wep.keys_set)
2295 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2297 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2300 if (hostapd_config_check(conf))
2304 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2305 "'%s'", errors, fname);
2306 hostapd_config_free(conf);
2314 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2318 if (a->idx != b->idx || a->default_len != b->default_len)
2320 for (i = 0; i < NUM_WEP_KEYS; i++)
2321 if (a->len[i] != b->len[i] ||
2322 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2328 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2333 for (i = 0; i < num_servers; i++) {
2334 os_free(servers[i].shared_secret);
2340 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2342 os_free(user->identity);
2343 os_free(user->password);
2348 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2351 for (i = 0; i < NUM_WEP_KEYS; i++) {
2352 os_free(keys->key[i]);
2353 keys->key[i] = NULL;
2358 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2360 struct hostapd_wpa_psk *psk, *prev;
2361 struct hostapd_eap_user *user, *prev_user;
2366 psk = conf->ssid.wpa_psk;
2373 os_free(conf->ssid.wpa_passphrase);
2374 os_free(conf->ssid.wpa_psk_file);
2375 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2376 os_free(conf->ssid.vlan_tagged_interface);
2377 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2379 user = conf->eap_user;
2383 hostapd_config_free_eap_user(prev_user);
2386 os_free(conf->dump_log_name);
2387 os_free(conf->eap_req_id_text);
2388 os_free(conf->accept_mac);
2389 os_free(conf->deny_mac);
2390 os_free(conf->nas_identifier);
2391 hostapd_config_free_radius(conf->radius->auth_servers,
2392 conf->radius->num_auth_servers);
2393 hostapd_config_free_radius(conf->radius->acct_servers,
2394 conf->radius->num_acct_servers);
2395 os_free(conf->rsn_preauth_interfaces);
2396 os_free(conf->ctrl_interface);
2397 os_free(conf->ca_cert);
2398 os_free(conf->server_cert);
2399 os_free(conf->private_key);
2400 os_free(conf->private_key_passwd);
2401 os_free(conf->dh_file);
2402 os_free(conf->pac_opaque_encr_key);
2403 os_free(conf->eap_fast_a_id);
2404 os_free(conf->eap_fast_a_id_info);
2405 os_free(conf->eap_sim_db);
2406 os_free(conf->radius_server_clients);
2407 os_free(conf->test_socket);
2408 os_free(conf->radius);
2409 hostapd_config_free_vlan(conf);
2410 if (conf->ssid.dyn_vlan_keys) {
2411 struct hostapd_ssid *ssid = &conf->ssid;
2413 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2414 if (ssid->dyn_vlan_keys[i] == NULL)
2416 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2417 os_free(ssid->dyn_vlan_keys[i]);
2419 os_free(ssid->dyn_vlan_keys);
2420 ssid->dyn_vlan_keys = NULL;
2423 #ifdef CONFIG_IEEE80211R
2425 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2426 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2428 r0kh = conf->r0kh_list;
2429 conf->r0kh_list = NULL;
2436 r1kh = conf->r1kh_list;
2437 conf->r1kh_list = NULL;
2444 #endif /* CONFIG_IEEE80211R */
2447 os_free(conf->wps_pin_requests);
2448 os_free(conf->device_name);
2449 os_free(conf->manufacturer);
2450 os_free(conf->model_name);
2451 os_free(conf->model_number);
2452 os_free(conf->serial_number);
2453 os_free(conf->device_type);
2454 os_free(conf->config_methods);
2455 os_free(conf->ap_pin);
2456 os_free(conf->extra_cred);
2457 os_free(conf->ap_settings);
2458 os_free(conf->upnp_iface);
2459 os_free(conf->friendly_name);
2460 os_free(conf->manufacturer_url);
2461 os_free(conf->model_description);
2462 os_free(conf->model_url);
2464 #endif /* CONFIG_WPS */
2469 * hostapd_config_free - Free hostapd configuration
2470 * @conf: Configuration data from hostapd_config_read().
2472 void hostapd_config_free(struct hostapd_config *conf)
2479 for (i = 0; i < conf->num_bss; i++)
2480 hostapd_config_free_bss(&conf->bss[i]);
2482 os_free(conf->supported_rates);
2483 os_free(conf->basic_rates);
2490 * hostapd_maclist_found - Find a MAC address from a list
2491 * @list: MAC address list
2492 * @num_entries: Number of addresses in the list
2493 * @addr: Address to search for
2494 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
2495 * Returns: 1 if address is in the list or 0 if not.
2497 * Perform a binary search for given MAC address from a pre-sorted list.
2499 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2500 const u8 *addr, int *vlan_id)
2502 int start, end, middle, res;
2505 end = num_entries - 1;
2507 while (start <= end) {
2508 middle = (start + end) / 2;
2509 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2512 *vlan_id = list[middle].vlan_id;
2525 int hostapd_rate_found(int *list, int rate)
2532 for (i = 0; list[i] >= 0; i++)
2533 if (list[i] == rate)
2540 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2542 struct hostapd_vlan *v = vlan;
2544 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2552 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2553 const u8 *addr, const u8 *prev_psk)
2555 struct hostapd_wpa_psk *psk;
2556 int next_ok = prev_psk == NULL;
2558 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2560 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2563 if (psk->psk == prev_psk)
2571 const struct hostapd_eap_user *
2572 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2573 size_t identity_len, int phase2)
2575 struct hostapd_eap_user *user = conf->eap_user;
2578 if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
2579 os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
2580 static struct hostapd_eap_user wsc_enrollee;
2581 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
2582 wsc_enrollee.methods[0].method = eap_server_get_type(
2583 "WSC", &wsc_enrollee.methods[0].vendor);
2584 return &wsc_enrollee;
2587 if (conf->wps_state && conf->ap_pin &&
2588 identity_len == WSC_ID_REGISTRAR_LEN &&
2589 os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
2590 static struct hostapd_eap_user wsc_registrar;
2591 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
2592 wsc_registrar.methods[0].method = eap_server_get_type(
2593 "WSC", &wsc_registrar.methods[0].vendor);
2594 wsc_registrar.password = (u8 *) conf->ap_pin;
2595 wsc_registrar.password_len = os_strlen(conf->ap_pin);
2596 return &wsc_registrar;
2598 #endif /* CONFIG_WPS */
2601 if (!phase2 && user->identity == NULL) {
2602 /* Wildcard match */
2606 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2607 identity_len >= user->identity_len &&
2608 os_memcmp(user->identity, identity, user->identity_len) ==
2610 /* Wildcard prefix match */
2614 if (user->phase2 == !!phase2 &&
2615 user->identity_len == identity_len &&
2616 os_memcmp(user->identity, identity, identity_len) == 0)