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"
31 #define MAX_STA_COUNT 2007
33 extern struct wpa_driver_ops *hostapd_drivers[];
36 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
40 char buf[128], *pos, *pos2;
41 int line = 0, vlan_id;
42 struct hostapd_vlan *vlan;
44 f = fopen(fname, "r");
46 printf("VLAN file '%s' not readable.\n", fname);
50 while (fgets(buf, sizeof(buf), f)) {
56 while (*pos != '\0') {
67 vlan_id = VLAN_ID_WILDCARD;
70 vlan_id = strtol(buf, &pos, 10);
71 if (buf == pos || vlan_id < 1 ||
72 vlan_id > MAX_VLAN_ID) {
73 printf("Invalid VLAN ID at line %d in '%s'\n",
80 while (*pos == ' ' || *pos == '\t')
83 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
86 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
87 printf("Invalid VLAN ifname at line %d in '%s'\n",
93 vlan = os_malloc(sizeof(*vlan));
95 printf("Out of memory while reading VLAN interfaces "
96 "from '%s'\n", fname);
101 os_memset(vlan, 0, sizeof(*vlan));
102 vlan->vlan_id = vlan_id;
103 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
105 bss->vlan_tail->next = vlan;
108 bss->vlan_tail = vlan;
117 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
119 struct hostapd_vlan *vlan, *prev;
133 /* convert floats with one decimal place to value*10 int, i.e.,
134 * "1.5" will return 15 */
135 static int hostapd_config_read_int10(const char *value)
141 pos = os_strchr(value, '.');
145 if (*pos >= '0' && *pos <= '9')
153 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
155 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
156 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
157 bss->logger_syslog = (unsigned int) -1;
158 bss->logger_stdout = (unsigned int) -1;
160 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
162 bss->wep_rekeying_period = 300;
163 /* use key0 in individual key and key1 in broadcast key */
164 bss->broadcast_key_idx_min = 1;
165 bss->broadcast_key_idx_max = 2;
166 bss->eap_reauth_period = 3600;
168 bss->wpa_group_rekey = 600;
169 bss->wpa_gmk_rekey = 86400;
170 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
171 bss->wpa_pairwise = WPA_CIPHER_TKIP;
172 bss->wpa_group = WPA_CIPHER_TKIP;
173 bss->rsn_pairwise = 0;
175 bss->max_num_sta = MAX_STA_COUNT;
177 bss->dtim_period = 2;
179 bss->radius_server_auth_port = 1812;
180 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
181 bss->eapol_version = EAPOL_VERSION;
183 bss->max_listen_interval = 65535;
185 #ifdef CONFIG_IEEE80211W
186 bss->assoc_ping_timeout = 1000;
187 bss->assoc_ping_attempts = 3;
188 #endif /* CONFIG_IEEE80211W */
190 /* both anonymous and authenticated provisioning */
191 bss->eap_fast_prov = 3;
192 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
193 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
194 #endif /* EAP_FAST */
198 static struct hostapd_config * hostapd_config_defaults(void)
200 struct hostapd_config *conf;
201 struct hostapd_bss_config *bss;
203 const int aCWmin = 15, aCWmax = 1024;
204 const struct hostapd_wme_ac_params ac_bk =
205 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
206 const struct hostapd_wme_ac_params ac_be =
207 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
208 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
209 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
210 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
211 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
213 conf = os_zalloc(sizeof(*conf));
214 bss = os_zalloc(sizeof(*bss));
215 if (conf == NULL || bss == NULL) {
216 printf("Failed to allocate memory for configuration data.\n");
222 /* set default driver based on configuration */
223 conf->driver = hostapd_drivers[0];
224 if (conf->driver == NULL) {
225 printf("No driver wrappers registered!\n");
231 bss->radius = os_zalloc(sizeof(*bss->radius));
232 if (bss->radius == NULL) {
238 hostapd_config_defaults_bss(bss);
243 conf->beacon_int = 100;
244 conf->rts_threshold = -1; /* use driver default: 2347 */
245 conf->fragm_threshold = -1; /* user driver default: 2346 */
246 conf->send_probe_response = 1;
247 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
249 os_memcpy(conf->country, "US ", 3);
251 for (i = 0; i < NUM_TX_QUEUES; i++)
252 conf->tx_queue[i].aifs = -1; /* use hw default */
254 conf->wme_ac_params[0] = ac_be;
255 conf->wme_ac_params[1] = ac_bk;
256 conf->wme_ac_params[2] = ac_vi;
257 conf->wme_ac_params[3] = ac_vo;
259 #ifdef CONFIG_IEEE80211N
260 SET_2BIT_LE16(&conf->ht_capab,
261 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
262 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
264 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
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 printf("MAC list file '%s' not found.\n", fname);
311 while (fgets(buf, sizeof(buf), f)) {
317 while (*pos != '\0') {
327 if (hwaddr_aton(buf, addr)) {
328 printf("Invalid MAC address '%s' at line %d in '%s'\n",
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 printf("MAC list reallocation failed\n");
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 printf("WPA PSK file '%s' not found.\n", fname);
382 while (fgets(buf, sizeof(buf), f)) {
388 while (*pos != '\0') {
398 if (hwaddr_aton(buf, addr)) {
399 printf("Invalid MAC address '%s' on line %d in '%s'\n",
405 psk = os_zalloc(sizeof(*psk));
407 printf("WPA PSK allocation failed\n");
411 if (is_zero_ether_addr(addr))
414 os_memcpy(psk->addr, addr, ETH_ALEN);
418 printf("No PSK on line %d in '%s'\n", line, fname);
426 len = os_strlen(pos);
427 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
429 else if (len >= 8 && len < 64) {
430 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
431 4096, psk->psk, PMK_LEN);
435 printf("Invalid PSK '%s' on line %d in '%s'\n",
442 psk->next = ssid->wpa_psk;
452 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
454 struct hostapd_ssid *ssid = &conf->ssid;
456 if (ssid->wpa_passphrase != NULL) {
457 if (ssid->wpa_psk != NULL) {
458 printf("Warning: both WPA PSK and passphrase set. "
459 "Using passphrase.\n");
460 os_free(ssid->wpa_psk);
462 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
463 if (ssid->wpa_psk == NULL) {
464 printf("Unable to alloc space for PSK\n");
467 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
468 (u8 *) ssid->ssid, ssid->ssid_len);
469 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
470 (u8 *) ssid->wpa_passphrase,
471 os_strlen(ssid->wpa_passphrase));
472 pbkdf2_sha1(ssid->wpa_passphrase,
473 ssid->ssid, ssid->ssid_len,
474 4096, ssid->wpa_psk->psk, PMK_LEN);
475 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
476 ssid->wpa_psk->psk, PMK_LEN);
477 ssid->wpa_psk->group = 1;
479 os_memset(ssid->wpa_passphrase, 0,
480 os_strlen(ssid->wpa_passphrase));
481 os_free(ssid->wpa_passphrase);
482 ssid->wpa_passphrase = NULL;
485 if (ssid->wpa_psk_file) {
486 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
496 static int hostapd_config_read_eap_user(const char *fname,
497 struct hostapd_bss_config *conf)
500 char buf[512], *pos, *start, *pos2;
501 int line = 0, ret = 0, num_methods;
502 struct hostapd_eap_user *user, *tail = NULL;
507 f = fopen(fname, "r");
509 printf("EAP user file '%s' not found.\n", fname);
513 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
514 while (fgets(buf, sizeof(buf), f)) {
520 while (*pos != '\0') {
532 if (buf[0] != '"' && buf[0] != '*') {
533 printf("Invalid EAP identity (no \" in start) on "
534 "line %d in '%s'\n", line, fname);
538 user = os_zalloc(sizeof(*user));
540 printf("EAP user allocation failed\n");
543 user->force_version = -1;
550 while (*pos != '"' && *pos != '\0')
553 printf("Invalid EAP identity (no \" in end) on"
554 " line %d in '%s'\n", line, fname);
558 user->identity = os_malloc(pos - start);
559 if (user->identity == NULL) {
560 printf("Failed to allocate memory for EAP "
564 os_memcpy(user->identity, start, pos - start);
565 user->identity_len = pos - start;
567 if (pos[0] == '"' && pos[1] == '*') {
568 user->wildcard_prefix = 1;
573 while (*pos == ' ' || *pos == '\t')
577 printf("No EAP method on line %d in '%s'\n",
583 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
593 char *pos3 = os_strchr(start, ',');
597 user->methods[num_methods].method =
600 &user->methods[num_methods].vendor);
601 if (user->methods[num_methods].vendor ==
603 user->methods[num_methods].method == EAP_TYPE_NONE)
605 if (os_strcmp(start, "TTLS-PAP") == 0) {
606 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
609 if (os_strcmp(start, "TTLS-CHAP") == 0) {
610 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
613 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
615 EAP_TTLS_AUTH_MSCHAP;
618 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
620 EAP_TTLS_AUTH_MSCHAPV2;
623 printf("Unsupported EAP type '%s' on line %d "
624 "in '%s'\n", start, line, fname);
629 if (num_methods >= EAP_USER_MAX_METHODS)
636 if (num_methods == 0 && user->ttls_auth == 0) {
637 printf("No EAP types configured on line %d in '%s'\n",
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 printf("Invalid EAP password (no \" in end) "
672 "on line %d in '%s'\n", line, fname);
676 user->password = os_malloc(pos - start);
677 if (user->password == NULL) {
678 printf("Failed to allocate memory for EAP "
682 os_memcpy(user->password, start, pos - start);
683 user->password_len = pos - start;
686 } else if (os_strncmp(pos, "hash:", 5) == 0) {
689 while (*pos2 != '\0' && *pos2 != ' ' &&
690 *pos2 != '\t' && *pos2 != '#')
692 if (pos2 - pos != 32) {
693 printf("Invalid password hash on line %d in "
694 "'%s'\n", line, fname);
697 user->password = os_malloc(16);
698 if (user->password == NULL) {
699 printf("Failed to allocate memory for EAP "
703 if (hexstr2bin(pos, user->password, 16) < 0) {
704 printf("Invalid hash password on line %d in "
705 "'%s'\n", line, fname);
708 user->password_len = 16;
709 user->password_hash = 1;
713 while (*pos2 != '\0' && *pos2 != ' ' &&
714 *pos2 != '\t' && *pos2 != '#')
716 if ((pos2 - pos) & 1) {
717 printf("Invalid hex password on line %d in "
718 "'%s'\n", line, fname);
721 user->password = os_malloc((pos2 - pos) / 2);
722 if (user->password == NULL) {
723 printf("Failed to allocate memory for EAP "
727 if (hexstr2bin(pos, user->password,
728 (pos2 - pos) / 2) < 0) {
729 printf("Invalid hex password on line %d in "
730 "'%s'\n", line, fname);
733 user->password_len = (pos2 - pos) / 2;
737 while (*pos == ' ' || *pos == '\t')
739 if (os_strncmp(pos, "[2]", 3) == 0) {
745 tail = conf->eap_user = user;
754 os_free(user->password);
755 os_free(user->identity);
766 #endif /* EAP_SERVER */
770 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
771 int *num_server, const char *val, int def_port,
772 struct hostapd_radius_server **curr_serv)
774 struct hostapd_radius_server *nserv;
776 static int server_index = 1;
778 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
783 nserv = &nserv[*num_server];
785 (*curr_serv) = nserv;
787 os_memset(nserv, 0, sizeof(*nserv));
788 nserv->port = def_port;
789 ret = hostapd_parse_ip_addr(val, &nserv->addr);
790 nserv->index = server_index++;
796 static int hostapd_config_parse_key_mgmt(int line, const char *value)
799 char *start, *end, *buf;
801 buf = os_strdup(value);
806 while (start != '\0') {
807 while (*start == ' ' || *start == '\t')
812 while (*end != ' ' && *end != '\t' && *end != '\0')
816 if (os_strcmp(start, "WPA-PSK") == 0)
817 val |= WPA_KEY_MGMT_PSK;
818 else if (os_strcmp(start, "WPA-EAP") == 0)
819 val |= WPA_KEY_MGMT_IEEE8021X;
820 #ifdef CONFIG_IEEE80211R
821 else if (os_strcmp(start, "FT-PSK") == 0)
822 val |= WPA_KEY_MGMT_FT_PSK;
823 else if (os_strcmp(start, "FT-EAP") == 0)
824 val |= WPA_KEY_MGMT_FT_IEEE8021X;
825 #endif /* CONFIG_IEEE80211R */
826 #ifdef CONFIG_IEEE80211W
827 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
828 val |= WPA_KEY_MGMT_PSK_SHA256;
829 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
830 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
831 #endif /* CONFIG_IEEE80211W */
833 printf("Line %d: invalid key_mgmt '%s'\n",
846 printf("Line %d: no key_mgmt values configured.\n", line);
854 static int hostapd_config_parse_cipher(int line, const char *value)
857 char *start, *end, *buf;
859 buf = os_strdup(value);
864 while (start != '\0') {
865 while (*start == ' ' || *start == '\t')
870 while (*end != ' ' && *end != '\t' && *end != '\0')
874 if (os_strcmp(start, "CCMP") == 0)
875 val |= WPA_CIPHER_CCMP;
876 else if (os_strcmp(start, "TKIP") == 0)
877 val |= WPA_CIPHER_TKIP;
878 else if (os_strcmp(start, "WEP104") == 0)
879 val |= WPA_CIPHER_WEP104;
880 else if (os_strcmp(start, "WEP40") == 0)
881 val |= WPA_CIPHER_WEP40;
882 else if (os_strcmp(start, "NONE") == 0)
883 val |= WPA_CIPHER_NONE;
885 printf("Line %d: invalid cipher '%s'.", line, start);
897 printf("Line %d: no cipher values configured.", line);
904 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
905 struct hostapd_config *conf)
907 if (bss->ieee802_1x && !bss->eap_server &&
908 !bss->radius->auth_servers) {
909 printf("Invalid IEEE 802.1X configuration (no EAP "
910 "authenticator configured).\n");
914 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
915 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
916 bss->ssid.wpa_psk_file == NULL) {
917 printf("WPA-PSK enabled, but PSK or passphrase is not "
922 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
925 for (i = 0; i < conf->num_bss; i++) {
926 if ((&conf->bss[i] != bss) &&
927 (hostapd_mac_comp(conf->bss[i].bssid,
929 printf("Duplicate BSSID " MACSTR
930 " on interface '%s' and '%s'.\n",
932 conf->bss[i].iface, bss->iface);
938 #ifdef CONFIG_IEEE80211R
939 if ((bss->wpa_key_mgmt &
940 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
941 (bss->nas_identifier == NULL ||
942 os_strlen(bss->nas_identifier) < 1 ||
943 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
944 printf("FT (IEEE 802.11r) requires nas_identifier to be "
945 "configured as a 1..48 octet string\n");
948 #endif /* CONFIG_IEEE80211R */
954 static int hostapd_config_check(struct hostapd_config *conf)
958 for (i = 0; i < conf->num_bss; i++) {
959 if (hostapd_config_check_bss(&conf->bss[i], conf))
967 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
970 size_t len = os_strlen(val);
972 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
976 if (len < 2 || val[len - 1] != '"')
979 wep->key[keyidx] = os_malloc(len);
980 if (wep->key[keyidx] == NULL)
982 os_memcpy(wep->key[keyidx], val + 1, len);
983 wep->len[keyidx] = len;
988 wep->key[keyidx] = os_malloc(len);
989 if (wep->key[keyidx] == NULL)
991 wep->len[keyidx] = len;
992 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1002 static int hostapd_parse_rates(int **rate_list, char *val)
1008 os_free(*rate_list);
1013 while (*pos != '\0') {
1019 list = os_malloc(sizeof(int) * (count + 2));
1024 while (*pos != '\0') {
1025 end = os_strchr(pos, ' ');
1029 list[count++] = atoi(pos);
1041 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1043 struct hostapd_bss_config *bss;
1045 if (*ifname == '\0')
1048 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1049 sizeof(struct hostapd_bss_config));
1051 printf("Failed to allocate memory for multi-BSS entry\n");
1056 bss = &(conf->bss[conf->num_bss]);
1057 os_memset(bss, 0, sizeof(*bss));
1058 bss->radius = os_zalloc(sizeof(*bss->radius));
1059 if (bss->radius == NULL) {
1060 printf("Failed to allocate memory for multi-BSS RADIUS "
1066 conf->last_bss = bss;
1068 hostapd_config_defaults_bss(bss);
1069 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1070 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1076 static int valid_cw(int cw)
1078 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1079 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1084 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1085 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1086 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1087 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1088 IEEE80211_TX_QUEUE_DATA4 = 4,
1089 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1090 IEEE80211_TX_QUEUE_BEACON = 7
1093 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1098 struct hostapd_tx_queue_params *queue;
1100 /* skip 'tx_queue_' prefix */
1102 if (os_strncmp(pos, "data", 4) == 0 &&
1103 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1106 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1107 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1109 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1110 num = IEEE80211_TX_QUEUE_BEACON;
1113 printf("Unknown tx_queue name '%s'\n", pos);
1117 queue = &conf->tx_queue[num];
1119 if (os_strcmp(pos, "aifs") == 0) {
1120 queue->aifs = atoi(val);
1121 if (queue->aifs < 0 || queue->aifs > 255) {
1122 printf("Invalid AIFS value %d\n", queue->aifs);
1125 } else if (os_strcmp(pos, "cwmin") == 0) {
1126 queue->cwmin = atoi(val);
1127 if (!valid_cw(queue->cwmin)) {
1128 printf("Invalid cwMin value %d\n", queue->cwmin);
1131 } else if (os_strcmp(pos, "cwmax") == 0) {
1132 queue->cwmax = atoi(val);
1133 if (!valid_cw(queue->cwmax)) {
1134 printf("Invalid cwMax value %d\n", queue->cwmax);
1137 } else if (os_strcmp(pos, "burst") == 0) {
1138 queue->burst = hostapd_config_read_int10(val);
1140 printf("Unknown tx_queue field '%s'\n", pos);
1144 queue->configured = 1;
1150 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1155 struct hostapd_wme_ac_params *ac;
1157 /* skip 'wme_ac_' prefix */
1159 if (os_strncmp(pos, "be_", 3) == 0) {
1162 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1165 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1168 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1172 printf("Unknown wme name '%s'\n", pos);
1176 ac = &conf->wme_ac_params[num];
1178 if (os_strcmp(pos, "aifs") == 0) {
1180 if (v < 1 || v > 255) {
1181 printf("Invalid AIFS value %d\n", v);
1185 } else if (os_strcmp(pos, "cwmin") == 0) {
1187 if (v < 0 || v > 12) {
1188 printf("Invalid cwMin value %d\n", v);
1192 } else if (os_strcmp(pos, "cwmax") == 0) {
1194 if (v < 0 || v > 12) {
1195 printf("Invalid cwMax value %d\n", v);
1199 } else if (os_strcmp(pos, "txop_limit") == 0) {
1201 if (v < 0 || v > 0xffff) {
1202 printf("Invalid txop value %d\n", v);
1206 } else if (os_strcmp(pos, "acm") == 0) {
1208 if (v < 0 || v > 1) {
1209 printf("Invalid acm value %d\n", v);
1212 ac->admission_control_mandatory = v;
1214 printf("Unknown wme_ac_ field '%s'\n", pos);
1222 #ifdef CONFIG_IEEE80211R
1223 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1225 struct ft_remote_r0kh *r0kh;
1228 r0kh = os_zalloc(sizeof(*r0kh));
1232 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1234 next = os_strchr(pos, ' ');
1237 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1238 printf("Invalid R0KH MAC address: '%s'\n", pos);
1244 next = os_strchr(pos, ' ');
1247 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1248 printf("Invalid R0KH-ID: '%s'\n", pos);
1252 r0kh->id_len = next - pos - 1;
1253 os_memcpy(r0kh->id, pos, r0kh->id_len);
1256 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1257 printf("Invalid R0KH key: '%s'\n", pos);
1262 r0kh->next = bss->r0kh_list;
1263 bss->r0kh_list = r0kh;
1269 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1271 struct ft_remote_r1kh *r1kh;
1274 r1kh = os_zalloc(sizeof(*r1kh));
1278 /* 02:01:02:03:04:05 02:01:02:03:04:05
1279 * 000102030405060708090a0b0c0d0e0f */
1281 next = os_strchr(pos, ' ');
1284 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1285 printf("Invalid R1KH MAC address: '%s'\n", pos);
1291 next = os_strchr(pos, ' ');
1294 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1295 printf("Invalid R1KH-ID: '%s'\n", pos);
1301 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1302 printf("Invalid R1KH key: '%s'\n", pos);
1307 r1kh->next = bss->r1kh_list;
1308 bss->r1kh_list = r1kh;
1312 #endif /* CONFIG_IEEE80211R */
1315 struct hostapd_config * hostapd_config_read(const char *fname)
1317 struct hostapd_config *conf;
1318 struct hostapd_bss_config *bss;
1320 char buf[256], *pos;
1326 f = fopen(fname, "r");
1328 printf("Could not open configuration file '%s' for reading.\n",
1333 conf = hostapd_config_defaults();
1338 bss = conf->last_bss = conf->bss;
1340 while (fgets(buf, sizeof(buf), f)) {
1341 bss = conf->last_bss;
1347 while (*pos != '\0') {
1357 pos = os_strchr(buf, '=');
1359 printf("Line %d: invalid line '%s'\n", line, buf);
1366 if (os_strcmp(buf, "interface") == 0) {
1367 os_strlcpy(conf->bss[0].iface, pos,
1368 sizeof(conf->bss[0].iface));
1369 } else if (os_strcmp(buf, "bridge") == 0) {
1370 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1371 } else if (os_strcmp(buf, "driver") == 0) {
1373 /* clear to get error below if setting is invalid */
1374 conf->driver = NULL;
1375 for (i = 0; hostapd_drivers[i]; i++) {
1376 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1378 conf->driver = hostapd_drivers[i];
1382 if (conf->driver == NULL) {
1383 printf("Line %d: invalid/unknown driver "
1384 "'%s'\n", line, pos);
1387 } else if (os_strcmp(buf, "debug") == 0) {
1388 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1389 "configuration variable is not used "
1391 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1392 bss->logger_syslog_level = atoi(pos);
1393 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1394 bss->logger_stdout_level = atoi(pos);
1395 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1396 bss->logger_syslog = atoi(pos);
1397 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1398 bss->logger_stdout = atoi(pos);
1399 } else if (os_strcmp(buf, "dump_file") == 0) {
1400 bss->dump_log_name = os_strdup(pos);
1401 } else if (os_strcmp(buf, "ssid") == 0) {
1402 bss->ssid.ssid_len = os_strlen(pos);
1403 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1404 bss->ssid.ssid_len < 1) {
1405 printf("Line %d: invalid SSID '%s'\n", line,
1409 os_memcpy(bss->ssid.ssid, pos,
1410 bss->ssid.ssid_len);
1411 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1412 bss->ssid.ssid_set = 1;
1414 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1415 bss->macaddr_acl = atoi(pos);
1416 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1417 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1418 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1419 printf("Line %d: unknown macaddr_acl %d\n",
1420 line, bss->macaddr_acl);
1422 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1423 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1424 &bss->num_accept_mac))
1426 printf("Line %d: Failed to read "
1427 "accept_mac_file '%s'\n",
1431 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1432 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1433 &bss->num_deny_mac))
1435 printf("Line %d: Failed to read "
1436 "deny_mac_file '%s'\n",
1440 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1441 bss->ap_max_inactivity = atoi(pos);
1442 } else if (os_strcmp(buf, "country_code") == 0) {
1443 os_memcpy(conf->country, pos, 2);
1444 /* FIX: make this configurable */
1445 conf->country[2] = ' ';
1446 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1447 conf->ieee80211d = atoi(pos);
1448 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1449 bss->ieee802_1x = atoi(pos);
1450 } else if (os_strcmp(buf, "eapol_version") == 0) {
1451 bss->eapol_version = atoi(pos);
1452 if (bss->eapol_version < 1 ||
1453 bss->eapol_version > 2) {
1454 printf("Line %d: invalid EAPOL "
1455 "version (%d): '%s'.\n",
1456 line, bss->eapol_version, pos);
1459 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1460 bss->eapol_version);
1462 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1463 bss->eap_server = atoi(pos);
1464 printf("Line %d: obsolete eap_authenticator used; "
1465 "this has been renamed to eap_server\n", line);
1466 } else if (os_strcmp(buf, "eap_server") == 0) {
1467 bss->eap_server = atoi(pos);
1468 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1469 if (hostapd_config_read_eap_user(pos, bss))
1471 } else if (os_strcmp(buf, "ca_cert") == 0) {
1472 os_free(bss->ca_cert);
1473 bss->ca_cert = os_strdup(pos);
1474 } else if (os_strcmp(buf, "server_cert") == 0) {
1475 os_free(bss->server_cert);
1476 bss->server_cert = os_strdup(pos);
1477 } else if (os_strcmp(buf, "private_key") == 0) {
1478 os_free(bss->private_key);
1479 bss->private_key = os_strdup(pos);
1480 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1481 os_free(bss->private_key_passwd);
1482 bss->private_key_passwd = os_strdup(pos);
1483 } else if (os_strcmp(buf, "check_crl") == 0) {
1484 bss->check_crl = atoi(pos);
1485 } else if (os_strcmp(buf, "dh_file") == 0) {
1486 os_free(bss->dh_file);
1487 bss->dh_file = os_strdup(pos);
1489 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1490 os_free(bss->pac_opaque_encr_key);
1491 bss->pac_opaque_encr_key = os_malloc(16);
1492 if (bss->pac_opaque_encr_key == NULL) {
1493 printf("Line %d: No memory for "
1494 "pac_opque_encr_key\n", line);
1496 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1498 printf("Line %d: Invalid pac_opque_encr_key\n",
1502 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1503 size_t idlen = os_strlen(pos);
1505 printf("Line %d: Invalid eap_fast_a_id\n",
1509 os_free(bss->eap_fast_a_id);
1510 bss->eap_fast_a_id = os_malloc(idlen / 2);
1511 if (bss->eap_fast_a_id == NULL ||
1512 hexstr2bin(pos, bss->eap_fast_a_id,
1514 printf("Line %d: Failed to parse "
1515 "eap_fast_a_id\n", line);
1518 bss->eap_fast_a_id_len = idlen / 2;
1520 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1521 os_free(bss->eap_fast_a_id_info);
1522 bss->eap_fast_a_id_info = os_strdup(pos);
1523 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1524 bss->eap_fast_prov = atoi(pos);
1525 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1526 bss->pac_key_lifetime = atoi(pos);
1527 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1528 bss->pac_key_refresh_time = atoi(pos);
1529 #endif /* EAP_FAST */
1531 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1532 os_free(bss->eap_sim_db);
1533 bss->eap_sim_db = os_strdup(pos);
1534 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1535 bss->eap_sim_aka_result_ind = atoi(pos);
1536 #endif /* EAP_SIM */
1538 } else if (os_strcmp(buf, "tnc") == 0) {
1539 bss->tnc = atoi(pos);
1540 #endif /* EAP_TNC */
1541 #endif /* EAP_SERVER */
1542 } else if (os_strcmp(buf, "eap_message") == 0) {
1544 bss->eap_req_id_text = os_strdup(pos);
1545 if (bss->eap_req_id_text == NULL) {
1546 printf("Line %d: Failed to allocate memory "
1547 "for eap_req_id_text\n", line);
1551 bss->eap_req_id_text_len =
1552 os_strlen(bss->eap_req_id_text);
1553 term = os_strstr(bss->eap_req_id_text, "\\0");
1556 os_memmove(term, term + 1,
1557 bss->eap_req_id_text_len -
1558 (term - bss->eap_req_id_text) - 1);
1559 bss->eap_req_id_text_len--;
1561 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1562 bss->default_wep_key_len = atoi(pos);
1563 if (bss->default_wep_key_len > 13) {
1564 printf("Line %d: invalid WEP key len %lu "
1565 "(= %lu bits)\n", line,
1567 bss->default_wep_key_len,
1569 bss->default_wep_key_len * 8);
1572 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1573 bss->individual_wep_key_len = atoi(pos);
1574 if (bss->individual_wep_key_len < 0 ||
1575 bss->individual_wep_key_len > 13) {
1576 printf("Line %d: invalid WEP key len %d "
1577 "(= %d bits)\n", line,
1578 bss->individual_wep_key_len,
1579 bss->individual_wep_key_len * 8);
1582 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1583 bss->wep_rekeying_period = atoi(pos);
1584 if (bss->wep_rekeying_period < 0) {
1585 printf("Line %d: invalid period %d\n",
1586 line, bss->wep_rekeying_period);
1589 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1590 bss->eap_reauth_period = atoi(pos);
1591 if (bss->eap_reauth_period < 0) {
1592 printf("Line %d: invalid period %d\n",
1593 line, bss->eap_reauth_period);
1596 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1597 bss->eapol_key_index_workaround = atoi(pos);
1599 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1600 bss->ieee802_11f = 1;
1601 os_strlcpy(bss->iapp_iface, pos,
1602 sizeof(bss->iapp_iface));
1603 #endif /* CONFIG_IAPP */
1604 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1605 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1606 printf("Line %d: invalid IP address '%s'\n",
1610 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1611 bss->nas_identifier = os_strdup(pos);
1612 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1613 if (hostapd_config_read_radius_addr(
1614 &bss->radius->auth_servers,
1615 &bss->radius->num_auth_servers, pos, 1812,
1616 &bss->radius->auth_server)) {
1617 printf("Line %d: invalid IP address '%s'\n",
1621 } else if (bss->radius->auth_server &&
1622 os_strcmp(buf, "auth_server_port") == 0) {
1623 bss->radius->auth_server->port = atoi(pos);
1624 } else if (bss->radius->auth_server &&
1625 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1626 int len = os_strlen(pos);
1628 /* RFC 2865, Ch. 3 */
1629 printf("Line %d: empty shared secret is not "
1630 "allowed.\n", line);
1633 bss->radius->auth_server->shared_secret =
1634 (u8 *) os_strdup(pos);
1635 bss->radius->auth_server->shared_secret_len = len;
1636 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1637 if (hostapd_config_read_radius_addr(
1638 &bss->radius->acct_servers,
1639 &bss->radius->num_acct_servers, pos, 1813,
1640 &bss->radius->acct_server)) {
1641 printf("Line %d: invalid IP address '%s'\n",
1645 } else if (bss->radius->acct_server &&
1646 os_strcmp(buf, "acct_server_port") == 0) {
1647 bss->radius->acct_server->port = atoi(pos);
1648 } else if (bss->radius->acct_server &&
1649 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1650 int len = os_strlen(pos);
1652 /* RFC 2865, Ch. 3 */
1653 printf("Line %d: empty shared secret is not "
1654 "allowed.\n", line);
1657 bss->radius->acct_server->shared_secret =
1658 (u8 *) os_strdup(pos);
1659 bss->radius->acct_server->shared_secret_len = len;
1660 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1662 bss->radius->retry_primary_interval = atoi(pos);
1663 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1665 bss->radius->acct_interim_interval = atoi(pos);
1666 } else if (os_strcmp(buf, "auth_algs") == 0) {
1667 bss->auth_algs = atoi(pos);
1668 if (bss->auth_algs == 0) {
1669 printf("Line %d: no authentication algorithms "
1674 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1675 bss->max_num_sta = atoi(pos);
1676 if (bss->max_num_sta < 0 ||
1677 bss->max_num_sta > MAX_STA_COUNT) {
1678 printf("Line %d: Invalid max_num_sta=%d; "
1679 "allowed range 0..%d\n", line,
1680 bss->max_num_sta, MAX_STA_COUNT);
1683 } else if (os_strcmp(buf, "wpa") == 0) {
1684 bss->wpa = atoi(pos);
1685 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1686 bss->wpa_group_rekey = atoi(pos);
1687 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1688 bss->wpa_strict_rekey = atoi(pos);
1689 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1690 bss->wpa_gmk_rekey = atoi(pos);
1691 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
1692 bss->wpa_ptk_rekey = atoi(pos);
1693 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1694 int len = os_strlen(pos);
1695 if (len < 8 || len > 63) {
1696 printf("Line %d: invalid WPA passphrase length"
1697 " %d (expected 8..63)\n", line, len);
1700 os_free(bss->ssid.wpa_passphrase);
1701 bss->ssid.wpa_passphrase = os_strdup(pos);
1703 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1704 os_free(bss->ssid.wpa_psk);
1706 os_zalloc(sizeof(struct hostapd_wpa_psk));
1707 if (bss->ssid.wpa_psk == NULL)
1709 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1711 pos[PMK_LEN * 2] != '\0') {
1712 printf("Line %d: Invalid PSK '%s'.\n", line,
1716 bss->ssid.wpa_psk->group = 1;
1718 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1719 os_free(bss->ssid.wpa_psk_file);
1720 bss->ssid.wpa_psk_file = os_strdup(pos);
1721 if (!bss->ssid.wpa_psk_file) {
1722 printf("Line %d: allocation failed\n", line);
1725 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1727 hostapd_config_parse_key_mgmt(line, pos);
1728 if (bss->wpa_key_mgmt == -1)
1730 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1732 hostapd_config_parse_cipher(line, pos);
1733 if (bss->wpa_pairwise == -1 ||
1734 bss->wpa_pairwise == 0)
1736 else if (bss->wpa_pairwise &
1737 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1738 WPA_CIPHER_WEP104)) {
1739 printf("Line %d: unsupported pairwise "
1740 "cipher suite '%s'\n",
1741 bss->wpa_pairwise, pos);
1744 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1746 hostapd_config_parse_cipher(line, pos);
1747 if (bss->rsn_pairwise == -1 ||
1748 bss->rsn_pairwise == 0)
1750 else if (bss->rsn_pairwise &
1751 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1752 WPA_CIPHER_WEP104)) {
1753 printf("Line %d: unsupported pairwise "
1754 "cipher suite '%s'\n",
1755 bss->rsn_pairwise, pos);
1758 #ifdef CONFIG_RSN_PREAUTH
1759 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1760 bss->rsn_preauth = atoi(pos);
1761 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1762 bss->rsn_preauth_interfaces = os_strdup(pos);
1763 #endif /* CONFIG_RSN_PREAUTH */
1764 #ifdef CONFIG_PEERKEY
1765 } else if (os_strcmp(buf, "peerkey") == 0) {
1766 bss->peerkey = atoi(pos);
1767 #endif /* CONFIG_PEERKEY */
1768 #ifdef CONFIG_IEEE80211R
1769 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1770 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1771 hexstr2bin(pos, bss->mobility_domain,
1772 MOBILITY_DOMAIN_ID_LEN) != 0) {
1773 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1774 "mobility_domain '%s'", line, pos);
1778 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1779 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1780 hexstr2bin(pos, bss->r1_key_holder,
1781 FT_R1KH_ID_LEN) != 0) {
1782 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1783 "r1_key_holder '%s'", line, pos);
1787 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1788 bss->r0_key_lifetime = atoi(pos);
1789 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1790 bss->reassociation_deadline = atoi(pos);
1791 } else if (os_strcmp(buf, "r0kh") == 0) {
1792 if (add_r0kh(bss, pos) < 0) {
1793 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1794 "r0kh '%s'", line, pos);
1798 } else if (os_strcmp(buf, "r1kh") == 0) {
1799 if (add_r1kh(bss, pos) < 0) {
1800 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1801 "r1kh '%s'", line, pos);
1805 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1806 bss->pmk_r1_push = atoi(pos);
1807 #endif /* CONFIG_IEEE80211R */
1808 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1809 os_free(bss->ctrl_interface);
1810 bss->ctrl_interface = os_strdup(pos);
1811 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1812 #ifndef CONFIG_NATIVE_WINDOWS
1815 const char *group = pos;
1817 grp = getgrnam(group);
1819 bss->ctrl_interface_gid = grp->gr_gid;
1820 bss->ctrl_interface_gid_set = 1;
1821 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1822 " (from group name '%s')",
1823 bss->ctrl_interface_gid, group);
1827 /* Group name not found - try to parse this as gid */
1828 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1829 if (*group == '\0' || *endp != '\0') {
1830 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1831 "'%s'", line, group);
1835 bss->ctrl_interface_gid_set = 1;
1836 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1837 bss->ctrl_interface_gid);
1838 #endif /* CONFIG_NATIVE_WINDOWS */
1839 #ifdef RADIUS_SERVER
1840 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1841 os_free(bss->radius_server_clients);
1842 bss->radius_server_clients = os_strdup(pos);
1843 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1844 bss->radius_server_auth_port = atoi(pos);
1845 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1846 bss->radius_server_ipv6 = atoi(pos);
1847 #endif /* RADIUS_SERVER */
1848 } else if (os_strcmp(buf, "test_socket") == 0) {
1849 os_free(bss->test_socket);
1850 bss->test_socket = os_strdup(pos);
1851 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1852 bss->use_pae_group_addr = atoi(pos);
1853 } else if (os_strcmp(buf, "hw_mode") == 0) {
1854 if (os_strcmp(pos, "a") == 0)
1855 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1856 else if (os_strcmp(pos, "b") == 0)
1857 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1858 else if (os_strcmp(pos, "g") == 0)
1859 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1861 printf("Line %d: unknown hw_mode '%s'\n",
1865 } else if (os_strcmp(buf, "channel") == 0) {
1866 conf->channel = atoi(pos);
1867 } else if (os_strcmp(buf, "beacon_int") == 0) {
1868 int val = atoi(pos);
1869 /* MIB defines range as 1..65535, but very small values
1870 * cause problems with the current implementation.
1871 * Since it is unlikely that this small numbers are
1872 * useful in real life scenarios, do not allow beacon
1873 * period to be set below 15 TU. */
1874 if (val < 15 || val > 65535) {
1875 printf("Line %d: invalid beacon_int %d "
1876 "(expected 15..65535)\n",
1880 conf->beacon_int = val;
1881 } else if (os_strcmp(buf, "dtim_period") == 0) {
1882 bss->dtim_period = atoi(pos);
1883 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1884 printf("Line %d: invalid dtim_period %d\n",
1885 line, bss->dtim_period);
1888 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1889 conf->rts_threshold = atoi(pos);
1890 if (conf->rts_threshold < 0 ||
1891 conf->rts_threshold > 2347) {
1892 printf("Line %d: invalid rts_threshold %d\n",
1893 line, conf->rts_threshold);
1896 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1897 conf->fragm_threshold = atoi(pos);
1898 if (conf->fragm_threshold < 256 ||
1899 conf->fragm_threshold > 2346) {
1900 printf("Line %d: invalid fragm_threshold %d\n",
1901 line, conf->fragm_threshold);
1904 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1905 int val = atoi(pos);
1906 if (val != 0 && val != 1) {
1907 printf("Line %d: invalid send_probe_response "
1908 "%d (expected 0 or 1)\n", line, val);
1910 conf->send_probe_response = val;
1911 } else if (os_strcmp(buf, "supported_rates") == 0) {
1912 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
1913 printf("Line %d: invalid rate list\n", line);
1916 } else if (os_strcmp(buf, "basic_rates") == 0) {
1917 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
1918 printf("Line %d: invalid rate list\n", line);
1921 } else if (os_strcmp(buf, "preamble") == 0) {
1923 conf->preamble = SHORT_PREAMBLE;
1925 conf->preamble = LONG_PREAMBLE;
1926 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
1927 bss->ignore_broadcast_ssid = atoi(pos);
1928 } else if (os_strcmp(buf, "bridge_packets") == 0) {
1929 conf->bridge_packets = atoi(pos);
1930 } else if (os_strcmp(buf, "wep_default_key") == 0) {
1931 bss->ssid.wep.idx = atoi(pos);
1932 if (bss->ssid.wep.idx > 3) {
1933 printf("Invalid wep_default_key index %d\n",
1937 } else if (os_strcmp(buf, "wep_key0") == 0 ||
1938 os_strcmp(buf, "wep_key1") == 0 ||
1939 os_strcmp(buf, "wep_key2") == 0 ||
1940 os_strcmp(buf, "wep_key3") == 0) {
1941 if (hostapd_config_read_wep(&bss->ssid.wep,
1942 buf[7] - '0', pos)) {
1943 printf("Line %d: invalid WEP key '%s'\n",
1947 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
1948 bss->ssid.dynamic_vlan = atoi(pos);
1949 } else if (os_strcmp(buf, "vlan_file") == 0) {
1950 if (hostapd_config_read_vlan_file(bss, pos)) {
1951 printf("Line %d: failed to read VLAN file "
1952 "'%s'\n", line, pos);
1955 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1956 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
1957 bss->ssid.vlan_tagged_interface = os_strdup(pos);
1958 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1959 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
1960 conf->passive_scan_interval = atoi(pos);
1961 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
1962 conf->passive_scan_listen = atoi(pos);
1963 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
1964 conf->passive_scan_mode = atoi(pos);
1965 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
1966 conf->ap_table_max_size = atoi(pos);
1967 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
1968 conf->ap_table_expiration_time = atoi(pos);
1969 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
1970 if (hostapd_config_tx_queue(conf, buf, pos)) {
1971 printf("Line %d: invalid TX queue item\n",
1975 } else if (os_strcmp(buf, "wme_enabled") == 0) {
1976 bss->wme_enabled = atoi(pos);
1977 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
1978 if (hostapd_config_wme_ac(conf, buf, pos)) {
1979 printf("Line %d: invalid wme ac item\n",
1983 } else if (os_strcmp(buf, "bss") == 0) {
1984 if (hostapd_config_bss(conf, pos)) {
1985 printf("Line %d: invalid bss item\n", line);
1988 } else if (os_strcmp(buf, "bssid") == 0) {
1989 if (bss == conf->bss &&
1990 (!conf->driver || !conf->driver->init_bssid)) {
1991 printf("Line %d: bssid item not allowed "
1992 "for the default interface and this "
1995 } else if (hwaddr_aton(pos, bss->bssid)) {
1996 printf("Line %d: invalid bssid item\n", line);
1999 #ifdef CONFIG_IEEE80211W
2000 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2001 bss->ieee80211w = atoi(pos);
2002 } else if (os_strcmp(buf, "assoc_ping_timeout") == 0) {
2003 bss->assoc_ping_timeout = atoi(pos);
2004 if (bss->assoc_ping_timeout == 0) {
2005 printf("Line %d: invalid assoc_ping_timeout\n",
2009 } else if (os_strcmp(buf, "assoc_ping_attempts") == 0) {
2010 bss->assoc_ping_timeout = atoi(pos);
2011 if (bss->assoc_ping_timeout == 0) {
2012 printf("Line %d: invalid assoc_ping_attempts "
2013 "(valid range: 1..255)\n",
2017 #endif /* CONFIG_IEEE80211W */
2018 #ifdef CONFIG_IEEE80211N
2019 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2020 conf->ieee80211n = atoi(pos);
2021 #endif /* CONFIG_IEEE80211N */
2022 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2023 bss->max_listen_interval = atoi(pos);
2024 } else if (os_strcmp(buf, "okc") == 0) {
2025 bss->okc = atoi(pos);
2027 printf("Line %d: unknown configuration item '%s'\n",
2035 if (bss->individual_wep_key_len == 0) {
2036 /* individual keys are not use; can use key idx0 for broadcast
2038 bss->broadcast_key_idx_min = 0;
2041 /* Select group cipher based on the enabled pairwise cipher suites */
2044 pairwise |= bss->wpa_pairwise;
2046 if (bss->rsn_pairwise == 0)
2047 bss->rsn_pairwise = bss->wpa_pairwise;
2048 pairwise |= bss->rsn_pairwise;
2050 if (pairwise & WPA_CIPHER_TKIP)
2051 bss->wpa_group = WPA_CIPHER_TKIP;
2053 bss->wpa_group = WPA_CIPHER_CCMP;
2055 for (i = 0; i < conf->num_bss; i++) {
2056 bss = &conf->bss[i];
2058 bss->radius->auth_server = bss->radius->auth_servers;
2059 bss->radius->acct_server = bss->radius->acct_servers;
2061 if (bss->wpa && bss->ieee802_1x) {
2062 bss->ssid.security_policy = SECURITY_WPA;
2063 } else if (bss->wpa) {
2064 bss->ssid.security_policy = SECURITY_WPA_PSK;
2065 } else if (bss->ieee802_1x) {
2066 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2067 bss->ssid.wep.default_len = bss->default_wep_key_len;
2068 } else if (bss->ssid.wep.keys_set)
2069 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2071 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2074 if (hostapd_config_check(conf))
2078 printf("%d errors found in configuration file '%s'\n",
2080 hostapd_config_free(conf);
2088 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2092 if (a->idx != b->idx || a->default_len != b->default_len)
2094 for (i = 0; i < NUM_WEP_KEYS; i++)
2095 if (a->len[i] != b->len[i] ||
2096 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2102 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2107 for (i = 0; i < num_servers; i++) {
2108 os_free(servers[i].shared_secret);
2114 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2116 os_free(user->identity);
2117 os_free(user->password);
2122 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2125 for (i = 0; i < NUM_WEP_KEYS; i++) {
2126 os_free(keys->key[i]);
2127 keys->key[i] = NULL;
2132 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2134 struct hostapd_wpa_psk *psk, *prev;
2135 struct hostapd_eap_user *user, *prev_user;
2140 psk = conf->ssid.wpa_psk;
2147 os_free(conf->ssid.wpa_passphrase);
2148 os_free(conf->ssid.wpa_psk_file);
2149 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2150 os_free(conf->ssid.vlan_tagged_interface);
2151 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2153 user = conf->eap_user;
2157 hostapd_config_free_eap_user(prev_user);
2160 os_free(conf->dump_log_name);
2161 os_free(conf->eap_req_id_text);
2162 os_free(conf->accept_mac);
2163 os_free(conf->deny_mac);
2164 os_free(conf->nas_identifier);
2165 hostapd_config_free_radius(conf->radius->auth_servers,
2166 conf->radius->num_auth_servers);
2167 hostapd_config_free_radius(conf->radius->acct_servers,
2168 conf->radius->num_acct_servers);
2169 os_free(conf->rsn_preauth_interfaces);
2170 os_free(conf->ctrl_interface);
2171 os_free(conf->ca_cert);
2172 os_free(conf->server_cert);
2173 os_free(conf->private_key);
2174 os_free(conf->private_key_passwd);
2175 os_free(conf->dh_file);
2176 os_free(conf->pac_opaque_encr_key);
2177 os_free(conf->eap_fast_a_id);
2178 os_free(conf->eap_fast_a_id_info);
2179 os_free(conf->eap_sim_db);
2180 os_free(conf->radius_server_clients);
2181 os_free(conf->test_socket);
2182 os_free(conf->radius);
2183 hostapd_config_free_vlan(conf);
2184 if (conf->ssid.dyn_vlan_keys) {
2185 struct hostapd_ssid *ssid = &conf->ssid;
2187 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2188 if (ssid->dyn_vlan_keys[i] == NULL)
2190 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2191 os_free(ssid->dyn_vlan_keys[i]);
2193 os_free(ssid->dyn_vlan_keys);
2194 ssid->dyn_vlan_keys = NULL;
2197 #ifdef CONFIG_IEEE80211R
2199 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2200 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2202 r0kh = conf->r0kh_list;
2203 conf->r0kh_list = NULL;
2210 r1kh = conf->r1kh_list;
2211 conf->r1kh_list = NULL;
2218 #endif /* CONFIG_IEEE80211R */
2222 void hostapd_config_free(struct hostapd_config *conf)
2229 for (i = 0; i < conf->num_bss; i++)
2230 hostapd_config_free_bss(&conf->bss[i]);
2237 /* Perform a binary search for given MAC address from a pre-sorted list.
2238 * Returns 1 if address is in the list or 0 if not. */
2239 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2240 const u8 *addr, int *vlan_id)
2242 int start, end, middle, res;
2245 end = num_entries - 1;
2247 while (start <= end) {
2248 middle = (start + end) / 2;
2249 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2252 *vlan_id = list[middle].vlan_id;
2265 int hostapd_rate_found(int *list, int rate)
2272 for (i = 0; list[i] >= 0; i++)
2273 if (list[i] == rate)
2280 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2282 struct hostapd_vlan *v = vlan;
2284 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2292 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2293 const u8 *addr, const u8 *prev_psk)
2295 struct hostapd_wpa_psk *psk;
2296 int next_ok = prev_psk == NULL;
2298 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2300 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2303 if (psk->psk == prev_psk)
2311 const struct hostapd_eap_user *
2312 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2313 size_t identity_len, int phase2)
2315 struct hostapd_eap_user *user = conf->eap_user;
2318 if (!phase2 && user->identity == NULL) {
2319 /* Wildcard match */
2323 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2324 identity_len >= user->identity_len &&
2325 os_memcmp(user->identity, identity, user->identity_len) ==
2327 /* Wildcard prefix match */
2331 if (user->phase2 == !!phase2 &&
2332 user->identity_len == identity_len &&
2333 os_memcmp(user->identity, identity, identity_len) == 0)