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 */
192 static struct hostapd_config * hostapd_config_defaults(void)
194 struct hostapd_config *conf;
195 struct hostapd_bss_config *bss;
197 const int aCWmin = 15, aCWmax = 1024;
198 const struct hostapd_wme_ac_params ac_bk =
199 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
200 const struct hostapd_wme_ac_params ac_be =
201 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
202 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
203 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
204 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
205 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
207 conf = os_zalloc(sizeof(*conf));
208 bss = os_zalloc(sizeof(*bss));
209 if (conf == NULL || bss == NULL) {
210 printf("Failed to allocate memory for configuration data.\n");
216 /* set default driver based on configuration */
217 conf->driver = hostapd_drivers[0];
218 if (conf->driver == NULL) {
219 printf("No driver wrappers registered!\n");
225 bss->radius = os_zalloc(sizeof(*bss->radius));
226 if (bss->radius == NULL) {
232 hostapd_config_defaults_bss(bss);
237 conf->beacon_int = 100;
238 conf->rts_threshold = -1; /* use driver default: 2347 */
239 conf->fragm_threshold = -1; /* user driver default: 2346 */
240 conf->send_probe_response = 1;
241 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
243 os_memcpy(conf->country, "US ", 3);
245 for (i = 0; i < NUM_TX_QUEUES; i++)
246 conf->tx_queue[i].aifs = -1; /* use hw default */
248 conf->wme_ac_params[0] = ac_be;
249 conf->wme_ac_params[1] = ac_bk;
250 conf->wme_ac_params[2] = ac_vi;
251 conf->wme_ac_params[3] = ac_vo;
253 #ifdef CONFIG_IEEE80211N
254 SET_2BIT_LE16(&conf->ht_capab,
255 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
256 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
258 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
259 #endif /* CONFIG_IEEE80211N */
265 int hostapd_mac_comp(const void *a, const void *b)
267 return os_memcmp(a, b, sizeof(macaddr));
271 int hostapd_mac_comp_empty(const void *a)
273 macaddr empty = { 0 };
274 return os_memcmp(a, empty, sizeof(macaddr));
278 static int hostapd_acl_comp(const void *a, const void *b)
280 const struct mac_acl_entry *aa = a;
281 const struct mac_acl_entry *bb = b;
282 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
286 static int hostapd_config_read_maclist(const char *fname,
287 struct mac_acl_entry **acl, int *num)
293 struct mac_acl_entry *newacl;
299 f = fopen(fname, "r");
301 printf("MAC list file '%s' not found.\n", fname);
305 while (fgets(buf, sizeof(buf), f)) {
311 while (*pos != '\0') {
321 if (hwaddr_aton(buf, addr)) {
322 printf("Invalid MAC address '%s' at line %d in '%s'\n",
330 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
332 while (*pos == ' ' || *pos == '\t')
337 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
338 if (newacl == NULL) {
339 printf("MAC list reallocation failed\n");
345 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
346 (*acl)[*num].vlan_id = vlan_id;
352 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
358 static int hostapd_config_read_wpa_psk(const char *fname,
359 struct hostapd_ssid *ssid)
363 int line = 0, ret = 0, len, ok;
365 struct hostapd_wpa_psk *psk;
370 f = fopen(fname, "r");
372 printf("WPA PSK file '%s' not found.\n", fname);
376 while (fgets(buf, sizeof(buf), f)) {
382 while (*pos != '\0') {
392 if (hwaddr_aton(buf, addr)) {
393 printf("Invalid MAC address '%s' on line %d in '%s'\n",
399 psk = os_zalloc(sizeof(*psk));
401 printf("WPA PSK allocation failed\n");
405 if (is_zero_ether_addr(addr))
408 os_memcpy(psk->addr, addr, ETH_ALEN);
412 printf("No PSK on line %d in '%s'\n", line, fname);
420 len = os_strlen(pos);
421 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
423 else if (len >= 8 && len < 64) {
424 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
425 4096, psk->psk, PMK_LEN);
429 printf("Invalid PSK '%s' on line %d in '%s'\n",
436 psk->next = ssid->wpa_psk;
446 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
448 struct hostapd_ssid *ssid = &conf->ssid;
450 if (ssid->wpa_passphrase != NULL) {
451 if (ssid->wpa_psk != NULL) {
452 printf("Warning: both WPA PSK and passphrase set. "
453 "Using passphrase.\n");
454 os_free(ssid->wpa_psk);
456 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
457 if (ssid->wpa_psk == NULL) {
458 printf("Unable to alloc space for PSK\n");
461 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
462 (u8 *) ssid->ssid, ssid->ssid_len);
463 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
464 (u8 *) ssid->wpa_passphrase,
465 os_strlen(ssid->wpa_passphrase));
466 pbkdf2_sha1(ssid->wpa_passphrase,
467 ssid->ssid, ssid->ssid_len,
468 4096, ssid->wpa_psk->psk, PMK_LEN);
469 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
470 ssid->wpa_psk->psk, PMK_LEN);
471 ssid->wpa_psk->group = 1;
473 os_memset(ssid->wpa_passphrase, 0,
474 os_strlen(ssid->wpa_passphrase));
475 os_free(ssid->wpa_passphrase);
476 ssid->wpa_passphrase = NULL;
479 if (ssid->wpa_psk_file) {
480 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
490 static int hostapd_config_read_eap_user(const char *fname,
491 struct hostapd_bss_config *conf)
494 char buf[512], *pos, *start, *pos2;
495 int line = 0, ret = 0, num_methods;
496 struct hostapd_eap_user *user, *tail = NULL;
501 f = fopen(fname, "r");
503 printf("EAP user file '%s' not found.\n", fname);
507 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
508 while (fgets(buf, sizeof(buf), f)) {
514 while (*pos != '\0') {
526 if (buf[0] != '"' && buf[0] != '*') {
527 printf("Invalid EAP identity (no \" in start) on "
528 "line %d in '%s'\n", line, fname);
532 user = os_zalloc(sizeof(*user));
534 printf("EAP user allocation failed\n");
537 user->force_version = -1;
544 while (*pos != '"' && *pos != '\0')
547 printf("Invalid EAP identity (no \" in end) on"
548 " line %d in '%s'\n", line, fname);
552 user->identity = os_malloc(pos - start);
553 if (user->identity == NULL) {
554 printf("Failed to allocate memory for EAP "
558 os_memcpy(user->identity, start, pos - start);
559 user->identity_len = pos - start;
561 if (pos[0] == '"' && pos[1] == '*') {
562 user->wildcard_prefix = 1;
567 while (*pos == ' ' || *pos == '\t')
571 printf("No EAP method on line %d in '%s'\n",
577 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
587 char *pos3 = os_strchr(start, ',');
591 user->methods[num_methods].method =
594 &user->methods[num_methods].vendor);
595 if (user->methods[num_methods].vendor ==
597 user->methods[num_methods].method == EAP_TYPE_NONE)
599 if (os_strcmp(start, "TTLS-PAP") == 0) {
600 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
603 if (os_strcmp(start, "TTLS-CHAP") == 0) {
604 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
607 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
609 EAP_TTLS_AUTH_MSCHAP;
612 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
614 EAP_TTLS_AUTH_MSCHAPV2;
617 printf("Unsupported EAP type '%s' on line %d "
618 "in '%s'\n", start, line, fname);
623 if (num_methods >= EAP_USER_MAX_METHODS)
630 if (num_methods == 0 && user->ttls_auth == 0) {
631 printf("No EAP types configured on line %d in '%s'\n",
639 while (*pos == ' ' || *pos == '\t')
644 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
645 user->force_version = 0;
649 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
650 user->force_version = 1;
654 if (os_strncmp(pos, "[2]", 3) == 0) {
662 while (*pos != '"' && *pos != '\0')
665 printf("Invalid EAP password (no \" in end) "
666 "on line %d in '%s'\n", line, fname);
670 user->password = os_malloc(pos - start);
671 if (user->password == NULL) {
672 printf("Failed to allocate memory for EAP "
676 os_memcpy(user->password, start, pos - start);
677 user->password_len = pos - start;
680 } else if (os_strncmp(pos, "hash:", 5) == 0) {
683 while (*pos2 != '\0' && *pos2 != ' ' &&
684 *pos2 != '\t' && *pos2 != '#')
686 if (pos2 - pos != 32) {
687 printf("Invalid password hash on line %d in "
688 "'%s'\n", line, fname);
691 user->password = os_malloc(16);
692 if (user->password == NULL) {
693 printf("Failed to allocate memory for EAP "
697 if (hexstr2bin(pos, user->password, 16) < 0) {
698 printf("Invalid hash password on line %d in "
699 "'%s'\n", line, fname);
702 user->password_len = 16;
703 user->password_hash = 1;
707 while (*pos2 != '\0' && *pos2 != ' ' &&
708 *pos2 != '\t' && *pos2 != '#')
710 if ((pos2 - pos) & 1) {
711 printf("Invalid hex password on line %d in "
712 "'%s'\n", line, fname);
715 user->password = os_malloc((pos2 - pos) / 2);
716 if (user->password == NULL) {
717 printf("Failed to allocate memory for EAP "
721 if (hexstr2bin(pos, user->password,
722 (pos2 - pos) / 2) < 0) {
723 printf("Invalid hex password on line %d in "
724 "'%s'\n", line, fname);
727 user->password_len = (pos2 - pos) / 2;
731 while (*pos == ' ' || *pos == '\t')
733 if (os_strncmp(pos, "[2]", 3) == 0) {
739 tail = conf->eap_user = user;
748 os_free(user->password);
749 os_free(user->identity);
760 #endif /* EAP_SERVER */
764 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
765 int *num_server, const char *val, int def_port,
766 struct hostapd_radius_server **curr_serv)
768 struct hostapd_radius_server *nserv;
770 static int server_index = 1;
772 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
777 nserv = &nserv[*num_server];
779 (*curr_serv) = nserv;
781 os_memset(nserv, 0, sizeof(*nserv));
782 nserv->port = def_port;
783 ret = hostapd_parse_ip_addr(val, &nserv->addr);
784 nserv->index = server_index++;
790 static int hostapd_config_parse_key_mgmt(int line, const char *value)
793 char *start, *end, *buf;
795 buf = os_strdup(value);
800 while (start != '\0') {
801 while (*start == ' ' || *start == '\t')
806 while (*end != ' ' && *end != '\t' && *end != '\0')
810 if (os_strcmp(start, "WPA-PSK") == 0)
811 val |= WPA_KEY_MGMT_PSK;
812 else if (os_strcmp(start, "WPA-EAP") == 0)
813 val |= WPA_KEY_MGMT_IEEE8021X;
814 #ifdef CONFIG_IEEE80211R
815 else if (os_strcmp(start, "FT-PSK") == 0)
816 val |= WPA_KEY_MGMT_FT_PSK;
817 else if (os_strcmp(start, "FT-EAP") == 0)
818 val |= WPA_KEY_MGMT_FT_IEEE8021X;
819 #endif /* CONFIG_IEEE80211R */
820 #ifdef CONFIG_IEEE80211W
821 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
822 val |= WPA_KEY_MGMT_PSK_SHA256;
823 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
824 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
825 #endif /* CONFIG_IEEE80211W */
827 printf("Line %d: invalid key_mgmt '%s'\n",
840 printf("Line %d: no key_mgmt values configured.\n", line);
848 static int hostapd_config_parse_cipher(int line, const char *value)
851 char *start, *end, *buf;
853 buf = os_strdup(value);
858 while (start != '\0') {
859 while (*start == ' ' || *start == '\t')
864 while (*end != ' ' && *end != '\t' && *end != '\0')
868 if (os_strcmp(start, "CCMP") == 0)
869 val |= WPA_CIPHER_CCMP;
870 else if (os_strcmp(start, "TKIP") == 0)
871 val |= WPA_CIPHER_TKIP;
872 else if (os_strcmp(start, "WEP104") == 0)
873 val |= WPA_CIPHER_WEP104;
874 else if (os_strcmp(start, "WEP40") == 0)
875 val |= WPA_CIPHER_WEP40;
876 else if (os_strcmp(start, "NONE") == 0)
877 val |= WPA_CIPHER_NONE;
879 printf("Line %d: invalid cipher '%s'.", line, start);
891 printf("Line %d: no cipher values configured.", line);
898 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
899 struct hostapd_config *conf)
901 if (bss->ieee802_1x && !bss->eap_server &&
902 !bss->radius->auth_servers) {
903 printf("Invalid IEEE 802.1X configuration (no EAP "
904 "authenticator configured).\n");
908 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
909 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
910 bss->ssid.wpa_psk_file == NULL) {
911 printf("WPA-PSK enabled, but PSK or passphrase is not "
916 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
919 for (i = 0; i < conf->num_bss; i++) {
920 if ((&conf->bss[i] != bss) &&
921 (hostapd_mac_comp(conf->bss[i].bssid,
923 printf("Duplicate BSSID " MACSTR
924 " on interface '%s' and '%s'.\n",
926 conf->bss[i].iface, bss->iface);
932 #ifdef CONFIG_IEEE80211R
933 if ((bss->wpa_key_mgmt &
934 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
935 (bss->nas_identifier == NULL ||
936 os_strlen(bss->nas_identifier) < 1 ||
937 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
938 printf("FT (IEEE 802.11r) requires nas_identifier to be "
939 "configured as a 1..48 octet string\n");
942 #endif /* CONFIG_IEEE80211R */
948 static int hostapd_config_check(struct hostapd_config *conf)
952 for (i = 0; i < conf->num_bss; i++) {
953 if (hostapd_config_check_bss(&conf->bss[i], conf))
961 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
964 size_t len = os_strlen(val);
966 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
970 if (len < 2 || val[len - 1] != '"')
973 wep->key[keyidx] = os_malloc(len);
974 if (wep->key[keyidx] == NULL)
976 os_memcpy(wep->key[keyidx], val + 1, len);
977 wep->len[keyidx] = len;
982 wep->key[keyidx] = os_malloc(len);
983 if (wep->key[keyidx] == NULL)
985 wep->len[keyidx] = len;
986 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
996 static int hostapd_parse_rates(int **rate_list, char *val)
1002 os_free(*rate_list);
1007 while (*pos != '\0') {
1013 list = os_malloc(sizeof(int) * (count + 2));
1018 while (*pos != '\0') {
1019 end = os_strchr(pos, ' ');
1023 list[count++] = atoi(pos);
1035 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1037 struct hostapd_bss_config *bss;
1039 if (*ifname == '\0')
1042 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1043 sizeof(struct hostapd_bss_config));
1045 printf("Failed to allocate memory for multi-BSS entry\n");
1050 bss = &(conf->bss[conf->num_bss]);
1051 os_memset(bss, 0, sizeof(*bss));
1052 bss->radius = os_zalloc(sizeof(*bss->radius));
1053 if (bss->radius == NULL) {
1054 printf("Failed to allocate memory for multi-BSS RADIUS "
1060 conf->last_bss = bss;
1062 hostapd_config_defaults_bss(bss);
1063 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1064 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1070 static int valid_cw(int cw)
1072 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1073 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1078 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1079 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1080 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1081 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1082 IEEE80211_TX_QUEUE_DATA4 = 4,
1083 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1084 IEEE80211_TX_QUEUE_BEACON = 7
1087 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1092 struct hostapd_tx_queue_params *queue;
1094 /* skip 'tx_queue_' prefix */
1096 if (os_strncmp(pos, "data", 4) == 0 &&
1097 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1100 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1101 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1103 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1104 num = IEEE80211_TX_QUEUE_BEACON;
1107 printf("Unknown tx_queue name '%s'\n", pos);
1111 queue = &conf->tx_queue[num];
1113 if (os_strcmp(pos, "aifs") == 0) {
1114 queue->aifs = atoi(val);
1115 if (queue->aifs < 0 || queue->aifs > 255) {
1116 printf("Invalid AIFS value %d\n", queue->aifs);
1119 } else if (os_strcmp(pos, "cwmin") == 0) {
1120 queue->cwmin = atoi(val);
1121 if (!valid_cw(queue->cwmin)) {
1122 printf("Invalid cwMin value %d\n", queue->cwmin);
1125 } else if (os_strcmp(pos, "cwmax") == 0) {
1126 queue->cwmax = atoi(val);
1127 if (!valid_cw(queue->cwmax)) {
1128 printf("Invalid cwMax value %d\n", queue->cwmax);
1131 } else if (os_strcmp(pos, "burst") == 0) {
1132 queue->burst = hostapd_config_read_int10(val);
1134 printf("Unknown tx_queue field '%s'\n", pos);
1138 queue->configured = 1;
1144 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1149 struct hostapd_wme_ac_params *ac;
1151 /* skip 'wme_ac_' prefix */
1153 if (os_strncmp(pos, "be_", 3) == 0) {
1156 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1159 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1162 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1166 printf("Unknown wme name '%s'\n", pos);
1170 ac = &conf->wme_ac_params[num];
1172 if (os_strcmp(pos, "aifs") == 0) {
1174 if (v < 1 || v > 255) {
1175 printf("Invalid AIFS value %d\n", v);
1179 } else if (os_strcmp(pos, "cwmin") == 0) {
1181 if (v < 0 || v > 12) {
1182 printf("Invalid cwMin value %d\n", v);
1186 } else if (os_strcmp(pos, "cwmax") == 0) {
1188 if (v < 0 || v > 12) {
1189 printf("Invalid cwMax value %d\n", v);
1193 } else if (os_strcmp(pos, "txop_limit") == 0) {
1195 if (v < 0 || v > 0xffff) {
1196 printf("Invalid txop value %d\n", v);
1200 } else if (os_strcmp(pos, "acm") == 0) {
1202 if (v < 0 || v > 1) {
1203 printf("Invalid acm value %d\n", v);
1206 ac->admission_control_mandatory = v;
1208 printf("Unknown wme_ac_ field '%s'\n", pos);
1216 #ifdef CONFIG_IEEE80211R
1217 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1219 struct ft_remote_r0kh *r0kh;
1222 r0kh = os_zalloc(sizeof(*r0kh));
1226 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1228 next = os_strchr(pos, ' ');
1231 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1232 printf("Invalid R0KH MAC address: '%s'\n", pos);
1238 next = os_strchr(pos, ' ');
1241 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1242 printf("Invalid R0KH-ID: '%s'\n", pos);
1246 r0kh->id_len = next - pos - 1;
1247 os_memcpy(r0kh->id, pos, r0kh->id_len);
1250 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1251 printf("Invalid R0KH key: '%s'\n", pos);
1256 r0kh->next = bss->r0kh_list;
1257 bss->r0kh_list = r0kh;
1263 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1265 struct ft_remote_r1kh *r1kh;
1268 r1kh = os_zalloc(sizeof(*r1kh));
1272 /* 02:01:02:03:04:05 02:01:02:03:04:05
1273 * 000102030405060708090a0b0c0d0e0f */
1275 next = os_strchr(pos, ' ');
1278 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1279 printf("Invalid R1KH MAC address: '%s'\n", pos);
1285 next = os_strchr(pos, ' ');
1288 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1289 printf("Invalid R1KH-ID: '%s'\n", pos);
1295 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1296 printf("Invalid R1KH key: '%s'\n", pos);
1301 r1kh->next = bss->r1kh_list;
1302 bss->r1kh_list = r1kh;
1306 #endif /* CONFIG_IEEE80211R */
1309 struct hostapd_config * hostapd_config_read(const char *fname)
1311 struct hostapd_config *conf;
1312 struct hostapd_bss_config *bss;
1314 char buf[256], *pos;
1320 f = fopen(fname, "r");
1322 printf("Could not open configuration file '%s' for reading.\n",
1327 conf = hostapd_config_defaults();
1332 bss = conf->last_bss = conf->bss;
1334 while (fgets(buf, sizeof(buf), f)) {
1335 bss = conf->last_bss;
1341 while (*pos != '\0') {
1351 pos = os_strchr(buf, '=');
1353 printf("Line %d: invalid line '%s'\n", line, buf);
1360 if (os_strcmp(buf, "interface") == 0) {
1361 os_strlcpy(conf->bss[0].iface, pos,
1362 sizeof(conf->bss[0].iface));
1363 } else if (os_strcmp(buf, "bridge") == 0) {
1364 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1365 } else if (os_strcmp(buf, "driver") == 0) {
1367 /* clear to get error below if setting is invalid */
1368 conf->driver = NULL;
1369 for (i = 0; hostapd_drivers[i]; i++) {
1370 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1372 conf->driver = hostapd_drivers[i];
1376 if (conf->driver == NULL) {
1377 printf("Line %d: invalid/unknown driver "
1378 "'%s'\n", line, pos);
1381 } else if (os_strcmp(buf, "debug") == 0) {
1382 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1383 "configuration variable is not used "
1385 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1386 bss->logger_syslog_level = atoi(pos);
1387 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1388 bss->logger_stdout_level = atoi(pos);
1389 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1390 bss->logger_syslog = atoi(pos);
1391 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1392 bss->logger_stdout = atoi(pos);
1393 } else if (os_strcmp(buf, "dump_file") == 0) {
1394 bss->dump_log_name = os_strdup(pos);
1395 } else if (os_strcmp(buf, "ssid") == 0) {
1396 bss->ssid.ssid_len = os_strlen(pos);
1397 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1398 bss->ssid.ssid_len < 1) {
1399 printf("Line %d: invalid SSID '%s'\n", line,
1403 os_memcpy(bss->ssid.ssid, pos,
1404 bss->ssid.ssid_len);
1405 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1406 bss->ssid.ssid_set = 1;
1408 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1409 bss->macaddr_acl = atoi(pos);
1410 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1411 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1412 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1413 printf("Line %d: unknown macaddr_acl %d\n",
1414 line, bss->macaddr_acl);
1416 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1417 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1418 &bss->num_accept_mac))
1420 printf("Line %d: Failed to read "
1421 "accept_mac_file '%s'\n",
1425 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1426 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1427 &bss->num_deny_mac))
1429 printf("Line %d: Failed to read "
1430 "deny_mac_file '%s'\n",
1434 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1435 bss->ap_max_inactivity = atoi(pos);
1436 } else if (os_strcmp(buf, "country_code") == 0) {
1437 os_memcpy(conf->country, pos, 2);
1438 /* FIX: make this configurable */
1439 conf->country[2] = ' ';
1440 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1441 conf->ieee80211d = atoi(pos);
1442 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1443 conf->ieee80211h = atoi(pos);
1444 } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
1445 if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
1446 printf("Line %d: invalid MAC address '%s'\n",
1451 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1452 bss->ieee802_1x = atoi(pos);
1453 } else if (os_strcmp(buf, "eapol_version") == 0) {
1454 bss->eapol_version = atoi(pos);
1455 if (bss->eapol_version < 1 ||
1456 bss->eapol_version > 2) {
1457 printf("Line %d: invalid EAPOL "
1458 "version (%d): '%s'.\n",
1459 line, bss->eapol_version, pos);
1462 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1463 bss->eapol_version);
1465 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1466 bss->eap_server = atoi(pos);
1467 printf("Line %d: obsolete eap_authenticator used; "
1468 "this has been renamed to eap_server\n", line);
1469 } else if (os_strcmp(buf, "eap_server") == 0) {
1470 bss->eap_server = atoi(pos);
1471 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1472 if (hostapd_config_read_eap_user(pos, bss))
1474 } else if (os_strcmp(buf, "ca_cert") == 0) {
1475 os_free(bss->ca_cert);
1476 bss->ca_cert = os_strdup(pos);
1477 } else if (os_strcmp(buf, "server_cert") == 0) {
1478 os_free(bss->server_cert);
1479 bss->server_cert = os_strdup(pos);
1480 } else if (os_strcmp(buf, "private_key") == 0) {
1481 os_free(bss->private_key);
1482 bss->private_key = os_strdup(pos);
1483 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1484 os_free(bss->private_key_passwd);
1485 bss->private_key_passwd = os_strdup(pos);
1486 } else if (os_strcmp(buf, "check_crl") == 0) {
1487 bss->check_crl = atoi(pos);
1488 } else if (os_strcmp(buf, "dh_file") == 0) {
1489 os_free(bss->dh_file);
1490 bss->dh_file = os_strdup(pos);
1492 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1493 os_free(bss->pac_opaque_encr_key);
1494 bss->pac_opaque_encr_key = os_malloc(16);
1495 if (bss->pac_opaque_encr_key == NULL) {
1496 printf("Line %d: No memory for "
1497 "pac_opque_encr_key\n", line);
1499 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1501 printf("Line %d: Invalid pac_opque_encr_key\n",
1505 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1506 os_free(bss->eap_fast_a_id);
1507 bss->eap_fast_a_id = os_strdup(pos);
1508 #endif /* EAP_FAST */
1510 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1511 os_free(bss->eap_sim_db);
1512 bss->eap_sim_db = os_strdup(pos);
1513 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1514 bss->eap_sim_aka_result_ind = atoi(pos);
1515 #endif /* EAP_SIM */
1517 } else if (os_strcmp(buf, "tnc") == 0) {
1518 bss->tnc = atoi(pos);
1519 #endif /* EAP_TNC */
1520 #endif /* EAP_SERVER */
1521 } else if (os_strcmp(buf, "eap_message") == 0) {
1523 bss->eap_req_id_text = os_strdup(pos);
1524 if (bss->eap_req_id_text == NULL) {
1525 printf("Line %d: Failed to allocate memory "
1526 "for eap_req_id_text\n", line);
1530 bss->eap_req_id_text_len =
1531 os_strlen(bss->eap_req_id_text);
1532 term = os_strstr(bss->eap_req_id_text, "\\0");
1535 os_memmove(term, term + 1,
1536 bss->eap_req_id_text_len -
1537 (term - bss->eap_req_id_text) - 1);
1538 bss->eap_req_id_text_len--;
1540 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1541 bss->default_wep_key_len = atoi(pos);
1542 if (bss->default_wep_key_len > 13) {
1543 printf("Line %d: invalid WEP key len %lu "
1544 "(= %lu bits)\n", line,
1546 bss->default_wep_key_len,
1548 bss->default_wep_key_len * 8);
1551 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1552 bss->individual_wep_key_len = atoi(pos);
1553 if (bss->individual_wep_key_len < 0 ||
1554 bss->individual_wep_key_len > 13) {
1555 printf("Line %d: invalid WEP key len %d "
1556 "(= %d bits)\n", line,
1557 bss->individual_wep_key_len,
1558 bss->individual_wep_key_len * 8);
1561 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1562 bss->wep_rekeying_period = atoi(pos);
1563 if (bss->wep_rekeying_period < 0) {
1564 printf("Line %d: invalid period %d\n",
1565 line, bss->wep_rekeying_period);
1568 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1569 bss->eap_reauth_period = atoi(pos);
1570 if (bss->eap_reauth_period < 0) {
1571 printf("Line %d: invalid period %d\n",
1572 line, bss->eap_reauth_period);
1575 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1576 bss->eapol_key_index_workaround = atoi(pos);
1578 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1579 bss->ieee802_11f = 1;
1580 os_strlcpy(bss->iapp_iface, pos,
1581 sizeof(bss->iapp_iface));
1582 #endif /* CONFIG_IAPP */
1583 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1584 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1585 printf("Line %d: invalid IP address '%s'\n",
1589 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1590 bss->nas_identifier = os_strdup(pos);
1591 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1592 if (hostapd_config_read_radius_addr(
1593 &bss->radius->auth_servers,
1594 &bss->radius->num_auth_servers, pos, 1812,
1595 &bss->radius->auth_server)) {
1596 printf("Line %d: invalid IP address '%s'\n",
1600 } else if (bss->radius->auth_server &&
1601 os_strcmp(buf, "auth_server_port") == 0) {
1602 bss->radius->auth_server->port = atoi(pos);
1603 } else if (bss->radius->auth_server &&
1604 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1605 int len = os_strlen(pos);
1607 /* RFC 2865, Ch. 3 */
1608 printf("Line %d: empty shared secret is not "
1609 "allowed.\n", line);
1612 bss->radius->auth_server->shared_secret =
1613 (u8 *) os_strdup(pos);
1614 bss->radius->auth_server->shared_secret_len = len;
1615 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1616 if (hostapd_config_read_radius_addr(
1617 &bss->radius->acct_servers,
1618 &bss->radius->num_acct_servers, pos, 1813,
1619 &bss->radius->acct_server)) {
1620 printf("Line %d: invalid IP address '%s'\n",
1624 } else if (bss->radius->acct_server &&
1625 os_strcmp(buf, "acct_server_port") == 0) {
1626 bss->radius->acct_server->port = atoi(pos);
1627 } else if (bss->radius->acct_server &&
1628 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1629 int len = os_strlen(pos);
1631 /* RFC 2865, Ch. 3 */
1632 printf("Line %d: empty shared secret is not "
1633 "allowed.\n", line);
1636 bss->radius->acct_server->shared_secret =
1637 (u8 *) os_strdup(pos);
1638 bss->radius->acct_server->shared_secret_len = len;
1639 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1641 bss->radius->retry_primary_interval = atoi(pos);
1642 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1644 bss->radius->acct_interim_interval = atoi(pos);
1645 } else if (os_strcmp(buf, "auth_algs") == 0) {
1646 bss->auth_algs = atoi(pos);
1647 if (bss->auth_algs == 0) {
1648 printf("Line %d: no authentication algorithms "
1653 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1654 bss->max_num_sta = atoi(pos);
1655 if (bss->max_num_sta < 0 ||
1656 bss->max_num_sta > MAX_STA_COUNT) {
1657 printf("Line %d: Invalid max_num_sta=%d; "
1658 "allowed range 0..%d\n", line,
1659 bss->max_num_sta, MAX_STA_COUNT);
1662 } else if (os_strcmp(buf, "wpa") == 0) {
1663 bss->wpa = atoi(pos);
1664 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1665 bss->wpa_group_rekey = atoi(pos);
1666 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1667 bss->wpa_strict_rekey = atoi(pos);
1668 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1669 bss->wpa_gmk_rekey = atoi(pos);
1670 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1671 int len = os_strlen(pos);
1672 if (len < 8 || len > 63) {
1673 printf("Line %d: invalid WPA passphrase length"
1674 " %d (expected 8..63)\n", line, len);
1677 os_free(bss->ssid.wpa_passphrase);
1678 bss->ssid.wpa_passphrase = os_strdup(pos);
1680 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1681 os_free(bss->ssid.wpa_psk);
1683 os_zalloc(sizeof(struct hostapd_wpa_psk));
1684 if (bss->ssid.wpa_psk == NULL)
1686 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1688 pos[PMK_LEN * 2] != '\0') {
1689 printf("Line %d: Invalid PSK '%s'.\n", line,
1693 bss->ssid.wpa_psk->group = 1;
1695 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1696 os_free(bss->ssid.wpa_psk_file);
1697 bss->ssid.wpa_psk_file = os_strdup(pos);
1698 if (!bss->ssid.wpa_psk_file) {
1699 printf("Line %d: allocation failed\n", line);
1702 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1704 hostapd_config_parse_key_mgmt(line, pos);
1705 if (bss->wpa_key_mgmt == -1)
1707 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1709 hostapd_config_parse_cipher(line, pos);
1710 if (bss->wpa_pairwise == -1 ||
1711 bss->wpa_pairwise == 0)
1713 else if (bss->wpa_pairwise &
1714 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1715 WPA_CIPHER_WEP104)) {
1716 printf("Line %d: unsupported pairwise "
1717 "cipher suite '%s'\n",
1718 bss->wpa_pairwise, pos);
1721 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1723 hostapd_config_parse_cipher(line, pos);
1724 if (bss->rsn_pairwise == -1 ||
1725 bss->rsn_pairwise == 0)
1727 else if (bss->rsn_pairwise &
1728 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1729 WPA_CIPHER_WEP104)) {
1730 printf("Line %d: unsupported pairwise "
1731 "cipher suite '%s'\n",
1732 bss->rsn_pairwise, pos);
1735 #ifdef CONFIG_RSN_PREAUTH
1736 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1737 bss->rsn_preauth = atoi(pos);
1738 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1739 bss->rsn_preauth_interfaces = os_strdup(pos);
1740 #endif /* CONFIG_RSN_PREAUTH */
1741 #ifdef CONFIG_PEERKEY
1742 } else if (os_strcmp(buf, "peerkey") == 0) {
1743 bss->peerkey = atoi(pos);
1744 #endif /* CONFIG_PEERKEY */
1745 #ifdef CONFIG_IEEE80211R
1746 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1747 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1748 hexstr2bin(pos, bss->mobility_domain,
1749 MOBILITY_DOMAIN_ID_LEN) != 0) {
1750 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1751 "mobility_domain '%s'", line, pos);
1755 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1756 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1757 hexstr2bin(pos, bss->r1_key_holder,
1758 FT_R1KH_ID_LEN) != 0) {
1759 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1760 "r1_key_holder '%s'", line, pos);
1764 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1765 bss->r0_key_lifetime = atoi(pos);
1766 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1767 bss->reassociation_deadline = atoi(pos);
1768 } else if (os_strcmp(buf, "r0kh") == 0) {
1769 if (add_r0kh(bss, pos) < 0) {
1770 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1771 "r0kh '%s'", line, pos);
1775 } else if (os_strcmp(buf, "r1kh") == 0) {
1776 if (add_r1kh(bss, pos) < 0) {
1777 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1778 "r1kh '%s'", line, pos);
1782 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1783 bss->pmk_r1_push = atoi(pos);
1784 #endif /* CONFIG_IEEE80211R */
1785 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1786 os_free(bss->ctrl_interface);
1787 bss->ctrl_interface = os_strdup(pos);
1788 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1789 #ifndef CONFIG_NATIVE_WINDOWS
1792 const char *group = pos;
1794 grp = getgrnam(group);
1796 bss->ctrl_interface_gid = grp->gr_gid;
1797 bss->ctrl_interface_gid_set = 1;
1798 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1799 " (from group name '%s')",
1800 bss->ctrl_interface_gid, group);
1804 /* Group name not found - try to parse this as gid */
1805 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1806 if (*group == '\0' || *endp != '\0') {
1807 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1808 "'%s'", line, group);
1812 bss->ctrl_interface_gid_set = 1;
1813 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1814 bss->ctrl_interface_gid);
1815 #endif /* CONFIG_NATIVE_WINDOWS */
1816 #ifdef RADIUS_SERVER
1817 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1818 os_free(bss->radius_server_clients);
1819 bss->radius_server_clients = os_strdup(pos);
1820 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1821 bss->radius_server_auth_port = atoi(pos);
1822 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1823 bss->radius_server_ipv6 = atoi(pos);
1824 #endif /* RADIUS_SERVER */
1825 } else if (os_strcmp(buf, "test_socket") == 0) {
1826 os_free(bss->test_socket);
1827 bss->test_socket = os_strdup(pos);
1828 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1829 bss->use_pae_group_addr = atoi(pos);
1830 } else if (os_strcmp(buf, "hw_mode") == 0) {
1831 if (os_strcmp(pos, "a") == 0)
1832 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1833 else if (os_strcmp(pos, "b") == 0)
1834 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1835 else if (os_strcmp(pos, "g") == 0)
1836 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1838 printf("Line %d: unknown hw_mode '%s'\n",
1842 } else if (os_strcmp(buf, "channel") == 0) {
1843 conf->channel = atoi(pos);
1844 } else if (os_strcmp(buf, "beacon_int") == 0) {
1845 int val = atoi(pos);
1846 /* MIB defines range as 1..65535, but very small values
1847 * cause problems with the current implementation.
1848 * Since it is unlikely that this small numbers are
1849 * useful in real life scenarios, do not allow beacon
1850 * period to be set below 15 TU. */
1851 if (val < 15 || val > 65535) {
1852 printf("Line %d: invalid beacon_int %d "
1853 "(expected 15..65535)\n",
1857 conf->beacon_int = val;
1858 } else if (os_strcmp(buf, "dtim_period") == 0) {
1859 bss->dtim_period = atoi(pos);
1860 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1861 printf("Line %d: invalid dtim_period %d\n",
1862 line, bss->dtim_period);
1865 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1866 conf->rts_threshold = atoi(pos);
1867 if (conf->rts_threshold < 0 ||
1868 conf->rts_threshold > 2347) {
1869 printf("Line %d: invalid rts_threshold %d\n",
1870 line, conf->rts_threshold);
1873 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1874 conf->fragm_threshold = atoi(pos);
1875 if (conf->fragm_threshold < 256 ||
1876 conf->fragm_threshold > 2346) {
1877 printf("Line %d: invalid fragm_threshold %d\n",
1878 line, conf->fragm_threshold);
1881 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1882 int val = atoi(pos);
1883 if (val != 0 && val != 1) {
1884 printf("Line %d: invalid send_probe_response "
1885 "%d (expected 0 or 1)\n", line, val);
1887 conf->send_probe_response = val;
1888 } else if (os_strcmp(buf, "supported_rates") == 0) {
1889 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
1890 printf("Line %d: invalid rate list\n", line);
1893 } else if (os_strcmp(buf, "basic_rates") == 0) {
1894 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
1895 printf("Line %d: invalid rate list\n", line);
1898 } else if (os_strcmp(buf, "preamble") == 0) {
1900 conf->preamble = SHORT_PREAMBLE;
1902 conf->preamble = LONG_PREAMBLE;
1903 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
1904 bss->ignore_broadcast_ssid = atoi(pos);
1905 } else if (os_strcmp(buf, "bridge_packets") == 0) {
1906 conf->bridge_packets = atoi(pos);
1907 } else if (os_strcmp(buf, "wep_default_key") == 0) {
1908 bss->ssid.wep.idx = atoi(pos);
1909 if (bss->ssid.wep.idx > 3) {
1910 printf("Invalid wep_default_key index %d\n",
1914 } else if (os_strcmp(buf, "wep_key0") == 0 ||
1915 os_strcmp(buf, "wep_key1") == 0 ||
1916 os_strcmp(buf, "wep_key2") == 0 ||
1917 os_strcmp(buf, "wep_key3") == 0) {
1918 if (hostapd_config_read_wep(&bss->ssid.wep,
1919 buf[7] - '0', pos)) {
1920 printf("Line %d: invalid WEP key '%s'\n",
1924 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
1925 bss->ssid.dynamic_vlan = atoi(pos);
1926 } else if (os_strcmp(buf, "vlan_file") == 0) {
1927 if (hostapd_config_read_vlan_file(bss, pos)) {
1928 printf("Line %d: failed to read VLAN file "
1929 "'%s'\n", line, pos);
1932 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1933 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
1934 bss->ssid.vlan_tagged_interface = os_strdup(pos);
1935 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1936 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
1937 conf->passive_scan_interval = atoi(pos);
1938 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
1939 conf->passive_scan_listen = atoi(pos);
1940 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
1941 conf->passive_scan_mode = atoi(pos);
1942 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
1943 conf->ap_table_max_size = atoi(pos);
1944 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
1945 conf->ap_table_expiration_time = atoi(pos);
1946 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
1947 if (hostapd_config_tx_queue(conf, buf, pos)) {
1948 printf("Line %d: invalid TX queue item\n",
1952 } else if (os_strcmp(buf, "wme_enabled") == 0) {
1953 bss->wme_enabled = atoi(pos);
1954 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
1955 if (hostapd_config_wme_ac(conf, buf, pos)) {
1956 printf("Line %d: invalid wme ac item\n",
1960 } else if (os_strcmp(buf, "bss") == 0) {
1961 if (hostapd_config_bss(conf, pos)) {
1962 printf("Line %d: invalid bss item\n", line);
1965 } else if (os_strcmp(buf, "bssid") == 0) {
1966 if (bss == conf->bss &&
1967 (!conf->driver || !conf->driver->init_bssid)) {
1968 printf("Line %d: bssid item not allowed "
1969 "for the default interface and this "
1972 } else if (hwaddr_aton(pos, bss->bssid)) {
1973 printf("Line %d: invalid bssid item\n", line);
1976 #ifdef CONFIG_IEEE80211W
1977 } else if (os_strcmp(buf, "ieee80211w") == 0) {
1978 bss->ieee80211w = atoi(pos);
1979 } else if (os_strcmp(buf, "assoc_ping_timeout") == 0) {
1980 bss->assoc_ping_timeout = atoi(pos);
1981 if (bss->assoc_ping_timeout == 0) {
1982 printf("Line %d: invalid assoc_ping_timeout\n",
1986 } else if (os_strcmp(buf, "assoc_ping_attempts") == 0) {
1987 bss->assoc_ping_timeout = atoi(pos);
1988 if (bss->assoc_ping_timeout == 0) {
1989 printf("Line %d: invalid assoc_ping_attempts "
1990 "(valid range: 1..255)\n",
1994 #endif /* CONFIG_IEEE80211W */
1995 #ifdef CONFIG_IEEE80211N
1996 } else if (os_strcmp(buf, "ieee80211n") == 0) {
1997 conf->ieee80211n = atoi(pos);
1998 #endif /* CONFIG_IEEE80211N */
1999 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2000 bss->max_listen_interval = atoi(pos);
2001 } else if (os_strcmp(buf, "okc") == 0) {
2002 bss->okc = atoi(pos);
2004 printf("Line %d: unknown configuration item '%s'\n",
2012 if (bss->individual_wep_key_len == 0) {
2013 /* individual keys are not use; can use key idx0 for broadcast
2015 bss->broadcast_key_idx_min = 0;
2018 /* Select group cipher based on the enabled pairwise cipher suites */
2021 pairwise |= bss->wpa_pairwise;
2023 if (bss->rsn_pairwise == 0)
2024 bss->rsn_pairwise = bss->wpa_pairwise;
2025 pairwise |= bss->rsn_pairwise;
2027 if (pairwise & WPA_CIPHER_TKIP)
2028 bss->wpa_group = WPA_CIPHER_TKIP;
2030 bss->wpa_group = WPA_CIPHER_CCMP;
2032 for (i = 0; i < conf->num_bss; i++) {
2033 bss = &conf->bss[i];
2035 bss->radius->auth_server = bss->radius->auth_servers;
2036 bss->radius->acct_server = bss->radius->acct_servers;
2038 if (bss->wpa && bss->ieee802_1x) {
2039 bss->ssid.security_policy = SECURITY_WPA;
2040 } else if (bss->wpa) {
2041 bss->ssid.security_policy = SECURITY_WPA_PSK;
2042 } else if (bss->ieee802_1x) {
2043 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2044 bss->ssid.wep.default_len = bss->default_wep_key_len;
2045 } else if (bss->ssid.wep.keys_set)
2046 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2048 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2051 if (hostapd_config_check(conf))
2055 printf("%d errors found in configuration file '%s'\n",
2057 hostapd_config_free(conf);
2065 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2069 if (a->idx != b->idx || a->default_len != b->default_len)
2071 for (i = 0; i < NUM_WEP_KEYS; i++)
2072 if (a->len[i] != b->len[i] ||
2073 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2079 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2084 for (i = 0; i < num_servers; i++) {
2085 os_free(servers[i].shared_secret);
2091 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2093 os_free(user->identity);
2094 os_free(user->password);
2099 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2102 for (i = 0; i < NUM_WEP_KEYS; i++) {
2103 os_free(keys->key[i]);
2104 keys->key[i] = NULL;
2109 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2111 struct hostapd_wpa_psk *psk, *prev;
2112 struct hostapd_eap_user *user, *prev_user;
2117 psk = conf->ssid.wpa_psk;
2124 os_free(conf->ssid.wpa_passphrase);
2125 os_free(conf->ssid.wpa_psk_file);
2126 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2127 os_free(conf->ssid.vlan_tagged_interface);
2128 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2130 user = conf->eap_user;
2134 hostapd_config_free_eap_user(prev_user);
2137 os_free(conf->dump_log_name);
2138 os_free(conf->eap_req_id_text);
2139 os_free(conf->accept_mac);
2140 os_free(conf->deny_mac);
2141 os_free(conf->nas_identifier);
2142 hostapd_config_free_radius(conf->radius->auth_servers,
2143 conf->radius->num_auth_servers);
2144 hostapd_config_free_radius(conf->radius->acct_servers,
2145 conf->radius->num_acct_servers);
2146 os_free(conf->rsn_preauth_interfaces);
2147 os_free(conf->ctrl_interface);
2148 os_free(conf->ca_cert);
2149 os_free(conf->server_cert);
2150 os_free(conf->private_key);
2151 os_free(conf->private_key_passwd);
2152 os_free(conf->dh_file);
2153 os_free(conf->pac_opaque_encr_key);
2154 os_free(conf->eap_fast_a_id);
2155 os_free(conf->eap_sim_db);
2156 os_free(conf->radius_server_clients);
2157 os_free(conf->test_socket);
2158 os_free(conf->radius);
2159 hostapd_config_free_vlan(conf);
2160 if (conf->ssid.dyn_vlan_keys) {
2161 struct hostapd_ssid *ssid = &conf->ssid;
2163 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2164 if (ssid->dyn_vlan_keys[i] == NULL)
2166 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2167 os_free(ssid->dyn_vlan_keys[i]);
2169 os_free(ssid->dyn_vlan_keys);
2170 ssid->dyn_vlan_keys = NULL;
2173 #ifdef CONFIG_IEEE80211R
2175 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2176 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2178 r0kh = conf->r0kh_list;
2179 conf->r0kh_list = NULL;
2186 r1kh = conf->r1kh_list;
2187 conf->r1kh_list = NULL;
2194 #endif /* CONFIG_IEEE80211R */
2198 void hostapd_config_free(struct hostapd_config *conf)
2205 for (i = 0; i < conf->num_bss; i++)
2206 hostapd_config_free_bss(&conf->bss[i]);
2213 /* Perform a binary search for given MAC address from a pre-sorted list.
2214 * Returns 1 if address is in the list or 0 if not. */
2215 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
2216 const u8 *addr, int *vlan_id)
2218 int start, end, middle, res;
2221 end = num_entries - 1;
2223 while (start <= end) {
2224 middle = (start + end) / 2;
2225 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
2228 *vlan_id = list[middle].vlan_id;
2241 int hostapd_rate_found(int *list, int rate)
2248 for (i = 0; list[i] >= 0; i++)
2249 if (list[i] == rate)
2256 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2258 struct hostapd_vlan *v = vlan;
2260 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2268 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2269 const u8 *addr, const u8 *prev_psk)
2271 struct hostapd_wpa_psk *psk;
2272 int next_ok = prev_psk == NULL;
2274 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2276 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2279 if (psk->psk == prev_psk)
2287 const struct hostapd_eap_user *
2288 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2289 size_t identity_len, int phase2)
2291 struct hostapd_eap_user *user = conf->eap_user;
2294 if (!phase2 && user->identity == NULL) {
2295 /* Wildcard match */
2299 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2300 identity_len >= user->identity_len &&
2301 os_memcmp(user->identity, identity, user->identity_len) ==
2303 /* Wildcard prefix match */
2307 if (user->phase2 == !!phase2 &&
2308 user->identity_len == identity_len &&
2309 os_memcmp(user->identity, identity, identity_len) == 0)