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 #ifndef CONFIG_NO_VLAN
38 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
42 char buf[128], *pos, *pos2;
43 int line = 0, vlan_id;
44 struct hostapd_vlan *vlan;
46 f = fopen(fname, "r");
48 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
52 while (fgets(buf, sizeof(buf), f)) {
58 while (*pos != '\0') {
69 vlan_id = VLAN_ID_WILDCARD;
72 vlan_id = strtol(buf, &pos, 10);
73 if (buf == pos || vlan_id < 1 ||
74 vlan_id > MAX_VLAN_ID) {
75 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
76 "line %d in '%s'", line, fname);
82 while (*pos == ' ' || *pos == '\t')
85 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
88 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
89 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
90 "in '%s'", line, fname);
95 vlan = os_malloc(sizeof(*vlan));
97 wpa_printf(MSG_ERROR, "Out of memory while reading "
98 "VLAN interfaces from '%s'", fname);
103 os_memset(vlan, 0, sizeof(*vlan));
104 vlan->vlan_id = vlan_id;
105 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
107 bss->vlan_tail->next = vlan;
110 bss->vlan_tail = vlan;
117 #endif /* CONFIG_NO_VLAN */
120 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
122 struct hostapd_vlan *vlan, *prev;
136 /* convert floats with one decimal place to value*10 int, i.e.,
137 * "1.5" will return 15 */
138 static int hostapd_config_read_int10(const char *value)
144 pos = os_strchr(value, '.');
148 if (*pos >= '0' && *pos <= '9')
156 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
158 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
159 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
160 bss->logger_syslog = (unsigned int) -1;
161 bss->logger_stdout = (unsigned int) -1;
163 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
165 bss->wep_rekeying_period = 300;
166 /* use key0 in individual key and key1 in broadcast key */
167 bss->broadcast_key_idx_min = 1;
168 bss->broadcast_key_idx_max = 2;
169 bss->eap_reauth_period = 3600;
171 bss->wpa_group_rekey = 600;
172 bss->wpa_gmk_rekey = 86400;
173 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
174 bss->wpa_pairwise = WPA_CIPHER_TKIP;
175 bss->wpa_group = WPA_CIPHER_TKIP;
176 bss->rsn_pairwise = 0;
178 bss->max_num_sta = MAX_STA_COUNT;
180 bss->dtim_period = 2;
182 bss->radius_server_auth_port = 1812;
183 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
184 bss->eapol_version = EAPOL_VERSION;
186 bss->max_listen_interval = 65535;
188 #ifdef CONFIG_IEEE80211W
189 bss->assoc_sa_query_max_timeout = 1000;
190 bss->assoc_sa_query_retry_timeout = 201;
191 #endif /* CONFIG_IEEE80211W */
193 /* both anonymous and authenticated provisioning */
194 bss->eap_fast_prov = 3;
195 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
196 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
197 #endif /* EAP_FAST */
201 static struct hostapd_config * hostapd_config_defaults(void)
203 struct hostapd_config *conf;
204 struct hostapd_bss_config *bss;
206 const int aCWmin = 15, aCWmax = 1024;
207 const struct hostapd_wme_ac_params ac_bk =
208 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
209 const struct hostapd_wme_ac_params ac_be =
210 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
211 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
212 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
213 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
214 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
216 conf = os_zalloc(sizeof(*conf));
217 bss = os_zalloc(sizeof(*bss));
218 if (conf == NULL || bss == NULL) {
219 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
220 "configuration data.");
226 /* set default driver based on configuration */
227 conf->driver = hostapd_drivers[0];
228 if (conf->driver == NULL) {
229 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
235 bss->radius = os_zalloc(sizeof(*bss->radius));
236 if (bss->radius == NULL) {
242 hostapd_config_defaults_bss(bss);
247 conf->beacon_int = 100;
248 conf->rts_threshold = -1; /* use driver default: 2347 */
249 conf->fragm_threshold = -1; /* user driver default: 2346 */
250 conf->send_probe_response = 1;
251 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
253 os_memcpy(conf->country, "US ", 3);
255 for (i = 0; i < NUM_TX_QUEUES; i++)
256 conf->tx_queue[i].aifs = -1; /* use hw default */
258 conf->wme_ac_params[0] = ac_be;
259 conf->wme_ac_params[1] = ac_bk;
260 conf->wme_ac_params[2] = ac_vi;
261 conf->wme_ac_params[3] = ac_vo;
263 #ifdef CONFIG_IEEE80211N
264 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
265 #endif /* CONFIG_IEEE80211N */
271 int hostapd_mac_comp(const void *a, const void *b)
273 return os_memcmp(a, b, sizeof(macaddr));
277 int hostapd_mac_comp_empty(const void *a)
279 macaddr empty = { 0 };
280 return os_memcmp(a, empty, sizeof(macaddr));
284 static int hostapd_acl_comp(const void *a, const void *b)
286 const struct mac_acl_entry *aa = a;
287 const struct mac_acl_entry *bb = b;
288 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
292 static int hostapd_config_read_maclist(const char *fname,
293 struct mac_acl_entry **acl, int *num)
299 struct mac_acl_entry *newacl;
305 f = fopen(fname, "r");
307 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
311 while (fgets(buf, sizeof(buf), f)) {
317 while (*pos != '\0') {
327 if (hwaddr_aton(buf, addr)) {
328 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
329 "line %d in '%s'", buf, line, fname);
336 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
338 while (*pos == ' ' || *pos == '\t')
343 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
344 if (newacl == NULL) {
345 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
351 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
352 (*acl)[*num].vlan_id = vlan_id;
358 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
364 static int hostapd_config_read_wpa_psk(const char *fname,
365 struct hostapd_ssid *ssid)
369 int line = 0, ret = 0, len, ok;
371 struct hostapd_wpa_psk *psk;
376 f = fopen(fname, "r");
378 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
382 while (fgets(buf, sizeof(buf), f)) {
388 while (*pos != '\0') {
398 if (hwaddr_aton(buf, addr)) {
399 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
400 "line %d in '%s'", buf, line, fname);
405 psk = os_zalloc(sizeof(*psk));
407 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
411 if (is_zero_ether_addr(addr))
414 os_memcpy(psk->addr, addr, ETH_ALEN);
418 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
427 len = os_strlen(pos);
428 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
430 else if (len >= 8 && len < 64) {
431 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
432 4096, psk->psk, PMK_LEN);
436 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
437 "'%s'", pos, line, fname);
443 psk->next = ssid->wpa_psk;
453 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
455 struct hostapd_ssid *ssid = &conf->ssid;
457 if (ssid->wpa_passphrase != NULL) {
458 if (ssid->wpa_psk != NULL) {
459 wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
460 "passphrase set. Using passphrase.");
461 os_free(ssid->wpa_psk);
463 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
464 if (ssid->wpa_psk == NULL) {
465 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
468 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
469 (u8 *) ssid->ssid, ssid->ssid_len);
470 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
471 (u8 *) ssid->wpa_passphrase,
472 os_strlen(ssid->wpa_passphrase));
473 pbkdf2_sha1(ssid->wpa_passphrase,
474 ssid->ssid, ssid->ssid_len,
475 4096, ssid->wpa_psk->psk, PMK_LEN);
476 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
477 ssid->wpa_psk->psk, PMK_LEN);
478 ssid->wpa_psk->group = 1;
480 os_memset(ssid->wpa_passphrase, 0,
481 os_strlen(ssid->wpa_passphrase));
482 os_free(ssid->wpa_passphrase);
483 ssid->wpa_passphrase = NULL;
486 if (ssid->wpa_psk_file) {
487 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
497 static int hostapd_config_read_eap_user(const char *fname,
498 struct hostapd_bss_config *conf)
501 char buf[512], *pos, *start, *pos2;
502 int line = 0, ret = 0, num_methods;
503 struct hostapd_eap_user *user, *tail = NULL;
508 f = fopen(fname, "r");
510 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
514 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
515 while (fgets(buf, sizeof(buf), f)) {
521 while (*pos != '\0') {
533 if (buf[0] != '"' && buf[0] != '*') {
534 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
535 "start) on line %d in '%s'", line, fname);
539 user = os_zalloc(sizeof(*user));
541 wpa_printf(MSG_ERROR, "EAP user allocation failed");
544 user->force_version = -1;
551 while (*pos != '"' && *pos != '\0')
554 wpa_printf(MSG_ERROR, "Invalid EAP identity "
555 "(no \" in end) on line %d in '%s'",
560 user->identity = os_malloc(pos - start);
561 if (user->identity == NULL) {
562 wpa_printf(MSG_ERROR, "Failed to allocate "
563 "memory for EAP identity");
566 os_memcpy(user->identity, start, pos - start);
567 user->identity_len = pos - start;
569 if (pos[0] == '"' && pos[1] == '*') {
570 user->wildcard_prefix = 1;
575 while (*pos == ' ' || *pos == '\t')
579 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
580 "'%s'", line, fname);
585 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
595 char *pos3 = os_strchr(start, ',');
599 user->methods[num_methods].method =
602 &user->methods[num_methods].vendor);
603 if (user->methods[num_methods].vendor ==
605 user->methods[num_methods].method == EAP_TYPE_NONE)
607 if (os_strcmp(start, "TTLS-PAP") == 0) {
608 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
611 if (os_strcmp(start, "TTLS-CHAP") == 0) {
612 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
615 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
617 EAP_TTLS_AUTH_MSCHAP;
620 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
622 EAP_TTLS_AUTH_MSCHAPV2;
625 wpa_printf(MSG_ERROR, "Unsupported EAP type "
626 "'%s' on line %d in '%s'",
632 if (num_methods >= EAP_USER_MAX_METHODS)
639 if (num_methods == 0 && user->ttls_auth == 0) {
640 wpa_printf(MSG_ERROR, "No EAP types configured on "
641 "line %d in '%s'", line, fname);
648 while (*pos == ' ' || *pos == '\t')
653 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
654 user->force_version = 0;
658 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
659 user->force_version = 1;
663 if (os_strncmp(pos, "[2]", 3) == 0) {
671 while (*pos != '"' && *pos != '\0')
674 wpa_printf(MSG_ERROR, "Invalid EAP password "
675 "(no \" in end) on line %d in '%s'",
680 user->password = os_malloc(pos - start);
681 if (user->password == NULL) {
682 wpa_printf(MSG_ERROR, "Failed to allocate "
683 "memory for EAP password");
686 os_memcpy(user->password, start, pos - start);
687 user->password_len = pos - start;
690 } else if (os_strncmp(pos, "hash:", 5) == 0) {
693 while (*pos2 != '\0' && *pos2 != ' ' &&
694 *pos2 != '\t' && *pos2 != '#')
696 if (pos2 - pos != 32) {
697 wpa_printf(MSG_ERROR, "Invalid password hash "
698 "on line %d in '%s'", line, fname);
701 user->password = os_malloc(16);
702 if (user->password == NULL) {
703 wpa_printf(MSG_ERROR, "Failed to allocate "
704 "memory for EAP password hash");
707 if (hexstr2bin(pos, user->password, 16) < 0) {
708 wpa_printf(MSG_ERROR, "Invalid hash password "
709 "on line %d in '%s'", line, fname);
712 user->password_len = 16;
713 user->password_hash = 1;
717 while (*pos2 != '\0' && *pos2 != ' ' &&
718 *pos2 != '\t' && *pos2 != '#')
720 if ((pos2 - pos) & 1) {
721 wpa_printf(MSG_ERROR, "Invalid hex password "
722 "on line %d in '%s'", line, fname);
725 user->password = os_malloc((pos2 - pos) / 2);
726 if (user->password == NULL) {
727 wpa_printf(MSG_ERROR, "Failed to allocate "
728 "memory for EAP password");
731 if (hexstr2bin(pos, user->password,
732 (pos2 - pos) / 2) < 0) {
733 wpa_printf(MSG_ERROR, "Invalid hex password "
734 "on line %d in '%s'", line, fname);
737 user->password_len = (pos2 - pos) / 2;
741 while (*pos == ' ' || *pos == '\t')
743 if (os_strncmp(pos, "[2]", 3) == 0) {
749 tail = conf->eap_user = user;
758 os_free(user->password);
759 os_free(user->identity);
770 #endif /* EAP_SERVER */
773 #ifndef CONFIG_NO_RADIUS
775 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
776 int *num_server, const char *val, int def_port,
777 struct hostapd_radius_server **curr_serv)
779 struct hostapd_radius_server *nserv;
781 static int server_index = 1;
783 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
788 nserv = &nserv[*num_server];
790 (*curr_serv) = nserv;
792 os_memset(nserv, 0, sizeof(*nserv));
793 nserv->port = def_port;
794 ret = hostapd_parse_ip_addr(val, &nserv->addr);
795 nserv->index = server_index++;
799 #endif /* CONFIG_NO_RADIUS */
802 static int hostapd_config_parse_key_mgmt(int line, const char *value)
805 char *start, *end, *buf;
807 buf = os_strdup(value);
812 while (*start != '\0') {
813 while (*start == ' ' || *start == '\t')
818 while (*end != ' ' && *end != '\t' && *end != '\0')
822 if (os_strcmp(start, "WPA-PSK") == 0)
823 val |= WPA_KEY_MGMT_PSK;
824 else if (os_strcmp(start, "WPA-EAP") == 0)
825 val |= WPA_KEY_MGMT_IEEE8021X;
826 #ifdef CONFIG_IEEE80211R
827 else if (os_strcmp(start, "FT-PSK") == 0)
828 val |= WPA_KEY_MGMT_FT_PSK;
829 else if (os_strcmp(start, "FT-EAP") == 0)
830 val |= WPA_KEY_MGMT_FT_IEEE8021X;
831 #endif /* CONFIG_IEEE80211R */
832 #ifdef CONFIG_IEEE80211W
833 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
834 val |= WPA_KEY_MGMT_PSK_SHA256;
835 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
836 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
837 #endif /* CONFIG_IEEE80211W */
839 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
852 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
853 "configured.", line);
861 static int hostapd_config_parse_cipher(int line, const char *value)
864 char *start, *end, *buf;
866 buf = os_strdup(value);
871 while (*start != '\0') {
872 while (*start == ' ' || *start == '\t')
877 while (*end != ' ' && *end != '\t' && *end != '\0')
881 if (os_strcmp(start, "CCMP") == 0)
882 val |= WPA_CIPHER_CCMP;
883 else if (os_strcmp(start, "TKIP") == 0)
884 val |= WPA_CIPHER_TKIP;
885 else if (os_strcmp(start, "WEP104") == 0)
886 val |= WPA_CIPHER_WEP104;
887 else if (os_strcmp(start, "WEP40") == 0)
888 val |= WPA_CIPHER_WEP40;
889 else if (os_strcmp(start, "NONE") == 0)
890 val |= WPA_CIPHER_NONE;
892 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
905 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
913 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
914 struct hostapd_config *conf)
916 if (bss->ieee802_1x && !bss->eap_server &&
917 !bss->radius->auth_servers) {
918 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
919 "EAP authenticator configured).");
923 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
924 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
925 bss->ssid.wpa_psk_file == NULL) {
926 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
927 "is not configured.");
931 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
934 for (i = 0; i < conf->num_bss; i++) {
935 if ((&conf->bss[i] != bss) &&
936 (hostapd_mac_comp(conf->bss[i].bssid,
938 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
939 " on interface '%s' and '%s'.",
941 conf->bss[i].iface, bss->iface);
947 #ifdef CONFIG_IEEE80211R
948 if ((bss->wpa_key_mgmt &
949 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
950 (bss->nas_identifier == NULL ||
951 os_strlen(bss->nas_identifier) < 1 ||
952 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
953 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
954 "nas_identifier to be configured as a 1..48 octet "
958 #endif /* CONFIG_IEEE80211R */
960 #ifdef CONFIG_IEEE80211N
961 if (conf->ieee80211n && bss->wpa &&
962 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
963 !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
964 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
965 "requires CCMP to be enabled");
968 #endif /* CONFIG_IEEE80211N */
974 static int hostapd_config_check(struct hostapd_config *conf)
978 for (i = 0; i < conf->num_bss; i++) {
979 if (hostapd_config_check_bss(&conf->bss[i], conf))
987 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
990 size_t len = os_strlen(val);
992 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
996 if (len < 2 || val[len - 1] != '"')
999 wep->key[keyidx] = os_malloc(len);
1000 if (wep->key[keyidx] == NULL)
1002 os_memcpy(wep->key[keyidx], val + 1, len);
1003 wep->len[keyidx] = len;
1008 wep->key[keyidx] = os_malloc(len);
1009 if (wep->key[keyidx] == NULL)
1011 wep->len[keyidx] = len;
1012 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1022 static int hostapd_parse_rates(int **rate_list, char *val)
1028 os_free(*rate_list);
1033 while (*pos != '\0') {
1039 list = os_malloc(sizeof(int) * (count + 2));
1044 while (*pos != '\0') {
1045 end = os_strchr(pos, ' ');
1049 list[count++] = atoi(pos);
1061 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1063 struct hostapd_bss_config *bss;
1065 if (*ifname == '\0')
1068 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1069 sizeof(struct hostapd_bss_config));
1071 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1077 bss = &(conf->bss[conf->num_bss]);
1078 os_memset(bss, 0, sizeof(*bss));
1079 bss->radius = os_zalloc(sizeof(*bss->radius));
1080 if (bss->radius == NULL) {
1081 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
1082 "multi-BSS RADIUS data");
1087 conf->last_bss = bss;
1089 hostapd_config_defaults_bss(bss);
1090 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1091 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1097 static int valid_cw(int cw)
1099 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1100 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1105 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1106 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1107 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1108 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1109 IEEE80211_TX_QUEUE_DATA4 = 4,
1110 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1111 IEEE80211_TX_QUEUE_BEACON = 7
1114 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1119 struct hostapd_tx_queue_params *queue;
1121 /* skip 'tx_queue_' prefix */
1123 if (os_strncmp(pos, "data", 4) == 0 &&
1124 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1127 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1128 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1130 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1131 num = IEEE80211_TX_QUEUE_BEACON;
1134 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1138 queue = &conf->tx_queue[num];
1140 if (os_strcmp(pos, "aifs") == 0) {
1141 queue->aifs = atoi(val);
1142 if (queue->aifs < 0 || queue->aifs > 255) {
1143 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1147 } else if (os_strcmp(pos, "cwmin") == 0) {
1148 queue->cwmin = atoi(val);
1149 if (!valid_cw(queue->cwmin)) {
1150 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1154 } else if (os_strcmp(pos, "cwmax") == 0) {
1155 queue->cwmax = atoi(val);
1156 if (!valid_cw(queue->cwmax)) {
1157 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1161 } else if (os_strcmp(pos, "burst") == 0) {
1162 queue->burst = hostapd_config_read_int10(val);
1164 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1168 queue->configured = 1;
1174 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1179 struct hostapd_wme_ac_params *ac;
1181 /* skip 'wme_ac_' prefix */
1183 if (os_strncmp(pos, "be_", 3) == 0) {
1186 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1189 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1192 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1196 wpa_printf(MSG_ERROR, "Unknown wme name '%s'", pos);
1200 ac = &conf->wme_ac_params[num];
1202 if (os_strcmp(pos, "aifs") == 0) {
1204 if (v < 1 || v > 255) {
1205 wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
1209 } else if (os_strcmp(pos, "cwmin") == 0) {
1211 if (v < 0 || v > 12) {
1212 wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
1216 } else if (os_strcmp(pos, "cwmax") == 0) {
1218 if (v < 0 || v > 12) {
1219 wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
1223 } else if (os_strcmp(pos, "txop_limit") == 0) {
1225 if (v < 0 || v > 0xffff) {
1226 wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
1230 } else if (os_strcmp(pos, "acm") == 0) {
1232 if (v < 0 || v > 1) {
1233 wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
1236 ac->admission_control_mandatory = v;
1238 wpa_printf(MSG_ERROR, "Unknown wme_ac_ field '%s'", pos);
1246 #ifdef CONFIG_IEEE80211R
1247 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1249 struct ft_remote_r0kh *r0kh;
1252 r0kh = os_zalloc(sizeof(*r0kh));
1256 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1258 next = os_strchr(pos, ' ');
1261 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1262 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1268 next = os_strchr(pos, ' ');
1271 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1272 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1276 r0kh->id_len = next - pos - 1;
1277 os_memcpy(r0kh->id, pos, r0kh->id_len);
1280 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1281 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1286 r0kh->next = bss->r0kh_list;
1287 bss->r0kh_list = r0kh;
1293 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1295 struct ft_remote_r1kh *r1kh;
1298 r1kh = os_zalloc(sizeof(*r1kh));
1302 /* 02:01:02:03:04:05 02:01:02:03:04:05
1303 * 000102030405060708090a0b0c0d0e0f */
1305 next = os_strchr(pos, ' ');
1308 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1309 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1315 next = os_strchr(pos, ' ');
1318 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1319 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1325 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1326 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1331 r1kh->next = bss->r1kh_list;
1332 bss->r1kh_list = r1kh;
1336 #endif /* CONFIG_IEEE80211R */
1339 #ifdef CONFIG_IEEE80211N
1340 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1343 if (os_strstr(capab, "[LDPC]"))
1344 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1345 if (os_strstr(capab, "[HT40-]")) {
1346 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1347 conf->secondary_channel = -1;
1349 if (os_strstr(capab, "[HT40+]")) {
1350 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1351 conf->secondary_channel = 1;
1353 if (os_strstr(capab, "[SMPS-STATIC]")) {
1354 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1355 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1357 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1358 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1359 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1361 if (os_strstr(capab, "[GF]"))
1362 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1363 if (os_strstr(capab, "[SHORT-GI-20]"))
1364 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1365 if (os_strstr(capab, "[SHORT-GI-40]"))
1366 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1367 if (os_strstr(capab, "[TX-STBC]"))
1368 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1369 if (os_strstr(capab, "[RX-STBC1]")) {
1370 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1371 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1373 if (os_strstr(capab, "[RX-STBC12]")) {
1374 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1375 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1377 if (os_strstr(capab, "[RX-STBC123]")) {
1378 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1379 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1381 if (os_strstr(capab, "[DELAYED-BA]"))
1382 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1383 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1384 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1385 if (os_strstr(capab, "[DSSS_CCK-40]"))
1386 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1387 if (os_strstr(capab, "[PSMP]"))
1388 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1389 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1390 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1394 #endif /* CONFIG_IEEE80211N */
1398 * hostapd_config_read - Read and parse a configuration file
1399 * @fname: Configuration file name (including path, if needed)
1400 * Returns: Allocated configuration data structure
1402 struct hostapd_config * hostapd_config_read(const char *fname)
1404 struct hostapd_config *conf;
1405 struct hostapd_bss_config *bss;
1407 char buf[256], *pos;
1413 f = fopen(fname, "r");
1415 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
1416 "for reading.", fname);
1420 conf = hostapd_config_defaults();
1425 bss = conf->last_bss = conf->bss;
1427 while (fgets(buf, sizeof(buf), f)) {
1428 bss = conf->last_bss;
1434 while (*pos != '\0') {
1444 pos = os_strchr(buf, '=');
1446 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
1454 if (os_strcmp(buf, "interface") == 0) {
1455 os_strlcpy(conf->bss[0].iface, pos,
1456 sizeof(conf->bss[0].iface));
1457 } else if (os_strcmp(buf, "bridge") == 0) {
1458 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1459 } else if (os_strcmp(buf, "driver") == 0) {
1461 /* clear to get error below if setting is invalid */
1462 conf->driver = NULL;
1463 for (i = 0; hostapd_drivers[i]; i++) {
1464 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1466 conf->driver = hostapd_drivers[i];
1470 if (conf->driver == NULL) {
1471 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1472 "unknown driver '%s'", line, pos);
1475 } else if (os_strcmp(buf, "debug") == 0) {
1476 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1477 "configuration variable is not used "
1479 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1480 bss->logger_syslog_level = atoi(pos);
1481 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1482 bss->logger_stdout_level = atoi(pos);
1483 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1484 bss->logger_syslog = atoi(pos);
1485 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1486 bss->logger_stdout = atoi(pos);
1487 } else if (os_strcmp(buf, "dump_file") == 0) {
1488 bss->dump_log_name = os_strdup(pos);
1489 } else if (os_strcmp(buf, "ssid") == 0) {
1490 bss->ssid.ssid_len = os_strlen(pos);
1491 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1492 bss->ssid.ssid_len < 1) {
1493 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1497 os_memcpy(bss->ssid.ssid, pos,
1498 bss->ssid.ssid_len);
1499 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1500 bss->ssid.ssid_set = 1;
1502 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1503 bss->macaddr_acl = atoi(pos);
1504 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1505 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1506 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1507 wpa_printf(MSG_ERROR, "Line %d: unknown "
1509 line, bss->macaddr_acl);
1511 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1512 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1513 &bss->num_accept_mac))
1515 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1516 "read accept_mac_file '%s'",
1520 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1521 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1522 &bss->num_deny_mac)) {
1523 wpa_printf(MSG_ERROR "Line %d: Failed to read "
1524 "deny_mac_file '%s'", line, pos);
1527 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1528 bss->ap_max_inactivity = atoi(pos);
1529 } else if (os_strcmp(buf, "country_code") == 0) {
1530 os_memcpy(conf->country, pos, 2);
1531 /* FIX: make this configurable */
1532 conf->country[2] = ' ';
1533 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1534 conf->ieee80211d = atoi(pos);
1535 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1536 bss->ieee802_1x = atoi(pos);
1537 } else if (os_strcmp(buf, "eapol_version") == 0) {
1538 bss->eapol_version = atoi(pos);
1539 if (bss->eapol_version < 1 ||
1540 bss->eapol_version > 2) {
1541 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1542 "version (%d): '%s'.",
1543 line, bss->eapol_version, pos);
1546 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1547 bss->eapol_version);
1549 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1550 bss->eap_server = atoi(pos);
1551 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1552 "eap_authenticator used; this has been "
1553 "renamed to eap_server", line);
1554 } else if (os_strcmp(buf, "eap_server") == 0) {
1555 bss->eap_server = atoi(pos);
1556 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1557 if (hostapd_config_read_eap_user(pos, bss))
1559 } else if (os_strcmp(buf, "ca_cert") == 0) {
1560 os_free(bss->ca_cert);
1561 bss->ca_cert = os_strdup(pos);
1562 } else if (os_strcmp(buf, "server_cert") == 0) {
1563 os_free(bss->server_cert);
1564 bss->server_cert = os_strdup(pos);
1565 } else if (os_strcmp(buf, "private_key") == 0) {
1566 os_free(bss->private_key);
1567 bss->private_key = os_strdup(pos);
1568 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1569 os_free(bss->private_key_passwd);
1570 bss->private_key_passwd = os_strdup(pos);
1571 } else if (os_strcmp(buf, "check_crl") == 0) {
1572 bss->check_crl = atoi(pos);
1573 } else if (os_strcmp(buf, "dh_file") == 0) {
1574 os_free(bss->dh_file);
1575 bss->dh_file = os_strdup(pos);
1577 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1578 os_free(bss->pac_opaque_encr_key);
1579 bss->pac_opaque_encr_key = os_malloc(16);
1580 if (bss->pac_opaque_encr_key == NULL) {
1581 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1582 "pac_opaque_encr_key", line);
1584 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1586 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1587 "pac_opaque_encr_key", line);
1590 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1591 size_t idlen = os_strlen(pos);
1593 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1594 "eap_fast_a_id", line);
1597 os_free(bss->eap_fast_a_id);
1598 bss->eap_fast_a_id = os_malloc(idlen / 2);
1599 if (bss->eap_fast_a_id == NULL ||
1600 hexstr2bin(pos, bss->eap_fast_a_id,
1602 wpa_printf(MSG_ERROR, "Line %d: "
1604 "eap_fast_a_id", line);
1607 bss->eap_fast_a_id_len = idlen / 2;
1609 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1610 os_free(bss->eap_fast_a_id_info);
1611 bss->eap_fast_a_id_info = os_strdup(pos);
1612 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1613 bss->eap_fast_prov = atoi(pos);
1614 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1615 bss->pac_key_lifetime = atoi(pos);
1616 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1617 bss->pac_key_refresh_time = atoi(pos);
1618 #endif /* EAP_FAST */
1620 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1621 os_free(bss->eap_sim_db);
1622 bss->eap_sim_db = os_strdup(pos);
1623 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1624 bss->eap_sim_aka_result_ind = atoi(pos);
1625 #endif /* EAP_SIM */
1627 } else if (os_strcmp(buf, "tnc") == 0) {
1628 bss->tnc = atoi(pos);
1629 #endif /* EAP_TNC */
1630 #endif /* EAP_SERVER */
1631 } else if (os_strcmp(buf, "eap_message") == 0) {
1633 bss->eap_req_id_text = os_strdup(pos);
1634 if (bss->eap_req_id_text == NULL) {
1635 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1636 "allocate memory for "
1637 "eap_req_id_text", line);
1641 bss->eap_req_id_text_len =
1642 os_strlen(bss->eap_req_id_text);
1643 term = os_strstr(bss->eap_req_id_text, "\\0");
1646 os_memmove(term, term + 1,
1647 bss->eap_req_id_text_len -
1648 (term - bss->eap_req_id_text) - 1);
1649 bss->eap_req_id_text_len--;
1651 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1652 bss->default_wep_key_len = atoi(pos);
1653 if (bss->default_wep_key_len > 13) {
1654 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1655 "key len %lu (= %lu bits)", line,
1657 bss->default_wep_key_len,
1659 bss->default_wep_key_len * 8);
1662 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1663 bss->individual_wep_key_len = atoi(pos);
1664 if (bss->individual_wep_key_len < 0 ||
1665 bss->individual_wep_key_len > 13) {
1666 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1667 "key len %d (= %d bits)", line,
1668 bss->individual_wep_key_len,
1669 bss->individual_wep_key_len * 8);
1672 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1673 bss->wep_rekeying_period = atoi(pos);
1674 if (bss->wep_rekeying_period < 0) {
1675 wpa_printf(MSG_ERROR, "Line %d: invalid "
1677 line, bss->wep_rekeying_period);
1680 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1681 bss->eap_reauth_period = atoi(pos);
1682 if (bss->eap_reauth_period < 0) {
1683 wpa_printf(MSG_ERROR, "Line %d: invalid "
1685 line, bss->eap_reauth_period);
1688 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1689 bss->eapol_key_index_workaround = atoi(pos);
1691 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1692 bss->ieee802_11f = 1;
1693 os_strlcpy(bss->iapp_iface, pos,
1694 sizeof(bss->iapp_iface));
1695 #endif /* CONFIG_IAPP */
1696 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1697 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1698 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1699 "address '%s'", line, pos);
1702 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1703 bss->nas_identifier = os_strdup(pos);
1704 #ifndef CONFIG_NO_RADIUS
1705 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1706 if (hostapd_config_read_radius_addr(
1707 &bss->radius->auth_servers,
1708 &bss->radius->num_auth_servers, pos, 1812,
1709 &bss->radius->auth_server)) {
1710 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1711 "address '%s'", line, pos);
1714 } else if (bss->radius->auth_server &&
1715 os_strcmp(buf, "auth_server_port") == 0) {
1716 bss->radius->auth_server->port = atoi(pos);
1717 } else if (bss->radius->auth_server &&
1718 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1719 int len = os_strlen(pos);
1721 /* RFC 2865, Ch. 3 */
1722 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1723 "secret is not allowed.", line);
1726 bss->radius->auth_server->shared_secret =
1727 (u8 *) os_strdup(pos);
1728 bss->radius->auth_server->shared_secret_len = len;
1729 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1730 if (hostapd_config_read_radius_addr(
1731 &bss->radius->acct_servers,
1732 &bss->radius->num_acct_servers, pos, 1813,
1733 &bss->radius->acct_server)) {
1734 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1735 "address '%s'", line, pos);
1738 } else if (bss->radius->acct_server &&
1739 os_strcmp(buf, "acct_server_port") == 0) {
1740 bss->radius->acct_server->port = atoi(pos);
1741 } else if (bss->radius->acct_server &&
1742 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1743 int len = os_strlen(pos);
1745 /* RFC 2865, Ch. 3 */
1746 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1747 "secret is not allowed.", line);
1750 bss->radius->acct_server->shared_secret =
1751 (u8 *) os_strdup(pos);
1752 bss->radius->acct_server->shared_secret_len = len;
1753 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1755 bss->radius->retry_primary_interval = atoi(pos);
1756 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1758 bss->radius->acct_interim_interval = atoi(pos);
1759 #endif /* CONFIG_NO_RADIUS */
1760 } else if (os_strcmp(buf, "auth_algs") == 0) {
1761 bss->auth_algs = atoi(pos);
1762 if (bss->auth_algs == 0) {
1763 wpa_printf(MSG_ERROR, "Line %d: no "
1764 "authentication algorithms allowed",
1768 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1769 bss->max_num_sta = atoi(pos);
1770 if (bss->max_num_sta < 0 ||
1771 bss->max_num_sta > MAX_STA_COUNT) {
1772 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1773 "max_num_sta=%d; allowed range "
1774 "0..%d", line, bss->max_num_sta,
1778 } else if (os_strcmp(buf, "wpa") == 0) {
1779 bss->wpa = atoi(pos);
1780 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1781 bss->wpa_group_rekey = atoi(pos);
1782 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1783 bss->wpa_strict_rekey = atoi(pos);
1784 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1785 bss->wpa_gmk_rekey = atoi(pos);
1786 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1787 bss->wpa_ptk_rekey = atoi(pos);
1788 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1789 int len = os_strlen(pos);
1790 if (len < 8 || len > 63) {
1791 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
1792 "passphrase length %d (expected "
1793 "8..63)", line, len);
1796 os_free(bss->ssid.wpa_passphrase);
1797 bss->ssid.wpa_passphrase = os_strdup(pos);
1799 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1800 os_free(bss->ssid.wpa_psk);
1802 os_zalloc(sizeof(struct hostapd_wpa_psk));
1803 if (bss->ssid.wpa_psk == NULL)
1805 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1807 pos[PMK_LEN * 2] != '\0') {
1808 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
1809 "'%s'.", line, pos);
1812 bss->ssid.wpa_psk->group = 1;
1814 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1815 os_free(bss->ssid.wpa_psk_file);
1816 bss->ssid.wpa_psk_file = os_strdup(pos);
1817 if (!bss->ssid.wpa_psk_file) {
1818 wpa_printf(MSG_ERROR, "Line %d: allocation "
1822 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1824 hostapd_config_parse_key_mgmt(line, pos);
1825 if (bss->wpa_key_mgmt == -1)
1827 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1829 hostapd_config_parse_cipher(line, pos);
1830 if (bss->wpa_pairwise == -1 ||
1831 bss->wpa_pairwise == 0)
1833 else if (bss->wpa_pairwise &
1834 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1835 WPA_CIPHER_WEP104)) {
1836 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1837 "pairwise cipher suite '%s'",
1838 bss->wpa_pairwise, pos);
1841 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1843 hostapd_config_parse_cipher(line, pos);
1844 if (bss->rsn_pairwise == -1 ||
1845 bss->rsn_pairwise == 0)
1847 else if (bss->rsn_pairwise &
1848 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1849 WPA_CIPHER_WEP104)) {
1850 wpa_printf(MSG_ERROR, "Line %d: unsupported "
1851 "pairwise cipher suite '%s'",
1852 bss->rsn_pairwise, pos);
1855 #ifdef CONFIG_RSN_PREAUTH
1856 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1857 bss->rsn_preauth = atoi(pos);
1858 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1859 bss->rsn_preauth_interfaces = os_strdup(pos);
1860 #endif /* CONFIG_RSN_PREAUTH */
1861 #ifdef CONFIG_PEERKEY
1862 } else if (os_strcmp(buf, "peerkey") == 0) {
1863 bss->peerkey = atoi(pos);
1864 #endif /* CONFIG_PEERKEY */
1865 #ifdef CONFIG_IEEE80211R
1866 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1867 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1868 hexstr2bin(pos, bss->mobility_domain,
1869 MOBILITY_DOMAIN_ID_LEN) != 0) {
1870 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1871 "mobility_domain '%s'", line, pos);
1875 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1876 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1877 hexstr2bin(pos, bss->r1_key_holder,
1878 FT_R1KH_ID_LEN) != 0) {
1879 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1880 "r1_key_holder '%s'", line, pos);
1884 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1885 bss->r0_key_lifetime = atoi(pos);
1886 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1887 bss->reassociation_deadline = atoi(pos);
1888 } else if (os_strcmp(buf, "r0kh") == 0) {
1889 if (add_r0kh(bss, pos) < 0) {
1890 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1891 "r0kh '%s'", line, pos);
1895 } else if (os_strcmp(buf, "r1kh") == 0) {
1896 if (add_r1kh(bss, pos) < 0) {
1897 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1898 "r1kh '%s'", line, pos);
1902 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1903 bss->pmk_r1_push = atoi(pos);
1904 #endif /* CONFIG_IEEE80211R */
1905 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1906 os_free(bss->ctrl_interface);
1907 bss->ctrl_interface = os_strdup(pos);
1908 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1909 #ifndef CONFIG_NATIVE_WINDOWS
1912 const char *group = pos;
1914 grp = getgrnam(group);
1916 bss->ctrl_interface_gid = grp->gr_gid;
1917 bss->ctrl_interface_gid_set = 1;
1918 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1919 " (from group name '%s')",
1920 bss->ctrl_interface_gid, group);
1924 /* Group name not found - try to parse this as gid */
1925 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1926 if (*group == '\0' || *endp != '\0') {
1927 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1928 "'%s'", line, group);
1932 bss->ctrl_interface_gid_set = 1;
1933 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1934 bss->ctrl_interface_gid);
1935 #endif /* CONFIG_NATIVE_WINDOWS */
1936 #ifdef RADIUS_SERVER
1937 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1938 os_free(bss->radius_server_clients);
1939 bss->radius_server_clients = os_strdup(pos);
1940 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1941 bss->radius_server_auth_port = atoi(pos);
1942 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1943 bss->radius_server_ipv6 = atoi(pos);
1944 #endif /* RADIUS_SERVER */
1945 } else if (os_strcmp(buf, "test_socket") == 0) {
1946 os_free(bss->test_socket);
1947 bss->test_socket = os_strdup(pos);
1948 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1949 bss->use_pae_group_addr = atoi(pos);
1950 } else if (os_strcmp(buf, "hw_mode") == 0) {
1951 if (os_strcmp(pos, "a") == 0)
1952 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1953 else if (os_strcmp(pos, "b") == 0)
1954 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1955 else if (os_strcmp(pos, "g") == 0)
1956 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1958 wpa_printf(MSG_ERROR, "Line %d: unknown "
1959 "hw_mode '%s'", line, pos);
1962 } else if (os_strcmp(buf, "channel") == 0) {
1963 conf->channel = atoi(pos);
1964 } else if (os_strcmp(buf, "beacon_int") == 0) {
1965 int val = atoi(pos);
1966 /* MIB defines range as 1..65535, but very small values
1967 * cause problems with the current implementation.
1968 * Since it is unlikely that this small numbers are
1969 * useful in real life scenarios, do not allow beacon
1970 * period to be set below 15 TU. */
1971 if (val < 15 || val > 65535) {
1972 wpa_printf(MSG_ERROR, "Line %d: invalid "
1973 "beacon_int %d (expected "
1974 "15..65535)", line, val);
1977 conf->beacon_int = val;
1978 } else if (os_strcmp(buf, "dtim_period") == 0) {
1979 bss->dtim_period = atoi(pos);
1980 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1981 wpa_printf(MSG_ERROR, "Line %d: invalid "
1983 line, bss->dtim_period);
1986 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1987 conf->rts_threshold = atoi(pos);
1988 if (conf->rts_threshold < 0 ||
1989 conf->rts_threshold > 2347) {
1990 wpa_printf(MSG_ERROR, "Line %d: invalid "
1992 line, conf->rts_threshold);
1995 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1996 conf->fragm_threshold = atoi(pos);
1997 if (conf->fragm_threshold < 256 ||
1998 conf->fragm_threshold > 2346) {
1999 wpa_printf(MSG_ERROR, "Line %d: invalid "
2000 "fragm_threshold %d",
2001 line, conf->fragm_threshold);
2004 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2005 int val = atoi(pos);
2006 if (val != 0 && val != 1) {
2007 wpa_printf(MSG_ERROR, "Line %d: invalid "
2008 "send_probe_response %d (expected "
2009 "0 or 1)", line, val);
2011 conf->send_probe_response = val;
2012 } else if (os_strcmp(buf, "supported_rates") == 0) {
2013 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2014 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2018 } else if (os_strcmp(buf, "basic_rates") == 0) {
2019 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2020 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2024 } else if (os_strcmp(buf, "preamble") == 0) {
2026 conf->preamble = SHORT_PREAMBLE;
2028 conf->preamble = LONG_PREAMBLE;
2029 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2030 bss->ignore_broadcast_ssid = atoi(pos);
2031 } else if (os_strcmp(buf, "bridge_packets") == 0) {
2032 conf->bridge_packets = atoi(pos);
2033 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2034 bss->ssid.wep.idx = atoi(pos);
2035 if (bss->ssid.wep.idx > 3) {
2036 wpa_printf(MSG_ERROR, "Invalid "
2037 "wep_default_key index %d",
2041 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2042 os_strcmp(buf, "wep_key1") == 0 ||
2043 os_strcmp(buf, "wep_key2") == 0 ||
2044 os_strcmp(buf, "wep_key3") == 0) {
2045 if (hostapd_config_read_wep(&bss->ssid.wep,
2046 buf[7] - '0', pos)) {
2047 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2048 "key '%s'", line, buf);
2051 #ifndef CONFIG_NO_VLAN
2052 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2053 bss->ssid.dynamic_vlan = atoi(pos);
2054 } else if (os_strcmp(buf, "vlan_file") == 0) {
2055 if (hostapd_config_read_vlan_file(bss, pos)) {
2056 wpa_printf(MSG_ERROR, "Line %d: failed to "
2057 "read VLAN file '%s'", line, pos);
2060 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2061 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2062 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2063 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2064 #endif /* CONFIG_NO_VLAN */
2065 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
2066 conf->passive_scan_interval = atoi(pos);
2067 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
2068 conf->passive_scan_listen = atoi(pos);
2069 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
2070 conf->passive_scan_mode = atoi(pos);
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 bss->wme_enabled = atoi(pos);
2083 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
2084 if (hostapd_config_wme_ac(conf, buf, pos)) {
2085 wpa_printf(MSG_ERROR, "Line %d: invalid wme "
2089 } else if (os_strcmp(buf, "bss") == 0) {
2090 if (hostapd_config_bss(conf, pos)) {
2091 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2095 } else if (os_strcmp(buf, "bssid") == 0) {
2096 if (bss == conf->bss &&
2097 (!conf->driver || !conf->driver->init_bssid)) {
2098 wpa_printf(MSG_ERROR, "Line %d: bssid item "
2099 "not allowed for the default "
2100 "interface and this driver", line);
2102 } else if (hwaddr_aton(pos, bss->bssid)) {
2103 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2107 #ifdef CONFIG_IEEE80211W
2108 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2109 bss->ieee80211w = atoi(pos);
2110 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2111 bss->assoc_sa_query_max_timeout = atoi(pos);
2112 if (bss->assoc_sa_query_max_timeout == 0) {
2113 wpa_printf(MSG_ERROR, "Line %d: invalid "
2114 "assoc_sa_query_max_timeout", line);
2117 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2119 bss->assoc_sa_query_retry_timeout = atoi(pos);
2120 if (bss->assoc_sa_query_retry_timeout == 0) {
2121 wpa_printf(MSG_ERROR, "Line %d: invalid "
2122 "assoc_sa_query_retry_timeout",
2126 #endif /* CONFIG_IEEE80211W */
2127 #ifdef CONFIG_IEEE80211N
2128 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2129 conf->ieee80211n = atoi(pos);
2130 } else if (os_strcmp(buf, "ht_capab") == 0) {
2131 if (hostapd_config_ht_capab(conf, pos) < 0) {
2132 wpa_printf(MSG_ERROR, "Line %d: invalid "
2136 #endif /* CONFIG_IEEE80211N */
2137 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2138 bss->max_listen_interval = atoi(pos);
2139 } else if (os_strcmp(buf, "okc") == 0) {
2140 bss->okc = atoi(pos);
2142 } else if (os_strcmp(buf, "wps_state") == 0) {
2143 bss->wps_state = atoi(pos);
2144 if (bss->wps_state < 0 || bss->wps_state > 2) {
2145 wpa_printf(MSG_ERROR, "Line %d: invalid "
2149 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2150 bss->ap_setup_locked = atoi(pos);
2151 } else if (os_strcmp(buf, "uuid") == 0) {
2152 if (uuid_str2bin(pos, bss->uuid)) {
2153 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2157 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2158 bss->wps_pin_requests = os_strdup(pos);
2159 } else if (os_strcmp(buf, "device_name") == 0) {
2160 if (os_strlen(pos) > 32) {
2161 wpa_printf(MSG_ERROR, "Line %d: Too long "
2162 "device_name", line);
2165 bss->device_name = os_strdup(pos);
2166 } else if (os_strcmp(buf, "manufacturer") == 0) {
2167 if (os_strlen(pos) > 64) {
2168 wpa_printf(MSG_ERROR, "Line %d: Too long "
2169 "manufacturer", line);
2172 bss->manufacturer = os_strdup(pos);
2173 } else if (os_strcmp(buf, "model_name") == 0) {
2174 if (os_strlen(pos) > 32) {
2175 wpa_printf(MSG_ERROR, "Line %d: Too long "
2176 "model_name", line);
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 bss->model_number = os_strdup(pos);
2187 } else if (os_strcmp(buf, "serial_number") == 0) {
2188 if (os_strlen(pos) > 32) {
2189 wpa_printf(MSG_ERROR, "Line %d: Too long "
2190 "serial_number", line);
2193 bss->serial_number = os_strdup(pos);
2194 } else if (os_strcmp(buf, "device_type") == 0) {
2195 bss->device_type = os_strdup(pos);
2196 } else if (os_strcmp(buf, "config_methods") == 0) {
2197 bss->config_methods = os_strdup(pos);
2198 } else if (os_strcmp(buf, "os_version") == 0) {
2199 if (hexstr2bin(pos, bss->os_version, 4)) {
2200 wpa_printf(MSG_ERROR, "Line %d: invalid "
2201 "os_version", line);
2204 } else if (os_strcmp(buf, "ap_pin") == 0) {
2205 bss->ap_pin = os_strdup(pos);
2206 #endif /* CONFIG_WPS */
2208 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2209 "item '%s'", line, buf);
2216 if (bss->individual_wep_key_len == 0) {
2217 /* individual keys are not use; can use key idx0 for broadcast
2219 bss->broadcast_key_idx_min = 0;
2222 /* Select group cipher based on the enabled pairwise cipher suites */
2225 pairwise |= bss->wpa_pairwise;
2227 if (bss->rsn_pairwise == 0)
2228 bss->rsn_pairwise = bss->wpa_pairwise;
2229 pairwise |= bss->rsn_pairwise;
2231 if (pairwise & WPA_CIPHER_TKIP)
2232 bss->wpa_group = WPA_CIPHER_TKIP;
2234 bss->wpa_group = WPA_CIPHER_CCMP;
2236 for (i = 0; i < conf->num_bss; i++) {
2237 bss = &conf->bss[i];
2239 bss->radius->auth_server = bss->radius->auth_servers;
2240 bss->radius->acct_server = bss->radius->acct_servers;
2242 if (bss->wpa && bss->ieee802_1x) {
2243 bss->ssid.security_policy = SECURITY_WPA;
2244 } else if (bss->wpa) {
2245 bss->ssid.security_policy = SECURITY_WPA_PSK;
2246 } else if (bss->ieee802_1x) {
2247 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2248 bss->ssid.wep.default_len = bss->default_wep_key_len;
2249 } else if (bss->ssid.wep.keys_set)
2250 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2252 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2255 if (hostapd_config_check(conf))
2259 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
2260 "'%s'", errors, fname);
2261 hostapd_config_free(conf);
2269 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2273 if (a->idx != b->idx || a->default_len != b->default_len)
2275 for (i = 0; i < NUM_WEP_KEYS; i++)
2276 if (a->len[i] != b->len[i] ||
2277 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2283 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2288 for (i = 0; i < num_servers; i++) {
2289 os_free(servers[i].shared_secret);
2295 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2297 os_free(user->identity);
2298 os_free(user->password);
2303 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2306 for (i = 0; i < NUM_WEP_KEYS; i++) {
2307 os_free(keys->key[i]);
2308 keys->key[i] = NULL;
2313 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2315 struct hostapd_wpa_psk *psk, *prev;
2316 struct hostapd_eap_user *user, *prev_user;
2321 psk = conf->ssid.wpa_psk;
2328 os_free(conf->ssid.wpa_passphrase);
2329 os_free(conf->ssid.wpa_psk_file);
2330 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2331 os_free(conf->ssid.vlan_tagged_interface);
2332 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2334 user = conf->eap_user;
2338 hostapd_config_free_eap_user(prev_user);
2341 os_free(conf->dump_log_name);
2342 os_free(conf->eap_req_id_text);
2343 os_free(conf->accept_mac);
2344 os_free(conf->deny_mac);
2345 os_free(conf->nas_identifier);
2346 hostapd_config_free_radius(conf->radius->auth_servers,
2347 conf->radius->num_auth_servers);
2348 hostapd_config_free_radius(conf->radius->acct_servers,
2349 conf->radius->num_acct_servers);
2350 os_free(conf->rsn_preauth_interfaces);
2351 os_free(conf->ctrl_interface);
2352 os_free(conf->ca_cert);
2353 os_free(conf->server_cert);
2354 os_free(conf->private_key);
2355 os_free(conf->private_key_passwd);
2356 os_free(conf->dh_file);
2357 os_free(conf->pac_opaque_encr_key);
2358 os_free(conf->eap_fast_a_id);
2359 os_free(conf->eap_fast_a_id_info);
2360 os_free(conf->eap_sim_db);
2361 os_free(conf->radius_server_clients);
2362 os_free(conf->test_socket);
2363 os_free(conf->radius);
2364 hostapd_config_free_vlan(conf);
2365 if (conf->ssid.dyn_vlan_keys) {
2366 struct hostapd_ssid *ssid = &conf->ssid;
2368 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2369 if (ssid->dyn_vlan_keys[i] == NULL)
2371 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2372 os_free(ssid->dyn_vlan_keys[i]);
2374 os_free(ssid->dyn_vlan_keys);
2375 ssid->dyn_vlan_keys = NULL;
2378 #ifdef CONFIG_IEEE80211R
2380 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2381 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2383 r0kh = conf->r0kh_list;
2384 conf->r0kh_list = NULL;
2391 r1kh = conf->r1kh_list;
2392 conf->r1kh_list = NULL;
2399 #endif /* CONFIG_IEEE80211R */
2402 os_free(conf->wps_pin_requests);
2403 os_free(conf->device_name);
2404 os_free(conf->manufacturer);
2405 os_free(conf->model_name);
2406 os_free(conf->model_number);
2407 os_free(conf->serial_number);
2408 os_free(conf->device_type);
2409 os_free(conf->config_methods);
2410 os_free(conf->ap_pin);
2411 #endif /* CONFIG_WPS */
2416 * hostapd_config_free - Free hostapd configuration
2417 * @conf: Configuration data from hostapd_config_read().
2419 void hostapd_config_free(struct hostapd_config *conf)
2426 for (i = 0; i < conf->num_bss; i++)
2427 hostapd_config_free_bss(&conf->bss[i]);
2435 * hostapd_maclist_found - Find a MAC address from a list
2436 * @list: MAC address list
2437 * @num_entries: Number of addresses in the list
2438 * @addr: Address to search for
2439 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
2440 * Returns: 1 if address is in the list or 0 if not.
2442 * Perform a binary search for given MAC address from a pre-sorted list.
2444 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2445 const u8 *addr, int *vlan_id)
2447 int start, end, middle, res;
2450 end = num_entries - 1;
2452 while (start <= end) {
2453 middle = (start + end) / 2;
2454 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2457 *vlan_id = list[middle].vlan_id;
2470 int hostapd_rate_found(int *list, int rate)
2477 for (i = 0; list[i] >= 0; i++)
2478 if (list[i] == rate)
2485 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2487 struct hostapd_vlan *v = vlan;
2489 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2497 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2498 const u8 *addr, const u8 *prev_psk)
2500 struct hostapd_wpa_psk *psk;
2501 int next_ok = prev_psk == NULL;
2503 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2505 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2508 if (psk->psk == prev_psk)
2516 const struct hostapd_eap_user *
2517 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2518 size_t identity_len, int phase2)
2520 struct hostapd_eap_user *user = conf->eap_user;
2523 if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
2524 os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
2525 static struct hostapd_eap_user wsc_enrollee;
2526 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
2527 wsc_enrollee.methods[0].method = eap_server_get_type(
2528 "WSC", &wsc_enrollee.methods[0].vendor);
2529 return &wsc_enrollee;
2532 if (conf->wps_state && conf->ap_pin &&
2533 identity_len == WSC_ID_REGISTRAR_LEN &&
2534 os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
2535 static struct hostapd_eap_user wsc_registrar;
2536 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
2537 wsc_registrar.methods[0].method = eap_server_get_type(
2538 "WSC", &wsc_registrar.methods[0].vendor);
2539 wsc_registrar.password = (u8 *) conf->ap_pin;
2540 wsc_registrar.password_len = os_strlen(conf->ap_pin);
2541 return &wsc_registrar;
2543 #endif /* CONFIG_WPS */
2546 if (!phase2 && user->identity == NULL) {
2547 /* Wildcard match */
2551 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2552 identity_len >= user->identity_len &&
2553 os_memcmp(user->identity, identity, user->identity_len) ==
2555 /* Wildcard prefix match */
2559 if (user->phase2 == !!phase2 &&
2560 user->identity_len == identity_len &&
2561 os_memcmp(user->identity, identity, identity_len) == 0)