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 */
23 #include "drivers/driver.h"
25 #include "eap_server/eap.h"
26 #include "radius/radius_client.h"
27 #include "common/ieee802_11_defs.h"
28 #include "common/wpa_common.h"
31 #include "eap_common/eap_wsc_common.h"
36 #define MAX_STA_COUNT 2007
38 extern struct wpa_driver_ops *wpa_drivers[];
41 #ifndef CONFIG_NO_VLAN
42 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
46 char buf[128], *pos, *pos2;
47 int line = 0, vlan_id;
48 struct hostapd_vlan *vlan;
50 f = fopen(fname, "r");
52 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
56 while (fgets(buf, sizeof(buf), f)) {
62 while (*pos != '\0') {
73 vlan_id = VLAN_ID_WILDCARD;
76 vlan_id = strtol(buf, &pos, 10);
77 if (buf == pos || vlan_id < 1 ||
78 vlan_id > MAX_VLAN_ID) {
79 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
80 "line %d in '%s'", line, fname);
86 while (*pos == ' ' || *pos == '\t')
89 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
92 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
93 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
94 "in '%s'", line, fname);
99 vlan = os_malloc(sizeof(*vlan));
101 wpa_printf(MSG_ERROR, "Out of memory while reading "
102 "VLAN interfaces from '%s'", fname);
107 os_memset(vlan, 0, sizeof(*vlan));
108 vlan->vlan_id = vlan_id;
109 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
111 bss->vlan_tail->next = vlan;
114 bss->vlan_tail = vlan;
121 #endif /* CONFIG_NO_VLAN */
124 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
126 struct hostapd_vlan *vlan, *prev;
140 /* convert floats with one decimal place to value*10 int, i.e.,
141 * "1.5" will return 15 */
142 static int hostapd_config_read_int10(const char *value)
148 pos = os_strchr(value, '.');
152 if (*pos >= '0' && *pos <= '9')
160 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
162 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
163 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
164 bss->logger_syslog = (unsigned int) -1;
165 bss->logger_stdout = (unsigned int) -1;
167 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
169 bss->wep_rekeying_period = 300;
170 /* use key0 in individual key and key1 in broadcast key */
171 bss->broadcast_key_idx_min = 1;
172 bss->broadcast_key_idx_max = 2;
173 bss->eap_reauth_period = 3600;
175 bss->wpa_group_rekey = 600;
176 bss->wpa_gmk_rekey = 86400;
177 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
178 bss->wpa_pairwise = WPA_CIPHER_TKIP;
179 bss->wpa_group = WPA_CIPHER_TKIP;
180 bss->rsn_pairwise = 0;
182 bss->max_num_sta = MAX_STA_COUNT;
184 bss->dtim_period = 2;
186 bss->radius_server_auth_port = 1812;
187 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
188 bss->eapol_version = EAPOL_VERSION;
190 bss->max_listen_interval = 65535;
192 #ifdef CONFIG_IEEE80211W
193 bss->assoc_sa_query_max_timeout = 1000;
194 bss->assoc_sa_query_retry_timeout = 201;
195 #endif /* CONFIG_IEEE80211W */
196 #ifdef EAP_SERVER_FAST
197 /* both anonymous and authenticated provisioning */
198 bss->eap_fast_prov = 3;
199 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
200 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
201 #endif /* EAP_SERVER_FAST */
205 struct hostapd_config * hostapd_config_defaults(void)
207 struct hostapd_config *conf;
208 struct hostapd_bss_config *bss;
210 const int aCWmin = 15, aCWmax = 1024;
211 const struct hostapd_wmm_ac_params ac_bk =
212 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
213 const struct hostapd_wmm_ac_params ac_be =
214 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
215 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
216 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
217 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
218 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
220 conf = os_zalloc(sizeof(*conf));
221 bss = os_zalloc(sizeof(*bss));
222 if (conf == NULL || bss == NULL) {
223 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
224 "configuration data.");
230 /* set default driver based on configuration */
231 conf->driver = wpa_drivers[0];
232 if (conf->driver == NULL) {
233 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
239 bss->radius = os_zalloc(sizeof(*bss->radius));
240 if (bss->radius == NULL) {
246 hostapd_config_defaults_bss(bss);
251 conf->beacon_int = 100;
252 conf->rts_threshold = -1; /* use driver default: 2347 */
253 conf->fragm_threshold = -1; /* user driver default: 2346 */
254 conf->send_probe_response = 1;
255 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
257 for (i = 0; i < NUM_TX_QUEUES; i++)
258 conf->tx_queue[i].aifs = -1; /* use hw default */
260 conf->wmm_ac_params[0] = ac_be;
261 conf->wmm_ac_params[1] = ac_bk;
262 conf->wmm_ac_params[2] = ac_vi;
263 conf->wmm_ac_params[3] = ac_vo;
265 #ifdef CONFIG_IEEE80211N
266 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
267 #endif /* CONFIG_IEEE80211N */
273 int hostapd_mac_comp(const void *a, const void *b)
275 return os_memcmp(a, b, sizeof(macaddr));
279 int hostapd_mac_comp_empty(const void *a)
281 macaddr empty = { 0 };
282 return os_memcmp(a, empty, sizeof(macaddr));
286 static int hostapd_acl_comp(const void *a, const void *b)
288 const struct mac_acl_entry *aa = a;
289 const struct mac_acl_entry *bb = b;
290 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
294 static int hostapd_config_read_maclist(const char *fname,
295 struct mac_acl_entry **acl, int *num)
301 struct mac_acl_entry *newacl;
307 f = fopen(fname, "r");
309 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
313 while (fgets(buf, sizeof(buf), f)) {
319 while (*pos != '\0') {
329 if (hwaddr_aton(buf, addr)) {
330 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
331 "line %d in '%s'", buf, line, fname);
338 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
340 while (*pos == ' ' || *pos == '\t')
345 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
346 if (newacl == NULL) {
347 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
353 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
354 (*acl)[*num].vlan_id = vlan_id;
360 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
366 static int hostapd_config_read_wpa_psk(const char *fname,
367 struct hostapd_ssid *ssid)
371 int line = 0, ret = 0, len, ok;
373 struct hostapd_wpa_psk *psk;
378 f = fopen(fname, "r");
380 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
384 while (fgets(buf, sizeof(buf), f)) {
390 while (*pos != '\0') {
400 if (hwaddr_aton(buf, addr)) {
401 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
402 "line %d in '%s'", buf, line, fname);
407 psk = os_zalloc(sizeof(*psk));
409 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
413 if (is_zero_ether_addr(addr))
416 os_memcpy(psk->addr, addr, ETH_ALEN);
420 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
429 len = os_strlen(pos);
430 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
432 else if (len >= 8 && len < 64) {
433 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
434 4096, psk->psk, PMK_LEN);
438 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
439 "'%s'", pos, line, fname);
445 psk->next = ssid->wpa_psk;
455 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
457 struct hostapd_ssid *ssid = &conf->ssid;
459 if (ssid->wpa_passphrase != NULL) {
460 if (ssid->wpa_psk != NULL) {
461 wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
462 "passphrase set. Using passphrase.");
463 os_free(ssid->wpa_psk);
465 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
466 if (ssid->wpa_psk == NULL) {
467 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
470 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
471 (u8 *) ssid->ssid, ssid->ssid_len);
472 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
473 (u8 *) ssid->wpa_passphrase,
474 os_strlen(ssid->wpa_passphrase));
475 pbkdf2_sha1(ssid->wpa_passphrase,
476 ssid->ssid, ssid->ssid_len,
477 4096, ssid->wpa_psk->psk, PMK_LEN);
478 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
479 ssid->wpa_psk->psk, PMK_LEN);
480 ssid->wpa_psk->group = 1;
483 if (ssid->wpa_psk_file) {
484 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
494 static int hostapd_config_read_eap_user(const char *fname,
495 struct hostapd_bss_config *conf)
498 char buf[512], *pos, *start, *pos2;
499 int line = 0, ret = 0, num_methods;
500 struct hostapd_eap_user *user, *tail = NULL;
505 f = fopen(fname, "r");
507 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
511 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
512 while (fgets(buf, sizeof(buf), f)) {
518 while (*pos != '\0') {
530 if (buf[0] != '"' && buf[0] != '*') {
531 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
532 "start) on line %d in '%s'", line, fname);
536 user = os_zalloc(sizeof(*user));
538 wpa_printf(MSG_ERROR, "EAP user allocation failed");
541 user->force_version = -1;
548 while (*pos != '"' && *pos != '\0')
551 wpa_printf(MSG_ERROR, "Invalid EAP identity "
552 "(no \" in end) on line %d in '%s'",
557 user->identity = os_malloc(pos - start);
558 if (user->identity == NULL) {
559 wpa_printf(MSG_ERROR, "Failed to allocate "
560 "memory for EAP identity");
563 os_memcpy(user->identity, start, pos - start);
564 user->identity_len = pos - start;
566 if (pos[0] == '"' && pos[1] == '*') {
567 user->wildcard_prefix = 1;
572 while (*pos == ' ' || *pos == '\t')
576 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
577 "'%s'", line, fname);
582 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
592 char *pos3 = os_strchr(start, ',');
596 user->methods[num_methods].method =
599 &user->methods[num_methods].vendor);
600 if (user->methods[num_methods].vendor ==
602 user->methods[num_methods].method == EAP_TYPE_NONE)
604 if (os_strcmp(start, "TTLS-PAP") == 0) {
605 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
608 if (os_strcmp(start, "TTLS-CHAP") == 0) {
609 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
612 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
614 EAP_TTLS_AUTH_MSCHAP;
617 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
619 EAP_TTLS_AUTH_MSCHAPV2;
622 wpa_printf(MSG_ERROR, "Unsupported EAP type "
623 "'%s' on line %d in '%s'",
629 if (num_methods >= EAP_USER_MAX_METHODS)
636 if (num_methods == 0 && user->ttls_auth == 0) {
637 wpa_printf(MSG_ERROR, "No EAP types configured on "
638 "line %d in '%s'", line, fname);
645 while (*pos == ' ' || *pos == '\t')
650 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
651 user->force_version = 0;
655 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
656 user->force_version = 1;
660 if (os_strncmp(pos, "[2]", 3) == 0) {
668 while (*pos != '"' && *pos != '\0')
671 wpa_printf(MSG_ERROR, "Invalid EAP password "
672 "(no \" in end) on line %d in '%s'",
677 user->password = os_malloc(pos - start);
678 if (user->password == NULL) {
679 wpa_printf(MSG_ERROR, "Failed to allocate "
680 "memory for EAP password");
683 os_memcpy(user->password, start, pos - start);
684 user->password_len = pos - start;
687 } else if (os_strncmp(pos, "hash:", 5) == 0) {
690 while (*pos2 != '\0' && *pos2 != ' ' &&
691 *pos2 != '\t' && *pos2 != '#')
693 if (pos2 - pos != 32) {
694 wpa_printf(MSG_ERROR, "Invalid password hash "
695 "on line %d in '%s'", line, fname);
698 user->password = os_malloc(16);
699 if (user->password == NULL) {
700 wpa_printf(MSG_ERROR, "Failed to allocate "
701 "memory for EAP password hash");
704 if (hexstr2bin(pos, user->password, 16) < 0) {
705 wpa_printf(MSG_ERROR, "Invalid hash password "
706 "on line %d in '%s'", line, fname);
709 user->password_len = 16;
710 user->password_hash = 1;
714 while (*pos2 != '\0' && *pos2 != ' ' &&
715 *pos2 != '\t' && *pos2 != '#')
717 if ((pos2 - pos) & 1) {
718 wpa_printf(MSG_ERROR, "Invalid hex password "
719 "on line %d in '%s'", line, fname);
722 user->password = os_malloc((pos2 - pos) / 2);
723 if (user->password == NULL) {
724 wpa_printf(MSG_ERROR, "Failed to allocate "
725 "memory for EAP password");
728 if (hexstr2bin(pos, user->password,
729 (pos2 - pos) / 2) < 0) {
730 wpa_printf(MSG_ERROR, "Invalid hex password "
731 "on line %d in '%s'", line, fname);
734 user->password_len = (pos2 - pos) / 2;
738 while (*pos == ' ' || *pos == '\t')
740 if (os_strncmp(pos, "[2]", 3) == 0) {
746 tail = conf->eap_user = user;
755 os_free(user->password);
756 os_free(user->identity);
767 #endif /* EAP_SERVER */
770 #ifndef CONFIG_NO_RADIUS
772 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
773 int *num_server, const char *val, int def_port,
774 struct hostapd_radius_server **curr_serv)
776 struct hostapd_radius_server *nserv;
778 static int server_index = 1;
780 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
785 nserv = &nserv[*num_server];
787 (*curr_serv) = nserv;
789 os_memset(nserv, 0, sizeof(*nserv));
790 nserv->port = def_port;
791 ret = hostapd_parse_ip_addr(val, &nserv->addr);
792 nserv->index = server_index++;
796 #endif /* CONFIG_NO_RADIUS */
799 static int hostapd_config_parse_key_mgmt(int line, const char *value)
802 char *start, *end, *buf;
804 buf = os_strdup(value);
809 while (*start != '\0') {
810 while (*start == ' ' || *start == '\t')
815 while (*end != ' ' && *end != '\t' && *end != '\0')
819 if (os_strcmp(start, "WPA-PSK") == 0)
820 val |= WPA_KEY_MGMT_PSK;
821 else if (os_strcmp(start, "WPA-EAP") == 0)
822 val |= WPA_KEY_MGMT_IEEE8021X;
823 #ifdef CONFIG_IEEE80211R
824 else if (os_strcmp(start, "FT-PSK") == 0)
825 val |= WPA_KEY_MGMT_FT_PSK;
826 else if (os_strcmp(start, "FT-EAP") == 0)
827 val |= WPA_KEY_MGMT_FT_IEEE8021X;
828 #endif /* CONFIG_IEEE80211R */
829 #ifdef CONFIG_IEEE80211W
830 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
831 val |= WPA_KEY_MGMT_PSK_SHA256;
832 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
833 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
834 #endif /* CONFIG_IEEE80211W */
836 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
849 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
850 "configured.", line);
858 static int hostapd_config_parse_cipher(int line, const char *value)
861 char *start, *end, *buf;
863 buf = os_strdup(value);
868 while (*start != '\0') {
869 while (*start == ' ' || *start == '\t')
874 while (*end != ' ' && *end != '\t' && *end != '\0')
878 if (os_strcmp(start, "CCMP") == 0)
879 val |= WPA_CIPHER_CCMP;
880 else if (os_strcmp(start, "TKIP") == 0)
881 val |= WPA_CIPHER_TKIP;
882 else if (os_strcmp(start, "WEP104") == 0)
883 val |= WPA_CIPHER_WEP104;
884 else if (os_strcmp(start, "WEP40") == 0)
885 val |= WPA_CIPHER_WEP40;
886 else if (os_strcmp(start, "NONE") == 0)
887 val |= WPA_CIPHER_NONE;
889 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
902 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
910 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
911 struct hostapd_config *conf)
913 if (bss->ieee802_1x && !bss->eap_server &&
914 !bss->radius->auth_servers) {
915 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
916 "EAP authenticator configured).");
920 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
921 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
922 bss->ssid.wpa_psk_file == NULL) {
923 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
924 "is not configured.");
928 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
931 for (i = 0; i < conf->num_bss; i++) {
932 if ((&conf->bss[i] != bss) &&
933 (hostapd_mac_comp(conf->bss[i].bssid,
935 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
936 " on interface '%s' and '%s'.",
938 conf->bss[i].iface, bss->iface);
944 #ifdef CONFIG_IEEE80211R
945 if ((bss->wpa_key_mgmt &
946 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
947 (bss->nas_identifier == NULL ||
948 os_strlen(bss->nas_identifier) < 1 ||
949 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
950 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
951 "nas_identifier to be configured as a 1..48 octet "
955 #endif /* CONFIG_IEEE80211R */
957 #ifdef CONFIG_IEEE80211N
958 if (conf->ieee80211n && bss->wpa &&
959 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
960 !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
961 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
962 "requires CCMP to be enabled");
965 #endif /* CONFIG_IEEE80211N */
971 static int hostapd_config_check(struct hostapd_config *conf)
975 if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
976 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
977 "setting the country_code");
981 for (i = 0; i < conf->num_bss; i++) {
982 if (hostapd_config_check_bss(&conf->bss[i], conf))
990 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
993 size_t len = os_strlen(val);
995 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
999 if (len < 2 || val[len - 1] != '"')
1002 wep->key[keyidx] = os_malloc(len);
1003 if (wep->key[keyidx] == NULL)
1005 os_memcpy(wep->key[keyidx], val + 1, len);
1006 wep->len[keyidx] = len;
1011 wep->key[keyidx] = os_malloc(len);
1012 if (wep->key[keyidx] == NULL)
1014 wep->len[keyidx] = len;
1015 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1025 static int hostapd_parse_rates(int **rate_list, char *val)
1031 os_free(*rate_list);
1036 while (*pos != '\0') {
1042 list = os_malloc(sizeof(int) * (count + 2));
1047 while (*pos != '\0') {
1048 end = os_strchr(pos, ' ');
1052 list[count++] = atoi(pos);
1064 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1066 struct hostapd_bss_config *bss;
1068 if (*ifname == '\0')
1071 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1072 sizeof(struct hostapd_bss_config));
1074 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1080 bss = &(conf->bss[conf->num_bss]);
1081 os_memset(bss, 0, sizeof(*bss));
1082 bss->radius = os_zalloc(sizeof(*bss->radius));
1083 if (bss->radius == NULL) {
1084 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1085 "multi-BSS RADIUS data");
1090 conf->last_bss = bss;
1092 hostapd_config_defaults_bss(bss);
1093 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1094 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1100 static int valid_cw(int cw)
1102 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1103 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1108 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1109 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1110 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1111 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1112 IEEE80211_TX_QUEUE_DATA4 = 4,
1113 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1114 IEEE80211_TX_QUEUE_BEACON = 7
1117 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1122 struct hostapd_tx_queue_params *queue;
1124 /* skip 'tx_queue_' prefix */
1126 if (os_strncmp(pos, "data", 4) == 0 &&
1127 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1130 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1131 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1133 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1134 num = IEEE80211_TX_QUEUE_BEACON;
1137 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1141 queue = &conf->tx_queue[num];
1143 if (os_strcmp(pos, "aifs") == 0) {
1144 queue->aifs = atoi(val);
1145 if (queue->aifs < 0 || queue->aifs > 255) {
1146 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1150 } else if (os_strcmp(pos, "cwmin") == 0) {
1151 queue->cwmin = atoi(val);
1152 if (!valid_cw(queue->cwmin)) {
1153 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1157 } else if (os_strcmp(pos, "cwmax") == 0) {
1158 queue->cwmax = atoi(val);
1159 if (!valid_cw(queue->cwmax)) {
1160 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1164 } else if (os_strcmp(pos, "burst") == 0) {
1165 queue->burst = hostapd_config_read_int10(val);
1167 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1171 queue->configured = 1;
1177 static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
1182 struct hostapd_wmm_ac_params *ac;
1184 /* skip 'wme_ac_' or 'wmm_ac_' prefix */
1186 if (os_strncmp(pos, "be_", 3) == 0) {
1189 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1192 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1195 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1199 wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
1203 ac = &conf->wmm_ac_params[num];
1205 if (os_strcmp(pos, "aifs") == 0) {
1207 if (v < 1 || v > 255) {
1208 wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
1212 } else if (os_strcmp(pos, "cwmin") == 0) {
1214 if (v < 0 || v > 12) {
1215 wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
1219 } else if (os_strcmp(pos, "cwmax") == 0) {
1221 if (v < 0 || v > 12) {
1222 wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
1226 } else if (os_strcmp(pos, "txop_limit") == 0) {
1228 if (v < 0 || v > 0xffff) {
1229 wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
1233 } else if (os_strcmp(pos, "acm") == 0) {
1235 if (v < 0 || v > 1) {
1236 wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
1239 ac->admission_control_mandatory = v;
1241 wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
1249 #ifdef CONFIG_IEEE80211R
1250 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1252 struct ft_remote_r0kh *r0kh;
1255 r0kh = os_zalloc(sizeof(*r0kh));
1259 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1261 next = os_strchr(pos, ' ');
1264 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1265 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1271 next = os_strchr(pos, ' ');
1274 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1275 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1279 r0kh->id_len = next - pos - 1;
1280 os_memcpy(r0kh->id, pos, r0kh->id_len);
1283 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1284 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1289 r0kh->next = bss->r0kh_list;
1290 bss->r0kh_list = r0kh;
1296 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1298 struct ft_remote_r1kh *r1kh;
1301 r1kh = os_zalloc(sizeof(*r1kh));
1305 /* 02:01:02:03:04:05 02:01:02:03:04:05
1306 * 000102030405060708090a0b0c0d0e0f */
1308 next = os_strchr(pos, ' ');
1311 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1312 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1318 next = os_strchr(pos, ' ');
1321 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1322 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1328 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1329 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1334 r1kh->next = bss->r1kh_list;
1335 bss->r1kh_list = r1kh;
1339 #endif /* CONFIG_IEEE80211R */
1342 #ifdef CONFIG_IEEE80211N
1343 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1346 if (os_strstr(capab, "[LDPC]"))
1347 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1348 if (os_strstr(capab, "[HT40-]")) {
1349 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1350 conf->secondary_channel = -1;
1352 if (os_strstr(capab, "[HT40+]")) {
1353 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1354 conf->secondary_channel = 1;
1356 if (os_strstr(capab, "[SMPS-STATIC]")) {
1357 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1358 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1360 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1361 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1362 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1364 if (os_strstr(capab, "[GF]"))
1365 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1366 if (os_strstr(capab, "[SHORT-GI-20]"))
1367 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1368 if (os_strstr(capab, "[SHORT-GI-40]"))
1369 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1370 if (os_strstr(capab, "[TX-STBC]"))
1371 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1372 if (os_strstr(capab, "[RX-STBC1]")) {
1373 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1374 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1376 if (os_strstr(capab, "[RX-STBC12]")) {
1377 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1378 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1380 if (os_strstr(capab, "[RX-STBC123]")) {
1381 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1382 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1384 if (os_strstr(capab, "[DELAYED-BA]"))
1385 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1386 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1387 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1388 if (os_strstr(capab, "[DSSS_CCK-40]"))
1389 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1390 if (os_strstr(capab, "[PSMP]"))
1391 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1392 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1393 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1397 #endif /* CONFIG_IEEE80211N */
1401 * hostapd_config_read - Read and parse a configuration file
1402 * @fname: Configuration file name (including path, if needed)
1403 * Returns: Allocated configuration data structure
1405 struct hostapd_config * hostapd_config_read(const char *fname)
1407 struct hostapd_config *conf;
1408 struct hostapd_bss_config *bss;
1410 char buf[256], *pos;
1416 f = fopen(fname, "r");
1418 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
1419 "for reading.", fname);
1423 conf = hostapd_config_defaults();
1428 bss = conf->last_bss = conf->bss;
1430 while (fgets(buf, sizeof(buf), f)) {
1431 bss = conf->last_bss;
1437 while (*pos != '\0') {
1447 pos = os_strchr(buf, '=');
1449 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
1457 if (os_strcmp(buf, "interface") == 0) {
1458 os_strlcpy(conf->bss[0].iface, pos,
1459 sizeof(conf->bss[0].iface));
1460 } else if (os_strcmp(buf, "bridge") == 0) {
1461 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1462 } else if (os_strcmp(buf, "driver") == 0) {
1464 /* clear to get error below if setting is invalid */
1465 conf->driver = NULL;
1466 for (j = 0; wpa_drivers[j]; j++) {
1467 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
1469 conf->driver = wpa_drivers[j];
1473 if (conf->driver == NULL) {
1474 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1475 "unknown driver '%s'", line, pos);
1478 } else if (os_strcmp(buf, "debug") == 0) {
1479 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1480 "configuration variable is not used "
1482 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1483 bss->logger_syslog_level = atoi(pos);
1484 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1485 bss->logger_stdout_level = atoi(pos);
1486 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1487 bss->logger_syslog = atoi(pos);
1488 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1489 bss->logger_stdout = atoi(pos);
1490 } else if (os_strcmp(buf, "dump_file") == 0) {
1491 bss->dump_log_name = os_strdup(pos);
1492 } else if (os_strcmp(buf, "ssid") == 0) {
1493 bss->ssid.ssid_len = os_strlen(pos);
1494 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1495 bss->ssid.ssid_len < 1) {
1496 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1500 os_memcpy(bss->ssid.ssid, pos,
1501 bss->ssid.ssid_len);
1502 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1503 bss->ssid.ssid_set = 1;
1505 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1506 bss->macaddr_acl = atoi(pos);
1507 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1508 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1509 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1510 wpa_printf(MSG_ERROR, "Line %d: unknown "
1512 line, bss->macaddr_acl);
1514 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1515 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1516 &bss->num_accept_mac))
1518 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1519 "read accept_mac_file '%s'",
1523 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1524 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1525 &bss->num_deny_mac)) {
1526 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1527 "read deny_mac_file '%s'",
1531 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1532 bss->ap_max_inactivity = atoi(pos);
1533 } else if (os_strcmp(buf, "country_code") == 0) {
1534 os_memcpy(conf->country, pos, 2);
1535 /* FIX: make this configurable */
1536 conf->country[2] = ' ';
1537 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1538 conf->ieee80211d = atoi(pos);
1539 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1540 bss->ieee802_1x = atoi(pos);
1541 } else if (os_strcmp(buf, "eapol_version") == 0) {
1542 bss->eapol_version = atoi(pos);
1543 if (bss->eapol_version < 1 ||
1544 bss->eapol_version > 2) {
1545 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1546 "version (%d): '%s'.",
1547 line, bss->eapol_version, pos);
1550 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1551 bss->eapol_version);
1553 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1554 bss->eap_server = atoi(pos);
1555 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1556 "eap_authenticator used; this has been "
1557 "renamed to eap_server", line);
1558 } else if (os_strcmp(buf, "eap_server") == 0) {
1559 bss->eap_server = atoi(pos);
1560 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1561 if (hostapd_config_read_eap_user(pos, bss))
1563 } else if (os_strcmp(buf, "ca_cert") == 0) {
1564 os_free(bss->ca_cert);
1565 bss->ca_cert = os_strdup(pos);
1566 } else if (os_strcmp(buf, "server_cert") == 0) {
1567 os_free(bss->server_cert);
1568 bss->server_cert = os_strdup(pos);
1569 } else if (os_strcmp(buf, "private_key") == 0) {
1570 os_free(bss->private_key);
1571 bss->private_key = os_strdup(pos);
1572 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1573 os_free(bss->private_key_passwd);
1574 bss->private_key_passwd = os_strdup(pos);
1575 } else if (os_strcmp(buf, "check_crl") == 0) {
1576 bss->check_crl = atoi(pos);
1577 } else if (os_strcmp(buf, "dh_file") == 0) {
1578 os_free(bss->dh_file);
1579 bss->dh_file = os_strdup(pos);
1580 #ifdef EAP_SERVER_FAST
1581 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1582 os_free(bss->pac_opaque_encr_key);
1583 bss->pac_opaque_encr_key = os_malloc(16);
1584 if (bss->pac_opaque_encr_key == NULL) {
1585 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1586 "pac_opaque_encr_key", line);
1588 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1590 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1591 "pac_opaque_encr_key", line);
1594 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1595 size_t idlen = os_strlen(pos);
1597 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1598 "eap_fast_a_id", line);
1601 os_free(bss->eap_fast_a_id);
1602 bss->eap_fast_a_id = os_malloc(idlen / 2);
1603 if (bss->eap_fast_a_id == NULL ||
1604 hexstr2bin(pos, bss->eap_fast_a_id,
1606 wpa_printf(MSG_ERROR, "Line %d: "
1608 "eap_fast_a_id", line);
1611 bss->eap_fast_a_id_len = idlen / 2;
1613 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1614 os_free(bss->eap_fast_a_id_info);
1615 bss->eap_fast_a_id_info = os_strdup(pos);
1616 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1617 bss->eap_fast_prov = atoi(pos);
1618 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1619 bss->pac_key_lifetime = atoi(pos);
1620 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1621 bss->pac_key_refresh_time = atoi(pos);
1622 #endif /* EAP_SERVER_FAST */
1623 #ifdef EAP_SERVER_SIM
1624 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1625 os_free(bss->eap_sim_db);
1626 bss->eap_sim_db = os_strdup(pos);
1627 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1628 bss->eap_sim_aka_result_ind = atoi(pos);
1629 #endif /* EAP_SERVER_SIM */
1630 #ifdef EAP_SERVER_TNC
1631 } else if (os_strcmp(buf, "tnc") == 0) {
1632 bss->tnc = atoi(pos);
1633 #endif /* EAP_SERVER_TNC */
1634 #endif /* EAP_SERVER */
1635 } else if (os_strcmp(buf, "eap_message") == 0) {
1637 bss->eap_req_id_text = os_strdup(pos);
1638 if (bss->eap_req_id_text == NULL) {
1639 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1640 "allocate memory for "
1641 "eap_req_id_text", line);
1645 bss->eap_req_id_text_len =
1646 os_strlen(bss->eap_req_id_text);
1647 term = os_strstr(bss->eap_req_id_text, "\\0");
1650 os_memmove(term, term + 1,
1651 bss->eap_req_id_text_len -
1652 (term - bss->eap_req_id_text) - 1);
1653 bss->eap_req_id_text_len--;
1655 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1656 bss->default_wep_key_len = atoi(pos);
1657 if (bss->default_wep_key_len > 13) {
1658 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1659 "key len %lu (= %lu bits)", line,
1661 bss->default_wep_key_len,
1663 bss->default_wep_key_len * 8);
1666 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1667 bss->individual_wep_key_len = atoi(pos);
1668 if (bss->individual_wep_key_len < 0 ||
1669 bss->individual_wep_key_len > 13) {
1670 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1671 "key len %d (= %d bits)", line,
1672 bss->individual_wep_key_len,
1673 bss->individual_wep_key_len * 8);
1676 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1677 bss->wep_rekeying_period = atoi(pos);
1678 if (bss->wep_rekeying_period < 0) {
1679 wpa_printf(MSG_ERROR, "Line %d: invalid "
1681 line, bss->wep_rekeying_period);
1684 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1685 bss->eap_reauth_period = atoi(pos);
1686 if (bss->eap_reauth_period < 0) {
1687 wpa_printf(MSG_ERROR, "Line %d: invalid "
1689 line, bss->eap_reauth_period);
1692 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1693 bss->eapol_key_index_workaround = atoi(pos);
1695 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1696 bss->ieee802_11f = 1;
1697 os_strlcpy(bss->iapp_iface, pos,
1698 sizeof(bss->iapp_iface));
1699 #endif /* CONFIG_IAPP */
1700 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1701 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1702 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1703 "address '%s'", line, pos);
1706 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1707 bss->nas_identifier = os_strdup(pos);
1708 #ifndef CONFIG_NO_RADIUS
1709 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1710 if (hostapd_config_read_radius_addr(
1711 &bss->radius->auth_servers,
1712 &bss->radius->num_auth_servers, pos, 1812,
1713 &bss->radius->auth_server)) {
1714 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1715 "address '%s'", line, pos);
1718 } else if (bss->radius->auth_server &&
1719 os_strcmp(buf, "auth_server_port") == 0) {
1720 bss->radius->auth_server->port = atoi(pos);
1721 } else if (bss->radius->auth_server &&
1722 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1723 int len = os_strlen(pos);
1725 /* RFC 2865, Ch. 3 */
1726 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1727 "secret is not allowed.", line);
1730 bss->radius->auth_server->shared_secret =
1731 (u8 *) os_strdup(pos);
1732 bss->radius->auth_server->shared_secret_len = len;
1733 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1734 if (hostapd_config_read_radius_addr(
1735 &bss->radius->acct_servers,
1736 &bss->radius->num_acct_servers, pos, 1813,
1737 &bss->radius->acct_server)) {
1738 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1739 "address '%s'", line, pos);
1742 } else if (bss->radius->acct_server &&
1743 os_strcmp(buf, "acct_server_port") == 0) {
1744 bss->radius->acct_server->port = atoi(pos);
1745 } else if (bss->radius->acct_server &&
1746 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1747 int len = os_strlen(pos);
1749 /* RFC 2865, Ch. 3 */
1750 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1751 "secret is not allowed.", line);
1754 bss->radius->acct_server->shared_secret =
1755 (u8 *) os_strdup(pos);
1756 bss->radius->acct_server->shared_secret_len = len;
1757 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1759 bss->radius->retry_primary_interval = atoi(pos);
1760 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1762 bss->acct_interim_interval = atoi(pos);
1763 #endif /* CONFIG_NO_RADIUS */
1764 } else if (os_strcmp(buf, "auth_algs") == 0) {
1765 bss->auth_algs = atoi(pos);
1766 if (bss->auth_algs == 0) {
1767 wpa_printf(MSG_ERROR, "Line %d: no "
1768 "authentication algorithms allowed",
1772 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1773 bss->max_num_sta = atoi(pos);
1774 if (bss->max_num_sta < 0 ||
1775 bss->max_num_sta > MAX_STA_COUNT) {
1776 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1777 "max_num_sta=%d; allowed range "
1778 "0..%d", line, bss->max_num_sta,
1782 } else if (os_strcmp(buf, "wpa") == 0) {
1783 bss->wpa = atoi(pos);
1784 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1785 bss->wpa_group_rekey = atoi(pos);
1786 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1787 bss->wpa_strict_rekey = atoi(pos);
1788 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1789 bss->wpa_gmk_rekey = atoi(pos);
1790 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1791 bss->wpa_ptk_rekey = atoi(pos);
1792 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1793 int len = os_strlen(pos);
1794 if (len < 8 || len > 63) {
1795 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1796 "passphrase length %d (expected "
1797 "8..63)", line, len);
1800 os_free(bss->ssid.wpa_passphrase);
1801 bss->ssid.wpa_passphrase = os_strdup(pos);
1803 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1804 os_free(bss->ssid.wpa_psk);
1806 os_zalloc(sizeof(struct hostapd_wpa_psk));
1807 if (bss->ssid.wpa_psk == NULL)
1809 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1811 pos[PMK_LEN * 2] != '\0') {
1812 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1813 "'%s'.", line, pos);
1816 bss->ssid.wpa_psk->group = 1;
1818 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1819 os_free(bss->ssid.wpa_psk_file);
1820 bss->ssid.wpa_psk_file = os_strdup(pos);
1821 if (!bss->ssid.wpa_psk_file) {
1822 wpa_printf(MSG_ERROR, "Line %d: allocation "
1826 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1828 hostapd_config_parse_key_mgmt(line, pos);
1829 if (bss->wpa_key_mgmt == -1)
1831 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1833 hostapd_config_parse_cipher(line, pos);
1834 if (bss->wpa_pairwise == -1 ||
1835 bss->wpa_pairwise == 0)
1837 else if (bss->wpa_pairwise &
1838 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1839 WPA_CIPHER_WEP104)) {
1840 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1841 "pairwise cipher suite '%s'",
1842 bss->wpa_pairwise, pos);
1845 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1847 hostapd_config_parse_cipher(line, pos);
1848 if (bss->rsn_pairwise == -1 ||
1849 bss->rsn_pairwise == 0)
1851 else if (bss->rsn_pairwise &
1852 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1853 WPA_CIPHER_WEP104)) {
1854 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1855 "pairwise cipher suite '%s'",
1856 bss->rsn_pairwise, pos);
1859 #ifdef CONFIG_RSN_PREAUTH
1860 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1861 bss->rsn_preauth = atoi(pos);
1862 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1863 bss->rsn_preauth_interfaces = os_strdup(pos);
1864 #endif /* CONFIG_RSN_PREAUTH */
1865 #ifdef CONFIG_PEERKEY
1866 } else if (os_strcmp(buf, "peerkey") == 0) {
1867 bss->peerkey = atoi(pos);
1868 #endif /* CONFIG_PEERKEY */
1869 #ifdef CONFIG_IEEE80211R
1870 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1871 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1872 hexstr2bin(pos, bss->mobility_domain,
1873 MOBILITY_DOMAIN_ID_LEN) != 0) {
1874 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1875 "mobility_domain '%s'", line, pos);
1879 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1880 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1881 hexstr2bin(pos, bss->r1_key_holder,
1882 FT_R1KH_ID_LEN) != 0) {
1883 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1884 "r1_key_holder '%s'", line, pos);
1888 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1889 bss->r0_key_lifetime = atoi(pos);
1890 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1891 bss->reassociation_deadline = atoi(pos);
1892 } else if (os_strcmp(buf, "r0kh") == 0) {
1893 if (add_r0kh(bss, pos) < 0) {
1894 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1895 "r0kh '%s'", line, pos);
1899 } else if (os_strcmp(buf, "r1kh") == 0) {
1900 if (add_r1kh(bss, pos) < 0) {
1901 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1902 "r1kh '%s'", line, pos);
1906 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1907 bss->pmk_r1_push = atoi(pos);
1908 #endif /* CONFIG_IEEE80211R */
1909 #ifndef CONFIG_NO_CTRL_IFACE
1910 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1911 os_free(bss->ctrl_interface);
1912 bss->ctrl_interface = os_strdup(pos);
1913 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1914 #ifndef CONFIG_NATIVE_WINDOWS
1917 const char *group = pos;
1919 grp = getgrnam(group);
1921 bss->ctrl_interface_gid = grp->gr_gid;
1922 bss->ctrl_interface_gid_set = 1;
1923 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1924 " (from group name '%s')",
1925 bss->ctrl_interface_gid, group);
1929 /* Group name not found - try to parse this as gid */
1930 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1931 if (*group == '\0' || *endp != '\0') {
1932 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1933 "'%s'", line, group);
1937 bss->ctrl_interface_gid_set = 1;
1938 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1939 bss->ctrl_interface_gid);
1940 #endif /* CONFIG_NATIVE_WINDOWS */
1941 #endif /* CONFIG_NO_CTRL_IFACE */
1942 #ifdef RADIUS_SERVER
1943 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1944 os_free(bss->radius_server_clients);
1945 bss->radius_server_clients = os_strdup(pos);
1946 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1947 bss->radius_server_auth_port = atoi(pos);
1948 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1949 bss->radius_server_ipv6 = atoi(pos);
1950 #endif /* RADIUS_SERVER */
1951 } else if (os_strcmp(buf, "test_socket") == 0) {
1952 os_free(bss->test_socket);
1953 bss->test_socket = os_strdup(pos);
1954 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1955 bss->use_pae_group_addr = atoi(pos);
1956 } else if (os_strcmp(buf, "hw_mode") == 0) {
1957 if (os_strcmp(pos, "a") == 0)
1958 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1959 else if (os_strcmp(pos, "b") == 0)
1960 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1961 else if (os_strcmp(pos, "g") == 0)
1962 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1964 wpa_printf(MSG_ERROR, "Line %d: unknown "
1965 "hw_mode '%s'", line, pos);
1968 } else if (os_strcmp(buf, "channel") == 0) {
1969 conf->channel = atoi(pos);
1970 } else if (os_strcmp(buf, "beacon_int") == 0) {
1971 int val = atoi(pos);
1972 /* MIB defines range as 1..65535, but very small values
1973 * cause problems with the current implementation.
1974 * Since it is unlikely that this small numbers are
1975 * useful in real life scenarios, do not allow beacon
1976 * period to be set below 15 TU. */
1977 if (val < 15 || val > 65535) {
1978 wpa_printf(MSG_ERROR, "Line %d: invalid "
1979 "beacon_int %d (expected "
1980 "15..65535)", line, val);
1983 conf->beacon_int = val;
1984 } else if (os_strcmp(buf, "dtim_period") == 0) {
1985 bss->dtim_period = atoi(pos);
1986 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1987 wpa_printf(MSG_ERROR, "Line %d: invalid "
1989 line, bss->dtim_period);
1992 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1993 conf->rts_threshold = atoi(pos);
1994 if (conf->rts_threshold < 0 ||
1995 conf->rts_threshold > 2347) {
1996 wpa_printf(MSG_ERROR, "Line %d: invalid "
1998 line, conf->rts_threshold);
2001 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2002 conf->fragm_threshold = atoi(pos);
2003 if (conf->fragm_threshold < 256 ||
2004 conf->fragm_threshold > 2346) {
2005 wpa_printf(MSG_ERROR, "Line %d: invalid "
2006 "fragm_threshold %d",
2007 line, conf->fragm_threshold);
2010 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2011 int val = atoi(pos);
2012 if (val != 0 && val != 1) {
2013 wpa_printf(MSG_ERROR, "Line %d: invalid "
2014 "send_probe_response %d (expected "
2015 "0 or 1)", line, val);
2017 conf->send_probe_response = val;
2018 } else if (os_strcmp(buf, "supported_rates") == 0) {
2019 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2020 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2024 } else if (os_strcmp(buf, "basic_rates") == 0) {
2025 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2026 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2030 } else if (os_strcmp(buf, "preamble") == 0) {
2032 conf->preamble = SHORT_PREAMBLE;
2034 conf->preamble = LONG_PREAMBLE;
2035 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2036 bss->ignore_broadcast_ssid = atoi(pos);
2037 } else if (os_strcmp(buf, "bridge_packets") == 0) {
2038 conf->bridge_packets = atoi(pos);
2039 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2040 bss->ssid.wep.idx = atoi(pos);
2041 if (bss->ssid.wep.idx > 3) {
2042 wpa_printf(MSG_ERROR, "Invalid "
2043 "wep_default_key index %d",
2047 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2048 os_strcmp(buf, "wep_key1") == 0 ||
2049 os_strcmp(buf, "wep_key2") == 0 ||
2050 os_strcmp(buf, "wep_key3") == 0) {
2051 if (hostapd_config_read_wep(&bss->ssid.wep,
2052 buf[7] - '0', pos)) {
2053 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2054 "key '%s'", line, buf);
2057 #ifndef CONFIG_NO_VLAN
2058 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2059 bss->ssid.dynamic_vlan = atoi(pos);
2060 } else if (os_strcmp(buf, "vlan_file") == 0) {
2061 if (hostapd_config_read_vlan_file(bss, pos)) {
2062 wpa_printf(MSG_ERROR, "Line %d: failed to "
2063 "read VLAN file '%s'", line, pos);
2066 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2067 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2068 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2069 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2070 #endif /* CONFIG_NO_VLAN */
2071 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2072 conf->ap_table_max_size = atoi(pos);
2073 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2074 conf->ap_table_expiration_time = atoi(pos);
2075 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2076 if (hostapd_config_tx_queue(conf, buf, pos)) {
2077 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2078 "queue item", line);
2081 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2082 os_strcmp(buf, "wmm_enabled") == 0) {
2083 bss->wmm_enabled = atoi(pos);
2084 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2085 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2086 if (hostapd_config_wmm_ac(conf, buf, pos)) {
2087 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2091 } else if (os_strcmp(buf, "bss") == 0) {
2092 if (hostapd_config_bss(conf, pos)) {
2093 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2097 } else if (os_strcmp(buf, "bssid") == 0) {
2098 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 os_free(bss->wps_pin_requests);
2155 bss->wps_pin_requests = os_strdup(pos);
2156 } else if (os_strcmp(buf, "device_name") == 0) {
2157 if (os_strlen(pos) > 32) {
2158 wpa_printf(MSG_ERROR, "Line %d: Too long "
2159 "device_name", line);
2162 os_free(bss->device_name);
2163 bss->device_name = os_strdup(pos);
2164 } else if (os_strcmp(buf, "manufacturer") == 0) {
2165 if (os_strlen(pos) > 64) {
2166 wpa_printf(MSG_ERROR, "Line %d: Too long "
2167 "manufacturer", line);
2170 os_free(bss->manufacturer);
2171 bss->manufacturer = os_strdup(pos);
2172 } else if (os_strcmp(buf, "model_name") == 0) {
2173 if (os_strlen(pos) > 32) {
2174 wpa_printf(MSG_ERROR, "Line %d: Too long "
2175 "model_name", line);
2178 os_free(bss->model_name);
2179 bss->model_name = os_strdup(pos);
2180 } else if (os_strcmp(buf, "model_number") == 0) {
2181 if (os_strlen(pos) > 32) {
2182 wpa_printf(MSG_ERROR, "Line %d: Too long "
2183 "model_number", line);
2186 os_free(bss->model_number);
2187 bss->model_number = os_strdup(pos);
2188 } else if (os_strcmp(buf, "serial_number") == 0) {
2189 if (os_strlen(pos) > 32) {
2190 wpa_printf(MSG_ERROR, "Line %d: Too long "
2191 "serial_number", line);
2194 os_free(bss->serial_number);
2195 bss->serial_number = os_strdup(pos);
2196 } else if (os_strcmp(buf, "device_type") == 0) {
2197 os_free(bss->device_type);
2198 bss->device_type = os_strdup(pos);
2199 } else if (os_strcmp(buf, "config_methods") == 0) {
2200 os_free(bss->config_methods);
2201 bss->config_methods = os_strdup(pos);
2202 } else if (os_strcmp(buf, "os_version") == 0) {
2203 if (hexstr2bin(pos, bss->os_version, 4)) {
2204 wpa_printf(MSG_ERROR, "Line %d: invalid "
2205 "os_version", line);
2208 } else if (os_strcmp(buf, "ap_pin") == 0) {
2209 os_free(bss->ap_pin);
2210 bss->ap_pin = os_strdup(pos);
2211 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2212 bss->skip_cred_build = atoi(pos);
2213 } else if (os_strcmp(buf, "extra_cred") == 0) {
2214 os_free(bss->extra_cred);
2216 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2217 if (bss->extra_cred == NULL) {
2218 wpa_printf(MSG_ERROR, "Line %d: could not "
2219 "read Credentials from '%s'",
2223 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2224 bss->wps_cred_processing = atoi(pos);
2225 } else if (os_strcmp(buf, "ap_settings") == 0) {
2226 os_free(bss->ap_settings);
2228 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2229 if (bss->ap_settings == NULL) {
2230 wpa_printf(MSG_ERROR, "Line %d: could not "
2231 "read AP Settings from '%s'",
2235 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2236 bss->upnp_iface = os_strdup(pos);
2237 } else if (os_strcmp(buf, "friendly_name") == 0) {
2238 os_free(bss->friendly_name);
2239 bss->friendly_name = os_strdup(pos);
2240 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2241 os_free(bss->manufacturer_url);
2242 bss->manufacturer_url = os_strdup(pos);
2243 } else if (os_strcmp(buf, "model_description") == 0) {
2244 os_free(bss->model_description);
2245 bss->model_description = os_strdup(pos);
2246 } else if (os_strcmp(buf, "model_url") == 0) {
2247 os_free(bss->model_url);
2248 bss->model_url = os_strdup(pos);
2249 } else if (os_strcmp(buf, "upc") == 0) {
2251 bss->upc = os_strdup(pos);
2252 #endif /* CONFIG_WPS */
2254 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2255 "item '%s'", line, buf);
2262 for (i = 0; i < conf->num_bss; i++) {
2263 bss = &conf->bss[i];
2265 if (bss->individual_wep_key_len == 0) {
2266 /* individual keys are not use; can use key idx0 for
2268 bss->broadcast_key_idx_min = 0;
2271 /* Select group cipher based on the enabled pairwise cipher
2275 pairwise |= bss->wpa_pairwise;
2277 if (bss->rsn_pairwise == 0)
2278 bss->rsn_pairwise = bss->wpa_pairwise;
2279 pairwise |= bss->rsn_pairwise;
2281 if (pairwise & WPA_CIPHER_TKIP)
2282 bss->wpa_group = WPA_CIPHER_TKIP;
2284 bss->wpa_group = WPA_CIPHER_CCMP;
2286 bss->radius->auth_server = bss->radius->auth_servers;
2287 bss->radius->acct_server = bss->radius->acct_servers;
2289 if (bss->wpa && bss->ieee802_1x) {
2290 bss->ssid.security_policy = SECURITY_WPA;
2291 } else if (bss->wpa) {
2292 bss->ssid.security_policy = SECURITY_WPA_PSK;
2293 } else if (bss->ieee802_1x) {
2294 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2295 bss->ssid.wep.default_len = bss->default_wep_key_len;
2296 } else if (bss->ssid.wep.keys_set)
2297 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2299 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2302 if (hostapd_config_check(conf))
2306 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2307 "'%s'", errors, fname);
2308 hostapd_config_free(conf);
2316 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2320 if (a->idx != b->idx || a->default_len != b->default_len)
2322 for (i = 0; i < NUM_WEP_KEYS; i++)
2323 if (a->len[i] != b->len[i] ||
2324 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2330 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2335 for (i = 0; i < num_servers; i++) {
2336 os_free(servers[i].shared_secret);
2342 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2344 os_free(user->identity);
2345 os_free(user->password);
2350 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2353 for (i = 0; i < NUM_WEP_KEYS; i++) {
2354 os_free(keys->key[i]);
2355 keys->key[i] = NULL;
2360 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2362 struct hostapd_wpa_psk *psk, *prev;
2363 struct hostapd_eap_user *user, *prev_user;
2368 psk = conf->ssid.wpa_psk;
2375 os_free(conf->ssid.wpa_passphrase);
2376 os_free(conf->ssid.wpa_psk_file);
2377 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2378 os_free(conf->ssid.vlan_tagged_interface);
2379 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2381 user = conf->eap_user;
2385 hostapd_config_free_eap_user(prev_user);
2388 os_free(conf->dump_log_name);
2389 os_free(conf->eap_req_id_text);
2390 os_free(conf->accept_mac);
2391 os_free(conf->deny_mac);
2392 os_free(conf->nas_identifier);
2393 hostapd_config_free_radius(conf->radius->auth_servers,
2394 conf->radius->num_auth_servers);
2395 hostapd_config_free_radius(conf->radius->acct_servers,
2396 conf->radius->num_acct_servers);
2397 os_free(conf->rsn_preauth_interfaces);
2398 os_free(conf->ctrl_interface);
2399 os_free(conf->ca_cert);
2400 os_free(conf->server_cert);
2401 os_free(conf->private_key);
2402 os_free(conf->private_key_passwd);
2403 os_free(conf->dh_file);
2404 os_free(conf->pac_opaque_encr_key);
2405 os_free(conf->eap_fast_a_id);
2406 os_free(conf->eap_fast_a_id_info);
2407 os_free(conf->eap_sim_db);
2408 os_free(conf->radius_server_clients);
2409 os_free(conf->test_socket);
2410 os_free(conf->radius);
2411 hostapd_config_free_vlan(conf);
2412 if (conf->ssid.dyn_vlan_keys) {
2413 struct hostapd_ssid *ssid = &conf->ssid;
2415 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2416 if (ssid->dyn_vlan_keys[i] == NULL)
2418 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2419 os_free(ssid->dyn_vlan_keys[i]);
2421 os_free(ssid->dyn_vlan_keys);
2422 ssid->dyn_vlan_keys = NULL;
2425 #ifdef CONFIG_IEEE80211R
2427 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2428 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2430 r0kh = conf->r0kh_list;
2431 conf->r0kh_list = NULL;
2438 r1kh = conf->r1kh_list;
2439 conf->r1kh_list = NULL;
2446 #endif /* CONFIG_IEEE80211R */
2449 os_free(conf->wps_pin_requests);
2450 os_free(conf->device_name);
2451 os_free(conf->manufacturer);
2452 os_free(conf->model_name);
2453 os_free(conf->model_number);
2454 os_free(conf->serial_number);
2455 os_free(conf->device_type);
2456 os_free(conf->config_methods);
2457 os_free(conf->ap_pin);
2458 os_free(conf->extra_cred);
2459 os_free(conf->ap_settings);
2460 os_free(conf->upnp_iface);
2461 os_free(conf->friendly_name);
2462 os_free(conf->manufacturer_url);
2463 os_free(conf->model_description);
2464 os_free(conf->model_url);
2466 #endif /* CONFIG_WPS */
2471 * hostapd_config_free - Free hostapd configuration
2472 * @conf: Configuration data from hostapd_config_read().
2474 void hostapd_config_free(struct hostapd_config *conf)
2481 for (i = 0; i < conf->num_bss; i++)
2482 hostapd_config_free_bss(&conf->bss[i]);
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)