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 = 15, aCWmax = 1024;
205 const struct hostapd_wme_ac_params ac_bk =
206 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
207 const struct hostapd_wme_ac_params ac_be =
208 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
209 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
210 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
211 const struct hostapd_wme_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 os_memcpy(conf->country, "US ", 3);
253 for (i = 0; i < NUM_TX_QUEUES; i++)
254 conf->tx_queue[i].aifs = -1; /* use hw default */
256 conf->wme_ac_params[0] = ac_be;
257 conf->wme_ac_params[1] = ac_bk;
258 conf->wme_ac_params[2] = ac_vi;
259 conf->wme_ac_params[3] = ac_vo;
261 #ifdef CONFIG_IEEE80211N
262 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
263 #endif /* CONFIG_IEEE80211N */
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 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
453 struct hostapd_ssid *ssid = &conf->ssid;
455 if (ssid->wpa_passphrase != NULL) {
456 if (ssid->wpa_psk != NULL) {
457 wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
458 "passphrase set. Using passphrase.");
459 os_free(ssid->wpa_psk);
461 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
462 if (ssid->wpa_psk == NULL) {
463 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
466 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
467 (u8 *) ssid->ssid, ssid->ssid_len);
468 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
469 (u8 *) ssid->wpa_passphrase,
470 os_strlen(ssid->wpa_passphrase));
471 pbkdf2_sha1(ssid->wpa_passphrase,
472 ssid->ssid, ssid->ssid_len,
473 4096, ssid->wpa_psk->psk, PMK_LEN);
474 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
475 ssid->wpa_psk->psk, PMK_LEN);
476 ssid->wpa_psk->group = 1;
478 os_memset(ssid->wpa_passphrase, 0,
479 os_strlen(ssid->wpa_passphrase));
480 os_free(ssid->wpa_passphrase);
481 ssid->wpa_passphrase = NULL;
484 if (ssid->wpa_psk_file) {
485 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
495 static int hostapd_config_read_eap_user(const char *fname,
496 struct hostapd_bss_config *conf)
499 char buf[512], *pos, *start, *pos2;
500 int line = 0, ret = 0, num_methods;
501 struct hostapd_eap_user *user, *tail = NULL;
506 f = fopen(fname, "r");
508 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
512 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
513 while (fgets(buf, sizeof(buf), f)) {
519 while (*pos != '\0') {
531 if (buf[0] != '"' && buf[0] != '*') {
532 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
533 "start) on line %d in '%s'", line, fname);
537 user = os_zalloc(sizeof(*user));
539 wpa_printf(MSG_ERROR, "EAP user allocation failed");
542 user->force_version = -1;
549 while (*pos != '"' && *pos != '\0')
552 wpa_printf(MSG_ERROR, "Invalid EAP identity "
553 "(no \" in end) on line %d in '%s'",
558 user->identity = os_malloc(pos - start);
559 if (user->identity == NULL) {
560 wpa_printf(MSG_ERROR, "Failed to allocate "
561 "memory for EAP identity");
564 os_memcpy(user->identity, start, pos - start);
565 user->identity_len = pos - start;
567 if (pos[0] == '"' && pos[1] == '*') {
568 user->wildcard_prefix = 1;
573 while (*pos == ' ' || *pos == '\t')
577 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
578 "'%s'", line, fname);
583 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
593 char *pos3 = os_strchr(start, ',');
597 user->methods[num_methods].method =
600 &user->methods[num_methods].vendor);
601 if (user->methods[num_methods].vendor ==
603 user->methods[num_methods].method == EAP_TYPE_NONE)
605 if (os_strcmp(start, "TTLS-PAP") == 0) {
606 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
609 if (os_strcmp(start, "TTLS-CHAP") == 0) {
610 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
613 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
615 EAP_TTLS_AUTH_MSCHAP;
618 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
620 EAP_TTLS_AUTH_MSCHAPV2;
623 wpa_printf(MSG_ERROR, "Unsupported EAP type "
624 "'%s' on line %d in '%s'",
630 if (num_methods >= EAP_USER_MAX_METHODS)
637 if (num_methods == 0 && user->ttls_auth == 0) {
638 wpa_printf(MSG_ERROR, "No EAP types configured on "
639 "line %d in '%s'", line, fname);
646 while (*pos == ' ' || *pos == '\t')
651 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
652 user->force_version = 0;
656 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
657 user->force_version = 1;
661 if (os_strncmp(pos, "[2]", 3) == 0) {
669 while (*pos != '"' && *pos != '\0')
672 wpa_printf(MSG_ERROR, "Invalid EAP password "
673 "(no \" in end) on line %d in '%s'",
678 user->password = os_malloc(pos - start);
679 if (user->password == NULL) {
680 wpa_printf(MSG_ERROR, "Failed to allocate "
681 "memory for EAP password");
684 os_memcpy(user->password, start, pos - start);
685 user->password_len = pos - start;
688 } else if (os_strncmp(pos, "hash:", 5) == 0) {
691 while (*pos2 != '\0' && *pos2 != ' ' &&
692 *pos2 != '\t' && *pos2 != '#')
694 if (pos2 - pos != 32) {
695 wpa_printf(MSG_ERROR, "Invalid password hash "
696 "on line %d in '%s'", line, fname);
699 user->password = os_malloc(16);
700 if (user->password == NULL) {
701 wpa_printf(MSG_ERROR, "Failed to allocate "
702 "memory for EAP password hash");
705 if (hexstr2bin(pos, user->password, 16) < 0) {
706 wpa_printf(MSG_ERROR, "Invalid hash password "
707 "on line %d in '%s'", line, fname);
710 user->password_len = 16;
711 user->password_hash = 1;
715 while (*pos2 != '\0' && *pos2 != ' ' &&
716 *pos2 != '\t' && *pos2 != '#')
718 if ((pos2 - pos) & 1) {
719 wpa_printf(MSG_ERROR, "Invalid hex password "
720 "on line %d in '%s'", line, fname);
723 user->password = os_malloc((pos2 - pos) / 2);
724 if (user->password == NULL) {
725 wpa_printf(MSG_ERROR, "Failed to allocate "
726 "memory for EAP password");
729 if (hexstr2bin(pos, user->password,
730 (pos2 - pos) / 2) < 0) {
731 wpa_printf(MSG_ERROR, "Invalid hex password "
732 "on line %d in '%s'", line, fname);
735 user->password_len = (pos2 - pos) / 2;
739 while (*pos == ' ' || *pos == '\t')
741 if (os_strncmp(pos, "[2]", 3) == 0) {
747 tail = conf->eap_user = user;
756 os_free(user->password);
757 os_free(user->identity);
768 #endif /* EAP_SERVER */
771 #ifndef CONFIG_NO_RADIUS
773 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
774 int *num_server, const char *val, int def_port,
775 struct hostapd_radius_server **curr_serv)
777 struct hostapd_radius_server *nserv;
779 static int server_index = 1;
781 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
786 nserv = &nserv[*num_server];
788 (*curr_serv) = nserv;
790 os_memset(nserv, 0, sizeof(*nserv));
791 nserv->port = def_port;
792 ret = hostapd_parse_ip_addr(val, &nserv->addr);
793 nserv->index = server_index++;
797 #endif /* CONFIG_NO_RADIUS */
800 static int hostapd_config_parse_key_mgmt(int line, const char *value)
803 char *start, *end, *buf;
805 buf = os_strdup(value);
810 while (*start != '\0') {
811 while (*start == ' ' || *start == '\t')
816 while (*end != ' ' && *end != '\t' && *end != '\0')
820 if (os_strcmp(start, "WPA-PSK") == 0)
821 val |= WPA_KEY_MGMT_PSK;
822 else if (os_strcmp(start, "WPA-EAP") == 0)
823 val |= WPA_KEY_MGMT_IEEE8021X;
824 #ifdef CONFIG_IEEE80211R
825 else if (os_strcmp(start, "FT-PSK") == 0)
826 val |= WPA_KEY_MGMT_FT_PSK;
827 else if (os_strcmp(start, "FT-EAP") == 0)
828 val |= WPA_KEY_MGMT_FT_IEEE8021X;
829 #endif /* CONFIG_IEEE80211R */
830 #ifdef CONFIG_IEEE80211W
831 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
832 val |= WPA_KEY_MGMT_PSK_SHA256;
833 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
834 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
835 #endif /* CONFIG_IEEE80211W */
837 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
850 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
851 "configured.", line);
859 static int hostapd_config_parse_cipher(int line, const char *value)
862 char *start, *end, *buf;
864 buf = os_strdup(value);
869 while (*start != '\0') {
870 while (*start == ' ' || *start == '\t')
875 while (*end != ' ' && *end != '\t' && *end != '\0')
879 if (os_strcmp(start, "CCMP") == 0)
880 val |= WPA_CIPHER_CCMP;
881 else if (os_strcmp(start, "TKIP") == 0)
882 val |= WPA_CIPHER_TKIP;
883 else if (os_strcmp(start, "WEP104") == 0)
884 val |= WPA_CIPHER_WEP104;
885 else if (os_strcmp(start, "WEP40") == 0)
886 val |= WPA_CIPHER_WEP40;
887 else if (os_strcmp(start, "NONE") == 0)
888 val |= WPA_CIPHER_NONE;
890 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
903 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
911 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
912 struct hostapd_config *conf)
914 if (bss->ieee802_1x && !bss->eap_server &&
915 !bss->radius->auth_servers) {
916 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
917 "EAP authenticator configured).");
921 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
922 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
923 bss->ssid.wpa_psk_file == NULL) {
924 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
925 "is not configured.");
929 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
932 for (i = 0; i < conf->num_bss; i++) {
933 if ((&conf->bss[i] != bss) &&
934 (hostapd_mac_comp(conf->bss[i].bssid,
936 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
937 " on interface '%s' and '%s'.",
939 conf->bss[i].iface, bss->iface);
945 #ifdef CONFIG_IEEE80211R
946 if ((bss->wpa_key_mgmt &
947 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
948 (bss->nas_identifier == NULL ||
949 os_strlen(bss->nas_identifier) < 1 ||
950 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
951 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
952 "nas_identifier to be configured as a 1..48 octet "
956 #endif /* CONFIG_IEEE80211R */
958 #ifdef CONFIG_IEEE80211N
959 if (conf->ieee80211n && bss->wpa &&
960 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
961 !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
962 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
963 "requires CCMP to be enabled");
966 #endif /* CONFIG_IEEE80211N */
972 static int hostapd_config_check(struct hostapd_config *conf)
976 for (i = 0; i < conf->num_bss; i++) {
977 if (hostapd_config_check_bss(&conf->bss[i], conf))
985 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
988 size_t len = os_strlen(val);
990 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
994 if (len < 2 || val[len - 1] != '"')
997 wep->key[keyidx] = os_malloc(len);
998 if (wep->key[keyidx] == NULL)
1000 os_memcpy(wep->key[keyidx], val + 1, len);
1001 wep->len[keyidx] = len;
1006 wep->key[keyidx] = os_malloc(len);
1007 if (wep->key[keyidx] == NULL)
1009 wep->len[keyidx] = len;
1010 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1020 static int hostapd_parse_rates(int **rate_list, char *val)
1026 os_free(*rate_list);
1031 while (*pos != '\0') {
1037 list = os_malloc(sizeof(int) * (count + 2));
1042 while (*pos != '\0') {
1043 end = os_strchr(pos, ' ');
1047 list[count++] = atoi(pos);
1059 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1061 struct hostapd_bss_config *bss;
1063 if (*ifname == '\0')
1066 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1067 sizeof(struct hostapd_bss_config));
1069 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1075 bss = &(conf->bss[conf->num_bss]);
1076 os_memset(bss, 0, sizeof(*bss));
1077 bss->radius = os_zalloc(sizeof(*bss->radius));
1078 if (bss->radius == NULL) {
1079 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1080 "multi-BSS RADIUS data");
1085 conf->last_bss = bss;
1087 hostapd_config_defaults_bss(bss);
1088 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1089 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1095 static int valid_cw(int cw)
1097 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1098 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1103 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1104 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1105 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1106 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1107 IEEE80211_TX_QUEUE_DATA4 = 4,
1108 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1109 IEEE80211_TX_QUEUE_BEACON = 7
1112 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1117 struct hostapd_tx_queue_params *queue;
1119 /* skip 'tx_queue_' prefix */
1121 if (os_strncmp(pos, "data", 4) == 0 &&
1122 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1125 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1126 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1128 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1129 num = IEEE80211_TX_QUEUE_BEACON;
1132 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1136 queue = &conf->tx_queue[num];
1138 if (os_strcmp(pos, "aifs") == 0) {
1139 queue->aifs = atoi(val);
1140 if (queue->aifs < 0 || queue->aifs > 255) {
1141 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1145 } else if (os_strcmp(pos, "cwmin") == 0) {
1146 queue->cwmin = atoi(val);
1147 if (!valid_cw(queue->cwmin)) {
1148 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1152 } else if (os_strcmp(pos, "cwmax") == 0) {
1153 queue->cwmax = atoi(val);
1154 if (!valid_cw(queue->cwmax)) {
1155 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1159 } else if (os_strcmp(pos, "burst") == 0) {
1160 queue->burst = hostapd_config_read_int10(val);
1162 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1166 queue->configured = 1;
1172 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1177 struct hostapd_wme_ac_params *ac;
1179 /* skip 'wme_ac_' prefix */
1181 if (os_strncmp(pos, "be_", 3) == 0) {
1184 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1187 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1190 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1194 wpa_printf(MSG_ERROR, "Unknown wme name '%s'", pos);
1198 ac = &conf->wme_ac_params[num];
1200 if (os_strcmp(pos, "aifs") == 0) {
1202 if (v < 1 || v > 255) {
1203 wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
1207 } else if (os_strcmp(pos, "cwmin") == 0) {
1209 if (v < 0 || v > 12) {
1210 wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
1214 } else if (os_strcmp(pos, "cwmax") == 0) {
1216 if (v < 0 || v > 12) {
1217 wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
1221 } else if (os_strcmp(pos, "txop_limit") == 0) {
1223 if (v < 0 || v > 0xffff) {
1224 wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
1228 } else if (os_strcmp(pos, "acm") == 0) {
1230 if (v < 0 || v > 1) {
1231 wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
1234 ac->admission_control_mandatory = v;
1236 wpa_printf(MSG_ERROR, "Unknown wme_ac_ field '%s'", pos);
1244 #ifdef CONFIG_IEEE80211R
1245 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1247 struct ft_remote_r0kh *r0kh;
1250 r0kh = os_zalloc(sizeof(*r0kh));
1254 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1256 next = os_strchr(pos, ' ');
1259 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1260 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1266 next = os_strchr(pos, ' ');
1269 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1270 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1274 r0kh->id_len = next - pos - 1;
1275 os_memcpy(r0kh->id, pos, r0kh->id_len);
1278 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1279 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1284 r0kh->next = bss->r0kh_list;
1285 bss->r0kh_list = r0kh;
1291 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1293 struct ft_remote_r1kh *r1kh;
1296 r1kh = os_zalloc(sizeof(*r1kh));
1300 /* 02:01:02:03:04:05 02:01:02:03:04:05
1301 * 000102030405060708090a0b0c0d0e0f */
1303 next = os_strchr(pos, ' ');
1306 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1307 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1313 next = os_strchr(pos, ' ');
1316 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1317 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1323 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1324 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1329 r1kh->next = bss->r1kh_list;
1330 bss->r1kh_list = r1kh;
1334 #endif /* CONFIG_IEEE80211R */
1337 #ifdef CONFIG_IEEE80211N
1338 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1341 if (os_strstr(capab, "[LDPC]"))
1342 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1343 if (os_strstr(capab, "[HT40-]")) {
1344 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1345 conf->secondary_channel = -1;
1347 if (os_strstr(capab, "[HT40+]")) {
1348 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1349 conf->secondary_channel = 1;
1351 if (os_strstr(capab, "[SMPS-STATIC]")) {
1352 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1353 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1355 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1356 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1357 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1359 if (os_strstr(capab, "[GF]"))
1360 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1361 if (os_strstr(capab, "[SHORT-GI-20]"))
1362 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1363 if (os_strstr(capab, "[SHORT-GI-40]"))
1364 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1365 if (os_strstr(capab, "[TX-STBC]"))
1366 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1367 if (os_strstr(capab, "[RX-STBC1]")) {
1368 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1369 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1371 if (os_strstr(capab, "[RX-STBC12]")) {
1372 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1373 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1375 if (os_strstr(capab, "[RX-STBC123]")) {
1376 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1377 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1379 if (os_strstr(capab, "[DELAYED-BA]"))
1380 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1381 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1382 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1383 if (os_strstr(capab, "[DSSS_CCK-40]"))
1384 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1385 if (os_strstr(capab, "[PSMP]"))
1386 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1387 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1388 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1392 #endif /* CONFIG_IEEE80211N */
1396 * hostapd_config_read - Read and parse a configuration file
1397 * @fname: Configuration file name (including path, if needed)
1398 * Returns: Allocated configuration data structure
1400 struct hostapd_config * hostapd_config_read(const char *fname)
1402 struct hostapd_config *conf;
1403 struct hostapd_bss_config *bss;
1405 char buf[256], *pos;
1411 f = fopen(fname, "r");
1413 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
1414 "for reading.", fname);
1418 conf = hostapd_config_defaults();
1423 bss = conf->last_bss = conf->bss;
1425 while (fgets(buf, sizeof(buf), f)) {
1426 bss = conf->last_bss;
1432 while (*pos != '\0') {
1442 pos = os_strchr(buf, '=');
1444 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
1452 if (os_strcmp(buf, "interface") == 0) {
1453 os_strlcpy(conf->bss[0].iface, pos,
1454 sizeof(conf->bss[0].iface));
1455 } else if (os_strcmp(buf, "bridge") == 0) {
1456 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1457 } else if (os_strcmp(buf, "driver") == 0) {
1459 /* clear to get error below if setting is invalid */
1460 conf->driver = NULL;
1461 for (i = 0; hostapd_drivers[i]; i++) {
1462 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1464 conf->driver = hostapd_drivers[i];
1468 if (conf->driver == NULL) {
1469 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1470 "unknown driver '%s'", line, pos);
1473 } else if (os_strcmp(buf, "debug") == 0) {
1474 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1475 "configuration variable is not used "
1477 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1478 bss->logger_syslog_level = atoi(pos);
1479 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1480 bss->logger_stdout_level = atoi(pos);
1481 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1482 bss->logger_syslog = atoi(pos);
1483 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1484 bss->logger_stdout = atoi(pos);
1485 } else if (os_strcmp(buf, "dump_file") == 0) {
1486 bss->dump_log_name = os_strdup(pos);
1487 } else if (os_strcmp(buf, "ssid") == 0) {
1488 bss->ssid.ssid_len = os_strlen(pos);
1489 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1490 bss->ssid.ssid_len < 1) {
1491 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1495 os_memcpy(bss->ssid.ssid, pos,
1496 bss->ssid.ssid_len);
1497 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1498 bss->ssid.ssid_set = 1;
1500 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1501 bss->macaddr_acl = atoi(pos);
1502 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1503 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1504 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1505 wpa_printf(MSG_ERROR, "Line %d: unknown "
1507 line, bss->macaddr_acl);
1509 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1510 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1511 &bss->num_accept_mac))
1513 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1514 "read accept_mac_file '%s'",
1518 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1519 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1520 &bss->num_deny_mac)) {
1521 wpa_printf(MSG_ERROR "Line %d: Failed to read "
1522 "deny_mac_file '%s'", line, pos);
1525 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1526 bss->ap_max_inactivity = atoi(pos);
1527 } else if (os_strcmp(buf, "country_code") == 0) {
1528 os_memcpy(conf->country, pos, 2);
1529 /* FIX: make this configurable */
1530 conf->country[2] = ' ';
1531 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1532 conf->ieee80211d = atoi(pos);
1533 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1534 bss->ieee802_1x = atoi(pos);
1535 } else if (os_strcmp(buf, "eapol_version") == 0) {
1536 bss->eapol_version = atoi(pos);
1537 if (bss->eapol_version < 1 ||
1538 bss->eapol_version > 2) {
1539 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1540 "version (%d): '%s'.",
1541 line, bss->eapol_version, pos);
1544 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1545 bss->eapol_version);
1547 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1548 bss->eap_server = atoi(pos);
1549 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1550 "eap_authenticator used; this has been "
1551 "renamed to eap_server", line);
1552 } else if (os_strcmp(buf, "eap_server") == 0) {
1553 bss->eap_server = atoi(pos);
1554 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1555 if (hostapd_config_read_eap_user(pos, bss))
1557 } else if (os_strcmp(buf, "ca_cert") == 0) {
1558 os_free(bss->ca_cert);
1559 bss->ca_cert = os_strdup(pos);
1560 } else if (os_strcmp(buf, "server_cert") == 0) {
1561 os_free(bss->server_cert);
1562 bss->server_cert = os_strdup(pos);
1563 } else if (os_strcmp(buf, "private_key") == 0) {
1564 os_free(bss->private_key);
1565 bss->private_key = os_strdup(pos);
1566 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1567 os_free(bss->private_key_passwd);
1568 bss->private_key_passwd = os_strdup(pos);
1569 } else if (os_strcmp(buf, "check_crl") == 0) {
1570 bss->check_crl = atoi(pos);
1571 } else if (os_strcmp(buf, "dh_file") == 0) {
1572 os_free(bss->dh_file);
1573 bss->dh_file = os_strdup(pos);
1575 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1576 os_free(bss->pac_opaque_encr_key);
1577 bss->pac_opaque_encr_key = os_malloc(16);
1578 if (bss->pac_opaque_encr_key == NULL) {
1579 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1580 "pac_opaque_encr_key", line);
1582 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1584 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1585 "pac_opaque_encr_key", line);
1588 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1589 size_t idlen = os_strlen(pos);
1591 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1592 "eap_fast_a_id", line);
1595 os_free(bss->eap_fast_a_id);
1596 bss->eap_fast_a_id = os_malloc(idlen / 2);
1597 if (bss->eap_fast_a_id == NULL ||
1598 hexstr2bin(pos, bss->eap_fast_a_id,
1600 wpa_printf(MSG_ERROR, "Line %d: "
1602 "eap_fast_a_id", line);
1605 bss->eap_fast_a_id_len = idlen / 2;
1607 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1608 os_free(bss->eap_fast_a_id_info);
1609 bss->eap_fast_a_id_info = os_strdup(pos);
1610 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1611 bss->eap_fast_prov = atoi(pos);
1612 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1613 bss->pac_key_lifetime = atoi(pos);
1614 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1615 bss->pac_key_refresh_time = atoi(pos);
1616 #endif /* EAP_FAST */
1618 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1619 os_free(bss->eap_sim_db);
1620 bss->eap_sim_db = os_strdup(pos);
1621 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1622 bss->eap_sim_aka_result_ind = atoi(pos);
1623 #endif /* EAP_SIM */
1625 } else if (os_strcmp(buf, "tnc") == 0) {
1626 bss->tnc = atoi(pos);
1627 #endif /* EAP_TNC */
1628 #endif /* EAP_SERVER */
1629 } else if (os_strcmp(buf, "eap_message") == 0) {
1631 bss->eap_req_id_text = os_strdup(pos);
1632 if (bss->eap_req_id_text == NULL) {
1633 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1634 "allocate memory for "
1635 "eap_req_id_text", line);
1639 bss->eap_req_id_text_len =
1640 os_strlen(bss->eap_req_id_text);
1641 term = os_strstr(bss->eap_req_id_text, "\\0");
1644 os_memmove(term, term + 1,
1645 bss->eap_req_id_text_len -
1646 (term - bss->eap_req_id_text) - 1);
1647 bss->eap_req_id_text_len--;
1649 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1650 bss->default_wep_key_len = atoi(pos);
1651 if (bss->default_wep_key_len > 13) {
1652 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1653 "key len %lu (= %lu bits)", line,
1655 bss->default_wep_key_len,
1657 bss->default_wep_key_len * 8);
1660 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1661 bss->individual_wep_key_len = atoi(pos);
1662 if (bss->individual_wep_key_len < 0 ||
1663 bss->individual_wep_key_len > 13) {
1664 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1665 "key len %d (= %d bits)", line,
1666 bss->individual_wep_key_len,
1667 bss->individual_wep_key_len * 8);
1670 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1671 bss->wep_rekeying_period = atoi(pos);
1672 if (bss->wep_rekeying_period < 0) {
1673 wpa_printf(MSG_ERROR, "Line %d: invalid "
1675 line, bss->wep_rekeying_period);
1678 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1679 bss->eap_reauth_period = atoi(pos);
1680 if (bss->eap_reauth_period < 0) {
1681 wpa_printf(MSG_ERROR, "Line %d: invalid "
1683 line, bss->eap_reauth_period);
1686 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1687 bss->eapol_key_index_workaround = atoi(pos);
1689 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1690 bss->ieee802_11f = 1;
1691 os_strlcpy(bss->iapp_iface, pos,
1692 sizeof(bss->iapp_iface));
1693 #endif /* CONFIG_IAPP */
1694 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1695 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1696 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1697 "address '%s'", line, pos);
1700 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1701 bss->nas_identifier = os_strdup(pos);
1702 #ifndef CONFIG_NO_RADIUS
1703 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1704 if (hostapd_config_read_radius_addr(
1705 &bss->radius->auth_servers,
1706 &bss->radius->num_auth_servers, pos, 1812,
1707 &bss->radius->auth_server)) {
1708 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1709 "address '%s'", line, pos);
1712 } else if (bss->radius->auth_server &&
1713 os_strcmp(buf, "auth_server_port") == 0) {
1714 bss->radius->auth_server->port = atoi(pos);
1715 } else if (bss->radius->auth_server &&
1716 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1717 int len = os_strlen(pos);
1719 /* RFC 2865, Ch. 3 */
1720 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1721 "secret is not allowed.", line);
1724 bss->radius->auth_server->shared_secret =
1725 (u8 *) os_strdup(pos);
1726 bss->radius->auth_server->shared_secret_len = len;
1727 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1728 if (hostapd_config_read_radius_addr(
1729 &bss->radius->acct_servers,
1730 &bss->radius->num_acct_servers, pos, 1813,
1731 &bss->radius->acct_server)) {
1732 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1733 "address '%s'", line, pos);
1736 } else if (bss->radius->acct_server &&
1737 os_strcmp(buf, "acct_server_port") == 0) {
1738 bss->radius->acct_server->port = atoi(pos);
1739 } else if (bss->radius->acct_server &&
1740 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1741 int len = os_strlen(pos);
1743 /* RFC 2865, Ch. 3 */
1744 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1745 "secret is not allowed.", line);
1748 bss->radius->acct_server->shared_secret =
1749 (u8 *) os_strdup(pos);
1750 bss->radius->acct_server->shared_secret_len = len;
1751 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1753 bss->radius->retry_primary_interval = atoi(pos);
1754 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1756 bss->radius->acct_interim_interval = atoi(pos);
1757 #endif /* CONFIG_NO_RADIUS */
1758 } else if (os_strcmp(buf, "auth_algs") == 0) {
1759 bss->auth_algs = atoi(pos);
1760 if (bss->auth_algs == 0) {
1761 wpa_printf(MSG_ERROR, "Line %d: no "
1762 "authentication algorithms allowed",
1766 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1767 bss->max_num_sta = atoi(pos);
1768 if (bss->max_num_sta < 0 ||
1769 bss->max_num_sta > MAX_STA_COUNT) {
1770 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1771 "max_num_sta=%d; allowed range "
1772 "0..%d", line, bss->max_num_sta,
1776 } else if (os_strcmp(buf, "wpa") == 0) {
1777 bss->wpa = atoi(pos);
1778 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1779 bss->wpa_group_rekey = atoi(pos);
1780 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1781 bss->wpa_strict_rekey = atoi(pos);
1782 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1783 bss->wpa_gmk_rekey = atoi(pos);
1784 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1785 bss->wpa_ptk_rekey = atoi(pos);
1786 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1787 int len = os_strlen(pos);
1788 if (len < 8 || len > 63) {
1789 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1790 "passphrase length %d (expected "
1791 "8..63)", line, len);
1794 os_free(bss->ssid.wpa_passphrase);
1795 bss->ssid.wpa_passphrase = os_strdup(pos);
1797 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1798 os_free(bss->ssid.wpa_psk);
1800 os_zalloc(sizeof(struct hostapd_wpa_psk));
1801 if (bss->ssid.wpa_psk == NULL)
1803 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1805 pos[PMK_LEN * 2] != '\0') {
1806 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1807 "'%s'.", line, pos);
1810 bss->ssid.wpa_psk->group = 1;
1812 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1813 os_free(bss->ssid.wpa_psk_file);
1814 bss->ssid.wpa_psk_file = os_strdup(pos);
1815 if (!bss->ssid.wpa_psk_file) {
1816 wpa_printf(MSG_ERROR, "Line %d: allocation "
1820 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1822 hostapd_config_parse_key_mgmt(line, pos);
1823 if (bss->wpa_key_mgmt == -1)
1825 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1827 hostapd_config_parse_cipher(line, pos);
1828 if (bss->wpa_pairwise == -1 ||
1829 bss->wpa_pairwise == 0)
1831 else if (bss->wpa_pairwise &
1832 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1833 WPA_CIPHER_WEP104)) {
1834 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1835 "pairwise cipher suite '%s'",
1836 bss->wpa_pairwise, pos);
1839 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1841 hostapd_config_parse_cipher(line, pos);
1842 if (bss->rsn_pairwise == -1 ||
1843 bss->rsn_pairwise == 0)
1845 else if (bss->rsn_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->rsn_pairwise, pos);
1853 #ifdef CONFIG_RSN_PREAUTH
1854 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1855 bss->rsn_preauth = atoi(pos);
1856 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1857 bss->rsn_preauth_interfaces = os_strdup(pos);
1858 #endif /* CONFIG_RSN_PREAUTH */
1859 #ifdef CONFIG_PEERKEY
1860 } else if (os_strcmp(buf, "peerkey") == 0) {
1861 bss->peerkey = atoi(pos);
1862 #endif /* CONFIG_PEERKEY */
1863 #ifdef CONFIG_IEEE80211R
1864 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1865 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1866 hexstr2bin(pos, bss->mobility_domain,
1867 MOBILITY_DOMAIN_ID_LEN) != 0) {
1868 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1869 "mobility_domain '%s'", line, pos);
1873 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1874 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1875 hexstr2bin(pos, bss->r1_key_holder,
1876 FT_R1KH_ID_LEN) != 0) {
1877 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1878 "r1_key_holder '%s'", line, pos);
1882 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1883 bss->r0_key_lifetime = atoi(pos);
1884 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1885 bss->reassociation_deadline = atoi(pos);
1886 } else if (os_strcmp(buf, "r0kh") == 0) {
1887 if (add_r0kh(bss, pos) < 0) {
1888 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1889 "r0kh '%s'", line, pos);
1893 } else if (os_strcmp(buf, "r1kh") == 0) {
1894 if (add_r1kh(bss, pos) < 0) {
1895 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1896 "r1kh '%s'", line, pos);
1900 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1901 bss->pmk_r1_push = atoi(pos);
1902 #endif /* CONFIG_IEEE80211R */
1903 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1904 os_free(bss->ctrl_interface);
1905 bss->ctrl_interface = os_strdup(pos);
1906 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1907 #ifndef CONFIG_NATIVE_WINDOWS
1910 const char *group = pos;
1912 grp = getgrnam(group);
1914 bss->ctrl_interface_gid = grp->gr_gid;
1915 bss->ctrl_interface_gid_set = 1;
1916 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1917 " (from group name '%s')",
1918 bss->ctrl_interface_gid, group);
1922 /* Group name not found - try to parse this as gid */
1923 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1924 if (*group == '\0' || *endp != '\0') {
1925 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1926 "'%s'", line, group);
1930 bss->ctrl_interface_gid_set = 1;
1931 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1932 bss->ctrl_interface_gid);
1933 #endif /* CONFIG_NATIVE_WINDOWS */
1934 #ifdef RADIUS_SERVER
1935 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1936 os_free(bss->radius_server_clients);
1937 bss->radius_server_clients = os_strdup(pos);
1938 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1939 bss->radius_server_auth_port = atoi(pos);
1940 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1941 bss->radius_server_ipv6 = atoi(pos);
1942 #endif /* RADIUS_SERVER */
1943 } else if (os_strcmp(buf, "test_socket") == 0) {
1944 os_free(bss->test_socket);
1945 bss->test_socket = os_strdup(pos);
1946 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1947 bss->use_pae_group_addr = atoi(pos);
1948 } else if (os_strcmp(buf, "hw_mode") == 0) {
1949 if (os_strcmp(pos, "a") == 0)
1950 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1951 else if (os_strcmp(pos, "b") == 0)
1952 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1953 else if (os_strcmp(pos, "g") == 0)
1954 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1956 wpa_printf(MSG_ERROR, "Line %d: unknown "
1957 "hw_mode '%s'", line, pos);
1960 } else if (os_strcmp(buf, "channel") == 0) {
1961 conf->channel = atoi(pos);
1962 } else if (os_strcmp(buf, "beacon_int") == 0) {
1963 int val = atoi(pos);
1964 /* MIB defines range as 1..65535, but very small values
1965 * cause problems with the current implementation.
1966 * Since it is unlikely that this small numbers are
1967 * useful in real life scenarios, do not allow beacon
1968 * period to be set below 15 TU. */
1969 if (val < 15 || val > 65535) {
1970 wpa_printf(MSG_ERROR, "Line %d: invalid "
1971 "beacon_int %d (expected "
1972 "15..65535)", line, val);
1975 conf->beacon_int = val;
1976 } else if (os_strcmp(buf, "dtim_period") == 0) {
1977 bss->dtim_period = atoi(pos);
1978 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1979 wpa_printf(MSG_ERROR, "Line %d: invalid "
1981 line, bss->dtim_period);
1984 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1985 conf->rts_threshold = atoi(pos);
1986 if (conf->rts_threshold < 0 ||
1987 conf->rts_threshold > 2347) {
1988 wpa_printf(MSG_ERROR, "Line %d: invalid "
1990 line, conf->rts_threshold);
1993 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1994 conf->fragm_threshold = atoi(pos);
1995 if (conf->fragm_threshold < 256 ||
1996 conf->fragm_threshold > 2346) {
1997 wpa_printf(MSG_ERROR, "Line %d: invalid "
1998 "fragm_threshold %d",
1999 line, conf->fragm_threshold);
2002 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2003 int val = atoi(pos);
2004 if (val != 0 && val != 1) {
2005 wpa_printf(MSG_ERROR, "Line %d: invalid "
2006 "send_probe_response %d (expected "
2007 "0 or 1)", line, val);
2009 conf->send_probe_response = val;
2010 } else if (os_strcmp(buf, "supported_rates") == 0) {
2011 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2012 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2016 } else if (os_strcmp(buf, "basic_rates") == 0) {
2017 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2018 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2022 } else if (os_strcmp(buf, "preamble") == 0) {
2024 conf->preamble = SHORT_PREAMBLE;
2026 conf->preamble = LONG_PREAMBLE;
2027 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2028 bss->ignore_broadcast_ssid = atoi(pos);
2029 } else if (os_strcmp(buf, "bridge_packets") == 0) {
2030 conf->bridge_packets = atoi(pos);
2031 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2032 bss->ssid.wep.idx = atoi(pos);
2033 if (bss->ssid.wep.idx > 3) {
2034 wpa_printf(MSG_ERROR, "Invalid "
2035 "wep_default_key index %d",
2039 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2040 os_strcmp(buf, "wep_key1") == 0 ||
2041 os_strcmp(buf, "wep_key2") == 0 ||
2042 os_strcmp(buf, "wep_key3") == 0) {
2043 if (hostapd_config_read_wep(&bss->ssid.wep,
2044 buf[7] - '0', pos)) {
2045 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2046 "key '%s'", line, buf);
2049 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2050 bss->ssid.dynamic_vlan = atoi(pos);
2051 } else if (os_strcmp(buf, "vlan_file") == 0) {
2052 if (hostapd_config_read_vlan_file(bss, pos)) {
2053 wpa_printf(MSG_ERROR, "Line %d: failed to "
2054 "read VLAN file '%s'", line, pos);
2057 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2058 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2059 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2060 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2061 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
2062 conf->passive_scan_interval = atoi(pos);
2063 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
2064 conf->passive_scan_listen = atoi(pos);
2065 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
2066 conf->passive_scan_mode = atoi(pos);
2067 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2068 conf->ap_table_max_size = atoi(pos);
2069 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2070 conf->ap_table_expiration_time = atoi(pos);
2071 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2072 if (hostapd_config_tx_queue(conf, buf, pos)) {
2073 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2074 "queue item", line);
2077 } else if (os_strcmp(buf, "wme_enabled") == 0) {
2078 bss->wme_enabled = atoi(pos);
2079 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
2080 if (hostapd_config_wme_ac(conf, buf, pos)) {
2081 wpa_printf(MSG_ERROR, "Line %d: invalid wme "
2085 } else if (os_strcmp(buf, "bss") == 0) {
2086 if (hostapd_config_bss(conf, pos)) {
2087 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2091 } else if (os_strcmp(buf, "bssid") == 0) {
2092 if (bss == conf->bss &&
2093 (!conf->driver || !conf->driver->init_bssid)) {
2094 wpa_printf(MSG_ERROR, "Line %d: bssid item "
2095 "not allowed for the default "
2096 "interface and this driver", line);
2098 } else if (hwaddr_aton(pos, bss->bssid)) {
2099 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2103 #ifdef CONFIG_IEEE80211W
2104 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2105 bss->ieee80211w = atoi(pos);
2106 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2107 bss->assoc_sa_query_max_timeout = atoi(pos);
2108 if (bss->assoc_sa_query_max_timeout == 0) {
2109 wpa_printf(MSG_ERROR, "Line %d: invalid "
2110 "assoc_sa_query_max_timeout", line);
2113 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2115 bss->assoc_sa_query_retry_timeout = atoi(pos);
2116 if (bss->assoc_sa_query_retry_timeout == 0) {
2117 wpa_printf(MSG_ERROR, "Line %d: invalid "
2118 "assoc_sa_query_retry_timeout",
2122 #endif /* CONFIG_IEEE80211W */
2123 #ifdef CONFIG_IEEE80211N
2124 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2125 conf->ieee80211n = atoi(pos);
2126 } else if (os_strcmp(buf, "ht_capab") == 0) {
2127 if (hostapd_config_ht_capab(conf, pos) < 0) {
2128 wpa_printf(MSG_ERROR, "Line %d: invalid "
2132 #endif /* CONFIG_IEEE80211N */
2133 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2134 bss->max_listen_interval = atoi(pos);
2135 } else if (os_strcmp(buf, "okc") == 0) {
2136 bss->okc = atoi(pos);
2138 } else if (os_strcmp(buf, "wps_state") == 0) {
2139 bss->wps_state = atoi(pos);
2140 if (bss->wps_state < 0 || bss->wps_state > 2) {
2141 wpa_printf(MSG_ERROR, "Line %d: invalid "
2145 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2146 bss->ap_setup_locked = atoi(pos);
2147 } else if (os_strcmp(buf, "uuid") == 0) {
2148 if (uuid_str2bin(pos, bss->uuid)) {
2149 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2153 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2154 bss->wps_pin_requests = os_strdup(pos);
2155 } else if (os_strcmp(buf, "device_name") == 0) {
2156 if (os_strlen(pos) > 32) {
2157 wpa_printf(MSG_ERROR, "Line %d: Too long "
2158 "device_name", line);
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 bss->manufacturer = os_strdup(pos);
2169 } else if (os_strcmp(buf, "model_name") == 0) {
2170 if (os_strlen(pos) > 32) {
2171 wpa_printf(MSG_ERROR, "Line %d: Too long "
2172 "model_name", line);
2175 bss->model_name = os_strdup(pos);
2176 } else if (os_strcmp(buf, "model_number") == 0) {
2177 if (os_strlen(pos) > 32) {
2178 wpa_printf(MSG_ERROR, "Line %d: Too long "
2179 "model_number", line);
2182 bss->model_number = os_strdup(pos);
2183 } else if (os_strcmp(buf, "serial_number") == 0) {
2184 if (os_strlen(pos) > 32) {
2185 wpa_printf(MSG_ERROR, "Line %d: Too long "
2186 "serial_number", line);
2189 bss->serial_number = os_strdup(pos);
2190 } else if (os_strcmp(buf, "device_type") == 0) {
2191 bss->device_type = os_strdup(pos);
2192 } else if (os_strcmp(buf, "config_methods") == 0) {
2193 bss->config_methods = os_strdup(pos);
2194 } else if (os_strcmp(buf, "os_version") == 0) {
2195 if (hexstr2bin(pos, bss->os_version, 4)) {
2196 wpa_printf(MSG_ERROR, "Line %d: invalid "
2197 "os_version", line);
2200 } else if (os_strcmp(buf, "ap_pin") == 0) {
2201 bss->ap_pin = os_strdup(pos);
2202 #endif /* CONFIG_WPS */
2204 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2205 "item '%s'", line, buf);
2212 if (bss->individual_wep_key_len == 0) {
2213 /* individual keys are not use; can use key idx0 for broadcast
2215 bss->broadcast_key_idx_min = 0;
2218 /* Select group cipher based on the enabled pairwise cipher suites */
2221 pairwise |= bss->wpa_pairwise;
2223 if (bss->rsn_pairwise == 0)
2224 bss->rsn_pairwise = bss->wpa_pairwise;
2225 pairwise |= bss->rsn_pairwise;
2227 if (pairwise & WPA_CIPHER_TKIP)
2228 bss->wpa_group = WPA_CIPHER_TKIP;
2230 bss->wpa_group = WPA_CIPHER_CCMP;
2232 for (i = 0; i < conf->num_bss; i++) {
2233 bss = &conf->bss[i];
2235 bss->radius->auth_server = bss->radius->auth_servers;
2236 bss->radius->acct_server = bss->radius->acct_servers;
2238 if (bss->wpa && bss->ieee802_1x) {
2239 bss->ssid.security_policy = SECURITY_WPA;
2240 } else if (bss->wpa) {
2241 bss->ssid.security_policy = SECURITY_WPA_PSK;
2242 } else if (bss->ieee802_1x) {
2243 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2244 bss->ssid.wep.default_len = bss->default_wep_key_len;
2245 } else if (bss->ssid.wep.keys_set)
2246 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2248 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2251 if (hostapd_config_check(conf))
2255 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2256 "'%s'", errors, fname);
2257 hostapd_config_free(conf);
2265 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2269 if (a->idx != b->idx || a->default_len != b->default_len)
2271 for (i = 0; i < NUM_WEP_KEYS; i++)
2272 if (a->len[i] != b->len[i] ||
2273 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2279 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2284 for (i = 0; i < num_servers; i++) {
2285 os_free(servers[i].shared_secret);
2291 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2293 os_free(user->identity);
2294 os_free(user->password);
2299 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2302 for (i = 0; i < NUM_WEP_KEYS; i++) {
2303 os_free(keys->key[i]);
2304 keys->key[i] = NULL;
2309 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2311 struct hostapd_wpa_psk *psk, *prev;
2312 struct hostapd_eap_user *user, *prev_user;
2317 psk = conf->ssid.wpa_psk;
2324 os_free(conf->ssid.wpa_passphrase);
2325 os_free(conf->ssid.wpa_psk_file);
2326 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2327 os_free(conf->ssid.vlan_tagged_interface);
2328 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2330 user = conf->eap_user;
2334 hostapd_config_free_eap_user(prev_user);
2337 os_free(conf->dump_log_name);
2338 os_free(conf->eap_req_id_text);
2339 os_free(conf->accept_mac);
2340 os_free(conf->deny_mac);
2341 os_free(conf->nas_identifier);
2342 hostapd_config_free_radius(conf->radius->auth_servers,
2343 conf->radius->num_auth_servers);
2344 hostapd_config_free_radius(conf->radius->acct_servers,
2345 conf->radius->num_acct_servers);
2346 os_free(conf->rsn_preauth_interfaces);
2347 os_free(conf->ctrl_interface);
2348 os_free(conf->ca_cert);
2349 os_free(conf->server_cert);
2350 os_free(conf->private_key);
2351 os_free(conf->private_key_passwd);
2352 os_free(conf->dh_file);
2353 os_free(conf->pac_opaque_encr_key);
2354 os_free(conf->eap_fast_a_id);
2355 os_free(conf->eap_fast_a_id_info);
2356 os_free(conf->eap_sim_db);
2357 os_free(conf->radius_server_clients);
2358 os_free(conf->test_socket);
2359 os_free(conf->radius);
2360 hostapd_config_free_vlan(conf);
2361 if (conf->ssid.dyn_vlan_keys) {
2362 struct hostapd_ssid *ssid = &conf->ssid;
2364 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2365 if (ssid->dyn_vlan_keys[i] == NULL)
2367 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2368 os_free(ssid->dyn_vlan_keys[i]);
2370 os_free(ssid->dyn_vlan_keys);
2371 ssid->dyn_vlan_keys = NULL;
2374 #ifdef CONFIG_IEEE80211R
2376 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2377 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2379 r0kh = conf->r0kh_list;
2380 conf->r0kh_list = NULL;
2387 r1kh = conf->r1kh_list;
2388 conf->r1kh_list = NULL;
2395 #endif /* CONFIG_IEEE80211R */
2398 os_free(conf->wps_pin_requests);
2399 os_free(conf->device_name);
2400 os_free(conf->manufacturer);
2401 os_free(conf->model_name);
2402 os_free(conf->model_number);
2403 os_free(conf->serial_number);
2404 os_free(conf->device_type);
2405 os_free(conf->config_methods);
2406 os_free(conf->ap_pin);
2407 #endif /* CONFIG_WPS */
2412 * hostapd_config_free - Free hostapd configuration
2413 * @conf: Configuration data from hostapd_config_read().
2415 void hostapd_config_free(struct hostapd_config *conf)
2422 for (i = 0; i < conf->num_bss; i++)
2423 hostapd_config_free_bss(&conf->bss[i]);
2431 * hostapd_maclist_found - Find a MAC address from a list
2432 * @list: MAC address list
2433 * @num_entries: Number of addresses in the list
2434 * @addr: Address to search for
2435 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
2436 * Returns: 1 if address is in the list or 0 if not.
2438 * Perform a binary search for given MAC address from a pre-sorted list.
2440 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2441 const u8 *addr, int *vlan_id)
2443 int start, end, middle, res;
2446 end = num_entries - 1;
2448 while (start <= end) {
2449 middle = (start + end) / 2;
2450 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2453 *vlan_id = list[middle].vlan_id;
2466 int hostapd_rate_found(int *list, int rate)
2473 for (i = 0; list[i] >= 0; i++)
2474 if (list[i] == rate)
2481 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2483 struct hostapd_vlan *v = vlan;
2485 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2493 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2494 const u8 *addr, const u8 *prev_psk)
2496 struct hostapd_wpa_psk *psk;
2497 int next_ok = prev_psk == NULL;
2499 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2501 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2504 if (psk->psk == prev_psk)
2512 const struct hostapd_eap_user *
2513 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2514 size_t identity_len, int phase2)
2516 struct hostapd_eap_user *user = conf->eap_user;
2519 if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
2520 os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
2521 static struct hostapd_eap_user wsc_enrollee;
2522 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
2523 wsc_enrollee.methods[0].method = eap_server_get_type(
2524 "WSC", &wsc_enrollee.methods[0].vendor);
2525 return &wsc_enrollee;
2528 if (conf->wps_state && conf->ap_pin &&
2529 identity_len == WSC_ID_REGISTRAR_LEN &&
2530 os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
2531 static struct hostapd_eap_user wsc_registrar;
2532 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
2533 wsc_registrar.methods[0].method = eap_server_get_type(
2534 "WSC", &wsc_registrar.methods[0].vendor);
2535 wsc_registrar.password = (u8 *) conf->ap_pin;
2536 wsc_registrar.password_len = os_strlen(conf->ap_pin);
2537 return &wsc_registrar;
2539 #endif /* CONFIG_WPS */
2542 if (!phase2 && user->identity == NULL) {
2543 /* Wildcard match */
2547 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2548 identity_len >= user->identity_len &&
2549 os_memcmp(user->identity, identity, user->identity_len) ==
2551 /* Wildcard prefix match */
2555 if (user->phase2 == !!phase2 &&
2556 user->identity_len == identity_len &&
2557 os_memcmp(user->identity, identity, identity_len) == 0)