]> git.ipfire.org Git - thirdparty/hostap.git/blame - hostapd/config_file.c
tests: Use 16 instead of 13 as the cwmin/cwmax invalid case
[thirdparty/hostap.git] / hostapd / config_file.c
CommitLineData
41d719d6
JM
1/*
2 * hostapd / Configuration file parser
5e3b5197 3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
41d719d6 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
41d719d6
JM
7 */
8
6226e38d 9#include "utils/includes.h"
41d719d6
JM
10#ifndef CONFIG_NATIVE_WINDOWS
11#include <grp.h>
12#endif /* CONFIG_NATIVE_WINDOWS */
13
6226e38d
JM
14#include "utils/common.h"
15#include "utils/uuid.h"
41d719d6
JM
16#include "common/ieee802_11_defs.h"
17#include "drivers/driver.h"
18#include "eap_server/eap.h"
19#include "radius/radius_client.h"
6226e38d
JM
20#include "ap/wpa_auth.h"
21#include "ap/ap_config.h"
1057d78e 22#include "config_file.h"
41d719d6
JM
23
24
d0ee16ed
JM
25#ifndef CONFIG_NO_RADIUS
26#ifdef EAP_SERVER
27static struct hostapd_radius_attr *
28hostapd_parse_radius_attr(const char *value);
29#endif /* EAP_SERVER */
30#endif /* CONFIG_NO_RADIUS */
31
32
41d719d6
JM
33#ifndef CONFIG_NO_VLAN
34static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
35 const char *fname)
36{
37 FILE *f;
38 char buf[128], *pos, *pos2;
39 int line = 0, vlan_id;
40 struct hostapd_vlan *vlan;
41
42 f = fopen(fname, "r");
43 if (!f) {
44 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
45 return -1;
46 }
47
48 while (fgets(buf, sizeof(buf), f)) {
49 line++;
50
51 if (buf[0] == '#')
52 continue;
53 pos = buf;
54 while (*pos != '\0') {
55 if (*pos == '\n') {
56 *pos = '\0';
57 break;
58 }
59 pos++;
60 }
61 if (buf[0] == '\0')
62 continue;
63
64 if (buf[0] == '*') {
65 vlan_id = VLAN_ID_WILDCARD;
66 pos = buf + 1;
67 } else {
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);
73 fclose(f);
74 return -1;
75 }
76 }
77
78 while (*pos == ' ' || *pos == '\t')
79 pos++;
80 pos2 = pos;
81 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
82 pos2++;
83 *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);
87 fclose(f);
88 return -1;
89 }
90
8b44ad7e 91 vlan = os_zalloc(sizeof(*vlan));
41d719d6
JM
92 if (vlan == NULL) {
93 wpa_printf(MSG_ERROR, "Out of memory while reading "
94 "VLAN interfaces from '%s'", fname);
95 fclose(f);
96 return -1;
97 }
98
41d719d6
JM
99 vlan->vlan_id = vlan_id;
100 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
c2db79f2
MB
101 vlan->next = bss->vlan;
102 bss->vlan = vlan;
41d719d6
JM
103 }
104
105 fclose(f);
106
107 return 0;
108}
109#endif /* CONFIG_NO_VLAN */
110
111
112static int hostapd_acl_comp(const void *a, const void *b)
113{
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));
117}
118
119
120static int hostapd_config_read_maclist(const char *fname,
121 struct mac_acl_entry **acl, int *num)
122{
123 FILE *f;
124 char buf[128], *pos;
125 int line = 0;
126 u8 addr[ETH_ALEN];
127 struct mac_acl_entry *newacl;
128 int vlan_id;
129
130 if (!fname)
131 return 0;
132
133 f = fopen(fname, "r");
134 if (!f) {
135 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
136 return -1;
137 }
138
139 while (fgets(buf, sizeof(buf), f)) {
1748f1da
ET
140 int i, rem = 0;
141
41d719d6
JM
142 line++;
143
144 if (buf[0] == '#')
145 continue;
146 pos = buf;
147 while (*pos != '\0') {
148 if (*pos == '\n') {
149 *pos = '\0';
150 break;
151 }
152 pos++;
153 }
154 if (buf[0] == '\0')
155 continue;
1748f1da
ET
156 pos = buf;
157 if (buf[0] == '-') {
158 rem = 1;
159 pos++;
160 }
41d719d6 161
1748f1da 162 if (hwaddr_aton(pos, addr)) {
41d719d6 163 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
1748f1da 164 "line %d in '%s'", pos, line, fname);
41d719d6
JM
165 fclose(f);
166 return -1;
167 }
168
1748f1da
ET
169 if (rem) {
170 i = 0;
171 while (i < *num) {
172 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
173 0) {
174 os_remove_in_array(*acl, *num,
175 sizeof(**acl), i);
176 (*num)--;
177 } else
178 i++;
179 }
180 continue;
181 }
41d719d6
JM
182 vlan_id = 0;
183 pos = buf;
184 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
185 pos++;
186 while (*pos == ' ' || *pos == '\t')
187 pos++;
188 if (*pos != '\0')
189 vlan_id = atoi(pos);
190
067ffa26 191 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
41d719d6
JM
192 if (newacl == NULL) {
193 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
194 fclose(f);
195 return -1;
196 }
197
198 *acl = newacl;
199 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
200 (*acl)[*num].vlan_id = vlan_id;
201 (*num)++;
202 }
203
204 fclose(f);
205
206 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
207
208 return 0;
209}
210
211
212#ifdef EAP_SERVER
213static int hostapd_config_read_eap_user(const char *fname,
214 struct hostapd_bss_config *conf)
215{
216 FILE *f;
217 char buf[512], *pos, *start, *pos2;
218 int line = 0, ret = 0, num_methods;
4437f8fc 219 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
41d719d6
JM
220
221 if (!fname)
222 return 0;
223
ee431d77 224 if (os_strncmp(fname, "sqlite:", 7) == 0) {
c469d622 225#ifdef CONFIG_SQLITE
ee431d77
JM
226 os_free(conf->eap_user_sqlite);
227 conf->eap_user_sqlite = os_strdup(fname + 7);
228 return 0;
c469d622
BG
229#else /* CONFIG_SQLITE */
230 wpa_printf(MSG_ERROR,
231 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
232 return -1;
233#endif /* CONFIG_SQLITE */
ee431d77
JM
234 }
235
41d719d6
JM
236 f = fopen(fname, "r");
237 if (!f) {
238 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
239 return -1;
240 }
241
242 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
243 while (fgets(buf, sizeof(buf), f)) {
244 line++;
245
246 if (buf[0] == '#')
247 continue;
248 pos = buf;
249 while (*pos != '\0') {
250 if (*pos == '\n') {
251 *pos = '\0';
252 break;
253 }
254 pos++;
255 }
256 if (buf[0] == '\0')
257 continue;
258
d0ee16ed
JM
259#ifndef CONFIG_NO_RADIUS
260 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
261 struct hostapd_radius_attr *attr, *a;
262 attr = hostapd_parse_radius_attr(buf + 19);
263 if (attr == NULL) {
264 wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
265 buf + 19);
4fb363c6 266 user = NULL; /* already in the BSS list */
d0ee16ed
JM
267 goto failed;
268 }
269 if (user->accept_attr == NULL) {
270 user->accept_attr = attr;
271 } else {
272 a = user->accept_attr;
273 while (a->next)
274 a = a->next;
275 a->next = attr;
276 }
277 continue;
278 }
279#endif /* CONFIG_NO_RADIUS */
280
41d719d6
JM
281 user = NULL;
282
283 if (buf[0] != '"' && buf[0] != '*') {
284 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
285 "start) on line %d in '%s'", line, fname);
286 goto failed;
287 }
288
289 user = os_zalloc(sizeof(*user));
290 if (user == NULL) {
291 wpa_printf(MSG_ERROR, "EAP user allocation failed");
292 goto failed;
293 }
294 user->force_version = -1;
295
296 if (buf[0] == '*') {
297 pos = buf;
298 } else {
299 pos = buf + 1;
300 start = pos;
301 while (*pos != '"' && *pos != '\0')
302 pos++;
303 if (*pos == '\0') {
304 wpa_printf(MSG_ERROR, "Invalid EAP identity "
305 "(no \" in end) on line %d in '%s'",
306 line, fname);
307 goto failed;
308 }
309
310 user->identity = os_malloc(pos - start);
311 if (user->identity == NULL) {
312 wpa_printf(MSG_ERROR, "Failed to allocate "
313 "memory for EAP identity");
314 goto failed;
315 }
316 os_memcpy(user->identity, start, pos - start);
317 user->identity_len = pos - start;
318
319 if (pos[0] == '"' && pos[1] == '*') {
320 user->wildcard_prefix = 1;
321 pos++;
322 }
323 }
324 pos++;
325 while (*pos == ' ' || *pos == '\t')
326 pos++;
327
328 if (*pos == '\0') {
329 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
330 "'%s'", line, fname);
331 goto failed;
332 }
333
334 start = pos;
335 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
336 pos++;
337 if (*pos == '\0') {
338 pos = NULL;
339 } else {
340 *pos = '\0';
341 pos++;
342 }
343 num_methods = 0;
344 while (*start) {
345 char *pos3 = os_strchr(start, ',');
346 if (pos3) {
347 *pos3++ = '\0';
348 }
349 user->methods[num_methods].method =
350 eap_server_get_type(
351 start,
352 &user->methods[num_methods].vendor);
353 if (user->methods[num_methods].vendor ==
354 EAP_VENDOR_IETF &&
355 user->methods[num_methods].method == EAP_TYPE_NONE)
356 {
357 if (os_strcmp(start, "TTLS-PAP") == 0) {
358 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
359 goto skip_eap;
360 }
361 if (os_strcmp(start, "TTLS-CHAP") == 0) {
362 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
363 goto skip_eap;
364 }
365 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
366 user->ttls_auth |=
367 EAP_TTLS_AUTH_MSCHAP;
368 goto skip_eap;
369 }
370 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
371 user->ttls_auth |=
372 EAP_TTLS_AUTH_MSCHAPV2;
373 goto skip_eap;
374 }
8943cc99
JM
375 if (os_strcmp(start, "MACACL") == 0) {
376 user->macacl = 1;
377 goto skip_eap;
378 }
41d719d6
JM
379 wpa_printf(MSG_ERROR, "Unsupported EAP type "
380 "'%s' on line %d in '%s'",
381 start, line, fname);
382 goto failed;
383 }
384
385 num_methods++;
e9447a94 386 if (num_methods >= EAP_MAX_METHODS)
41d719d6
JM
387 break;
388 skip_eap:
389 if (pos3 == NULL)
390 break;
391 start = pos3;
392 }
8943cc99 393 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
41d719d6
JM
394 wpa_printf(MSG_ERROR, "No EAP types configured on "
395 "line %d in '%s'", line, fname);
396 goto failed;
397 }
398
399 if (pos == NULL)
400 goto done;
401
402 while (*pos == ' ' || *pos == '\t')
403 pos++;
404 if (*pos == '\0')
405 goto done;
406
407 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
408 user->force_version = 0;
409 goto done;
410 }
411
412 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
413 user->force_version = 1;
414 goto done;
415 }
416
417 if (os_strncmp(pos, "[2]", 3) == 0) {
418 user->phase2 = 1;
419 goto done;
420 }
421
422 if (*pos == '"') {
423 pos++;
424 start = pos;
425 while (*pos != '"' && *pos != '\0')
426 pos++;
427 if (*pos == '\0') {
428 wpa_printf(MSG_ERROR, "Invalid EAP password "
429 "(no \" in end) on line %d in '%s'",
430 line, fname);
431 goto failed;
432 }
433
434 user->password = os_malloc(pos - start);
435 if (user->password == NULL) {
436 wpa_printf(MSG_ERROR, "Failed to allocate "
437 "memory for EAP password");
438 goto failed;
439 }
440 os_memcpy(user->password, start, pos - start);
441 user->password_len = pos - start;
442
443 pos++;
444 } else if (os_strncmp(pos, "hash:", 5) == 0) {
445 pos += 5;
446 pos2 = pos;
447 while (*pos2 != '\0' && *pos2 != ' ' &&
448 *pos2 != '\t' && *pos2 != '#')
449 pos2++;
450 if (pos2 - pos != 32) {
451 wpa_printf(MSG_ERROR, "Invalid password hash "
452 "on line %d in '%s'", line, fname);
453 goto failed;
454 }
455 user->password = os_malloc(16);
456 if (user->password == NULL) {
457 wpa_printf(MSG_ERROR, "Failed to allocate "
458 "memory for EAP password hash");
459 goto failed;
460 }
461 if (hexstr2bin(pos, user->password, 16) < 0) {
462 wpa_printf(MSG_ERROR, "Invalid hash password "
463 "on line %d in '%s'", line, fname);
464 goto failed;
465 }
466 user->password_len = 16;
467 user->password_hash = 1;
468 pos = pos2;
469 } else {
470 pos2 = pos;
471 while (*pos2 != '\0' && *pos2 != ' ' &&
472 *pos2 != '\t' && *pos2 != '#')
473 pos2++;
474 if ((pos2 - pos) & 1) {
475 wpa_printf(MSG_ERROR, "Invalid hex password "
476 "on line %d in '%s'", line, fname);
477 goto failed;
478 }
479 user->password = os_malloc((pos2 - pos) / 2);
480 if (user->password == NULL) {
481 wpa_printf(MSG_ERROR, "Failed to allocate "
482 "memory for EAP password");
483 goto failed;
484 }
485 if (hexstr2bin(pos, user->password,
486 (pos2 - pos) / 2) < 0) {
487 wpa_printf(MSG_ERROR, "Invalid hex password "
488 "on line %d in '%s'", line, fname);
489 goto failed;
490 }
491 user->password_len = (pos2 - pos) / 2;
492 pos = pos2;
493 }
494
495 while (*pos == ' ' || *pos == '\t')
496 pos++;
497 if (os_strncmp(pos, "[2]", 3) == 0) {
498 user->phase2 = 1;
499 }
500
501 done:
502 if (tail == NULL) {
4437f8fc 503 tail = new_user = user;
41d719d6
JM
504 } else {
505 tail->next = user;
506 tail = user;
507 }
508 continue;
509
510 failed:
d0ee16ed
JM
511 if (user)
512 hostapd_config_free_eap_user(user);
41d719d6
JM
513 ret = -1;
514 break;
515 }
516
517 fclose(f);
518
4437f8fc
JM
519 if (ret == 0) {
520 user = conf->eap_user;
521 while (user) {
522 struct hostapd_eap_user *prev;
523
524 prev = user;
525 user = user->next;
526 hostapd_config_free_eap_user(prev);
527 }
528 conf->eap_user = new_user;
529 }
530
41d719d6
JM
531 return ret;
532}
533#endif /* EAP_SERVER */
534
535
536#ifndef CONFIG_NO_RADIUS
537static int
538hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
539 int *num_server, const char *val, int def_port,
540 struct hostapd_radius_server **curr_serv)
541{
542 struct hostapd_radius_server *nserv;
543 int ret;
544 static int server_index = 1;
545
067ffa26 546 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
41d719d6
JM
547 if (nserv == NULL)
548 return -1;
549
550 *server = nserv;
551 nserv = &nserv[*num_server];
552 (*num_server)++;
553 (*curr_serv) = nserv;
554
555 os_memset(nserv, 0, sizeof(*nserv));
556 nserv->port = def_port;
557 ret = hostapd_parse_ip_addr(val, &nserv->addr);
558 nserv->index = server_index++;
559
560 return ret;
561}
af35e7af
JM
562
563
564static struct hostapd_radius_attr *
565hostapd_parse_radius_attr(const char *value)
566{
567 const char *pos;
568 char syntax;
569 struct hostapd_radius_attr *attr;
570 size_t len;
571
572 attr = os_zalloc(sizeof(*attr));
573 if (attr == NULL)
574 return NULL;
575
576 attr->type = atoi(value);
577
578 pos = os_strchr(value, ':');
579 if (pos == NULL) {
580 attr->val = wpabuf_alloc(1);
581 if (attr->val == NULL) {
582 os_free(attr);
583 return NULL;
584 }
585 wpabuf_put_u8(attr->val, 0);
586 return attr;
587 }
588
589 pos++;
590 if (pos[0] == '\0' || pos[1] != ':') {
591 os_free(attr);
592 return NULL;
593 }
594 syntax = *pos++;
595 pos++;
596
597 switch (syntax) {
598 case 's':
599 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
600 break;
601 case 'x':
602 len = os_strlen(pos);
603 if (len & 1)
604 break;
605 len /= 2;
606 attr->val = wpabuf_alloc(len);
607 if (attr->val == NULL)
608 break;
609 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
610 wpabuf_free(attr->val);
611 os_free(attr);
612 return NULL;
613 }
614 break;
615 case 'd':
616 attr->val = wpabuf_alloc(4);
617 if (attr->val)
618 wpabuf_put_be32(attr->val, atoi(pos));
619 break;
620 default:
621 os_free(attr);
622 return NULL;
623 }
624
625 if (attr->val == NULL) {
626 os_free(attr);
627 return NULL;
628 }
629
630 return attr;
631}
b031338c
JM
632
633
634static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
635 const char *val)
636{
637 char *secret;
b031338c
JM
638
639 secret = os_strchr(val, ' ');
640 if (secret == NULL)
641 return -1;
642
643 secret++;
b031338c
JM
644
645 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
646 return -1;
647
648 os_free(bss->radius_das_shared_secret);
6e459875 649 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
b031338c
JM
650 if (bss->radius_das_shared_secret == NULL)
651 return -1;
6e459875 652 bss->radius_das_shared_secret_len = os_strlen(secret);
b031338c
JM
653
654 return 0;
655}
41d719d6
JM
656#endif /* CONFIG_NO_RADIUS */
657
658
659static int hostapd_config_parse_key_mgmt(int line, const char *value)
660{
661 int val = 0, last;
662 char *start, *end, *buf;
663
664 buf = os_strdup(value);
665 if (buf == NULL)
666 return -1;
667 start = buf;
668
669 while (*start != '\0') {
670 while (*start == ' ' || *start == '\t')
671 start++;
672 if (*start == '\0')
673 break;
674 end = start;
675 while (*end != ' ' && *end != '\t' && *end != '\0')
676 end++;
677 last = *end == '\0';
678 *end = '\0';
679 if (os_strcmp(start, "WPA-PSK") == 0)
680 val |= WPA_KEY_MGMT_PSK;
681 else if (os_strcmp(start, "WPA-EAP") == 0)
682 val |= WPA_KEY_MGMT_IEEE8021X;
683#ifdef CONFIG_IEEE80211R
684 else if (os_strcmp(start, "FT-PSK") == 0)
685 val |= WPA_KEY_MGMT_FT_PSK;
686 else if (os_strcmp(start, "FT-EAP") == 0)
687 val |= WPA_KEY_MGMT_FT_IEEE8021X;
688#endif /* CONFIG_IEEE80211R */
689#ifdef CONFIG_IEEE80211W
690 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
691 val |= WPA_KEY_MGMT_PSK_SHA256;
692 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
693 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
694#endif /* CONFIG_IEEE80211W */
c10347f2
JM
695#ifdef CONFIG_SAE
696 else if (os_strcmp(start, "SAE") == 0)
697 val |= WPA_KEY_MGMT_SAE;
698 else if (os_strcmp(start, "FT-SAE") == 0)
699 val |= WPA_KEY_MGMT_FT_SAE;
700#endif /* CONFIG_SAE */
5e3b5197 701#ifdef CONFIG_SUITEB
666497c8
JM
702 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
703 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
5e3b5197
JM
704#endif /* CONFIG_SUITEB */
705#ifdef CONFIG_SUITEB192
706 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
707 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
708#endif /* CONFIG_SUITEB192 */
41d719d6
JM
709 else {
710 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
711 line, start);
712 os_free(buf);
713 return -1;
714 }
715
716 if (last)
717 break;
718 start = end + 1;
719 }
720
721 os_free(buf);
722 if (val == 0) {
723 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
724 "configured.", line);
725 return -1;
726 }
727
728 return val;
729}
730
731
732static int hostapd_config_parse_cipher(int line, const char *value)
733{
a39c78be
JM
734 int val = wpa_parse_cipher(value);
735 if (val < 0) {
736 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
737 line, value);
41d719d6 738 return -1;
41d719d6 739 }
41d719d6
JM
740 if (val == 0) {
741 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
742 line);
743 return -1;
744 }
745 return val;
746}
747
748
749static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
750 char *val)
751{
752 size_t len = os_strlen(val);
753
754 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
755 return -1;
756
757 if (val[0] == '"') {
758 if (len < 2 || val[len - 1] != '"')
759 return -1;
760 len -= 2;
761 wep->key[keyidx] = os_malloc(len);
762 if (wep->key[keyidx] == NULL)
763 return -1;
764 os_memcpy(wep->key[keyidx], val + 1, len);
765 wep->len[keyidx] = len;
766 } else {
767 if (len & 1)
768 return -1;
769 len /= 2;
770 wep->key[keyidx] = os_malloc(len);
771 if (wep->key[keyidx] == NULL)
772 return -1;
773 wep->len[keyidx] = len;
774 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
775 return -1;
776 }
777
778 wep->keys_set++;
779
780 return 0;
781}
782
783
857d9422
MM
784static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
785{
786 char *pos;
787
788 /* for backwards compatibility, translate ' ' in conf str to ',' */
789 pos = val;
790 while (pos) {
791 pos = os_strchr(pos, ' ');
792 if (pos)
793 *pos++ = ',';
794 }
795 if (freq_range_list_parse(&conf->acs_ch_list, val))
796 return -1;
797
798 return 0;
799}
800
801
732118ec 802static int hostapd_parse_intlist(int **int_list, char *val)
41d719d6
JM
803{
804 int *list;
805 int count;
806 char *pos, *end;
807
732118ec
SW
808 os_free(*int_list);
809 *int_list = NULL;
41d719d6
JM
810
811 pos = val;
812 count = 0;
813 while (*pos != '\0') {
814 if (*pos == ' ')
815 count++;
816 pos++;
817 }
818
819 list = os_malloc(sizeof(int) * (count + 2));
820 if (list == NULL)
821 return -1;
822 pos = val;
823 count = 0;
824 while (*pos != '\0') {
825 end = os_strchr(pos, ' ');
826 if (end)
827 *end = '\0';
828
829 list[count++] = atoi(pos);
830 if (!end)
831 break;
832 pos = end + 1;
833 }
834 list[count] = -1;
835
732118ec 836 *int_list = list;
41d719d6
JM
837 return 0;
838}
839
840
841static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
842{
ebd79f07 843 struct hostapd_bss_config **all, *bss;
41d719d6
JM
844
845 if (*ifname == '\0')
846 return -1;
847
ebd79f07
JM
848 all = os_realloc_array(conf->bss, conf->num_bss + 1,
849 sizeof(struct hostapd_bss_config *));
850 if (all == NULL) {
41d719d6
JM
851 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
852 "multi-BSS entry");
853 return -1;
854 }
ebd79f07 855 conf->bss = all;
41d719d6 856
2fe210ce
JM
857 bss = os_zalloc(sizeof(*bss));
858 if (bss == NULL)
859 return -1;
41d719d6
JM
860 bss->radius = os_zalloc(sizeof(*bss->radius));
861 if (bss->radius == NULL) {
862 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
863 "multi-BSS RADIUS data");
2fe210ce 864 os_free(bss);
41d719d6
JM
865 return -1;
866 }
867
2fe210ce 868 conf->bss[conf->num_bss++] = bss;
41d719d6
JM
869 conf->last_bss = bss;
870
871 hostapd_config_defaults_bss(bss);
872 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
873 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
874
875 return 0;
876}
877
878
879/* convert floats with one decimal place to value*10 int, i.e.,
880 * "1.5" will return 15 */
881static int hostapd_config_read_int10(const char *value)
882{
883 int i, d;
884 char *pos;
885
886 i = atoi(value);
887 pos = os_strchr(value, '.');
888 d = 0;
889 if (pos) {
890 pos++;
891 if (*pos >= '0' && *pos <= '9')
892 d = *pos - '0';
893 }
894
895 return i * 10 + d;
896}
897
898
899static int valid_cw(int cw)
900{
901 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
902 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
903}
904
905
906enum {
907 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
908 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
909 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
7e3c1781 910 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
41d719d6
JM
911};
912
913static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
914 char *val)
915{
916 int num;
917 char *pos;
918 struct hostapd_tx_queue_params *queue;
919
920 /* skip 'tx_queue_' prefix */
921 pos = name + 9;
922 if (os_strncmp(pos, "data", 4) == 0 &&
923 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
924 num = pos[4] - '0';
925 pos += 6;
7e3c1781
JM
926 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
927 os_strncmp(pos, "beacon_", 7) == 0) {
928 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
929 return 0;
41d719d6
JM
930 } else {
931 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
932 return -1;
933 }
934
7e3c1781 935 if (num >= NUM_TX_QUEUES) {
d2da2249 936 /* for backwards compatibility, do not trigger failure */
7e3c1781
JM
937 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
938 return 0;
939 }
940
41d719d6
JM
941 queue = &conf->tx_queue[num];
942
943 if (os_strcmp(pos, "aifs") == 0) {
944 queue->aifs = atoi(val);
945 if (queue->aifs < 0 || queue->aifs > 255) {
946 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
947 queue->aifs);
948 return -1;
949 }
950 } else if (os_strcmp(pos, "cwmin") == 0) {
951 queue->cwmin = atoi(val);
952 if (!valid_cw(queue->cwmin)) {
953 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
954 queue->cwmin);
955 return -1;
956 }
957 } else if (os_strcmp(pos, "cwmax") == 0) {
958 queue->cwmax = atoi(val);
959 if (!valid_cw(queue->cwmax)) {
960 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
961 queue->cwmax);
962 return -1;
963 }
964 } else if (os_strcmp(pos, "burst") == 0) {
965 queue->burst = hostapd_config_read_int10(val);
966 } else {
967 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
968 return -1;
969 }
970
41d719d6
JM
971 return 0;
972}
973
974
41d719d6
JM
975#ifdef CONFIG_IEEE80211R
976static int add_r0kh(struct hostapd_bss_config *bss, char *value)
977{
978 struct ft_remote_r0kh *r0kh;
979 char *pos, *next;
980
981 r0kh = os_zalloc(sizeof(*r0kh));
982 if (r0kh == NULL)
983 return -1;
984
985 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
986 pos = value;
987 next = os_strchr(pos, ' ');
988 if (next)
989 *next++ = '\0';
990 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
991 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
992 os_free(r0kh);
993 return -1;
994 }
995
996 pos = next;
997 next = os_strchr(pos, ' ');
998 if (next)
999 *next++ = '\0';
1000 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1001 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1002 os_free(r0kh);
1003 return -1;
1004 }
1005 r0kh->id_len = next - pos - 1;
1006 os_memcpy(r0kh->id, pos, r0kh->id_len);
1007
1008 pos = next;
1009 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1010 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1011 os_free(r0kh);
1012 return -1;
1013 }
1014
1015 r0kh->next = bss->r0kh_list;
1016 bss->r0kh_list = r0kh;
1017
1018 return 0;
1019}
1020
1021
1022static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1023{
1024 struct ft_remote_r1kh *r1kh;
1025 char *pos, *next;
1026
1027 r1kh = os_zalloc(sizeof(*r1kh));
1028 if (r1kh == NULL)
1029 return -1;
1030
1031 /* 02:01:02:03:04:05 02:01:02:03:04:05
1032 * 000102030405060708090a0b0c0d0e0f */
1033 pos = value;
1034 next = os_strchr(pos, ' ');
1035 if (next)
1036 *next++ = '\0';
1037 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1038 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1039 os_free(r1kh);
1040 return -1;
1041 }
1042
1043 pos = next;
1044 next = os_strchr(pos, ' ');
1045 if (next)
1046 *next++ = '\0';
1047 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1048 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1049 os_free(r1kh);
1050 return -1;
1051 }
1052
1053 pos = next;
1054 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1055 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1056 os_free(r1kh);
1057 return -1;
1058 }
1059
1060 r1kh->next = bss->r1kh_list;
1061 bss->r1kh_list = r1kh;
1062
1063 return 0;
1064}
1065#endif /* CONFIG_IEEE80211R */
1066
1067
1068#ifdef CONFIG_IEEE80211N
1069static int hostapd_config_ht_capab(struct hostapd_config *conf,
1070 const char *capab)
1071{
1072 if (os_strstr(capab, "[LDPC]"))
1073 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1074 if (os_strstr(capab, "[HT40-]")) {
1075 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1076 conf->secondary_channel = -1;
1077 }
1078 if (os_strstr(capab, "[HT40+]")) {
1079 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1080 conf->secondary_channel = 1;
1081 }
1082 if (os_strstr(capab, "[SMPS-STATIC]")) {
1083 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1084 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1085 }
1086 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1087 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1088 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1089 }
1090 if (os_strstr(capab, "[GF]"))
1091 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1092 if (os_strstr(capab, "[SHORT-GI-20]"))
1093 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1094 if (os_strstr(capab, "[SHORT-GI-40]"))
1095 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1096 if (os_strstr(capab, "[TX-STBC]"))
1097 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1098 if (os_strstr(capab, "[RX-STBC1]")) {
1099 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1100 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1101 }
1102 if (os_strstr(capab, "[RX-STBC12]")) {
1103 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1104 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1105 }
1106 if (os_strstr(capab, "[RX-STBC123]")) {
1107 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1108 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1109 }
1110 if (os_strstr(capab, "[DELAYED-BA]"))
1111 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1112 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1113 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1114 if (os_strstr(capab, "[DSSS_CCK-40]"))
1115 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
b7a8d67f
JM
1116 if (os_strstr(capab, "[40-INTOLERANT]"))
1117 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
41d719d6
JM
1118 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1119 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1120
1121 return 0;
1122}
1123#endif /* CONFIG_IEEE80211N */
1124
1125
efe45d14
MP
1126#ifdef CONFIG_IEEE80211AC
1127static int hostapd_config_vht_capab(struct hostapd_config *conf,
1128 const char *capab)
1129{
1130 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1131 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1132 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1133 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1134 if (os_strstr(capab, "[VHT160]"))
1135 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1136 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1137 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
efe45d14
MP
1138 if (os_strstr(capab, "[RXLDPC]"))
1139 conf->vht_capab |= VHT_CAP_RXLDPC;
1140 if (os_strstr(capab, "[SHORT-GI-80]"))
1141 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1142 if (os_strstr(capab, "[SHORT-GI-160]"))
1143 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1144 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1145 conf->vht_capab |= VHT_CAP_TXSTBC;
1146 if (os_strstr(capab, "[RX-STBC-1]"))
1147 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1148 if (os_strstr(capab, "[RX-STBC-12]"))
1149 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1150 if (os_strstr(capab, "[RX-STBC-123]"))
1151 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1152 if (os_strstr(capab, "[RX-STBC-1234]"))
1153 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1154 if (os_strstr(capab, "[SU-BEAMFORMER]"))
7066a8e7 1155 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
efe45d14 1156 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
7066a8e7 1157 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
efe45d14 1158 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
b29b012c
EP
1159 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1160 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
efe45d14 1161 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
b29b012c
EP
1162 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1163 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
efe45d14
MP
1164 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1165 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
efe45d14
MP
1166 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1167 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1168 if (os_strstr(capab, "[HTC-VHT]"))
1169 conf->vht_capab |= VHT_CAP_HTC_VHT;
905828fe
BM
1170 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1171 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1172 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1173 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1174 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1175 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1176 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1177 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1178 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1179 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1180 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1181 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1182 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1183 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
efe45d14
MP
1184 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1185 (conf->vht_capab & VHT_CAP_HTC_VHT))
1186 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1187 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1188 (conf->vht_capab & VHT_CAP_HTC_VHT))
1189 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1190 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1191 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1192 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1193 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1194 return 0;
1195}
1196#endif /* CONFIG_IEEE80211AC */
1197
1198
4b2a77ab
JM
1199#ifdef CONFIG_INTERWORKING
1200static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1201 int line)
1202{
1203 size_t len = os_strlen(pos);
1204 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1205
1206 struct hostapd_roaming_consortium *rc;
1207
1208 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1209 hexstr2bin(pos, oi, len / 2)) {
1210 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1211 "'%s'", line, pos);
1212 return -1;
1213 }
1214 len /= 2;
1215
067ffa26
JM
1216 rc = os_realloc_array(bss->roaming_consortium,
1217 bss->roaming_consortium_count + 1,
1218 sizeof(struct hostapd_roaming_consortium));
4b2a77ab
JM
1219 if (rc == NULL)
1220 return -1;
1221
1222 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1223 rc[bss->roaming_consortium_count].len = len;
1224
1225 bss->roaming_consortium = rc;
1226 bss->roaming_consortium_count++;
1227
1228 return 0;
1229}
648cc711
JM
1230
1231
1792e58d
JM
1232static int parse_lang_string(struct hostapd_lang_string **array,
1233 unsigned int *count, char *pos)
648cc711 1234{
f224cf05
KP
1235 char *sep, *str = NULL;
1236 size_t clen, nlen, slen;
1792e58d 1237 struct hostapd_lang_string *ls;
f224cf05
KP
1238 int ret = -1;
1239
1240 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1241 str = wpa_config_parse_string(pos, &slen);
1242 if (!str)
1243 return -1;
1244 pos = str;
1245 }
648cc711
JM
1246
1247 sep = os_strchr(pos, ':');
1248 if (sep == NULL)
f224cf05 1249 goto fail;
648cc711
JM
1250 *sep++ = '\0';
1251
1252 clen = os_strlen(pos);
04e533e2 1253 if (clen < 2 || clen > sizeof(ls->lang))
f224cf05 1254 goto fail;
648cc711
JM
1255 nlen = os_strlen(sep);
1256 if (nlen > 252)
f224cf05 1257 goto fail;
648cc711 1258
1792e58d
JM
1259 ls = os_realloc_array(*array, *count + 1,
1260 sizeof(struct hostapd_lang_string));
1261 if (ls == NULL)
f224cf05 1262 goto fail;
648cc711 1263
1792e58d
JM
1264 *array = ls;
1265 ls = &(*array)[*count];
1266 (*count)++;
648cc711 1267
1792e58d
JM
1268 os_memset(ls->lang, 0, sizeof(ls->lang));
1269 os_memcpy(ls->lang, pos, clen);
1270 ls->name_len = nlen;
1271 os_memcpy(ls->name, sep, nlen);
648cc711 1272
f224cf05
KP
1273 ret = 0;
1274fail:
1275 os_free(str);
1276 return ret;
1792e58d
JM
1277}
1278
648cc711 1279
1792e58d
JM
1280static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1281 int line)
1282{
1283 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1284 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1285 line, pos);
1286 return -1;
1287 }
1288 return 0;
648cc711 1289}
7515adb2
JK
1290
1291
1292static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1293 int line)
1294{
1295 size_t count;
1296 char *pos;
1297 u8 *info = NULL, *ipos;
1298
1299 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1300
1301 count = 1;
1302 for (pos = buf; *pos; pos++) {
4be20bf9 1303 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
7515adb2
JK
1304 goto fail;
1305 if (*pos == ';')
1306 count++;
1307 }
1308 if (1 + count * 3 > 0x7f)
1309 goto fail;
1310
1311 info = os_zalloc(2 + 3 + count * 3);
1312 if (info == NULL)
1313 return -1;
1314
1315 ipos = info;
1316 *ipos++ = 0; /* GUD - Version 1 */
1317 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1318 *ipos++ = 0; /* PLMN List IEI */
1319 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1320 *ipos++ = 1 + count * 3;
1321 *ipos++ = count; /* Number of PLMNs */
1322
1323 pos = buf;
1324 while (pos && *pos) {
1325 char *mcc, *mnc;
1326 size_t mnc_len;
1327
1328 mcc = pos;
1329 mnc = os_strchr(pos, ',');
1330 if (mnc == NULL)
1331 goto fail;
1332 *mnc++ = '\0';
1333 pos = os_strchr(mnc, ';');
1334 if (pos)
1335 *pos++ = '\0';
1336
1337 mnc_len = os_strlen(mnc);
1338 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1339 goto fail;
1340
1341 /* BC coded MCC,MNC */
1342 /* MCC digit 2 | MCC digit 1 */
1343 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1344 /* MNC digit 3 | MCC digit 3 */
1345 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1346 (mcc[2] - '0');
1347 /* MNC digit 2 | MNC digit 1 */
1348 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1349 }
1350
1351 os_free(bss->anqp_3gpp_cell_net);
1352 bss->anqp_3gpp_cell_net = info;
1353 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1354 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1355 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
1356
1357 return 0;
1358
1359fail:
1360 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1361 line, buf);
1362 os_free(info);
1363 return -1;
1364}
1365
8047b186
JK
1366
1367static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1368{
1369 struct hostapd_nai_realm_data *realm;
1370 size_t i, j, len;
1371 int *offsets;
1372 char *pos, *end, *rpos;
1373
1374 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1375 sizeof(int));
1376 if (offsets == NULL)
1377 return -1;
1378
1379 for (i = 0; i < bss->nai_realm_count; i++) {
1380 realm = &bss->nai_realm_data[i];
1381 for (j = 0; j < MAX_NAI_REALMS; j++) {
1382 offsets[i * MAX_NAI_REALMS + j] =
1383 realm->realm[j] ?
1384 realm->realm[j] - realm->realm_buf : -1;
1385 }
1386 }
1387
1388 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1389 sizeof(struct hostapd_nai_realm_data));
1390 if (realm == NULL) {
1391 os_free(offsets);
1392 return -1;
1393 }
1394 bss->nai_realm_data = realm;
1395
1396 /* patch the pointers after realloc */
1397 for (i = 0; i < bss->nai_realm_count; i++) {
1398 realm = &bss->nai_realm_data[i];
1399 for (j = 0; j < MAX_NAI_REALMS; j++) {
1400 int offs = offsets[i * MAX_NAI_REALMS + j];
1401 if (offs >= 0)
1402 realm->realm[j] = realm->realm_buf + offs;
1403 else
1404 realm->realm[j] = NULL;
1405 }
1406 }
1407 os_free(offsets);
1408
1409 realm = &bss->nai_realm_data[bss->nai_realm_count];
1410 os_memset(realm, 0, sizeof(*realm));
1411
1412 pos = buf;
1413 realm->encoding = atoi(pos);
1414 pos = os_strchr(pos, ',');
1415 if (pos == NULL)
1416 goto fail;
1417 pos++;
1418
1419 end = os_strchr(pos, ',');
1420 if (end) {
1421 len = end - pos;
1422 *end = '\0';
1423 } else {
1424 len = os_strlen(pos);
1425 }
1426
1427 if (len > MAX_NAI_REALMLEN) {
1428 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1429 "characters)", (int) len, MAX_NAI_REALMLEN);
1430 goto fail;
1431 }
1432 os_memcpy(realm->realm_buf, pos, len);
1433
1434 if (end)
1435 pos = end + 1;
1436 else
1437 pos = NULL;
1438
1439 while (pos && *pos) {
1440 struct hostapd_nai_realm_eap *eap;
1441
1442 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1443 wpa_printf(MSG_ERROR, "Too many EAP methods");
1444 goto fail;
1445 }
1446
1447 eap = &realm->eap_method[realm->eap_method_count];
1448 realm->eap_method_count++;
1449
1450 end = os_strchr(pos, ',');
1451 if (end == NULL)
1452 end = pos + os_strlen(pos);
1453
1454 eap->eap_method = atoi(pos);
1455 for (;;) {
1456 pos = os_strchr(pos, '[');
1457 if (pos == NULL || pos > end)
1458 break;
1459 pos++;
1460 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1461 wpa_printf(MSG_ERROR, "Too many auth params");
1462 goto fail;
1463 }
1464 eap->auth_id[eap->num_auths] = atoi(pos);
1465 pos = os_strchr(pos, ':');
1466 if (pos == NULL || pos > end)
1467 goto fail;
1468 pos++;
1469 eap->auth_val[eap->num_auths] = atoi(pos);
1470 pos = os_strchr(pos, ']');
1471 if (pos == NULL || pos > end)
1472 goto fail;
1473 pos++;
1474 eap->num_auths++;
1475 }
1476
1477 if (*end != ',')
1478 break;
1479
1480 pos = end + 1;
1481 }
1482
1483 /* Split realm list into null terminated realms */
1484 rpos = realm->realm_buf;
1485 i = 0;
1486 while (*rpos) {
1487 if (i >= MAX_NAI_REALMS) {
1488 wpa_printf(MSG_ERROR, "Too many realms");
1489 goto fail;
1490 }
1491 realm->realm[i++] = rpos;
1492 rpos = os_strchr(rpos, ';');
1493 if (rpos == NULL)
1494 break;
1495 *rpos++ = '\0';
1496 }
1497
1498 bss->nai_realm_count++;
1499
1500 return 0;
1501
1502fail:
1503 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1504 return -1;
1505}
1506
c551700f
KP
1507
1508static int parse_qos_map_set(struct hostapd_bss_config *bss,
1509 char *buf, int line)
1510{
1511 u8 qos_map_set[16 + 2 * 21], count = 0;
1512 char *pos = buf;
1513 int val;
1514
1515 for (;;) {
1516 if (count == sizeof(qos_map_set)) {
1517 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1518 "parameters '%s'", line, buf);
1519 return -1;
1520 }
1521
1522 val = atoi(pos);
1523 if (val > 255 || val < 0) {
1524 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1525 "'%s'", line, buf);
1526 return -1;
1527 }
1528
1529 qos_map_set[count++] = val;
1530 pos = os_strchr(pos, ',');
1531 if (!pos)
1532 break;
1533 pos++;
1534 }
1535
1536 if (count < 16 || count & 1) {
1537 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1538 line, buf);
1539 return -1;
1540 }
1541
1542 os_memcpy(bss->qos_map_set, qos_map_set, count);
1543 bss->qos_map_set_len = count;
1544
1545 return 0;
1546}
1547
4b2a77ab
JM
1548#endif /* CONFIG_INTERWORKING */
1549
1550
5ccc54aa
JK
1551#ifdef CONFIG_HS20
1552static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1553 int line)
1554{
1555 u8 *conn_cap;
1556 char *pos;
1557
1558 if (bss->hs20_connection_capability_len >= 0xfff0)
1559 return -1;
1560
1561 conn_cap = os_realloc(bss->hs20_connection_capability,
1562 bss->hs20_connection_capability_len + 4);
1563 if (conn_cap == NULL)
1564 return -1;
1565
1566 bss->hs20_connection_capability = conn_cap;
1567 conn_cap += bss->hs20_connection_capability_len;
1568 pos = buf;
1569 conn_cap[0] = atoi(pos);
1570 pos = os_strchr(pos, ':');
1571 if (pos == NULL)
1572 return -1;
1573 pos++;
1574 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1575 pos = os_strchr(pos, ':');
1576 if (pos == NULL)
1577 return -1;
1578 pos++;
1579 conn_cap[3] = atoi(pos);
1580 bss->hs20_connection_capability_len += 4;
1581
1582 return 0;
1583}
4065a309
JK
1584
1585
1586static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1587 int line)
1588{
1589 u8 *wan_metrics;
1590 char *pos;
1591
1592 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1593
1594 wan_metrics = os_zalloc(13);
1595 if (wan_metrics == NULL)
1596 return -1;
1597
1598 pos = buf;
1599 /* WAN Info */
1600 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1601 goto fail;
1602 pos += 2;
1603 if (*pos != ':')
1604 goto fail;
1605 pos++;
1606
1607 /* Downlink Speed */
1608 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1609 pos = os_strchr(pos, ':');
1610 if (pos == NULL)
1611 goto fail;
1612 pos++;
1613
1614 /* Uplink Speed */
1615 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1616 pos = os_strchr(pos, ':');
1617 if (pos == NULL)
1618 goto fail;
1619 pos++;
1620
1621 /* Downlink Load */
1622 wan_metrics[9] = atoi(pos);
1623 pos = os_strchr(pos, ':');
1624 if (pos == NULL)
1625 goto fail;
1626 pos++;
1627
1628 /* Uplink Load */
1629 wan_metrics[10] = atoi(pos);
1630 pos = os_strchr(pos, ':');
1631 if (pos == NULL)
1632 goto fail;
1633 pos++;
1634
1635 /* LMD */
1636 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1637
1638 os_free(bss->hs20_wan_metrics);
1639 bss->hs20_wan_metrics = wan_metrics;
1640
1641 return 0;
1642
1643fail:
1644 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
5cfc87b7 1645 line, buf);
4065a309
JK
1646 os_free(wan_metrics);
1647 return -1;
1648}
a9277e85
JK
1649
1650
1651static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1652 char *pos, int line)
1653{
1654 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1655 &bss->hs20_oper_friendly_name_count, pos)) {
1656 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1657 "hs20_oper_friendly_name '%s'", line, pos);
1658 return -1;
1659 }
1660 return 0;
1661}
f7bd7a01
JM
1662
1663
1664static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1665{
1666 struct hs20_icon *icon;
1667 char *end;
1668
1669 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1670 sizeof(struct hs20_icon));
1671 if (icon == NULL)
1672 return -1;
1673 bss->hs20_icons = icon;
1674 icon = &bss->hs20_icons[bss->hs20_icons_count];
1675 os_memset(icon, 0, sizeof(*icon));
1676
1677 icon->width = atoi(pos);
1678 pos = os_strchr(pos, ':');
1679 if (pos == NULL)
1680 return -1;
1681 pos++;
1682
1683 icon->height = atoi(pos);
1684 pos = os_strchr(pos, ':');
1685 if (pos == NULL)
1686 return -1;
1687 pos++;
1688
1689 end = os_strchr(pos, ':');
1690 if (end == NULL || end - pos > 3)
1691 return -1;
1692 os_memcpy(icon->language, pos, end - pos);
1693 pos = end + 1;
1694
1695 end = os_strchr(pos, ':');
1696 if (end == NULL || end - pos > 255)
1697 return -1;
1698 os_memcpy(icon->type, pos, end - pos);
1699 pos = end + 1;
1700
1701 end = os_strchr(pos, ':');
1702 if (end == NULL || end - pos > 255)
1703 return -1;
1704 os_memcpy(icon->name, pos, end - pos);
1705 pos = end + 1;
1706
1707 if (os_strlen(pos) > 255)
1708 return -1;
1709 os_memcpy(icon->file, pos, os_strlen(pos));
1710
1711 bss->hs20_icons_count++;
1712
1713 return 0;
1714}
1715
ae6d15c7
JM
1716
1717static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1718 char *pos, int line)
1719{
1720 size_t slen;
1721 char *str;
1722
1723 str = wpa_config_parse_string(pos, &slen);
81847c22 1724 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
ae6d15c7 1725 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
b2e32cde 1726 os_free(str);
ae6d15c7
JM
1727 return -1;
1728 }
1729
1730 os_memcpy(bss->osu_ssid, str, slen);
1731 bss->osu_ssid_len = slen;
1732 os_free(str);
1733
1734 return 0;
1735}
1736
1737
1738static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1739 char *pos, int line)
1740{
1741 struct hs20_osu_provider *p;
1742
1743 p = os_realloc_array(bss->hs20_osu_providers,
1744 bss->hs20_osu_providers_count + 1, sizeof(*p));
1745 if (p == NULL)
1746 return -1;
1747
1748 bss->hs20_osu_providers = p;
1749 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1750 bss->hs20_osu_providers_count++;
1751 os_memset(bss->last_osu, 0, sizeof(*p));
1752 bss->last_osu->server_uri = os_strdup(pos);
1753
1754 return 0;
1755}
1756
1757
1758static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1759 char *pos, int line)
1760{
1761 if (bss->last_osu == NULL) {
1762 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1763 return -1;
1764 }
1765
1766 if (parse_lang_string(&bss->last_osu->friendly_name,
1767 &bss->last_osu->friendly_name_count, pos)) {
1768 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1769 line, pos);
1770 return -1;
1771 }
1772
1773 return 0;
1774}
1775
1776
1777static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1778 char *pos, int line)
1779{
1780 if (bss->last_osu == NULL) {
1781 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1782 return -1;
1783 }
1784
1785 os_free(bss->last_osu->osu_nai);
1786 bss->last_osu->osu_nai = os_strdup(pos);
1787 if (bss->last_osu->osu_nai == NULL)
1788 return -1;
1789
1790 return 0;
1791}
1792
1793
1794static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1795 int line)
1796{
1797 if (bss->last_osu == NULL) {
1798 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1799 return -1;
1800 }
1801
1802 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1803 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1804 return -1;
1805 }
1806
1807 return 0;
1808}
1809
1810
1811static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1812 int line)
1813{
1814 char **n;
1815 struct hs20_osu_provider *p = bss->last_osu;
1816
1817 if (p == NULL) {
1818 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1819 return -1;
1820 }
1821
1822 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1823 if (n == NULL)
1824 return -1;
1825 p->icons = n;
1826 p->icons[p->icons_count] = os_strdup(pos);
1827 if (p->icons[p->icons_count] == NULL)
1828 return -1;
1829 p->icons_count++;
1830
1831 return 0;
1832}
1833
1834
1835static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1836 char *pos, int line)
1837{
1838 if (bss->last_osu == NULL) {
1839 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1840 return -1;
1841 }
1842
1843 if (parse_lang_string(&bss->last_osu->service_desc,
1844 &bss->last_osu->service_desc_count, pos)) {
1845 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1846 line, pos);
1847 return -1;
1848 }
1849
1850 return 0;
1851}
1852
5ccc54aa
JK
1853#endif /* CONFIG_HS20 */
1854
1855
ffdaa05a
JM
1856#ifdef CONFIG_WPS_NFC
1857static struct wpabuf * hostapd_parse_bin(const char *buf)
1858{
1859 size_t len;
1860 struct wpabuf *ret;
1861
1862 len = os_strlen(buf);
1863 if (len & 0x01)
1864 return NULL;
1865 len /= 2;
1866
1867 ret = wpabuf_alloc(len);
1868 if (ret == NULL)
1869 return NULL;
1870
1871 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1872 wpabuf_free(ret);
1873 return NULL;
1874 }
1875
1876 return ret;
1877}
1878#endif /* CONFIG_WPS_NFC */
1879
1880
68fa00c3
JM
1881#ifdef CONFIG_ACS
1882static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
1883 char *pos)
1884{
1885 struct acs_bias *bias = NULL, *tmp;
1886 unsigned int num = 0;
1887 char *end;
1888
1889 while (*pos) {
1890 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
1891 if (!tmp)
1892 goto fail;
1893 bias = tmp;
1894
1895 bias[num].channel = atoi(pos);
1896 if (bias[num].channel <= 0)
1897 goto fail;
1898 pos = os_strchr(pos, ':');
1899 if (!pos)
1900 goto fail;
1901 pos++;
1902 bias[num].bias = strtod(pos, &end);
1903 if (end == pos || bias[num].bias < 0.0)
1904 goto fail;
1905 pos = end;
1906 if (*pos != ' ' && *pos != '\0')
1907 goto fail;
1908 num++;
1909 }
1910
1911 os_free(conf->acs_chan_bias);
1912 conf->acs_chan_bias = bias;
1913 conf->num_acs_chan_bias = num;
1914
1915 return 0;
1916fail:
1917 os_free(bias);
1918 return -1;
1919}
1920#endif /* CONFIG_ACS */
1921
1922
ef45bc89
SP
1923static int hostapd_config_fill(struct hostapd_config *conf,
1924 struct hostapd_bss_config *bss,
1925 char *buf, char *pos, int line)
41d719d6 1926{
599f40db
JM
1927 if (os_strcmp(buf, "interface") == 0) {
1928 os_strlcpy(conf->bss[0]->iface, pos,
1929 sizeof(conf->bss[0]->iface));
1930 } else if (os_strcmp(buf, "bridge") == 0) {
1931 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1932 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1933 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
1934 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1935 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
1936 } else if (os_strcmp(buf, "driver") == 0) {
1937 int j;
1938 /* clear to get error below if setting is invalid */
1939 conf->driver = NULL;
1940 for (j = 0; wpa_drivers[j]; j++) {
1941 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
1942 conf->driver = wpa_drivers[j];
1943 break;
41d719d6 1944 }
599f40db
JM
1945 }
1946 if (conf->driver == NULL) {
1947 wpa_printf(MSG_ERROR,
1948 "Line %d: invalid/unknown driver '%s'",
1949 line, pos);
a0b728b7 1950 return 1;
599f40db 1951 }
0ecff8d7
JM
1952 } else if (os_strcmp(buf, "driver_params") == 0) {
1953 os_free(conf->driver_params);
1954 conf->driver_params = os_strdup(pos);
599f40db
JM
1955 } else if (os_strcmp(buf, "debug") == 0) {
1956 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
1957 line);
1958 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1959 bss->logger_syslog_level = atoi(pos);
1960 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1961 bss->logger_stdout_level = atoi(pos);
1962 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1963 bss->logger_syslog = atoi(pos);
1964 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1965 bss->logger_stdout = atoi(pos);
1966 } else if (os_strcmp(buf, "dump_file") == 0) {
1967 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
1968 line);
1969 } else if (os_strcmp(buf, "ssid") == 0) {
1970 bss->ssid.ssid_len = os_strlen(pos);
81847c22 1971 if (bss->ssid.ssid_len > SSID_MAX_LEN ||
599f40db
JM
1972 bss->ssid.ssid_len < 1) {
1973 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1974 line, pos);
a0b728b7 1975 return 1;
599f40db 1976 }
b4c26ef9
JM
1977 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
1978 bss->ssid.ssid_set = 1;
599f40db
JM
1979 } else if (os_strcmp(buf, "ssid2") == 0) {
1980 size_t slen;
1981 char *str = wpa_config_parse_string(pos, &slen);
81847c22 1982 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
599f40db
JM
1983 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1984 line, pos);
b2e32cde 1985 os_free(str);
a0b728b7 1986 return 1;
599f40db 1987 }
b2e32cde
JM
1988 os_memcpy(bss->ssid.ssid, str, slen);
1989 bss->ssid.ssid_len = slen;
1990 bss->ssid.ssid_set = 1;
599f40db
JM
1991 os_free(str);
1992 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1993 bss->ssid.utf8_ssid = atoi(pos) > 0;
1994 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1995 bss->macaddr_acl = atoi(pos);
1996 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1997 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1998 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1999 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
2000 line, bss->macaddr_acl);
2001 }
2002 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2003 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2004 &bss->num_accept_mac)) {
2005 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2006 line, pos);
a0b728b7 2007 return 1;
599f40db
JM
2008 }
2009 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2010 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2011 &bss->num_deny_mac)) {
2012 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2013 line, pos);
a0b728b7 2014 return 1;
599f40db
JM
2015 }
2016 } else if (os_strcmp(buf, "wds_sta") == 0) {
2017 bss->wds_sta = atoi(pos);
2018 } else if (os_strcmp(buf, "start_disabled") == 0) {
2019 bss->start_disabled = atoi(pos);
2020 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2021 bss->isolate = atoi(pos);
2022 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2023 bss->ap_max_inactivity = atoi(pos);
2024 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2025 bss->skip_inactivity_poll = atoi(pos);
2026 } else if (os_strcmp(buf, "country_code") == 0) {
2027 os_memcpy(conf->country, pos, 2);
2028 /* FIX: make this configurable */
2029 conf->country[2] = ' ';
2030 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2031 conf->ieee80211d = atoi(pos);
2032 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2033 conf->ieee80211h = atoi(pos);
2034 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2035 bss->ieee802_1x = atoi(pos);
2036 } else if (os_strcmp(buf, "eapol_version") == 0) {
2037 bss->eapol_version = atoi(pos);
2038 if (bss->eapol_version < 1 || bss->eapol_version > 2) {
2039 wpa_printf(MSG_ERROR,
2040 "Line %d: invalid EAPOL version (%d): '%s'.",
2041 line, bss->eapol_version, pos);
a0b728b7 2042 return 1;
b4c26ef9
JM
2043 }
2044 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
41d719d6 2045#ifdef EAP_SERVER
599f40db
JM
2046 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2047 bss->eap_server = atoi(pos);
2048 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2049 } else if (os_strcmp(buf, "eap_server") == 0) {
2050 bss->eap_server = atoi(pos);
2051 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2052 if (hostapd_config_read_eap_user(pos, bss))
a0b728b7 2053 return 1;
599f40db
JM
2054 } else if (os_strcmp(buf, "ca_cert") == 0) {
2055 os_free(bss->ca_cert);
2056 bss->ca_cert = os_strdup(pos);
2057 } else if (os_strcmp(buf, "server_cert") == 0) {
2058 os_free(bss->server_cert);
2059 bss->server_cert = os_strdup(pos);
2060 } else if (os_strcmp(buf, "private_key") == 0) {
2061 os_free(bss->private_key);
2062 bss->private_key = os_strdup(pos);
2063 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2064 os_free(bss->private_key_passwd);
2065 bss->private_key_passwd = os_strdup(pos);
2066 } else if (os_strcmp(buf, "check_crl") == 0) {
2067 bss->check_crl = atoi(pos);
2068 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2069 os_free(bss->ocsp_stapling_response);
2070 bss->ocsp_stapling_response = os_strdup(pos);
2071 } else if (os_strcmp(buf, "dh_file") == 0) {
2072 os_free(bss->dh_file);
2073 bss->dh_file = os_strdup(pos);
f8995f8f
JM
2074 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2075 os_free(bss->openssl_ciphers);
2076 bss->openssl_ciphers = os_strdup(pos);
599f40db
JM
2077 } else if (os_strcmp(buf, "fragment_size") == 0) {
2078 bss->fragment_size = atoi(pos);
41d719d6 2079#ifdef EAP_SERVER_FAST
599f40db
JM
2080 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2081 os_free(bss->pac_opaque_encr_key);
2082 bss->pac_opaque_encr_key = os_malloc(16);
2083 if (bss->pac_opaque_encr_key == NULL) {
2084 wpa_printf(MSG_ERROR,
2085 "Line %d: No memory for pac_opaque_encr_key",
2086 line);
a0b728b7 2087 return 1;
599f40db
JM
2088 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2089 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2090 line);
a0b728b7 2091 return 1;
599f40db
JM
2092 }
2093 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2094 size_t idlen = os_strlen(pos);
2095 if (idlen & 1) {
2096 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2097 line);
a0b728b7 2098 return 1;
b4c26ef9
JM
2099 }
2100 os_free(bss->eap_fast_a_id);
2101 bss->eap_fast_a_id = os_malloc(idlen / 2);
2102 if (bss->eap_fast_a_id == NULL ||
2103 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2104 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2105 line);
599f40db 2106 os_free(bss->eap_fast_a_id);
b4c26ef9
JM
2107 bss->eap_fast_a_id = NULL;
2108 return 1;
2109 } else {
2110 bss->eap_fast_a_id_len = idlen / 2;
599f40db
JM
2111 }
2112 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2113 os_free(bss->eap_fast_a_id_info);
2114 bss->eap_fast_a_id_info = os_strdup(pos);
2115 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2116 bss->eap_fast_prov = atoi(pos);
2117 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2118 bss->pac_key_lifetime = atoi(pos);
2119 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2120 bss->pac_key_refresh_time = atoi(pos);
41d719d6
JM
2121#endif /* EAP_SERVER_FAST */
2122#ifdef EAP_SERVER_SIM
599f40db
JM
2123 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2124 os_free(bss->eap_sim_db);
2125 bss->eap_sim_db = os_strdup(pos);
2126 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2127 bss->eap_sim_aka_result_ind = atoi(pos);
41d719d6
JM
2128#endif /* EAP_SERVER_SIM */
2129#ifdef EAP_SERVER_TNC
599f40db
JM
2130 } else if (os_strcmp(buf, "tnc") == 0) {
2131 bss->tnc = atoi(pos);
41d719d6 2132#endif /* EAP_SERVER_TNC */
df684d82 2133#ifdef EAP_SERVER_PWD
599f40db
JM
2134 } else if (os_strcmp(buf, "pwd_group") == 0) {
2135 bss->pwd_group = atoi(pos);
df684d82 2136#endif /* EAP_SERVER_PWD */
d3bddd8b
JM
2137 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2138 bss->eap_server_erp = atoi(pos);
41d719d6 2139#endif /* EAP_SERVER */
599f40db
JM
2140 } else if (os_strcmp(buf, "eap_message") == 0) {
2141 char *term;
5784b9a4 2142 os_free(bss->eap_req_id_text);
599f40db
JM
2143 bss->eap_req_id_text = os_strdup(pos);
2144 if (bss->eap_req_id_text == NULL) {
2145 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2146 line);
a0b728b7 2147 return 1;
599f40db
JM
2148 }
2149 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2150 term = os_strstr(bss->eap_req_id_text, "\\0");
2151 if (term) {
2152 *term++ = '\0';
2153 os_memmove(term, term + 1,
2154 bss->eap_req_id_text_len -
2155 (term - bss->eap_req_id_text) - 1);
2156 bss->eap_req_id_text_len--;
2157 }
2a5156a6
JM
2158 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2159 bss->erp_send_reauth_start = atoi(pos);
2160 } else if (os_strcmp(buf, "erp_domain") == 0) {
2161 os_free(bss->erp_domain);
2162 bss->erp_domain = os_strdup(pos);
599f40db
JM
2163 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
2164 bss->default_wep_key_len = atoi(pos);
2165 if (bss->default_wep_key_len > 13) {
2166 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
2167 line,
2168 (unsigned long) bss->default_wep_key_len,
2169 (unsigned long)
2170 bss->default_wep_key_len * 8);
a0b728b7 2171 return 1;
599f40db
JM
2172 }
2173 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
2174 bss->individual_wep_key_len = atoi(pos);
2175 if (bss->individual_wep_key_len < 0 ||
2176 bss->individual_wep_key_len > 13) {
2177 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
2178 line, bss->individual_wep_key_len,
2179 bss->individual_wep_key_len * 8);
a0b728b7 2180 return 1;
599f40db
JM
2181 }
2182 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2183 bss->wep_rekeying_period = atoi(pos);
2184 if (bss->wep_rekeying_period < 0) {
2185 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2186 line, bss->wep_rekeying_period);
a0b728b7 2187 return 1;
599f40db
JM
2188 }
2189 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2190 bss->eap_reauth_period = atoi(pos);
2191 if (bss->eap_reauth_period < 0) {
2192 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2193 line, bss->eap_reauth_period);
a0b728b7 2194 return 1;
599f40db
JM
2195 }
2196 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2197 bss->eapol_key_index_workaround = atoi(pos);
41d719d6 2198#ifdef CONFIG_IAPP
599f40db
JM
2199 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2200 bss->ieee802_11f = 1;
2201 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
41d719d6 2202#endif /* CONFIG_IAPP */
599f40db
JM
2203 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2204 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2205 wpa_printf(MSG_ERROR,
2206 "Line %d: invalid IP address '%s'",
2207 line, pos);
a0b728b7 2208 return 1;
599f40db
JM
2209 }
2210 } else if (os_strcmp(buf, "nas_identifier") == 0) {
5784b9a4 2211 os_free(bss->nas_identifier);
599f40db 2212 bss->nas_identifier = os_strdup(pos);
41d719d6 2213#ifndef CONFIG_NO_RADIUS
9836cb53
JM
2214 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2215 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2216 wpa_printf(MSG_ERROR,
2217 "Line %d: invalid IP address '%s'",
2218 line, pos);
2219 return 1;
2220 }
2221 bss->radius->force_client_addr = 1;
599f40db
JM
2222 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2223 if (hostapd_config_read_radius_addr(
2224 &bss->radius->auth_servers,
2225 &bss->radius->num_auth_servers, pos, 1812,
2226 &bss->radius->auth_server)) {
2227 wpa_printf(MSG_ERROR,
2228 "Line %d: invalid IP address '%s'",
2229 line, pos);
a0b728b7 2230 return 1;
599f40db 2231 }
bbee36e3
JM
2232 } else if (bss->radius->auth_server &&
2233 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2234 if (hostapd_parse_ip_addr(pos,
2235 &bss->radius->auth_server->addr)) {
2236 wpa_printf(MSG_ERROR,
2237 "Line %d: invalid IP address '%s'",
2238 line, pos);
2239 return 1;
2240 }
599f40db
JM
2241 } else if (bss->radius->auth_server &&
2242 os_strcmp(buf, "auth_server_port") == 0) {
2243 bss->radius->auth_server->port = atoi(pos);
2244 } else if (bss->radius->auth_server &&
2245 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2246 int len = os_strlen(pos);
2247 if (len == 0) {
2248 /* RFC 2865, Ch. 3 */
2249 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2250 line);
a0b728b7 2251 return 1;
599f40db 2252 }
5784b9a4 2253 os_free(bss->radius->auth_server->shared_secret);
599f40db
JM
2254 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2255 bss->radius->auth_server->shared_secret_len = len;
2256 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2257 if (hostapd_config_read_radius_addr(
2258 &bss->radius->acct_servers,
2259 &bss->radius->num_acct_servers, pos, 1813,
2260 &bss->radius->acct_server)) {
2261 wpa_printf(MSG_ERROR,
2262 "Line %d: invalid IP address '%s'",
2263 line, pos);
a0b728b7 2264 return 1;
bbee36e3
JM
2265 }
2266 } else if (bss->radius->acct_server &&
2267 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2268 if (hostapd_parse_ip_addr(pos,
2269 &bss->radius->acct_server->addr)) {
2270 wpa_printf(MSG_ERROR,
2271 "Line %d: invalid IP address '%s'",
2272 line, pos);
2273 return 1;
599f40db
JM
2274 }
2275 } else if (bss->radius->acct_server &&
2276 os_strcmp(buf, "acct_server_port") == 0) {
2277 bss->radius->acct_server->port = atoi(pos);
2278 } else if (bss->radius->acct_server &&
2279 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2280 int len = os_strlen(pos);
2281 if (len == 0) {
2282 /* RFC 2865, Ch. 3 */
2283 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2284 line);
a0b728b7 2285 return 1;
599f40db 2286 }
5784b9a4 2287 os_free(bss->radius->acct_server->shared_secret);
599f40db
JM
2288 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2289 bss->radius->acct_server->shared_secret_len = len;
2290 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2291 bss->radius->retry_primary_interval = atoi(pos);
2292 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2293 bss->acct_interim_interval = atoi(pos);
2294 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2295 bss->radius_request_cui = atoi(pos);
2296 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2297 struct hostapd_radius_attr *attr, *a;
2298 attr = hostapd_parse_radius_attr(pos);
2299 if (attr == NULL) {
2300 wpa_printf(MSG_ERROR,
2301 "Line %d: invalid radius_auth_req_attr",
2302 line);
a0b728b7 2303 return 1;
599f40db
JM
2304 } else if (bss->radius_auth_req_attr == NULL) {
2305 bss->radius_auth_req_attr = attr;
2306 } else {
2307 a = bss->radius_auth_req_attr;
2308 while (a->next)
2309 a = a->next;
2310 a->next = attr;
2311 }
2312 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2313 struct hostapd_radius_attr *attr, *a;
2314 attr = hostapd_parse_radius_attr(pos);
2315 if (attr == NULL) {
2316 wpa_printf(MSG_ERROR,
2317 "Line %d: invalid radius_acct_req_attr",
2318 line);
a0b728b7 2319 return 1;
599f40db
JM
2320 } else if (bss->radius_acct_req_attr == NULL) {
2321 bss->radius_acct_req_attr = attr;
2322 } else {
2323 a = bss->radius_acct_req_attr;
2324 while (a->next)
2325 a = a->next;
2326 a->next = attr;
2327 }
2328 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2329 bss->radius_das_port = atoi(pos);
2330 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2331 if (hostapd_parse_das_client(bss, pos) < 0) {
2332 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2333 line);
a0b728b7 2334 return 1;
599f40db
JM
2335 }
2336 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2337 bss->radius_das_time_window = atoi(pos);
2338 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2339 bss->radius_das_require_event_timestamp = atoi(pos);
41d719d6 2340#endif /* CONFIG_NO_RADIUS */
599f40db
JM
2341 } else if (os_strcmp(buf, "auth_algs") == 0) {
2342 bss->auth_algs = atoi(pos);
2343 if (bss->auth_algs == 0) {
2344 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2345 line);
a0b728b7 2346 return 1;
599f40db
JM
2347 }
2348 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2349 bss->max_num_sta = atoi(pos);
2350 if (bss->max_num_sta < 0 ||
2351 bss->max_num_sta > MAX_STA_COUNT) {
2352 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2353 line, bss->max_num_sta, MAX_STA_COUNT);
a0b728b7 2354 return 1;
599f40db
JM
2355 }
2356 } else if (os_strcmp(buf, "wpa") == 0) {
2357 bss->wpa = atoi(pos);
2358 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2359 bss->wpa_group_rekey = atoi(pos);
2360 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2361 bss->wpa_strict_rekey = atoi(pos);
2362 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2363 bss->wpa_gmk_rekey = atoi(pos);
2364 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2365 bss->wpa_ptk_rekey = atoi(pos);
2366 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2367 int len = os_strlen(pos);
2368 if (len < 8 || len > 63) {
2369 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2370 line, len);
a0b728b7 2371 return 1;
b4c26ef9
JM
2372 }
2373 os_free(bss->ssid.wpa_passphrase);
2374 bss->ssid.wpa_passphrase = os_strdup(pos);
2375 if (bss->ssid.wpa_passphrase) {
891dfb33 2376 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
b4c26ef9 2377 bss->ssid.wpa_passphrase_set = 1;
599f40db
JM
2378 }
2379 } else if (os_strcmp(buf, "wpa_psk") == 0) {
891dfb33 2380 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
599f40db
JM
2381 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2382 if (bss->ssid.wpa_psk == NULL)
a0b728b7 2383 return 1;
b4c26ef9
JM
2384 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2385 pos[PMK_LEN * 2] != '\0') {
599f40db
JM
2386 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2387 line, pos);
891dfb33 2388 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
a0b728b7 2389 return 1;
599f40db 2390 }
b4c26ef9
JM
2391 bss->ssid.wpa_psk->group = 1;
2392 os_free(bss->ssid.wpa_passphrase);
2393 bss->ssid.wpa_passphrase = NULL;
2394 bss->ssid.wpa_psk_set = 1;
599f40db
JM
2395 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2396 os_free(bss->ssid.wpa_psk_file);
2397 bss->ssid.wpa_psk_file = os_strdup(pos);
2398 if (!bss->ssid.wpa_psk_file) {
2399 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2400 line);
a0b728b7 2401 return 1;
599f40db
JM
2402 }
2403 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2404 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2405 if (bss->wpa_key_mgmt == -1)
a0b728b7 2406 return 1;
599f40db
JM
2407 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2408 bss->wpa_psk_radius = atoi(pos);
2409 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2410 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2411 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2412 wpa_printf(MSG_ERROR,
2413 "Line %d: unknown wpa_psk_radius %d",
2414 line, bss->wpa_psk_radius);
a0b728b7 2415 return 1;
599f40db
JM
2416 }
2417 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2418 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2419 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
a0b728b7 2420 return 1;
b4c26ef9
JM
2421 if (bss->wpa_pairwise &
2422 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
599f40db
JM
2423 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2424 bss->wpa_pairwise, pos);
a0b728b7 2425 return 1;
599f40db
JM
2426 }
2427 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2428 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2429 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
a0b728b7 2430 return 1;
b4c26ef9
JM
2431 if (bss->rsn_pairwise &
2432 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
599f40db
JM
2433 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2434 bss->rsn_pairwise, pos);
a0b728b7 2435 return 1;
599f40db 2436 }
41d719d6 2437#ifdef CONFIG_RSN_PREAUTH
599f40db
JM
2438 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2439 bss->rsn_preauth = atoi(pos);
2440 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
5784b9a4 2441 os_free(bss->rsn_preauth_interfaces);
599f40db 2442 bss->rsn_preauth_interfaces = os_strdup(pos);
41d719d6
JM
2443#endif /* CONFIG_RSN_PREAUTH */
2444#ifdef CONFIG_PEERKEY
599f40db
JM
2445 } else if (os_strcmp(buf, "peerkey") == 0) {
2446 bss->peerkey = atoi(pos);
41d719d6
JM
2447#endif /* CONFIG_PEERKEY */
2448#ifdef CONFIG_IEEE80211R
599f40db
JM
2449 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2450 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2451 hexstr2bin(pos, bss->mobility_domain,
2452 MOBILITY_DOMAIN_ID_LEN) != 0) {
2453 wpa_printf(MSG_ERROR,
2454 "Line %d: Invalid mobility_domain '%s'",
2455 line, pos);
a0b728b7 2456 return 1;
599f40db
JM
2457 }
2458 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2459 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2460 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2461 wpa_printf(MSG_ERROR,
2462 "Line %d: Invalid r1_key_holder '%s'",
2463 line, pos);
a0b728b7 2464 return 1;
599f40db
JM
2465 }
2466 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2467 bss->r0_key_lifetime = atoi(pos);
2468 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2469 bss->reassociation_deadline = atoi(pos);
2470 } else if (os_strcmp(buf, "r0kh") == 0) {
2471 if (add_r0kh(bss, pos) < 0) {
2472 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2473 line, pos);
a0b728b7 2474 return 1;
599f40db
JM
2475 }
2476 } else if (os_strcmp(buf, "r1kh") == 0) {
2477 if (add_r1kh(bss, pos) < 0) {
2478 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2479 line, pos);
a0b728b7 2480 return 1;
599f40db
JM
2481 }
2482 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2483 bss->pmk_r1_push = atoi(pos);
2484 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2485 bss->ft_over_ds = atoi(pos);
41d719d6
JM
2486#endif /* CONFIG_IEEE80211R */
2487#ifndef CONFIG_NO_CTRL_IFACE
599f40db
JM
2488 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2489 os_free(bss->ctrl_interface);
2490 bss->ctrl_interface = os_strdup(pos);
2491 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
41d719d6 2492#ifndef CONFIG_NATIVE_WINDOWS
599f40db
JM
2493 struct group *grp;
2494 char *endp;
2495 const char *group = pos;
41d719d6 2496
599f40db
JM
2497 grp = getgrnam(group);
2498 if (grp) {
2499 bss->ctrl_interface_gid = grp->gr_gid;
41d719d6 2500 bss->ctrl_interface_gid_set = 1;
599f40db
JM
2501 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2502 bss->ctrl_interface_gid, group);
2503 return 0;
2504 }
2505
2506 /* Group name not found - try to parse this as gid */
2507 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2508 if (*group == '\0' || *endp != '\0') {
2509 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2510 line, group);
2511 return 1;
2512 }
2513 bss->ctrl_interface_gid_set = 1;
2514 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2515 bss->ctrl_interface_gid);
41d719d6
JM
2516#endif /* CONFIG_NATIVE_WINDOWS */
2517#endif /* CONFIG_NO_CTRL_IFACE */
2518#ifdef RADIUS_SERVER
599f40db
JM
2519 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2520 os_free(bss->radius_server_clients);
2521 bss->radius_server_clients = os_strdup(pos);
2522 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2523 bss->radius_server_auth_port = atoi(pos);
2524 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2525 bss->radius_server_acct_port = atoi(pos);
2526 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2527 bss->radius_server_ipv6 = atoi(pos);
41d719d6 2528#endif /* RADIUS_SERVER */
599f40db
JM
2529 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2530 bss->use_pae_group_addr = atoi(pos);
2531 } else if (os_strcmp(buf, "hw_mode") == 0) {
2532 if (os_strcmp(pos, "a") == 0)
2533 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2534 else if (os_strcmp(pos, "b") == 0)
2535 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2536 else if (os_strcmp(pos, "g") == 0)
2537 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2538 else if (os_strcmp(pos, "ad") == 0)
2539 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
3784c058
PX
2540 else if (os_strcmp(pos, "any") == 0)
2541 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
599f40db
JM
2542 else {
2543 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
2544 line, pos);
a0b728b7 2545 return 1;
599f40db
JM
2546 }
2547 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
01a02593
HK
2548 if (os_strcmp(pos, "ad") == 0)
2549 bss->wps_rf_bands = WPS_RF_60GHZ;
2550 else if (os_strcmp(pos, "a") == 0)
599f40db
JM
2551 bss->wps_rf_bands = WPS_RF_50GHZ;
2552 else if (os_strcmp(pos, "g") == 0 ||
2553 os_strcmp(pos, "b") == 0)
2554 bss->wps_rf_bands = WPS_RF_24GHZ;
2555 else if (os_strcmp(pos, "ag") == 0 ||
2556 os_strcmp(pos, "ga") == 0)
2557 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
2558 else {
2559 wpa_printf(MSG_ERROR,
2560 "Line %d: unknown wps_rf_band '%s'",
2561 line, pos);
a0b728b7 2562 return 1;
599f40db
JM
2563 }
2564 } else if (os_strcmp(buf, "channel") == 0) {
2565 if (os_strcmp(pos, "acs_survey") == 0) {
50f4f2a0 2566#ifndef CONFIG_ACS
599f40db
JM
2567 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
2568 line);
a0b728b7 2569 return 1;
9670f877 2570#else /* CONFIG_ACS */
857d9422 2571 conf->acs = 1;
599f40db 2572 conf->channel = 0;
9670f877 2573#endif /* CONFIG_ACS */
857d9422 2574 } else {
599f40db 2575 conf->channel = atoi(pos);
857d9422
MM
2576 conf->acs = conf->channel == 0;
2577 }
599f40db 2578 } else if (os_strcmp(buf, "chanlist") == 0) {
857d9422 2579 if (hostapd_parse_chanlist(conf, pos)) {
599f40db
JM
2580 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
2581 line);
a0b728b7 2582 return 1;
599f40db
JM
2583 }
2584 } else if (os_strcmp(buf, "beacon_int") == 0) {
2585 int val = atoi(pos);
2586 /* MIB defines range as 1..65535, but very small values
2587 * cause problems with the current implementation.
2588 * Since it is unlikely that this small numbers are
2589 * useful in real life scenarios, do not allow beacon
2590 * period to be set below 15 TU. */
2591 if (val < 15 || val > 65535) {
2592 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
2593 line, val);
a0b728b7 2594 return 1;
b4c26ef9
JM
2595 }
2596 conf->beacon_int = val;
50f4f2a0 2597#ifdef CONFIG_ACS
599f40db
JM
2598 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
2599 int val = atoi(pos);
2600 if (val <= 0 || val > 100) {
2601 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
2602 line, val);
a0b728b7 2603 return 1;
b4c26ef9
JM
2604 }
2605 conf->acs_num_scans = val;
68fa00c3
JM
2606 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
2607 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
2608 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
2609 line);
2610 return -1;
2611 }
50f4f2a0 2612#endif /* CONFIG_ACS */
599f40db
JM
2613 } else if (os_strcmp(buf, "dtim_period") == 0) {
2614 bss->dtim_period = atoi(pos);
2615 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2616 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
2617 line, bss->dtim_period);
a0b728b7 2618 return 1;
599f40db 2619 }
ec8f36af
KP
2620 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
2621 bss->bss_load_update_period = atoi(pos);
2622 if (bss->bss_load_update_period < 0 ||
2623 bss->bss_load_update_period > 100) {
2624 wpa_printf(MSG_ERROR,
2625 "Line %d: invalid bss_load_update_period %d",
2626 line, bss->bss_load_update_period);
2627 return 1;
2628 }
599f40db
JM
2629 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2630 conf->rts_threshold = atoi(pos);
2631 if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
2632 wpa_printf(MSG_ERROR,
2633 "Line %d: invalid rts_threshold %d",
2634 line, conf->rts_threshold);
a0b728b7 2635 return 1;
599f40db
JM
2636 }
2637 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2638 conf->fragm_threshold = atoi(pos);
2639 if (conf->fragm_threshold < 256 ||
2640 conf->fragm_threshold > 2346) {
2641 wpa_printf(MSG_ERROR,
2642 "Line %d: invalid fragm_threshold %d",
2643 line, conf->fragm_threshold);
a0b728b7 2644 return 1;
599f40db
JM
2645 }
2646 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2647 int val = atoi(pos);
2648 if (val != 0 && val != 1) {
2649 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
2650 line, val);
b4c26ef9
JM
2651 return 1;
2652 }
2653 conf->send_probe_response = val;
599f40db
JM
2654 } else if (os_strcmp(buf, "supported_rates") == 0) {
2655 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
2656 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2657 line);
a0b728b7 2658 return 1;
599f40db
JM
2659 }
2660 } else if (os_strcmp(buf, "basic_rates") == 0) {
2661 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
2662 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2663 line);
a0b728b7 2664 return 1;
599f40db
JM
2665 }
2666 } else if (os_strcmp(buf, "preamble") == 0) {
2667 if (atoi(pos))
2668 conf->preamble = SHORT_PREAMBLE;
2669 else
2670 conf->preamble = LONG_PREAMBLE;
2671 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2672 bss->ignore_broadcast_ssid = atoi(pos);
2673 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2674 bss->ssid.wep.idx = atoi(pos);
2675 if (bss->ssid.wep.idx > 3) {
2676 wpa_printf(MSG_ERROR,
2677 "Invalid wep_default_key index %d",
2678 bss->ssid.wep.idx);
a0b728b7 2679 return 1;
599f40db
JM
2680 }
2681 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2682 os_strcmp(buf, "wep_key1") == 0 ||
2683 os_strcmp(buf, "wep_key2") == 0 ||
2684 os_strcmp(buf, "wep_key3") == 0) {
2685 if (hostapd_config_read_wep(&bss->ssid.wep,
2686 buf[7] - '0', pos)) {
2687 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
2688 line, buf);
a0b728b7 2689 return 1;
599f40db 2690 }
41d719d6 2691#ifndef CONFIG_NO_VLAN
599f40db
JM
2692 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2693 bss->ssid.dynamic_vlan = atoi(pos);
2694 } else if (os_strcmp(buf, "vlan_file") == 0) {
2695 if (hostapd_config_read_vlan_file(bss, pos)) {
2696 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
2697 line, pos);
a0b728b7 2698 return 1;
599f40db
JM
2699 }
2700 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2701 bss->ssid.vlan_naming = atoi(pos);
2702 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2703 bss->ssid.vlan_naming < 0) {
2704 wpa_printf(MSG_ERROR,
2705 "Line %d: invalid naming scheme %d",
2706 line, bss->ssid.vlan_naming);
a0b728b7 2707 return 1;
599f40db 2708 }
41d719d6 2709#ifdef CONFIG_FULL_DYNAMIC_VLAN
599f40db 2710 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
5784b9a4 2711 os_free(bss->ssid.vlan_tagged_interface);
599f40db 2712 bss->ssid.vlan_tagged_interface = os_strdup(pos);
41d719d6
JM
2713#endif /* CONFIG_FULL_DYNAMIC_VLAN */
2714#endif /* CONFIG_NO_VLAN */
599f40db
JM
2715 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2716 conf->ap_table_max_size = atoi(pos);
2717 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2718 conf->ap_table_expiration_time = atoi(pos);
2719 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2720 if (hostapd_config_tx_queue(conf, buf, pos)) {
2721 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
2722 line);
a0b728b7 2723 return 1;
599f40db
JM
2724 }
2725 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2726 os_strcmp(buf, "wmm_enabled") == 0) {
2727 bss->wmm_enabled = atoi(pos);
2728 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2729 bss->wmm_uapsd = atoi(pos);
2730 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2731 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2732 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
2733 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
2734 line);
a0b728b7 2735 return 1;
599f40db
JM
2736 }
2737 } else if (os_strcmp(buf, "bss") == 0) {
2738 if (hostapd_config_bss(conf, pos)) {
2739 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
2740 line);
a0b728b7 2741 return 1;
599f40db
JM
2742 }
2743 } else if (os_strcmp(buf, "bssid") == 0) {
2744 if (hwaddr_aton(pos, bss->bssid)) {
2745 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
2746 line);
a0b728b7 2747 return 1;
599f40db 2748 }
41d719d6 2749#ifdef CONFIG_IEEE80211W
599f40db
JM
2750 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2751 bss->ieee80211w = atoi(pos);
8dd9f9cd
JM
2752 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
2753 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
2754 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
2755 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
2756 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
2757 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
2758 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
2759 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
2760 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
2761 } else {
2762 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
2763 line, pos);
2764 return 1;
2765 }
599f40db
JM
2766 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2767 bss->assoc_sa_query_max_timeout = atoi(pos);
2768 if (bss->assoc_sa_query_max_timeout == 0) {
2769 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
2770 line);
a0b728b7 2771 return 1;
599f40db
JM
2772 }
2773 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
2774 bss->assoc_sa_query_retry_timeout = atoi(pos);
2775 if (bss->assoc_sa_query_retry_timeout == 0) {
2776 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
2777 line);
a0b728b7 2778 return 1;
599f40db 2779 }
41d719d6
JM
2780#endif /* CONFIG_IEEE80211W */
2781#ifdef CONFIG_IEEE80211N
599f40db
JM
2782 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2783 conf->ieee80211n = atoi(pos);
2784 } else if (os_strcmp(buf, "ht_capab") == 0) {
2785 if (hostapd_config_ht_capab(conf, pos) < 0) {
2786 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
2787 line);
a0b728b7 2788 return 1;
599f40db
JM
2789 }
2790 } else if (os_strcmp(buf, "require_ht") == 0) {
2791 conf->require_ht = atoi(pos);
2792 } else if (os_strcmp(buf, "obss_interval") == 0) {
2793 conf->obss_interval = atoi(pos);
41d719d6 2794#endif /* CONFIG_IEEE80211N */
efe45d14 2795#ifdef CONFIG_IEEE80211AC
599f40db
JM
2796 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2797 conf->ieee80211ac = atoi(pos);
2798 } else if (os_strcmp(buf, "vht_capab") == 0) {
2799 if (hostapd_config_vht_capab(conf, pos) < 0) {
2800 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
2801 line);
a0b728b7 2802 return 1;
599f40db
JM
2803 }
2804 } else if (os_strcmp(buf, "require_vht") == 0) {
2805 conf->require_vht = atoi(pos);
2806 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2807 conf->vht_oper_chwidth = atoi(pos);
2808 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
2809 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2810 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
2811 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
e7d0e97b
YL
2812 } else if (os_strcmp(buf, "vendor_vht") == 0) {
2813 bss->vendor_vht = atoi(pos);
efe45d14 2814#endif /* CONFIG_IEEE80211AC */
599f40db
JM
2815 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2816 bss->max_listen_interval = atoi(pos);
2817 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2818 bss->disable_pmksa_caching = atoi(pos);
2819 } else if (os_strcmp(buf, "okc") == 0) {
2820 bss->okc = atoi(pos);
41d719d6 2821#ifdef CONFIG_WPS
599f40db
JM
2822 } else if (os_strcmp(buf, "wps_state") == 0) {
2823 bss->wps_state = atoi(pos);
2824 if (bss->wps_state < 0 || bss->wps_state > 2) {
2825 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
2826 line);
a0b728b7 2827 return 1;
599f40db
JM
2828 }
2829 } else if (os_strcmp(buf, "wps_independent") == 0) {
2830 bss->wps_independent = atoi(pos);
2831 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2832 bss->ap_setup_locked = atoi(pos);
2833 } else if (os_strcmp(buf, "uuid") == 0) {
2834 if (uuid_str2bin(pos, bss->uuid)) {
2835 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
a0b728b7 2836 return 1;
599f40db
JM
2837 }
2838 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2839 os_free(bss->wps_pin_requests);
2840 bss->wps_pin_requests = os_strdup(pos);
2841 } else if (os_strcmp(buf, "device_name") == 0) {
cc6f2438 2842 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
599f40db
JM
2843 wpa_printf(MSG_ERROR, "Line %d: Too long "
2844 "device_name", line);
a0b728b7 2845 return 1;
599f40db
JM
2846 }
2847 os_free(bss->device_name);
2848 bss->device_name = os_strdup(pos);
2849 } else if (os_strcmp(buf, "manufacturer") == 0) {
2850 if (os_strlen(pos) > 64) {
2851 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
2852 line);
a0b728b7 2853 return 1;
599f40db
JM
2854 }
2855 os_free(bss->manufacturer);
2856 bss->manufacturer = os_strdup(pos);
2857 } else if (os_strcmp(buf, "model_name") == 0) {
2858 if (os_strlen(pos) > 32) {
2859 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
2860 line);
a0b728b7 2861 return 1;
599f40db
JM
2862 }
2863 os_free(bss->model_name);
2864 bss->model_name = os_strdup(pos);
2865 } else if (os_strcmp(buf, "model_number") == 0) {
2866 if (os_strlen(pos) > 32) {
2867 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
2868 line);
a0b728b7 2869 return 1;
599f40db
JM
2870 }
2871 os_free(bss->model_number);
2872 bss->model_number = os_strdup(pos);
2873 } else if (os_strcmp(buf, "serial_number") == 0) {
2874 if (os_strlen(pos) > 32) {
2875 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
2876 line);
a0b728b7 2877 return 1;
599f40db
JM
2878 }
2879 os_free(bss->serial_number);
2880 bss->serial_number = os_strdup(pos);
2881 } else if (os_strcmp(buf, "device_type") == 0) {
2882 if (wps_dev_type_str2bin(pos, bss->device_type))
a0b728b7 2883 return 1;
599f40db
JM
2884 } else if (os_strcmp(buf, "config_methods") == 0) {
2885 os_free(bss->config_methods);
2886 bss->config_methods = os_strdup(pos);
2887 } else if (os_strcmp(buf, "os_version") == 0) {
2888 if (hexstr2bin(pos, bss->os_version, 4)) {
2889 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
2890 line);
a0b728b7 2891 return 1;
599f40db
JM
2892 }
2893 } else if (os_strcmp(buf, "ap_pin") == 0) {
2894 os_free(bss->ap_pin);
2895 bss->ap_pin = os_strdup(pos);
2896 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2897 bss->skip_cred_build = atoi(pos);
2898 } else if (os_strcmp(buf, "extra_cred") == 0) {
2899 os_free(bss->extra_cred);
2900 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
2901 if (bss->extra_cred == NULL) {
2902 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
2903 line, pos);
a0b728b7 2904 return 1;
599f40db
JM
2905 }
2906 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2907 bss->wps_cred_processing = atoi(pos);
2908 } else if (os_strcmp(buf, "ap_settings") == 0) {
2909 os_free(bss->ap_settings);
2910 bss->ap_settings =
2911 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2912 if (bss->ap_settings == NULL) {
2913 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
2914 line, pos);
a0b728b7 2915 return 1;
599f40db
JM
2916 }
2917 } else if (os_strcmp(buf, "upnp_iface") == 0) {
5784b9a4 2918 os_free(bss->upnp_iface);
599f40db
JM
2919 bss->upnp_iface = os_strdup(pos);
2920 } else if (os_strcmp(buf, "friendly_name") == 0) {
2921 os_free(bss->friendly_name);
2922 bss->friendly_name = os_strdup(pos);
2923 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2924 os_free(bss->manufacturer_url);
2925 bss->manufacturer_url = os_strdup(pos);
2926 } else if (os_strcmp(buf, "model_description") == 0) {
2927 os_free(bss->model_description);
2928 bss->model_description = os_strdup(pos);
2929 } else if (os_strcmp(buf, "model_url") == 0) {
2930 os_free(bss->model_url);
2931 bss->model_url = os_strdup(pos);
2932 } else if (os_strcmp(buf, "upc") == 0) {
2933 os_free(bss->upc);
2934 bss->upc = os_strdup(pos);
2935 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2936 bss->pbc_in_m1 = atoi(pos);
2937 } else if (os_strcmp(buf, "server_id") == 0) {
2938 os_free(bss->server_id);
2939 bss->server_id = os_strdup(pos);
ffdaa05a 2940#ifdef CONFIG_WPS_NFC
599f40db
JM
2941 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2942 bss->wps_nfc_dev_pw_id = atoi(pos);
2943 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2944 bss->wps_nfc_dev_pw_id > 0xffff) {
2945 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
2946 line);
a0b728b7 2947 return 1;
599f40db
JM
2948 }
2949 bss->wps_nfc_pw_from_config = 1;
2950 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2951 wpabuf_free(bss->wps_nfc_dh_pubkey);
2952 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2953 bss->wps_nfc_pw_from_config = 1;
2954 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2955 wpabuf_free(bss->wps_nfc_dh_privkey);
2956 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2957 bss->wps_nfc_pw_from_config = 1;
2958 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2959 wpabuf_free(bss->wps_nfc_dev_pw);
2960 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2961 bss->wps_nfc_pw_from_config = 1;
ffdaa05a 2962#endif /* CONFIG_WPS_NFC */
41d719d6 2963#endif /* CONFIG_WPS */
962473c1 2964#ifdef CONFIG_P2P_MANAGER
599f40db 2965 } else if (os_strcmp(buf, "manage_p2p") == 0) {
b4c26ef9 2966 if (atoi(pos))
599f40db
JM
2967 bss->p2p |= P2P_MANAGE;
2968 else
2969 bss->p2p &= ~P2P_MANAGE;
2970 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2971 if (atoi(pos))
2972 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2973 else
2974 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
962473c1 2975#endif /* CONFIG_P2P_MANAGER */
599f40db
JM
2976 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2977 bss->disassoc_low_ack = atoi(pos);
2978 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
b4c26ef9 2979 if (atoi(pos))
599f40db
JM
2980 bss->tdls |= TDLS_PROHIBIT;
2981 else
2982 bss->tdls &= ~TDLS_PROHIBIT;
2983 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
b4c26ef9 2984 if (atoi(pos))
599f40db
JM
2985 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2986 else
2987 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
cd9fc786 2988#ifdef CONFIG_RSN_TESTING
599f40db
JM
2989 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2990 extern int rsn_testing;
2991 rsn_testing = atoi(pos);
cd9fc786 2992#endif /* CONFIG_RSN_TESTING */
599f40db
JM
2993 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2994 bss->time_advertisement = atoi(pos);
2995 } else if (os_strcmp(buf, "time_zone") == 0) {
2996 size_t tz_len = os_strlen(pos);
2997 if (tz_len < 4 || tz_len > 255) {
2998 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
2999 line);
a0b728b7 3000 return 1;
599f40db
JM
3001 }
3002 os_free(bss->time_zone);
3003 bss->time_zone = os_strdup(pos);
3004 if (bss->time_zone == NULL)
a0b728b7 3005 return 1;
2049a875 3006#ifdef CONFIG_WNM
599f40db
JM
3007 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3008 bss->wnm_sleep_mode = atoi(pos);
3009 } else if (os_strcmp(buf, "bss_transition") == 0) {
3010 bss->bss_transition = atoi(pos);
2049a875 3011#endif /* CONFIG_WNM */
b83e3e93 3012#ifdef CONFIG_INTERWORKING
599f40db
JM
3013 } else if (os_strcmp(buf, "interworking") == 0) {
3014 bss->interworking = atoi(pos);
3015 } else if (os_strcmp(buf, "access_network_type") == 0) {
3016 bss->access_network_type = atoi(pos);
3017 if (bss->access_network_type < 0 ||
3018 bss->access_network_type > 15) {
3019 wpa_printf(MSG_ERROR,
3020 "Line %d: invalid access_network_type",
3021 line);
a0b728b7 3022 return 1;
599f40db
JM
3023 }
3024 } else if (os_strcmp(buf, "internet") == 0) {
3025 bss->internet = atoi(pos);
3026 } else if (os_strcmp(buf, "asra") == 0) {
3027 bss->asra = atoi(pos);
3028 } else if (os_strcmp(buf, "esr") == 0) {
3029 bss->esr = atoi(pos);
3030 } else if (os_strcmp(buf, "uesa") == 0) {
3031 bss->uesa = atoi(pos);
3032 } else if (os_strcmp(buf, "venue_group") == 0) {
3033 bss->venue_group = atoi(pos);
3034 bss->venue_info_set = 1;
3035 } else if (os_strcmp(buf, "venue_type") == 0) {
3036 bss->venue_type = atoi(pos);
3037 bss->venue_info_set = 1;
3038 } else if (os_strcmp(buf, "hessid") == 0) {
3039 if (hwaddr_aton(pos, bss->hessid)) {
3040 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
a0b728b7 3041 return 1;
599f40db
JM
3042 }
3043 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3044 if (parse_roaming_consortium(bss, pos, line) < 0)
a0b728b7 3045 return 1;
599f40db
JM
3046 } else if (os_strcmp(buf, "venue_name") == 0) {
3047 if (parse_venue_name(bss, pos, line) < 0)
a0b728b7 3048 return 1;
599f40db
JM
3049 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3050 u8 auth_type;
3051 u16 redirect_url_len;
3052 if (hexstr2bin(pos, &auth_type, 1)) {
3053 wpa_printf(MSG_ERROR,
3054 "Line %d: Invalid network_auth_type '%s'",
3055 line, pos);
a0b728b7 3056 return 1;
599f40db
JM
3057 }
3058 if (auth_type == 0 || auth_type == 2)
3059 redirect_url_len = os_strlen(pos + 2);
3060 else
3061 redirect_url_len = 0;
3062 os_free(bss->network_auth_type);
3063 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
a0b728b7
JM
3064 if (bss->network_auth_type == NULL)
3065 return 1;
599f40db
JM
3066 *bss->network_auth_type = auth_type;
3067 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3068 if (redirect_url_len)
3069 os_memcpy(bss->network_auth_type + 3, pos + 2,
3070 redirect_url_len);
3071 bss->network_auth_type_len = 3 + redirect_url_len;
3072 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3073 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3074 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3075 line, pos);
3076 bss->ipaddr_type_configured = 0;
a0b728b7 3077 return 1;
599f40db
JM
3078 }
3079 bss->ipaddr_type_configured = 1;
b4c26ef9 3080 } else if (os_strcmp(buf, "domain_name") == 0) {
599f40db
JM
3081 int j, num_domains, domain_len, domain_list_len = 0;
3082 char *tok_start, *tok_prev;
3083 u8 *domain_list, *domain_ptr;
26fac8b6 3084
599f40db
JM
3085 domain_list_len = os_strlen(pos) + 1;
3086 domain_list = os_malloc(domain_list_len);
a0b728b7
JM
3087 if (domain_list == NULL)
3088 return 1;
26fac8b6 3089
599f40db
JM
3090 domain_ptr = domain_list;
3091 tok_prev = pos;
3092 num_domains = 1;
3093 while ((tok_prev = os_strchr(tok_prev, ','))) {
3094 num_domains++;
3095 tok_prev++;
3096 }
3097 tok_prev = pos;
3098 for (j = 0; j < num_domains; j++) {
3099 tok_start = os_strchr(tok_prev, ',');
3100 if (tok_start) {
3101 domain_len = tok_start - tok_prev;
3102 *domain_ptr = domain_len;
3103 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3104 domain_ptr += domain_len + 1;
3105 tok_prev = ++tok_start;
3106 } else {
3107 domain_len = os_strlen(tok_prev);
3108 *domain_ptr = domain_len;
3109 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3110 domain_ptr += domain_len + 1;
26fac8b6 3111 }
599f40db 3112 }
26fac8b6 3113
599f40db
JM
3114 os_free(bss->domain_name);
3115 bss->domain_name = domain_list;
3116 bss->domain_name_len = domain_list_len;
3117 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3118 if (parse_3gpp_cell_net(bss, pos, line) < 0)
a0b728b7 3119 return 1;
599f40db
JM
3120 } else if (os_strcmp(buf, "nai_realm") == 0) {
3121 if (parse_nai_realm(bss, pos, line) < 0)
a0b728b7 3122 return 1;
599f40db
JM
3123 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
3124 bss->gas_frag_limit = atoi(pos);
3125 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3126 bss->gas_comeback_delay = atoi(pos);
3127 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3128 if (parse_qos_map_set(bss, pos, line) < 0)
a0b728b7 3129 return 1;
b83e3e93 3130#endif /* CONFIG_INTERWORKING */
505a3694 3131#ifdef CONFIG_RADIUS_TEST
599f40db
JM
3132 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3133 os_free(bss->dump_msk_file);
3134 bss->dump_msk_file = os_strdup(pos);
505a3694 3135#endif /* CONFIG_RADIUS_TEST */
159c89ab 3136#ifdef CONFIG_HS20
599f40db
JM
3137 } else if (os_strcmp(buf, "hs20") == 0) {
3138 bss->hs20 = atoi(pos);
3139 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3140 bss->disable_dgaf = atoi(pos);
7d597d46
KP
3141 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3142 bss->proxy_arp = atoi(pos);
4a7ce984
JM
3143 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
3144 bss->na_mcast_to_ucast = atoi(pos);
599f40db
JM
3145 } else if (os_strcmp(buf, "osen") == 0) {
3146 bss->osen = atoi(pos);
3147 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3148 bss->anqp_domain_id = atoi(pos);
3149 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3150 bss->hs20_deauth_req_timeout = atoi(pos);
3151 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3152 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
a0b728b7 3153 return 1;
599f40db 3154 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
a0b728b7
JM
3155 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3156 return 1;
599f40db
JM
3157 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3158 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
a0b728b7 3159 return 1;
599f40db
JM
3160 }
3161 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3162 u8 *oper_class;
3163 size_t oper_class_len;
3164 oper_class_len = os_strlen(pos);
3165 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3166 wpa_printf(MSG_ERROR,
3167 "Line %d: Invalid hs20_operating_class '%s'",
3168 line, pos);
a0b728b7 3169 return 1;
599f40db
JM
3170 }
3171 oper_class_len /= 2;
3172 oper_class = os_malloc(oper_class_len);
a0b728b7
JM
3173 if (oper_class == NULL)
3174 return 1;
599f40db
JM
3175 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3176 wpa_printf(MSG_ERROR,
3177 "Line %d: Invalid hs20_operating_class '%s'",
3178 line, pos);
3179 os_free(oper_class);
a0b728b7 3180 return 1;
599f40db
JM
3181 }
3182 os_free(bss->hs20_operating_class);
3183 bss->hs20_operating_class = oper_class;
3184 bss->hs20_operating_class_len = oper_class_len;
3185 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3186 if (hs20_parse_icon(bss, pos) < 0) {
3187 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3188 line, pos);
a0b728b7 3189 return 1;
599f40db
JM
3190 }
3191 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3192 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
a0b728b7 3193 return 1;
599f40db
JM
3194 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3195 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
a0b728b7 3196 return 1;
599f40db
JM
3197 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3198 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
a0b728b7 3199 return 1;
599f40db
JM
3200 } else if (os_strcmp(buf, "osu_nai") == 0) {
3201 if (hs20_parse_osu_nai(bss, pos, line) < 0)
a0b728b7 3202 return 1;
599f40db
JM
3203 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3204 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
a0b728b7 3205 return 1;
599f40db
JM
3206 } else if (os_strcmp(buf, "osu_icon") == 0) {
3207 if (hs20_parse_osu_icon(bss, pos, line) < 0)
a0b728b7 3208 return 1;
599f40db
JM
3209 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3210 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
a0b728b7 3211 return 1;
599f40db
JM
3212 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3213 os_free(bss->subscr_remediation_url);
3214 bss->subscr_remediation_url = os_strdup(pos);
3215 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3216 bss->subscr_remediation_method = atoi(pos);
159c89ab 3217#endif /* CONFIG_HS20 */
c2aff6b1 3218#ifdef CONFIG_TESTING_OPTIONS
599f40db
JM
3219#define PARSE_TEST_PROBABILITY(_val) \
3220 } else if (os_strcmp(buf, #_val) == 0) { \
3221 char *end; \
3222 \
3223 conf->_val = strtod(pos, &end); \
06df2aa6
JM
3224 if (*end || conf->_val < 0.0 || \
3225 conf->_val > 1.0) { \
599f40db
JM
3226 wpa_printf(MSG_ERROR, \
3227 "Line %d: Invalid value '%s'", \
3228 line, pos); \
a0b728b7 3229 return 1; \
599f40db
JM
3230 }
3231 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3232 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3233 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3234 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3235 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
3236 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3237 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3238 pos = os_strchr(pos, ':');
3239 if (pos == NULL) {
3240 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3241 line);
3242 return 1;
3243 }
3244 pos++;
3245 bss->bss_load_test[2] = atoi(pos);
3246 pos = os_strchr(pos, ':');
3247 if (pos == NULL) {
3248 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3249 line);
3250 return 1;
3251 }
3252 pos++;
3253 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3254 bss->bss_load_test_set = 1;
0629eeb4
JM
3255 } else if (os_strcmp(buf, "radio_measurements") == 0) {
3256 bss->radio_measurements = atoi(pos);
c2aff6b1 3257#endif /* CONFIG_TESTING_OPTIONS */
599f40db
JM
3258 } else if (os_strcmp(buf, "vendor_elements") == 0) {
3259 struct wpabuf *elems;
3260 size_t len = os_strlen(pos);
3261 if (len & 0x01) {
3262 wpa_printf(MSG_ERROR,
3263 "Line %d: Invalid vendor_elements '%s'",
3264 line, pos);
3265 return 1;
3266 }
3267 len /= 2;
3268 if (len == 0) {
3269 wpabuf_free(bss->vendor_elements);
3270 bss->vendor_elements = NULL;
3271 return 0;
3272 }
b52f084c 3273
599f40db
JM
3274 elems = wpabuf_alloc(len);
3275 if (elems == NULL)
3276 return 1;
b52f084c 3277
599f40db
JM
3278 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
3279 wpabuf_free(elems);
3280 wpa_printf(MSG_ERROR,
3281 "Line %d: Invalid vendor_elements '%s'",
3282 line, pos);
3283 return 1;
3284 }
b52f084c 3285
599f40db
JM
3286 wpabuf_free(bss->vendor_elements);
3287 bss->vendor_elements = elems;
3288 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3289 bss->sae_anti_clogging_threshold = atoi(pos);
3290 } else if (os_strcmp(buf, "sae_groups") == 0) {
3291 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3292 wpa_printf(MSG_ERROR,
3293 "Line %d: Invalid sae_groups value '%s'",
3294 line, pos);
3295 return 1;
41d719d6 3296 }
599f40db
JM
3297 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3298 int val = atoi(pos);
3299 if (val < 0 || val > 255) {
3300 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3301 line, val);
3302 return 1;
3303 }
3304 conf->local_pwr_constraint = val;
3305 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3306 conf->spectrum_mgmt_required = atoi(pos);
88cb27c7
DS
3307 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3308 os_free(bss->wowlan_triggers);
3309 bss->wowlan_triggers = os_strdup(pos);
599f40db
JM
3310 } else {
3311 wpa_printf(MSG_ERROR,
3312 "Line %d: unknown configuration item '%s'",
3313 line, buf);
a0b728b7 3314 return 1;
41d719d6
JM
3315 }
3316
a0b728b7 3317 return 0;
ef45bc89
SP
3318}
3319
3320
3321/**
3322 * hostapd_config_read - Read and parse a configuration file
3323 * @fname: Configuration file name (including path, if needed)
3324 * Returns: Allocated configuration data structure
3325 */
3326struct hostapd_config * hostapd_config_read(const char *fname)
3327{
3328 struct hostapd_config *conf;
ef45bc89 3329 FILE *f;
ffdaa05a 3330 char buf[512], *pos;
ef45bc89
SP
3331 int line = 0;
3332 int errors = 0;
ef45bc89
SP
3333 size_t i;
3334
3335 f = fopen(fname, "r");
3336 if (f == NULL) {
3337 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3338 "for reading.", fname);
3339 return NULL;
3340 }
3341
3342 conf = hostapd_config_defaults();
3343 if (conf == NULL) {
3344 fclose(f);
3345 return NULL;
3346 }
3347
3348 /* set default driver based on configuration */
3349 conf->driver = wpa_drivers[0];
3350 if (conf->driver == NULL) {
3351 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3352 hostapd_config_free(conf);
3353 fclose(f);
3354 return NULL;
3355 }
3356
df756b37 3357 conf->last_bss = conf->bss[0];
ef45bc89
SP
3358
3359 while (fgets(buf, sizeof(buf), f)) {
df756b37
JM
3360 struct hostapd_bss_config *bss;
3361
ef45bc89
SP
3362 bss = conf->last_bss;
3363 line++;
3364
3365 if (buf[0] == '#')
3366 continue;
3367 pos = buf;
3368 while (*pos != '\0') {
3369 if (*pos == '\n') {
3370 *pos = '\0';
3371 break;
3372 }
3373 pos++;
3374 }
3375 if (buf[0] == '\0')
3376 continue;
3377
3378 pos = os_strchr(buf, '=');
3379 if (pos == NULL) {
3380 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3381 line, buf);
3382 errors++;
3383 continue;
3384 }
3385 *pos = '\0';
3386 pos++;
3387 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3388 }
3389
41d719d6
JM
3390 fclose(f);
3391
a7f5b74d 3392 for (i = 0; i < conf->num_bss; i++)
5d67bf15 3393 hostapd_set_security_params(conf->bss[i], 1);
41d719d6 3394
08081ad8 3395 if (hostapd_config_check(conf, 1))
41d719d6
JM
3396 errors++;
3397
ae6e1bee 3398#ifndef WPA_IGNORE_CONFIG_ERRORS
41d719d6
JM
3399 if (errors) {
3400 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3401 "'%s'", errors, fname);
3402 hostapd_config_free(conf);
3403 conf = NULL;
3404 }
ae6e1bee 3405#endif /* WPA_IGNORE_CONFIG_ERRORS */
41d719d6
JM
3406
3407 return conf;
3408}
31b79e11
SP
3409
3410
3411int hostapd_set_iface(struct hostapd_config *conf,
3412 struct hostapd_bss_config *bss, char *field, char *value)
3413{
4929898d 3414 int errors;
31b79e11
SP
3415 size_t i;
3416
3417 errors = hostapd_config_fill(conf, bss, field, value, 0);
3418 if (errors) {
3419 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3420 "to value '%s'", field, value);
3421 return -1;
3422 }
3423
3424 for (i = 0; i < conf->num_bss; i++)
5d67bf15 3425 hostapd_set_security_params(conf->bss[i], 0);
31b79e11 3426
08081ad8 3427 if (hostapd_config_check(conf, 0)) {
31b79e11 3428 wpa_printf(MSG_ERROR, "Configuration check failed");
17706d1c 3429 return -1;
31b79e11
SP
3430 }
3431
3432 return 0;
3433}