2 * hostapd / Configuration file parser
3 * Copyright (c) 2003-2015, 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 #ifndef CONFIG_NO_RADIUS
27 static struct hostapd_radius_attr *
28 hostapd_parse_radius_attr(const char *value);
29 #endif /* EAP_SERVER */
30 #endif /* CONFIG_NO_RADIUS */
33 #ifndef CONFIG_NO_VLAN
34 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
38 char buf[128], *pos, *pos2;
39 int line = 0, vlan_id;
40 struct hostapd_vlan *vlan;
42 f = fopen(fname, "r");
44 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
48 while (fgets(buf, sizeof(buf), f)) {
54 while (*pos != '\0') {
65 vlan_id = VLAN_ID_WILDCARD;
68 vlan_id = strtol(buf, &pos, 10);
69 if (buf == pos || vlan_id < 1 ||
70 vlan_id > MAX_VLAN_ID) {
71 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
72 "line %d in '%s'", line, fname);
78 while (*pos == ' ' || *pos == '\t')
81 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
84 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
85 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
86 "in '%s'", line, fname);
91 vlan = os_zalloc(sizeof(*vlan));
93 wpa_printf(MSG_ERROR, "Out of memory while reading "
94 "VLAN interfaces from '%s'", fname);
99 vlan->vlan_id = vlan_id;
100 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
101 vlan->next = bss->vlan;
109 #endif /* CONFIG_NO_VLAN */
112 static int hostapd_acl_comp(const void *a, const void *b)
114 const struct mac_acl_entry *aa = a;
115 const struct mac_acl_entry *bb = b;
116 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
120 static int hostapd_config_read_maclist(const char *fname,
121 struct mac_acl_entry **acl, int *num)
127 struct mac_acl_entry *newacl;
133 f = fopen(fname, "r");
135 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
139 while (fgets(buf, sizeof(buf), f)) {
147 while (*pos != '\0') {
162 if (hwaddr_aton(pos, addr)) {
163 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
164 "line %d in '%s'", pos, line, fname);
172 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
174 os_remove_in_array(*acl, *num,
184 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
186 while (*pos == ' ' || *pos == '\t')
191 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
192 if (newacl == NULL) {
193 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
199 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
200 (*acl)[*num].vlan_id = vlan_id;
206 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
213 static int hostapd_config_read_eap_user(const char *fname,
214 struct hostapd_bss_config *conf)
217 char buf[512], *pos, *start, *pos2;
218 int line = 0, ret = 0, num_methods;
219 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
224 if (os_strncmp(fname, "sqlite:", 7) == 0) {
225 os_free(conf->eap_user_sqlite);
226 conf->eap_user_sqlite = os_strdup(fname + 7);
230 f = fopen(fname, "r");
232 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
236 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
237 while (fgets(buf, sizeof(buf), f)) {
243 while (*pos != '\0') {
253 #ifndef CONFIG_NO_RADIUS
254 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
255 struct hostapd_radius_attr *attr, *a;
256 attr = hostapd_parse_radius_attr(buf + 19);
258 wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
260 user = NULL; /* already in the BSS list */
263 if (user->accept_attr == NULL) {
264 user->accept_attr = attr;
266 a = user->accept_attr;
273 #endif /* CONFIG_NO_RADIUS */
277 if (buf[0] != '"' && buf[0] != '*') {
278 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
279 "start) on line %d in '%s'", line, fname);
283 user = os_zalloc(sizeof(*user));
285 wpa_printf(MSG_ERROR, "EAP user allocation failed");
288 user->force_version = -1;
295 while (*pos != '"' && *pos != '\0')
298 wpa_printf(MSG_ERROR, "Invalid EAP identity "
299 "(no \" in end) on line %d in '%s'",
304 user->identity = os_malloc(pos - start);
305 if (user->identity == NULL) {
306 wpa_printf(MSG_ERROR, "Failed to allocate "
307 "memory for EAP identity");
310 os_memcpy(user->identity, start, pos - start);
311 user->identity_len = pos - start;
313 if (pos[0] == '"' && pos[1] == '*') {
314 user->wildcard_prefix = 1;
319 while (*pos == ' ' || *pos == '\t')
323 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
324 "'%s'", line, fname);
329 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
339 char *pos3 = os_strchr(start, ',');
343 user->methods[num_methods].method =
346 &user->methods[num_methods].vendor);
347 if (user->methods[num_methods].vendor ==
349 user->methods[num_methods].method == EAP_TYPE_NONE)
351 if (os_strcmp(start, "TTLS-PAP") == 0) {
352 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
355 if (os_strcmp(start, "TTLS-CHAP") == 0) {
356 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
359 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
361 EAP_TTLS_AUTH_MSCHAP;
364 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
366 EAP_TTLS_AUTH_MSCHAPV2;
369 if (os_strcmp(start, "MACACL") == 0) {
373 wpa_printf(MSG_ERROR, "Unsupported EAP type "
374 "'%s' on line %d in '%s'",
380 if (num_methods >= EAP_MAX_METHODS)
387 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
388 wpa_printf(MSG_ERROR, "No EAP types configured on "
389 "line %d in '%s'", line, fname);
396 while (*pos == ' ' || *pos == '\t')
401 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
402 user->force_version = 0;
406 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
407 user->force_version = 1;
411 if (os_strncmp(pos, "[2]", 3) == 0) {
419 while (*pos != '"' && *pos != '\0')
422 wpa_printf(MSG_ERROR, "Invalid EAP password "
423 "(no \" in end) on line %d in '%s'",
428 user->password = os_malloc(pos - start);
429 if (user->password == NULL) {
430 wpa_printf(MSG_ERROR, "Failed to allocate "
431 "memory for EAP password");
434 os_memcpy(user->password, start, pos - start);
435 user->password_len = pos - start;
438 } else if (os_strncmp(pos, "hash:", 5) == 0) {
441 while (*pos2 != '\0' && *pos2 != ' ' &&
442 *pos2 != '\t' && *pos2 != '#')
444 if (pos2 - pos != 32) {
445 wpa_printf(MSG_ERROR, "Invalid password hash "
446 "on line %d in '%s'", line, fname);
449 user->password = os_malloc(16);
450 if (user->password == NULL) {
451 wpa_printf(MSG_ERROR, "Failed to allocate "
452 "memory for EAP password hash");
455 if (hexstr2bin(pos, user->password, 16) < 0) {
456 wpa_printf(MSG_ERROR, "Invalid hash password "
457 "on line %d in '%s'", line, fname);
460 user->password_len = 16;
461 user->password_hash = 1;
465 while (*pos2 != '\0' && *pos2 != ' ' &&
466 *pos2 != '\t' && *pos2 != '#')
468 if ((pos2 - pos) & 1) {
469 wpa_printf(MSG_ERROR, "Invalid hex password "
470 "on line %d in '%s'", line, fname);
473 user->password = os_malloc((pos2 - pos) / 2);
474 if (user->password == NULL) {
475 wpa_printf(MSG_ERROR, "Failed to allocate "
476 "memory for EAP password");
479 if (hexstr2bin(pos, user->password,
480 (pos2 - pos) / 2) < 0) {
481 wpa_printf(MSG_ERROR, "Invalid hex password "
482 "on line %d in '%s'", line, fname);
485 user->password_len = (pos2 - pos) / 2;
489 while (*pos == ' ' || *pos == '\t')
491 if (os_strncmp(pos, "[2]", 3) == 0) {
497 tail = new_user = user;
506 hostapd_config_free_eap_user(user);
514 user = conf->eap_user;
516 struct hostapd_eap_user *prev;
520 hostapd_config_free_eap_user(prev);
522 conf->eap_user = new_user;
527 #endif /* EAP_SERVER */
530 #ifndef CONFIG_NO_RADIUS
532 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
533 int *num_server, const char *val, int def_port,
534 struct hostapd_radius_server **curr_serv)
536 struct hostapd_radius_server *nserv;
538 static int server_index = 1;
540 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
545 nserv = &nserv[*num_server];
547 (*curr_serv) = nserv;
549 os_memset(nserv, 0, sizeof(*nserv));
550 nserv->port = def_port;
551 ret = hostapd_parse_ip_addr(val, &nserv->addr);
552 nserv->index = server_index++;
558 static struct hostapd_radius_attr *
559 hostapd_parse_radius_attr(const char *value)
563 struct hostapd_radius_attr *attr;
566 attr = os_zalloc(sizeof(*attr));
570 attr->type = atoi(value);
572 pos = os_strchr(value, ':');
574 attr->val = wpabuf_alloc(1);
575 if (attr->val == NULL) {
579 wpabuf_put_u8(attr->val, 0);
584 if (pos[0] == '\0' || pos[1] != ':') {
593 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
596 len = os_strlen(pos);
600 attr->val = wpabuf_alloc(len);
601 if (attr->val == NULL)
603 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
604 wpabuf_free(attr->val);
610 attr->val = wpabuf_alloc(4);
612 wpabuf_put_be32(attr->val, atoi(pos));
619 if (attr->val == NULL) {
628 static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
633 secret = os_strchr(val, ' ');
639 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
642 os_free(bss->radius_das_shared_secret);
643 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
644 if (bss->radius_das_shared_secret == NULL)
646 bss->radius_das_shared_secret_len = os_strlen(secret);
650 #endif /* CONFIG_NO_RADIUS */
653 static int hostapd_config_parse_key_mgmt(int line, const char *value)
656 char *start, *end, *buf;
658 buf = os_strdup(value);
663 while (*start != '\0') {
664 while (*start == ' ' || *start == '\t')
669 while (*end != ' ' && *end != '\t' && *end != '\0')
673 if (os_strcmp(start, "WPA-PSK") == 0)
674 val |= WPA_KEY_MGMT_PSK;
675 else if (os_strcmp(start, "WPA-EAP") == 0)
676 val |= WPA_KEY_MGMT_IEEE8021X;
677 #ifdef CONFIG_IEEE80211R
678 else if (os_strcmp(start, "FT-PSK") == 0)
679 val |= WPA_KEY_MGMT_FT_PSK;
680 else if (os_strcmp(start, "FT-EAP") == 0)
681 val |= WPA_KEY_MGMT_FT_IEEE8021X;
682 #endif /* CONFIG_IEEE80211R */
683 #ifdef CONFIG_IEEE80211W
684 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
685 val |= WPA_KEY_MGMT_PSK_SHA256;
686 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
687 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
688 #endif /* CONFIG_IEEE80211W */
690 else if (os_strcmp(start, "SAE") == 0)
691 val |= WPA_KEY_MGMT_SAE;
692 else if (os_strcmp(start, "FT-SAE") == 0)
693 val |= WPA_KEY_MGMT_FT_SAE;
694 #endif /* CONFIG_SAE */
696 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
697 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
698 #endif /* CONFIG_SUITEB */
699 #ifdef CONFIG_SUITEB192
700 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
701 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
702 #endif /* CONFIG_SUITEB192 */
704 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
717 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
718 "configured.", line);
726 static int hostapd_config_parse_cipher(int line, const char *value)
728 int val = wpa_parse_cipher(value);
730 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
735 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
743 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
746 size_t len = os_strlen(val);
748 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
752 if (len < 2 || val[len - 1] != '"')
755 wep->key[keyidx] = os_malloc(len);
756 if (wep->key[keyidx] == NULL)
758 os_memcpy(wep->key[keyidx], val + 1, len);
759 wep->len[keyidx] = len;
764 wep->key[keyidx] = os_malloc(len);
765 if (wep->key[keyidx] == NULL)
767 wep->len[keyidx] = len;
768 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
778 static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
782 /* for backwards compatibility, translate ' ' in conf str to ',' */
785 pos = os_strchr(pos, ' ');
789 if (freq_range_list_parse(&conf->acs_ch_list, val))
796 static int hostapd_parse_intlist(int **int_list, char *val)
807 while (*pos != '\0') {
813 list = os_malloc(sizeof(int) * (count + 2));
818 while (*pos != '\0') {
819 end = os_strchr(pos, ' ');
823 list[count++] = atoi(pos);
835 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
837 struct hostapd_bss_config **all, *bss;
842 all = os_realloc_array(conf->bss, conf->num_bss + 1,
843 sizeof(struct hostapd_bss_config *));
845 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
851 bss = os_zalloc(sizeof(*bss));
854 bss->radius = os_zalloc(sizeof(*bss->radius));
855 if (bss->radius == NULL) {
856 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
857 "multi-BSS RADIUS data");
862 conf->bss[conf->num_bss++] = bss;
863 conf->last_bss = bss;
865 hostapd_config_defaults_bss(bss);
866 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
867 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
873 /* convert floats with one decimal place to value*10 int, i.e.,
874 * "1.5" will return 15 */
875 static int hostapd_config_read_int10(const char *value)
881 pos = os_strchr(value, '.');
885 if (*pos >= '0' && *pos <= '9')
893 static int valid_cw(int cw)
895 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
896 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
901 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
902 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
903 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
904 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
907 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
912 struct hostapd_tx_queue_params *queue;
914 /* skip 'tx_queue_' prefix */
916 if (os_strncmp(pos, "data", 4) == 0 &&
917 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
920 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
921 os_strncmp(pos, "beacon_", 7) == 0) {
922 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
925 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
929 if (num >= NUM_TX_QUEUES) {
930 /* for backwards compatibility, do not trigger failure */
931 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
935 queue = &conf->tx_queue[num];
937 if (os_strcmp(pos, "aifs") == 0) {
938 queue->aifs = atoi(val);
939 if (queue->aifs < 0 || queue->aifs > 255) {
940 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
944 } else if (os_strcmp(pos, "cwmin") == 0) {
945 queue->cwmin = atoi(val);
946 if (!valid_cw(queue->cwmin)) {
947 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
951 } else if (os_strcmp(pos, "cwmax") == 0) {
952 queue->cwmax = atoi(val);
953 if (!valid_cw(queue->cwmax)) {
954 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
958 } else if (os_strcmp(pos, "burst") == 0) {
959 queue->burst = hostapd_config_read_int10(val);
961 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
969 #ifdef CONFIG_IEEE80211R
970 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
972 struct ft_remote_r0kh *r0kh;
975 r0kh = os_zalloc(sizeof(*r0kh));
979 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
981 next = os_strchr(pos, ' ');
984 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
985 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
991 next = os_strchr(pos, ' ');
994 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
995 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
999 r0kh->id_len = next - pos - 1;
1000 os_memcpy(r0kh->id, pos, r0kh->id_len);
1003 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1004 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1009 r0kh->next = bss->r0kh_list;
1010 bss->r0kh_list = r0kh;
1016 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1018 struct ft_remote_r1kh *r1kh;
1021 r1kh = os_zalloc(sizeof(*r1kh));
1025 /* 02:01:02:03:04:05 02:01:02:03:04:05
1026 * 000102030405060708090a0b0c0d0e0f */
1028 next = os_strchr(pos, ' ');
1031 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1032 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1038 next = os_strchr(pos, ' ');
1041 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1042 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1048 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1049 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1054 r1kh->next = bss->r1kh_list;
1055 bss->r1kh_list = r1kh;
1059 #endif /* CONFIG_IEEE80211R */
1062 #ifdef CONFIG_IEEE80211N
1063 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1066 if (os_strstr(capab, "[LDPC]"))
1067 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1068 if (os_strstr(capab, "[HT40-]")) {
1069 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1070 conf->secondary_channel = -1;
1072 if (os_strstr(capab, "[HT40+]")) {
1073 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1074 conf->secondary_channel = 1;
1076 if (os_strstr(capab, "[SMPS-STATIC]")) {
1077 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1078 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1080 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1081 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1082 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1084 if (os_strstr(capab, "[GF]"))
1085 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1086 if (os_strstr(capab, "[SHORT-GI-20]"))
1087 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1088 if (os_strstr(capab, "[SHORT-GI-40]"))
1089 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1090 if (os_strstr(capab, "[TX-STBC]"))
1091 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1092 if (os_strstr(capab, "[RX-STBC1]")) {
1093 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1094 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1096 if (os_strstr(capab, "[RX-STBC12]")) {
1097 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1098 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1100 if (os_strstr(capab, "[RX-STBC123]")) {
1101 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1102 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1104 if (os_strstr(capab, "[DELAYED-BA]"))
1105 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1106 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1107 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1108 if (os_strstr(capab, "[DSSS_CCK-40]"))
1109 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1110 if (os_strstr(capab, "[40-INTOLERANT]"))
1111 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
1112 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1113 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1117 #endif /* CONFIG_IEEE80211N */
1120 #ifdef CONFIG_IEEE80211AC
1121 static int hostapd_config_vht_capab(struct hostapd_config *conf,
1124 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1125 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1126 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1127 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1128 if (os_strstr(capab, "[VHT160]"))
1129 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1130 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1131 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1132 if (os_strstr(capab, "[RXLDPC]"))
1133 conf->vht_capab |= VHT_CAP_RXLDPC;
1134 if (os_strstr(capab, "[SHORT-GI-80]"))
1135 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1136 if (os_strstr(capab, "[SHORT-GI-160]"))
1137 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1138 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1139 conf->vht_capab |= VHT_CAP_TXSTBC;
1140 if (os_strstr(capab, "[RX-STBC-1]"))
1141 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1142 if (os_strstr(capab, "[RX-STBC-12]"))
1143 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1144 if (os_strstr(capab, "[RX-STBC-123]"))
1145 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1146 if (os_strstr(capab, "[RX-STBC-1234]"))
1147 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1148 if (os_strstr(capab, "[SU-BEAMFORMER]"))
1149 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
1150 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
1151 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1152 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
1153 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1154 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1155 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
1156 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1157 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1158 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1159 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1160 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1161 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1162 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1163 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1164 if (os_strstr(capab, "[HTC-VHT]"))
1165 conf->vht_capab |= VHT_CAP_HTC_VHT;
1166 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1167 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1168 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1169 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1170 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1171 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1172 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1173 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1174 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1175 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1176 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1177 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1178 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1179 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
1180 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1181 (conf->vht_capab & VHT_CAP_HTC_VHT))
1182 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1183 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1184 (conf->vht_capab & VHT_CAP_HTC_VHT))
1185 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1186 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1187 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1188 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1189 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1192 #endif /* CONFIG_IEEE80211AC */
1195 #ifdef CONFIG_INTERWORKING
1196 static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1199 size_t len = os_strlen(pos);
1200 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1202 struct hostapd_roaming_consortium *rc;
1204 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1205 hexstr2bin(pos, oi, len / 2)) {
1206 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1212 rc = os_realloc_array(bss->roaming_consortium,
1213 bss->roaming_consortium_count + 1,
1214 sizeof(struct hostapd_roaming_consortium));
1218 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1219 rc[bss->roaming_consortium_count].len = len;
1221 bss->roaming_consortium = rc;
1222 bss->roaming_consortium_count++;
1228 static int parse_lang_string(struct hostapd_lang_string **array,
1229 unsigned int *count, char *pos)
1231 char *sep, *str = NULL;
1232 size_t clen, nlen, slen;
1233 struct hostapd_lang_string *ls;
1236 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1237 str = wpa_config_parse_string(pos, &slen);
1243 sep = os_strchr(pos, ':');
1248 clen = os_strlen(pos);
1249 if (clen < 2 || clen > sizeof(ls->lang))
1251 nlen = os_strlen(sep);
1255 ls = os_realloc_array(*array, *count + 1,
1256 sizeof(struct hostapd_lang_string));
1261 ls = &(*array)[*count];
1264 os_memset(ls->lang, 0, sizeof(ls->lang));
1265 os_memcpy(ls->lang, pos, clen);
1266 ls->name_len = nlen;
1267 os_memcpy(ls->name, sep, nlen);
1276 static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1279 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1280 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1288 static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1293 u8 *info = NULL, *ipos;
1295 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1298 for (pos = buf; *pos; pos++) {
1299 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
1304 if (1 + count * 3 > 0x7f)
1307 info = os_zalloc(2 + 3 + count * 3);
1312 *ipos++ = 0; /* GUD - Version 1 */
1313 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1314 *ipos++ = 0; /* PLMN List IEI */
1315 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1316 *ipos++ = 1 + count * 3;
1317 *ipos++ = count; /* Number of PLMNs */
1320 while (pos && *pos) {
1325 mnc = os_strchr(pos, ',');
1329 pos = os_strchr(mnc, ';');
1333 mnc_len = os_strlen(mnc);
1334 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1337 /* BC coded MCC,MNC */
1338 /* MCC digit 2 | MCC digit 1 */
1339 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1340 /* MNC digit 3 | MCC digit 3 */
1341 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1343 /* MNC digit 2 | MNC digit 1 */
1344 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1347 os_free(bss->anqp_3gpp_cell_net);
1348 bss->anqp_3gpp_cell_net = info;
1349 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1350 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1351 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
1356 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1363 static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1365 struct hostapd_nai_realm_data *realm;
1368 char *pos, *end, *rpos;
1370 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1372 if (offsets == NULL)
1375 for (i = 0; i < bss->nai_realm_count; i++) {
1376 realm = &bss->nai_realm_data[i];
1377 for (j = 0; j < MAX_NAI_REALMS; j++) {
1378 offsets[i * MAX_NAI_REALMS + j] =
1380 realm->realm[j] - realm->realm_buf : -1;
1384 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1385 sizeof(struct hostapd_nai_realm_data));
1386 if (realm == NULL) {
1390 bss->nai_realm_data = realm;
1392 /* patch the pointers after realloc */
1393 for (i = 0; i < bss->nai_realm_count; i++) {
1394 realm = &bss->nai_realm_data[i];
1395 for (j = 0; j < MAX_NAI_REALMS; j++) {
1396 int offs = offsets[i * MAX_NAI_REALMS + j];
1398 realm->realm[j] = realm->realm_buf + offs;
1400 realm->realm[j] = NULL;
1405 realm = &bss->nai_realm_data[bss->nai_realm_count];
1406 os_memset(realm, 0, sizeof(*realm));
1409 realm->encoding = atoi(pos);
1410 pos = os_strchr(pos, ',');
1415 end = os_strchr(pos, ',');
1420 len = os_strlen(pos);
1423 if (len > MAX_NAI_REALMLEN) {
1424 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1425 "characters)", (int) len, MAX_NAI_REALMLEN);
1428 os_memcpy(realm->realm_buf, pos, len);
1435 while (pos && *pos) {
1436 struct hostapd_nai_realm_eap *eap;
1438 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1439 wpa_printf(MSG_ERROR, "Too many EAP methods");
1443 eap = &realm->eap_method[realm->eap_method_count];
1444 realm->eap_method_count++;
1446 end = os_strchr(pos, ',');
1448 end = pos + os_strlen(pos);
1450 eap->eap_method = atoi(pos);
1452 pos = os_strchr(pos, '[');
1453 if (pos == NULL || pos > end)
1456 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1457 wpa_printf(MSG_ERROR, "Too many auth params");
1460 eap->auth_id[eap->num_auths] = atoi(pos);
1461 pos = os_strchr(pos, ':');
1462 if (pos == NULL || pos > end)
1465 eap->auth_val[eap->num_auths] = atoi(pos);
1466 pos = os_strchr(pos, ']');
1467 if (pos == NULL || pos > end)
1479 /* Split realm list into null terminated realms */
1480 rpos = realm->realm_buf;
1483 if (i >= MAX_NAI_REALMS) {
1484 wpa_printf(MSG_ERROR, "Too many realms");
1487 realm->realm[i++] = rpos;
1488 rpos = os_strchr(rpos, ';');
1494 bss->nai_realm_count++;
1499 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1504 static int parse_qos_map_set(struct hostapd_bss_config *bss,
1505 char *buf, int line)
1507 u8 qos_map_set[16 + 2 * 21], count = 0;
1512 if (count == sizeof(qos_map_set)) {
1513 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1514 "parameters '%s'", line, buf);
1519 if (val > 255 || val < 0) {
1520 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1525 qos_map_set[count++] = val;
1526 pos = os_strchr(pos, ',');
1532 if (count < 16 || count & 1) {
1533 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1538 os_memcpy(bss->qos_map_set, qos_map_set, count);
1539 bss->qos_map_set_len = count;
1544 #endif /* CONFIG_INTERWORKING */
1548 static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1554 if (bss->hs20_connection_capability_len >= 0xfff0)
1557 conn_cap = os_realloc(bss->hs20_connection_capability,
1558 bss->hs20_connection_capability_len + 4);
1559 if (conn_cap == NULL)
1562 bss->hs20_connection_capability = conn_cap;
1563 conn_cap += bss->hs20_connection_capability_len;
1565 conn_cap[0] = atoi(pos);
1566 pos = os_strchr(pos, ':');
1570 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1571 pos = os_strchr(pos, ':');
1575 conn_cap[3] = atoi(pos);
1576 bss->hs20_connection_capability_len += 4;
1582 static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1588 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1590 wan_metrics = os_zalloc(13);
1591 if (wan_metrics == NULL)
1596 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1603 /* Downlink Speed */
1604 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1605 pos = os_strchr(pos, ':');
1611 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1612 pos = os_strchr(pos, ':');
1618 wan_metrics[9] = atoi(pos);
1619 pos = os_strchr(pos, ':');
1625 wan_metrics[10] = atoi(pos);
1626 pos = os_strchr(pos, ':');
1632 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1634 os_free(bss->hs20_wan_metrics);
1635 bss->hs20_wan_metrics = wan_metrics;
1640 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
1642 os_free(wan_metrics);
1647 static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1648 char *pos, int line)
1650 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1651 &bss->hs20_oper_friendly_name_count, pos)) {
1652 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1653 "hs20_oper_friendly_name '%s'", line, pos);
1660 static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1662 struct hs20_icon *icon;
1665 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1666 sizeof(struct hs20_icon));
1669 bss->hs20_icons = icon;
1670 icon = &bss->hs20_icons[bss->hs20_icons_count];
1671 os_memset(icon, 0, sizeof(*icon));
1673 icon->width = atoi(pos);
1674 pos = os_strchr(pos, ':');
1679 icon->height = atoi(pos);
1680 pos = os_strchr(pos, ':');
1685 end = os_strchr(pos, ':');
1686 if (end == NULL || end - pos > 3)
1688 os_memcpy(icon->language, pos, end - pos);
1691 end = os_strchr(pos, ':');
1692 if (end == NULL || end - pos > 255)
1694 os_memcpy(icon->type, pos, end - pos);
1697 end = os_strchr(pos, ':');
1698 if (end == NULL || end - pos > 255)
1700 os_memcpy(icon->name, pos, end - pos);
1703 if (os_strlen(pos) > 255)
1705 os_memcpy(icon->file, pos, os_strlen(pos));
1707 bss->hs20_icons_count++;
1713 static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1714 char *pos, int line)
1719 str = wpa_config_parse_string(pos, &slen);
1720 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1721 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
1726 os_memcpy(bss->osu_ssid, str, slen);
1727 bss->osu_ssid_len = slen;
1734 static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1735 char *pos, int line)
1737 struct hs20_osu_provider *p;
1739 p = os_realloc_array(bss->hs20_osu_providers,
1740 bss->hs20_osu_providers_count + 1, sizeof(*p));
1744 bss->hs20_osu_providers = p;
1745 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1746 bss->hs20_osu_providers_count++;
1747 os_memset(bss->last_osu, 0, sizeof(*p));
1748 bss->last_osu->server_uri = os_strdup(pos);
1754 static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1755 char *pos, int line)
1757 if (bss->last_osu == NULL) {
1758 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1762 if (parse_lang_string(&bss->last_osu->friendly_name,
1763 &bss->last_osu->friendly_name_count, pos)) {
1764 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1773 static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1774 char *pos, int line)
1776 if (bss->last_osu == NULL) {
1777 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1781 os_free(bss->last_osu->osu_nai);
1782 bss->last_osu->osu_nai = os_strdup(pos);
1783 if (bss->last_osu->osu_nai == NULL)
1790 static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1793 if (bss->last_osu == NULL) {
1794 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1798 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1799 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1807 static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1811 struct hs20_osu_provider *p = bss->last_osu;
1814 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1818 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1822 p->icons[p->icons_count] = os_strdup(pos);
1823 if (p->icons[p->icons_count] == NULL)
1831 static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1832 char *pos, int line)
1834 if (bss->last_osu == NULL) {
1835 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1839 if (parse_lang_string(&bss->last_osu->service_desc,
1840 &bss->last_osu->service_desc_count, pos)) {
1841 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1849 #endif /* CONFIG_HS20 */
1852 #ifdef CONFIG_WPS_NFC
1853 static struct wpabuf * hostapd_parse_bin(const char *buf)
1858 len = os_strlen(buf);
1863 ret = wpabuf_alloc(len);
1867 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1874 #endif /* CONFIG_WPS_NFC */
1878 static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
1881 struct acs_bias *bias = NULL, *tmp;
1882 unsigned int num = 0;
1886 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
1891 bias[num].channel = atoi(pos);
1892 if (bias[num].channel <= 0)
1894 pos = os_strchr(pos, ':');
1898 bias[num].bias = strtod(pos, &end);
1899 if (end == pos || bias[num].bias < 0.0)
1902 if (*pos != ' ' && *pos != '\0')
1907 os_free(conf->acs_chan_bias);
1908 conf->acs_chan_bias = bias;
1909 conf->num_acs_chan_bias = num;
1916 #endif /* CONFIG_ACS */
1919 static int hostapd_config_fill(struct hostapd_config *conf,
1920 struct hostapd_bss_config *bss,
1921 char *buf, char *pos, int line)
1923 if (os_strcmp(buf, "interface") == 0) {
1924 os_strlcpy(conf->bss[0]->iface, pos,
1925 sizeof(conf->bss[0]->iface));
1926 } else if (os_strcmp(buf, "bridge") == 0) {
1927 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1928 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1929 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
1930 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1931 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
1932 } else if (os_strcmp(buf, "driver") == 0) {
1934 /* clear to get error below if setting is invalid */
1935 conf->driver = NULL;
1936 for (j = 0; wpa_drivers[j]; j++) {
1937 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
1938 conf->driver = wpa_drivers[j];
1942 if (conf->driver == NULL) {
1943 wpa_printf(MSG_ERROR,
1944 "Line %d: invalid/unknown driver '%s'",
1948 } else if (os_strcmp(buf, "driver_params") == 0) {
1949 os_free(conf->driver_params);
1950 conf->driver_params = os_strdup(pos);
1951 } else if (os_strcmp(buf, "debug") == 0) {
1952 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
1954 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1955 bss->logger_syslog_level = atoi(pos);
1956 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1957 bss->logger_stdout_level = atoi(pos);
1958 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1959 bss->logger_syslog = atoi(pos);
1960 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1961 bss->logger_stdout = atoi(pos);
1962 } else if (os_strcmp(buf, "dump_file") == 0) {
1963 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
1965 } else if (os_strcmp(buf, "ssid") == 0) {
1966 bss->ssid.ssid_len = os_strlen(pos);
1967 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1968 bss->ssid.ssid_len < 1) {
1969 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1973 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
1974 bss->ssid.ssid_set = 1;
1975 } else if (os_strcmp(buf, "ssid2") == 0) {
1977 char *str = wpa_config_parse_string(pos, &slen);
1978 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1979 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1984 os_memcpy(bss->ssid.ssid, str, slen);
1985 bss->ssid.ssid_len = slen;
1986 bss->ssid.ssid_set = 1;
1988 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1989 bss->ssid.utf8_ssid = atoi(pos) > 0;
1990 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1991 bss->macaddr_acl = atoi(pos);
1992 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1993 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1994 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1995 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
1996 line, bss->macaddr_acl);
1998 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1999 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2000 &bss->num_accept_mac)) {
2001 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2005 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2006 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2007 &bss->num_deny_mac)) {
2008 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2012 } else if (os_strcmp(buf, "wds_sta") == 0) {
2013 bss->wds_sta = atoi(pos);
2014 } else if (os_strcmp(buf, "start_disabled") == 0) {
2015 bss->start_disabled = atoi(pos);
2016 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2017 bss->isolate = atoi(pos);
2018 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2019 bss->ap_max_inactivity = atoi(pos);
2020 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2021 bss->skip_inactivity_poll = atoi(pos);
2022 } else if (os_strcmp(buf, "country_code") == 0) {
2023 os_memcpy(conf->country, pos, 2);
2024 /* FIX: make this configurable */
2025 conf->country[2] = ' ';
2026 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2027 conf->ieee80211d = atoi(pos);
2028 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2029 conf->ieee80211h = atoi(pos);
2030 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2031 bss->ieee802_1x = atoi(pos);
2032 } else if (os_strcmp(buf, "eapol_version") == 0) {
2033 bss->eapol_version = atoi(pos);
2034 if (bss->eapol_version < 1 || bss->eapol_version > 2) {
2035 wpa_printf(MSG_ERROR,
2036 "Line %d: invalid EAPOL version (%d): '%s'.",
2037 line, bss->eapol_version, pos);
2040 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
2042 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2043 bss->eap_server = atoi(pos);
2044 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2045 } else if (os_strcmp(buf, "eap_server") == 0) {
2046 bss->eap_server = atoi(pos);
2047 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2048 if (hostapd_config_read_eap_user(pos, bss))
2050 } else if (os_strcmp(buf, "ca_cert") == 0) {
2051 os_free(bss->ca_cert);
2052 bss->ca_cert = os_strdup(pos);
2053 } else if (os_strcmp(buf, "server_cert") == 0) {
2054 os_free(bss->server_cert);
2055 bss->server_cert = os_strdup(pos);
2056 } else if (os_strcmp(buf, "private_key") == 0) {
2057 os_free(bss->private_key);
2058 bss->private_key = os_strdup(pos);
2059 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2060 os_free(bss->private_key_passwd);
2061 bss->private_key_passwd = os_strdup(pos);
2062 } else if (os_strcmp(buf, "check_crl") == 0) {
2063 bss->check_crl = atoi(pos);
2064 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2065 os_free(bss->ocsp_stapling_response);
2066 bss->ocsp_stapling_response = os_strdup(pos);
2067 } else if (os_strcmp(buf, "dh_file") == 0) {
2068 os_free(bss->dh_file);
2069 bss->dh_file = os_strdup(pos);
2070 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2071 os_free(bss->openssl_ciphers);
2072 bss->openssl_ciphers = os_strdup(pos);
2073 } else if (os_strcmp(buf, "fragment_size") == 0) {
2074 bss->fragment_size = atoi(pos);
2075 #ifdef EAP_SERVER_FAST
2076 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2077 os_free(bss->pac_opaque_encr_key);
2078 bss->pac_opaque_encr_key = os_malloc(16);
2079 if (bss->pac_opaque_encr_key == NULL) {
2080 wpa_printf(MSG_ERROR,
2081 "Line %d: No memory for pac_opaque_encr_key",
2084 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2085 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2089 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2090 size_t idlen = os_strlen(pos);
2092 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2096 os_free(bss->eap_fast_a_id);
2097 bss->eap_fast_a_id = os_malloc(idlen / 2);
2098 if (bss->eap_fast_a_id == NULL ||
2099 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2100 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2102 os_free(bss->eap_fast_a_id);
2103 bss->eap_fast_a_id = NULL;
2106 bss->eap_fast_a_id_len = idlen / 2;
2108 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2109 os_free(bss->eap_fast_a_id_info);
2110 bss->eap_fast_a_id_info = os_strdup(pos);
2111 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2112 bss->eap_fast_prov = atoi(pos);
2113 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2114 bss->pac_key_lifetime = atoi(pos);
2115 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2116 bss->pac_key_refresh_time = atoi(pos);
2117 #endif /* EAP_SERVER_FAST */
2118 #ifdef EAP_SERVER_SIM
2119 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2120 os_free(bss->eap_sim_db);
2121 bss->eap_sim_db = os_strdup(pos);
2122 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2123 bss->eap_sim_aka_result_ind = atoi(pos);
2124 #endif /* EAP_SERVER_SIM */
2125 #ifdef EAP_SERVER_TNC
2126 } else if (os_strcmp(buf, "tnc") == 0) {
2127 bss->tnc = atoi(pos);
2128 #endif /* EAP_SERVER_TNC */
2129 #ifdef EAP_SERVER_PWD
2130 } else if (os_strcmp(buf, "pwd_group") == 0) {
2131 bss->pwd_group = atoi(pos);
2132 #endif /* EAP_SERVER_PWD */
2133 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2134 bss->eap_server_erp = atoi(pos);
2135 #endif /* EAP_SERVER */
2136 } else if (os_strcmp(buf, "eap_message") == 0) {
2138 os_free(bss->eap_req_id_text);
2139 bss->eap_req_id_text = os_strdup(pos);
2140 if (bss->eap_req_id_text == NULL) {
2141 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2145 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2146 term = os_strstr(bss->eap_req_id_text, "\\0");
2149 os_memmove(term, term + 1,
2150 bss->eap_req_id_text_len -
2151 (term - bss->eap_req_id_text) - 1);
2152 bss->eap_req_id_text_len--;
2154 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2155 bss->erp_send_reauth_start = atoi(pos);
2156 } else if (os_strcmp(buf, "erp_domain") == 0) {
2157 os_free(bss->erp_domain);
2158 bss->erp_domain = os_strdup(pos);
2159 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
2160 bss->default_wep_key_len = atoi(pos);
2161 if (bss->default_wep_key_len > 13) {
2162 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
2164 (unsigned long) bss->default_wep_key_len,
2166 bss->default_wep_key_len * 8);
2169 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
2170 bss->individual_wep_key_len = atoi(pos);
2171 if (bss->individual_wep_key_len < 0 ||
2172 bss->individual_wep_key_len > 13) {
2173 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
2174 line, bss->individual_wep_key_len,
2175 bss->individual_wep_key_len * 8);
2178 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2179 bss->wep_rekeying_period = atoi(pos);
2180 if (bss->wep_rekeying_period < 0) {
2181 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2182 line, bss->wep_rekeying_period);
2185 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2186 bss->eap_reauth_period = atoi(pos);
2187 if (bss->eap_reauth_period < 0) {
2188 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2189 line, bss->eap_reauth_period);
2192 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2193 bss->eapol_key_index_workaround = atoi(pos);
2195 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2196 bss->ieee802_11f = 1;
2197 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
2198 #endif /* CONFIG_IAPP */
2199 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2200 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2201 wpa_printf(MSG_ERROR,
2202 "Line %d: invalid IP address '%s'",
2206 } else if (os_strcmp(buf, "nas_identifier") == 0) {
2207 os_free(bss->nas_identifier);
2208 bss->nas_identifier = os_strdup(pos);
2209 #ifndef CONFIG_NO_RADIUS
2210 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2211 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2212 wpa_printf(MSG_ERROR,
2213 "Line %d: invalid IP address '%s'",
2217 bss->radius->force_client_addr = 1;
2218 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2219 if (hostapd_config_read_radius_addr(
2220 &bss->radius->auth_servers,
2221 &bss->radius->num_auth_servers, pos, 1812,
2222 &bss->radius->auth_server)) {
2223 wpa_printf(MSG_ERROR,
2224 "Line %d: invalid IP address '%s'",
2228 } else if (bss->radius->auth_server &&
2229 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2230 if (hostapd_parse_ip_addr(pos,
2231 &bss->radius->auth_server->addr)) {
2232 wpa_printf(MSG_ERROR,
2233 "Line %d: invalid IP address '%s'",
2237 } else if (bss->radius->auth_server &&
2238 os_strcmp(buf, "auth_server_port") == 0) {
2239 bss->radius->auth_server->port = atoi(pos);
2240 } else if (bss->radius->auth_server &&
2241 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2242 int len = os_strlen(pos);
2244 /* RFC 2865, Ch. 3 */
2245 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2249 os_free(bss->radius->auth_server->shared_secret);
2250 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2251 bss->radius->auth_server->shared_secret_len = len;
2252 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2253 if (hostapd_config_read_radius_addr(
2254 &bss->radius->acct_servers,
2255 &bss->radius->num_acct_servers, pos, 1813,
2256 &bss->radius->acct_server)) {
2257 wpa_printf(MSG_ERROR,
2258 "Line %d: invalid IP address '%s'",
2262 } else if (bss->radius->acct_server &&
2263 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2264 if (hostapd_parse_ip_addr(pos,
2265 &bss->radius->acct_server->addr)) {
2266 wpa_printf(MSG_ERROR,
2267 "Line %d: invalid IP address '%s'",
2271 } else if (bss->radius->acct_server &&
2272 os_strcmp(buf, "acct_server_port") == 0) {
2273 bss->radius->acct_server->port = atoi(pos);
2274 } else if (bss->radius->acct_server &&
2275 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2276 int len = os_strlen(pos);
2278 /* RFC 2865, Ch. 3 */
2279 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2283 os_free(bss->radius->acct_server->shared_secret);
2284 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2285 bss->radius->acct_server->shared_secret_len = len;
2286 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2287 bss->radius->retry_primary_interval = atoi(pos);
2288 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2289 bss->acct_interim_interval = atoi(pos);
2290 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2291 bss->radius_request_cui = atoi(pos);
2292 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2293 struct hostapd_radius_attr *attr, *a;
2294 attr = hostapd_parse_radius_attr(pos);
2296 wpa_printf(MSG_ERROR,
2297 "Line %d: invalid radius_auth_req_attr",
2300 } else if (bss->radius_auth_req_attr == NULL) {
2301 bss->radius_auth_req_attr = attr;
2303 a = bss->radius_auth_req_attr;
2308 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2309 struct hostapd_radius_attr *attr, *a;
2310 attr = hostapd_parse_radius_attr(pos);
2312 wpa_printf(MSG_ERROR,
2313 "Line %d: invalid radius_acct_req_attr",
2316 } else if (bss->radius_acct_req_attr == NULL) {
2317 bss->radius_acct_req_attr = attr;
2319 a = bss->radius_acct_req_attr;
2324 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2325 bss->radius_das_port = atoi(pos);
2326 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2327 if (hostapd_parse_das_client(bss, pos) < 0) {
2328 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2332 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2333 bss->radius_das_time_window = atoi(pos);
2334 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2335 bss->radius_das_require_event_timestamp = atoi(pos);
2336 #endif /* CONFIG_NO_RADIUS */
2337 } else if (os_strcmp(buf, "auth_algs") == 0) {
2338 bss->auth_algs = atoi(pos);
2339 if (bss->auth_algs == 0) {
2340 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2344 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2345 bss->max_num_sta = atoi(pos);
2346 if (bss->max_num_sta < 0 ||
2347 bss->max_num_sta > MAX_STA_COUNT) {
2348 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2349 line, bss->max_num_sta, MAX_STA_COUNT);
2352 } else if (os_strcmp(buf, "wpa") == 0) {
2353 bss->wpa = atoi(pos);
2354 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2355 bss->wpa_group_rekey = atoi(pos);
2356 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2357 bss->wpa_strict_rekey = atoi(pos);
2358 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2359 bss->wpa_gmk_rekey = atoi(pos);
2360 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2361 bss->wpa_ptk_rekey = atoi(pos);
2362 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2363 int len = os_strlen(pos);
2364 if (len < 8 || len > 63) {
2365 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2369 os_free(bss->ssid.wpa_passphrase);
2370 bss->ssid.wpa_passphrase = os_strdup(pos);
2371 if (bss->ssid.wpa_passphrase) {
2372 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
2373 bss->ssid.wpa_passphrase_set = 1;
2375 } else if (os_strcmp(buf, "wpa_psk") == 0) {
2376 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
2377 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2378 if (bss->ssid.wpa_psk == NULL)
2380 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2381 pos[PMK_LEN * 2] != '\0') {
2382 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2384 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
2387 bss->ssid.wpa_psk->group = 1;
2388 os_free(bss->ssid.wpa_passphrase);
2389 bss->ssid.wpa_passphrase = NULL;
2390 bss->ssid.wpa_psk_set = 1;
2391 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2392 os_free(bss->ssid.wpa_psk_file);
2393 bss->ssid.wpa_psk_file = os_strdup(pos);
2394 if (!bss->ssid.wpa_psk_file) {
2395 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2399 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2400 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2401 if (bss->wpa_key_mgmt == -1)
2403 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2404 bss->wpa_psk_radius = atoi(pos);
2405 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2406 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2407 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2408 wpa_printf(MSG_ERROR,
2409 "Line %d: unknown wpa_psk_radius %d",
2410 line, bss->wpa_psk_radius);
2413 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2414 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2415 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2417 if (bss->wpa_pairwise &
2418 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2419 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2420 bss->wpa_pairwise, pos);
2423 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2424 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2425 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2427 if (bss->rsn_pairwise &
2428 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2429 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2430 bss->rsn_pairwise, pos);
2433 #ifdef CONFIG_RSN_PREAUTH
2434 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2435 bss->rsn_preauth = atoi(pos);
2436 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
2437 os_free(bss->rsn_preauth_interfaces);
2438 bss->rsn_preauth_interfaces = os_strdup(pos);
2439 #endif /* CONFIG_RSN_PREAUTH */
2440 #ifdef CONFIG_PEERKEY
2441 } else if (os_strcmp(buf, "peerkey") == 0) {
2442 bss->peerkey = atoi(pos);
2443 #endif /* CONFIG_PEERKEY */
2444 #ifdef CONFIG_IEEE80211R
2445 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2446 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2447 hexstr2bin(pos, bss->mobility_domain,
2448 MOBILITY_DOMAIN_ID_LEN) != 0) {
2449 wpa_printf(MSG_ERROR,
2450 "Line %d: Invalid mobility_domain '%s'",
2454 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2455 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2456 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2457 wpa_printf(MSG_ERROR,
2458 "Line %d: Invalid r1_key_holder '%s'",
2462 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2463 bss->r0_key_lifetime = atoi(pos);
2464 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2465 bss->reassociation_deadline = atoi(pos);
2466 } else if (os_strcmp(buf, "r0kh") == 0) {
2467 if (add_r0kh(bss, pos) < 0) {
2468 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2472 } else if (os_strcmp(buf, "r1kh") == 0) {
2473 if (add_r1kh(bss, pos) < 0) {
2474 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2478 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2479 bss->pmk_r1_push = atoi(pos);
2480 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2481 bss->ft_over_ds = atoi(pos);
2482 #endif /* CONFIG_IEEE80211R */
2483 #ifndef CONFIG_NO_CTRL_IFACE
2484 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2485 os_free(bss->ctrl_interface);
2486 bss->ctrl_interface = os_strdup(pos);
2487 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
2488 #ifndef CONFIG_NATIVE_WINDOWS
2491 const char *group = pos;
2493 grp = getgrnam(group);
2495 bss->ctrl_interface_gid = grp->gr_gid;
2496 bss->ctrl_interface_gid_set = 1;
2497 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2498 bss->ctrl_interface_gid, group);
2502 /* Group name not found - try to parse this as gid */
2503 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2504 if (*group == '\0' || *endp != '\0') {
2505 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2509 bss->ctrl_interface_gid_set = 1;
2510 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2511 bss->ctrl_interface_gid);
2512 #endif /* CONFIG_NATIVE_WINDOWS */
2513 #endif /* CONFIG_NO_CTRL_IFACE */
2514 #ifdef RADIUS_SERVER
2515 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2516 os_free(bss->radius_server_clients);
2517 bss->radius_server_clients = os_strdup(pos);
2518 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2519 bss->radius_server_auth_port = atoi(pos);
2520 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2521 bss->radius_server_acct_port = atoi(pos);
2522 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2523 bss->radius_server_ipv6 = atoi(pos);
2524 #endif /* RADIUS_SERVER */
2525 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2526 bss->use_pae_group_addr = atoi(pos);
2527 } else if (os_strcmp(buf, "hw_mode") == 0) {
2528 if (os_strcmp(pos, "a") == 0)
2529 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2530 else if (os_strcmp(pos, "b") == 0)
2531 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2532 else if (os_strcmp(pos, "g") == 0)
2533 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2534 else if (os_strcmp(pos, "ad") == 0)
2535 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
2537 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
2541 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2542 if (os_strcmp(pos, "a") == 0)
2543 bss->wps_rf_bands = WPS_RF_50GHZ;
2544 else if (os_strcmp(pos, "g") == 0 ||
2545 os_strcmp(pos, "b") == 0)
2546 bss->wps_rf_bands = WPS_RF_24GHZ;
2547 else if (os_strcmp(pos, "ag") == 0 ||
2548 os_strcmp(pos, "ga") == 0)
2549 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
2551 wpa_printf(MSG_ERROR,
2552 "Line %d: unknown wps_rf_band '%s'",
2556 } else if (os_strcmp(buf, "channel") == 0) {
2557 if (os_strcmp(pos, "acs_survey") == 0) {
2559 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
2562 #else /* CONFIG_ACS */
2565 #endif /* CONFIG_ACS */
2567 conf->channel = atoi(pos);
2568 conf->acs = conf->channel == 0;
2570 } else if (os_strcmp(buf, "chanlist") == 0) {
2571 if (hostapd_parse_chanlist(conf, pos)) {
2572 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
2576 } else if (os_strcmp(buf, "beacon_int") == 0) {
2577 int val = atoi(pos);
2578 /* MIB defines range as 1..65535, but very small values
2579 * cause problems with the current implementation.
2580 * Since it is unlikely that this small numbers are
2581 * useful in real life scenarios, do not allow beacon
2582 * period to be set below 15 TU. */
2583 if (val < 15 || val > 65535) {
2584 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
2588 conf->beacon_int = val;
2590 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
2591 int val = atoi(pos);
2592 if (val <= 0 || val > 100) {
2593 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
2597 conf->acs_num_scans = val;
2598 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
2599 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
2600 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
2604 #endif /* CONFIG_ACS */
2605 } else if (os_strcmp(buf, "dtim_period") == 0) {
2606 bss->dtim_period = atoi(pos);
2607 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2608 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
2609 line, bss->dtim_period);
2612 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
2613 bss->bss_load_update_period = atoi(pos);
2614 if (bss->bss_load_update_period < 0 ||
2615 bss->bss_load_update_period > 100) {
2616 wpa_printf(MSG_ERROR,
2617 "Line %d: invalid bss_load_update_period %d",
2618 line, bss->bss_load_update_period);
2621 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2622 conf->rts_threshold = atoi(pos);
2623 if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
2624 wpa_printf(MSG_ERROR,
2625 "Line %d: invalid rts_threshold %d",
2626 line, conf->rts_threshold);
2629 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2630 conf->fragm_threshold = atoi(pos);
2631 if (conf->fragm_threshold < 256 ||
2632 conf->fragm_threshold > 2346) {
2633 wpa_printf(MSG_ERROR,
2634 "Line %d: invalid fragm_threshold %d",
2635 line, conf->fragm_threshold);
2638 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2639 int val = atoi(pos);
2640 if (val != 0 && val != 1) {
2641 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
2645 conf->send_probe_response = val;
2646 } else if (os_strcmp(buf, "supported_rates") == 0) {
2647 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
2648 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2652 } else if (os_strcmp(buf, "basic_rates") == 0) {
2653 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
2654 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2658 } else if (os_strcmp(buf, "preamble") == 0) {
2660 conf->preamble = SHORT_PREAMBLE;
2662 conf->preamble = LONG_PREAMBLE;
2663 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2664 bss->ignore_broadcast_ssid = atoi(pos);
2665 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2666 bss->ssid.wep.idx = atoi(pos);
2667 if (bss->ssid.wep.idx > 3) {
2668 wpa_printf(MSG_ERROR,
2669 "Invalid wep_default_key index %d",
2673 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2674 os_strcmp(buf, "wep_key1") == 0 ||
2675 os_strcmp(buf, "wep_key2") == 0 ||
2676 os_strcmp(buf, "wep_key3") == 0) {
2677 if (hostapd_config_read_wep(&bss->ssid.wep,
2678 buf[7] - '0', pos)) {
2679 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
2683 #ifndef CONFIG_NO_VLAN
2684 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2685 bss->ssid.dynamic_vlan = atoi(pos);
2686 } else if (os_strcmp(buf, "vlan_file") == 0) {
2687 if (hostapd_config_read_vlan_file(bss, pos)) {
2688 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
2692 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2693 bss->ssid.vlan_naming = atoi(pos);
2694 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2695 bss->ssid.vlan_naming < 0) {
2696 wpa_printf(MSG_ERROR,
2697 "Line %d: invalid naming scheme %d",
2698 line, bss->ssid.vlan_naming);
2701 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2702 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2703 os_free(bss->ssid.vlan_tagged_interface);
2704 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2705 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2706 #endif /* CONFIG_NO_VLAN */
2707 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2708 conf->ap_table_max_size = atoi(pos);
2709 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2710 conf->ap_table_expiration_time = atoi(pos);
2711 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2712 if (hostapd_config_tx_queue(conf, buf, pos)) {
2713 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
2717 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2718 os_strcmp(buf, "wmm_enabled") == 0) {
2719 bss->wmm_enabled = atoi(pos);
2720 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2721 bss->wmm_uapsd = atoi(pos);
2722 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2723 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2724 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
2725 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
2729 } else if (os_strcmp(buf, "bss") == 0) {
2730 if (hostapd_config_bss(conf, pos)) {
2731 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
2735 } else if (os_strcmp(buf, "bssid") == 0) {
2736 if (hwaddr_aton(pos, bss->bssid)) {
2737 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
2741 #ifdef CONFIG_IEEE80211W
2742 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2743 bss->ieee80211w = atoi(pos);
2744 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
2745 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
2746 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
2747 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
2748 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
2749 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
2750 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
2751 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
2752 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
2754 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
2758 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2759 bss->assoc_sa_query_max_timeout = atoi(pos);
2760 if (bss->assoc_sa_query_max_timeout == 0) {
2761 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
2765 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
2766 bss->assoc_sa_query_retry_timeout = atoi(pos);
2767 if (bss->assoc_sa_query_retry_timeout == 0) {
2768 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
2772 #endif /* CONFIG_IEEE80211W */
2773 #ifdef CONFIG_IEEE80211N
2774 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2775 conf->ieee80211n = atoi(pos);
2776 } else if (os_strcmp(buf, "ht_capab") == 0) {
2777 if (hostapd_config_ht_capab(conf, pos) < 0) {
2778 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
2782 } else if (os_strcmp(buf, "require_ht") == 0) {
2783 conf->require_ht = atoi(pos);
2784 } else if (os_strcmp(buf, "obss_interval") == 0) {
2785 conf->obss_interval = atoi(pos);
2786 #endif /* CONFIG_IEEE80211N */
2787 #ifdef CONFIG_IEEE80211AC
2788 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2789 conf->ieee80211ac = atoi(pos);
2790 } else if (os_strcmp(buf, "vht_capab") == 0) {
2791 if (hostapd_config_vht_capab(conf, pos) < 0) {
2792 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
2796 } else if (os_strcmp(buf, "require_vht") == 0) {
2797 conf->require_vht = atoi(pos);
2798 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2799 conf->vht_oper_chwidth = atoi(pos);
2800 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
2801 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2802 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
2803 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
2804 } else if (os_strcmp(buf, "vendor_vht") == 0) {
2805 bss->vendor_vht = atoi(pos);
2806 #endif /* CONFIG_IEEE80211AC */
2807 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2808 bss->max_listen_interval = atoi(pos);
2809 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2810 bss->disable_pmksa_caching = atoi(pos);
2811 } else if (os_strcmp(buf, "okc") == 0) {
2812 bss->okc = atoi(pos);
2814 } else if (os_strcmp(buf, "wps_state") == 0) {
2815 bss->wps_state = atoi(pos);
2816 if (bss->wps_state < 0 || bss->wps_state > 2) {
2817 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
2821 } else if (os_strcmp(buf, "wps_independent") == 0) {
2822 bss->wps_independent = atoi(pos);
2823 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2824 bss->ap_setup_locked = atoi(pos);
2825 } else if (os_strcmp(buf, "uuid") == 0) {
2826 if (uuid_str2bin(pos, bss->uuid)) {
2827 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2830 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2831 os_free(bss->wps_pin_requests);
2832 bss->wps_pin_requests = os_strdup(pos);
2833 } else if (os_strcmp(buf, "device_name") == 0) {
2834 if (os_strlen(pos) > 32) {
2835 wpa_printf(MSG_ERROR, "Line %d: Too long "
2836 "device_name", line);
2839 os_free(bss->device_name);
2840 bss->device_name = os_strdup(pos);
2841 } else if (os_strcmp(buf, "manufacturer") == 0) {
2842 if (os_strlen(pos) > 64) {
2843 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
2847 os_free(bss->manufacturer);
2848 bss->manufacturer = os_strdup(pos);
2849 } else if (os_strcmp(buf, "model_name") == 0) {
2850 if (os_strlen(pos) > 32) {
2851 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
2855 os_free(bss->model_name);
2856 bss->model_name = os_strdup(pos);
2857 } else if (os_strcmp(buf, "model_number") == 0) {
2858 if (os_strlen(pos) > 32) {
2859 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
2863 os_free(bss->model_number);
2864 bss->model_number = os_strdup(pos);
2865 } else if (os_strcmp(buf, "serial_number") == 0) {
2866 if (os_strlen(pos) > 32) {
2867 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
2871 os_free(bss->serial_number);
2872 bss->serial_number = os_strdup(pos);
2873 } else if (os_strcmp(buf, "device_type") == 0) {
2874 if (wps_dev_type_str2bin(pos, bss->device_type))
2876 } else if (os_strcmp(buf, "config_methods") == 0) {
2877 os_free(bss->config_methods);
2878 bss->config_methods = os_strdup(pos);
2879 } else if (os_strcmp(buf, "os_version") == 0) {
2880 if (hexstr2bin(pos, bss->os_version, 4)) {
2881 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
2885 } else if (os_strcmp(buf, "ap_pin") == 0) {
2886 os_free(bss->ap_pin);
2887 bss->ap_pin = os_strdup(pos);
2888 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2889 bss->skip_cred_build = atoi(pos);
2890 } else if (os_strcmp(buf, "extra_cred") == 0) {
2891 os_free(bss->extra_cred);
2892 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
2893 if (bss->extra_cred == NULL) {
2894 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
2898 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2899 bss->wps_cred_processing = atoi(pos);
2900 } else if (os_strcmp(buf, "ap_settings") == 0) {
2901 os_free(bss->ap_settings);
2903 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2904 if (bss->ap_settings == NULL) {
2905 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
2909 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2910 os_free(bss->upnp_iface);
2911 bss->upnp_iface = os_strdup(pos);
2912 } else if (os_strcmp(buf, "friendly_name") == 0) {
2913 os_free(bss->friendly_name);
2914 bss->friendly_name = os_strdup(pos);
2915 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2916 os_free(bss->manufacturer_url);
2917 bss->manufacturer_url = os_strdup(pos);
2918 } else if (os_strcmp(buf, "model_description") == 0) {
2919 os_free(bss->model_description);
2920 bss->model_description = os_strdup(pos);
2921 } else if (os_strcmp(buf, "model_url") == 0) {
2922 os_free(bss->model_url);
2923 bss->model_url = os_strdup(pos);
2924 } else if (os_strcmp(buf, "upc") == 0) {
2926 bss->upc = os_strdup(pos);
2927 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2928 bss->pbc_in_m1 = atoi(pos);
2929 } else if (os_strcmp(buf, "server_id") == 0) {
2930 os_free(bss->server_id);
2931 bss->server_id = os_strdup(pos);
2932 #ifdef CONFIG_WPS_NFC
2933 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2934 bss->wps_nfc_dev_pw_id = atoi(pos);
2935 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2936 bss->wps_nfc_dev_pw_id > 0xffff) {
2937 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
2941 bss->wps_nfc_pw_from_config = 1;
2942 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2943 wpabuf_free(bss->wps_nfc_dh_pubkey);
2944 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2945 bss->wps_nfc_pw_from_config = 1;
2946 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2947 wpabuf_free(bss->wps_nfc_dh_privkey);
2948 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2949 bss->wps_nfc_pw_from_config = 1;
2950 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2951 wpabuf_free(bss->wps_nfc_dev_pw);
2952 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2953 bss->wps_nfc_pw_from_config = 1;
2954 #endif /* CONFIG_WPS_NFC */
2955 #endif /* CONFIG_WPS */
2956 #ifdef CONFIG_P2P_MANAGER
2957 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2959 bss->p2p |= P2P_MANAGE;
2961 bss->p2p &= ~P2P_MANAGE;
2962 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2964 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2966 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
2967 #endif /* CONFIG_P2P_MANAGER */
2968 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2969 bss->disassoc_low_ack = atoi(pos);
2970 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2972 bss->tdls |= TDLS_PROHIBIT;
2974 bss->tdls &= ~TDLS_PROHIBIT;
2975 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2977 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2979 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
2980 #ifdef CONFIG_RSN_TESTING
2981 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2982 extern int rsn_testing;
2983 rsn_testing = atoi(pos);
2984 #endif /* CONFIG_RSN_TESTING */
2985 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2986 bss->time_advertisement = atoi(pos);
2987 } else if (os_strcmp(buf, "time_zone") == 0) {
2988 size_t tz_len = os_strlen(pos);
2989 if (tz_len < 4 || tz_len > 255) {
2990 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
2994 os_free(bss->time_zone);
2995 bss->time_zone = os_strdup(pos);
2996 if (bss->time_zone == NULL)
2999 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3000 bss->wnm_sleep_mode = atoi(pos);
3001 } else if (os_strcmp(buf, "bss_transition") == 0) {
3002 bss->bss_transition = atoi(pos);
3003 #endif /* CONFIG_WNM */
3004 #ifdef CONFIG_INTERWORKING
3005 } else if (os_strcmp(buf, "interworking") == 0) {
3006 bss->interworking = atoi(pos);
3007 } else if (os_strcmp(buf, "access_network_type") == 0) {
3008 bss->access_network_type = atoi(pos);
3009 if (bss->access_network_type < 0 ||
3010 bss->access_network_type > 15) {
3011 wpa_printf(MSG_ERROR,
3012 "Line %d: invalid access_network_type",
3016 } else if (os_strcmp(buf, "internet") == 0) {
3017 bss->internet = atoi(pos);
3018 } else if (os_strcmp(buf, "asra") == 0) {
3019 bss->asra = atoi(pos);
3020 } else if (os_strcmp(buf, "esr") == 0) {
3021 bss->esr = atoi(pos);
3022 } else if (os_strcmp(buf, "uesa") == 0) {
3023 bss->uesa = atoi(pos);
3024 } else if (os_strcmp(buf, "venue_group") == 0) {
3025 bss->venue_group = atoi(pos);
3026 bss->venue_info_set = 1;
3027 } else if (os_strcmp(buf, "venue_type") == 0) {
3028 bss->venue_type = atoi(pos);
3029 bss->venue_info_set = 1;
3030 } else if (os_strcmp(buf, "hessid") == 0) {
3031 if (hwaddr_aton(pos, bss->hessid)) {
3032 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3035 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3036 if (parse_roaming_consortium(bss, pos, line) < 0)
3038 } else if (os_strcmp(buf, "venue_name") == 0) {
3039 if (parse_venue_name(bss, pos, line) < 0)
3041 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3043 u16 redirect_url_len;
3044 if (hexstr2bin(pos, &auth_type, 1)) {
3045 wpa_printf(MSG_ERROR,
3046 "Line %d: Invalid network_auth_type '%s'",
3050 if (auth_type == 0 || auth_type == 2)
3051 redirect_url_len = os_strlen(pos + 2);
3053 redirect_url_len = 0;
3054 os_free(bss->network_auth_type);
3055 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3056 if (bss->network_auth_type == NULL)
3058 *bss->network_auth_type = auth_type;
3059 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3060 if (redirect_url_len)
3061 os_memcpy(bss->network_auth_type + 3, pos + 2,
3063 bss->network_auth_type_len = 3 + redirect_url_len;
3064 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3065 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3066 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3068 bss->ipaddr_type_configured = 0;
3071 bss->ipaddr_type_configured = 1;
3072 } else if (os_strcmp(buf, "domain_name") == 0) {
3073 int j, num_domains, domain_len, domain_list_len = 0;
3074 char *tok_start, *tok_prev;
3075 u8 *domain_list, *domain_ptr;
3077 domain_list_len = os_strlen(pos) + 1;
3078 domain_list = os_malloc(domain_list_len);
3079 if (domain_list == NULL)
3082 domain_ptr = domain_list;
3085 while ((tok_prev = os_strchr(tok_prev, ','))) {
3090 for (j = 0; j < num_domains; j++) {
3091 tok_start = os_strchr(tok_prev, ',');
3093 domain_len = tok_start - tok_prev;
3094 *domain_ptr = domain_len;
3095 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3096 domain_ptr += domain_len + 1;
3097 tok_prev = ++tok_start;
3099 domain_len = os_strlen(tok_prev);
3100 *domain_ptr = domain_len;
3101 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3102 domain_ptr += domain_len + 1;
3106 os_free(bss->domain_name);
3107 bss->domain_name = domain_list;
3108 bss->domain_name_len = domain_list_len;
3109 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3110 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3112 } else if (os_strcmp(buf, "nai_realm") == 0) {
3113 if (parse_nai_realm(bss, pos, line) < 0)
3115 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
3116 bss->gas_frag_limit = atoi(pos);
3117 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3118 bss->gas_comeback_delay = atoi(pos);
3119 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3120 if (parse_qos_map_set(bss, pos, line) < 0)
3122 #endif /* CONFIG_INTERWORKING */
3123 #ifdef CONFIG_RADIUS_TEST
3124 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3125 os_free(bss->dump_msk_file);
3126 bss->dump_msk_file = os_strdup(pos);
3127 #endif /* CONFIG_RADIUS_TEST */
3129 } else if (os_strcmp(buf, "hs20") == 0) {
3130 bss->hs20 = atoi(pos);
3131 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3132 bss->disable_dgaf = atoi(pos);
3133 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3134 bss->proxy_arp = atoi(pos);
3135 } else if (os_strcmp(buf, "osen") == 0) {
3136 bss->osen = atoi(pos);
3137 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3138 bss->anqp_domain_id = atoi(pos);
3139 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3140 bss->hs20_deauth_req_timeout = atoi(pos);
3141 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3142 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3144 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3145 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3147 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3148 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3151 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3153 size_t oper_class_len;
3154 oper_class_len = os_strlen(pos);
3155 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3156 wpa_printf(MSG_ERROR,
3157 "Line %d: Invalid hs20_operating_class '%s'",
3161 oper_class_len /= 2;
3162 oper_class = os_malloc(oper_class_len);
3163 if (oper_class == NULL)
3165 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3166 wpa_printf(MSG_ERROR,
3167 "Line %d: Invalid hs20_operating_class '%s'",
3169 os_free(oper_class);
3172 os_free(bss->hs20_operating_class);
3173 bss->hs20_operating_class = oper_class;
3174 bss->hs20_operating_class_len = oper_class_len;
3175 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3176 if (hs20_parse_icon(bss, pos) < 0) {
3177 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3181 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3182 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
3184 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3185 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
3187 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3188 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
3190 } else if (os_strcmp(buf, "osu_nai") == 0) {
3191 if (hs20_parse_osu_nai(bss, pos, line) < 0)
3193 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3194 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
3196 } else if (os_strcmp(buf, "osu_icon") == 0) {
3197 if (hs20_parse_osu_icon(bss, pos, line) < 0)
3199 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3200 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
3202 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3203 os_free(bss->subscr_remediation_url);
3204 bss->subscr_remediation_url = os_strdup(pos);
3205 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3206 bss->subscr_remediation_method = atoi(pos);
3207 #endif /* CONFIG_HS20 */
3208 #ifdef CONFIG_TESTING_OPTIONS
3209 #define PARSE_TEST_PROBABILITY(_val) \
3210 } else if (os_strcmp(buf, #_val) == 0) { \
3213 conf->_val = strtod(pos, &end); \
3214 if (*end || conf->_val < 0.0 || \
3215 conf->_val > 1.0) { \
3216 wpa_printf(MSG_ERROR, \
3217 "Line %d: Invalid value '%s'", \
3221 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3222 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3223 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3224 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3225 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
3226 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3227 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3228 pos = os_strchr(pos, ':');
3230 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3235 bss->bss_load_test[2] = atoi(pos);
3236 pos = os_strchr(pos, ':');
3238 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3243 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3244 bss->bss_load_test_set = 1;
3245 } else if (os_strcmp(buf, "radio_measurements") == 0) {
3246 bss->radio_measurements = atoi(pos);
3247 #endif /* CONFIG_TESTING_OPTIONS */
3248 } else if (os_strcmp(buf, "vendor_elements") == 0) {
3249 struct wpabuf *elems;
3250 size_t len = os_strlen(pos);
3252 wpa_printf(MSG_ERROR,
3253 "Line %d: Invalid vendor_elements '%s'",
3259 wpabuf_free(bss->vendor_elements);
3260 bss->vendor_elements = NULL;
3264 elems = wpabuf_alloc(len);
3268 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
3270 wpa_printf(MSG_ERROR,
3271 "Line %d: Invalid vendor_elements '%s'",
3276 wpabuf_free(bss->vendor_elements);
3277 bss->vendor_elements = elems;
3278 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3279 bss->sae_anti_clogging_threshold = atoi(pos);
3280 } else if (os_strcmp(buf, "sae_groups") == 0) {
3281 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3282 wpa_printf(MSG_ERROR,
3283 "Line %d: Invalid sae_groups value '%s'",
3287 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3288 int val = atoi(pos);
3289 if (val < 0 || val > 255) {
3290 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3294 conf->local_pwr_constraint = val;
3295 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3296 conf->spectrum_mgmt_required = atoi(pos);
3297 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3298 os_free(bss->wowlan_triggers);
3299 bss->wowlan_triggers = os_strdup(pos);
3301 wpa_printf(MSG_ERROR,
3302 "Line %d: unknown configuration item '%s'",
3312 * hostapd_config_read - Read and parse a configuration file
3313 * @fname: Configuration file name (including path, if needed)
3314 * Returns: Allocated configuration data structure
3316 struct hostapd_config * hostapd_config_read(const char *fname)
3318 struct hostapd_config *conf;
3320 char buf[512], *pos;
3325 f = fopen(fname, "r");
3327 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3328 "for reading.", fname);
3332 conf = hostapd_config_defaults();
3338 /* set default driver based on configuration */
3339 conf->driver = wpa_drivers[0];
3340 if (conf->driver == NULL) {
3341 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3342 hostapd_config_free(conf);
3347 conf->last_bss = conf->bss[0];
3349 while (fgets(buf, sizeof(buf), f)) {
3350 struct hostapd_bss_config *bss;
3352 bss = conf->last_bss;
3358 while (*pos != '\0') {
3368 pos = os_strchr(buf, '=');
3370 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3377 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3382 for (i = 0; i < conf->num_bss; i++)
3383 hostapd_set_security_params(conf->bss[i], 1);
3385 if (hostapd_config_check(conf, 1))
3388 #ifndef WPA_IGNORE_CONFIG_ERRORS
3390 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3391 "'%s'", errors, fname);
3392 hostapd_config_free(conf);
3395 #endif /* WPA_IGNORE_CONFIG_ERRORS */
3401 int hostapd_set_iface(struct hostapd_config *conf,
3402 struct hostapd_bss_config *bss, char *field, char *value)
3407 errors = hostapd_config_fill(conf, bss, field, value, 0);
3409 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3410 "to value '%s'", field, value);
3414 for (i = 0; i < conf->num_bss; i++)
3415 hostapd_set_security_params(conf->bss[i], 0);
3417 if (hostapd_config_check(conf, 0)) {
3418 wpa_printf(MSG_ERROR, "Configuration check failed");