2 * hostapd / Configuration file parser
3 * Copyright (c) 2003-2012, 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_malloc(sizeof(*vlan));
88 wpa_printf(MSG_ERROR, "Out of memory while reading "
89 "VLAN interfaces from '%s'", fname);
94 os_memset(vlan, 0, sizeof(*vlan));
95 vlan->vlan_id = vlan_id;
96 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
98 bss->vlan_tail->next = vlan;
101 bss->vlan_tail = vlan;
108 #endif /* CONFIG_NO_VLAN */
111 static int hostapd_acl_comp(const void *a, const void *b)
113 const struct mac_acl_entry *aa = a;
114 const struct mac_acl_entry *bb = b;
115 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
119 static int hostapd_config_read_maclist(const char *fname,
120 struct mac_acl_entry **acl, int *num)
126 struct mac_acl_entry *newacl;
132 f = fopen(fname, "r");
134 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
138 while (fgets(buf, sizeof(buf), f)) {
144 while (*pos != '\0') {
154 if (hwaddr_aton(buf, addr)) {
155 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
156 "line %d in '%s'", buf, line, fname);
163 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
165 while (*pos == ' ' || *pos == '\t')
170 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
171 if (newacl == NULL) {
172 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
178 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
179 (*acl)[*num].vlan_id = vlan_id;
185 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
192 static int hostapd_config_read_eap_user(const char *fname,
193 struct hostapd_bss_config *conf)
196 char buf[512], *pos, *start, *pos2;
197 int line = 0, ret = 0, num_methods;
198 struct hostapd_eap_user *user, *tail = NULL;
203 if (os_strncmp(fname, "sqlite:", 7) == 0) {
204 os_free(conf->eap_user_sqlite);
205 conf->eap_user_sqlite = os_strdup(fname + 7);
209 f = fopen(fname, "r");
211 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
215 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
216 while (fgets(buf, sizeof(buf), f)) {
222 while (*pos != '\0') {
234 if (buf[0] != '"' && buf[0] != '*') {
235 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
236 "start) on line %d in '%s'", line, fname);
240 user = os_zalloc(sizeof(*user));
242 wpa_printf(MSG_ERROR, "EAP user allocation failed");
245 user->force_version = -1;
252 while (*pos != '"' && *pos != '\0')
255 wpa_printf(MSG_ERROR, "Invalid EAP identity "
256 "(no \" in end) on line %d in '%s'",
261 user->identity = os_malloc(pos - start);
262 if (user->identity == NULL) {
263 wpa_printf(MSG_ERROR, "Failed to allocate "
264 "memory for EAP identity");
267 os_memcpy(user->identity, start, pos - start);
268 user->identity_len = pos - start;
270 if (pos[0] == '"' && pos[1] == '*') {
271 user->wildcard_prefix = 1;
276 while (*pos == ' ' || *pos == '\t')
280 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
281 "'%s'", line, fname);
286 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
296 char *pos3 = os_strchr(start, ',');
300 user->methods[num_methods].method =
303 &user->methods[num_methods].vendor);
304 if (user->methods[num_methods].vendor ==
306 user->methods[num_methods].method == EAP_TYPE_NONE)
308 if (os_strcmp(start, "TTLS-PAP") == 0) {
309 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
312 if (os_strcmp(start, "TTLS-CHAP") == 0) {
313 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
316 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
318 EAP_TTLS_AUTH_MSCHAP;
321 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
323 EAP_TTLS_AUTH_MSCHAPV2;
326 wpa_printf(MSG_ERROR, "Unsupported EAP type "
327 "'%s' on line %d in '%s'",
333 if (num_methods >= EAP_MAX_METHODS)
340 if (num_methods == 0 && user->ttls_auth == 0) {
341 wpa_printf(MSG_ERROR, "No EAP types configured on "
342 "line %d in '%s'", line, fname);
349 while (*pos == ' ' || *pos == '\t')
354 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
355 user->force_version = 0;
359 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
360 user->force_version = 1;
364 if (os_strncmp(pos, "[2]", 3) == 0) {
372 while (*pos != '"' && *pos != '\0')
375 wpa_printf(MSG_ERROR, "Invalid EAP password "
376 "(no \" in end) on line %d in '%s'",
381 user->password = os_malloc(pos - start);
382 if (user->password == NULL) {
383 wpa_printf(MSG_ERROR, "Failed to allocate "
384 "memory for EAP password");
387 os_memcpy(user->password, start, pos - start);
388 user->password_len = pos - start;
391 } else if (os_strncmp(pos, "hash:", 5) == 0) {
394 while (*pos2 != '\0' && *pos2 != ' ' &&
395 *pos2 != '\t' && *pos2 != '#')
397 if (pos2 - pos != 32) {
398 wpa_printf(MSG_ERROR, "Invalid password hash "
399 "on line %d in '%s'", line, fname);
402 user->password = os_malloc(16);
403 if (user->password == NULL) {
404 wpa_printf(MSG_ERROR, "Failed to allocate "
405 "memory for EAP password hash");
408 if (hexstr2bin(pos, user->password, 16) < 0) {
409 wpa_printf(MSG_ERROR, "Invalid hash password "
410 "on line %d in '%s'", line, fname);
413 user->password_len = 16;
414 user->password_hash = 1;
418 while (*pos2 != '\0' && *pos2 != ' ' &&
419 *pos2 != '\t' && *pos2 != '#')
421 if ((pos2 - pos) & 1) {
422 wpa_printf(MSG_ERROR, "Invalid hex password "
423 "on line %d in '%s'", line, fname);
426 user->password = os_malloc((pos2 - pos) / 2);
427 if (user->password == NULL) {
428 wpa_printf(MSG_ERROR, "Failed to allocate "
429 "memory for EAP password");
432 if (hexstr2bin(pos, user->password,
433 (pos2 - pos) / 2) < 0) {
434 wpa_printf(MSG_ERROR, "Invalid hex password "
435 "on line %d in '%s'", line, fname);
438 user->password_len = (pos2 - pos) / 2;
442 while (*pos == ' ' || *pos == '\t')
444 if (os_strncmp(pos, "[2]", 3) == 0) {
450 tail = conf->eap_user = user;
459 os_free(user->password);
460 os_free(user->identity);
471 #endif /* EAP_SERVER */
474 #ifndef CONFIG_NO_RADIUS
476 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
477 int *num_server, const char *val, int def_port,
478 struct hostapd_radius_server **curr_serv)
480 struct hostapd_radius_server *nserv;
482 static int server_index = 1;
484 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
489 nserv = &nserv[*num_server];
491 (*curr_serv) = nserv;
493 os_memset(nserv, 0, sizeof(*nserv));
494 nserv->port = def_port;
495 ret = hostapd_parse_ip_addr(val, &nserv->addr);
496 nserv->index = server_index++;
502 static struct hostapd_radius_attr *
503 hostapd_parse_radius_attr(const char *value)
507 struct hostapd_radius_attr *attr;
510 attr = os_zalloc(sizeof(*attr));
514 attr->type = atoi(value);
516 pos = os_strchr(value, ':');
518 attr->val = wpabuf_alloc(1);
519 if (attr->val == NULL) {
523 wpabuf_put_u8(attr->val, 0);
528 if (pos[0] == '\0' || pos[1] != ':') {
537 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
540 len = os_strlen(pos);
544 attr->val = wpabuf_alloc(len);
545 if (attr->val == NULL)
547 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
548 wpabuf_free(attr->val);
554 attr->val = wpabuf_alloc(4);
556 wpabuf_put_be32(attr->val, atoi(pos));
563 if (attr->val == NULL) {
572 static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
577 secret = os_strchr(val, ' ');
583 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
586 os_free(bss->radius_das_shared_secret);
587 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
588 if (bss->radius_das_shared_secret == NULL)
590 bss->radius_das_shared_secret_len = os_strlen(secret);
594 #endif /* CONFIG_NO_RADIUS */
597 static int hostapd_config_parse_key_mgmt(int line, const char *value)
600 char *start, *end, *buf;
602 buf = os_strdup(value);
607 while (*start != '\0') {
608 while (*start == ' ' || *start == '\t')
613 while (*end != ' ' && *end != '\t' && *end != '\0')
617 if (os_strcmp(start, "WPA-PSK") == 0)
618 val |= WPA_KEY_MGMT_PSK;
619 else if (os_strcmp(start, "WPA-EAP") == 0)
620 val |= WPA_KEY_MGMT_IEEE8021X;
621 #ifdef CONFIG_IEEE80211R
622 else if (os_strcmp(start, "FT-PSK") == 0)
623 val |= WPA_KEY_MGMT_FT_PSK;
624 else if (os_strcmp(start, "FT-EAP") == 0)
625 val |= WPA_KEY_MGMT_FT_IEEE8021X;
626 #endif /* CONFIG_IEEE80211R */
627 #ifdef CONFIG_IEEE80211W
628 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
629 val |= WPA_KEY_MGMT_PSK_SHA256;
630 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
631 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
632 #endif /* CONFIG_IEEE80211W */
634 else if (os_strcmp(start, "SAE") == 0)
635 val |= WPA_KEY_MGMT_SAE;
636 else if (os_strcmp(start, "FT-SAE") == 0)
637 val |= WPA_KEY_MGMT_FT_SAE;
638 #endif /* CONFIG_SAE */
640 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
653 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
654 "configured.", line);
662 static int hostapd_config_parse_cipher(int line, const char *value)
665 char *start, *end, *buf;
667 buf = os_strdup(value);
672 while (*start != '\0') {
673 while (*start == ' ' || *start == '\t')
678 while (*end != ' ' && *end != '\t' && *end != '\0')
682 if (os_strcmp(start, "CCMP") == 0)
683 val |= WPA_CIPHER_CCMP;
684 else if (os_strcmp(start, "GCMP") == 0)
685 val |= WPA_CIPHER_GCMP;
686 else if (os_strcmp(start, "TKIP") == 0)
687 val |= WPA_CIPHER_TKIP;
688 else if (os_strcmp(start, "WEP104") == 0)
689 val |= WPA_CIPHER_WEP104;
690 else if (os_strcmp(start, "WEP40") == 0)
691 val |= WPA_CIPHER_WEP40;
692 else if (os_strcmp(start, "NONE") == 0)
693 val |= WPA_CIPHER_NONE;
695 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
708 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
716 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
719 size_t len = os_strlen(val);
721 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
725 if (len < 2 || val[len - 1] != '"')
728 wep->key[keyidx] = os_malloc(len);
729 if (wep->key[keyidx] == NULL)
731 os_memcpy(wep->key[keyidx], val + 1, len);
732 wep->len[keyidx] = len;
737 wep->key[keyidx] = os_malloc(len);
738 if (wep->key[keyidx] == NULL)
740 wep->len[keyidx] = len;
741 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
751 static int hostapd_parse_rates(int **rate_list, char *val)
762 while (*pos != '\0') {
768 list = os_malloc(sizeof(int) * (count + 2));
773 while (*pos != '\0') {
774 end = os_strchr(pos, ' ');
778 list[count++] = atoi(pos);
790 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
792 struct hostapd_bss_config *bss;
797 bss = os_realloc_array(conf->bss, conf->num_bss + 1,
798 sizeof(struct hostapd_bss_config));
800 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
806 bss = &(conf->bss[conf->num_bss]);
807 os_memset(bss, 0, sizeof(*bss));
808 bss->radius = os_zalloc(sizeof(*bss->radius));
809 if (bss->radius == NULL) {
810 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
811 "multi-BSS RADIUS data");
816 conf->last_bss = bss;
818 hostapd_config_defaults_bss(bss);
819 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
820 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
826 /* convert floats with one decimal place to value*10 int, i.e.,
827 * "1.5" will return 15 */
828 static int hostapd_config_read_int10(const char *value)
834 pos = os_strchr(value, '.');
838 if (*pos >= '0' && *pos <= '9')
846 static int valid_cw(int cw)
848 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
849 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
854 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
855 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
856 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
857 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
860 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
865 struct hostapd_tx_queue_params *queue;
867 /* skip 'tx_queue_' prefix */
869 if (os_strncmp(pos, "data", 4) == 0 &&
870 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
873 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
874 os_strncmp(pos, "beacon_", 7) == 0) {
875 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
878 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
882 if (num >= NUM_TX_QUEUES) {
883 /* for backwards compatibility, do not trigger failure */
884 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
888 queue = &conf->tx_queue[num];
890 if (os_strcmp(pos, "aifs") == 0) {
891 queue->aifs = atoi(val);
892 if (queue->aifs < 0 || queue->aifs > 255) {
893 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
897 } else if (os_strcmp(pos, "cwmin") == 0) {
898 queue->cwmin = atoi(val);
899 if (!valid_cw(queue->cwmin)) {
900 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
904 } else if (os_strcmp(pos, "cwmax") == 0) {
905 queue->cwmax = atoi(val);
906 if (!valid_cw(queue->cwmax)) {
907 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
911 } else if (os_strcmp(pos, "burst") == 0) {
912 queue->burst = hostapd_config_read_int10(val);
914 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
922 #ifdef CONFIG_IEEE80211R
923 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
925 struct ft_remote_r0kh *r0kh;
928 r0kh = os_zalloc(sizeof(*r0kh));
932 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
934 next = os_strchr(pos, ' ');
937 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
938 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
944 next = os_strchr(pos, ' ');
947 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
948 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
952 r0kh->id_len = next - pos - 1;
953 os_memcpy(r0kh->id, pos, r0kh->id_len);
956 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
957 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
962 r0kh->next = bss->r0kh_list;
963 bss->r0kh_list = r0kh;
969 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
971 struct ft_remote_r1kh *r1kh;
974 r1kh = os_zalloc(sizeof(*r1kh));
978 /* 02:01:02:03:04:05 02:01:02:03:04:05
979 * 000102030405060708090a0b0c0d0e0f */
981 next = os_strchr(pos, ' ');
984 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
985 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
991 next = os_strchr(pos, ' ');
994 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
995 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1001 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1002 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1007 r1kh->next = bss->r1kh_list;
1008 bss->r1kh_list = r1kh;
1012 #endif /* CONFIG_IEEE80211R */
1015 #ifdef CONFIG_IEEE80211N
1016 static int hostapd_config_ht_capab(struct hostapd_config *conf,
1019 if (os_strstr(capab, "[LDPC]"))
1020 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1021 if (os_strstr(capab, "[HT40-]")) {
1022 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1023 conf->secondary_channel = -1;
1025 if (os_strstr(capab, "[HT40+]")) {
1026 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1027 conf->secondary_channel = 1;
1029 if (os_strstr(capab, "[SMPS-STATIC]")) {
1030 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1031 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1033 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1034 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1035 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1037 if (os_strstr(capab, "[GF]"))
1038 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1039 if (os_strstr(capab, "[SHORT-GI-20]"))
1040 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1041 if (os_strstr(capab, "[SHORT-GI-40]"))
1042 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1043 if (os_strstr(capab, "[TX-STBC]"))
1044 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1045 if (os_strstr(capab, "[RX-STBC1]")) {
1046 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1047 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1049 if (os_strstr(capab, "[RX-STBC12]")) {
1050 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1051 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1053 if (os_strstr(capab, "[RX-STBC123]")) {
1054 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1055 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1057 if (os_strstr(capab, "[DELAYED-BA]"))
1058 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1059 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1060 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1061 if (os_strstr(capab, "[DSSS_CCK-40]"))
1062 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1063 if (os_strstr(capab, "[PSMP]"))
1064 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1065 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1066 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1070 #endif /* CONFIG_IEEE80211N */
1073 #ifdef CONFIG_IEEE80211AC
1074 static int hostapd_config_vht_capab(struct hostapd_config *conf,
1077 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1078 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1079 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1080 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1081 if (os_strstr(capab, "[VHT160]"))
1082 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1083 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1084 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1085 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1086 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1087 if (os_strstr(capab, "[RXLDPC]"))
1088 conf->vht_capab |= VHT_CAP_RXLDPC;
1089 if (os_strstr(capab, "[SHORT-GI-80]"))
1090 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1091 if (os_strstr(capab, "[SHORT-GI-160]"))
1092 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1093 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1094 conf->vht_capab |= VHT_CAP_TXSTBC;
1095 if (os_strstr(capab, "[RX-STBC-1]"))
1096 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1097 if (os_strstr(capab, "[RX-STBC-12]"))
1098 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1099 if (os_strstr(capab, "[RX-STBC-123]"))
1100 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1101 if (os_strstr(capab, "[RX-STBC-1234]"))
1102 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1103 if (os_strstr(capab, "[SU-BEAMFORMER]"))
1104 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1105 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
1106 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1107 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
1108 (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
1109 conf->vht_capab |= VHT_CAP_BEAMFORMER_ANTENNAS_MAX;
1110 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
1111 (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
1112 conf->vht_capab |= VHT_CAP_SOUNDING_DIMENTION_MAX;
1113 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1114 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1115 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1116 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1117 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1118 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1119 if (os_strstr(capab, "[HTC-VHT]"))
1120 conf->vht_capab |= VHT_CAP_HTC_VHT;
1121 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
1122 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
1123 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1124 (conf->vht_capab & VHT_CAP_HTC_VHT))
1125 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1126 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1127 (conf->vht_capab & VHT_CAP_HTC_VHT))
1128 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1129 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1130 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1131 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1132 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1135 #endif /* CONFIG_IEEE80211AC */
1138 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
1139 struct hostapd_config *conf)
1141 if (bss->ieee802_1x && !bss->eap_server &&
1142 !bss->radius->auth_servers) {
1143 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1144 "EAP authenticator configured).");
1148 if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
1149 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1150 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1151 "RADIUS checking (macaddr_acl=2) enabled.");
1155 if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
1156 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1157 bss->ssid.wpa_psk_file == NULL &&
1158 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1159 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1160 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1161 "is not configured.");
1165 if (hostapd_mac_comp_empty(bss->bssid) != 0) {
1168 for (i = 0; i < conf->num_bss; i++) {
1169 if ((&conf->bss[i] != bss) &&
1170 (hostapd_mac_comp(conf->bss[i].bssid,
1171 bss->bssid) == 0)) {
1172 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1173 " on interface '%s' and '%s'.",
1174 MAC2STR(bss->bssid),
1175 conf->bss[i].iface, bss->iface);
1181 #ifdef CONFIG_IEEE80211R
1182 if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
1183 (bss->nas_identifier == NULL ||
1184 os_strlen(bss->nas_identifier) < 1 ||
1185 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1186 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1187 "nas_identifier to be configured as a 1..48 octet "
1191 #endif /* CONFIG_IEEE80211R */
1193 #ifdef CONFIG_IEEE80211N
1194 if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
1195 bss->disable_11n = 1;
1196 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
1197 "allowed, disabling HT capabilites");
1200 if (conf->ieee80211n &&
1201 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1202 bss->disable_11n = 1;
1203 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1204 "allowed, disabling HT capabilities");
1207 if (conf->ieee80211n && bss->wpa &&
1208 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1209 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP))) {
1210 bss->disable_11n = 1;
1211 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1212 "requires CCMP/GCMP to be enabled, disabling HT "
1215 #endif /* CONFIG_IEEE80211N */
1218 if (bss->wps_state && bss->ignore_broadcast_ssid) {
1219 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1220 "configuration forced WPS to be disabled");
1224 if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
1225 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1230 if (bss->wps_state && bss->wpa &&
1232 !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
1233 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
1234 "WPA2/CCMP forced WPS to be disabled");
1237 #endif /* CONFIG_WPS2 */
1242 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
1243 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1244 "configuration is required for Hotspot 2.0 "
1248 #endif /* CONFIG_HS20 */
1254 static int hostapd_config_check(struct hostapd_config *conf)
1258 if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
1259 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1260 "setting the country_code");
1264 for (i = 0; i < conf->num_bss; i++) {
1265 if (hostapd_config_check_bss(&conf->bss[i], conf))
1273 #ifdef CONFIG_INTERWORKING
1274 static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1277 size_t len = os_strlen(pos);
1278 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1280 struct hostapd_roaming_consortium *rc;
1282 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1283 hexstr2bin(pos, oi, len / 2)) {
1284 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1290 rc = os_realloc_array(bss->roaming_consortium,
1291 bss->roaming_consortium_count + 1,
1292 sizeof(struct hostapd_roaming_consortium));
1296 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1297 rc[bss->roaming_consortium_count].len = len;
1299 bss->roaming_consortium = rc;
1300 bss->roaming_consortium_count++;
1306 static int parse_lang_string(struct hostapd_lang_string **array,
1307 unsigned int *count, char *pos)
1311 struct hostapd_lang_string *ls;
1313 sep = os_strchr(pos, ':');
1318 clen = os_strlen(pos);
1321 nlen = os_strlen(sep);
1325 ls = os_realloc_array(*array, *count + 1,
1326 sizeof(struct hostapd_lang_string));
1331 ls = &(*array)[*count];
1334 os_memset(ls->lang, 0, sizeof(ls->lang));
1335 os_memcpy(ls->lang, pos, clen);
1336 ls->name_len = nlen;
1337 os_memcpy(ls->name, sep, nlen);
1343 static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1346 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1347 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1355 static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1360 u8 *info = NULL, *ipos;
1362 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1365 for (pos = buf; *pos; pos++) {
1366 if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
1371 if (1 + count * 3 > 0x7f)
1374 info = os_zalloc(2 + 3 + count * 3);
1379 *ipos++ = 0; /* GUD - Version 1 */
1380 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1381 *ipos++ = 0; /* PLMN List IEI */
1382 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1383 *ipos++ = 1 + count * 3;
1384 *ipos++ = count; /* Number of PLMNs */
1387 while (pos && *pos) {
1392 mnc = os_strchr(pos, ',');
1396 pos = os_strchr(mnc, ';');
1400 mnc_len = os_strlen(mnc);
1401 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1404 /* BC coded MCC,MNC */
1405 /* MCC digit 2 | MCC digit 1 */
1406 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1407 /* MNC digit 3 | MCC digit 3 */
1408 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1410 /* MNC digit 2 | MNC digit 1 */
1411 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1414 os_free(bss->anqp_3gpp_cell_net);
1415 bss->anqp_3gpp_cell_net = info;
1416 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1417 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1418 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
1423 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1430 static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1432 struct hostapd_nai_realm_data *realm;
1435 char *pos, *end, *rpos;
1437 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1439 if (offsets == NULL)
1442 for (i = 0; i < bss->nai_realm_count; i++) {
1443 realm = &bss->nai_realm_data[i];
1444 for (j = 0; j < MAX_NAI_REALMS; j++) {
1445 offsets[i * MAX_NAI_REALMS + j] =
1447 realm->realm[j] - realm->realm_buf : -1;
1451 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1452 sizeof(struct hostapd_nai_realm_data));
1453 if (realm == NULL) {
1457 bss->nai_realm_data = realm;
1459 /* patch the pointers after realloc */
1460 for (i = 0; i < bss->nai_realm_count; i++) {
1461 realm = &bss->nai_realm_data[i];
1462 for (j = 0; j < MAX_NAI_REALMS; j++) {
1463 int offs = offsets[i * MAX_NAI_REALMS + j];
1465 realm->realm[j] = realm->realm_buf + offs;
1467 realm->realm[j] = NULL;
1472 realm = &bss->nai_realm_data[bss->nai_realm_count];
1473 os_memset(realm, 0, sizeof(*realm));
1476 realm->encoding = atoi(pos);
1477 pos = os_strchr(pos, ',');
1482 end = os_strchr(pos, ',');
1487 len = os_strlen(pos);
1490 if (len > MAX_NAI_REALMLEN) {
1491 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1492 "characters)", (int) len, MAX_NAI_REALMLEN);
1495 os_memcpy(realm->realm_buf, pos, len);
1502 while (pos && *pos) {
1503 struct hostapd_nai_realm_eap *eap;
1505 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1506 wpa_printf(MSG_ERROR, "Too many EAP methods");
1510 eap = &realm->eap_method[realm->eap_method_count];
1511 realm->eap_method_count++;
1513 end = os_strchr(pos, ',');
1515 end = pos + os_strlen(pos);
1517 eap->eap_method = atoi(pos);
1519 pos = os_strchr(pos, '[');
1520 if (pos == NULL || pos > end)
1523 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1524 wpa_printf(MSG_ERROR, "Too many auth params");
1527 eap->auth_id[eap->num_auths] = atoi(pos);
1528 pos = os_strchr(pos, ':');
1529 if (pos == NULL || pos > end)
1532 eap->auth_val[eap->num_auths] = atoi(pos);
1533 pos = os_strchr(pos, ']');
1534 if (pos == NULL || pos > end)
1546 /* Split realm list into null terminated realms */
1547 rpos = realm->realm_buf;
1550 if (i >= MAX_NAI_REALMS) {
1551 wpa_printf(MSG_ERROR, "Too many realms");
1554 realm->realm[i++] = rpos;
1555 rpos = os_strchr(rpos, ';');
1561 bss->nai_realm_count++;
1566 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1570 #endif /* CONFIG_INTERWORKING */
1574 static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1580 if (bss->hs20_connection_capability_len >= 0xfff0)
1583 conn_cap = os_realloc(bss->hs20_connection_capability,
1584 bss->hs20_connection_capability_len + 4);
1585 if (conn_cap == NULL)
1588 bss->hs20_connection_capability = conn_cap;
1589 conn_cap += bss->hs20_connection_capability_len;
1591 conn_cap[0] = atoi(pos);
1592 pos = os_strchr(pos, ':');
1596 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1597 pos = os_strchr(pos, ':');
1601 conn_cap[3] = atoi(pos);
1602 bss->hs20_connection_capability_len += 4;
1608 static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1614 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1616 wan_metrics = os_zalloc(13);
1617 if (wan_metrics == NULL)
1622 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1629 /* Downlink Speed */
1630 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1631 pos = os_strchr(pos, ':');
1637 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1638 pos = os_strchr(pos, ':');
1644 wan_metrics[9] = atoi(pos);
1645 pos = os_strchr(pos, ':');
1651 wan_metrics[10] = atoi(pos);
1652 pos = os_strchr(pos, ':');
1658 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1660 os_free(bss->hs20_wan_metrics);
1661 bss->hs20_wan_metrics = wan_metrics;
1666 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
1668 os_free(wan_metrics);
1673 static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1674 char *pos, int line)
1676 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1677 &bss->hs20_oper_friendly_name_count, pos)) {
1678 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1679 "hs20_oper_friendly_name '%s'", line, pos);
1684 #endif /* CONFIG_HS20 */
1687 #ifdef CONFIG_WPS_NFC
1688 static struct wpabuf * hostapd_parse_bin(const char *buf)
1693 len = os_strlen(buf);
1698 ret = wpabuf_alloc(len);
1702 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1709 #endif /* CONFIG_WPS_NFC */
1712 static int hostapd_config_fill(struct hostapd_config *conf,
1713 struct hostapd_bss_config *bss,
1714 char *buf, char *pos, int line)
1719 if (os_strcmp(buf, "interface") == 0) {
1720 os_strlcpy(conf->bss[0].iface, pos,
1721 sizeof(conf->bss[0].iface));
1722 } else if (os_strcmp(buf, "bridge") == 0) {
1723 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1724 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1725 os_strlcpy(bss->wds_bridge, pos,
1726 sizeof(bss->wds_bridge));
1727 } else if (os_strcmp(buf, "driver") == 0) {
1729 /* clear to get error below if setting is invalid */
1730 conf->driver = NULL;
1731 for (j = 0; wpa_drivers[j]; j++) {
1732 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
1734 conf->driver = wpa_drivers[j];
1738 if (conf->driver == NULL) {
1739 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1740 "unknown driver '%s'", line, pos);
1743 } else if (os_strcmp(buf, "debug") == 0) {
1744 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1745 "configuration variable is not used "
1747 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1748 bss->logger_syslog_level = atoi(pos);
1749 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1750 bss->logger_stdout_level = atoi(pos);
1751 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1752 bss->logger_syslog = atoi(pos);
1753 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1754 bss->logger_stdout = atoi(pos);
1755 } else if (os_strcmp(buf, "dump_file") == 0) {
1756 bss->dump_log_name = os_strdup(pos);
1757 } else if (os_strcmp(buf, "ssid") == 0) {
1758 bss->ssid.ssid_len = os_strlen(pos);
1759 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1760 bss->ssid.ssid_len < 1) {
1761 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1765 os_memcpy(bss->ssid.ssid, pos,
1766 bss->ssid.ssid_len);
1767 bss->ssid.ssid_set = 1;
1769 } else if (os_strcmp(buf, "ssid2") == 0) {
1771 char *str = wpa_config_parse_string(pos, &slen);
1772 if (str == NULL || slen < 1 ||
1773 slen > HOSTAPD_MAX_SSID_LEN) {
1774 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1778 os_memcpy(bss->ssid.ssid, str, slen);
1779 bss->ssid.ssid_len = slen;
1780 bss->ssid.ssid_set = 1;
1783 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1784 bss->macaddr_acl = atoi(pos);
1785 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1786 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1787 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1788 wpa_printf(MSG_ERROR, "Line %d: unknown "
1790 line, bss->macaddr_acl);
1792 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1793 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1794 &bss->num_accept_mac))
1796 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1797 "read accept_mac_file '%s'",
1801 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1802 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1803 &bss->num_deny_mac)) {
1804 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1805 "read deny_mac_file '%s'",
1809 } else if (os_strcmp(buf, "wds_sta") == 0) {
1810 bss->wds_sta = atoi(pos);
1811 } else if (os_strcmp(buf, "ap_isolate") == 0) {
1812 bss->isolate = atoi(pos);
1813 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1814 bss->ap_max_inactivity = atoi(pos);
1815 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
1816 bss->skip_inactivity_poll = atoi(pos);
1817 } else if (os_strcmp(buf, "country_code") == 0) {
1818 os_memcpy(conf->country, pos, 2);
1819 /* FIX: make this configurable */
1820 conf->country[2] = ' ';
1821 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1822 conf->ieee80211d = atoi(pos);
1823 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1824 bss->ieee802_1x = atoi(pos);
1825 } else if (os_strcmp(buf, "eapol_version") == 0) {
1826 bss->eapol_version = atoi(pos);
1827 if (bss->eapol_version < 1 ||
1828 bss->eapol_version > 2) {
1829 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1830 "version (%d): '%s'.",
1831 line, bss->eapol_version, pos);
1834 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1835 bss->eapol_version);
1837 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1838 bss->eap_server = atoi(pos);
1839 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1840 "eap_authenticator used; this has been "
1841 "renamed to eap_server", line);
1842 } else if (os_strcmp(buf, "eap_server") == 0) {
1843 bss->eap_server = atoi(pos);
1844 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1845 if (hostapd_config_read_eap_user(pos, bss))
1847 } else if (os_strcmp(buf, "ca_cert") == 0) {
1848 os_free(bss->ca_cert);
1849 bss->ca_cert = os_strdup(pos);
1850 } else if (os_strcmp(buf, "server_cert") == 0) {
1851 os_free(bss->server_cert);
1852 bss->server_cert = os_strdup(pos);
1853 } else if (os_strcmp(buf, "private_key") == 0) {
1854 os_free(bss->private_key);
1855 bss->private_key = os_strdup(pos);
1856 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1857 os_free(bss->private_key_passwd);
1858 bss->private_key_passwd = os_strdup(pos);
1859 } else if (os_strcmp(buf, "check_crl") == 0) {
1860 bss->check_crl = atoi(pos);
1861 } else if (os_strcmp(buf, "dh_file") == 0) {
1862 os_free(bss->dh_file);
1863 bss->dh_file = os_strdup(pos);
1864 } else if (os_strcmp(buf, "fragment_size") == 0) {
1865 bss->fragment_size = atoi(pos);
1866 #ifdef EAP_SERVER_FAST
1867 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1868 os_free(bss->pac_opaque_encr_key);
1869 bss->pac_opaque_encr_key = os_malloc(16);
1870 if (bss->pac_opaque_encr_key == NULL) {
1871 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1872 "pac_opaque_encr_key", line);
1874 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1876 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1877 "pac_opaque_encr_key", line);
1880 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1881 size_t idlen = os_strlen(pos);
1883 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1884 "eap_fast_a_id", line);
1887 os_free(bss->eap_fast_a_id);
1888 bss->eap_fast_a_id = os_malloc(idlen / 2);
1889 if (bss->eap_fast_a_id == NULL ||
1890 hexstr2bin(pos, bss->eap_fast_a_id,
1892 wpa_printf(MSG_ERROR, "Line %d: "
1894 "eap_fast_a_id", line);
1897 bss->eap_fast_a_id_len = idlen / 2;
1899 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
1900 os_free(bss->eap_fast_a_id_info);
1901 bss->eap_fast_a_id_info = os_strdup(pos);
1902 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
1903 bss->eap_fast_prov = atoi(pos);
1904 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
1905 bss->pac_key_lifetime = atoi(pos);
1906 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
1907 bss->pac_key_refresh_time = atoi(pos);
1908 #endif /* EAP_SERVER_FAST */
1909 #ifdef EAP_SERVER_SIM
1910 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
1911 os_free(bss->eap_sim_db);
1912 bss->eap_sim_db = os_strdup(pos);
1913 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
1914 bss->eap_sim_aka_result_ind = atoi(pos);
1915 #endif /* EAP_SERVER_SIM */
1916 #ifdef EAP_SERVER_TNC
1917 } else if (os_strcmp(buf, "tnc") == 0) {
1918 bss->tnc = atoi(pos);
1919 #endif /* EAP_SERVER_TNC */
1920 #ifdef EAP_SERVER_PWD
1921 } else if (os_strcmp(buf, "pwd_group") == 0) {
1922 bss->pwd_group = atoi(pos);
1923 #endif /* EAP_SERVER_PWD */
1924 #endif /* EAP_SERVER */
1925 } else if (os_strcmp(buf, "eap_message") == 0) {
1927 bss->eap_req_id_text = os_strdup(pos);
1928 if (bss->eap_req_id_text == NULL) {
1929 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1930 "allocate memory for "
1931 "eap_req_id_text", line);
1935 bss->eap_req_id_text_len =
1936 os_strlen(bss->eap_req_id_text);
1937 term = os_strstr(bss->eap_req_id_text, "\\0");
1940 os_memmove(term, term + 1,
1941 bss->eap_req_id_text_len -
1942 (term - bss->eap_req_id_text) - 1);
1943 bss->eap_req_id_text_len--;
1945 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
1946 bss->default_wep_key_len = atoi(pos);
1947 if (bss->default_wep_key_len > 13) {
1948 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1949 "key len %lu (= %lu bits)", line,
1951 bss->default_wep_key_len,
1953 bss->default_wep_key_len * 8);
1956 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
1957 bss->individual_wep_key_len = atoi(pos);
1958 if (bss->individual_wep_key_len < 0 ||
1959 bss->individual_wep_key_len > 13) {
1960 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
1961 "key len %d (= %d bits)", line,
1962 bss->individual_wep_key_len,
1963 bss->individual_wep_key_len * 8);
1966 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
1967 bss->wep_rekeying_period = atoi(pos);
1968 if (bss->wep_rekeying_period < 0) {
1969 wpa_printf(MSG_ERROR, "Line %d: invalid "
1971 line, bss->wep_rekeying_period);
1974 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
1975 bss->eap_reauth_period = atoi(pos);
1976 if (bss->eap_reauth_period < 0) {
1977 wpa_printf(MSG_ERROR, "Line %d: invalid "
1979 line, bss->eap_reauth_period);
1982 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
1983 bss->eapol_key_index_workaround = atoi(pos);
1985 } else if (os_strcmp(buf, "iapp_interface") == 0) {
1986 bss->ieee802_11f = 1;
1987 os_strlcpy(bss->iapp_iface, pos,
1988 sizeof(bss->iapp_iface));
1989 #endif /* CONFIG_IAPP */
1990 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
1991 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
1992 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
1993 "address '%s'", line, pos);
1996 } else if (os_strcmp(buf, "nas_identifier") == 0) {
1997 bss->nas_identifier = os_strdup(pos);
1998 #ifndef CONFIG_NO_RADIUS
1999 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2000 if (hostapd_config_read_radius_addr(
2001 &bss->radius->auth_servers,
2002 &bss->radius->num_auth_servers, pos, 1812,
2003 &bss->radius->auth_server)) {
2004 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2005 "address '%s'", line, pos);
2008 } else if (bss->radius->auth_server &&
2009 os_strcmp(buf, "auth_server_port") == 0) {
2010 bss->radius->auth_server->port = atoi(pos);
2011 } else if (bss->radius->auth_server &&
2012 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2013 int len = os_strlen(pos);
2015 /* RFC 2865, Ch. 3 */
2016 wpa_printf(MSG_ERROR, "Line %d: empty shared "
2017 "secret is not allowed.", line);
2020 bss->radius->auth_server->shared_secret =
2021 (u8 *) os_strdup(pos);
2022 bss->radius->auth_server->shared_secret_len = len;
2023 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2024 if (hostapd_config_read_radius_addr(
2025 &bss->radius->acct_servers,
2026 &bss->radius->num_acct_servers, pos, 1813,
2027 &bss->radius->acct_server)) {
2028 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2029 "address '%s'", line, pos);
2032 } else if (bss->radius->acct_server &&
2033 os_strcmp(buf, "acct_server_port") == 0) {
2034 bss->radius->acct_server->port = atoi(pos);
2035 } else if (bss->radius->acct_server &&
2036 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2037 int len = os_strlen(pos);
2039 /* RFC 2865, Ch. 3 */
2040 wpa_printf(MSG_ERROR, "Line %d: empty shared "
2041 "secret is not allowed.", line);
2044 bss->radius->acct_server->shared_secret =
2045 (u8 *) os_strdup(pos);
2046 bss->radius->acct_server->shared_secret_len = len;
2047 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
2049 bss->radius->retry_primary_interval = atoi(pos);
2050 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
2052 bss->acct_interim_interval = atoi(pos);
2053 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2054 bss->radius_request_cui = atoi(pos);
2055 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2056 struct hostapd_radius_attr *attr, *a;
2057 attr = hostapd_parse_radius_attr(pos);
2059 wpa_printf(MSG_ERROR, "Line %d: invalid "
2060 "radius_auth_req_attr", line);
2062 } else if (bss->radius_auth_req_attr == NULL) {
2063 bss->radius_auth_req_attr = attr;
2065 a = bss->radius_auth_req_attr;
2070 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2071 struct hostapd_radius_attr *attr, *a;
2072 attr = hostapd_parse_radius_attr(pos);
2074 wpa_printf(MSG_ERROR, "Line %d: invalid "
2075 "radius_acct_req_attr", line);
2077 } else if (bss->radius_acct_req_attr == NULL) {
2078 bss->radius_acct_req_attr = attr;
2080 a = bss->radius_acct_req_attr;
2085 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2086 bss->radius_das_port = atoi(pos);
2087 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2088 if (hostapd_parse_das_client(bss, pos) < 0) {
2089 wpa_printf(MSG_ERROR, "Line %d: invalid "
2090 "DAS client", line);
2093 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2094 bss->radius_das_time_window = atoi(pos);
2095 } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
2097 bss->radius_das_require_event_timestamp = atoi(pos);
2098 #endif /* CONFIG_NO_RADIUS */
2099 } else if (os_strcmp(buf, "auth_algs") == 0) {
2100 bss->auth_algs = atoi(pos);
2101 if (bss->auth_algs == 0) {
2102 wpa_printf(MSG_ERROR, "Line %d: no "
2103 "authentication algorithms allowed",
2107 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2108 bss->max_num_sta = atoi(pos);
2109 if (bss->max_num_sta < 0 ||
2110 bss->max_num_sta > MAX_STA_COUNT) {
2111 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2112 "max_num_sta=%d; allowed range "
2113 "0..%d", line, bss->max_num_sta,
2117 } else if (os_strcmp(buf, "wpa") == 0) {
2118 bss->wpa = atoi(pos);
2119 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2120 bss->wpa_group_rekey = atoi(pos);
2121 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2122 bss->wpa_strict_rekey = atoi(pos);
2123 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2124 bss->wpa_gmk_rekey = atoi(pos);
2125 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2126 bss->wpa_ptk_rekey = atoi(pos);
2127 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2128 int len = os_strlen(pos);
2129 if (len < 8 || len > 63) {
2130 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
2131 "passphrase length %d (expected "
2132 "8..63)", line, len);
2135 os_free(bss->ssid.wpa_passphrase);
2136 bss->ssid.wpa_passphrase = os_strdup(pos);
2137 os_free(bss->ssid.wpa_psk);
2138 bss->ssid.wpa_psk = NULL;
2140 } else if (os_strcmp(buf, "wpa_psk") == 0) {
2141 os_free(bss->ssid.wpa_psk);
2143 os_zalloc(sizeof(struct hostapd_wpa_psk));
2144 if (bss->ssid.wpa_psk == NULL)
2146 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
2148 pos[PMK_LEN * 2] != '\0') {
2149 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
2150 "'%s'.", line, pos);
2153 bss->ssid.wpa_psk->group = 1;
2154 os_free(bss->ssid.wpa_passphrase);
2155 bss->ssid.wpa_passphrase = NULL;
2157 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2158 os_free(bss->ssid.wpa_psk_file);
2159 bss->ssid.wpa_psk_file = os_strdup(pos);
2160 if (!bss->ssid.wpa_psk_file) {
2161 wpa_printf(MSG_ERROR, "Line %d: allocation "
2165 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2167 hostapd_config_parse_key_mgmt(line, pos);
2168 if (bss->wpa_key_mgmt == -1)
2170 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2171 bss->wpa_psk_radius = atoi(pos);
2172 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2173 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2174 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2175 wpa_printf(MSG_ERROR, "Line %d: unknown "
2176 "wpa_psk_radius %d",
2177 line, bss->wpa_psk_radius);
2180 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2182 hostapd_config_parse_cipher(line, pos);
2183 if (bss->wpa_pairwise == -1 ||
2184 bss->wpa_pairwise == 0)
2186 else if (bss->wpa_pairwise &
2187 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2188 WPA_CIPHER_WEP104)) {
2189 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2190 "pairwise cipher suite '%s'",
2191 bss->wpa_pairwise, pos);
2194 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2196 hostapd_config_parse_cipher(line, pos);
2197 if (bss->rsn_pairwise == -1 ||
2198 bss->rsn_pairwise == 0)
2200 else if (bss->rsn_pairwise &
2201 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2202 WPA_CIPHER_WEP104)) {
2203 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2204 "pairwise cipher suite '%s'",
2205 bss->rsn_pairwise, pos);
2208 #ifdef CONFIG_RSN_PREAUTH
2209 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2210 bss->rsn_preauth = atoi(pos);
2211 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
2212 bss->rsn_preauth_interfaces = os_strdup(pos);
2213 #endif /* CONFIG_RSN_PREAUTH */
2214 #ifdef CONFIG_PEERKEY
2215 } else if (os_strcmp(buf, "peerkey") == 0) {
2216 bss->peerkey = atoi(pos);
2217 #endif /* CONFIG_PEERKEY */
2218 #ifdef CONFIG_IEEE80211R
2219 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2220 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2221 hexstr2bin(pos, bss->mobility_domain,
2222 MOBILITY_DOMAIN_ID_LEN) != 0) {
2223 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2224 "mobility_domain '%s'", line, pos);
2228 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2229 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2230 hexstr2bin(pos, bss->r1_key_holder,
2231 FT_R1KH_ID_LEN) != 0) {
2232 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2233 "r1_key_holder '%s'", line, pos);
2237 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2238 bss->r0_key_lifetime = atoi(pos);
2239 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2240 bss->reassociation_deadline = atoi(pos);
2241 } else if (os_strcmp(buf, "r0kh") == 0) {
2242 if (add_r0kh(bss, pos) < 0) {
2243 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2244 "r0kh '%s'", line, pos);
2248 } else if (os_strcmp(buf, "r1kh") == 0) {
2249 if (add_r1kh(bss, pos) < 0) {
2250 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2251 "r1kh '%s'", line, pos);
2255 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2256 bss->pmk_r1_push = atoi(pos);
2257 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2258 bss->ft_over_ds = atoi(pos);
2259 #endif /* CONFIG_IEEE80211R */
2260 #ifndef CONFIG_NO_CTRL_IFACE
2261 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2262 os_free(bss->ctrl_interface);
2263 bss->ctrl_interface = os_strdup(pos);
2264 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
2265 #ifndef CONFIG_NATIVE_WINDOWS
2268 const char *group = pos;
2270 grp = getgrnam(group);
2272 bss->ctrl_interface_gid = grp->gr_gid;
2273 bss->ctrl_interface_gid_set = 1;
2274 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
2275 " (from group name '%s')",
2276 bss->ctrl_interface_gid, group);
2280 /* Group name not found - try to parse this as gid */
2281 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2282 if (*group == '\0' || *endp != '\0') {
2283 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
2284 "'%s'", line, group);
2288 bss->ctrl_interface_gid_set = 1;
2289 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2290 bss->ctrl_interface_gid);
2291 #endif /* CONFIG_NATIVE_WINDOWS */
2292 #endif /* CONFIG_NO_CTRL_IFACE */
2293 #ifdef RADIUS_SERVER
2294 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2295 os_free(bss->radius_server_clients);
2296 bss->radius_server_clients = os_strdup(pos);
2297 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2298 bss->radius_server_auth_port = atoi(pos);
2299 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2300 bss->radius_server_ipv6 = atoi(pos);
2301 #endif /* RADIUS_SERVER */
2302 } else if (os_strcmp(buf, "test_socket") == 0) {
2303 os_free(bss->test_socket);
2304 bss->test_socket = os_strdup(pos);
2305 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2306 bss->use_pae_group_addr = atoi(pos);
2307 } else if (os_strcmp(buf, "hw_mode") == 0) {
2308 if (os_strcmp(pos, "a") == 0)
2309 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2310 else if (os_strcmp(pos, "b") == 0)
2311 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2312 else if (os_strcmp(pos, "g") == 0)
2313 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2315 wpa_printf(MSG_ERROR, "Line %d: unknown "
2316 "hw_mode '%s'", line, pos);
2319 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2320 if (os_strcmp(pos, "a") == 0)
2321 bss->wps_rf_bands = WPS_RF_50GHZ;
2322 else if (os_strcmp(pos, "g") == 0 ||
2323 os_strcmp(pos, "b") == 0)
2324 bss->wps_rf_bands = WPS_RF_24GHZ;
2325 else if (os_strcmp(pos, "ag") == 0 ||
2326 os_strcmp(pos, "ga") == 0)
2328 WPS_RF_24GHZ | WPS_RF_50GHZ;
2330 wpa_printf(MSG_ERROR, "Line %d: unknown "
2331 "wps_rf_band '%s'", line, pos);
2334 } else if (os_strcmp(buf, "channel") == 0) {
2335 conf->channel = atoi(pos);
2336 } else if (os_strcmp(buf, "beacon_int") == 0) {
2337 int val = atoi(pos);
2338 /* MIB defines range as 1..65535, but very small values
2339 * cause problems with the current implementation.
2340 * Since it is unlikely that this small numbers are
2341 * useful in real life scenarios, do not allow beacon
2342 * period to be set below 15 TU. */
2343 if (val < 15 || val > 65535) {
2344 wpa_printf(MSG_ERROR, "Line %d: invalid "
2345 "beacon_int %d (expected "
2346 "15..65535)", line, val);
2349 conf->beacon_int = val;
2350 } else if (os_strcmp(buf, "dtim_period") == 0) {
2351 bss->dtim_period = atoi(pos);
2352 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2353 wpa_printf(MSG_ERROR, "Line %d: invalid "
2355 line, bss->dtim_period);
2358 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2359 conf->rts_threshold = atoi(pos);
2360 if (conf->rts_threshold < 0 ||
2361 conf->rts_threshold > 2347) {
2362 wpa_printf(MSG_ERROR, "Line %d: invalid "
2364 line, conf->rts_threshold);
2367 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2368 conf->fragm_threshold = atoi(pos);
2369 if (conf->fragm_threshold < 256 ||
2370 conf->fragm_threshold > 2346) {
2371 wpa_printf(MSG_ERROR, "Line %d: invalid "
2372 "fragm_threshold %d",
2373 line, conf->fragm_threshold);
2376 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2377 int val = atoi(pos);
2378 if (val != 0 && val != 1) {
2379 wpa_printf(MSG_ERROR, "Line %d: invalid "
2380 "send_probe_response %d (expected "
2381 "0 or 1)", line, val);
2383 conf->send_probe_response = val;
2384 } else if (os_strcmp(buf, "supported_rates") == 0) {
2385 if (hostapd_parse_rates(&conf->supported_rates, pos)) {
2386 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2390 } else if (os_strcmp(buf, "basic_rates") == 0) {
2391 if (hostapd_parse_rates(&conf->basic_rates, pos)) {
2392 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2396 } else if (os_strcmp(buf, "preamble") == 0) {
2398 conf->preamble = SHORT_PREAMBLE;
2400 conf->preamble = LONG_PREAMBLE;
2401 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2402 bss->ignore_broadcast_ssid = atoi(pos);
2403 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2404 bss->ssid.wep.idx = atoi(pos);
2405 if (bss->ssid.wep.idx > 3) {
2406 wpa_printf(MSG_ERROR, "Invalid "
2407 "wep_default_key index %d",
2411 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2412 os_strcmp(buf, "wep_key1") == 0 ||
2413 os_strcmp(buf, "wep_key2") == 0 ||
2414 os_strcmp(buf, "wep_key3") == 0) {
2415 if (hostapd_config_read_wep(&bss->ssid.wep,
2416 buf[7] - '0', pos)) {
2417 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2418 "key '%s'", line, buf);
2421 #ifndef CONFIG_NO_VLAN
2422 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2423 bss->ssid.dynamic_vlan = atoi(pos);
2424 } else if (os_strcmp(buf, "vlan_file") == 0) {
2425 if (hostapd_config_read_vlan_file(bss, pos)) {
2426 wpa_printf(MSG_ERROR, "Line %d: failed to "
2427 "read VLAN file '%s'", line, pos);
2430 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2431 bss->ssid.vlan_naming = atoi(pos);
2432 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2433 bss->ssid.vlan_naming < 0) {
2434 wpa_printf(MSG_ERROR, "Line %d: invalid "
2435 "naming scheme %d", line,
2436 bss->ssid.vlan_naming);
2439 #ifdef CONFIG_FULL_DYNAMIC_VLAN
2440 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2441 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2442 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
2443 #endif /* CONFIG_NO_VLAN */
2444 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2445 conf->ap_table_max_size = atoi(pos);
2446 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2447 conf->ap_table_expiration_time = atoi(pos);
2448 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2449 if (hostapd_config_tx_queue(conf, buf, pos)) {
2450 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2451 "queue item", line);
2454 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2455 os_strcmp(buf, "wmm_enabled") == 0) {
2456 bss->wmm_enabled = atoi(pos);
2457 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2458 bss->wmm_uapsd = atoi(pos);
2459 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2460 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2461 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
2463 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2467 } else if (os_strcmp(buf, "bss") == 0) {
2468 if (hostapd_config_bss(conf, pos)) {
2469 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2473 } else if (os_strcmp(buf, "bssid") == 0) {
2474 if (hwaddr_aton(pos, bss->bssid)) {
2475 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2479 #ifdef CONFIG_IEEE80211W
2480 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2481 bss->ieee80211w = atoi(pos);
2482 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2483 bss->assoc_sa_query_max_timeout = atoi(pos);
2484 if (bss->assoc_sa_query_max_timeout == 0) {
2485 wpa_printf(MSG_ERROR, "Line %d: invalid "
2486 "assoc_sa_query_max_timeout", line);
2489 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2491 bss->assoc_sa_query_retry_timeout = atoi(pos);
2492 if (bss->assoc_sa_query_retry_timeout == 0) {
2493 wpa_printf(MSG_ERROR, "Line %d: invalid "
2494 "assoc_sa_query_retry_timeout",
2498 #endif /* CONFIG_IEEE80211W */
2499 #ifdef CONFIG_IEEE80211N
2500 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2501 conf->ieee80211n = atoi(pos);
2502 } else if (os_strcmp(buf, "ht_capab") == 0) {
2503 if (hostapd_config_ht_capab(conf, pos) < 0) {
2504 wpa_printf(MSG_ERROR, "Line %d: invalid "
2508 } else if (os_strcmp(buf, "require_ht") == 0) {
2509 conf->require_ht = atoi(pos);
2510 #endif /* CONFIG_IEEE80211N */
2511 #ifdef CONFIG_IEEE80211AC
2512 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2513 conf->ieee80211ac = atoi(pos);
2514 } else if (os_strcmp(buf, "vht_capab") == 0) {
2515 if (hostapd_config_vht_capab(conf, pos) < 0) {
2516 wpa_printf(MSG_ERROR, "Line %d: invalid "
2520 } else if (os_strcmp(buf, "require_vht") == 0) {
2521 conf->require_vht = atoi(pos);
2522 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2523 conf->vht_oper_chwidth = atoi(pos);
2524 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
2526 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2527 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
2529 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
2530 #endif /* CONFIG_IEEE80211AC */
2531 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2532 bss->max_listen_interval = atoi(pos);
2533 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2534 bss->disable_pmksa_caching = atoi(pos);
2535 } else if (os_strcmp(buf, "okc") == 0) {
2536 bss->okc = atoi(pos);
2538 } else if (os_strcmp(buf, "wps_state") == 0) {
2539 bss->wps_state = atoi(pos);
2540 if (bss->wps_state < 0 || bss->wps_state > 2) {
2541 wpa_printf(MSG_ERROR, "Line %d: invalid "
2545 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2546 bss->ap_setup_locked = atoi(pos);
2547 } else if (os_strcmp(buf, "uuid") == 0) {
2548 if (uuid_str2bin(pos, bss->uuid)) {
2549 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2553 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2554 os_free(bss->wps_pin_requests);
2555 bss->wps_pin_requests = os_strdup(pos);
2556 } else if (os_strcmp(buf, "device_name") == 0) {
2557 if (os_strlen(pos) > 32) {
2558 wpa_printf(MSG_ERROR, "Line %d: Too long "
2559 "device_name", line);
2562 os_free(bss->device_name);
2563 bss->device_name = os_strdup(pos);
2564 } else if (os_strcmp(buf, "manufacturer") == 0) {
2565 if (os_strlen(pos) > 64) {
2566 wpa_printf(MSG_ERROR, "Line %d: Too long "
2567 "manufacturer", line);
2570 os_free(bss->manufacturer);
2571 bss->manufacturer = os_strdup(pos);
2572 } else if (os_strcmp(buf, "model_name") == 0) {
2573 if (os_strlen(pos) > 32) {
2574 wpa_printf(MSG_ERROR, "Line %d: Too long "
2575 "model_name", line);
2578 os_free(bss->model_name);
2579 bss->model_name = os_strdup(pos);
2580 } else if (os_strcmp(buf, "model_number") == 0) {
2581 if (os_strlen(pos) > 32) {
2582 wpa_printf(MSG_ERROR, "Line %d: Too long "
2583 "model_number", line);
2586 os_free(bss->model_number);
2587 bss->model_number = os_strdup(pos);
2588 } else if (os_strcmp(buf, "serial_number") == 0) {
2589 if (os_strlen(pos) > 32) {
2590 wpa_printf(MSG_ERROR, "Line %d: Too long "
2591 "serial_number", line);
2594 os_free(bss->serial_number);
2595 bss->serial_number = os_strdup(pos);
2596 } else if (os_strcmp(buf, "device_type") == 0) {
2597 if (wps_dev_type_str2bin(pos, bss->device_type))
2599 } else if (os_strcmp(buf, "config_methods") == 0) {
2600 os_free(bss->config_methods);
2601 bss->config_methods = os_strdup(pos);
2602 } else if (os_strcmp(buf, "os_version") == 0) {
2603 if (hexstr2bin(pos, bss->os_version, 4)) {
2604 wpa_printf(MSG_ERROR, "Line %d: invalid "
2605 "os_version", line);
2608 } else if (os_strcmp(buf, "ap_pin") == 0) {
2609 os_free(bss->ap_pin);
2610 bss->ap_pin = os_strdup(pos);
2611 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2612 bss->skip_cred_build = atoi(pos);
2613 } else if (os_strcmp(buf, "extra_cred") == 0) {
2614 os_free(bss->extra_cred);
2616 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2617 if (bss->extra_cred == NULL) {
2618 wpa_printf(MSG_ERROR, "Line %d: could not "
2619 "read Credentials from '%s'",
2623 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2624 bss->wps_cred_processing = atoi(pos);
2625 } else if (os_strcmp(buf, "ap_settings") == 0) {
2626 os_free(bss->ap_settings);
2628 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2629 if (bss->ap_settings == NULL) {
2630 wpa_printf(MSG_ERROR, "Line %d: could not "
2631 "read AP Settings from '%s'",
2635 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2636 bss->upnp_iface = os_strdup(pos);
2637 } else if (os_strcmp(buf, "friendly_name") == 0) {
2638 os_free(bss->friendly_name);
2639 bss->friendly_name = os_strdup(pos);
2640 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2641 os_free(bss->manufacturer_url);
2642 bss->manufacturer_url = os_strdup(pos);
2643 } else if (os_strcmp(buf, "model_description") == 0) {
2644 os_free(bss->model_description);
2645 bss->model_description = os_strdup(pos);
2646 } else if (os_strcmp(buf, "model_url") == 0) {
2647 os_free(bss->model_url);
2648 bss->model_url = os_strdup(pos);
2649 } else if (os_strcmp(buf, "upc") == 0) {
2651 bss->upc = os_strdup(pos);
2652 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2653 bss->pbc_in_m1 = atoi(pos);
2654 #ifdef CONFIG_WPS_NFC
2655 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2656 bss->wps_nfc_dev_pw_id = atoi(pos);
2657 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2658 bss->wps_nfc_dev_pw_id > 0xffff) {
2659 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2660 "wps_nfc_dev_pw_id value", line);
2663 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2664 wpabuf_free(bss->wps_nfc_dh_pubkey);
2665 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2666 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2667 wpabuf_free(bss->wps_nfc_dh_privkey);
2668 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2669 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2670 wpabuf_free(bss->wps_nfc_dev_pw);
2671 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2672 #endif /* CONFIG_WPS_NFC */
2673 #endif /* CONFIG_WPS */
2674 #ifdef CONFIG_P2P_MANAGER
2675 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2676 int manage = atoi(pos);
2678 bss->p2p |= P2P_MANAGE;
2680 bss->p2p &= ~P2P_MANAGE;
2681 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2683 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2685 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
2686 #endif /* CONFIG_P2P_MANAGER */
2687 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2688 bss->disassoc_low_ack = atoi(pos);
2689 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2690 int val = atoi(pos);
2692 bss->tdls |= TDLS_PROHIBIT;
2694 bss->tdls &= ~TDLS_PROHIBIT;
2695 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2696 int val = atoi(pos);
2698 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2700 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
2701 #ifdef CONFIG_RSN_TESTING
2702 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2703 extern int rsn_testing;
2704 rsn_testing = atoi(pos);
2705 #endif /* CONFIG_RSN_TESTING */
2706 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2707 bss->time_advertisement = atoi(pos);
2708 } else if (os_strcmp(buf, "time_zone") == 0) {
2709 size_t tz_len = os_strlen(pos);
2710 if (tz_len < 4 || tz_len > 255) {
2711 wpa_printf(MSG_DEBUG, "Line %d: invalid "
2716 os_free(bss->time_zone);
2717 bss->time_zone = os_strdup(pos);
2718 if (bss->time_zone == NULL)
2720 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
2721 bss->wnm_sleep_mode = atoi(pos);
2722 #ifdef CONFIG_INTERWORKING
2723 } else if (os_strcmp(buf, "interworking") == 0) {
2724 bss->interworking = atoi(pos);
2725 } else if (os_strcmp(buf, "access_network_type") == 0) {
2726 bss->access_network_type = atoi(pos);
2727 if (bss->access_network_type < 0 ||
2728 bss->access_network_type > 15) {
2729 wpa_printf(MSG_ERROR, "Line %d: invalid "
2730 "access_network_type", line);
2733 } else if (os_strcmp(buf, "internet") == 0) {
2734 bss->internet = atoi(pos);
2735 } else if (os_strcmp(buf, "asra") == 0) {
2736 bss->asra = atoi(pos);
2737 } else if (os_strcmp(buf, "esr") == 0) {
2738 bss->esr = atoi(pos);
2739 } else if (os_strcmp(buf, "uesa") == 0) {
2740 bss->uesa = atoi(pos);
2741 } else if (os_strcmp(buf, "venue_group") == 0) {
2742 bss->venue_group = atoi(pos);
2743 bss->venue_info_set = 1;
2744 } else if (os_strcmp(buf, "venue_type") == 0) {
2745 bss->venue_type = atoi(pos);
2746 bss->venue_info_set = 1;
2747 } else if (os_strcmp(buf, "hessid") == 0) {
2748 if (hwaddr_aton(pos, bss->hessid)) {
2749 wpa_printf(MSG_ERROR, "Line %d: invalid "
2753 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
2754 if (parse_roaming_consortium(bss, pos, line) < 0)
2756 } else if (os_strcmp(buf, "venue_name") == 0) {
2757 if (parse_venue_name(bss, pos, line) < 0)
2759 } else if (os_strcmp(buf, "network_auth_type") == 0) {
2761 u16 redirect_url_len;
2762 if (hexstr2bin(pos, &auth_type, 1)) {
2763 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2764 "network_auth_type '%s'",
2769 if (auth_type == 0 || auth_type == 2)
2770 redirect_url_len = os_strlen(pos + 2);
2772 redirect_url_len = 0;
2773 os_free(bss->network_auth_type);
2774 bss->network_auth_type =
2775 os_malloc(redirect_url_len + 3 + 1);
2776 if (bss->network_auth_type == NULL) {
2780 *bss->network_auth_type = auth_type;
2781 WPA_PUT_LE16(bss->network_auth_type + 1,
2783 if (redirect_url_len)
2784 os_memcpy(bss->network_auth_type + 3,
2785 pos + 2, redirect_url_len);
2786 bss->network_auth_type_len = 3 + redirect_url_len;
2787 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
2788 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
2790 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2791 "ipaddr_type_availability '%s'",
2793 bss->ipaddr_type_configured = 0;
2797 bss->ipaddr_type_configured = 1;
2798 } else if (os_strcmp(buf, "domain_name") == 0) {
2799 int j, num_domains, domain_len, domain_list_len = 0;
2800 char *tok_start, *tok_prev;
2801 u8 *domain_list, *domain_ptr;
2803 domain_list_len = os_strlen(pos) + 1;
2804 domain_list = os_malloc(domain_list_len);
2805 if (domain_list == NULL) {
2810 domain_ptr = domain_list;
2813 while ((tok_prev = os_strchr(tok_prev, ','))) {
2818 for (j = 0; j < num_domains; j++) {
2819 tok_start = os_strchr(tok_prev, ',');
2821 domain_len = tok_start - tok_prev;
2822 *domain_ptr = domain_len;
2823 os_memcpy(domain_ptr + 1, tok_prev,
2825 domain_ptr += domain_len + 1;
2826 tok_prev = ++tok_start;
2828 domain_len = os_strlen(tok_prev);
2829 *domain_ptr = domain_len;
2830 os_memcpy(domain_ptr + 1, tok_prev,
2832 domain_ptr += domain_len + 1;
2836 os_free(bss->domain_name);
2837 bss->domain_name = domain_list;
2838 bss->domain_name_len = domain_list_len;
2839 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
2840 if (parse_3gpp_cell_net(bss, pos, line) < 0)
2842 } else if (os_strcmp(buf, "nai_realm") == 0) {
2843 if (parse_nai_realm(bss, pos, line) < 0)
2845 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
2846 bss->gas_frag_limit = atoi(pos);
2847 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
2848 bss->gas_comeback_delay = atoi(pos);
2849 #endif /* CONFIG_INTERWORKING */
2850 #ifdef CONFIG_RADIUS_TEST
2851 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
2852 os_free(bss->dump_msk_file);
2853 bss->dump_msk_file = os_strdup(pos);
2854 #endif /* CONFIG_RADIUS_TEST */
2856 } else if (os_strcmp(buf, "hs20") == 0) {
2857 bss->hs20 = atoi(pos);
2858 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
2859 bss->disable_dgaf = atoi(pos);
2860 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
2861 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
2863 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
2864 if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
2868 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
2869 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
2873 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
2875 size_t oper_class_len;
2876 oper_class_len = os_strlen(pos);
2877 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
2878 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2879 "hs20_operating_class '%s'",
2884 oper_class_len /= 2;
2885 oper_class = os_malloc(oper_class_len);
2886 if (oper_class == NULL) {
2890 if (hexstr2bin(pos, oper_class, oper_class_len)) {
2891 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2892 "hs20_operating_class '%s'",
2894 os_free(oper_class);
2898 os_free(bss->hs20_operating_class);
2899 bss->hs20_operating_class = oper_class;
2900 bss->hs20_operating_class_len = oper_class_len;
2901 #endif /* CONFIG_HS20 */
2902 } else if (os_strcmp(buf, "vendor_elements") == 0) {
2903 struct wpabuf *elems;
2904 size_t len = os_strlen(pos);
2906 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2907 "vendor_elements '%s'", line, pos);
2912 wpabuf_free(bss->vendor_elements);
2913 bss->vendor_elements = NULL;
2917 elems = wpabuf_alloc(len);
2921 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
2923 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2924 "vendor_elements '%s'", line, pos);
2928 wpabuf_free(bss->vendor_elements);
2929 bss->vendor_elements = elems;
2931 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
2932 "item '%s'", line, buf);
2941 static void hostapd_set_security_params(struct hostapd_bss_config *bss)
2945 if (bss->individual_wep_key_len == 0) {
2946 /* individual keys are not use; can use key idx0 for
2948 bss->broadcast_key_idx_min = 0;
2951 /* Select group cipher based on the enabled pairwise cipher
2955 pairwise |= bss->wpa_pairwise;
2957 if (bss->rsn_pairwise == 0)
2958 bss->rsn_pairwise = bss->wpa_pairwise;
2959 pairwise |= bss->rsn_pairwise;
2961 if (pairwise & WPA_CIPHER_TKIP)
2962 bss->wpa_group = WPA_CIPHER_TKIP;
2963 else if ((pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ==
2965 bss->wpa_group = WPA_CIPHER_GCMP;
2967 bss->wpa_group = WPA_CIPHER_CCMP;
2969 bss->radius->auth_server = bss->radius->auth_servers;
2970 bss->radius->acct_server = bss->radius->acct_servers;
2972 if (bss->wpa && bss->ieee802_1x) {
2973 bss->ssid.security_policy = SECURITY_WPA;
2974 } else if (bss->wpa) {
2975 bss->ssid.security_policy = SECURITY_WPA_PSK;
2976 } else if (bss->ieee802_1x) {
2977 int cipher = WPA_CIPHER_NONE;
2978 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2979 bss->ssid.wep.default_len = bss->default_wep_key_len;
2980 if (bss->default_wep_key_len)
2981 cipher = bss->default_wep_key_len >= 13 ?
2982 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
2983 bss->wpa_group = cipher;
2984 bss->wpa_pairwise = cipher;
2985 bss->rsn_pairwise = cipher;
2986 } else if (bss->ssid.wep.keys_set) {
2987 int cipher = WPA_CIPHER_WEP40;
2988 if (bss->ssid.wep.len[0] >= 13)
2989 cipher = WPA_CIPHER_WEP104;
2990 bss->ssid.security_policy = SECURITY_STATIC_WEP;
2991 bss->wpa_group = cipher;
2992 bss->wpa_pairwise = cipher;
2993 bss->rsn_pairwise = cipher;
2995 bss->ssid.security_policy = SECURITY_PLAINTEXT;
2996 bss->wpa_group = WPA_CIPHER_NONE;
2997 bss->wpa_pairwise = WPA_CIPHER_NONE;
2998 bss->rsn_pairwise = WPA_CIPHER_NONE;
3004 * hostapd_config_read - Read and parse a configuration file
3005 * @fname: Configuration file name (including path, if needed)
3006 * Returns: Allocated configuration data structure
3008 struct hostapd_config * hostapd_config_read(const char *fname)
3010 struct hostapd_config *conf;
3011 struct hostapd_bss_config *bss;
3013 char buf[512], *pos;
3018 f = fopen(fname, "r");
3020 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3021 "for reading.", fname);
3025 conf = hostapd_config_defaults();
3031 /* set default driver based on configuration */
3032 conf->driver = wpa_drivers[0];
3033 if (conf->driver == NULL) {
3034 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3035 hostapd_config_free(conf);
3040 bss = conf->last_bss = conf->bss;
3042 while (fgets(buf, sizeof(buf), f)) {
3043 bss = conf->last_bss;
3049 while (*pos != '\0') {
3059 pos = os_strchr(buf, '=');
3061 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3068 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3073 for (i = 0; i < conf->num_bss; i++)
3074 hostapd_set_security_params(&conf->bss[i]);
3076 if (hostapd_config_check(conf))
3079 #ifndef WPA_IGNORE_CONFIG_ERRORS
3081 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3082 "'%s'", errors, fname);
3083 hostapd_config_free(conf);
3086 #endif /* WPA_IGNORE_CONFIG_ERRORS */
3092 int hostapd_set_iface(struct hostapd_config *conf,
3093 struct hostapd_bss_config *bss, char *field, char *value)
3098 errors = hostapd_config_fill(conf, bss, field, value, 0);
3100 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3101 "to value '%s'", field, value);
3105 for (i = 0; i < conf->num_bss; i++)
3106 hostapd_set_security_params(&conf->bss[i]);
3108 if (hostapd_config_check(conf)) {
3109 wpa_printf(MSG_ERROR, "Configuration check failed");