2 * hostapd / Configuration file
3 * Copyright (c) 2003-2007, 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;
187 static struct hostapd_config * hostapd_config_defaults(void)
189 struct hostapd_config *conf;
190 struct hostapd_bss_config *bss;
192 const int aCWmin = 15, aCWmax = 1024;
193 const struct hostapd_wme_ac_params ac_bk =
194 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
195 const struct hostapd_wme_ac_params ac_be =
196 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
197 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
198 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
199 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
200 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
202 conf = os_zalloc(sizeof(*conf));
203 bss = os_zalloc(sizeof(*bss));
204 if (conf == NULL || bss == NULL) {
205 printf("Failed to allocate memory for configuration data.\n");
211 /* set default driver based on configuration */
212 conf->driver = hostapd_drivers[0];
213 if (conf->driver == NULL) {
214 printf("No driver wrappers registered!\n");
220 bss->radius = os_zalloc(sizeof(*bss->radius));
221 if (bss->radius == NULL) {
227 hostapd_config_defaults_bss(bss);
232 conf->beacon_int = 100;
233 conf->rts_threshold = -1; /* use driver default: 2347 */
234 conf->fragm_threshold = -1; /* user driver default: 2346 */
235 conf->send_probe_response = 1;
236 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
238 os_memcpy(conf->country, "US ", 3);
240 for (i = 0; i < NUM_TX_QUEUES; i++)
241 conf->tx_queue[i].aifs = -1; /* use hw default */
243 conf->wme_ac_params[0] = ac_be;
244 conf->wme_ac_params[1] = ac_bk;
245 conf->wme_ac_params[2] = ac_vi;
246 conf->wme_ac_params[3] = ac_vo;
248 #ifdef CONFIG_IEEE80211N
249 SET_2BIT_LE16(&conf->ht_capab,
250 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
251 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
253 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
254 #endif /* CONFIG_IEEE80211N */
260 int hostapd_mac_comp(const void *a, const void *b)
262 return os_memcmp(a, b, sizeof(macaddr));
266 int hostapd_mac_comp_empty(const void *a)
268 macaddr empty = { 0 };
269 return os_memcmp(a, empty, sizeof(macaddr));
273 static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
285 f = fopen(fname, "r");
287 printf("MAC list file '%s' not found.\n", fname);
291 while (fgets(buf, sizeof(buf), f)) {
297 while (*pos != '\0') {
307 if (hwaddr_aton(buf, addr)) {
308 printf("Invalid MAC address '%s' at line %d in '%s'\n",
314 newacl = os_realloc(*acl, (*num + 1) * ETH_ALEN);
315 if (newacl == NULL) {
316 printf("MAC list reallocation failed\n");
322 os_memcpy((*acl)[*num], addr, ETH_ALEN);
328 qsort(*acl, *num, sizeof(macaddr), hostapd_mac_comp);
334 static int hostapd_config_read_wpa_psk(const char *fname,
335 struct hostapd_ssid *ssid)
339 int line = 0, ret = 0, len, ok;
341 struct hostapd_wpa_psk *psk;
346 f = fopen(fname, "r");
348 printf("WPA PSK file '%s' not found.\n", fname);
352 while (fgets(buf, sizeof(buf), f)) {
358 while (*pos != '\0') {
368 if (hwaddr_aton(buf, addr)) {
369 printf("Invalid MAC address '%s' on line %d in '%s'\n",
375 psk = os_zalloc(sizeof(*psk));
377 printf("WPA PSK allocation failed\n");
381 if (is_zero_ether_addr(addr))
384 os_memcpy(psk->addr, addr, ETH_ALEN);
388 printf("No PSK on line %d in '%s'\n", line, fname);
396 len = os_strlen(pos);
397 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
399 else if (len >= 8 && len < 64) {
400 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
401 4096, psk->psk, PMK_LEN);
405 printf("Invalid PSK '%s' on line %d in '%s'\n",
412 psk->next = ssid->wpa_psk;
422 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
424 struct hostapd_ssid *ssid = &conf->ssid;
426 if (ssid->wpa_passphrase != NULL) {
427 if (ssid->wpa_psk != NULL) {
428 printf("Warning: both WPA PSK and passphrase set. "
429 "Using passphrase.\n");
430 os_free(ssid->wpa_psk);
432 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
433 if (ssid->wpa_psk == NULL) {
434 printf("Unable to alloc space for PSK\n");
437 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
438 (u8 *) ssid->ssid, ssid->ssid_len);
439 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
440 (u8 *) ssid->wpa_passphrase,
441 os_strlen(ssid->wpa_passphrase));
442 pbkdf2_sha1(ssid->wpa_passphrase,
443 ssid->ssid, ssid->ssid_len,
444 4096, ssid->wpa_psk->psk, PMK_LEN);
445 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
446 ssid->wpa_psk->psk, PMK_LEN);
447 ssid->wpa_psk->group = 1;
449 os_memset(ssid->wpa_passphrase, 0,
450 os_strlen(ssid->wpa_passphrase));
451 os_free(ssid->wpa_passphrase);
452 ssid->wpa_passphrase = NULL;
455 if (ssid->wpa_psk_file) {
456 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
466 static int hostapd_config_read_eap_user(const char *fname,
467 struct hostapd_bss_config *conf)
470 char buf[512], *pos, *start, *pos2;
471 int line = 0, ret = 0, num_methods;
472 struct hostapd_eap_user *user, *tail = NULL;
477 f = fopen(fname, "r");
479 printf("EAP user file '%s' not found.\n", fname);
483 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
484 while (fgets(buf, sizeof(buf), f)) {
490 while (*pos != '\0') {
502 if (buf[0] != '"' && buf[0] != '*') {
503 printf("Invalid EAP identity (no \" in start) on "
504 "line %d in '%s'\n", line, fname);
508 user = os_zalloc(sizeof(*user));
510 printf("EAP user allocation failed\n");
513 user->force_version = -1;
520 while (*pos != '"' && *pos != '\0')
523 printf("Invalid EAP identity (no \" in end) on"
524 " line %d in '%s'\n", line, fname);
528 user->identity = os_malloc(pos - start);
529 if (user->identity == NULL) {
530 printf("Failed to allocate memory for EAP "
534 os_memcpy(user->identity, start, pos - start);
535 user->identity_len = pos - start;
537 if (pos[0] == '"' && pos[1] == '*') {
538 user->wildcard_prefix = 1;
543 while (*pos == ' ' || *pos == '\t')
547 printf("No EAP method on line %d in '%s'\n",
553 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
563 char *pos3 = os_strchr(start, ',');
567 user->methods[num_methods].method =
570 &user->methods[num_methods].vendor);
571 if (user->methods[num_methods].vendor ==
573 user->methods[num_methods].method == EAP_TYPE_NONE)
575 if (os_strcmp(start, "TTLS-PAP") == 0) {
576 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
579 if (os_strcmp(start, "TTLS-CHAP") == 0) {
580 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
583 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
585 EAP_TTLS_AUTH_MSCHAP;
588 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
590 EAP_TTLS_AUTH_MSCHAPV2;
593 printf("Unsupported EAP type '%s' on line %d "
594 "in '%s'\n", start, line, fname);
599 if (num_methods >= EAP_USER_MAX_METHODS)
606 if (num_methods == 0 && user->ttls_auth == 0) {
607 printf("No EAP types configured on line %d in '%s'\n",
615 while (*pos == ' ' || *pos == '\t')
620 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
621 user->force_version = 0;
625 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
626 user->force_version = 1;
630 if (os_strncmp(pos, "[2]", 3) == 0) {
638 while (*pos != '"' && *pos != '\0')
641 printf("Invalid EAP password (no \" in end) "
642 "on line %d in '%s'\n", line, fname);
646 user->password = os_malloc(pos - start);
647 if (user->password == NULL) {
648 printf("Failed to allocate memory for EAP "
652 os_memcpy(user->password, start, pos - start);
653 user->password_len = pos - start;
656 } else if (os_strncmp(pos, "hash:", 5) == 0) {
659 while (*pos2 != '\0' && *pos2 != ' ' &&
660 *pos2 != '\t' && *pos2 != '#')
662 if (pos2 - pos != 32) {
663 printf("Invalid password hash on line %d in "
664 "'%s'\n", line, fname);
667 user->password = os_malloc(16);
668 if (user->password == NULL) {
669 printf("Failed to allocate memory for EAP "
673 if (hexstr2bin(pos, user->password, 16) < 0) {
674 printf("Invalid hash password on line %d in "
675 "'%s'\n", line, fname);
678 user->password_len = 16;
679 user->password_hash = 1;
683 while (*pos2 != '\0' && *pos2 != ' ' &&
684 *pos2 != '\t' && *pos2 != '#')
686 if ((pos2 - pos) & 1) {
687 printf("Invalid hex password on line %d in "
688 "'%s'\n", line, fname);
691 user->password = os_malloc((pos2 - pos) / 2);
692 if (user->password == NULL) {
693 printf("Failed to allocate memory for EAP "
697 if (hexstr2bin(pos, user->password,
698 (pos2 - pos) / 2) < 0) {
699 printf("Invalid hex password on line %d in "
700 "'%s'\n", line, fname);
703 user->password_len = (pos2 - pos) / 2;
707 while (*pos == ' ' || *pos == '\t')
709 if (os_strncmp(pos, "[2]", 3) == 0) {
715 tail = conf->eap_user = user;
724 os_free(user->password);
725 os_free(user->identity);
736 #endif /* EAP_SERVER */
740 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
741 int *num_server, const char *val, int def_port,
742 struct hostapd_radius_server **curr_serv)
744 struct hostapd_radius_server *nserv;
746 static int server_index = 1;
748 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
753 nserv = &nserv[*num_server];
755 (*curr_serv) = nserv;
757 os_memset(nserv, 0, sizeof(*nserv));
758 nserv->port = def_port;
759 ret = hostapd_parse_ip_addr(val, &nserv->addr);
760 nserv->index = server_index++;
766 static int hostapd_config_parse_key_mgmt(int line, const char *value)
769 char *start, *end, *buf;
771 buf = os_strdup(value);
776 while (start != '\0') {
777 while (*start == ' ' || *start == '\t')
782 while (*end != ' ' && *end != '\t' && *end != '\0')
786 if (os_strcmp(start, "WPA-PSK") == 0)
787 val |= WPA_KEY_MGMT_PSK;
788 else if (os_strcmp(start, "WPA-EAP") == 0)
789 val |= WPA_KEY_MGMT_IEEE8021X;
790 #ifdef CONFIG_IEEE80211R
791 else if (os_strcmp(start, "FT-PSK") == 0)
792 val |= WPA_KEY_MGMT_FT_PSK;
793 else if (os_strcmp(start, "FT-EAP") == 0)
794 val |= WPA_KEY_MGMT_FT_IEEE8021X;
795 #endif /* CONFIG_IEEE80211R */
797 printf("Line %d: invalid key_mgmt '%s'\n",
810 printf("Line %d: no key_mgmt values configured.\n", line);
818 static int hostapd_config_parse_cipher(int line, const char *value)
821 char *start, *end, *buf;
823 buf = os_strdup(value);
828 while (start != '\0') {
829 while (*start == ' ' || *start == '\t')
834 while (*end != ' ' && *end != '\t' && *end != '\0')
838 if (os_strcmp(start, "CCMP") == 0)
839 val |= WPA_CIPHER_CCMP;
840 else if (os_strcmp(start, "TKIP") == 0)
841 val |= WPA_CIPHER_TKIP;
842 else if (os_strcmp(start, "WEP104") == 0)
843 val |= WPA_CIPHER_WEP104;
844 else if (os_strcmp(start, "WEP40") == 0)
845 val |= WPA_CIPHER_WEP40;
846 else if (os_strcmp(start, "NONE") == 0)
847 val |= WPA_CIPHER_NONE;
849 printf("Line %d: invalid cipher '%s'.", line, start);
861 printf("Line %d: no cipher values configured.", line);
868 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
869 struct hostapd_config *conf)
871 if (bss->ieee802_1x && !bss->eap_server &&
872 !bss->radius->auth_servers) {
873 printf("Invalid IEEE 802.1X configuration (no EAP "
874 "authenticator configured).\n");
878 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
879 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
880 bss->ssid.wpa_psk_file == NULL) {
881 printf("WPA-PSK enabled, but PSK or passphrase is not "
886 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
889 for (i = 0; i < conf->num_bss; i++) {
890 if ((&conf->bss[i] != bss) &&
891 (hostapd_mac_comp(conf->bss[i].bssid,
893 printf("Duplicate BSSID " MACSTR
894 " on interface '%s' and '%s'.\n",
896 conf->bss[i].iface, bss->iface);
902 #ifdef CONFIG_IEEE80211R
903 if ((bss->wpa_key_mgmt &
904 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
905 (bss->nas_identifier == NULL ||
906 os_strlen(bss->nas_identifier) < 1 ||
907 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
908 printf("FT (IEEE 802.11r) requires nas_identifier to be "
909 "configured as a 1..48 octet string\n");
912 #endif /* CONFIG_IEEE80211R */
918 static int hostapd_config_check(struct hostapd_config *conf)
922 for (i = 0; i < conf->num_bss; i++) {
923 if (hostapd_config_check_bss(&conf->bss[i], conf))
931 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
934 size_t len = os_strlen(val);
936 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
940 if (len < 2 || val[len - 1] != '"')
943 wep->key[keyidx] = os_malloc(len);
944 if (wep->key[keyidx] == NULL)
946 os_memcpy(wep->key[keyidx], val + 1, len);
947 wep->len[keyidx] = len;
952 wep->key[keyidx] = os_malloc(len);
953 if (wep->key[keyidx] == NULL)
955 wep->len[keyidx] = len;
956 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
966 static int hostapd_parse_rates(int **rate_list, char *val)
977 while (*pos != '\0') {
983 list = os_malloc(sizeof(int) * (count + 2));
988 while (*pos != '\0') {
989 end = os_strchr(pos, ' ');
993 list[count++] = atoi(pos);
1005 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1007 struct hostapd_bss_config *bss;
1009 if (*ifname == '\0')
1012 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1013 sizeof(struct hostapd_bss_config));
1015 printf("Failed to allocate memory for multi-BSS entry\n");
1020 bss = &(conf->bss[conf->num_bss]);
1021 os_memset(bss, 0, sizeof(*bss));
1022 bss->radius = os_zalloc(sizeof(*bss->radius));
1023 if (bss->radius == NULL) {
1024 printf("Failed to allocate memory for multi-BSS RADIUS "
1030 conf->last_bss = bss;
1032 hostapd_config_defaults_bss(bss);
1033 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1034 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1040 static int valid_cw(int cw)
1042 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1043 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1048 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1049 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1050 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1051 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1052 IEEE80211_TX_QUEUE_DATA4 = 4,
1053 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1054 IEEE80211_TX_QUEUE_BEACON = 7
1057 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1062 struct hostapd_tx_queue_params *queue;
1064 /* skip 'tx_queue_' prefix */
1066 if (os_strncmp(pos, "data", 4) == 0 &&
1067 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1070 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1071 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1073 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1074 num = IEEE80211_TX_QUEUE_BEACON;
1077 printf("Unknown tx_queue name '%s'\n", pos);
1081 queue = &conf->tx_queue[num];
1083 if (os_strcmp(pos, "aifs") == 0) {
1084 queue->aifs = atoi(val);
1085 if (queue->aifs < 0 || queue->aifs > 255) {
1086 printf("Invalid AIFS value %d\n", queue->aifs);
1089 } else if (os_strcmp(pos, "cwmin") == 0) {
1090 queue->cwmin = atoi(val);
1091 if (!valid_cw(queue->cwmin)) {
1092 printf("Invalid cwMin value %d\n", queue->cwmin);
1095 } else if (os_strcmp(pos, "cwmax") == 0) {
1096 queue->cwmax = atoi(val);
1097 if (!valid_cw(queue->cwmax)) {
1098 printf("Invalid cwMax value %d\n", queue->cwmax);
1101 } else if (os_strcmp(pos, "burst") == 0) {
1102 queue->burst = hostapd_config_read_int10(val);
1104 printf("Unknown tx_queue field '%s'\n", pos);
1108 queue->configured = 1;
1114 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1119 struct hostapd_wme_ac_params *ac;
1121 /* skip 'wme_ac_' prefix */
1123 if (os_strncmp(pos, "be_", 3) == 0) {
1126 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1129 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1132 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1136 printf("Unknown wme name '%s'\n", pos);
1140 ac = &conf->wme_ac_params[num];
1142 if (os_strcmp(pos, "aifs") == 0) {
1144 if (v < 1 || v > 255) {
1145 printf("Invalid AIFS value %d\n", v);
1149 } else if (os_strcmp(pos, "cwmin") == 0) {
1151 if (v < 0 || v > 12) {
1152 printf("Invalid cwMin value %d\n", v);
1156 } else if (os_strcmp(pos, "cwmax") == 0) {
1158 if (v < 0 || v > 12) {
1159 printf("Invalid cwMax value %d\n", v);
1163 } else if (os_strcmp(pos, "txop_limit") == 0) {
1165 if (v < 0 || v > 0xffff) {
1166 printf("Invalid txop value %d\n", v);
1170 } else if (os_strcmp(pos, "acm") == 0) {
1172 if (v < 0 || v > 1) {
1173 printf("Invalid acm value %d\n", v);
1176 ac->admission_control_mandatory = v;
1178 printf("Unknown wme_ac_ field '%s'\n", pos);
1186 #ifdef CONFIG_IEEE80211R
1187 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1189 struct ft_remote_r0kh *r0kh;
1192 r0kh = os_zalloc(sizeof(*r0kh));
1196 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1198 next = os_strchr(pos, ' ');
1201 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1202 printf("Invalid R0KH MAC address: '%s'\n", pos);
1208 next = os_strchr(pos, ' ');
1211 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1212 printf("Invalid R0KH-ID: '%s'\n", pos);
1216 r0kh->id_len = next - pos - 1;
1217 os_memcpy(r0kh->id, pos, r0kh->id_len);
1220 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1221 printf("Invalid R0KH key: '%s'\n", pos);
1226 r0kh->next = bss->r0kh_list;
1227 bss->r0kh_list = r0kh;
1233 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1235 struct ft_remote_r1kh *r1kh;
1238 r1kh = os_zalloc(sizeof(*r1kh));
1242 /* 02:01:02:03:04:05 02:01:02:03:04:05
1243 * 000102030405060708090a0b0c0d0e0f */
1245 next = os_strchr(pos, ' ');
1248 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1249 printf("Invalid R1KH MAC address: '%s'\n", pos);
1255 next = os_strchr(pos, ' ');
1258 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1259 printf("Invalid R1KH-ID: '%s'\n", pos);
1265 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1266 printf("Invalid R1KH key: '%s'\n", pos);
1271 r1kh->next = bss->r1kh_list;
1272 bss->r1kh_list = r1kh;
1276 #endif /* CONFIG_IEEE80211R */
1279 struct hostapd_config * hostapd_config_read(const char *fname)
1281 struct hostapd_config *conf;
1282 struct hostapd_bss_config *bss;
1284 char buf[256], *pos;
1290 f = fopen(fname, "r");
1292 printf("Could not open configuration file '%s' for reading.\n",
1297 conf = hostapd_config_defaults();
1302 bss = conf->last_bss = conf->bss;
1304 while (fgets(buf, sizeof(buf), f)) {
1305 bss = conf->last_bss;
1311 while (*pos != '\0') {
1321 pos = os_strchr(buf, '=');
1323 printf("Line %d: invalid line '%s'\n", line, buf);
1330 if (os_strcmp(buf, "interface") == 0) {
1331 os_strlcpy(conf->bss[0].iface, pos,
1332 sizeof(conf->bss[0].iface));
1333 } else if (os_strcmp(buf, "bridge") == 0) {
1334 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1335 } else if (os_strcmp(buf, "driver") == 0) {
1337 /* clear to get error below if setting is invalid */
1338 conf->driver = NULL;
1339 for (i = 0; hostapd_drivers[i]; i++) {
1340 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1342 conf->driver = hostapd_drivers[i];
1346 if (conf->driver == NULL) {
1347 printf("Line %d: invalid/unknown driver "
1348 "'%s'\n", line, pos);
1351 } else if (os_strcmp(buf, "debug") == 0) {
1352 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1353 "configuration variable is not used "
1355 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1356 bss->logger_syslog_level = atoi(pos);
1357 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1358 bss->logger_stdout_level = atoi(pos);
1359 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1360 bss->logger_syslog = atoi(pos);
1361 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1362 bss->logger_stdout = atoi(pos);
1363 } else if (os_strcmp(buf, "dump_file") == 0) {
1364 bss->dump_log_name = os_strdup(pos);
1365 } else if (os_strcmp(buf, "ssid") == 0) {
1366 bss->ssid.ssid_len = os_strlen(pos);
1367 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1368 bss->ssid.ssid_len < 1) {
1369 printf("Line %d: invalid SSID '%s'\n", line,
1373 os_memcpy(bss->ssid.ssid, pos,
1374 bss->ssid.ssid_len);
1375 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1376 bss->ssid.ssid_set = 1;
1378 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1379 bss->macaddr_acl = atoi(pos);
1380 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1381 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1382 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1383 printf("Line %d: unknown macaddr_acl %d\n",
1384 line, bss->macaddr_acl);
1386 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1387 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1388 &bss->num_accept_mac))
1390 printf("Line %d: Failed to read "
1391 "accept_mac_file '%s'\n",
1395 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1396 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1397 &bss->num_deny_mac))
1399 printf("Line %d: Failed to read "
1400 "deny_mac_file '%s'\n",
1404 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1405 bss->ap_max_inactivity = atoi(pos);
1406 } else if (os_strcmp(buf, "country_code") == 0) {
1407 os_memcpy(conf->country, pos, 2);
1408 /* FIX: make this configurable */
1409 conf->country[2] = ' ';
1410 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1411 conf->ieee80211d = atoi(pos);
1412 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1413 conf->ieee80211h = atoi(pos);
1414 } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
1415 if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
1416 printf("Line %d: invalid MAC address '%s'\n",
1421 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1422 bss->ieee802_1x = atoi(pos);
1423 } else if (os_strcmp(buf, "eapol_version") == 0) {
1424 bss->eapol_version = atoi(pos);
1425 if (bss->eapol_version < 1 ||
1426 bss->eapol_version > 2) {
1427 printf("Line %d: invalid EAPOL "
1428 "version (%d): '%s'.\n",
1429 line, bss->eapol_version, pos);
1432 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1433 bss->eapol_version);
1435 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1436 bss->eap_server = atoi(pos);
1437 printf("Line %d: obsolete eap_authenticator used; "
1438 "this has been renamed to eap_server\n", line);
1439 } else if (os_strcmp(buf, "eap_server") == 0) {
1440 bss->eap_server = atoi(pos);
1441 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1442 if (hostapd_config_read_eap_user(pos, bss))
1444 } else if (os_strcmp(buf, "ca_cert") == 0) {
1445 os_free(bss->ca_cert);
1446 bss->ca_cert = os_strdup(pos);
1447 } else if (os_strcmp(buf, "server_cert") == 0) {
1448 os_free(bss->server_cert);
1449 bss->server_cert = os_strdup(pos);
1450 } else if (os_strcmp(buf, "private_key") == 0) {
1451 os_free(bss->private_key);
1452 bss->private_key = os_strdup(pos);
1453 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1454 os_free(bss->private_key_passwd);
1455 bss->private_key_passwd = os_strdup(pos);
1456 } else if (os_strcmp(buf, "check_crl") == 0) {
1457 bss->check_crl = atoi(pos);
1458 } else if (os_strcmp(buf, "dh_file") == 0) {
1459 os_free(bss->dh_file);
1460 bss->dh_file = os_strdup(pos);
1462 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1463 os_free(bss->pac_opaque_encr_key);
1464 bss->pac_opaque_encr_key = os_malloc(16);
1465 if (bss->pac_opaque_encr_key == NULL) {
1466 printf("Line %d: No memory for "
1467 "pac_opque_encr_key\n", line);
1469 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1471 printf("Line %d: Invalid pac_opque_encr_key\n",
1475 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1476 os_free(bss->eap_fast_a_id);
1477 bss->eap_fast_a_id = os_strdup(pos);
1478 #endif /* EAP_FAST */
1480 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1481 os_free(bss->eap_sim_db);
1482 bss->eap_sim_db = os_strdup(pos);
1483 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1484 bss->eap_sim_aka_result_ind = atoi(pos);
1485 #endif /* EAP_SIM */
1487 } else if (os_strcmp(buf, "tnc") == 0) {
1488 bss->tnc = atoi(pos);
1489 #endif /* EAP_TNC */
1490 #endif /* EAP_SERVER */
1491 } else if (os_strcmp(buf, "eap_message") == 0) {
1493 bss->eap_req_id_text = os_strdup(pos);
1494 if (bss->eap_req_id_text == NULL) {
1495 printf("Line %d: Failed to allocate memory "
1496 "for eap_req_id_text\n", line);
1500 bss->eap_req_id_text_len =
1501 os_strlen(bss->eap_req_id_text);
1502 term = os_strstr(bss->eap_req_id_text, "\\0");
1505 os_memmove(term, term + 1,
1506 bss->eap_req_id_text_len -
1507 (term - bss->eap_req_id_text) - 1);
1508 bss->eap_req_id_text_len--;
1510 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1511 bss->default_wep_key_len = atoi(pos);
1512 if (bss->default_wep_key_len > 13) {
1513 printf("Line %d: invalid WEP key len %lu "
1514 "(= %lu bits)\n", line,
1516 bss->default_wep_key_len,
1518 bss->default_wep_key_len * 8);
1521 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1522 bss->individual_wep_key_len = atoi(pos);
1523 if (bss->individual_wep_key_len < 0 ||
1524 bss->individual_wep_key_len > 13) {
1525 printf("Line %d: invalid WEP key len %d "
1526 "(= %d bits)\n", line,
1527 bss->individual_wep_key_len,
1528 bss->individual_wep_key_len * 8);
1531 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1532 bss->wep_rekeying_period = atoi(pos);
1533 if (bss->wep_rekeying_period < 0) {
1534 printf("Line %d: invalid period %d\n",
1535 line, bss->wep_rekeying_period);
1538 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1539 bss->eap_reauth_period = atoi(pos);
1540 if (bss->eap_reauth_period < 0) {
1541 printf("Line %d: invalid period %d\n",
1542 line, bss->eap_reauth_period);
1545 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1546 bss->eapol_key_index_workaround = atoi(pos);
1548 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1549 bss->ieee802_11f = 1;
1550 os_strlcpy(bss->iapp_iface, pos,
1551 sizeof(bss->iapp_iface));
1552 #endif /* CONFIG_IAPP */
1553 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1554 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1555 printf("Line %d: invalid IP address '%s'\n",
1559 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1560 bss->nas_identifier = os_strdup(pos);
1561 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1562 if (hostapd_config_read_radius_addr(
1563 &bss->radius->auth_servers,
1564 &bss->radius->num_auth_servers, pos, 1812,
1565 &bss->radius->auth_server)) {
1566 printf("Line %d: invalid IP address '%s'\n",
1570 } else if (bss->radius->auth_server &&
1571 os_strcmp(buf, "auth_server_port") == 0) {
1572 bss->radius->auth_server->port = atoi(pos);
1573 } else if (bss->radius->auth_server &&
1574 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1575 int len = os_strlen(pos);
1577 /* RFC 2865, Ch. 3 */
1578 printf("Line %d: empty shared secret is not "
1579 "allowed.\n", line);
1582 bss->radius->auth_server->shared_secret =
1583 (u8 *) os_strdup(pos);
1584 bss->radius->auth_server->shared_secret_len = len;
1585 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1586 if (hostapd_config_read_radius_addr(
1587 &bss->radius->acct_servers,
1588 &bss->radius->num_acct_servers, pos, 1813,
1589 &bss->radius->acct_server)) {
1590 printf("Line %d: invalid IP address '%s'\n",
1594 } else if (bss->radius->acct_server &&
1595 os_strcmp(buf, "acct_server_port") == 0) {
1596 bss->radius->acct_server->port = atoi(pos);
1597 } else if (bss->radius->acct_server &&
1598 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1599 int len = os_strlen(pos);
1601 /* RFC 2865, Ch. 3 */
1602 printf("Line %d: empty shared secret is not "
1603 "allowed.\n", line);
1606 bss->radius->acct_server->shared_secret =
1607 (u8 *) os_strdup(pos);
1608 bss->radius->acct_server->shared_secret_len = len;
1609 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1611 bss->radius->retry_primary_interval = atoi(pos);
1612 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1614 bss->radius->acct_interim_interval = atoi(pos);
1615 } else if (os_strcmp(buf, "auth_algs") == 0) {
1616 bss->auth_algs = atoi(pos);
1617 if (bss->auth_algs == 0) {
1618 printf("Line %d: no authentication algorithms "
1623 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1624 bss->max_num_sta = atoi(pos);
1625 if (bss->max_num_sta < 0 ||
1626 bss->max_num_sta > MAX_STA_COUNT) {
1627 printf("Line %d: Invalid max_num_sta=%d; "
1628 "allowed range 0..%d\n", line,
1629 bss->max_num_sta, MAX_STA_COUNT);
1632 } else if (os_strcmp(buf, "wpa") == 0) {
1633 bss->wpa = atoi(pos);
1634 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1635 bss->wpa_group_rekey = atoi(pos);
1636 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1637 bss->wpa_strict_rekey = atoi(pos);
1638 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1639 bss->wpa_gmk_rekey = atoi(pos);
1640 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1641 int len = os_strlen(pos);
1642 if (len < 8 || len > 63) {
1643 printf("Line %d: invalid WPA passphrase length"
1644 " %d (expected 8..63)\n", line, len);
1647 os_free(bss->ssid.wpa_passphrase);
1648 bss->ssid.wpa_passphrase = os_strdup(pos);
1650 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1651 os_free(bss->ssid.wpa_psk);
1653 os_zalloc(sizeof(struct hostapd_wpa_psk));
1654 if (bss->ssid.wpa_psk == NULL)
1656 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1658 pos[PMK_LEN * 2] != '\0') {
1659 printf("Line %d: Invalid PSK '%s'.\n", line,
1663 bss->ssid.wpa_psk->group = 1;
1665 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1666 os_free(bss->ssid.wpa_psk_file);
1667 bss->ssid.wpa_psk_file = os_strdup(pos);
1668 if (!bss->ssid.wpa_psk_file) {
1669 printf("Line %d: allocation failed\n", line);
1672 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1674 hostapd_config_parse_key_mgmt(line, pos);
1675 if (bss->wpa_key_mgmt == -1)
1677 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1679 hostapd_config_parse_cipher(line, pos);
1680 if (bss->wpa_pairwise == -1 ||
1681 bss->wpa_pairwise == 0)
1683 else if (bss->wpa_pairwise &
1684 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1685 WPA_CIPHER_WEP104)) {
1686 printf("Line %d: unsupported pairwise "
1687 "cipher suite '%s'\n",
1688 bss->wpa_pairwise, pos);
1691 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1693 hostapd_config_parse_cipher(line, pos);
1694 if (bss->rsn_pairwise == -1 ||
1695 bss->rsn_pairwise == 0)
1697 else if (bss->rsn_pairwise &
1698 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1699 WPA_CIPHER_WEP104)) {
1700 printf("Line %d: unsupported pairwise "
1701 "cipher suite '%s'\n",
1702 bss->rsn_pairwise, pos);
1705 #ifdef CONFIG_RSN_PREAUTH
1706 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1707 bss->rsn_preauth = atoi(pos);
1708 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1709 bss->rsn_preauth_interfaces = os_strdup(pos);
1710 #endif /* CONFIG_RSN_PREAUTH */
1711 #ifdef CONFIG_PEERKEY
1712 } else if (os_strcmp(buf, "peerkey") == 0) {
1713 bss->peerkey = atoi(pos);
1714 #endif /* CONFIG_PEERKEY */
1715 #ifdef CONFIG_IEEE80211R
1716 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1717 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1718 hexstr2bin(pos, bss->mobility_domain,
1719 MOBILITY_DOMAIN_ID_LEN) != 0) {
1720 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1721 "mobility_domain '%s'", line, pos);
1725 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1726 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1727 hexstr2bin(pos, bss->r1_key_holder,
1728 FT_R1KH_ID_LEN) != 0) {
1729 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1730 "r1_key_holder '%s'", line, pos);
1734 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1735 bss->r0_key_lifetime = atoi(pos);
1736 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1737 bss->reassociation_deadline = atoi(pos);
1738 } else if (os_strcmp(buf, "r0kh") == 0) {
1739 if (add_r0kh(bss, pos) < 0) {
1740 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1741 "r0kh '%s'", line, pos);
1745 } else if (os_strcmp(buf, "r1kh") == 0) {
1746 if (add_r1kh(bss, pos) < 0) {
1747 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1748 "r1kh '%s'", line, pos);
1752 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1753 bss->pmk_r1_push = atoi(pos);
1754 #endif /* CONFIG_IEEE80211R */
1755 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1756 os_free(bss->ctrl_interface);
1757 bss->ctrl_interface = os_strdup(pos);
1758 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1759 #ifndef CONFIG_NATIVE_WINDOWS
1762 const char *group = pos;
1764 grp = getgrnam(group);
1766 bss->ctrl_interface_gid = grp->gr_gid;
1767 bss->ctrl_interface_gid_set = 1;
1768 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1769 " (from group name '%s')",
1770 bss->ctrl_interface_gid, group);
1774 /* Group name not found - try to parse this as gid */
1775 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1776 if (*group == '\0' || *endp != '\0') {
1777 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1778 "'%s'", line, group);
1782 bss->ctrl_interface_gid_set = 1;
1783 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1784 bss->ctrl_interface_gid);
1785 #endif /* CONFIG_NATIVE_WINDOWS */
1786 #ifdef RADIUS_SERVER
1787 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1788 os_free(bss->radius_server_clients);
1789 bss->radius_server_clients = os_strdup(pos);
1790 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1791 bss->radius_server_auth_port = atoi(pos);
1792 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1793 bss->radius_server_ipv6 = atoi(pos);
1794 #endif /* RADIUS_SERVER */
1795 } else if (os_strcmp(buf, "test_socket") == 0) {
1796 os_free(bss->test_socket);
1797 bss->test_socket = os_strdup(pos);
1798 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1799 bss->use_pae_group_addr = atoi(pos);
1800 } else if (os_strcmp(buf, "hw_mode") == 0) {
1801 if (os_strcmp(pos, "a") == 0)
1802 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1803 else if (os_strcmp(pos, "b") == 0)
1804 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1805 else if (os_strcmp(pos, "g") == 0)
1806 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1808 printf("Line %d: unknown hw_mode '%s'\n",
1812 } else if (os_strcmp(buf, "channel") == 0) {
1813 conf->channel = atoi(pos);
1814 } else if (os_strcmp(buf, "beacon_int") == 0) {
1815 int val = atoi(pos);
1816 /* MIB defines range as 1..65535, but very small values
1817 * cause problems with the current implementation.
1818 * Since it is unlikely that this small numbers are
1819 * useful in real life scenarios, do not allow beacon
1820 * period to be set below 15 TU. */
1821 if (val < 15 || val > 65535) {
1822 printf("Line %d: invalid beacon_int %d "
1823 "(expected 15..65535)\n",
1827 conf->beacon_int = val;
1828 } else if (os_strcmp(buf, "dtim_period") == 0) {
1829 bss->dtim_period = atoi(pos);
1830 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1831 printf("Line %d: invalid dtim_period %d\n",
1832 line, bss->dtim_period);
1835 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1836 conf->rts_threshold = atoi(pos);
1837 if (conf->rts_threshold < 0 ||
1838 conf->rts_threshold > 2347) {
1839 printf("Line %d: invalid rts_threshold %d\n",
1840 line, conf->rts_threshold);
1843 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1844 conf->fragm_threshold = atoi(pos);
1845 if (conf->fragm_threshold < 256 ||
1846 conf->fragm_threshold > 2346) {
1847 printf("Line %d: invalid fragm_threshold %d\n",
1848 line, conf->fragm_threshold);
1851 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1852 int val = atoi(pos);
1853 if (val != 0 && val != 1) {
1854 printf("Line %d: invalid send_probe_response "
1855 "%d (expected 0 or 1)\n", line, val);
1857 conf->send_probe_response = val;
1858 } else if (os_strcmp(buf, "supported_rates") == 0) {
1859 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
1860 printf("Line %d: invalid rate list\n", line);
1863 } else if (os_strcmp(buf, "basic_rates") == 0) {
1864 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
1865 printf("Line %d: invalid rate list\n", line);
1868 } else if (os_strcmp(buf, "preamble") == 0) {
1870 conf->preamble = SHORT_PREAMBLE;
1872 conf->preamble = LONG_PREAMBLE;
1873 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
1874 bss->ignore_broadcast_ssid = atoi(pos);
1875 } else if (os_strcmp(buf, "bridge_packets") == 0) {
1876 conf->bridge_packets = atoi(pos);
1877 } else if (os_strcmp(buf, "wep_default_key") == 0) {
1878 bss->ssid.wep.idx = atoi(pos);
1879 if (bss->ssid.wep.idx > 3) {
1880 printf("Invalid wep_default_key index %d\n",
1884 } else if (os_strcmp(buf, "wep_key0") == 0 ||
1885 os_strcmp(buf, "wep_key1") == 0 ||
1886 os_strcmp(buf, "wep_key2") == 0 ||
1887 os_strcmp(buf, "wep_key3") == 0) {
1888 if (hostapd_config_read_wep(&bss->ssid.wep,
1889 buf[7] - '0', pos)) {
1890 printf("Line %d: invalid WEP key '%s'\n",
1894 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
1895 bss->ssid.dynamic_vlan = atoi(pos);
1896 } else if (os_strcmp(buf, "vlan_file") == 0) {
1897 if (hostapd_config_read_vlan_file(bss, pos)) {
1898 printf("Line %d: failed to read VLAN file "
1899 "'%s'\n", line, pos);
1902 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1903 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
1904 bss->ssid.vlan_tagged_interface = os_strdup(pos);
1905 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1906 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
1907 conf->passive_scan_interval = atoi(pos);
1908 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
1909 conf->passive_scan_listen = atoi(pos);
1910 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
1911 conf->passive_scan_mode = atoi(pos);
1912 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
1913 conf->ap_table_max_size = atoi(pos);
1914 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
1915 conf->ap_table_expiration_time = atoi(pos);
1916 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
1917 if (hostapd_config_tx_queue(conf, buf, pos)) {
1918 printf("Line %d: invalid TX queue item\n",
1922 } else if (os_strcmp(buf, "wme_enabled") == 0) {
1923 bss->wme_enabled = atoi(pos);
1924 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
1925 if (hostapd_config_wme_ac(conf, buf, pos)) {
1926 printf("Line %d: invalid wme ac item\n",
1930 } else if (os_strcmp(buf, "bss") == 0) {
1931 if (hostapd_config_bss(conf, pos)) {
1932 printf("Line %d: invalid bss item\n", line);
1935 } else if (os_strcmp(buf, "bssid") == 0) {
1936 if (bss == conf->bss &&
1937 (!conf->driver || !conf->driver->init_bssid)) {
1938 printf("Line %d: bssid item not allowed "
1939 "for the default interface and this "
1942 } else if (hwaddr_aton(pos, bss->bssid)) {
1943 printf("Line %d: invalid bssid item\n", line);
1946 #ifdef CONFIG_IEEE80211W
1947 } else if (os_strcmp(buf, "ieee80211w") == 0) {
1948 bss->ieee80211w = atoi(pos);
1949 #endif /* CONFIG_IEEE80211W */
1950 #ifdef CONFIG_IEEE80211N
1951 } else if (os_strcmp(buf, "ieee80211n") == 0) {
1952 conf->ieee80211n = atoi(pos);
1953 #endif /* CONFIG_IEEE80211N */
1954 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
1955 bss->max_listen_interval = atoi(pos);
1956 } else if (os_strcmp(buf, "okc") == 0) {
1957 bss->okc = atoi(pos);
1959 printf("Line %d: unknown configuration item '%s'\n",
1967 if (bss->individual_wep_key_len == 0) {
1968 /* individual keys are not use; can use key idx0 for broadcast
1970 bss->broadcast_key_idx_min = 0;
1973 /* Select group cipher based on the enabled pairwise cipher suites */
1976 pairwise |= bss->wpa_pairwise;
1978 if (bss->rsn_pairwise == 0)
1979 bss->rsn_pairwise = bss->wpa_pairwise;
1980 pairwise |= bss->rsn_pairwise;
1982 if (pairwise & WPA_CIPHER_TKIP)
1983 bss->wpa_group = WPA_CIPHER_TKIP;
1985 bss->wpa_group = WPA_CIPHER_CCMP;
1987 for (i = 0; i < conf->num_bss; i++) {
1988 bss = &conf->bss[i];
1990 bss->radius->auth_server = bss->radius->auth_servers;
1991 bss->radius->acct_server = bss->radius->acct_servers;
1993 if (bss->wpa && bss->ieee802_1x) {
1994 bss->ssid.security_policy = SECURITY_WPA;
1995 } else if (bss->wpa) {
1996 bss->ssid.security_policy = SECURITY_WPA_PSK;
1997 } else if (bss->ieee802_1x) {
1998 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1999 bss->ssid.wep.default_len = bss->default_wep_key_len;
2000 } else if (bss->ssid.wep.keys_set)
2001 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2003 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2006 if (hostapd_config_check(conf))
2010 printf("%d errors found in configuration file '%s'\n",
2012 hostapd_config_free(conf);
2020 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2024 if (a->idx != b->idx || a->default_len != b->default_len)
2026 for (i = 0; i < NUM_WEP_KEYS; i++)
2027 if (a->len[i] != b->len[i] ||
2028 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2034 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2039 for (i = 0; i < num_servers; i++) {
2040 os_free(servers[i].shared_secret);
2046 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2048 os_free(user->identity);
2049 os_free(user->password);
2054 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2057 for (i = 0; i < NUM_WEP_KEYS; i++) {
2058 os_free(keys->key[i]);
2059 keys->key[i] = NULL;
2064 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2066 struct hostapd_wpa_psk *psk, *prev;
2067 struct hostapd_eap_user *user, *prev_user;
2072 psk = conf->ssid.wpa_psk;
2079 os_free(conf->ssid.wpa_passphrase);
2080 os_free(conf->ssid.wpa_psk_file);
2081 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2082 os_free(conf->ssid.vlan_tagged_interface);
2083 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2085 user = conf->eap_user;
2089 hostapd_config_free_eap_user(prev_user);
2092 os_free(conf->dump_log_name);
2093 os_free(conf->eap_req_id_text);
2094 os_free(conf->accept_mac);
2095 os_free(conf->deny_mac);
2096 os_free(conf->nas_identifier);
2097 hostapd_config_free_radius(conf->radius->auth_servers,
2098 conf->radius->num_auth_servers);
2099 hostapd_config_free_radius(conf->radius->acct_servers,
2100 conf->radius->num_acct_servers);
2101 os_free(conf->rsn_preauth_interfaces);
2102 os_free(conf->ctrl_interface);
2103 os_free(conf->ca_cert);
2104 os_free(conf->server_cert);
2105 os_free(conf->private_key);
2106 os_free(conf->private_key_passwd);
2107 os_free(conf->dh_file);
2108 os_free(conf->pac_opaque_encr_key);
2109 os_free(conf->eap_fast_a_id);
2110 os_free(conf->eap_sim_db);
2111 os_free(conf->radius_server_clients);
2112 os_free(conf->test_socket);
2113 os_free(conf->radius);
2114 hostapd_config_free_vlan(conf);
2115 if (conf->ssid.dyn_vlan_keys) {
2116 struct hostapd_ssid *ssid = &conf->ssid;
2118 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2119 if (ssid->dyn_vlan_keys[i] == NULL)
2121 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2122 os_free(ssid->dyn_vlan_keys[i]);
2124 os_free(ssid->dyn_vlan_keys);
2125 ssid->dyn_vlan_keys = NULL;
2128 #ifdef CONFIG_IEEE80211R
2130 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2131 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2133 r0kh = conf->r0kh_list;
2134 conf->r0kh_list = NULL;
2141 r1kh = conf->r1kh_list;
2142 conf->r1kh_list = NULL;
2149 #endif /* CONFIG_IEEE80211R */
2153 void hostapd_config_free(struct hostapd_config *conf)
2160 for (i = 0; i < conf->num_bss; i++)
2161 hostapd_config_free_bss(&conf->bss[i]);
2168 /* Perform a binary search for given MAC address from a pre-sorted list.
2169 * Returns 1 if address is in the list or 0 if not. */
2170 int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
2172 int start, end, middle, res;
2175 end = num_entries - 1;
2177 while (start <= end) {
2178 middle = (start + end) / 2;
2179 res = os_memcmp(list[middle], addr, ETH_ALEN);
2192 int hostapd_rate_found(int *list, int rate)
2199 for (i = 0; list[i] >= 0; i++)
2200 if (list[i] == rate)
2207 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2209 struct hostapd_vlan *v = vlan;
2211 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2219 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2220 const u8 *addr, const u8 *prev_psk)
2222 struct hostapd_wpa_psk *psk;
2223 int next_ok = prev_psk == NULL;
2225 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2227 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2230 if (psk->psk == prev_psk)
2238 const struct hostapd_eap_user *
2239 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2240 size_t identity_len, int phase2)
2242 struct hostapd_eap_user *user = conf->eap_user;
2245 if (!phase2 && user->identity == NULL) {
2246 /* Wildcard match */
2250 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2251 identity_len >= user->identity_len &&
2252 os_memcmp(user->identity, identity, user->identity_len) ==
2254 /* Wildcard prefix match */
2258 if (user->phase2 == !!phase2 &&
2259 user->identity_len == identity_len &&
2260 os_memcmp(user->identity, identity, identity_len) == 0)