2 * hostapd / Configuration file
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #ifndef CONFIG_NATIVE_WINDOWS
18 #endif /* CONFIG_NATIVE_WINDOWS */
23 #include "eap_server/eap.h"
24 #include "radius/radius_client.h"
25 #include "wpa_common.h"
30 #define MAX_STA_COUNT 2007
32 extern struct wpa_driver_ops *hostapd_drivers[];
35 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
39 char buf[128], *pos, *pos2;
40 int line = 0, vlan_id;
41 struct hostapd_vlan *vlan;
43 f = fopen(fname, "r");
45 printf("VLAN file '%s' not readable.\n", fname);
49 while (fgets(buf, sizeof(buf), f)) {
55 while (*pos != '\0') {
66 vlan_id = VLAN_ID_WILDCARD;
69 vlan_id = strtol(buf, &pos, 10);
70 if (buf == pos || vlan_id < 1 ||
71 vlan_id > MAX_VLAN_ID) {
72 printf("Invalid VLAN ID at line %d in '%s'\n",
79 while (*pos == ' ' || *pos == '\t')
82 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
85 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
86 printf("Invalid VLAN ifname at line %d in '%s'\n",
92 vlan = os_malloc(sizeof(*vlan));
94 printf("Out of memory while reading VLAN interfaces "
95 "from '%s'\n", fname);
100 os_memset(vlan, 0, sizeof(*vlan));
101 vlan->vlan_id = vlan_id;
102 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
104 bss->vlan_tail->next = vlan;
107 bss->vlan_tail = vlan;
116 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
118 struct hostapd_vlan *vlan, *prev;
132 /* convert floats with one decimal place to value*10 int, i.e.,
133 * "1.5" will return 15 */
134 static int hostapd_config_read_int10(const char *value)
140 pos = os_strchr(value, '.');
144 if (*pos >= '0' && *pos <= '9')
152 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
154 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
155 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
156 bss->logger_syslog = (unsigned int) -1;
157 bss->logger_stdout = (unsigned int) -1;
159 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
161 bss->wep_rekeying_period = 300;
162 /* use key0 in individual key and key1 in broadcast key */
163 bss->broadcast_key_idx_min = 1;
164 bss->broadcast_key_idx_max = 2;
165 bss->eap_reauth_period = 3600;
167 bss->wpa_group_rekey = 600;
168 bss->wpa_gmk_rekey = 86400;
169 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
170 bss->wpa_pairwise = WPA_CIPHER_TKIP;
171 bss->wpa_group = WPA_CIPHER_TKIP;
172 bss->rsn_pairwise = 0;
174 bss->max_num_sta = MAX_STA_COUNT;
176 bss->dtim_period = 2;
178 bss->radius_server_auth_port = 1812;
179 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
180 bss->eapol_version = EAPOL_VERSION;
182 bss->max_listen_interval = 65535;
186 #ifdef CONFIG_IEEE80211N
187 static int hostapd_config_defaults_bss_80211n(struct hostapd_bss_config *bss)
189 u16 capabilities_info = 0;
190 u16 operation_mode = 0;
195 /* add default values to HT capabilities parameters */
196 os_memset(&bss->ht_capabilities, 0, sizeof(struct ht_cap_ie));
197 bss->ht_capabilities.id = WLAN_EID_HT_CAP;
198 bss->ht_capabilities.length = HT_CAPABILITIES_LEN;
200 #if 0 /* FIX: remove? was commented out */
201 bss->ht_capabilities.mac_ht_param_info.max_rx_ampdu_factor =
202 MAX_RX_AMPDU_FACTOR_64KB;
204 SET_2BIT_U8(&bss->ht_capabilities.data.mac_ht_params_info,
205 MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
206 MAX_RX_AMPDU_FACTOR_64KB);
208 SET_2BIT_LE16(&capabilities_info,
209 HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
210 MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
212 capabilities_info |= HT_CAP_INFO_GREEN_FIELD;
214 bss->ht_capabilities.data.capabilities_info =
215 host_to_le16(capabilities_info);
217 bss->ht_capabilities.data.supported_mcs_set[0] = 0xff;
218 bss->ht_capabilities.data.supported_mcs_set[1] = 0xff;
220 /* add default values to HT operation parameters */
221 os_memset(&bss->ht_operation, 0, sizeof(struct ht_operation_ie));
222 bss->ht_operation.id = WLAN_EID_HT_OPERATION;
223 bss->ht_operation.length = HT_OPERATION_LEN;
224 SET_2BIT_LE16(&operation_mode,
225 HT_INFO_OPERATION_MODE_OP_MODE_OFFSET,
227 bss->ht_operation.data.operation_mode = host_to_le16(operation_mode);
231 #endif /* CONFIG_IEEE80211N */
234 static struct hostapd_config * hostapd_config_defaults(void)
236 struct hostapd_config *conf;
237 struct hostapd_bss_config *bss;
239 const int aCWmin = 15, aCWmax = 1024;
240 const struct hostapd_wme_ac_params ac_bk =
241 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
242 const struct hostapd_wme_ac_params ac_be =
243 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
244 const struct hostapd_wme_ac_params ac_vi = /* video traffic */
245 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
246 const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
247 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
249 conf = os_zalloc(sizeof(*conf));
250 bss = os_zalloc(sizeof(*bss));
251 if (conf == NULL || bss == NULL) {
252 printf("Failed to allocate memory for configuration data.\n");
258 /* set default driver based on configuration */
259 conf->driver = hostapd_drivers[0];
260 if (conf->driver == NULL) {
261 printf("No driver wrappers registered!\n");
267 bss->radius = os_zalloc(sizeof(*bss->radius));
268 if (bss->radius == NULL) {
274 hostapd_config_defaults_bss(bss);
279 conf->beacon_int = 100;
280 conf->rts_threshold = -1; /* use driver default: 2347 */
281 conf->fragm_threshold = -1; /* user driver default: 2346 */
282 conf->send_probe_response = 1;
283 conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
285 os_memcpy(conf->country, "US ", 3);
287 for (i = 0; i < NUM_TX_QUEUES; i++)
288 conf->tx_queue[i].aifs = -1; /* use hw default */
290 conf->wme_ac_params[0] = ac_be;
291 conf->wme_ac_params[1] = ac_bk;
292 conf->wme_ac_params[2] = ac_vi;
293 conf->wme_ac_params[3] = ac_vo;
295 #ifdef CONFIG_IEEE80211N
296 hostapd_config_defaults_bss_80211n(bss);
297 #endif /* CONFIG_IEEE80211N */
303 int hostapd_mac_comp(const void *a, const void *b)
305 return os_memcmp(a, b, sizeof(macaddr));
309 int hostapd_mac_comp_empty(const void *a)
311 macaddr empty = { 0 };
312 return os_memcmp(a, empty, sizeof(macaddr));
316 static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
328 f = fopen(fname, "r");
330 printf("MAC list file '%s' not found.\n", fname);
334 while (fgets(buf, sizeof(buf), f)) {
340 while (*pos != '\0') {
350 if (hwaddr_aton(buf, addr)) {
351 printf("Invalid MAC address '%s' at line %d in '%s'\n",
357 newacl = os_realloc(*acl, (*num + 1) * ETH_ALEN);
358 if (newacl == NULL) {
359 printf("MAC list reallocation failed\n");
365 os_memcpy((*acl)[*num], addr, ETH_ALEN);
371 qsort(*acl, *num, sizeof(macaddr), hostapd_mac_comp);
377 static int hostapd_config_read_wpa_psk(const char *fname,
378 struct hostapd_ssid *ssid)
382 int line = 0, ret = 0, len, ok;
384 struct hostapd_wpa_psk *psk;
389 f = fopen(fname, "r");
391 printf("WPA PSK file '%s' not found.\n", fname);
395 while (fgets(buf, sizeof(buf), f)) {
401 while (*pos != '\0') {
411 if (hwaddr_aton(buf, addr)) {
412 printf("Invalid MAC address '%s' on line %d in '%s'\n",
418 psk = os_zalloc(sizeof(*psk));
420 printf("WPA PSK allocation failed\n");
424 if (is_zero_ether_addr(addr))
427 os_memcpy(psk->addr, addr, ETH_ALEN);
431 printf("No PSK on line %d in '%s'\n", line, fname);
439 len = os_strlen(pos);
440 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
442 else if (len >= 8 && len < 64) {
443 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
444 4096, psk->psk, PMK_LEN);
448 printf("Invalid PSK '%s' on line %d in '%s'\n",
455 psk->next = ssid->wpa_psk;
465 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
467 struct hostapd_ssid *ssid = &conf->ssid;
469 if (ssid->wpa_passphrase != NULL) {
470 if (ssid->wpa_psk != NULL) {
471 printf("Warning: both WPA PSK and passphrase set. "
472 "Using passphrase.\n");
473 os_free(ssid->wpa_psk);
475 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
476 if (ssid->wpa_psk == NULL) {
477 printf("Unable to alloc space for PSK\n");
480 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
481 (u8 *) ssid->ssid, ssid->ssid_len);
482 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
483 (u8 *) ssid->wpa_passphrase,
484 os_strlen(ssid->wpa_passphrase));
485 pbkdf2_sha1(ssid->wpa_passphrase,
486 ssid->ssid, ssid->ssid_len,
487 4096, ssid->wpa_psk->psk, PMK_LEN);
488 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
489 ssid->wpa_psk->psk, PMK_LEN);
490 ssid->wpa_psk->group = 1;
492 os_memset(ssid->wpa_passphrase, 0,
493 os_strlen(ssid->wpa_passphrase));
494 os_free(ssid->wpa_passphrase);
495 ssid->wpa_passphrase = NULL;
498 if (ssid->wpa_psk_file) {
499 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
509 static int hostapd_config_read_eap_user(const char *fname,
510 struct hostapd_bss_config *conf)
513 char buf[512], *pos, *start, *pos2;
514 int line = 0, ret = 0, num_methods;
515 struct hostapd_eap_user *user, *tail = NULL;
520 f = fopen(fname, "r");
522 printf("EAP user file '%s' not found.\n", fname);
526 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
527 while (fgets(buf, sizeof(buf), f)) {
533 while (*pos != '\0') {
545 if (buf[0] != '"' && buf[0] != '*') {
546 printf("Invalid EAP identity (no \" in start) on "
547 "line %d in '%s'\n", line, fname);
551 user = os_zalloc(sizeof(*user));
553 printf("EAP user allocation failed\n");
556 user->force_version = -1;
563 while (*pos != '"' && *pos != '\0')
566 printf("Invalid EAP identity (no \" in end) on"
567 " line %d in '%s'\n", line, fname);
571 user->identity = os_malloc(pos - start);
572 if (user->identity == NULL) {
573 printf("Failed to allocate memory for EAP "
577 os_memcpy(user->identity, start, pos - start);
578 user->identity_len = pos - start;
580 if (pos[0] == '"' && pos[1] == '*') {
581 user->wildcard_prefix = 1;
586 while (*pos == ' ' || *pos == '\t')
590 printf("No EAP method on line %d in '%s'\n",
596 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
606 char *pos3 = os_strchr(start, ',');
610 user->methods[num_methods].method =
613 &user->methods[num_methods].vendor);
614 if (user->methods[num_methods].vendor ==
616 user->methods[num_methods].method == EAP_TYPE_NONE)
618 if (os_strcmp(start, "TTLS-PAP") == 0) {
619 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
622 if (os_strcmp(start, "TTLS-CHAP") == 0) {
623 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
626 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
628 EAP_TTLS_AUTH_MSCHAP;
631 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
633 EAP_TTLS_AUTH_MSCHAPV2;
636 printf("Unsupported EAP type '%s' on line %d "
637 "in '%s'\n", start, line, fname);
642 if (num_methods >= EAP_USER_MAX_METHODS)
649 if (num_methods == 0 && user->ttls_auth == 0) {
650 printf("No EAP types configured on line %d in '%s'\n",
658 while (*pos == ' ' || *pos == '\t')
663 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
664 user->force_version = 0;
668 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
669 user->force_version = 1;
673 if (os_strncmp(pos, "[2]", 3) == 0) {
681 while (*pos != '"' && *pos != '\0')
684 printf("Invalid EAP password (no \" in end) "
685 "on line %d in '%s'\n", line, fname);
689 user->password = os_malloc(pos - start);
690 if (user->password == NULL) {
691 printf("Failed to allocate memory for EAP "
695 os_memcpy(user->password, start, pos - start);
696 user->password_len = pos - start;
699 } else if (os_strncmp(pos, "hash:", 5) == 0) {
702 while (*pos2 != '\0' && *pos2 != ' ' &&
703 *pos2 != '\t' && *pos2 != '#')
705 if (pos2 - pos != 32) {
706 printf("Invalid password hash on line %d in "
707 "'%s'\n", line, fname);
710 user->password = os_malloc(16);
711 if (user->password == NULL) {
712 printf("Failed to allocate memory for EAP "
716 if (hexstr2bin(pos, user->password, 16) < 0) {
717 printf("Invalid hash password on line %d in "
718 "'%s'\n", line, fname);
721 user->password_len = 16;
722 user->password_hash = 1;
726 while (*pos2 != '\0' && *pos2 != ' ' &&
727 *pos2 != '\t' && *pos2 != '#')
729 if ((pos2 - pos) & 1) {
730 printf("Invalid hex password on line %d in "
731 "'%s'\n", line, fname);
734 user->password = os_malloc((pos2 - pos) / 2);
735 if (user->password == NULL) {
736 printf("Failed to allocate memory for EAP "
740 if (hexstr2bin(pos, user->password,
741 (pos2 - pos) / 2) < 0) {
742 printf("Invalid hex password on line %d in "
743 "'%s'\n", line, fname);
746 user->password_len = (pos2 - pos) / 2;
750 while (*pos == ' ' || *pos == '\t')
752 if (os_strncmp(pos, "[2]", 3) == 0) {
758 tail = conf->eap_user = user;
767 os_free(user->password);
768 os_free(user->identity);
779 #endif /* EAP_SERVER */
783 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
784 int *num_server, const char *val, int def_port,
785 struct hostapd_radius_server **curr_serv)
787 struct hostapd_radius_server *nserv;
789 static int server_index = 1;
791 nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
796 nserv = &nserv[*num_server];
798 (*curr_serv) = nserv;
800 os_memset(nserv, 0, sizeof(*nserv));
801 nserv->port = def_port;
802 ret = hostapd_parse_ip_addr(val, &nserv->addr);
803 nserv->index = server_index++;
809 static int hostapd_config_parse_key_mgmt(int line, const char *value)
812 char *start, *end, *buf;
814 buf = os_strdup(value);
819 while (start != '\0') {
820 while (*start == ' ' || *start == '\t')
825 while (*end != ' ' && *end != '\t' && *end != '\0')
829 if (os_strcmp(start, "WPA-PSK") == 0)
830 val |= WPA_KEY_MGMT_PSK;
831 else if (os_strcmp(start, "WPA-EAP") == 0)
832 val |= WPA_KEY_MGMT_IEEE8021X;
833 #ifdef CONFIG_IEEE80211R
834 else if (os_strcmp(start, "FT-PSK") == 0)
835 val |= WPA_KEY_MGMT_FT_PSK;
836 else if (os_strcmp(start, "FT-EAP") == 0)
837 val |= WPA_KEY_MGMT_FT_IEEE8021X;
838 #endif /* CONFIG_IEEE80211R */
840 printf("Line %d: invalid key_mgmt '%s'\n",
853 printf("Line %d: no key_mgmt values configured.\n", line);
861 static int hostapd_config_parse_cipher(int line, const char *value)
864 char *start, *end, *buf;
866 buf = os_strdup(value);
871 while (start != '\0') {
872 while (*start == ' ' || *start == '\t')
877 while (*end != ' ' && *end != '\t' && *end != '\0')
881 if (os_strcmp(start, "CCMP") == 0)
882 val |= WPA_CIPHER_CCMP;
883 else if (os_strcmp(start, "TKIP") == 0)
884 val |= WPA_CIPHER_TKIP;
885 else if (os_strcmp(start, "WEP104") == 0)
886 val |= WPA_CIPHER_WEP104;
887 else if (os_strcmp(start, "WEP40") == 0)
888 val |= WPA_CIPHER_WEP40;
889 else if (os_strcmp(start, "NONE") == 0)
890 val |= WPA_CIPHER_NONE;
892 printf("Line %d: invalid cipher '%s'.", line, start);
904 printf("Line %d: no cipher values configured.", line);
911 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
912 struct hostapd_config *conf)
914 if (bss->ieee802_1x && !bss->eap_server &&
915 !bss->radius->auth_servers) {
916 printf("Invalid IEEE 802.1X configuration (no EAP "
917 "authenticator configured).\n");
921 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
922 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
923 bss->ssid.wpa_psk_file == NULL) {
924 printf("WPA-PSK enabled, but PSK or passphrase is not "
929 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
932 for (i = 0; i < conf->num_bss; i++) {
933 if ((&conf->bss[i] != bss) &&
934 (hostapd_mac_comp(conf->bss[i].bssid,
936 printf("Duplicate BSSID " MACSTR
937 " on interface '%s' and '%s'.\n",
939 conf->bss[i].iface, bss->iface);
945 #ifdef CONFIG_IEEE80211R
946 if ((bss->wpa_key_mgmt &
947 (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
948 (bss->nas_identifier == NULL ||
949 os_strlen(bss->nas_identifier) < 1 ||
950 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
951 printf("FT (IEEE 802.11r) requires nas_identifier to be "
952 "configured as a 1..48 octet string\n");
955 #endif /* CONFIG_IEEE80211R */
961 static int hostapd_config_check(struct hostapd_config *conf)
965 for (i = 0; i < conf->num_bss; i++) {
966 if (hostapd_config_check_bss(&conf->bss[i], conf))
974 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
977 size_t len = os_strlen(val);
979 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
983 if (len < 2 || val[len - 1] != '"')
986 wep->key[keyidx] = os_malloc(len);
987 if (wep->key[keyidx] == NULL)
989 os_memcpy(wep->key[keyidx], val + 1, len);
990 wep->len[keyidx] = len;
995 wep->key[keyidx] = os_malloc(len);
996 if (wep->key[keyidx] == NULL)
998 wep->len[keyidx] = len;
999 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
1009 static int hostapd_parse_rates(int **rate_list, char *val)
1015 os_free(*rate_list);
1020 while (*pos != '\0') {
1026 list = os_malloc(sizeof(int) * (count + 2));
1031 while (*pos != '\0') {
1032 end = os_strchr(pos, ' ');
1036 list[count++] = atoi(pos);
1048 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
1050 struct hostapd_bss_config *bss;
1052 if (*ifname == '\0')
1055 bss = os_realloc(conf->bss, (conf->num_bss + 1) *
1056 sizeof(struct hostapd_bss_config));
1058 printf("Failed to allocate memory for multi-BSS entry\n");
1063 bss = &(conf->bss[conf->num_bss]);
1064 os_memset(bss, 0, sizeof(*bss));
1065 bss->radius = os_zalloc(sizeof(*bss->radius));
1066 if (bss->radius == NULL) {
1067 printf("Failed to allocate memory for multi-BSS RADIUS "
1073 conf->last_bss = bss;
1075 hostapd_config_defaults_bss(bss);
1076 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1077 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1083 static int valid_cw(int cw)
1085 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
1086 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
1091 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1092 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1093 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1094 IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
1095 IEEE80211_TX_QUEUE_DATA4 = 4,
1096 IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
1097 IEEE80211_TX_QUEUE_BEACON = 7
1100 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
1105 struct hostapd_tx_queue_params *queue;
1107 /* skip 'tx_queue_' prefix */
1109 if (os_strncmp(pos, "data", 4) == 0 &&
1110 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1113 } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
1114 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
1116 } else if (os_strncmp(pos, "beacon_", 7) == 0) {
1117 num = IEEE80211_TX_QUEUE_BEACON;
1120 printf("Unknown tx_queue name '%s'\n", pos);
1124 queue = &conf->tx_queue[num];
1126 if (os_strcmp(pos, "aifs") == 0) {
1127 queue->aifs = atoi(val);
1128 if (queue->aifs < 0 || queue->aifs > 255) {
1129 printf("Invalid AIFS value %d\n", queue->aifs);
1132 } else if (os_strcmp(pos, "cwmin") == 0) {
1133 queue->cwmin = atoi(val);
1134 if (!valid_cw(queue->cwmin)) {
1135 printf("Invalid cwMin value %d\n", queue->cwmin);
1138 } else if (os_strcmp(pos, "cwmax") == 0) {
1139 queue->cwmax = atoi(val);
1140 if (!valid_cw(queue->cwmax)) {
1141 printf("Invalid cwMax value %d\n", queue->cwmax);
1144 } else if (os_strcmp(pos, "burst") == 0) {
1145 queue->burst = hostapd_config_read_int10(val);
1147 printf("Unknown tx_queue field '%s'\n", pos);
1151 queue->configured = 1;
1157 static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
1162 struct hostapd_wme_ac_params *ac;
1164 /* skip 'wme_ac_' prefix */
1166 if (os_strncmp(pos, "be_", 3) == 0) {
1169 } else if (os_strncmp(pos, "bk_", 3) == 0) {
1172 } else if (os_strncmp(pos, "vi_", 3) == 0) {
1175 } else if (os_strncmp(pos, "vo_", 3) == 0) {
1179 printf("Unknown wme name '%s'\n", pos);
1183 ac = &conf->wme_ac_params[num];
1185 if (os_strcmp(pos, "aifs") == 0) {
1187 if (v < 1 || v > 255) {
1188 printf("Invalid AIFS value %d\n", v);
1192 } else if (os_strcmp(pos, "cwmin") == 0) {
1194 if (v < 0 || v > 12) {
1195 printf("Invalid cwMin value %d\n", v);
1199 } else if (os_strcmp(pos, "cwmax") == 0) {
1201 if (v < 0 || v > 12) {
1202 printf("Invalid cwMax value %d\n", v);
1206 } else if (os_strcmp(pos, "txop_limit") == 0) {
1208 if (v < 0 || v > 0xffff) {
1209 printf("Invalid txop value %d\n", v);
1213 } else if (os_strcmp(pos, "acm") == 0) {
1215 if (v < 0 || v > 1) {
1216 printf("Invalid acm value %d\n", v);
1219 ac->admission_control_mandatory = v;
1221 printf("Unknown wme_ac_ field '%s'\n", pos);
1229 #ifdef CONFIG_IEEE80211R
1230 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1232 struct ft_remote_r0kh *r0kh;
1235 r0kh = os_zalloc(sizeof(*r0kh));
1239 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1241 next = os_strchr(pos, ' ');
1244 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1245 printf("Invalid R0KH MAC address: '%s'\n", pos);
1251 next = os_strchr(pos, ' ');
1254 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1255 printf("Invalid R0KH-ID: '%s'\n", pos);
1259 r0kh->id_len = next - pos - 1;
1260 os_memcpy(r0kh->id, pos, r0kh->id_len);
1263 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1264 printf("Invalid R0KH key: '%s'\n", pos);
1269 r0kh->next = bss->r0kh_list;
1270 bss->r0kh_list = r0kh;
1276 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1278 struct ft_remote_r1kh *r1kh;
1281 r1kh = os_zalloc(sizeof(*r1kh));
1285 /* 02:01:02:03:04:05 02:01:02:03:04:05
1286 * 000102030405060708090a0b0c0d0e0f */
1288 next = os_strchr(pos, ' ');
1291 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1292 printf("Invalid R1KH MAC address: '%s'\n", pos);
1298 next = os_strchr(pos, ' ');
1301 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1302 printf("Invalid R1KH-ID: '%s'\n", pos);
1308 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1309 printf("Invalid R1KH key: '%s'\n", pos);
1314 r1kh->next = bss->r1kh_list;
1315 bss->r1kh_list = r1kh;
1319 #endif /* CONFIG_IEEE80211R */
1322 struct hostapd_config * hostapd_config_read(const char *fname)
1324 struct hostapd_config *conf;
1325 struct hostapd_bss_config *bss;
1327 char buf[256], *pos;
1333 f = fopen(fname, "r");
1335 printf("Could not open configuration file '%s' for reading.\n",
1340 conf = hostapd_config_defaults();
1345 bss = conf->last_bss = conf->bss;
1347 while (fgets(buf, sizeof(buf), f)) {
1348 bss = conf->last_bss;
1354 while (*pos != '\0') {
1364 pos = os_strchr(buf, '=');
1366 printf("Line %d: invalid line '%s'\n", line, buf);
1373 if (os_strcmp(buf, "interface") == 0) {
1374 os_strlcpy(conf->bss[0].iface, pos,
1375 sizeof(conf->bss[0].iface));
1376 } else if (os_strcmp(buf, "bridge") == 0) {
1377 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1378 } else if (os_strcmp(buf, "driver") == 0) {
1380 /* clear to get error below if setting is invalid */
1381 conf->driver = NULL;
1382 for (i = 0; hostapd_drivers[i]; i++) {
1383 if (os_strcmp(pos, hostapd_drivers[i]->name) ==
1385 conf->driver = hostapd_drivers[i];
1389 if (conf->driver == NULL) {
1390 printf("Line %d: invalid/unknown driver "
1391 "'%s'\n", line, pos);
1394 } else if (os_strcmp(buf, "debug") == 0) {
1395 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1396 "configuration variable is not used "
1398 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1399 bss->logger_syslog_level = atoi(pos);
1400 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1401 bss->logger_stdout_level = atoi(pos);
1402 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1403 bss->logger_syslog = atoi(pos);
1404 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1405 bss->logger_stdout = atoi(pos);
1406 } else if (os_strcmp(buf, "dump_file") == 0) {
1407 bss->dump_log_name = os_strdup(pos);
1408 } else if (os_strcmp(buf, "ssid") == 0) {
1409 bss->ssid.ssid_len = os_strlen(pos);
1410 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1411 bss->ssid.ssid_len < 1) {
1412 printf("Line %d: invalid SSID '%s'\n", line,
1416 os_memcpy(bss->ssid.ssid, pos,
1417 bss->ssid.ssid_len);
1418 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
1419 bss->ssid.ssid_set = 1;
1421 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1422 bss->macaddr_acl = atoi(pos);
1423 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1424 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1425 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1426 printf("Line %d: unknown macaddr_acl %d\n",
1427 line, bss->macaddr_acl);
1429 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1430 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1431 &bss->num_accept_mac))
1433 printf("Line %d: Failed to read "
1434 "accept_mac_file '%s'\n",
1438 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1439 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1440 &bss->num_deny_mac))
1442 printf("Line %d: Failed to read "
1443 "deny_mac_file '%s'\n",
1447 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1448 bss->ap_max_inactivity = atoi(pos);
1449 } else if (os_strcmp(buf, "country_code") == 0) {
1450 os_memcpy(conf->country, pos, 2);
1451 /* FIX: make this configurable */
1452 conf->country[2] = ' ';
1453 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1454 conf->ieee80211d = atoi(pos);
1455 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1456 conf->ieee80211h = atoi(pos);
1457 } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
1458 if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
1459 printf("Line %d: invalid MAC address '%s'\n",
1464 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1465 bss->ieee802_1x = atoi(pos);
1466 } else if (os_strcmp(buf, "eapol_version") == 0) {
1467 bss->eapol_version = atoi(pos);
1468 if (bss->eapol_version < 1 ||
1469 bss->eapol_version > 2) {
1470 printf("Line %d: invalid EAPOL "
1471 "version (%d): '%s'.\n",
1472 line, bss->eapol_version, pos);
1475 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1476 bss->eapol_version);
1478 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1479 bss->eap_server = atoi(pos);
1480 printf("Line %d: obsolete eap_authenticator used; "
1481 "this has been renamed to eap_server\n", line);
1482 } else if (os_strcmp(buf, "eap_server") == 0) {
1483 bss->eap_server = atoi(pos);
1484 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1485 if (hostapd_config_read_eap_user(pos, bss))
1487 } else if (os_strcmp(buf, "ca_cert") == 0) {
1488 os_free(bss->ca_cert);
1489 bss->ca_cert = os_strdup(pos);
1490 } else if (os_strcmp(buf, "server_cert") == 0) {
1491 os_free(bss->server_cert);
1492 bss->server_cert = os_strdup(pos);
1493 } else if (os_strcmp(buf, "private_key") == 0) {
1494 os_free(bss->private_key);
1495 bss->private_key = os_strdup(pos);
1496 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1497 os_free(bss->private_key_passwd);
1498 bss->private_key_passwd = os_strdup(pos);
1499 } else if (os_strcmp(buf, "check_crl") == 0) {
1500 bss->check_crl = atoi(pos);
1501 } else if (os_strcmp(buf, "dh_file") == 0) {
1502 os_free(bss->dh_file);
1503 bss->dh_file = os_strdup(pos);
1505 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1506 os_free(bss->pac_opaque_encr_key);
1507 bss->pac_opaque_encr_key = os_malloc(16);
1508 if (bss->pac_opaque_encr_key == NULL) {
1509 printf("Line %d: No memory for "
1510 "pac_opque_encr_key\n", line);
1512 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1514 printf("Line %d: Invalid pac_opque_encr_key\n",
1518 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1519 os_free(bss->eap_fast_a_id);
1520 bss->eap_fast_a_id = os_strdup(pos);
1521 #endif /* EAP_FAST */
1523 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1524 os_free(bss->eap_sim_db);
1525 bss->eap_sim_db = os_strdup(pos);
1526 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1527 bss->eap_sim_aka_result_ind = atoi(pos);
1528 #endif /* EAP_SIM */
1530 } else if (os_strcmp(buf, "tnc") == 0) {
1531 bss->tnc = atoi(pos);
1532 #endif /* EAP_TNC */
1533 #endif /* EAP_SERVER */
1534 } else if (os_strcmp(buf, "eap_message") == 0) {
1536 bss->eap_req_id_text = os_strdup(pos);
1537 if (bss->eap_req_id_text == NULL) {
1538 printf("Line %d: Failed to allocate memory "
1539 "for eap_req_id_text\n", line);
1543 bss->eap_req_id_text_len =
1544 os_strlen(bss->eap_req_id_text);
1545 term = os_strstr(bss->eap_req_id_text, "\\0");
1548 os_memmove(term, term + 1,
1549 bss->eap_req_id_text_len -
1550 (term - bss->eap_req_id_text) - 1);
1551 bss->eap_req_id_text_len--;
1553 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1554 bss->default_wep_key_len = atoi(pos);
1555 if (bss->default_wep_key_len > 13) {
1556 printf("Line %d: invalid WEP key len %lu "
1557 "(= %lu bits)\n", line,
1559 bss->default_wep_key_len,
1561 bss->default_wep_key_len * 8);
1564 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1565 bss->individual_wep_key_len = atoi(pos);
1566 if (bss->individual_wep_key_len < 0 ||
1567 bss->individual_wep_key_len > 13) {
1568 printf("Line %d: invalid WEP key len %d "
1569 "(= %d bits)\n", line,
1570 bss->individual_wep_key_len,
1571 bss->individual_wep_key_len * 8);
1574 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1575 bss->wep_rekeying_period = atoi(pos);
1576 if (bss->wep_rekeying_period < 0) {
1577 printf("Line %d: invalid period %d\n",
1578 line, bss->wep_rekeying_period);
1581 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1582 bss->eap_reauth_period = atoi(pos);
1583 if (bss->eap_reauth_period < 0) {
1584 printf("Line %d: invalid period %d\n",
1585 line, bss->eap_reauth_period);
1588 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1589 bss->eapol_key_index_workaround = atoi(pos);
1591 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1592 bss->ieee802_11f = 1;
1593 os_strlcpy(bss->iapp_iface, pos,
1594 sizeof(bss->iapp_iface));
1595 #endif /* CONFIG_IAPP */
1596 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1597 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1598 printf("Line %d: invalid IP address '%s'\n",
1602 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1603 bss->nas_identifier = os_strdup(pos);
1604 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1605 if (hostapd_config_read_radius_addr(
1606 &bss->radius->auth_servers,
1607 &bss->radius->num_auth_servers, pos, 1812,
1608 &bss->radius->auth_server)) {
1609 printf("Line %d: invalid IP address '%s'\n",
1613 } else if (bss->radius->auth_server &&
1614 os_strcmp(buf, "auth_server_port") == 0) {
1615 bss->radius->auth_server->port = atoi(pos);
1616 } else if (bss->radius->auth_server &&
1617 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1618 int len = os_strlen(pos);
1620 /* RFC 2865, Ch. 3 */
1621 printf("Line %d: empty shared secret is not "
1622 "allowed.\n", line);
1625 bss->radius->auth_server->shared_secret =
1626 (u8 *) os_strdup(pos);
1627 bss->radius->auth_server->shared_secret_len = len;
1628 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
1629 if (hostapd_config_read_radius_addr(
1630 &bss->radius->acct_servers,
1631 &bss->radius->num_acct_servers, pos, 1813,
1632 &bss->radius->acct_server)) {
1633 printf("Line %d: invalid IP address '%s'\n",
1637 } else if (bss->radius->acct_server &&
1638 os_strcmp(buf, "acct_server_port") == 0) {
1639 bss->radius->acct_server->port = atoi(pos);
1640 } else if (bss->radius->acct_server &&
1641 os_strcmp(buf, "acct_server_shared_secret") == 0) {
1642 int len = os_strlen(pos);
1644 /* RFC 2865, Ch. 3 */
1645 printf("Line %d: empty shared secret is not "
1646 "allowed.\n", line);
1649 bss->radius->acct_server->shared_secret =
1650 (u8 *) os_strdup(pos);
1651 bss->radius->acct_server->shared_secret_len = len;
1652 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
1654 bss->radius->retry_primary_interval = atoi(pos);
1655 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
1657 bss->radius->acct_interim_interval = atoi(pos);
1658 } else if (os_strcmp(buf, "auth_algs") == 0) {
1659 bss->auth_algs = atoi(pos);
1660 if (bss->auth_algs == 0) {
1661 printf("Line %d: no authentication algorithms "
1666 } else if (os_strcmp(buf, "max_num_sta") == 0) {
1667 bss->max_num_sta = atoi(pos);
1668 if (bss->max_num_sta < 0 ||
1669 bss->max_num_sta > MAX_STA_COUNT) {
1670 printf("Line %d: Invalid max_num_sta=%d; "
1671 "allowed range 0..%d\n", line,
1672 bss->max_num_sta, MAX_STA_COUNT);
1675 } else if (os_strcmp(buf, "wpa") == 0) {
1676 bss->wpa = atoi(pos);
1677 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
1678 bss->wpa_group_rekey = atoi(pos);
1679 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
1680 bss->wpa_strict_rekey = atoi(pos);
1681 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
1682 bss->wpa_gmk_rekey = atoi(pos);
1683 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
1684 int len = os_strlen(pos);
1685 if (len < 8 || len > 63) {
1686 printf("Line %d: invalid WPA passphrase length"
1687 " %d (expected 8..63)\n", line, len);
1690 os_free(bss->ssid.wpa_passphrase);
1691 bss->ssid.wpa_passphrase = os_strdup(pos);
1693 } else if (os_strcmp(buf, "wpa_psk") == 0) {
1694 os_free(bss->ssid.wpa_psk);
1696 os_zalloc(sizeof(struct hostapd_wpa_psk));
1697 if (bss->ssid.wpa_psk == NULL)
1699 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
1701 pos[PMK_LEN * 2] != '\0') {
1702 printf("Line %d: Invalid PSK '%s'.\n", line,
1706 bss->ssid.wpa_psk->group = 1;
1708 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
1709 os_free(bss->ssid.wpa_psk_file);
1710 bss->ssid.wpa_psk_file = os_strdup(pos);
1711 if (!bss->ssid.wpa_psk_file) {
1712 printf("Line %d: allocation failed\n", line);
1715 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
1717 hostapd_config_parse_key_mgmt(line, pos);
1718 if (bss->wpa_key_mgmt == -1)
1720 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
1722 hostapd_config_parse_cipher(line, pos);
1723 if (bss->wpa_pairwise == -1 ||
1724 bss->wpa_pairwise == 0)
1726 else if (bss->wpa_pairwise &
1727 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1728 WPA_CIPHER_WEP104)) {
1729 printf("Line %d: unsupported pairwise "
1730 "cipher suite '%s'\n",
1731 bss->wpa_pairwise, pos);
1734 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
1736 hostapd_config_parse_cipher(line, pos);
1737 if (bss->rsn_pairwise == -1 ||
1738 bss->rsn_pairwise == 0)
1740 else if (bss->rsn_pairwise &
1741 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
1742 WPA_CIPHER_WEP104)) {
1743 printf("Line %d: unsupported pairwise "
1744 "cipher suite '%s'\n",
1745 bss->rsn_pairwise, pos);
1748 #ifdef CONFIG_RSN_PREAUTH
1749 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
1750 bss->rsn_preauth = atoi(pos);
1751 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
1752 bss->rsn_preauth_interfaces = os_strdup(pos);
1753 #endif /* CONFIG_RSN_PREAUTH */
1754 #ifdef CONFIG_PEERKEY
1755 } else if (os_strcmp(buf, "peerkey") == 0) {
1756 bss->peerkey = atoi(pos);
1757 #endif /* CONFIG_PEERKEY */
1758 #ifdef CONFIG_IEEE80211R
1759 } else if (os_strcmp(buf, "mobility_domain") == 0) {
1760 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
1761 hexstr2bin(pos, bss->mobility_domain,
1762 MOBILITY_DOMAIN_ID_LEN) != 0) {
1763 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1764 "mobility_domain '%s'", line, pos);
1768 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
1769 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
1770 hexstr2bin(pos, bss->r1_key_holder,
1771 FT_R1KH_ID_LEN) != 0) {
1772 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1773 "r1_key_holder '%s'", line, pos);
1777 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
1778 bss->r0_key_lifetime = atoi(pos);
1779 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
1780 bss->reassociation_deadline = atoi(pos);
1781 } else if (os_strcmp(buf, "r0kh") == 0) {
1782 if (add_r0kh(bss, pos) < 0) {
1783 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1784 "r0kh '%s'", line, pos);
1788 } else if (os_strcmp(buf, "r1kh") == 0) {
1789 if (add_r1kh(bss, pos) < 0) {
1790 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
1791 "r1kh '%s'", line, pos);
1795 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
1796 bss->pmk_r1_push = atoi(pos);
1797 #endif /* CONFIG_IEEE80211R */
1798 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
1799 os_free(bss->ctrl_interface);
1800 bss->ctrl_interface = os_strdup(pos);
1801 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
1802 #ifndef CONFIG_NATIVE_WINDOWS
1805 const char *group = pos;
1807 grp = getgrnam(group);
1809 bss->ctrl_interface_gid = grp->gr_gid;
1810 bss->ctrl_interface_gid_set = 1;
1811 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
1812 " (from group name '%s')",
1813 bss->ctrl_interface_gid, group);
1817 /* Group name not found - try to parse this as gid */
1818 bss->ctrl_interface_gid = strtol(group, &endp, 10);
1819 if (*group == '\0' || *endp != '\0') {
1820 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
1821 "'%s'", line, group);
1825 bss->ctrl_interface_gid_set = 1;
1826 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
1827 bss->ctrl_interface_gid);
1828 #endif /* CONFIG_NATIVE_WINDOWS */
1829 #ifdef RADIUS_SERVER
1830 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
1831 os_free(bss->radius_server_clients);
1832 bss->radius_server_clients = os_strdup(pos);
1833 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
1834 bss->radius_server_auth_port = atoi(pos);
1835 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
1836 bss->radius_server_ipv6 = atoi(pos);
1837 #endif /* RADIUS_SERVER */
1838 } else if (os_strcmp(buf, "test_socket") == 0) {
1839 os_free(bss->test_socket);
1840 bss->test_socket = os_strdup(pos);
1841 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
1842 bss->use_pae_group_addr = atoi(pos);
1843 } else if (os_strcmp(buf, "hw_mode") == 0) {
1844 if (os_strcmp(pos, "a") == 0)
1845 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1846 else if (os_strcmp(pos, "b") == 0)
1847 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1848 else if (os_strcmp(pos, "g") == 0)
1849 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1851 printf("Line %d: unknown hw_mode '%s'\n",
1855 } else if (os_strcmp(buf, "channel") == 0) {
1856 conf->channel = atoi(pos);
1857 } else if (os_strcmp(buf, "beacon_int") == 0) {
1858 int val = atoi(pos);
1859 /* MIB defines range as 1..65535, but very small values
1860 * cause problems with the current implementation.
1861 * Since it is unlikely that this small numbers are
1862 * useful in real life scenarios, do not allow beacon
1863 * period to be set below 15 TU. */
1864 if (val < 15 || val > 65535) {
1865 printf("Line %d: invalid beacon_int %d "
1866 "(expected 15..65535)\n",
1870 conf->beacon_int = val;
1871 } else if (os_strcmp(buf, "dtim_period") == 0) {
1872 bss->dtim_period = atoi(pos);
1873 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
1874 printf("Line %d: invalid dtim_period %d\n",
1875 line, bss->dtim_period);
1878 } else if (os_strcmp(buf, "rts_threshold") == 0) {
1879 conf->rts_threshold = atoi(pos);
1880 if (conf->rts_threshold < 0 ||
1881 conf->rts_threshold > 2347) {
1882 printf("Line %d: invalid rts_threshold %d\n",
1883 line, conf->rts_threshold);
1886 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
1887 conf->fragm_threshold = atoi(pos);
1888 if (conf->fragm_threshold < 256 ||
1889 conf->fragm_threshold > 2346) {
1890 printf("Line %d: invalid fragm_threshold %d\n",
1891 line, conf->fragm_threshold);
1894 } else if (os_strcmp(buf, "send_probe_response") == 0) {
1895 int val = atoi(pos);
1896 if (val != 0 && val != 1) {
1897 printf("Line %d: invalid send_probe_response "
1898 "%d (expected 0 or 1)\n", line, val);
1900 conf->send_probe_response = val;
1901 } else if (os_strcmp(buf, "supported_rates") == 0) {
1902 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
1903 printf("Line %d: invalid rate list\n", line);
1906 } else if (os_strcmp(buf, "basic_rates") == 0) {
1907 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
1908 printf("Line %d: invalid rate list\n", line);
1911 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
1912 bss->ignore_broadcast_ssid = atoi(pos);
1913 } else if (os_strcmp(buf, "bridge_packets") == 0) {
1914 conf->bridge_packets = atoi(pos);
1915 } else if (os_strcmp(buf, "wep_default_key") == 0) {
1916 bss->ssid.wep.idx = atoi(pos);
1917 if (bss->ssid.wep.idx > 3) {
1918 printf("Invalid wep_default_key index %d\n",
1922 } else if (os_strcmp(buf, "wep_key0") == 0 ||
1923 os_strcmp(buf, "wep_key1") == 0 ||
1924 os_strcmp(buf, "wep_key2") == 0 ||
1925 os_strcmp(buf, "wep_key3") == 0) {
1926 if (hostapd_config_read_wep(&bss->ssid.wep,
1927 buf[7] - '0', pos)) {
1928 printf("Line %d: invalid WEP key '%s'\n",
1932 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
1933 bss->ssid.dynamic_vlan = atoi(pos);
1934 } else if (os_strcmp(buf, "vlan_file") == 0) {
1935 if (hostapd_config_read_vlan_file(bss, pos)) {
1936 printf("Line %d: failed to read VLAN file "
1937 "'%s'\n", line, pos);
1940 #ifdef CONFIG_FULL_DYNAMIC_VLAN
1941 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
1942 bss->ssid.vlan_tagged_interface = os_strdup(pos);
1943 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
1944 } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
1945 conf->passive_scan_interval = atoi(pos);
1946 } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
1947 conf->passive_scan_listen = atoi(pos);
1948 } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
1949 conf->passive_scan_mode = atoi(pos);
1950 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
1951 conf->ap_table_max_size = atoi(pos);
1952 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
1953 conf->ap_table_expiration_time = atoi(pos);
1954 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
1955 if (hostapd_config_tx_queue(conf, buf, pos)) {
1956 printf("Line %d: invalid TX queue item\n",
1960 } else if (os_strcmp(buf, "wme_enabled") == 0) {
1961 bss->wme_enabled = atoi(pos);
1962 } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
1963 if (hostapd_config_wme_ac(conf, buf, pos)) {
1964 printf("Line %d: invalid wme ac item\n",
1968 } else if (os_strcmp(buf, "bss") == 0) {
1969 if (hostapd_config_bss(conf, pos)) {
1970 printf("Line %d: invalid bss item\n", line);
1973 } else if (os_strcmp(buf, "bssid") == 0) {
1974 if (bss == conf->bss &&
1975 (!conf->driver || !conf->driver->init_bssid)) {
1976 printf("Line %d: bssid item not allowed "
1977 "for the default interface and this "
1980 } else if (hwaddr_aton(pos, bss->bssid)) {
1981 printf("Line %d: invalid bssid item\n", line);
1984 #ifdef CONFIG_IEEE80211W
1985 } else if (os_strcmp(buf, "ieee80211w") == 0) {
1986 bss->ieee80211w = atoi(pos);
1987 #endif /* CONFIG_IEEE80211W */
1988 #ifdef CONFIG_IEEE80211N
1989 } else if (os_strcmp(buf, "ieee80211n") == 0) {
1990 bss->ieee80211n = atoi(pos);
1991 #endif /* CONFIG_IEEE80211N */
1992 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
1993 bss->max_listen_interval = atoi(pos);
1994 } else if (os_strcmp(buf, "okc") == 0) {
1995 bss->okc = atoi(pos);
1997 printf("Line %d: unknown configuration item '%s'\n",
2005 if (bss->individual_wep_key_len == 0) {
2006 /* individual keys are not use; can use key idx0 for broadcast
2008 bss->broadcast_key_idx_min = 0;
2011 /* Select group cipher based on the enabled pairwise cipher suites */
2014 pairwise |= bss->wpa_pairwise;
2016 if (bss->rsn_pairwise == 0)
2017 bss->rsn_pairwise = bss->wpa_pairwise;
2018 pairwise |= bss->rsn_pairwise;
2020 if (pairwise & WPA_CIPHER_TKIP)
2021 bss->wpa_group = WPA_CIPHER_TKIP;
2023 bss->wpa_group = WPA_CIPHER_CCMP;
2025 for (i = 0; i < conf->num_bss; i++) {
2026 bss = &conf->bss[i];
2028 bss->radius->auth_server = bss->radius->auth_servers;
2029 bss->radius->acct_server = bss->radius->acct_servers;
2031 if (bss->wpa && bss->ieee802_1x) {
2032 bss->ssid.security_policy = SECURITY_WPA;
2033 } else if (bss->wpa) {
2034 bss->ssid.security_policy = SECURITY_WPA_PSK;
2035 } else if (bss->ieee802_1x) {
2036 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2037 bss->ssid.wep.default_len = bss->default_wep_key_len;
2038 } else if (bss->ssid.wep.keys_set)
2039 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2041 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2044 if (hostapd_config_check(conf))
2048 printf("%d errors found in configuration file '%s'\n",
2050 hostapd_config_free(conf);
2058 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
2062 if (a->idx != b->idx || a->default_len != b->default_len)
2064 for (i = 0; i < NUM_WEP_KEYS; i++)
2065 if (a->len[i] != b->len[i] ||
2066 os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
2072 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
2077 for (i = 0; i < num_servers; i++) {
2078 os_free(servers[i].shared_secret);
2084 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
2086 os_free(user->identity);
2087 os_free(user->password);
2092 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
2095 for (i = 0; i < NUM_WEP_KEYS; i++) {
2096 os_free(keys->key[i]);
2097 keys->key[i] = NULL;
2102 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
2104 struct hostapd_wpa_psk *psk, *prev;
2105 struct hostapd_eap_user *user, *prev_user;
2110 psk = conf->ssid.wpa_psk;
2117 os_free(conf->ssid.wpa_passphrase);
2118 os_free(conf->ssid.wpa_psk_file);
2119 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2120 os_free(conf->ssid.vlan_tagged_interface);
2121 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2123 user = conf->eap_user;
2127 hostapd_config_free_eap_user(prev_user);
2130 os_free(conf->dump_log_name);
2131 os_free(conf->eap_req_id_text);
2132 os_free(conf->accept_mac);
2133 os_free(conf->deny_mac);
2134 os_free(conf->nas_identifier);
2135 hostapd_config_free_radius(conf->radius->auth_servers,
2136 conf->radius->num_auth_servers);
2137 hostapd_config_free_radius(conf->radius->acct_servers,
2138 conf->radius->num_acct_servers);
2139 os_free(conf->rsn_preauth_interfaces);
2140 os_free(conf->ctrl_interface);
2141 os_free(conf->ca_cert);
2142 os_free(conf->server_cert);
2143 os_free(conf->private_key);
2144 os_free(conf->private_key_passwd);
2145 os_free(conf->dh_file);
2146 os_free(conf->pac_opaque_encr_key);
2147 os_free(conf->eap_fast_a_id);
2148 os_free(conf->eap_sim_db);
2149 os_free(conf->radius_server_clients);
2150 os_free(conf->test_socket);
2151 os_free(conf->radius);
2152 hostapd_config_free_vlan(conf);
2153 if (conf->ssid.dyn_vlan_keys) {
2154 struct hostapd_ssid *ssid = &conf->ssid;
2156 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
2157 if (ssid->dyn_vlan_keys[i] == NULL)
2159 hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
2160 os_free(ssid->dyn_vlan_keys[i]);
2162 os_free(ssid->dyn_vlan_keys);
2163 ssid->dyn_vlan_keys = NULL;
2166 #ifdef CONFIG_IEEE80211R
2168 struct ft_remote_r0kh *r0kh, *r0kh_prev;
2169 struct ft_remote_r1kh *r1kh, *r1kh_prev;
2171 r0kh = conf->r0kh_list;
2172 conf->r0kh_list = NULL;
2179 r1kh = conf->r1kh_list;
2180 conf->r1kh_list = NULL;
2187 #endif /* CONFIG_IEEE80211R */
2191 void hostapd_config_free(struct hostapd_config *conf)
2198 for (i = 0; i < conf->num_bss; i++)
2199 hostapd_config_free_bss(&conf->bss[i]);
2206 /* Perform a binary search for given MAC address from a pre-sorted list.
2207 * Returns 1 if address is in the list or 0 if not. */
2208 int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
2210 int start, end, middle, res;
2213 end = num_entries - 1;
2215 while (start <= end) {
2216 middle = (start + end) / 2;
2217 res = os_memcmp(list[middle], addr, ETH_ALEN);
2230 int hostapd_rate_found(int *list, int rate)
2237 for (i = 0; list[i] >= 0; i++)
2238 if (list[i] == rate)
2245 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
2247 struct hostapd_vlan *v = vlan;
2249 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
2257 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
2258 const u8 *addr, const u8 *prev_psk)
2260 struct hostapd_wpa_psk *psk;
2261 int next_ok = prev_psk == NULL;
2263 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
2265 (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
2268 if (psk->psk == prev_psk)
2276 const struct hostapd_eap_user *
2277 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
2278 size_t identity_len, int phase2)
2280 struct hostapd_eap_user *user = conf->eap_user;
2283 if (!phase2 && user->identity == NULL) {
2284 /* Wildcard match */
2288 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
2289 identity_len >= user->identity_len &&
2290 os_memcmp(user->identity, identity, user->identity_len) ==
2292 /* Wildcard prefix match */
2296 if (user->phase2 == !!phase2 &&
2297 user->identity_len == identity_len &&
2298 os_memcmp(user->identity, identity, identity_len) == 0)