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 #ifdef CONFIG_IEEE80211N
188 static int hostapd_config_defaults_bss_80211n(struct hostapd_bss_config *bss)
190 u16 capabilities_info = 0;
191 u16 operation_mode = 0;
196 /* add default values to HT capabilities parameters */
197 os_memset(&bss->ht_capabilities, 0, sizeof(struct ht_cap_ie));
198 bss->ht_capabilities.id = WLAN_EID_HT_CAP;
199 bss->ht_capabilities.length = HT_CAPABILITIES_LEN;
201 #if 0 /* FIX: remove? was commented out */
202 bss->ht_capabilities.mac_ht_param_info.max_rx_ampdu_factor =
203 MAX_RX_AMPDU_FACTOR_64KB;
205 SET_2BIT_U8(&bss->ht_capabilities.data.mac_ht_params_info,
206 MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
207 MAX_RX_AMPDU_FACTOR_64KB);
209 SET_2BIT_LE16(&capabilities_info,
210 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
211 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
213 capabilities_info |= HT_CAP_INFO_GREEN_FIELD;
215 bss->ht_capabilities.data.capabilities_info =
216 host_to_le16(capabilities_info);
218 bss->ht_capabilities.data.supported_mcs_set[0] = 0xff;
219 bss->ht_capabilities.data.supported_mcs_set[1] = 0xff;
221 /* add default values to HT operation parameters */
222 os_memset(&bss->ht_operation, 0, sizeof(struct ht_operation_ie));
223 bss->ht_operation.id = WLAN_EID_HT_OPERATION;
224 bss->ht_operation.length = HT_OPERATION_LEN;
225 SET_2BIT_LE16(&operation_mode,
226 HT_INFO_OPERATION_MODE_OP_MODE_OFFSET,
228 bss->ht_operation.data.operation_mode = host_to_le16(operation_mode);
232 #endif /* CONFIG_IEEE80211N */
235 static struct hostapd_config * hostapd_config_defaults(void)
237 struct hostapd_config *conf;
238 struct hostapd_bss_config *bss;
240 const int aCWmin = 15, aCWmax = 1024;
241 const struct hostapd_wme_ac_params ac_bk =
242 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
243 const struct hostapd_wme_ac_params ac_be =
244 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
245 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
246 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
247 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
248 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
250 conf = os_zalloc(sizeof(*conf));
251 bss = os_zalloc(sizeof(*bss));
252 if (conf == NULL || bss == NULL) {
253 printf("Failed to allocate memory for configuration data.\n");
259 /* set default driver based on configuration */
260 conf->driver = hostapd_drivers[0];
261 if (conf->driver == NULL) {
262 printf("No driver wrappers registered!\n");
268 bss->radius = os_zalloc(sizeof(*bss->radius));
269 if (bss->radius == NULL) {
275 hostapd_config_defaults_bss(bss);
280 conf->beacon_int = 100;
281 conf->rts_threshold = -1; /* use driver default: 2347 */
282 conf->fragm_threshold = -1; /* user driver default: 2346 */
283 conf->send_probe_response = 1;
284 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
286 os_memcpy(conf->country, "US ", 3);
288 for (i = 0; i < NUM_TX_QUEUES; i++)
289 conf->tx_queue[i].aifs = -1; /* use hw default */
291 conf->wme_ac_params[0] = ac_be;
292 conf->wme_ac_params[1] = ac_bk;
293 conf->wme_ac_params[2] = ac_vi;
294 conf->wme_ac_params[3] = ac_vo;
296 #ifdef CONFIG_IEEE80211N
297 hostapd_config_defaults_bss_80211n(bss);
298 #endif /* CONFIG_IEEE80211N */
304 int hostapd_mac_comp(const void *a, const void *b)
306 return os_memcmp(a, b, sizeof(macaddr));
310 int hostapd_mac_comp_empty(const void *a)
312 macaddr empty = { 0 };
313 return os_memcmp(a, empty, sizeof(macaddr));
317 static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
329 f = fopen(fname, "r");
331 printf("MAC list file '%s' not found.\n", fname);
335 while (fgets(buf, sizeof(buf), f)) {
341 while (*pos != '\0') {
351 if (hwaddr_aton(buf, addr)) {
352 printf("Invalid MAC address '%s' at line %d in '%s'\n",
358 newacl = os_realloc(*acl, (*num + 1) * ETH_ALEN);
359 if (newacl == NULL) {
360 printf("MAC list reallocation failed\n");
366 os_memcpy((*acl)[*num], addr, ETH_ALEN);
372 qsort(*acl, *num, sizeof(macaddr), hostapd_mac_comp);
378 static int hostapd_config_read_wpa_psk(const char *fname,
379 struct hostapd_ssid *ssid)
383 int line = 0, ret = 0, len, ok;
385 struct hostapd_wpa_psk *psk;
390 f = fopen(fname, "r");
392 printf("WPA PSK file '%s' not found.\n", fname);
396 while (fgets(buf, sizeof(buf), f)) {
402 while (*pos != '\0') {
412 if (hwaddr_aton(buf, addr)) {
413 printf("Invalid MAC address '%s' on line %d in '%s'\n",
419 psk = os_zalloc(sizeof(*psk));
421 printf("WPA PSK allocation failed\n");
425 if (is_zero_ether_addr(addr))
428 os_memcpy(psk->addr, addr, ETH_ALEN);
432 printf("No PSK on line %d in '%s'\n", line, fname);
440 len = os_strlen(pos);
441 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
443 else if (len >= 8 && len < 64) {
444 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
445 4096, psk->psk, PMK_LEN);
449 printf("Invalid PSK '%s' on line %d in '%s'\n",
456 psk->next = ssid->wpa_psk;
466 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
468 struct hostapd_ssid *ssid = &conf->ssid;
470 if (ssid->wpa_passphrase != NULL) {
471 if (ssid->wpa_psk != NULL) {
472 printf("Warning: both WPA PSK and passphrase set. "
473 "Using passphrase.\n");
474 os_free(ssid->wpa_psk);
476 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
477 if (ssid->wpa_psk == NULL) {
478 printf("Unable to alloc space for PSK\n");
481 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
482 (u8 *) ssid->ssid, ssid->ssid_len);
483 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
484 (u8 *) ssid->wpa_passphrase,
485 os_strlen(ssid->wpa_passphrase));
486 pbkdf2_sha1(ssid->wpa_passphrase,
487 ssid->ssid, ssid->ssid_len,
488 4096, ssid->wpa_psk->psk, PMK_LEN);
489 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
490 ssid->wpa_psk->psk, PMK_LEN);
491 ssid->wpa_psk->group = 1;
493 os_memset(ssid->wpa_passphrase, 0,
494 os_strlen(ssid->wpa_passphrase));
495 os_free(ssid->wpa_passphrase);
496 ssid->wpa_passphrase = NULL;
499 if (ssid->wpa_psk_file) {
500 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
510 static int hostapd_config_read_eap_user(const char *fname,
511 struct hostapd_bss_config *conf)
514 char buf[512], *pos, *start, *pos2;
515 int line = 0, ret = 0, num_methods;
516 struct hostapd_eap_user *user, *tail = NULL;
521 f = fopen(fname, "r");
523 printf("EAP user file '%s' not found.\n", fname);
527 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
528 while (fgets(buf, sizeof(buf), f)) {
534 while (*pos != '\0') {
546 if (buf[0] != '"' && buf[0] != '*') {
547 printf("Invalid EAP identity (no \" in start) on "
548 "line %d in '%s'\n", line, fname);
552 user = os_zalloc(sizeof(*user));
554 printf("EAP user allocation failed\n");
557 user->force_version = -1;
564 while (*pos != '"' && *pos != '\0')
567 printf("Invalid EAP identity (no \" in end) on"
568 " line %d in '%s'\n", line, fname);
572 user->identity = os_malloc(pos - start);
573 if (user->identity == NULL) {
574 printf("Failed to allocate memory for EAP "
578 os_memcpy(user->identity, start, pos - start);
579 user->identity_len = pos - start;
581 if (pos[0] == '"' && pos[1] == '*') {
582 user->wildcard_prefix = 1;
587 while (*pos == ' ' || *pos == '\t')
591 printf("No EAP method on line %d in '%s'\n",
597 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
607 char *pos3 = os_strchr(start, ',');
611 user->methods[num_methods].method =
614 &user->methods[num_methods].vendor);
615 if (user->methods[num_methods].vendor ==
617 user->methods[num_methods].method == EAP_TYPE_NONE)
619 if (os_strcmp(start, "TTLS-PAP") == 0) {
620 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
623 if (os_strcmp(start, "TTLS-CHAP") == 0) {
624 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
627 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
629 EAP_TTLS_AUTH_MSCHAP;
632 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
634 EAP_TTLS_AUTH_MSCHAPV2;
637 printf("Unsupported EAP type '%s' on line %d "
638 "in '%s'\n", start, line, fname);
643 if (num_methods >= EAP_USER_MAX_METHODS)
650 if (num_methods == 0 && user->ttls_auth == 0) {
651 printf("No EAP types configured on line %d in '%s'\n",
659 while (*pos == ' ' || *pos == '\t')
664 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
665 user->force_version = 0;
669 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
670 user->force_version = 1;
674 if (os_strncmp(pos, "[2]", 3) == 0) {
682 while (*pos != '"' && *pos != '\0')
685 printf("Invalid EAP password (no \" in end) "
686 "on line %d in '%s'\n", line, fname);
690 user->password = os_malloc(pos - start);
691 if (user->password == NULL) {
692 printf("Failed to allocate memory for EAP "
696 os_memcpy(user->password, start, pos - start);
697 user->password_len = pos - start;
700 } else if (os_strncmp(pos, "hash:", 5) == 0) {
703 while (*pos2 != '\0' && *pos2 != ' ' &&
704 *pos2 != '\t' && *pos2 != '#')
706 if (pos2 - pos != 32) {
707 printf("Invalid password hash on line %d in "
708 "'%s'\n", line, fname);
711 user->password = os_malloc(16);
712 if (user->password == NULL) {
713 printf("Failed to allocate memory for EAP "
717 if (hexstr2bin(pos, user->password, 16) < 0) {
718 printf("Invalid hash password on line %d in "
719 "'%s'\n", line, fname);
722 user->password_len = 16;
723 user->password_hash = 1;
727 while (*pos2 != '\0' && *pos2 != ' ' &&
728 *pos2 != '\t' && *pos2 != '#')
730 if ((pos2 - pos) & 1) {
731 printf("Invalid hex password on line %d in "
732 "'%s'\n", line, fname);
735 user->password = os_malloc((pos2 - pos) / 2);
736 if (user->password == NULL) {
737 printf("Failed to allocate memory for EAP "
741 if (hexstr2bin(pos, user->password,
742 (pos2 - pos) / 2) < 0) {
743 printf("Invalid hex password on line %d in "
744 "'%s'\n", line, fname);
747 user->password_len = (pos2 - pos) / 2;
751 while (*pos == ' ' || *pos == '\t')
753 if (os_strncmp(pos, "[2]", 3) == 0) {
759 tail = conf->eap_user = user;
768 os_free(user->password);
769 os_free(user->identity);
780 #endif /* EAP_SERVER */
784 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
785 int *num_server, const char *val, int def_port,
786 struct hostapd_radius_server **curr_serv)
788 struct hostapd_radius_server *nserv;
790 static int server_index = 1;
792 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
797 nserv = &nserv[*num_server];
799 (*curr_serv) = nserv;
801 os_memset(nserv, 0, sizeof(*nserv));
802 nserv->port = def_port;
803 ret = hostapd_parse_ip_addr(val, &nserv->addr);
804 nserv->index = server_index++;
810 static int hostapd_config_parse_key_mgmt(int line, const char *value)
813 char *start, *end, *buf;
815 buf = os_strdup(value);
820 while (start != '\0') {
821 while (*start == ' ' || *start == '\t')
826 while (*end != ' ' && *end != '\t' && *end != '\0')
830 if (os_strcmp(start, "WPA-PSK") == 0)
831 val |= WPA_KEY_MGMT_PSK;
832 else if (os_strcmp(start, "WPA-EAP") == 0)
833 val |= WPA_KEY_MGMT_IEEE8021X;
834 #ifdef CONFIG_IEEE80211R
835 else if (os_strcmp(start, "FT-PSK") == 0)
836 val |= WPA_KEY_MGMT_FT_PSK;
837 else if (os_strcmp(start, "FT-EAP") == 0)
838 val |= WPA_KEY_MGMT_FT_IEEE8021X;
839 #endif /* CONFIG_IEEE80211R */
841 printf("Line %d: invalid key_mgmt '%s'\n",
854 printf("Line %d: no key_mgmt values configured.\n", line);
862 static int hostapd_config_parse_cipher(int line, const char *value)
865 char *start, *end, *buf;
867 buf = os_strdup(value);
872 while (start != '\0') {
873 while (*start == ' ' || *start == '\t')
878 while (*end != ' ' && *end != '\t' && *end != '\0')
882 if (os_strcmp(start, "CCMP") == 0)
883 val |= WPA_CIPHER_CCMP;
884 else if (os_strcmp(start, "TKIP") == 0)
885 val |= WPA_CIPHER_TKIP;
886 else if (os_strcmp(start, "WEP104") == 0)
887 val |= WPA_CIPHER_WEP104;
888 else if (os_strcmp(start, "WEP40") == 0)
889 val |= WPA_CIPHER_WEP40;
890 else if (os_strcmp(start, "NONE") == 0)
891 val |= WPA_CIPHER_NONE;
893 printf("Line %d: invalid cipher '%s'.", line, start);
905 printf("Line %d: no cipher values configured.", line);
912 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
913 struct hostapd_config *conf)
915 if (bss->ieee802_1x && !bss->eap_server &&
916 !bss->radius->auth_servers) {
917 printf("Invalid IEEE 802.1X configuration (no EAP "
918 "authenticator configured).\n");
922 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
923 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
924 bss->ssid.wpa_psk_file == NULL) {
925 printf("WPA-PSK enabled, but PSK or passphrase is not "
930 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
933 for (i = 0; i < conf->num_bss; i++) {
934 if ((&conf->bss[i] != bss) &&
935 (hostapd_mac_comp(conf->bss[i].bssid,
937 printf("Duplicate BSSID " MACSTR
938 " on interface '%s' and '%s'.\n",
940 conf->bss[i].iface, bss->iface);
946 #ifdef CONFIG_IEEE80211R
947 if ((bss->wpa_key_mgmt &
948 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
949 (bss->nas_identifier == NULL ||
950 os_strlen(bss->nas_identifier) < 1 ||
951 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
952 printf("FT (IEEE 802.11r) requires nas_identifier to be "
953 "configured as a 1..48 octet string\n");
956 #endif /* CONFIG_IEEE80211R */
962 static int hostapd_config_check(struct hostapd_config *conf)
966 for (i = 0; i < conf->num_bss; i++) {
967 if (hostapd_config_check_bss(&conf->bss[i], conf))
975 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
978 size_t len = os_strlen(val);
980 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
984 if (len < 2 || val[len - 1] != '"')
987 wep->key[keyidx] = os_malloc(len);
988 if (wep->key[keyidx] == NULL)
990 os_memcpy(wep->key[keyidx], val + 1, len);
991 wep->len[keyidx] = len;
996 wep->key[keyidx] = os_malloc(len);
997 if (wep->key[keyidx] == NULL)
999 wep->len[keyidx] = len;
1000 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1010 static int hostapd_parse_rates(int **rate_list, char *val)
1016 os_free(*rate_list);
1021 while (*pos != '\0') {
1027 list = os_malloc(sizeof(int) * (count + 2));
1032 while (*pos != '\0') {
1033 end = os_strchr(pos, ' ');
1037 list[count++] = atoi(pos);
1049 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1051 struct hostapd_bss_config *bss;
1053 if (*ifname == '\0')
1056 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1057 sizeof(struct hostapd_bss_config));
1059 printf("Failed to allocate memory for multi-BSS entry\n");
1064 bss = &(conf->bss[conf->num_bss]);
1065 os_memset(bss, 0, sizeof(*bss));
1066 bss->radius = os_zalloc(sizeof(*bss->radius));
1067 if (bss->radius == NULL) {
1068 printf("Failed to allocate memory for multi-BSS RADIUS "
1074 conf->last_bss = bss;
1076 hostapd_config_defaults_bss(bss);
1077 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1078 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1084 static int valid_cw(int cw)
1086 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1087 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1092 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1093 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1094 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1095 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1096 IEEE80211_TX_QUEUE_DATA4 = 4,
1097 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1098 IEEE80211_TX_QUEUE_BEACON = 7
1101 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1106 struct hostapd_tx_queue_params *queue;
1108 /* skip 'tx_queue_' prefix */
1110 if (os_strncmp(pos, "data", 4) == 0 &&
1111 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1114 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1115 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1117 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1118 num = IEEE80211_TX_QUEUE_BEACON;
1121 printf("Unknown tx_queue name '%s'\n", pos);
1125 queue = &conf->tx_queue[num];
1127 if (os_strcmp(pos, "aifs") == 0) {
1128 queue->aifs = atoi(val);
1129 if (queue->aifs < 0 || queue->aifs > 255) {
1130 printf("Invalid AIFS value %d\n", queue->aifs);
1133 } else if (os_strcmp(pos, "cwmin") == 0) {
1134 queue->cwmin = atoi(val);
1135 if (!valid_cw(queue->cwmin)) {
1136 printf("Invalid cwMin value %d\n", queue->cwmin);
1139 } else if (os_strcmp(pos, "cwmax") == 0) {
1140 queue->cwmax = atoi(val);
1141 if (!valid_cw(queue->cwmax)) {
1142 printf("Invalid cwMax value %d\n", queue->cwmax);
1145 } else if (os_strcmp(pos, "burst") == 0) {
1146 queue->burst = hostapd_config_read_int10(val);
1148 printf("Unknown tx_queue field '%s'\n", pos);
1152 queue->configured = 1;
1158 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1163 struct hostapd_wme_ac_params *ac;
1165 /* skip 'wme_ac_' prefix */
1167 if (os_strncmp(pos, "be_", 3) == 0) {
1170 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1173 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1176 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1180 printf("Unknown wme name '%s'\n", pos);
1184 ac = &conf->wme_ac_params[num];
1186 if (os_strcmp(pos, "aifs") == 0) {
1188 if (v < 1 || v > 255) {
1189 printf("Invalid AIFS value %d\n", v);
1193 } else if (os_strcmp(pos, "cwmin") == 0) {
1195 if (v < 0 || v > 12) {
1196 printf("Invalid cwMin value %d\n", v);
1200 } else if (os_strcmp(pos, "cwmax") == 0) {
1202 if (v < 0 || v > 12) {
1203 printf("Invalid cwMax value %d\n", v);
1207 } else if (os_strcmp(pos, "txop_limit") == 0) {
1209 if (v < 0 || v > 0xffff) {
1210 printf("Invalid txop value %d\n", v);
1214 } else if (os_strcmp(pos, "acm") == 0) {
1216 if (v < 0 || v > 1) {
1217 printf("Invalid acm value %d\n", v);
1220 ac->admission_control_mandatory = v;
1222 printf("Unknown wme_ac_ field '%s'\n", pos);
1230 #ifdef CONFIG_IEEE80211R
1231 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1233 struct ft_remote_r0kh *r0kh;
1236 r0kh = os_zalloc(sizeof(*r0kh));
1240 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1242 next = os_strchr(pos, ' ');
1245 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1246 printf("Invalid R0KH MAC address: '%s'\n", pos);
1252 next = os_strchr(pos, ' ');
1255 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1256 printf("Invalid R0KH-ID: '%s'\n", pos);
1260 r0kh->id_len = next - pos - 1;
1261 os_memcpy(r0kh->id, pos, r0kh->id_len);
1264 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1265 printf("Invalid R0KH key: '%s'\n", pos);
1270 r0kh->next = bss->r0kh_list;
1271 bss->r0kh_list = r0kh;
1277 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1279 struct ft_remote_r1kh *r1kh;
1282 r1kh = os_zalloc(sizeof(*r1kh));
1286 /* 02:01:02:03:04:05 02:01:02:03:04:05
1287 * 000102030405060708090a0b0c0d0e0f */
1289 next = os_strchr(pos, ' ');
1292 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1293 printf("Invalid R1KH MAC address: '%s'\n", pos);
1299 next = os_strchr(pos, ' ');
1302 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1303 printf("Invalid R1KH-ID: '%s'\n", pos);
1309 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1310 printf("Invalid R1KH key: '%s'\n", pos);
1315 r1kh->next = bss->r1kh_list;
1316 bss->r1kh_list = r1kh;
1320 #endif /* CONFIG_IEEE80211R */
1323 struct hostapd_config * hostapd_config_read(const char *fname)
1325 struct hostapd_config *conf;
1326 struct hostapd_bss_config *bss;
1328 char buf[256], *pos;
1334 f = fopen(fname, "r");
1336 printf("Could not open configuration file '%s' for reading.\n",
1341 conf = hostapd_config_defaults();
1346 bss = conf->last_bss = conf->bss;
1348 while (fgets(buf, sizeof(buf), f)) {
1349 bss = conf->last_bss;
1355 while (*pos != '\0') {
1365 pos = os_strchr(buf, '=');
1367 printf("Line %d: invalid line '%s'\n", line, buf);
1374 if (os_strcmp(buf, "interface") == 0) {
1375 os_strlcpy(conf->bss[0].iface, pos,
1376 sizeof(conf->bss[0].iface));
1377 } else if (os_strcmp(buf, "bridge") == 0) {
1378 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1379 } else if (os_strcmp(buf, "driver") == 0) {
1381 /* clear to get error below if setting is invalid */
1382 conf->driver = NULL;
1383 for (i = 0; hostapd_drivers[i]; i++) {
1384 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1386 conf->driver = hostapd_drivers[i];
1390 if (conf->driver == NULL) {
1391 printf("Line %d: invalid/unknown driver "
1392 "'%s'\n", line, pos);
1395 } else if (os_strcmp(buf, "debug") == 0) {
1396 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1397 "configuration variable is not used "
1399 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1400 bss->logger_syslog_level = atoi(pos);
1401 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1402 bss->logger_stdout_level = atoi(pos);
1403 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1404 bss->logger_syslog = atoi(pos);
1405 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1406 bss->logger_stdout = atoi(pos);
1407 } else if (os_strcmp(buf, "dump_file") == 0) {
1408 bss->dump_log_name = os_strdup(pos);
1409 } else if (os_strcmp(buf, "ssid") == 0) {
1410 bss->ssid.ssid_len = os_strlen(pos);
1411 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1412 bss->ssid.ssid_len < 1) {
1413 printf("Line %d: invalid SSID '%s'\n", line,
1417 os_memcpy(bss->ssid.ssid, pos,
1418 bss->ssid.ssid_len);
1419 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1420 bss->ssid.ssid_set = 1;
1422 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1423 bss->macaddr_acl = atoi(pos);
1424 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1425 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1426 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1427 printf("Line %d: unknown macaddr_acl %d\n",
1428 line, bss->macaddr_acl);
1430 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1431 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1432 &bss->num_accept_mac))
1434 printf("Line %d: Failed to read "
1435 "accept_mac_file '%s'\n",
1439 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1440 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1441 &bss->num_deny_mac))
1443 printf("Line %d: Failed to read "
1444 "deny_mac_file '%s'\n",
1448 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1449 bss->ap_max_inactivity = atoi(pos);
1450 } else if (os_strcmp(buf, "country_code") == 0) {
1451 os_memcpy(conf->country, pos, 2);
1452 /* FIX: make this configurable */
1453 conf->country[2] = ' ';
1454 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1455 conf->ieee80211d = atoi(pos);
1456 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1457 conf->ieee80211h = atoi(pos);
1458 } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
1459 if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
1460 printf("Line %d: invalid MAC address '%s'\n",
1465 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1466 bss->ieee802_1x = atoi(pos);
1467 } else if (os_strcmp(buf, "eapol_version") == 0) {
1468 bss->eapol_version = atoi(pos);
1469 if (bss->eapol_version < 1 ||
1470 bss->eapol_version > 2) {
1471 printf("Line %d: invalid EAPOL "
1472 "version (%d): '%s'.\n",
1473 line, bss->eapol_version, pos);
1476 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1477 bss->eapol_version);
1479 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1480 bss->eap_server = atoi(pos);
1481 printf("Line %d: obsolete eap_authenticator used; "
1482 "this has been renamed to eap_server\n", line);
1483 } else if (os_strcmp(buf, "eap_server") == 0) {
1484 bss->eap_server = atoi(pos);
1485 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1486 if (hostapd_config_read_eap_user(pos, bss))
1488 } else if (os_strcmp(buf, "ca_cert") == 0) {
1489 os_free(bss->ca_cert);
1490 bss->ca_cert = os_strdup(pos);
1491 } else if (os_strcmp(buf, "server_cert") == 0) {
1492 os_free(bss->server_cert);
1493 bss->server_cert = os_strdup(pos);
1494 } else if (os_strcmp(buf, "private_key") == 0) {
1495 os_free(bss->private_key);
1496 bss->private_key = os_strdup(pos);
1497 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1498 os_free(bss->private_key_passwd);
1499 bss->private_key_passwd = os_strdup(pos);
1500 } else if (os_strcmp(buf, "check_crl") == 0) {
1501 bss->check_crl = atoi(pos);
1502 } else if (os_strcmp(buf, "dh_file") == 0) {
1503 os_free(bss->dh_file);
1504 bss->dh_file = os_strdup(pos);
1506 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1507 os_free(bss->pac_opaque_encr_key);
1508 bss->pac_opaque_encr_key = os_malloc(16);
1509 if (bss->pac_opaque_encr_key == NULL) {
1510 printf("Line %d: No memory for "
1511 "pac_opque_encr_key\n", line);
1513 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1515 printf("Line %d: Invalid pac_opque_encr_key\n",
1519 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1520 os_free(bss->eap_fast_a_id);
1521 bss->eap_fast_a_id = os_strdup(pos);
1522 #endif /* EAP_FAST */
1524 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1525 os_free(bss->eap_sim_db);
1526 bss->eap_sim_db = os_strdup(pos);
1527 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1528 bss->eap_sim_aka_result_ind = atoi(pos);
1529 #endif /* EAP_SIM */
1531 } else if (os_strcmp(buf, "tnc") == 0) {
1532 bss->tnc = atoi(pos);
1533 #endif /* EAP_TNC */
1534 #endif /* EAP_SERVER */
1535 } else if (os_strcmp(buf, "eap_message") == 0) {
1537 bss->eap_req_id_text = os_strdup(pos);
1538 if (bss->eap_req_id_text == NULL) {
1539 printf("Line %d: Failed to allocate memory "
1540 "for eap_req_id_text\n", line);
1544 bss->eap_req_id_text_len =
1545 os_strlen(bss->eap_req_id_text);
1546 term = os_strstr(bss->eap_req_id_text, "\\0");
1549 os_memmove(term, term + 1,
1550 bss->eap_req_id_text_len -
1551 (term - bss->eap_req_id_text) - 1);
1552 bss->eap_req_id_text_len--;
1554 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1555 bss->default_wep_key_len = atoi(pos);
1556 if (bss->default_wep_key_len > 13) {
1557 printf("Line %d: invalid WEP key len %lu "
1558 "(= %lu bits)\n", line,
1560 bss->default_wep_key_len,
1562 bss->default_wep_key_len * 8);
1565 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1566 bss->individual_wep_key_len = atoi(pos);
1567 if (bss->individual_wep_key_len < 0 ||
1568 bss->individual_wep_key_len > 13) {
1569 printf("Line %d: invalid WEP key len %d "
1570 "(= %d bits)\n", line,
1571 bss->individual_wep_key_len,
1572 bss->individual_wep_key_len * 8);
1575 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1576 bss->wep_rekeying_period = atoi(pos);
1577 if (bss->wep_rekeying_period < 0) {
1578 printf("Line %d: invalid period %d\n",
1579 line, bss->wep_rekeying_period);
1582 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1583 bss->eap_reauth_period = atoi(pos);
1584 if (bss->eap_reauth_period < 0) {
1585 printf("Line %d: invalid period %d\n",
1586 line, bss->eap_reauth_period);
1589 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1590 bss->eapol_key_index_workaround = atoi(pos);
1592 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1593 bss->ieee802_11f = 1;
1594 os_strlcpy(bss->iapp_iface, pos,
1595 sizeof(bss->iapp_iface));
1596 #endif /* CONFIG_IAPP */
1597 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1598 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1599 printf("Line %d: invalid IP address '%s'\n",
1603 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1604 bss->nas_identifier = os_strdup(pos);
1605 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1606 if (hostapd_config_read_radius_addr(
1607 &bss->radius->auth_servers,
1608 &bss->radius->num_auth_servers, pos, 1812,
1609 &bss->radius->auth_server)) {
1610 printf("Line %d: invalid IP address '%s'\n",
1614 } else if (bss->radius->auth_server &&
1615 os_strcmp(buf, "auth_server_port") == 0) {
1616 bss->radius->auth_server->port = atoi(pos);
1617 } else if (bss->radius->auth_server &&
1618 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1619 int len = os_strlen(pos);
1621 /* RFC 2865, Ch. 3 */
1622 printf("Line %d: empty shared secret is not "
1623 "allowed.\n", line);
1626 bss->radius->auth_server->shared_secret =
1627 (u8 *) os_strdup(pos);
1628 bss->radius->auth_server->shared_secret_len = len;
1629 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1630 if (hostapd_config_read_radius_addr(
1631 &bss->radius->acct_servers,
1632 &bss->radius->num_acct_servers, pos, 1813,
1633 &bss->radius->acct_server)) {
1634 printf("Line %d: invalid IP address '%s'\n",
1638 } else if (bss->radius->acct_server &&
1639 os_strcmp(buf, "acct_server_port") == 0) {
1640 bss->radius->acct_server->port = atoi(pos);
1641 } else if (bss->radius->acct_server &&
1642 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1643 int len = os_strlen(pos);
1645 /* RFC 2865, Ch. 3 */
1646 printf("Line %d: empty shared secret is not "
1647 "allowed.\n", line);
1650 bss->radius->acct_server->shared_secret =
1651 (u8 *) os_strdup(pos);
1652 bss->radius->acct_server->shared_secret_len = len;
1653 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1655 bss->radius->retry_primary_interval = atoi(pos);
1656 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1658 bss->radius->acct_interim_interval = atoi(pos);
1659 } else if (os_strcmp(buf, "auth_algs") == 0) {
1660 bss->auth_algs = atoi(pos);
1661 if (bss->auth_algs == 0) {
1662 printf("Line %d: no authentication algorithms "
1667 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1668 bss->max_num_sta = atoi(pos);
1669 if (bss->max_num_sta < 0 ||
1670 bss->max_num_sta > MAX_STA_COUNT) {
1671 printf("Line %d: Invalid max_num_sta=%d; "
1672 "allowed range 0..%d\n", line,
1673 bss->max_num_sta, MAX_STA_COUNT);
1676 } else if (os_strcmp(buf, "wpa") == 0) {
1677 bss->wpa = atoi(pos);
1678 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1679 bss->wpa_group_rekey = atoi(pos);
1680 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1681 bss->wpa_strict_rekey = atoi(pos);
1682 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1683 bss->wpa_gmk_rekey = atoi(pos);
1684 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1685 int len = os_strlen(pos);
1686 if (len < 8 || len > 63) {
1687 printf("Line %d: invalid WPA passphrase length"
1688 " %d (expected 8..63)\n", line, len);
1691 os_free(bss->ssid.wpa_passphrase);
1692 bss->ssid.wpa_passphrase = os_strdup(pos);
1694 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1695 os_free(bss->ssid.wpa_psk);
1697 os_zalloc(sizeof(struct hostapd_wpa_psk));
1698 if (bss->ssid.wpa_psk == NULL)
1700 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1702 pos[PMK_LEN * 2] != '\0') {
1703 printf("Line %d: Invalid PSK '%s'.\n", line,
1707 bss->ssid.wpa_psk->group = 1;
1709 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1710 os_free(bss->ssid.wpa_psk_file);
1711 bss->ssid.wpa_psk_file = os_strdup(pos);
1712 if (!bss->ssid.wpa_psk_file) {
1713 printf("Line %d: allocation failed\n", line);
1716 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1718 hostapd_config_parse_key_mgmt(line, pos);
1719 if (bss->wpa_key_mgmt == -1)
1721 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1723 hostapd_config_parse_cipher(line, pos);
1724 if (bss->wpa_pairwise == -1 ||
1725 bss->wpa_pairwise == 0)
1727 else if (bss->wpa_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->wpa_pairwise, pos);
1735 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1737 hostapd_config_parse_cipher(line, pos);
1738 if (bss->rsn_pairwise == -1 ||
1739 bss->rsn_pairwise == 0)
1741 else if (bss->rsn_pairwise &
1742 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1743 WPA_CIPHER_WEP104)) {
1744 printf("Line %d: unsupported pairwise "
1745 "cipher suite '%s'\n",
1746 bss->rsn_pairwise, pos);
1749 #ifdef CONFIG_RSN_PREAUTH
1750 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1751 bss->rsn_preauth = atoi(pos);
1752 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1753 bss->rsn_preauth_interfaces = os_strdup(pos);
1754 #endif /* CONFIG_RSN_PREAUTH */
1755 #ifdef CONFIG_PEERKEY
1756 } else if (os_strcmp(buf, "peerkey") == 0) {
1757 bss->peerkey = atoi(pos);
1758 #endif /* CONFIG_PEERKEY */
1759 #ifdef CONFIG_IEEE80211R
1760 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1761 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1762 hexstr2bin(pos, bss->mobility_domain,
1763 MOBILITY_DOMAIN_ID_LEN) != 0) {
1764 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1765 "mobility_domain '%s'", line, pos);
1769 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1770 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1771 hexstr2bin(pos, bss->r1_key_holder,
1772 FT_R1KH_ID_LEN) != 0) {
1773 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1774 "r1_key_holder '%s'", line, pos);
1778 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1779 bss->r0_key_lifetime = atoi(pos);
1780 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1781 bss->reassociation_deadline = atoi(pos);
1782 } else if (os_strcmp(buf, "r0kh") == 0) {
1783 if (add_r0kh(bss, pos) < 0) {
1784 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1785 "r0kh '%s'", line, pos);
1789 } else if (os_strcmp(buf, "r1kh") == 0) {
1790 if (add_r1kh(bss, pos) < 0) {
1791 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1792 "r1kh '%s'", line, pos);
1796 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1797 bss->pmk_r1_push = atoi(pos);
1798 #endif /* CONFIG_IEEE80211R */
1799 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1800 os_free(bss->ctrl_interface);
1801 bss->ctrl_interface = os_strdup(pos);
1802 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1803 #ifndef CONFIG_NATIVE_WINDOWS
1806 const char *group = pos;
1808 grp = getgrnam(group);
1810 bss->ctrl_interface_gid = grp->gr_gid;
1811 bss->ctrl_interface_gid_set = 1;
1812 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1813 " (from group name '%s')",
1814 bss->ctrl_interface_gid, group);
1818 /* Group name not found - try to parse this as gid */
1819 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1820 if (*group == '\0' || *endp != '\0') {
1821 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1822 "'%s'", line, group);
1826 bss->ctrl_interface_gid_set = 1;
1827 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1828 bss->ctrl_interface_gid);
1829 #endif /* CONFIG_NATIVE_WINDOWS */
1830 #ifdef RADIUS_SERVER
1831 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1832 os_free(bss->radius_server_clients);
1833 bss->radius_server_clients = os_strdup(pos);
1834 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1835 bss->radius_server_auth_port = atoi(pos);
1836 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1837 bss->radius_server_ipv6 = atoi(pos);
1838 #endif /* RADIUS_SERVER */
1839 } else if (os_strcmp(buf, "test_socket") == 0) {
1840 os_free(bss->test_socket);
1841 bss->test_socket = os_strdup(pos);
1842 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1843 bss->use_pae_group_addr = atoi(pos);
1844 } else if (os_strcmp(buf, "hw_mode") == 0) {
1845 if (os_strcmp(pos, "a") == 0)
1846 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1847 else if (os_strcmp(pos, "b") == 0)
1848 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1849 else if (os_strcmp(pos, "g") == 0)
1850 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1852 printf("Line %d: unknown hw_mode '%s'\n",
1856 } else if (os_strcmp(buf, "channel") == 0) {
1857 conf->channel = atoi(pos);
1858 } else if (os_strcmp(buf, "beacon_int") == 0) {
1859 int val = atoi(pos);
1860 /* MIB defines range as 1..65535, but very small values
1861 * cause problems with the current implementation.
1862 * Since it is unlikely that this small numbers are
1863 * useful in real life scenarios, do not allow beacon
1864 * period to be set below 15 TU. */
1865 if (val < 15 || val > 65535) {
1866 printf("Line %d: invalid beacon_int %d "
1867 "(expected 15..65535)\n",
1871 conf->beacon_int = val;
1872 } else if (os_strcmp(buf, "dtim_period") == 0) {
1873 bss->dtim_period = atoi(pos);
1874 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1875 printf("Line %d: invalid dtim_period %d\n",
1876 line, bss->dtim_period);
1879 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1880 conf->rts_threshold = atoi(pos);
1881 if (conf->rts_threshold < 0 ||
1882 conf->rts_threshold > 2347) {
1883 printf("Line %d: invalid rts_threshold %d\n",
1884 line, conf->rts_threshold);
1887 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1888 conf->fragm_threshold = atoi(pos);
1889 if (conf->fragm_threshold < 256 ||
1890 conf->fragm_threshold > 2346) {
1891 printf("Line %d: invalid fragm_threshold %d\n",
1892 line, conf->fragm_threshold);
1895 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1896 int val = atoi(pos);
1897 if (val != 0 && val != 1) {
1898 printf("Line %d: invalid send_probe_response "
1899 "%d (expected 0 or 1)\n", line, val);
1901 conf->send_probe_response = val;
1902 } else if (os_strcmp(buf, "supported_rates") == 0) {
1903 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
1904 printf("Line %d: invalid rate list\n", line);
1907 } else if (os_strcmp(buf, "basic_rates") == 0) {
1908 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
1909 printf("Line %d: invalid rate list\n", line);
1912 } else if (os_strcmp(buf, "preamble") == 0) {
1914 conf->preamble = SHORT_PREAMBLE;
1916 conf->preamble = LONG_PREAMBLE;
1917 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
1918 bss->ignore_broadcast_ssid = atoi(pos);
1919 } else if (os_strcmp(buf, "bridge_packets") == 0) {
1920 conf->bridge_packets = atoi(pos);
1921 } else if (os_strcmp(buf, "wep_default_key") == 0) {
1922 bss->ssid.wep.idx = atoi(pos);
1923 if (bss->ssid.wep.idx > 3) {
1924 printf("Invalid wep_default_key index %d\n",
1928 } else if (os_strcmp(buf, "wep_key0") == 0 ||
1929 os_strcmp(buf, "wep_key1") == 0 ||
1930 os_strcmp(buf, "wep_key2") == 0 ||
1931 os_strcmp(buf, "wep_key3") == 0) {
1932 if (hostapd_config_read_wep(&bss->ssid.wep,
1933 buf[7] - '0', pos)) {
1934 printf("Line %d: invalid WEP key '%s'\n",
1938 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
1939 bss->ssid.dynamic_vlan = atoi(pos);
1940 } else if (os_strcmp(buf, "vlan_file") == 0) {
1941 if (hostapd_config_read_vlan_file(bss, pos)) {
1942 printf("Line %d: failed to read VLAN file "
1943 "'%s'\n", line, pos);
1946 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1947 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
1948 bss->ssid.vlan_tagged_interface = os_strdup(pos);
1949 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1950 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
1951 conf->passive_scan_interval = atoi(pos);
1952 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
1953 conf->passive_scan_listen = atoi(pos);
1954 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
1955 conf->passive_scan_mode = atoi(pos);
1956 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
1957 conf->ap_table_max_size = atoi(pos);
1958 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
1959 conf->ap_table_expiration_time = atoi(pos);
1960 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
1961 if (hostapd_config_tx_queue(conf, buf, pos)) {
1962 printf("Line %d: invalid TX queue item\n",
1966 } else if (os_strcmp(buf, "wme_enabled") == 0) {
1967 bss->wme_enabled = atoi(pos);
1968 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
1969 if (hostapd_config_wme_ac(conf, buf, pos)) {
1970 printf("Line %d: invalid wme ac item\n",
1974 } else if (os_strcmp(buf, "bss") == 0) {
1975 if (hostapd_config_bss(conf, pos)) {
1976 printf("Line %d: invalid bss item\n", line);
1979 } else if (os_strcmp(buf, "bssid") == 0) {
1980 if (bss == conf->bss &&
1981 (!conf->driver || !conf->driver->init_bssid)) {
1982 printf("Line %d: bssid item not allowed "
1983 "for the default interface and this "
1986 } else if (hwaddr_aton(pos, bss->bssid)) {
1987 printf("Line %d: invalid bssid item\n", line);
1990 #ifdef CONFIG_IEEE80211W
1991 } else if (os_strcmp(buf, "ieee80211w") == 0) {
1992 bss->ieee80211w = atoi(pos);
1993 #endif /* CONFIG_IEEE80211W */
1994 #ifdef CONFIG_IEEE80211N
1995 } else if (os_strcmp(buf, "ieee80211n") == 0) {
1996 bss->ieee80211n = atoi(pos);
1997 #endif /* CONFIG_IEEE80211N */
1998 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
1999 bss->max_listen_interval = atoi(pos);
2000 } else if (os_strcmp(buf, "okc") == 0) {
2001 bss->okc = atoi(pos);
2003 printf("Line %d: unknown configuration item '%s'\n",
2011 if (bss->individual_wep_key_len == 0) {
2012 /* individual keys are not use; can use key idx0 for broadcast
2014 bss->broadcast_key_idx_min = 0;
2017 /* Select group cipher based on the enabled pairwise cipher suites */
2020 pairwise |= bss->wpa_pairwise;
2022 if (bss->rsn_pairwise == 0)
2023 bss->rsn_pairwise = bss->wpa_pairwise;
2024 pairwise |= bss->rsn_pairwise;
2026 if (pairwise & WPA_CIPHER_TKIP)
2027 bss->wpa_group = WPA_CIPHER_TKIP;
2029 bss->wpa_group = WPA_CIPHER_CCMP;
2031 for (i = 0; i < conf->num_bss; i++) {
2032 bss = &conf->bss[i];
2034 bss->radius->auth_server = bss->radius->auth_servers;
2035 bss->radius->acct_server = bss->radius->acct_servers;
2037 if (bss->wpa && bss->ieee802_1x) {
2038 bss->ssid.security_policy = SECURITY_WPA;
2039 } else if (bss->wpa) {
2040 bss->ssid.security_policy = SECURITY_WPA_PSK;
2041 } else if (bss->ieee802_1x) {
2042 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2043 bss->ssid.wep.default_len = bss->default_wep_key_len;
2044 } else if (bss->ssid.wep.keys_set)
2045 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2047 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2050 if (hostapd_config_check(conf))
2054 printf("%d errors found in configuration file '%s'\n",
2056 hostapd_config_free(conf);
2064 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2068 if (a->idx != b->idx || a->default_len != b->default_len)
2070 for (i = 0; i < NUM_WEP_KEYS; i++)
2071 if (a->len[i] != b->len[i] ||
2072 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2078 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2083 for (i = 0; i < num_servers; i++) {
2084 os_free(servers[i].shared_secret);
2090 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2092 os_free(user->identity);
2093 os_free(user->password);
2098 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2101 for (i = 0; i < NUM_WEP_KEYS; i++) {
2102 os_free(keys->key[i]);
2103 keys->key[i] = NULL;
2108 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2110 struct hostapd_wpa_psk *psk, *prev;
2111 struct hostapd_eap_user *user, *prev_user;
2116 psk = conf->ssid.wpa_psk;
2123 os_free(conf->ssid.wpa_passphrase);
2124 os_free(conf->ssid.wpa_psk_file);
2125 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2126 os_free(conf->ssid.vlan_tagged_interface);
2127 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2129 user = conf->eap_user;
2133 hostapd_config_free_eap_user(prev_user);
2136 os_free(conf->dump_log_name);
2137 os_free(conf->eap_req_id_text);
2138 os_free(conf->accept_mac);
2139 os_free(conf->deny_mac);
2140 os_free(conf->nas_identifier);
2141 hostapd_config_free_radius(conf->radius->auth_servers,
2142 conf->radius->num_auth_servers);
2143 hostapd_config_free_radius(conf->radius->acct_servers,
2144 conf->radius->num_acct_servers);
2145 os_free(conf->rsn_preauth_interfaces);
2146 os_free(conf->ctrl_interface);
2147 os_free(conf->ca_cert);
2148 os_free(conf->server_cert);
2149 os_free(conf->private_key);
2150 os_free(conf->private_key_passwd);
2151 os_free(conf->dh_file);
2152 os_free(conf->pac_opaque_encr_key);
2153 os_free(conf->eap_fast_a_id);
2154 os_free(conf->eap_sim_db);
2155 os_free(conf->radius_server_clients);
2156 os_free(conf->test_socket);
2157 os_free(conf->radius);
2158 hostapd_config_free_vlan(conf);
2159 if (conf->ssid.dyn_vlan_keys) {
2160 struct hostapd_ssid *ssid = &conf->ssid;
2162 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2163 if (ssid->dyn_vlan_keys[i] == NULL)
2165 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2166 os_free(ssid->dyn_vlan_keys[i]);
2168 os_free(ssid->dyn_vlan_keys);
2169 ssid->dyn_vlan_keys = NULL;
2172 #ifdef CONFIG_IEEE80211R
2174 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2175 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2177 r0kh = conf->r0kh_list;
2178 conf->r0kh_list = NULL;
2185 r1kh = conf->r1kh_list;
2186 conf->r1kh_list = NULL;
2193 #endif /* CONFIG_IEEE80211R */
2197 void hostapd_config_free(struct hostapd_config *conf)
2204 for (i = 0; i < conf->num_bss; i++)
2205 hostapd_config_free_bss(&conf->bss[i]);
2212 /* Perform a binary search for given MAC address from a pre-sorted list.
2213 * Returns 1 if address is in the list or 0 if not. */
2214 int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
2216 int start, end, middle, res;
2219 end = num_entries - 1;
2221 while (start <= end) {
2222 middle = (start + end) / 2;
2223 res = os_memcmp(list[middle], addr, ETH_ALEN);
2236 int hostapd_rate_found(int *list, int rate)
2243 for (i = 0; list[i] >= 0; i++)
2244 if (list[i] == rate)
2251 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2253 struct hostapd_vlan *v = vlan;
2255 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2263 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2264 const u8 *addr, const u8 *prev_psk)
2266 struct hostapd_wpa_psk *psk;
2267 int next_ok = prev_psk == NULL;
2269 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2271 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2274 if (psk->psk == prev_psk)
2282 const struct hostapd_eap_user *
2283 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2284 size_t identity_len, int phase2)
2286 struct hostapd_eap_user *user = conf->eap_user;
2289 if (!phase2 && user->identity == NULL) {
2290 /* Wildcard match */
2294 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2295 identity_len >= user->identity_len &&
2296 os_memcmp(user->identity, identity, user->identity_len) ==
2298 /* Wildcard prefix match */
2302 if (user->phase2 == !!phase2 &&
2303 user->identity_len == identity_len &&
2304 os_memcmp(user->identity, identity, identity_len) == 0)