2 * hostapd / Configuration file parser
3 * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #ifndef CONFIG_NATIVE_WINDOWS
12 #endif /* CONFIG_NATIVE_WINDOWS */
14 #include "utils/common.h"
15 #include "utils/uuid.h"
16 #include "common/ieee802_11_defs.h"
17 #include "drivers/driver.h"
18 #include "eap_server/eap.h"
19 #include "radius/radius_client.h"
20 #include "ap/wpa_auth.h"
21 #include "ap/ap_config.h"
22 #include "config_file.h"
25 extern struct wpa_driver_ops *wpa_drivers[];
28 #ifndef CONFIG_NO_VLAN
29 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
33 char buf[128], *pos, *pos2;
34 int line = 0, vlan_id;
35 struct hostapd_vlan *vlan;
37 f = fopen(fname, "r");
39 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
43 while (fgets(buf, sizeof(buf), f)) {
49 while (*pos != '\0') {
60 vlan_id = VLAN_ID_WILDCARD;
63 vlan_id = strtol(buf, &pos, 10);
64 if (buf == pos || vlan_id < 1 ||
65 vlan_id > MAX_VLAN_ID) {
66 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
67 "line %d in '%s'", line, fname);
73 while (*pos == ' ' || *pos == '\t')
76 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
79 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
80 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
81 "in '%s'", line, fname);
86 vlan = os_zalloc(sizeof(*vlan));
88 wpa_printf(MSG_ERROR, "Out of memory while reading "
89 "VLAN interfaces from '%s'", fname);
94 vlan->vlan_id = vlan_id;
95 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
97 bss->vlan_tail->next = vlan;
100 bss->vlan_tail = vlan;
107 #endif /* CONFIG_NO_VLAN */
110 static int hostapd_acl_comp(const void *a, const void *b)
112 const struct mac_acl_entry *aa = a;
113 const struct mac_acl_entry *bb = b;
114 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
118 static int hostapd_config_read_maclist(const char *fname,
119 struct mac_acl_entry **acl, int *num)
125 struct mac_acl_entry *newacl;
131 f = fopen(fname, "r");
133 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
137 while (fgets(buf, sizeof(buf), f)) {
143 while (*pos != '\0') {
153 if (hwaddr_aton(buf, addr)) {
154 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
155 "line %d in '%s'", buf, line, fname);
162 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
164 while (*pos == ' ' || *pos == '\t')
169 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
170 if (newacl == NULL) {
171 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
177 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
178 (*acl)[*num].vlan_id = vlan_id;
184 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
191 static int hostapd_config_read_eap_user(const char *fname,
192 struct hostapd_bss_config *conf)
195 char buf[512], *pos, *start, *pos2;
196 int line = 0, ret = 0, num_methods;
197 struct hostapd_eap_user *user, *tail = NULL;
202 if (os_strncmp(fname, "sqlite:", 7) == 0) {
203 os_free(conf->eap_user_sqlite);
204 conf->eap_user_sqlite = os_strdup(fname + 7);
208 f = fopen(fname, "r");
210 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
214 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
215 while (fgets(buf, sizeof(buf), f)) {
221 while (*pos != '\0') {
233 if (buf[0] != '"' && buf[0] != '*') {
234 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
235 "start) on line %d in '%s'", line, fname);
239 user = os_zalloc(sizeof(*user));
241 wpa_printf(MSG_ERROR, "EAP user allocation failed");
244 user->force_version = -1;
251 while (*pos != '"' && *pos != '\0')
254 wpa_printf(MSG_ERROR, "Invalid EAP identity "
255 "(no \" in end) on line %d in '%s'",
260 user->identity = os_malloc(pos - start);
261 if (user->identity == NULL) {
262 wpa_printf(MSG_ERROR, "Failed to allocate "
263 "memory for EAP identity");
266 os_memcpy(user->identity, start, pos - start);
267 user->identity_len = pos - start;
269 if (pos[0] == '"' && pos[1] == '*') {
270 user->wildcard_prefix = 1;
275 while (*pos == ' ' || *pos == '\t')
279 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
280 "'%s'", line, fname);
285 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
295 char *pos3 = os_strchr(start, ',');
299 user->methods[num_methods].method =
302 &user->methods[num_methods].vendor);
303 if (user->methods[num_methods].vendor ==
305 user->methods[num_methods].method == EAP_TYPE_NONE)
307 if (os_strcmp(start, "TTLS-PAP") == 0) {
308 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
311 if (os_strcmp(start, "TTLS-CHAP") == 0) {
312 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
315 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
317 EAP_TTLS_AUTH_MSCHAP;
320 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
322 EAP_TTLS_AUTH_MSCHAPV2;
325 wpa_printf(MSG_ERROR, "Unsupported EAP type "
326 "'%s' on line %d in '%s'",
332 if (num_methods >= EAP_MAX_METHODS)
339 if (num_methods == 0 && user->ttls_auth == 0) {
340 wpa_printf(MSG_ERROR, "No EAP types configured on "
341 "line %d in '%s'", line, fname);
348 while (*pos == ' ' || *pos == '\t')
353 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
354 user->force_version = 0;
358 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
359 user->force_version = 1;
363 if (os_strncmp(pos, "[2]", 3) == 0) {
371 while (*pos != '"' && *pos != '\0')
374 wpa_printf(MSG_ERROR, "Invalid EAP password "
375 "(no \" in end) on line %d in '%s'",
380 user->password = os_malloc(pos - start);
381 if (user->password == NULL) {
382 wpa_printf(MSG_ERROR, "Failed to allocate "
383 "memory for EAP password");
386 os_memcpy(user->password, start, pos - start);
387 user->password_len = pos - start;
390 } else if (os_strncmp(pos, "hash:", 5) == 0) {
393 while (*pos2 != '\0' && *pos2 != ' ' &&
394 *pos2 != '\t' && *pos2 != '#')
396 if (pos2 - pos != 32) {
397 wpa_printf(MSG_ERROR, "Invalid password hash "
398 "on line %d in '%s'", line, fname);
401 user->password = os_malloc(16);
402 if (user->password == NULL) {
403 wpa_printf(MSG_ERROR, "Failed to allocate "
404 "memory for EAP password hash");
407 if (hexstr2bin(pos, user->password, 16) < 0) {
408 wpa_printf(MSG_ERROR, "Invalid hash password "
409 "on line %d in '%s'", line, fname);
412 user->password_len = 16;
413 user->password_hash = 1;
417 while (*pos2 != '\0' && *pos2 != ' ' &&
418 *pos2 != '\t' && *pos2 != '#')
420 if ((pos2 - pos) & 1) {
421 wpa_printf(MSG_ERROR, "Invalid hex password "
422 "on line %d in '%s'", line, fname);
425 user->password = os_malloc((pos2 - pos) / 2);
426 if (user->password == NULL) {
427 wpa_printf(MSG_ERROR, "Failed to allocate "
428 "memory for EAP password");
431 if (hexstr2bin(pos, user->password,
432 (pos2 - pos) / 2) < 0) {
433 wpa_printf(MSG_ERROR, "Invalid hex password "
434 "on line %d in '%s'", line, fname);
437 user->password_len = (pos2 - pos) / 2;
441 while (*pos == ' ' || *pos == '\t')
443 if (os_strncmp(pos, "[2]", 3) == 0) {
449 tail = conf->eap_user = user;
458 os_free(user->password);
459 os_free(user->identity);
470 #endif /* EAP_SERVER */
473 #ifndef CONFIG_NO_RADIUS
475 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
476 int *num_server, const char *val, int def_port,
477 struct hostapd_radius_server **curr_serv)
479 struct hostapd_radius_server *nserv;
481 static int server_index = 1;
483 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
488 nserv = &nserv[*num_server];
490 (*curr_serv) = nserv;
492 os_memset(nserv, 0, sizeof(*nserv));
493 nserv->port = def_port;
494 ret = hostapd_parse_ip_addr(val, &nserv->addr);
495 nserv->index = server_index++;
501 static struct hostapd_radius_attr *
502 hostapd_parse_radius_attr(const char *value)
506 struct hostapd_radius_attr *attr;
509 attr = os_zalloc(sizeof(*attr));
513 attr->type = atoi(value);
515 pos = os_strchr(value, ':');
517 attr->val = wpabuf_alloc(1);
518 if (attr->val == NULL) {
522 wpabuf_put_u8(attr->val, 0);
527 if (pos[0] == '\0' || pos[1] != ':') {
536 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
539 len = os_strlen(pos);
543 attr->val = wpabuf_alloc(len);
544 if (attr->val == NULL)
546 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
547 wpabuf_free(attr->val);
553 attr->val = wpabuf_alloc(4);
555 wpabuf_put_be32(attr->val, atoi(pos));
562 if (attr->val == NULL) {
571 static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
576 secret = os_strchr(val, ' ');
582 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
585 os_free(bss->radius_das_shared_secret);
586 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
587 if (bss->radius_das_shared_secret == NULL)
589 bss->radius_das_shared_secret_len = os_strlen(secret);
593 #endif /* CONFIG_NO_RADIUS */
596 static int hostapd_config_parse_key_mgmt(int line, const char *value)
599 char *start, *end, *buf;
601 buf = os_strdup(value);
606 while (*start != '\0') {
607 while (*start == ' ' || *start == '\t')
612 while (*end != ' ' && *end != '\t' && *end != '\0')
616 if (os_strcmp(start, "WPA-PSK") == 0)
617 val |= WPA_KEY_MGMT_PSK;
618 else if (os_strcmp(start, "WPA-EAP") == 0)
619 val |= WPA_KEY_MGMT_IEEE8021X;
620 #ifdef CONFIG_IEEE80211R
621 else if (os_strcmp(start, "FT-PSK") == 0)
622 val |= WPA_KEY_MGMT_FT_PSK;
623 else if (os_strcmp(start, "FT-EAP") == 0)
624 val |= WPA_KEY_MGMT_FT_IEEE8021X;
625 #endif /* CONFIG_IEEE80211R */
626 #ifdef CONFIG_IEEE80211W
627 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
628 val |= WPA_KEY_MGMT_PSK_SHA256;
629 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
630 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
631 #endif /* CONFIG_IEEE80211W */
633 else if (os_strcmp(start, "SAE") == 0)
634 val |= WPA_KEY_MGMT_SAE;
635 else if (os_strcmp(start, "FT-SAE") == 0)
636 val |= WPA_KEY_MGMT_FT_SAE;
637 #endif /* CONFIG_SAE */
639 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
652 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
653 "configured.", line);
661 static int hostapd_config_parse_cipher(int line, const char *value)
663 int val = wpa_parse_cipher(value);
665 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
670 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
678 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
681 size_t len = os_strlen(val);
683 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
687 if (len < 2 || val[len - 1] != '"')
690 wep->key[keyidx] = os_malloc(len);
691 if (wep->key[keyidx] == NULL)
693 os_memcpy(wep->key[keyidx], val + 1, len);
694 wep->len[keyidx] = len;
699 wep->key[keyidx] = os_malloc(len);
700 if (wep->key[keyidx] == NULL)
702 wep->len[keyidx] = len;
703 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
713 static int hostapd_parse_intlist(int **int_list, char *val)
724 while (*pos != '\0') {
730 list = os_malloc(sizeof(int) * (count + 2));
735 while (*pos != '\0') {
736 end = os_strchr(pos, ' ');
740 list[count++] = atoi(pos);
752 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
754 struct hostapd_bss_config *bss;
759 bss = os_realloc_array(conf->bss, conf->num_bss + 1,
760 sizeof(struct hostapd_bss_config));
762 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
768 bss = &(conf->bss[conf->num_bss]);
769 os_memset(bss, 0, sizeof(*bss));
770 bss->radius = os_zalloc(sizeof(*bss->radius));
771 if (bss->radius == NULL) {
772 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
773 "multi-BSS RADIUS data");
778 conf->last_bss = bss;
780 hostapd_config_defaults_bss(bss);
781 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
782 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
788 /* convert floats with one decimal place to value*10 int, i.e.,
789 * "1.5" will return 15 */
790 static int hostapd_config_read_int10(const char *value)
796 pos = os_strchr(value, '.');
800 if (*pos >= '0' && *pos <= '9')
808 static int valid_cw(int cw)
810 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
811 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
816 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
817 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
818 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
819 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
822 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
827 struct hostapd_tx_queue_params *queue;
829 /* skip 'tx_queue_' prefix */
831 if (os_strncmp(pos, "data", 4) == 0 &&
832 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
835 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
836 os_strncmp(pos, "beacon_", 7) == 0) {
837 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
840 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
844 if (num >= NUM_TX_QUEUES) {
845 /* for backwards compatibility, do not trigger failure */
846 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
850 queue = &conf->tx_queue[num];
852 if (os_strcmp(pos, "aifs") == 0) {
853 queue->aifs = atoi(val);
854 if (queue->aifs < 0 || queue->aifs > 255) {
855 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
859 } else if (os_strcmp(pos, "cwmin") == 0) {
860 queue->cwmin = atoi(val);
861 if (!valid_cw(queue->cwmin)) {
862 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
866 } else if (os_strcmp(pos, "cwmax") == 0) {
867 queue->cwmax = atoi(val);
868 if (!valid_cw(queue->cwmax)) {
869 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
873 } else if (os_strcmp(pos, "burst") == 0) {
874 queue->burst = hostapd_config_read_int10(val);
876 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
884 #ifdef CONFIG_IEEE80211R
885 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
887 struct ft_remote_r0kh *r0kh;
890 r0kh = os_zalloc(sizeof(*r0kh));
894 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
896 next = os_strchr(pos, ' ');
899 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
900 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
906 next = os_strchr(pos, ' ');
909 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
910 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
914 r0kh->id_len = next - pos - 1;
915 os_memcpy(r0kh->id, pos, r0kh->id_len);
918 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
919 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
924 r0kh->next = bss->r0kh_list;
925 bss->r0kh_list = r0kh;
931 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
933 struct ft_remote_r1kh *r1kh;
936 r1kh = os_zalloc(sizeof(*r1kh));
940 /* 02:01:02:03:04:05 02:01:02:03:04:05
941 * 000102030405060708090a0b0c0d0e0f */
943 next = os_strchr(pos, ' ');
946 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
947 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
953 next = os_strchr(pos, ' ');
956 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
957 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
963 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
964 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
969 r1kh->next = bss->r1kh_list;
970 bss->r1kh_list = r1kh;
974 #endif /* CONFIG_IEEE80211R */
977 #ifdef CONFIG_IEEE80211N
978 static int hostapd_config_ht_capab(struct hostapd_config *conf,
981 if (os_strstr(capab, "[LDPC]"))
982 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
983 if (os_strstr(capab, "[HT40-]")) {
984 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
985 conf->secondary_channel = -1;
987 if (os_strstr(capab, "[HT40+]")) {
988 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
989 conf->secondary_channel = 1;
991 if (os_strstr(capab, "[SMPS-STATIC]")) {
992 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
993 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
995 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
996 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
997 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
999 if (os_strstr(capab, "[GF]"))
1000 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1001 if (os_strstr(capab, "[SHORT-GI-20]"))
1002 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1003 if (os_strstr(capab, "[SHORT-GI-40]"))
1004 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1005 if (os_strstr(capab, "[TX-STBC]"))
1006 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1007 if (os_strstr(capab, "[RX-STBC1]")) {
1008 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1009 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1011 if (os_strstr(capab, "[RX-STBC12]")) {
1012 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1013 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1015 if (os_strstr(capab, "[RX-STBC123]")) {
1016 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1017 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1019 if (os_strstr(capab, "[DELAYED-BA]"))
1020 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1021 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1022 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1023 if (os_strstr(capab, "[DSSS_CCK-40]"))
1024 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1025 if (os_strstr(capab, "[PSMP]"))
1026 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1027 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1028 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1032 #endif /* CONFIG_IEEE80211N */
1035 #ifdef CONFIG_IEEE80211AC
1036 static int hostapd_config_vht_capab(struct hostapd_config *conf,
1039 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1040 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1041 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1042 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1043 if (os_strstr(capab, "[VHT160]"))
1044 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1045 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1046 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1047 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1048 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1049 if (os_strstr(capab, "[RXLDPC]"))
1050 conf->vht_capab |= VHT_CAP_RXLDPC;
1051 if (os_strstr(capab, "[SHORT-GI-80]"))
1052 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1053 if (os_strstr(capab, "[SHORT-GI-160]"))
1054 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1055 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1056 conf->vht_capab |= VHT_CAP_TXSTBC;
1057 if (os_strstr(capab, "[RX-STBC-1]"))
1058 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1059 if (os_strstr(capab, "[RX-STBC-12]"))
1060 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1061 if (os_strstr(capab, "[RX-STBC-123]"))
1062 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1063 if (os_strstr(capab, "[RX-STBC-1234]"))
1064 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1065 if (os_strstr(capab, "[SU-BEAMFORMER]"))
1066 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1067 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
1068 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1069 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
1070 (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
1071 conf->vht_capab |= VHT_CAP_BEAMFORMER_ANTENNAS_MAX;
1072 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
1073 (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
1074 conf->vht_capab |= VHT_CAP_SOUNDING_DIMENTION_MAX;
1075 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1076 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1077 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1078 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1079 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1080 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1081 if (os_strstr(capab, "[HTC-VHT]"))
1082 conf->vht_capab |= VHT_CAP_HTC_VHT;
1083 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
1084 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
1085 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1086 (conf->vht_capab & VHT_CAP_HTC_VHT))
1087 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1088 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1089 (conf->vht_capab & VHT_CAP_HTC_VHT))
1090 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1091 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1092 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1093 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1094 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1097 #endif /* CONFIG_IEEE80211AC */
1100 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
1101 struct hostapd_config *conf)
1103 if (bss->ieee802_1x && !bss->eap_server &&
1104 !bss->radius->auth_servers) {
1105 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1106 "EAP authenticator configured).");
1110 if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
1111 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1112 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1113 "RADIUS checking (macaddr_acl=2) enabled.");
1117 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
1118 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1119 bss->ssid.wpa_psk_file == NULL &&
1120 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1121 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1122 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1123 "is not configured.");
1127 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
1130 for (i = 0; i < conf->num_bss; i++) {
1131 if ((&conf->bss[i] != bss) &&
1132 (hostapd_mac_comp(conf->bss[i].bssid,
1133 bss->bssid) == 0)) {
1134 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1135 " on interface '%s' and '%s'.",
1136 MAC2STR(bss->bssid),
1137 conf->bss[i].iface, bss->iface);
1143 #ifdef CONFIG_IEEE80211R
1144 if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
1145 (bss->nas_identifier == NULL ||
1146 os_strlen(bss->nas_identifier) < 1 ||
1147 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1148 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1149 "nas_identifier to be configured as a 1..48 octet "
1153 #endif /* CONFIG_IEEE80211R */
1155 #ifdef CONFIG_IEEE80211N
1156 if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
1157 bss->disable_11n = 1;
1158 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
1159 "allowed, disabling HT capabilites");
1162 if (conf->ieee80211n &&
1163 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1164 bss->disable_11n = 1;
1165 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1166 "allowed, disabling HT capabilities");
1169 if (conf->ieee80211n && bss->wpa &&
1170 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1171 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP))) {
1172 bss->disable_11n = 1;
1173 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1174 "requires CCMP/GCMP to be enabled, disabling HT "
1177 #endif /* CONFIG_IEEE80211N */
1180 if (bss->wps_state && bss->ignore_broadcast_ssid) {
1181 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1182 "configuration forced WPS to be disabled");
1186 if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
1187 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1192 if (bss->wps_state && bss->wpa &&
1194 !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
1195 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
1196 "WPA2/CCMP forced WPS to be disabled");
1199 #endif /* CONFIG_WPS2 */
1204 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
1205 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1206 "configuration is required for Hotspot 2.0 "
1210 #endif /* CONFIG_HS20 */
1216 static int hostapd_config_check(struct hostapd_config *conf)
1220 if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
1221 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1222 "setting the country_code");
1226 if (conf->ieee80211h && !conf->ieee80211d) {
1227 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1228 "IEEE 802.11d enabled");
1232 for (i = 0; i < conf->num_bss; i++) {
1233 if (hostapd_config_check_bss(&conf->bss[i], conf))
1241 #ifdef CONFIG_INTERWORKING
1242 static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1245 size_t len = os_strlen(pos);
1246 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1248 struct hostapd_roaming_consortium *rc;
1250 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1251 hexstr2bin(pos, oi, len / 2)) {
1252 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1258 rc = os_realloc_array(bss->roaming_consortium,
1259 bss->roaming_consortium_count + 1,
1260 sizeof(struct hostapd_roaming_consortium));
1264 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1265 rc[bss->roaming_consortium_count].len = len;
1267 bss->roaming_consortium = rc;
1268 bss->roaming_consortium_count++;
1274 static int parse_lang_string(struct hostapd_lang_string **array,
1275 unsigned int *count, char *pos)
1279 struct hostapd_lang_string *ls;
1281 sep = os_strchr(pos, ':');
1286 clen = os_strlen(pos);
1289 nlen = os_strlen(sep);
1293 ls = os_realloc_array(*array, *count + 1,
1294 sizeof(struct hostapd_lang_string));
1299 ls = &(*array)[*count];
1302 os_memset(ls->lang, 0, sizeof(ls->lang));
1303 os_memcpy(ls->lang, pos, clen);
1304 ls->name_len = nlen;
1305 os_memcpy(ls->name, sep, nlen);
1311 static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1314 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1315 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1323 static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1328 u8 *info = NULL, *ipos;
1330 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1333 for (pos = buf; *pos; pos++) {
1334 if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
1339 if (1 + count * 3 > 0x7f)
1342 info = os_zalloc(2 + 3 + count * 3);
1347 *ipos++ = 0; /* GUD - Version 1 */
1348 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1349 *ipos++ = 0; /* PLMN List IEI */
1350 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1351 *ipos++ = 1 + count * 3;
1352 *ipos++ = count; /* Number of PLMNs */
1355 while (pos && *pos) {
1360 mnc = os_strchr(pos, ',');
1364 pos = os_strchr(mnc, ';');
1368 mnc_len = os_strlen(mnc);
1369 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1372 /* BC coded MCC,MNC */
1373 /* MCC digit 2 | MCC digit 1 */
1374 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1375 /* MNC digit 3 | MCC digit 3 */
1376 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1378 /* MNC digit 2 | MNC digit 1 */
1379 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1382 os_free(bss->anqp_3gpp_cell_net);
1383 bss->anqp_3gpp_cell_net = info;
1384 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1385 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1386 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
1391 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1398 static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1400 struct hostapd_nai_realm_data *realm;
1403 char *pos, *end, *rpos;
1405 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1407 if (offsets == NULL)
1410 for (i = 0; i < bss->nai_realm_count; i++) {
1411 realm = &bss->nai_realm_data[i];
1412 for (j = 0; j < MAX_NAI_REALMS; j++) {
1413 offsets[i * MAX_NAI_REALMS + j] =
1415 realm->realm[j] - realm->realm_buf : -1;
1419 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1420 sizeof(struct hostapd_nai_realm_data));
1421 if (realm == NULL) {
1425 bss->nai_realm_data = realm;
1427 /* patch the pointers after realloc */
1428 for (i = 0; i < bss->nai_realm_count; i++) {
1429 realm = &bss->nai_realm_data[i];
1430 for (j = 0; j < MAX_NAI_REALMS; j++) {
1431 int offs = offsets[i * MAX_NAI_REALMS + j];
1433 realm->realm[j] = realm->realm_buf + offs;
1435 realm->realm[j] = NULL;
1440 realm = &bss->nai_realm_data[bss->nai_realm_count];
1441 os_memset(realm, 0, sizeof(*realm));
1444 realm->encoding = atoi(pos);
1445 pos = os_strchr(pos, ',');
1450 end = os_strchr(pos, ',');
1455 len = os_strlen(pos);
1458 if (len > MAX_NAI_REALMLEN) {
1459 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1460 "characters)", (int) len, MAX_NAI_REALMLEN);
1463 os_memcpy(realm->realm_buf, pos, len);
1470 while (pos && *pos) {
1471 struct hostapd_nai_realm_eap *eap;
1473 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1474 wpa_printf(MSG_ERROR, "Too many EAP methods");
1478 eap = &realm->eap_method[realm->eap_method_count];
1479 realm->eap_method_count++;
1481 end = os_strchr(pos, ',');
1483 end = pos + os_strlen(pos);
1485 eap->eap_method = atoi(pos);
1487 pos = os_strchr(pos, '[');
1488 if (pos == NULL || pos > end)
1491 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1492 wpa_printf(MSG_ERROR, "Too many auth params");
1495 eap->auth_id[eap->num_auths] = atoi(pos);
1496 pos = os_strchr(pos, ':');
1497 if (pos == NULL || pos > end)
1500 eap->auth_val[eap->num_auths] = atoi(pos);
1501 pos = os_strchr(pos, ']');
1502 if (pos == NULL || pos > end)
1514 /* Split realm list into null terminated realms */
1515 rpos = realm->realm_buf;
1518 if (i >= MAX_NAI_REALMS) {
1519 wpa_printf(MSG_ERROR, "Too many realms");
1522 realm->realm[i++] = rpos;
1523 rpos = os_strchr(rpos, ';');
1529 bss->nai_realm_count++;
1534 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1538 #endif /* CONFIG_INTERWORKING */
1542 static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1548 if (bss->hs20_connection_capability_len >= 0xfff0)
1551 conn_cap = os_realloc(bss->hs20_connection_capability,
1552 bss->hs20_connection_capability_len + 4);
1553 if (conn_cap == NULL)
1556 bss->hs20_connection_capability = conn_cap;
1557 conn_cap += bss->hs20_connection_capability_len;
1559 conn_cap[0] = atoi(pos);
1560 pos = os_strchr(pos, ':');
1564 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1565 pos = os_strchr(pos, ':');
1569 conn_cap[3] = atoi(pos);
1570 bss->hs20_connection_capability_len += 4;
1576 static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1582 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1584 wan_metrics = os_zalloc(13);
1585 if (wan_metrics == NULL)
1590 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1597 /* Downlink Speed */
1598 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1599 pos = os_strchr(pos, ':');
1605 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1606 pos = os_strchr(pos, ':');
1612 wan_metrics[9] = atoi(pos);
1613 pos = os_strchr(pos, ':');
1619 wan_metrics[10] = atoi(pos);
1620 pos = os_strchr(pos, ':');
1626 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1628 os_free(bss->hs20_wan_metrics);
1629 bss->hs20_wan_metrics = wan_metrics;
1634 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
1636 os_free(wan_metrics);
1641 static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1642 char *pos, int line)
1644 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1645 &bss->hs20_oper_friendly_name_count, pos)) {
1646 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1647 "hs20_oper_friendly_name '%s'", line, pos);
1652 #endif /* CONFIG_HS20 */
1655 #ifdef CONFIG_WPS_NFC
1656 static struct wpabuf * hostapd_parse_bin(const char *buf)
1661 len = os_strlen(buf);
1666 ret = wpabuf_alloc(len);
1670 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1677 #endif /* CONFIG_WPS_NFC */
1680 static int hostapd_config_fill(struct hostapd_config *conf,
1681 struct hostapd_bss_config *bss,
1682 char *buf, char *pos, int line)
1687 if (os_strcmp(buf, "interface") == 0) {
1688 os_strlcpy(conf->bss[0].iface, pos,
1689 sizeof(conf->bss[0].iface));
1690 } else if (os_strcmp(buf, "bridge") == 0) {
1691 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1692 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1693 os_strlcpy(bss->vlan_bridge, pos,
1694 sizeof(bss->vlan_bridge));
1695 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1696 os_strlcpy(bss->wds_bridge, pos,
1697 sizeof(bss->wds_bridge));
1698 } else if (os_strcmp(buf, "driver") == 0) {
1700 /* clear to get error below if setting is invalid */
1701 conf->driver = NULL;
1702 for (j = 0; wpa_drivers[j]; j++) {
1703 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
1705 conf->driver = wpa_drivers[j];
1709 if (conf->driver == NULL) {
1710 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1711 "unknown driver '%s'", line, pos);
1714 } else if (os_strcmp(buf, "debug") == 0) {
1715 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1716 "configuration variable is not used "
1718 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1719 bss->logger_syslog_level = atoi(pos);
1720 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1721 bss->logger_stdout_level = atoi(pos);
1722 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1723 bss->logger_syslog = atoi(pos);
1724 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1725 bss->logger_stdout = atoi(pos);
1726 } else if (os_strcmp(buf, "dump_file") == 0) {
1727 bss->dump_log_name = os_strdup(pos);
1728 } else if (os_strcmp(buf, "ssid") == 0) {
1729 bss->ssid.ssid_len = os_strlen(pos);
1730 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1731 bss->ssid.ssid_len < 1) {
1732 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1736 os_memcpy(bss->ssid.ssid, pos,
1737 bss->ssid.ssid_len);
1738 bss->ssid.ssid_set = 1;
1740 } else if (os_strcmp(buf, "ssid2") == 0) {
1742 char *str = wpa_config_parse_string(pos, &slen);
1743 if (str == NULL || slen < 1 ||
1744 slen > HOSTAPD_MAX_SSID_LEN) {
1745 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1749 os_memcpy(bss->ssid.ssid, str, slen);
1750 bss->ssid.ssid_len = slen;
1751 bss->ssid.ssid_set = 1;
1754 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1755 bss->ssid.utf8_ssid = atoi(pos) > 0;
1756 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1757 bss->macaddr_acl = atoi(pos);
1758 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1759 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1760 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1761 wpa_printf(MSG_ERROR, "Line %d: unknown "
1763 line, bss->macaddr_acl);
1765 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1766 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1767 &bss->num_accept_mac))
1769 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1770 "read accept_mac_file '%s'",
1774 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1775 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1776 &bss->num_deny_mac)) {
1777 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1778 "read deny_mac_file '%s'",
1782 } else if (os_strcmp(buf, "wds_sta") == 0) {
1783 bss->wds_sta = atoi(pos);
1784 } else if (os_strcmp(buf, "ap_isolate") == 0) {
1785 bss->isolate = atoi(pos);
1786 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1787 bss->ap_max_inactivity = atoi(pos);
1788 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
1789 bss->skip_inactivity_poll = atoi(pos);
1790 } else if (os_strcmp(buf, "country_code") == 0) {
1791 os_memcpy(conf->country, pos, 2);
1792 /* FIX: make this configurable */
1793 conf->country[2] = ' ';
1794 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1795 conf->ieee80211d = atoi(pos);
1796 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1797 conf->ieee80211h = atoi(pos);
1798 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1799 bss->ieee802_1x = atoi(pos);
1800 } else if (os_strcmp(buf, "eapol_version") == 0) {
1801 bss->eapol_version = atoi(pos);
1802 if (bss->eapol_version < 1 ||
1803 bss->eapol_version > 2) {
1804 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1805 "version (%d): '%s'.",
1806 line, bss->eapol_version, pos);
1809 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1810 bss->eapol_version);
1812 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1813 bss->eap_server = atoi(pos);
1814 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1815 "eap_authenticator used; this has been "
1816 "renamed to eap_server", line);
1817 } else if (os_strcmp(buf, "eap_server") == 0) {
1818 bss->eap_server = atoi(pos);
1819 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1820 if (hostapd_config_read_eap_user(pos, bss))
1822 } else if (os_strcmp(buf, "ca_cert") == 0) {
1823 os_free(bss->ca_cert);
1824 bss->ca_cert = os_strdup(pos);
1825 } else if (os_strcmp(buf, "server_cert") == 0) {
1826 os_free(bss->server_cert);
1827 bss->server_cert = os_strdup(pos);
1828 } else if (os_strcmp(buf, "private_key") == 0) {
1829 os_free(bss->private_key);
1830 bss->private_key = os_strdup(pos);
1831 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1832 os_free(bss->private_key_passwd);
1833 bss->private_key_passwd = os_strdup(pos);
1834 } else if (os_strcmp(buf, "check_crl") == 0) {
1835 bss->check_crl = atoi(pos);
1836 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
1837 os_free(bss->ocsp_stapling_response);
1838 bss->ocsp_stapling_response = os_strdup(pos);
1839 } else if (os_strcmp(buf, "dh_file") == 0) {
1840 os_free(bss->dh_file);
1841 bss->dh_file = os_strdup(pos);
1842 } else if (os_strcmp(buf, "fragment_size") == 0) {
1843 bss->fragment_size = atoi(pos);
1844 #ifdef EAP_SERVER_FAST
1845 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1846 os_free(bss->pac_opaque_encr_key);
1847 bss->pac_opaque_encr_key = os_malloc(16);
1848 if (bss->pac_opaque_encr_key == NULL) {
1849 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1850 "pac_opaque_encr_key", line);
1852 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1854 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1855 "pac_opaque_encr_key", line);
1858 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1859 size_t idlen = os_strlen(pos);
1861 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1862 "eap_fast_a_id", line);
1865 os_free(bss->eap_fast_a_id);
1866 bss->eap_fast_a_id = os_malloc(idlen / 2);
1867 if (bss->eap_fast_a_id == NULL ||
1868 hexstr2bin(pos, bss->eap_fast_a_id,
1870 wpa_printf(MSG_ERROR, "Line %d: "
1872 "eap_fast_a_id", line);
1875 bss->eap_fast_a_id_len = idlen / 2;
1877 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1878 os_free(bss->eap_fast_a_id_info);
1879 bss->eap_fast_a_id_info = os_strdup(pos);
1880 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1881 bss->eap_fast_prov = atoi(pos);
1882 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1883 bss->pac_key_lifetime = atoi(pos);
1884 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1885 bss->pac_key_refresh_time = atoi(pos);
1886 #endif /* EAP_SERVER_FAST */
1887 #ifdef EAP_SERVER_SIM
1888 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1889 os_free(bss->eap_sim_db);
1890 bss->eap_sim_db = os_strdup(pos);
1891 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1892 bss->eap_sim_aka_result_ind = atoi(pos);
1893 #endif /* EAP_SERVER_SIM */
1894 #ifdef EAP_SERVER_TNC
1895 } else if (os_strcmp(buf, "tnc") == 0) {
1896 bss->tnc = atoi(pos);
1897 #endif /* EAP_SERVER_TNC */
1898 #ifdef EAP_SERVER_PWD
1899 } else if (os_strcmp(buf, "pwd_group") == 0) {
1900 bss->pwd_group = atoi(pos);
1901 #endif /* EAP_SERVER_PWD */
1902 #endif /* EAP_SERVER */
1903 } else if (os_strcmp(buf, "eap_message") == 0) {
1905 bss->eap_req_id_text = os_strdup(pos);
1906 if (bss->eap_req_id_text == NULL) {
1907 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1908 "allocate memory for "
1909 "eap_req_id_text", line);
1913 bss->eap_req_id_text_len =
1914 os_strlen(bss->eap_req_id_text);
1915 term = os_strstr(bss->eap_req_id_text, "\\0");
1918 os_memmove(term, term + 1,
1919 bss->eap_req_id_text_len -
1920 (term - bss->eap_req_id_text) - 1);
1921 bss->eap_req_id_text_len--;
1923 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1924 bss->default_wep_key_len = atoi(pos);
1925 if (bss->default_wep_key_len > 13) {
1926 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1927 "key len %lu (= %lu bits)", line,
1929 bss->default_wep_key_len,
1931 bss->default_wep_key_len * 8);
1934 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1935 bss->individual_wep_key_len = atoi(pos);
1936 if (bss->individual_wep_key_len < 0 ||
1937 bss->individual_wep_key_len > 13) {
1938 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1939 "key len %d (= %d bits)", line,
1940 bss->individual_wep_key_len,
1941 bss->individual_wep_key_len * 8);
1944 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1945 bss->wep_rekeying_period = atoi(pos);
1946 if (bss->wep_rekeying_period < 0) {
1947 wpa_printf(MSG_ERROR, "Line %d: invalid "
1949 line, bss->wep_rekeying_period);
1952 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1953 bss->eap_reauth_period = atoi(pos);
1954 if (bss->eap_reauth_period < 0) {
1955 wpa_printf(MSG_ERROR, "Line %d: invalid "
1957 line, bss->eap_reauth_period);
1960 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1961 bss->eapol_key_index_workaround = atoi(pos);
1963 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1964 bss->ieee802_11f = 1;
1965 os_strlcpy(bss->iapp_iface, pos,
1966 sizeof(bss->iapp_iface));
1967 #endif /* CONFIG_IAPP */
1968 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1969 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1970 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1971 "address '%s'", line, pos);
1974 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1975 bss->nas_identifier = os_strdup(pos);
1976 #ifndef CONFIG_NO_RADIUS
1977 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
1978 if (hostapd_config_read_radius_addr(
1979 &bss->radius->auth_servers,
1980 &bss->radius->num_auth_servers, pos, 1812,
1981 &bss->radius->auth_server)) {
1982 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1983 "address '%s'", line, pos);
1986 } else if (bss->radius->auth_server &&
1987 os_strcmp(buf, "auth_server_port") == 0) {
1988 bss->radius->auth_server->port = atoi(pos);
1989 } else if (bss->radius->auth_server &&
1990 os_strcmp(buf, "auth_server_shared_secret") == 0) {
1991 int len = os_strlen(pos);
1993 /* RFC 2865, Ch. 3 */
1994 wpa_printf(MSG_ERROR, "Line %d: empty shared "
1995 "secret is not allowed.", line);
1998 bss->radius->auth_server->shared_secret =
1999 (u8 *) os_strdup(pos);
2000 bss->radius->auth_server->shared_secret_len = len;
2001 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2002 if (hostapd_config_read_radius_addr(
2003 &bss->radius->acct_servers,
2004 &bss->radius->num_acct_servers, pos, 1813,
2005 &bss->radius->acct_server)) {
2006 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2007 "address '%s'", line, pos);
2010 } else if (bss->radius->acct_server &&
2011 os_strcmp(buf, "acct_server_port") == 0) {
2012 bss->radius->acct_server->port = atoi(pos);
2013 } else if (bss->radius->acct_server &&
2014 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2015 int len = os_strlen(pos);
2017 /* RFC 2865, Ch. 3 */
2018 wpa_printf(MSG_ERROR, "Line %d: empty shared "
2019 "secret is not allowed.", line);
2022 bss->radius->acct_server->shared_secret =
2023 (u8 *) os_strdup(pos);
2024 bss->radius->acct_server->shared_secret_len = len;
2025 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
2027 bss->radius->retry_primary_interval = atoi(pos);
2028 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
2030 bss->acct_interim_interval = atoi(pos);
2031 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2032 bss->radius_request_cui = atoi(pos);
2033 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2034 struct hostapd_radius_attr *attr, *a;
2035 attr = hostapd_parse_radius_attr(pos);
2037 wpa_printf(MSG_ERROR, "Line %d: invalid "
2038 "radius_auth_req_attr", line);
2040 } else if (bss->radius_auth_req_attr == NULL) {
2041 bss->radius_auth_req_attr = attr;
2043 a = bss->radius_auth_req_attr;
2048 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2049 struct hostapd_radius_attr *attr, *a;
2050 attr = hostapd_parse_radius_attr(pos);
2052 wpa_printf(MSG_ERROR, "Line %d: invalid "
2053 "radius_acct_req_attr", line);
2055 } else if (bss->radius_acct_req_attr == NULL) {
2056 bss->radius_acct_req_attr = attr;
2058 a = bss->radius_acct_req_attr;
2063 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2064 bss->radius_das_port = atoi(pos);
2065 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2066 if (hostapd_parse_das_client(bss, pos) < 0) {
2067 wpa_printf(MSG_ERROR, "Line %d: invalid "
2068 "DAS client", line);
2071 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2072 bss->radius_das_time_window = atoi(pos);
2073 } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
2075 bss->radius_das_require_event_timestamp = atoi(pos);
2076 #endif /* CONFIG_NO_RADIUS */
2077 } else if (os_strcmp(buf, "auth_algs") == 0) {
2078 bss->auth_algs = atoi(pos);
2079 if (bss->auth_algs == 0) {
2080 wpa_printf(MSG_ERROR, "Line %d: no "
2081 "authentication algorithms allowed",
2085 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2086 bss->max_num_sta = atoi(pos);
2087 if (bss->max_num_sta < 0 ||
2088 bss->max_num_sta > MAX_STA_COUNT) {
2089 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2090 "max_num_sta=%d; allowed range "
2091 "0..%d", line, bss->max_num_sta,
2095 } else if (os_strcmp(buf, "wpa") == 0) {
2096 bss->wpa = atoi(pos);
2097 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2098 bss->wpa_group_rekey = atoi(pos);
2099 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2100 bss->wpa_strict_rekey = atoi(pos);
2101 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2102 bss->wpa_gmk_rekey = atoi(pos);
2103 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2104 bss->wpa_ptk_rekey = atoi(pos);
2105 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2106 int len = os_strlen(pos);
2107 if (len < 8 || len > 63) {
2108 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
2109 "passphrase length %d (expected "
2110 "8..63)", line, len);
2113 os_free(bss->ssid.wpa_passphrase);
2114 bss->ssid.wpa_passphrase = os_strdup(pos);
2115 os_free(bss->ssid.wpa_psk);
2116 bss->ssid.wpa_psk = NULL;
2118 } else if (os_strcmp(buf, "wpa_psk") == 0) {
2119 os_free(bss->ssid.wpa_psk);
2121 os_zalloc(sizeof(struct hostapd_wpa_psk));
2122 if (bss->ssid.wpa_psk == NULL)
2124 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
2126 pos[PMK_LEN * 2] != '\0') {
2127 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
2128 "'%s'.", line, pos);
2131 bss->ssid.wpa_psk->group = 1;
2132 os_free(bss->ssid.wpa_passphrase);
2133 bss->ssid.wpa_passphrase = NULL;
2135 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2136 os_free(bss->ssid.wpa_psk_file);
2137 bss->ssid.wpa_psk_file = os_strdup(pos);
2138 if (!bss->ssid.wpa_psk_file) {
2139 wpa_printf(MSG_ERROR, "Line %d: allocation "
2143 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2145 hostapd_config_parse_key_mgmt(line, pos);
2146 if (bss->wpa_key_mgmt == -1)
2148 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2149 bss->wpa_psk_radius = atoi(pos);
2150 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2151 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2152 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2153 wpa_printf(MSG_ERROR, "Line %d: unknown "
2154 "wpa_psk_radius %d",
2155 line, bss->wpa_psk_radius);
2158 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2160 hostapd_config_parse_cipher(line, pos);
2161 if (bss->wpa_pairwise == -1 ||
2162 bss->wpa_pairwise == 0)
2164 else if (bss->wpa_pairwise &
2165 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2166 WPA_CIPHER_WEP104)) {
2167 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2168 "pairwise cipher suite '%s'",
2169 bss->wpa_pairwise, pos);
2172 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2174 hostapd_config_parse_cipher(line, pos);
2175 if (bss->rsn_pairwise == -1 ||
2176 bss->rsn_pairwise == 0)
2178 else if (bss->rsn_pairwise &
2179 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2180 WPA_CIPHER_WEP104)) {
2181 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2182 "pairwise cipher suite '%s'",
2183 bss->rsn_pairwise, pos);
2186 #ifdef CONFIG_RSN_PREAUTH
2187 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2188 bss->rsn_preauth = atoi(pos);
2189 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
2190 bss->rsn_preauth_interfaces = os_strdup(pos);
2191 #endif /* CONFIG_RSN_PREAUTH */
2192 #ifdef CONFIG_PEERKEY
2193 } else if (os_strcmp(buf, "peerkey") == 0) {
2194 bss->peerkey = atoi(pos);
2195 #endif /* CONFIG_PEERKEY */
2196 #ifdef CONFIG_IEEE80211R
2197 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2198 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2199 hexstr2bin(pos, bss->mobility_domain,
2200 MOBILITY_DOMAIN_ID_LEN) != 0) {
2201 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2202 "mobility_domain '%s'", line, pos);
2206 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2207 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2208 hexstr2bin(pos, bss->r1_key_holder,
2209 FT_R1KH_ID_LEN) != 0) {
2210 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2211 "r1_key_holder '%s'", line, pos);
2215 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2216 bss->r0_key_lifetime = atoi(pos);
2217 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2218 bss->reassociation_deadline = atoi(pos);
2219 } else if (os_strcmp(buf, "r0kh") == 0) {
2220 if (add_r0kh(bss, pos) < 0) {
2221 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2222 "r0kh '%s'", line, pos);
2226 } else if (os_strcmp(buf, "r1kh") == 0) {
2227 if (add_r1kh(bss, pos) < 0) {
2228 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2229 "r1kh '%s'", line, pos);
2233 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2234 bss->pmk_r1_push = atoi(pos);
2235 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2236 bss->ft_over_ds = atoi(pos);
2237 #endif /* CONFIG_IEEE80211R */
2238 #ifndef CONFIG_NO_CTRL_IFACE
2239 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2240 os_free(bss->ctrl_interface);
2241 bss->ctrl_interface = os_strdup(pos);
2242 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
2243 #ifndef CONFIG_NATIVE_WINDOWS
2246 const char *group = pos;
2248 grp = getgrnam(group);
2250 bss->ctrl_interface_gid = grp->gr_gid;
2251 bss->ctrl_interface_gid_set = 1;
2252 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
2253 " (from group name '%s')",
2254 bss->ctrl_interface_gid, group);
2258 /* Group name not found - try to parse this as gid */
2259 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2260 if (*group == '\0' || *endp != '\0') {
2261 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
2262 "'%s'", line, group);
2266 bss->ctrl_interface_gid_set = 1;
2267 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2268 bss->ctrl_interface_gid);
2269 #endif /* CONFIG_NATIVE_WINDOWS */
2270 #endif /* CONFIG_NO_CTRL_IFACE */
2271 #ifdef RADIUS_SERVER
2272 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2273 os_free(bss->radius_server_clients);
2274 bss->radius_server_clients = os_strdup(pos);
2275 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2276 bss->radius_server_auth_port = atoi(pos);
2277 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2278 bss->radius_server_ipv6 = atoi(pos);
2279 #endif /* RADIUS_SERVER */
2280 } else if (os_strcmp(buf, "test_socket") == 0) {
2281 os_free(bss->test_socket);
2282 bss->test_socket = os_strdup(pos);
2283 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2284 bss->use_pae_group_addr = atoi(pos);
2285 } else if (os_strcmp(buf, "hw_mode") == 0) {
2286 if (os_strcmp(pos, "a") == 0)
2287 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2288 else if (os_strcmp(pos, "b") == 0)
2289 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2290 else if (os_strcmp(pos, "g") == 0)
2291 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2292 else if (os_strcmp(pos, "ad") == 0)
2293 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
2295 wpa_printf(MSG_ERROR, "Line %d: unknown "
2296 "hw_mode '%s'", line, pos);
2299 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2300 if (os_strcmp(pos, "a") == 0)
2301 bss->wps_rf_bands = WPS_RF_50GHZ;
2302 else if (os_strcmp(pos, "g") == 0 ||
2303 os_strcmp(pos, "b") == 0)
2304 bss->wps_rf_bands = WPS_RF_24GHZ;
2305 else if (os_strcmp(pos, "ag") == 0 ||
2306 os_strcmp(pos, "ga") == 0)
2308 WPS_RF_24GHZ | WPS_RF_50GHZ;
2310 wpa_printf(MSG_ERROR, "Line %d: unknown "
2311 "wps_rf_band '%s'", line, pos);
2314 } else if (os_strcmp(buf, "channel") == 0) {
2315 conf->channel = atoi(pos);
2316 } else if (os_strcmp(buf, "beacon_int") == 0) {
2317 int val = atoi(pos);
2318 /* MIB defines range as 1..65535, but very small values
2319 * cause problems with the current implementation.
2320 * Since it is unlikely that this small numbers are
2321 * useful in real life scenarios, do not allow beacon
2322 * period to be set below 15 TU. */
2323 if (val < 15 || val > 65535) {
2324 wpa_printf(MSG_ERROR, "Line %d: invalid "
2325 "beacon_int %d (expected "
2326 "15..65535)", line, val);
2329 conf->beacon_int = val;
2330 } else if (os_strcmp(buf, "dtim_period") == 0) {
2331 bss->dtim_period = atoi(pos);
2332 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2333 wpa_printf(MSG_ERROR, "Line %d: invalid "
2335 line, bss->dtim_period);
2338 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2339 conf->rts_threshold = atoi(pos);
2340 if (conf->rts_threshold < 0 ||
2341 conf->rts_threshold > 2347) {
2342 wpa_printf(MSG_ERROR, "Line %d: invalid "
2344 line, conf->rts_threshold);
2347 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2348 conf->fragm_threshold = atoi(pos);
2349 if (conf->fragm_threshold < 256 ||
2350 conf->fragm_threshold > 2346) {
2351 wpa_printf(MSG_ERROR, "Line %d: invalid "
2352 "fragm_threshold %d",
2353 line, conf->fragm_threshold);
2356 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2357 int val = atoi(pos);
2358 if (val != 0 && val != 1) {
2359 wpa_printf(MSG_ERROR, "Line %d: invalid "
2360 "send_probe_response %d (expected "
2361 "0 or 1)", line, val);
2363 conf->send_probe_response = val;
2364 } else if (os_strcmp(buf, "supported_rates") == 0) {
2365 if (hostapd_parse_intlist(&conf->supported_rates, pos))
2367 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2371 } else if (os_strcmp(buf, "basic_rates") == 0) {
2372 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
2373 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2377 } else if (os_strcmp(buf, "preamble") == 0) {
2379 conf->preamble = SHORT_PREAMBLE;
2381 conf->preamble = LONG_PREAMBLE;
2382 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2383 bss->ignore_broadcast_ssid = atoi(pos);
2384 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2385 bss->ssid.wep.idx = atoi(pos);
2386 if (bss->ssid.wep.idx > 3) {
2387 wpa_printf(MSG_ERROR, "Invalid "
2388 "wep_default_key index %d",
2392 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2393 os_strcmp(buf, "wep_key1") == 0 ||
2394 os_strcmp(buf, "wep_key2") == 0 ||
2395 os_strcmp(buf, "wep_key3") == 0) {
2396 if (hostapd_config_read_wep(&bss->ssid.wep,
2397 buf[7] - '0', pos)) {
2398 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2399 "key '%s'", line, buf);
2402 #ifndef CONFIG_NO_VLAN
2403 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2404 bss->ssid.dynamic_vlan = atoi(pos);
2405 } else if (os_strcmp(buf, "vlan_file") == 0) {
2406 if (hostapd_config_read_vlan_file(bss, pos)) {
2407 wpa_printf(MSG_ERROR, "Line %d: failed to "
2408 "read VLAN file '%s'", line, pos);
2411 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2412 bss->ssid.vlan_naming = atoi(pos);
2413 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2414 bss->ssid.vlan_naming < 0) {
2415 wpa_printf(MSG_ERROR, "Line %d: invalid "
2416 "naming scheme %d", line,
2417 bss->ssid.vlan_naming);
2420 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2421 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2422 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2423 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2424 #endif /* CONFIG_NO_VLAN */
2425 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2426 conf->ap_table_max_size = atoi(pos);
2427 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2428 conf->ap_table_expiration_time = atoi(pos);
2429 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2430 if (hostapd_config_tx_queue(conf, buf, pos)) {
2431 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2432 "queue item", line);
2435 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2436 os_strcmp(buf, "wmm_enabled") == 0) {
2437 bss->wmm_enabled = atoi(pos);
2438 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2439 bss->wmm_uapsd = atoi(pos);
2440 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2441 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2442 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
2444 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2448 } else if (os_strcmp(buf, "bss") == 0) {
2449 if (hostapd_config_bss(conf, pos)) {
2450 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2454 } else if (os_strcmp(buf, "bssid") == 0) {
2455 if (hwaddr_aton(pos, bss->bssid)) {
2456 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2460 #ifdef CONFIG_IEEE80211W
2461 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2462 bss->ieee80211w = atoi(pos);
2463 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2464 bss->assoc_sa_query_max_timeout = atoi(pos);
2465 if (bss->assoc_sa_query_max_timeout == 0) {
2466 wpa_printf(MSG_ERROR, "Line %d: invalid "
2467 "assoc_sa_query_max_timeout", line);
2470 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2472 bss->assoc_sa_query_retry_timeout = atoi(pos);
2473 if (bss->assoc_sa_query_retry_timeout == 0) {
2474 wpa_printf(MSG_ERROR, "Line %d: invalid "
2475 "assoc_sa_query_retry_timeout",
2479 #endif /* CONFIG_IEEE80211W */
2480 #ifdef CONFIG_IEEE80211N
2481 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2482 conf->ieee80211n = atoi(pos);
2483 } else if (os_strcmp(buf, "ht_capab") == 0) {
2484 if (hostapd_config_ht_capab(conf, pos) < 0) {
2485 wpa_printf(MSG_ERROR, "Line %d: invalid "
2489 } else if (os_strcmp(buf, "require_ht") == 0) {
2490 conf->require_ht = atoi(pos);
2491 #endif /* CONFIG_IEEE80211N */
2492 #ifdef CONFIG_IEEE80211AC
2493 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2494 conf->ieee80211ac = atoi(pos);
2495 } else if (os_strcmp(buf, "vht_capab") == 0) {
2496 if (hostapd_config_vht_capab(conf, pos) < 0) {
2497 wpa_printf(MSG_ERROR, "Line %d: invalid "
2501 } else if (os_strcmp(buf, "require_vht") == 0) {
2502 conf->require_vht = atoi(pos);
2503 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2504 conf->vht_oper_chwidth = atoi(pos);
2505 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
2507 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2508 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
2510 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
2511 #endif /* CONFIG_IEEE80211AC */
2512 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2513 bss->max_listen_interval = atoi(pos);
2514 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2515 bss->disable_pmksa_caching = atoi(pos);
2516 } else if (os_strcmp(buf, "okc") == 0) {
2517 bss->okc = atoi(pos);
2519 } else if (os_strcmp(buf, "wps_state") == 0) {
2520 bss->wps_state = atoi(pos);
2521 if (bss->wps_state < 0 || bss->wps_state > 2) {
2522 wpa_printf(MSG_ERROR, "Line %d: invalid "
2526 } else if (os_strcmp(buf, "wps_independent") == 0) {
2527 bss->wps_independent = atoi(pos);
2528 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2529 bss->ap_setup_locked = atoi(pos);
2530 } else if (os_strcmp(buf, "uuid") == 0) {
2531 if (uuid_str2bin(pos, bss->uuid)) {
2532 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2536 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2537 os_free(bss->wps_pin_requests);
2538 bss->wps_pin_requests = os_strdup(pos);
2539 } else if (os_strcmp(buf, "device_name") == 0) {
2540 if (os_strlen(pos) > 32) {
2541 wpa_printf(MSG_ERROR, "Line %d: Too long "
2542 "device_name", line);
2545 os_free(bss->device_name);
2546 bss->device_name = os_strdup(pos);
2547 } else if (os_strcmp(buf, "manufacturer") == 0) {
2548 if (os_strlen(pos) > 64) {
2549 wpa_printf(MSG_ERROR, "Line %d: Too long "
2550 "manufacturer", line);
2553 os_free(bss->manufacturer);
2554 bss->manufacturer = os_strdup(pos);
2555 } else if (os_strcmp(buf, "model_name") == 0) {
2556 if (os_strlen(pos) > 32) {
2557 wpa_printf(MSG_ERROR, "Line %d: Too long "
2558 "model_name", line);
2561 os_free(bss->model_name);
2562 bss->model_name = os_strdup(pos);
2563 } else if (os_strcmp(buf, "model_number") == 0) {
2564 if (os_strlen(pos) > 32) {
2565 wpa_printf(MSG_ERROR, "Line %d: Too long "
2566 "model_number", line);
2569 os_free(bss->model_number);
2570 bss->model_number = os_strdup(pos);
2571 } else if (os_strcmp(buf, "serial_number") == 0) {
2572 if (os_strlen(pos) > 32) {
2573 wpa_printf(MSG_ERROR, "Line %d: Too long "
2574 "serial_number", line);
2577 os_free(bss->serial_number);
2578 bss->serial_number = os_strdup(pos);
2579 } else if (os_strcmp(buf, "device_type") == 0) {
2580 if (wps_dev_type_str2bin(pos, bss->device_type))
2582 } else if (os_strcmp(buf, "config_methods") == 0) {
2583 os_free(bss->config_methods);
2584 bss->config_methods = os_strdup(pos);
2585 } else if (os_strcmp(buf, "os_version") == 0) {
2586 if (hexstr2bin(pos, bss->os_version, 4)) {
2587 wpa_printf(MSG_ERROR, "Line %d: invalid "
2588 "os_version", line);
2591 } else if (os_strcmp(buf, "ap_pin") == 0) {
2592 os_free(bss->ap_pin);
2593 bss->ap_pin = os_strdup(pos);
2594 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2595 bss->skip_cred_build = atoi(pos);
2596 } else if (os_strcmp(buf, "extra_cred") == 0) {
2597 os_free(bss->extra_cred);
2599 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2600 if (bss->extra_cred == NULL) {
2601 wpa_printf(MSG_ERROR, "Line %d: could not "
2602 "read Credentials from '%s'",
2606 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2607 bss->wps_cred_processing = atoi(pos);
2608 } else if (os_strcmp(buf, "ap_settings") == 0) {
2609 os_free(bss->ap_settings);
2611 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2612 if (bss->ap_settings == NULL) {
2613 wpa_printf(MSG_ERROR, "Line %d: could not "
2614 "read AP Settings from '%s'",
2618 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2619 bss->upnp_iface = os_strdup(pos);
2620 } else if (os_strcmp(buf, "friendly_name") == 0) {
2621 os_free(bss->friendly_name);
2622 bss->friendly_name = os_strdup(pos);
2623 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2624 os_free(bss->manufacturer_url);
2625 bss->manufacturer_url = os_strdup(pos);
2626 } else if (os_strcmp(buf, "model_description") == 0) {
2627 os_free(bss->model_description);
2628 bss->model_description = os_strdup(pos);
2629 } else if (os_strcmp(buf, "model_url") == 0) {
2630 os_free(bss->model_url);
2631 bss->model_url = os_strdup(pos);
2632 } else if (os_strcmp(buf, "upc") == 0) {
2634 bss->upc = os_strdup(pos);
2635 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2636 bss->pbc_in_m1 = atoi(pos);
2637 #ifdef CONFIG_WPS_NFC
2638 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2639 bss->wps_nfc_dev_pw_id = atoi(pos);
2640 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2641 bss->wps_nfc_dev_pw_id > 0xffff) {
2642 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2643 "wps_nfc_dev_pw_id value", line);
2646 bss->wps_nfc_pw_from_config = 1;
2647 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2648 wpabuf_free(bss->wps_nfc_dh_pubkey);
2649 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2650 bss->wps_nfc_pw_from_config = 1;
2651 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2652 wpabuf_free(bss->wps_nfc_dh_privkey);
2653 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2654 bss->wps_nfc_pw_from_config = 1;
2655 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2656 wpabuf_free(bss->wps_nfc_dev_pw);
2657 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2658 bss->wps_nfc_pw_from_config = 1;
2659 #endif /* CONFIG_WPS_NFC */
2660 #endif /* CONFIG_WPS */
2661 #ifdef CONFIG_P2P_MANAGER
2662 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2663 int manage = atoi(pos);
2665 bss->p2p |= P2P_MANAGE;
2667 bss->p2p &= ~P2P_MANAGE;
2668 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2670 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2672 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
2673 #endif /* CONFIG_P2P_MANAGER */
2674 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2675 bss->disassoc_low_ack = atoi(pos);
2676 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2677 int val = atoi(pos);
2679 bss->tdls |= TDLS_PROHIBIT;
2681 bss->tdls &= ~TDLS_PROHIBIT;
2682 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2683 int val = atoi(pos);
2685 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2687 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
2688 #ifdef CONFIG_RSN_TESTING
2689 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2690 extern int rsn_testing;
2691 rsn_testing = atoi(pos);
2692 #endif /* CONFIG_RSN_TESTING */
2693 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2694 bss->time_advertisement = atoi(pos);
2695 } else if (os_strcmp(buf, "time_zone") == 0) {
2696 size_t tz_len = os_strlen(pos);
2697 if (tz_len < 4 || tz_len > 255) {
2698 wpa_printf(MSG_DEBUG, "Line %d: invalid "
2703 os_free(bss->time_zone);
2704 bss->time_zone = os_strdup(pos);
2705 if (bss->time_zone == NULL)
2708 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
2709 bss->wnm_sleep_mode = atoi(pos);
2710 } else if (os_strcmp(buf, "bss_transition") == 0) {
2711 bss->bss_transition = atoi(pos);
2712 #endif /* CONFIG_WNM */
2713 #ifdef CONFIG_INTERWORKING
2714 } else if (os_strcmp(buf, "interworking") == 0) {
2715 bss->interworking = atoi(pos);
2716 } else if (os_strcmp(buf, "access_network_type") == 0) {
2717 bss->access_network_type = atoi(pos);
2718 if (bss->access_network_type < 0 ||
2719 bss->access_network_type > 15) {
2720 wpa_printf(MSG_ERROR, "Line %d: invalid "
2721 "access_network_type", line);
2724 } else if (os_strcmp(buf, "internet") == 0) {
2725 bss->internet = atoi(pos);
2726 } else if (os_strcmp(buf, "asra") == 0) {
2727 bss->asra = atoi(pos);
2728 } else if (os_strcmp(buf, "esr") == 0) {
2729 bss->esr = atoi(pos);
2730 } else if (os_strcmp(buf, "uesa") == 0) {
2731 bss->uesa = atoi(pos);
2732 } else if (os_strcmp(buf, "venue_group") == 0) {
2733 bss->venue_group = atoi(pos);
2734 bss->venue_info_set = 1;
2735 } else if (os_strcmp(buf, "venue_type") == 0) {
2736 bss->venue_type = atoi(pos);
2737 bss->venue_info_set = 1;
2738 } else if (os_strcmp(buf, "hessid") == 0) {
2739 if (hwaddr_aton(pos, bss->hessid)) {
2740 wpa_printf(MSG_ERROR, "Line %d: invalid "
2744 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
2745 if (parse_roaming_consortium(bss, pos, line) < 0)
2747 } else if (os_strcmp(buf, "venue_name") == 0) {
2748 if (parse_venue_name(bss, pos, line) < 0)
2750 } else if (os_strcmp(buf, "network_auth_type") == 0) {
2752 u16 redirect_url_len;
2753 if (hexstr2bin(pos, &auth_type, 1)) {
2754 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2755 "network_auth_type '%s'",
2760 if (auth_type == 0 || auth_type == 2)
2761 redirect_url_len = os_strlen(pos + 2);
2763 redirect_url_len = 0;
2764 os_free(bss->network_auth_type);
2765 bss->network_auth_type =
2766 os_malloc(redirect_url_len + 3 + 1);
2767 if (bss->network_auth_type == NULL) {
2771 *bss->network_auth_type = auth_type;
2772 WPA_PUT_LE16(bss->network_auth_type + 1,
2774 if (redirect_url_len)
2775 os_memcpy(bss->network_auth_type + 3,
2776 pos + 2, redirect_url_len);
2777 bss->network_auth_type_len = 3 + redirect_url_len;
2778 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
2779 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
2781 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2782 "ipaddr_type_availability '%s'",
2784 bss->ipaddr_type_configured = 0;
2788 bss->ipaddr_type_configured = 1;
2789 } else if (os_strcmp(buf, "domain_name") == 0) {
2790 int j, num_domains, domain_len, domain_list_len = 0;
2791 char *tok_start, *tok_prev;
2792 u8 *domain_list, *domain_ptr;
2794 domain_list_len = os_strlen(pos) + 1;
2795 domain_list = os_malloc(domain_list_len);
2796 if (domain_list == NULL) {
2801 domain_ptr = domain_list;
2804 while ((tok_prev = os_strchr(tok_prev, ','))) {
2809 for (j = 0; j < num_domains; j++) {
2810 tok_start = os_strchr(tok_prev, ',');
2812 domain_len = tok_start - tok_prev;
2813 *domain_ptr = domain_len;
2814 os_memcpy(domain_ptr + 1, tok_prev,
2816 domain_ptr += domain_len + 1;
2817 tok_prev = ++tok_start;
2819 domain_len = os_strlen(tok_prev);
2820 *domain_ptr = domain_len;
2821 os_memcpy(domain_ptr + 1, tok_prev,
2823 domain_ptr += domain_len + 1;
2827 os_free(bss->domain_name);
2828 bss->domain_name = domain_list;
2829 bss->domain_name_len = domain_list_len;
2830 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
2831 if (parse_3gpp_cell_net(bss, pos, line) < 0)
2833 } else if (os_strcmp(buf, "nai_realm") == 0) {
2834 if (parse_nai_realm(bss, pos, line) < 0)
2836 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
2837 bss->gas_frag_limit = atoi(pos);
2838 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
2839 bss->gas_comeback_delay = atoi(pos);
2840 #endif /* CONFIG_INTERWORKING */
2841 #ifdef CONFIG_RADIUS_TEST
2842 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
2843 os_free(bss->dump_msk_file);
2844 bss->dump_msk_file = os_strdup(pos);
2845 #endif /* CONFIG_RADIUS_TEST */
2847 } else if (os_strcmp(buf, "hs20") == 0) {
2848 bss->hs20 = atoi(pos);
2849 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
2850 bss->disable_dgaf = atoi(pos);
2851 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
2852 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
2854 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
2855 if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
2859 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
2860 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
2864 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
2866 size_t oper_class_len;
2867 oper_class_len = os_strlen(pos);
2868 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
2869 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2870 "hs20_operating_class '%s'",
2875 oper_class_len /= 2;
2876 oper_class = os_malloc(oper_class_len);
2877 if (oper_class == NULL) {
2881 if (hexstr2bin(pos, oper_class, oper_class_len)) {
2882 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2883 "hs20_operating_class '%s'",
2885 os_free(oper_class);
2889 os_free(bss->hs20_operating_class);
2890 bss->hs20_operating_class = oper_class;
2891 bss->hs20_operating_class_len = oper_class_len;
2892 #endif /* CONFIG_HS20 */
2893 #ifdef CONFIG_TESTING_OPTIONS
2894 #define PARSE_TEST_PROBABILITY(_val) \
2895 } else if (os_strcmp(buf, #_val) == 0) { \
2898 conf->_val = strtod(pos, &end); \
2899 if (*end || conf->_val < 0.0d || \
2900 conf->_val > 1.0d) { \
2901 wpa_printf(MSG_ERROR, \
2902 "Line %d: Invalid value '%s'", \
2907 PARSE_TEST_PROBABILITY(ignore_probe_probability)
2908 PARSE_TEST_PROBABILITY(ignore_auth_probability)
2909 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
2910 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
2911 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
2912 #endif /* CONFIG_TESTING_OPTIONS */
2913 } else if (os_strcmp(buf, "vendor_elements") == 0) {
2914 struct wpabuf *elems;
2915 size_t len = os_strlen(pos);
2917 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2918 "vendor_elements '%s'", line, pos);
2923 wpabuf_free(bss->vendor_elements);
2924 bss->vendor_elements = NULL;
2928 elems = wpabuf_alloc(len);
2932 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
2934 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2935 "vendor_elements '%s'", line, pos);
2939 wpabuf_free(bss->vendor_elements);
2940 bss->vendor_elements = elems;
2941 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
2942 bss->sae_anti_clogging_threshold = atoi(pos);
2943 } else if (os_strcmp(buf, "sae_groups") == 0) {
2944 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
2945 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2946 "sae_groups value '%s'", line, pos);
2950 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2951 "item '%s'", line, buf);
2960 static void hostapd_set_security_params(struct hostapd_bss_config *bss)
2962 if (bss->individual_wep_key_len == 0) {
2963 /* individual keys are not use; can use key idx0 for
2965 bss->broadcast_key_idx_min = 0;
2968 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
2969 bss->rsn_pairwise = bss->wpa_pairwise;
2970 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
2973 bss->radius->auth_server = bss->radius->auth_servers;
2974 bss->radius->acct_server = bss->radius->acct_servers;
2976 if (bss->wpa && bss->ieee802_1x) {
2977 bss->ssid.security_policy = SECURITY_WPA;
2978 } else if (bss->wpa) {
2979 bss->ssid.security_policy = SECURITY_WPA_PSK;
2980 } else if (bss->ieee802_1x) {
2981 int cipher = WPA_CIPHER_NONE;
2982 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2983 bss->ssid.wep.default_len = bss->default_wep_key_len;
2984 if (bss->default_wep_key_len)
2985 cipher = bss->default_wep_key_len >= 13 ?
2986 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
2987 bss->wpa_group = cipher;
2988 bss->wpa_pairwise = cipher;
2989 bss->rsn_pairwise = cipher;
2990 } else if (bss->ssid.wep.keys_set) {
2991 int cipher = WPA_CIPHER_WEP40;
2992 if (bss->ssid.wep.len[0] >= 13)
2993 cipher = WPA_CIPHER_WEP104;
2994 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2995 bss->wpa_group = cipher;
2996 bss->wpa_pairwise = cipher;
2997 bss->rsn_pairwise = cipher;
2999 bss->ssid.security_policy = SECURITY_PLAINTEXT;
3000 bss->wpa_group = WPA_CIPHER_NONE;
3001 bss->wpa_pairwise = WPA_CIPHER_NONE;
3002 bss->rsn_pairwise = WPA_CIPHER_NONE;
3008 * hostapd_config_read - Read and parse a configuration file
3009 * @fname: Configuration file name (including path, if needed)
3010 * Returns: Allocated configuration data structure
3012 struct hostapd_config * hostapd_config_read(const char *fname)
3014 struct hostapd_config *conf;
3015 struct hostapd_bss_config *bss;
3017 char buf[512], *pos;
3022 f = fopen(fname, "r");
3024 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3025 "for reading.", fname);
3029 conf = hostapd_config_defaults();
3035 /* set default driver based on configuration */
3036 conf->driver = wpa_drivers[0];
3037 if (conf->driver == NULL) {
3038 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3039 hostapd_config_free(conf);
3044 bss = conf->last_bss = conf->bss;
3046 while (fgets(buf, sizeof(buf), f)) {
3047 bss = conf->last_bss;
3053 while (*pos != '\0') {
3063 pos = os_strchr(buf, '=');
3065 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3072 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3077 for (i = 0; i < conf->num_bss; i++)
3078 hostapd_set_security_params(&conf->bss[i]);
3080 if (hostapd_config_check(conf))
3083 #ifndef WPA_IGNORE_CONFIG_ERRORS
3085 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3086 "'%s'", errors, fname);
3087 hostapd_config_free(conf);
3090 #endif /* WPA_IGNORE_CONFIG_ERRORS */
3096 int hostapd_set_iface(struct hostapd_config *conf,
3097 struct hostapd_bss_config *bss, char *field, char *value)
3102 errors = hostapd_config_fill(conf, bss, field, value, 0);
3104 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3105 "to value '%s'", field, value);
3109 for (i = 0; i < conf->num_bss; i++)
3110 hostapd_set_security_params(&conf->bss[i]);
3112 if (hostapd_config_check(conf)) {
3113 wpa_printf(MSG_ERROR, "Configuration check failed");