]> git.ipfire.org Git - thirdparty/hostap.git/blame - hostapd/config_file.c
FT: Add support for variable length PMK-R1 receiving in RRB
[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 16#include "common/ieee802_11_defs.h"
245fc96e 17#include "crypto/sha256.h"
6418400d 18#include "crypto/tls.h"
41d719d6
JM
19#include "drivers/driver.h"
20#include "eap_server/eap.h"
21#include "radius/radius_client.h"
6226e38d
JM
22#include "ap/wpa_auth.h"
23#include "ap/ap_config.h"
1057d78e 24#include "config_file.h"
41d719d6
JM
25
26
d0ee16ed
JM
27#ifndef CONFIG_NO_RADIUS
28#ifdef EAP_SERVER
29static struct hostapd_radius_attr *
30hostapd_parse_radius_attr(const char *value);
31#endif /* EAP_SERVER */
32#endif /* CONFIG_NO_RADIUS */
33
34
41d719d6
JM
35#ifndef CONFIG_NO_VLAN
36static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
37 const char *fname)
38{
39 FILE *f;
40 char buf[128], *pos, *pos2;
41 int line = 0, vlan_id;
42 struct hostapd_vlan *vlan;
43
44 f = fopen(fname, "r");
45 if (!f) {
46 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
47 return -1;
48 }
49
50 while (fgets(buf, sizeof(buf), f)) {
51 line++;
52
53 if (buf[0] == '#')
54 continue;
55 pos = buf;
56 while (*pos != '\0') {
57 if (*pos == '\n') {
58 *pos = '\0';
59 break;
60 }
61 pos++;
62 }
63 if (buf[0] == '\0')
64 continue;
65
66 if (buf[0] == '*') {
67 vlan_id = VLAN_ID_WILDCARD;
68 pos = buf + 1;
69 } else {
70 vlan_id = strtol(buf, &pos, 10);
71 if (buf == pos || vlan_id < 1 ||
72 vlan_id > MAX_VLAN_ID) {
73 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
74 "line %d in '%s'", line, fname);
75 fclose(f);
76 return -1;
77 }
78 }
79
80 while (*pos == ' ' || *pos == '\t')
81 pos++;
82 pos2 = pos;
83 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
84 pos2++;
85 *pos2 = '\0';
86 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
87 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
88 "in '%s'", line, fname);
89 fclose(f);
90 return -1;
91 }
92
8b44ad7e 93 vlan = os_zalloc(sizeof(*vlan));
41d719d6
JM
94 if (vlan == NULL) {
95 wpa_printf(MSG_ERROR, "Out of memory while reading "
96 "VLAN interfaces from '%s'", fname);
97 fclose(f);
98 return -1;
99 }
100
41d719d6 101 vlan->vlan_id = vlan_id;
1889af2e
MB
102 vlan->vlan_desc.untagged = vlan_id;
103 vlan->vlan_desc.notempty = !!vlan_id;
41d719d6 104 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
c2db79f2
MB
105 vlan->next = bss->vlan;
106 bss->vlan = vlan;
41d719d6
JM
107 }
108
109 fclose(f);
110
111 return 0;
112}
113#endif /* CONFIG_NO_VLAN */
114
115
3988046d 116int hostapd_acl_comp(const void *a, const void *b)
41d719d6
JM
117{
118 const struct mac_acl_entry *aa = a;
119 const struct mac_acl_entry *bb = b;
120 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
121}
122
123
3988046d
T
124int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
125 int vlan_id, const u8 *addr)
126{
127 struct mac_acl_entry *newacl;
128
129 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
130 if (!newacl) {
131 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
132 return -1;
133 }
134
135 *acl = newacl;
136 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
137 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
138 (*acl)[*num].vlan_id.untagged = vlan_id;
139 (*acl)[*num].vlan_id.notempty = !!vlan_id;
140 (*num)++;
141
142 return 0;
143}
144
145
146void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
147 const u8 *addr)
148{
149 int i = 0;
150
151 while (i < *num) {
152 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
153 os_remove_in_array(*acl, *num, sizeof(**acl), i);
154 (*num)--;
155 } else {
156 i++;
157 }
158 }
159}
160
161
41d719d6
JM
162static int hostapd_config_read_maclist(const char *fname,
163 struct mac_acl_entry **acl, int *num)
164{
165 FILE *f;
166 char buf[128], *pos;
167 int line = 0;
168 u8 addr[ETH_ALEN];
41d719d6
JM
169 int vlan_id;
170
41d719d6
JM
171 f = fopen(fname, "r");
172 if (!f) {
173 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
174 return -1;
175 }
176
177 while (fgets(buf, sizeof(buf), f)) {
3988046d 178 int rem = 0;
1748f1da 179
41d719d6
JM
180 line++;
181
182 if (buf[0] == '#')
183 continue;
184 pos = buf;
185 while (*pos != '\0') {
186 if (*pos == '\n') {
187 *pos = '\0';
188 break;
189 }
190 pos++;
191 }
192 if (buf[0] == '\0')
193 continue;
1748f1da
ET
194 pos = buf;
195 if (buf[0] == '-') {
196 rem = 1;
197 pos++;
198 }
41d719d6 199
1748f1da 200 if (hwaddr_aton(pos, addr)) {
41d719d6 201 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
1748f1da 202 "line %d in '%s'", pos, line, fname);
41d719d6
JM
203 fclose(f);
204 return -1;
205 }
206
1748f1da 207 if (rem) {
3988046d 208 hostapd_remove_acl_mac(acl, num, addr);
1748f1da
ET
209 continue;
210 }
41d719d6
JM
211 vlan_id = 0;
212 pos = buf;
213 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
214 pos++;
215 while (*pos == ' ' || *pos == '\t')
216 pos++;
217 if (*pos != '\0')
218 vlan_id = atoi(pos);
219
0fa669bc
JM
220 if (hostapd_add_acl_maclist(acl, num, vlan_id, addr) < 0) {
221 fclose(f);
41d719d6 222 return -1;
0fa669bc 223 }
41d719d6
JM
224 }
225
226 fclose(f);
227
33111c91
JC
228 if (*acl)
229 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
41d719d6
JM
230
231 return 0;
232}
233
234
235#ifdef EAP_SERVER
d52ead3d
DH
236
237static int hostapd_config_eap_user_salted(struct hostapd_eap_user *user,
238 const char *hash, size_t len,
239 char **pos, int line,
240 const char *fname)
241{
242 char *pos2 = *pos;
243
244 while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#')
245 pos2++;
246
247 if (pos2 - *pos < (int) (2 * (len + 1))) { /* at least 1 byte of salt */
248 wpa_printf(MSG_ERROR,
249 "Invalid salted %s hash on line %d in '%s'",
250 hash, line, fname);
251 return -1;
252 }
253
254 user->password = os_malloc(len);
255 if (!user->password) {
256 wpa_printf(MSG_ERROR,
257 "Failed to allocate memory for salted %s hash",
258 hash);
259 return -1;
260 }
261
262 if (hexstr2bin(*pos, user->password, len) < 0) {
263 wpa_printf(MSG_ERROR,
264 "Invalid salted password on line %d in '%s'",
265 line, fname);
266 return -1;
267 }
268 user->password_len = len;
269 *pos += 2 * len;
270
271 user->salt_len = (pos2 - *pos) / 2;
272 user->salt = os_malloc(user->salt_len);
273 if (!user->salt) {
274 wpa_printf(MSG_ERROR,
275 "Failed to allocate memory for salted %s hash",
276 hash);
277 return -1;
278 }
279
280 if (hexstr2bin(*pos, user->salt, user->salt_len) < 0) {
281 wpa_printf(MSG_ERROR,
282 "Invalid salt for password on line %d in '%s'",
283 line, fname);
284 return -1;
285 }
286
287 *pos = pos2;
288 return 0;
289}
290
291
41d719d6
JM
292static int hostapd_config_read_eap_user(const char *fname,
293 struct hostapd_bss_config *conf)
294{
295 FILE *f;
296 char buf[512], *pos, *start, *pos2;
297 int line = 0, ret = 0, num_methods;
4437f8fc 298 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
41d719d6 299
ee431d77 300 if (os_strncmp(fname, "sqlite:", 7) == 0) {
c469d622 301#ifdef CONFIG_SQLITE
ee431d77
JM
302 os_free(conf->eap_user_sqlite);
303 conf->eap_user_sqlite = os_strdup(fname + 7);
304 return 0;
c469d622
BG
305#else /* CONFIG_SQLITE */
306 wpa_printf(MSG_ERROR,
307 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
308 return -1;
309#endif /* CONFIG_SQLITE */
ee431d77
JM
310 }
311
41d719d6
JM
312 f = fopen(fname, "r");
313 if (!f) {
314 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
315 return -1;
316 }
317
318 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
319 while (fgets(buf, sizeof(buf), f)) {
320 line++;
321
322 if (buf[0] == '#')
323 continue;
324 pos = buf;
325 while (*pos != '\0') {
326 if (*pos == '\n') {
327 *pos = '\0';
328 break;
329 }
330 pos++;
331 }
332 if (buf[0] == '\0')
333 continue;
334
d0ee16ed
JM
335#ifndef CONFIG_NO_RADIUS
336 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
337 struct hostapd_radius_attr *attr, *a;
338 attr = hostapd_parse_radius_attr(buf + 19);
339 if (attr == NULL) {
340 wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
341 buf + 19);
4fb363c6 342 user = NULL; /* already in the BSS list */
d0ee16ed
JM
343 goto failed;
344 }
345 if (user->accept_attr == NULL) {
346 user->accept_attr = attr;
347 } else {
348 a = user->accept_attr;
349 while (a->next)
350 a = a->next;
351 a->next = attr;
352 }
353 continue;
354 }
355#endif /* CONFIG_NO_RADIUS */
356
41d719d6
JM
357 user = NULL;
358
359 if (buf[0] != '"' && buf[0] != '*') {
360 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
361 "start) on line %d in '%s'", line, fname);
362 goto failed;
363 }
364
365 user = os_zalloc(sizeof(*user));
366 if (user == NULL) {
367 wpa_printf(MSG_ERROR, "EAP user allocation failed");
368 goto failed;
369 }
370 user->force_version = -1;
371
372 if (buf[0] == '*') {
373 pos = buf;
374 } else {
375 pos = buf + 1;
376 start = pos;
377 while (*pos != '"' && *pos != '\0')
378 pos++;
379 if (*pos == '\0') {
380 wpa_printf(MSG_ERROR, "Invalid EAP identity "
381 "(no \" in end) on line %d in '%s'",
382 line, fname);
383 goto failed;
384 }
385
a1f11e34 386 user->identity = os_memdup(start, pos - start);
41d719d6
JM
387 if (user->identity == NULL) {
388 wpa_printf(MSG_ERROR, "Failed to allocate "
389 "memory for EAP identity");
390 goto failed;
391 }
41d719d6
JM
392 user->identity_len = pos - start;
393
394 if (pos[0] == '"' && pos[1] == '*') {
395 user->wildcard_prefix = 1;
396 pos++;
397 }
398 }
399 pos++;
400 while (*pos == ' ' || *pos == '\t')
401 pos++;
402
403 if (*pos == '\0') {
404 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
405 "'%s'", line, fname);
406 goto failed;
407 }
408
409 start = pos;
410 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
411 pos++;
412 if (*pos == '\0') {
413 pos = NULL;
414 } else {
415 *pos = '\0';
416 pos++;
417 }
418 num_methods = 0;
419 while (*start) {
420 char *pos3 = os_strchr(start, ',');
421 if (pos3) {
422 *pos3++ = '\0';
423 }
424 user->methods[num_methods].method =
425 eap_server_get_type(
426 start,
427 &user->methods[num_methods].vendor);
428 if (user->methods[num_methods].vendor ==
429 EAP_VENDOR_IETF &&
430 user->methods[num_methods].method == EAP_TYPE_NONE)
431 {
432 if (os_strcmp(start, "TTLS-PAP") == 0) {
433 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
434 goto skip_eap;
435 }
436 if (os_strcmp(start, "TTLS-CHAP") == 0) {
437 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
438 goto skip_eap;
439 }
440 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
441 user->ttls_auth |=
442 EAP_TTLS_AUTH_MSCHAP;
443 goto skip_eap;
444 }
445 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
446 user->ttls_auth |=
447 EAP_TTLS_AUTH_MSCHAPV2;
448 goto skip_eap;
449 }
8943cc99
JM
450 if (os_strcmp(start, "MACACL") == 0) {
451 user->macacl = 1;
452 goto skip_eap;
453 }
41d719d6
JM
454 wpa_printf(MSG_ERROR, "Unsupported EAP type "
455 "'%s' on line %d in '%s'",
456 start, line, fname);
457 goto failed;
458 }
459
460 num_methods++;
e9447a94 461 if (num_methods >= EAP_MAX_METHODS)
41d719d6
JM
462 break;
463 skip_eap:
464 if (pos3 == NULL)
465 break;
466 start = pos3;
467 }
8943cc99 468 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
41d719d6
JM
469 wpa_printf(MSG_ERROR, "No EAP types configured on "
470 "line %d in '%s'", line, fname);
471 goto failed;
472 }
473
474 if (pos == NULL)
475 goto done;
476
477 while (*pos == ' ' || *pos == '\t')
478 pos++;
479 if (*pos == '\0')
480 goto done;
481
482 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
483 user->force_version = 0;
484 goto done;
485 }
486
487 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
488 user->force_version = 1;
489 goto done;
490 }
491
492 if (os_strncmp(pos, "[2]", 3) == 0) {
493 user->phase2 = 1;
494 goto done;
495 }
496
497 if (*pos == '"') {
498 pos++;
499 start = pos;
500 while (*pos != '"' && *pos != '\0')
501 pos++;
502 if (*pos == '\0') {
503 wpa_printf(MSG_ERROR, "Invalid EAP password "
504 "(no \" in end) on line %d in '%s'",
505 line, fname);
506 goto failed;
507 }
508
a1f11e34 509 user->password = os_memdup(start, pos - start);
41d719d6
JM
510 if (user->password == NULL) {
511 wpa_printf(MSG_ERROR, "Failed to allocate "
512 "memory for EAP password");
513 goto failed;
514 }
41d719d6
JM
515 user->password_len = pos - start;
516
517 pos++;
518 } else if (os_strncmp(pos, "hash:", 5) == 0) {
519 pos += 5;
520 pos2 = pos;
521 while (*pos2 != '\0' && *pos2 != ' ' &&
522 *pos2 != '\t' && *pos2 != '#')
523 pos2++;
524 if (pos2 - pos != 32) {
525 wpa_printf(MSG_ERROR, "Invalid password hash "
526 "on line %d in '%s'", line, fname);
527 goto failed;
528 }
529 user->password = os_malloc(16);
530 if (user->password == NULL) {
531 wpa_printf(MSG_ERROR, "Failed to allocate "
532 "memory for EAP password hash");
533 goto failed;
534 }
535 if (hexstr2bin(pos, user->password, 16) < 0) {
536 wpa_printf(MSG_ERROR, "Invalid hash password "
537 "on line %d in '%s'", line, fname);
538 goto failed;
539 }
540 user->password_len = 16;
541 user->password_hash = 1;
542 pos = pos2;
d52ead3d
DH
543 } else if (os_strncmp(pos, "ssha1:", 6) == 0) {
544 pos += 6;
545 if (hostapd_config_eap_user_salted(user, "sha1", 20,
546 &pos,
547 line, fname) < 0)
548 goto failed;
549 } else if (os_strncmp(pos, "ssha256:", 8) == 0) {
550 pos += 8;
551 if (hostapd_config_eap_user_salted(user, "sha256", 32,
552 &pos,
553 line, fname) < 0)
554 goto failed;
555 } else if (os_strncmp(pos, "ssha512:", 8) == 0) {
556 pos += 8;
557 if (hostapd_config_eap_user_salted(user, "sha512", 64,
558 &pos,
559 line, fname) < 0)
560 goto failed;
41d719d6
JM
561 } else {
562 pos2 = pos;
563 while (*pos2 != '\0' && *pos2 != ' ' &&
564 *pos2 != '\t' && *pos2 != '#')
565 pos2++;
566 if ((pos2 - pos) & 1) {
567 wpa_printf(MSG_ERROR, "Invalid hex password "
568 "on line %d in '%s'", line, fname);
569 goto failed;
570 }
571 user->password = os_malloc((pos2 - pos) / 2);
572 if (user->password == NULL) {
573 wpa_printf(MSG_ERROR, "Failed to allocate "
574 "memory for EAP password");
575 goto failed;
576 }
577 if (hexstr2bin(pos, user->password,
578 (pos2 - pos) / 2) < 0) {
579 wpa_printf(MSG_ERROR, "Invalid hex password "
580 "on line %d in '%s'", line, fname);
581 goto failed;
582 }
583 user->password_len = (pos2 - pos) / 2;
584 pos = pos2;
585 }
586
587 while (*pos == ' ' || *pos == '\t')
588 pos++;
589 if (os_strncmp(pos, "[2]", 3) == 0) {
590 user->phase2 = 1;
591 }
592
593 done:
594 if (tail == NULL) {
4437f8fc 595 tail = new_user = user;
41d719d6
JM
596 } else {
597 tail->next = user;
598 tail = user;
599 }
600 continue;
601
602 failed:
d0ee16ed
JM
603 if (user)
604 hostapd_config_free_eap_user(user);
41d719d6
JM
605 ret = -1;
606 break;
607 }
608
609 fclose(f);
610
4437f8fc 611 if (ret == 0) {
78022c83 612 hostapd_config_free_eap_users(conf->eap_user);
4437f8fc 613 conf->eap_user = new_user;
78022c83
JM
614 } else {
615 hostapd_config_free_eap_users(new_user);
4437f8fc
JM
616 }
617
41d719d6
JM
618 return ret;
619}
d52ead3d 620
41d719d6
JM
621#endif /* EAP_SERVER */
622
623
624#ifndef CONFIG_NO_RADIUS
625static int
626hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
627 int *num_server, const char *val, int def_port,
628 struct hostapd_radius_server **curr_serv)
629{
630 struct hostapd_radius_server *nserv;
631 int ret;
632 static int server_index = 1;
633
067ffa26 634 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
41d719d6
JM
635 if (nserv == NULL)
636 return -1;
637
638 *server = nserv;
639 nserv = &nserv[*num_server];
640 (*num_server)++;
641 (*curr_serv) = nserv;
642
643 os_memset(nserv, 0, sizeof(*nserv));
644 nserv->port = def_port;
645 ret = hostapd_parse_ip_addr(val, &nserv->addr);
646 nserv->index = server_index++;
647
648 return ret;
649}
af35e7af
JM
650
651
652static struct hostapd_radius_attr *
653hostapd_parse_radius_attr(const char *value)
654{
655 const char *pos;
656 char syntax;
657 struct hostapd_radius_attr *attr;
658 size_t len;
659
660 attr = os_zalloc(sizeof(*attr));
661 if (attr == NULL)
662 return NULL;
663
664 attr->type = atoi(value);
665
666 pos = os_strchr(value, ':');
667 if (pos == NULL) {
668 attr->val = wpabuf_alloc(1);
669 if (attr->val == NULL) {
670 os_free(attr);
671 return NULL;
672 }
673 wpabuf_put_u8(attr->val, 0);
674 return attr;
675 }
676
677 pos++;
678 if (pos[0] == '\0' || pos[1] != ':') {
679 os_free(attr);
680 return NULL;
681 }
682 syntax = *pos++;
683 pos++;
684
685 switch (syntax) {
686 case 's':
687 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
688 break;
689 case 'x':
690 len = os_strlen(pos);
691 if (len & 1)
692 break;
693 len /= 2;
694 attr->val = wpabuf_alloc(len);
695 if (attr->val == NULL)
696 break;
697 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
698 wpabuf_free(attr->val);
699 os_free(attr);
700 return NULL;
701 }
702 break;
703 case 'd':
704 attr->val = wpabuf_alloc(4);
705 if (attr->val)
706 wpabuf_put_be32(attr->val, atoi(pos));
707 break;
708 default:
709 os_free(attr);
710 return NULL;
711 }
712
713 if (attr->val == NULL) {
714 os_free(attr);
715 return NULL;
716 }
717
718 return attr;
719}
b031338c
JM
720
721
79931efa 722static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val)
b031338c
JM
723{
724 char *secret;
b031338c
JM
725
726 secret = os_strchr(val, ' ');
727 if (secret == NULL)
728 return -1;
729
79931efa 730 *secret++ = '\0';
b031338c
JM
731
732 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
733 return -1;
734
735 os_free(bss->radius_das_shared_secret);
6e459875 736 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
b031338c
JM
737 if (bss->radius_das_shared_secret == NULL)
738 return -1;
6e459875 739 bss->radius_das_shared_secret_len = os_strlen(secret);
b031338c
JM
740
741 return 0;
742}
41d719d6
JM
743#endif /* CONFIG_NO_RADIUS */
744
745
746static int hostapd_config_parse_key_mgmt(int line, const char *value)
747{
748 int val = 0, last;
749 char *start, *end, *buf;
750
751 buf = os_strdup(value);
752 if (buf == NULL)
753 return -1;
754 start = buf;
755
756 while (*start != '\0') {
757 while (*start == ' ' || *start == '\t')
758 start++;
759 if (*start == '\0')
760 break;
761 end = start;
762 while (*end != ' ' && *end != '\t' && *end != '\0')
763 end++;
764 last = *end == '\0';
765 *end = '\0';
766 if (os_strcmp(start, "WPA-PSK") == 0)
767 val |= WPA_KEY_MGMT_PSK;
768 else if (os_strcmp(start, "WPA-EAP") == 0)
769 val |= WPA_KEY_MGMT_IEEE8021X;
d503eeea 770#ifdef CONFIG_IEEE80211R_AP
41d719d6
JM
771 else if (os_strcmp(start, "FT-PSK") == 0)
772 val |= WPA_KEY_MGMT_FT_PSK;
773 else if (os_strcmp(start, "FT-EAP") == 0)
774 val |= WPA_KEY_MGMT_FT_IEEE8021X;
d503eeea 775#endif /* CONFIG_IEEE80211R_AP */
41d719d6
JM
776#ifdef CONFIG_IEEE80211W
777 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
778 val |= WPA_KEY_MGMT_PSK_SHA256;
779 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
780 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
781#endif /* CONFIG_IEEE80211W */
c10347f2
JM
782#ifdef CONFIG_SAE
783 else if (os_strcmp(start, "SAE") == 0)
784 val |= WPA_KEY_MGMT_SAE;
785 else if (os_strcmp(start, "FT-SAE") == 0)
786 val |= WPA_KEY_MGMT_FT_SAE;
787#endif /* CONFIG_SAE */
5e3b5197 788#ifdef CONFIG_SUITEB
666497c8
JM
789 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
790 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
5e3b5197
JM
791#endif /* CONFIG_SUITEB */
792#ifdef CONFIG_SUITEB192
793 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
794 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
795#endif /* CONFIG_SUITEB192 */
903ecbe8
JM
796#ifdef CONFIG_FILS
797 else if (os_strcmp(start, "FILS-SHA256") == 0)
798 val |= WPA_KEY_MGMT_FILS_SHA256;
799 else if (os_strcmp(start, "FILS-SHA384") == 0)
800 val |= WPA_KEY_MGMT_FILS_SHA384;
d503eeea 801#ifdef CONFIG_IEEE80211R_AP
903ecbe8
JM
802 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
803 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
804 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
805 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
d503eeea 806#endif /* CONFIG_IEEE80211R_AP */
903ecbe8 807#endif /* CONFIG_FILS */
a1ea1b45
JM
808#ifdef CONFIG_OWE
809 else if (os_strcmp(start, "OWE") == 0)
810 val |= WPA_KEY_MGMT_OWE;
811#endif /* CONFIG_OWE */
567da5bb
JM
812#ifdef CONFIG_DPP
813 else if (os_strcmp(start, "DPP") == 0)
814 val |= WPA_KEY_MGMT_DPP;
815#endif /* CONFIG_DPP */
8d660a4b
JM
816#ifdef CONFIG_HS20
817 else if (os_strcmp(start, "OSEN") == 0)
818 val |= WPA_KEY_MGMT_OSEN;
819#endif /* CONFIG_HS20 */
41d719d6
JM
820 else {
821 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
822 line, start);
823 os_free(buf);
824 return -1;
825 }
826
827 if (last)
828 break;
829 start = end + 1;
830 }
831
832 os_free(buf);
833 if (val == 0) {
834 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
835 "configured.", line);
836 return -1;
837 }
838
839 return val;
840}
841
842
843static int hostapd_config_parse_cipher(int line, const char *value)
844{
a39c78be
JM
845 int val = wpa_parse_cipher(value);
846 if (val < 0) {
847 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
848 line, value);
41d719d6 849 return -1;
41d719d6 850 }
41d719d6
JM
851 if (val == 0) {
852 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
853 line);
854 return -1;
855 }
856 return val;
857}
858
859
860static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
861 char *val)
862{
863 size_t len = os_strlen(val);
864
20b1a9e2
JM
865 if (keyidx < 0 || keyidx > 3)
866 return -1;
867
868 if (len == 0) {
869 int i, set = 0;
870
871 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
872 wep->key[keyidx] = NULL;
873 wep->len[keyidx] = 0;
874 for (i = 0; i < NUM_WEP_KEYS; i++) {
875 if (wep->key[i])
876 set++;
877 }
878 if (!set)
879 wep->keys_set = 0;
880 return 0;
881 }
882
883 if (wep->key[keyidx] != NULL)
41d719d6
JM
884 return -1;
885
886 if (val[0] == '"') {
887 if (len < 2 || val[len - 1] != '"')
888 return -1;
889 len -= 2;
a1f11e34 890 wep->key[keyidx] = os_memdup(val + 1, len);
41d719d6
JM
891 if (wep->key[keyidx] == NULL)
892 return -1;
41d719d6
JM
893 wep->len[keyidx] = len;
894 } else {
895 if (len & 1)
896 return -1;
897 len /= 2;
898 wep->key[keyidx] = os_malloc(len);
899 if (wep->key[keyidx] == NULL)
900 return -1;
901 wep->len[keyidx] = len;
902 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
903 return -1;
904 }
905
906 wep->keys_set++;
907
908 return 0;
909}
910
911
857d9422
MM
912static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
913{
914 char *pos;
915
916 /* for backwards compatibility, translate ' ' in conf str to ',' */
917 pos = val;
918 while (pos) {
919 pos = os_strchr(pos, ' ');
920 if (pos)
921 *pos++ = ',';
922 }
923 if (freq_range_list_parse(&conf->acs_ch_list, val))
924 return -1;
925
926 return 0;
927}
928
929
732118ec 930static int hostapd_parse_intlist(int **int_list, char *val)
41d719d6
JM
931{
932 int *list;
933 int count;
934 char *pos, *end;
935
732118ec
SW
936 os_free(*int_list);
937 *int_list = NULL;
41d719d6
JM
938
939 pos = val;
940 count = 0;
941 while (*pos != '\0') {
942 if (*pos == ' ')
943 count++;
944 pos++;
945 }
946
947 list = os_malloc(sizeof(int) * (count + 2));
948 if (list == NULL)
949 return -1;
950 pos = val;
951 count = 0;
952 while (*pos != '\0') {
953 end = os_strchr(pos, ' ');
954 if (end)
955 *end = '\0';
956
957 list[count++] = atoi(pos);
958 if (!end)
959 break;
960 pos = end + 1;
961 }
962 list[count] = -1;
963
732118ec 964 *int_list = list;
41d719d6
JM
965 return 0;
966}
967
968
969static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
970{
ebd79f07 971 struct hostapd_bss_config **all, *bss;
41d719d6
JM
972
973 if (*ifname == '\0')
974 return -1;
975
ebd79f07
JM
976 all = os_realloc_array(conf->bss, conf->num_bss + 1,
977 sizeof(struct hostapd_bss_config *));
978 if (all == NULL) {
41d719d6
JM
979 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
980 "multi-BSS entry");
981 return -1;
982 }
ebd79f07 983 conf->bss = all;
41d719d6 984
2fe210ce
JM
985 bss = os_zalloc(sizeof(*bss));
986 if (bss == NULL)
987 return -1;
41d719d6
JM
988 bss->radius = os_zalloc(sizeof(*bss->radius));
989 if (bss->radius == NULL) {
990 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
991 "multi-BSS RADIUS data");
2fe210ce 992 os_free(bss);
41d719d6
JM
993 return -1;
994 }
995
2fe210ce 996 conf->bss[conf->num_bss++] = bss;
41d719d6
JM
997 conf->last_bss = bss;
998
999 hostapd_config_defaults_bss(bss);
1000 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1001 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1002
1003 return 0;
1004}
1005
1006
1007/* convert floats with one decimal place to value*10 int, i.e.,
1008 * "1.5" will return 15 */
1009static int hostapd_config_read_int10(const char *value)
1010{
1011 int i, d;
1012 char *pos;
1013
1014 i = atoi(value);
1015 pos = os_strchr(value, '.');
1016 d = 0;
1017 if (pos) {
1018 pos++;
1019 if (*pos >= '0' && *pos <= '9')
1020 d = *pos - '0';
1021 }
1022
1023 return i * 10 + d;
1024}
1025
1026
1027static int valid_cw(int cw)
1028{
1029 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
6c731491
JM
1030 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023 ||
1031 cw == 2047 || cw == 4095 || cw == 8191 || cw == 16383 ||
1032 cw == 32767);
41d719d6
JM
1033}
1034
1035
1036enum {
1037 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1038 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1039 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
7e3c1781 1040 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
41d719d6
JM
1041};
1042
63e169e1
JM
1043static int hostapd_config_tx_queue(struct hostapd_config *conf,
1044 const char *name, const char *val)
41d719d6
JM
1045{
1046 int num;
63e169e1 1047 const char *pos;
41d719d6
JM
1048 struct hostapd_tx_queue_params *queue;
1049
1050 /* skip 'tx_queue_' prefix */
1051 pos = name + 9;
1052 if (os_strncmp(pos, "data", 4) == 0 &&
1053 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1054 num = pos[4] - '0';
1055 pos += 6;
7e3c1781
JM
1056 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
1057 os_strncmp(pos, "beacon_", 7) == 0) {
1058 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
1059 return 0;
41d719d6
JM
1060 } else {
1061 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1062 return -1;
1063 }
1064
7e3c1781 1065 if (num >= NUM_TX_QUEUES) {
d2da2249 1066 /* for backwards compatibility, do not trigger failure */
7e3c1781
JM
1067 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
1068 return 0;
1069 }
1070
41d719d6
JM
1071 queue = &conf->tx_queue[num];
1072
1073 if (os_strcmp(pos, "aifs") == 0) {
1074 queue->aifs = atoi(val);
1075 if (queue->aifs < 0 || queue->aifs > 255) {
1076 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1077 queue->aifs);
1078 return -1;
1079 }
1080 } else if (os_strcmp(pos, "cwmin") == 0) {
1081 queue->cwmin = atoi(val);
1082 if (!valid_cw(queue->cwmin)) {
1083 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1084 queue->cwmin);
1085 return -1;
1086 }
1087 } else if (os_strcmp(pos, "cwmax") == 0) {
1088 queue->cwmax = atoi(val);
1089 if (!valid_cw(queue->cwmax)) {
1090 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1091 queue->cwmax);
1092 return -1;
1093 }
1094 } else if (os_strcmp(pos, "burst") == 0) {
1095 queue->burst = hostapd_config_read_int10(val);
1096 } else {
1097 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1098 return -1;
1099 }
1100
41d719d6
JM
1101 return 0;
1102}
1103
1104
d503eeea 1105#ifdef CONFIG_IEEE80211R_AP
245fc96e
MB
1106
1107static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
1108{
1109 u8 oldkey[16];
1110 int ret;
1111
1112 if (!hexstr2bin(pos, key, key_len))
1113 return 0;
1114
1115 /* Try to use old short key for backwards compatibility */
1116 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
1117 return -1;
1118
1119 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
1120 key, key_len);
1121 os_memset(oldkey, 0, sizeof(oldkey));
1122 return ret;
1123}
1124
1125
41d719d6
JM
1126static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1127{
1128 struct ft_remote_r0kh *r0kh;
1129 char *pos, *next;
1130
1131 r0kh = os_zalloc(sizeof(*r0kh));
1132 if (r0kh == NULL)
1133 return -1;
1134
1135 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1136 pos = value;
1137 next = os_strchr(pos, ' ');
1138 if (next)
1139 *next++ = '\0';
1140 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1141 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1142 os_free(r0kh);
1143 return -1;
1144 }
1145
1146 pos = next;
1147 next = os_strchr(pos, ' ');
1148 if (next)
1149 *next++ = '\0';
1150 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1151 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1152 os_free(r0kh);
1153 return -1;
1154 }
1155 r0kh->id_len = next - pos - 1;
1156 os_memcpy(r0kh->id, pos, r0kh->id_len);
1157
1158 pos = next;
245fc96e 1159 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
41d719d6
JM
1160 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1161 os_free(r0kh);
1162 return -1;
1163 }
1164
1165 r0kh->next = bss->r0kh_list;
1166 bss->r0kh_list = r0kh;
1167
1168 return 0;
1169}
1170
1171
1172static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1173{
1174 struct ft_remote_r1kh *r1kh;
1175 char *pos, *next;
1176
1177 r1kh = os_zalloc(sizeof(*r1kh));
1178 if (r1kh == NULL)
1179 return -1;
1180
1181 /* 02:01:02:03:04:05 02:01:02:03:04:05
1182 * 000102030405060708090a0b0c0d0e0f */
1183 pos = value;
1184 next = os_strchr(pos, ' ');
1185 if (next)
1186 *next++ = '\0';
1187 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1188 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1189 os_free(r1kh);
1190 return -1;
1191 }
1192
1193 pos = next;
1194 next = os_strchr(pos, ' ');
1195 if (next)
1196 *next++ = '\0';
1197 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1198 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1199 os_free(r1kh);
1200 return -1;
1201 }
1202
1203 pos = next;
245fc96e 1204 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
41d719d6
JM
1205 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1206 os_free(r1kh);
1207 return -1;
1208 }
1209
1210 r1kh->next = bss->r1kh_list;
1211 bss->r1kh_list = r1kh;
1212
1213 return 0;
1214}
d503eeea 1215#endif /* CONFIG_IEEE80211R_AP */
41d719d6
JM
1216
1217
1218#ifdef CONFIG_IEEE80211N
1219static int hostapd_config_ht_capab(struct hostapd_config *conf,
1220 const char *capab)
1221{
1222 if (os_strstr(capab, "[LDPC]"))
1223 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1224 if (os_strstr(capab, "[HT40-]")) {
1225 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1226 conf->secondary_channel = -1;
1227 }
1228 if (os_strstr(capab, "[HT40+]")) {
1229 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1230 conf->secondary_channel = 1;
1231 }
ec27b04e
PX
1232 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1233 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1234 conf->ht40_plus_minus_allowed = 1;
1235 }
41d719d6
JM
1236 if (os_strstr(capab, "[SMPS-STATIC]")) {
1237 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1238 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1239 }
1240 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1241 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1242 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1243 }
1244 if (os_strstr(capab, "[GF]"))
1245 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1246 if (os_strstr(capab, "[SHORT-GI-20]"))
1247 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1248 if (os_strstr(capab, "[SHORT-GI-40]"))
1249 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1250 if (os_strstr(capab, "[TX-STBC]"))
1251 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1252 if (os_strstr(capab, "[RX-STBC1]")) {
1253 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1254 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1255 }
1256 if (os_strstr(capab, "[RX-STBC12]")) {
1257 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1258 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1259 }
1260 if (os_strstr(capab, "[RX-STBC123]")) {
1261 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1262 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1263 }
1264 if (os_strstr(capab, "[DELAYED-BA]"))
1265 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1266 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1267 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1268 if (os_strstr(capab, "[DSSS_CCK-40]"))
1269 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
b7a8d67f
JM
1270 if (os_strstr(capab, "[40-INTOLERANT]"))
1271 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
41d719d6
JM
1272 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1273 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1274
1275 return 0;
1276}
1277#endif /* CONFIG_IEEE80211N */
1278
1279
efe45d14
MP
1280#ifdef CONFIG_IEEE80211AC
1281static int hostapd_config_vht_capab(struct hostapd_config *conf,
1282 const char *capab)
1283{
1284 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1285 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1286 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1287 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1288 if (os_strstr(capab, "[VHT160]"))
1289 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1290 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1291 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
efe45d14
MP
1292 if (os_strstr(capab, "[RXLDPC]"))
1293 conf->vht_capab |= VHT_CAP_RXLDPC;
1294 if (os_strstr(capab, "[SHORT-GI-80]"))
1295 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1296 if (os_strstr(capab, "[SHORT-GI-160]"))
1297 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1298 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1299 conf->vht_capab |= VHT_CAP_TXSTBC;
1300 if (os_strstr(capab, "[RX-STBC-1]"))
1301 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1302 if (os_strstr(capab, "[RX-STBC-12]"))
1303 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1304 if (os_strstr(capab, "[RX-STBC-123]"))
1305 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1306 if (os_strstr(capab, "[RX-STBC-1234]"))
1307 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1308 if (os_strstr(capab, "[SU-BEAMFORMER]"))
7066a8e7 1309 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
efe45d14 1310 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
7066a8e7 1311 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
efe45d14 1312 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
b29b012c
EP
1313 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1314 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
442ffc51
VN
1315 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1316 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1317 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1318 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1319 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1320 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
efe45d14 1321 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
b29b012c
EP
1322 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1323 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
442ffc51
VN
1324 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1325 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1326 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1327 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1328 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1329 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
efe45d14
MP
1330 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1331 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
efe45d14
MP
1332 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1333 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1334 if (os_strstr(capab, "[HTC-VHT]"))
1335 conf->vht_capab |= VHT_CAP_HTC_VHT;
905828fe
BM
1336 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1337 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1338 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1339 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1340 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1341 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1342 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1343 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1344 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1345 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1346 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1347 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1348 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1349 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
efe45d14
MP
1350 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1351 (conf->vht_capab & VHT_CAP_HTC_VHT))
1352 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1353 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1354 (conf->vht_capab & VHT_CAP_HTC_VHT))
1355 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1356 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1357 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1358 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1359 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1360 return 0;
1361}
1362#endif /* CONFIG_IEEE80211AC */
1363
1364
4b2a77ab
JM
1365#ifdef CONFIG_INTERWORKING
1366static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1367 int line)
1368{
1369 size_t len = os_strlen(pos);
1370 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1371
1372 struct hostapd_roaming_consortium *rc;
1373
1374 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1375 hexstr2bin(pos, oi, len / 2)) {
1376 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1377 "'%s'", line, pos);
1378 return -1;
1379 }
1380 len /= 2;
1381
067ffa26
JM
1382 rc = os_realloc_array(bss->roaming_consortium,
1383 bss->roaming_consortium_count + 1,
1384 sizeof(struct hostapd_roaming_consortium));
4b2a77ab
JM
1385 if (rc == NULL)
1386 return -1;
1387
1388 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1389 rc[bss->roaming_consortium_count].len = len;
1390
1391 bss->roaming_consortium = rc;
1392 bss->roaming_consortium_count++;
1393
1394 return 0;
1395}
648cc711
JM
1396
1397
1792e58d
JM
1398static int parse_lang_string(struct hostapd_lang_string **array,
1399 unsigned int *count, char *pos)
648cc711 1400{
f224cf05
KP
1401 char *sep, *str = NULL;
1402 size_t clen, nlen, slen;
1792e58d 1403 struct hostapd_lang_string *ls;
f224cf05
KP
1404 int ret = -1;
1405
1406 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1407 str = wpa_config_parse_string(pos, &slen);
1408 if (!str)
1409 return -1;
1410 pos = str;
1411 }
648cc711
JM
1412
1413 sep = os_strchr(pos, ':');
1414 if (sep == NULL)
f224cf05 1415 goto fail;
648cc711
JM
1416 *sep++ = '\0';
1417
1418 clen = os_strlen(pos);
04e533e2 1419 if (clen < 2 || clen > sizeof(ls->lang))
f224cf05 1420 goto fail;
648cc711
JM
1421 nlen = os_strlen(sep);
1422 if (nlen > 252)
f224cf05 1423 goto fail;
648cc711 1424
1792e58d
JM
1425 ls = os_realloc_array(*array, *count + 1,
1426 sizeof(struct hostapd_lang_string));
1427 if (ls == NULL)
f224cf05 1428 goto fail;
648cc711 1429
1792e58d
JM
1430 *array = ls;
1431 ls = &(*array)[*count];
1432 (*count)++;
648cc711 1433
1792e58d
JM
1434 os_memset(ls->lang, 0, sizeof(ls->lang));
1435 os_memcpy(ls->lang, pos, clen);
1436 ls->name_len = nlen;
1437 os_memcpy(ls->name, sep, nlen);
648cc711 1438
f224cf05
KP
1439 ret = 0;
1440fail:
1441 os_free(str);
1442 return ret;
1792e58d
JM
1443}
1444
648cc711 1445
1792e58d
JM
1446static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1447 int line)
1448{
1449 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1450 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1451 line, pos);
1452 return -1;
1453 }
1454 return 0;
648cc711 1455}
7515adb2
JK
1456
1457
7e1d3ee9
JM
1458static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1459 int line)
1460{
1461 char *sep;
1462 size_t nlen;
1463 struct hostapd_venue_url *url;
1464 int ret = -1;
1465
1466 sep = os_strchr(pos, ':');
1467 if (!sep)
1468 goto fail;
1469 *sep++ = '\0';
1470
1471 nlen = os_strlen(sep);
1472 if (nlen > 254)
1473 goto fail;
1474
1475 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1476 sizeof(struct hostapd_venue_url));
1477 if (!url)
1478 goto fail;
1479
1480 bss->venue_url = url;
1481 url = &bss->venue_url[bss->venue_url_count++];
1482
1483 url->venue_number = atoi(pos);
1484 url->url_len = nlen;
1485 os_memcpy(url->url, sep, nlen);
1486
1487 ret = 0;
1488fail:
1489 if (ret)
1490 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1491 line, pos);
1492 return ret;
1493}
1494
1495
7515adb2
JK
1496static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1497 int line)
1498{
1499 size_t count;
1500 char *pos;
1501 u8 *info = NULL, *ipos;
1502
1503 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1504
1505 count = 1;
1506 for (pos = buf; *pos; pos++) {
4be20bf9 1507 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
7515adb2
JK
1508 goto fail;
1509 if (*pos == ';')
1510 count++;
1511 }
1512 if (1 + count * 3 > 0x7f)
1513 goto fail;
1514
1515 info = os_zalloc(2 + 3 + count * 3);
1516 if (info == NULL)
1517 return -1;
1518
1519 ipos = info;
1520 *ipos++ = 0; /* GUD - Version 1 */
1521 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1522 *ipos++ = 0; /* PLMN List IEI */
1523 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1524 *ipos++ = 1 + count * 3;
1525 *ipos++ = count; /* Number of PLMNs */
1526
1527 pos = buf;
1528 while (pos && *pos) {
1529 char *mcc, *mnc;
1530 size_t mnc_len;
1531
1532 mcc = pos;
1533 mnc = os_strchr(pos, ',');
1534 if (mnc == NULL)
1535 goto fail;
1536 *mnc++ = '\0';
1537 pos = os_strchr(mnc, ';');
1538 if (pos)
1539 *pos++ = '\0';
1540
1541 mnc_len = os_strlen(mnc);
1542 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1543 goto fail;
1544
1545 /* BC coded MCC,MNC */
1546 /* MCC digit 2 | MCC digit 1 */
1547 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1548 /* MNC digit 3 | MCC digit 3 */
1549 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1550 (mcc[2] - '0');
1551 /* MNC digit 2 | MNC digit 1 */
1552 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1553 }
1554
1555 os_free(bss->anqp_3gpp_cell_net);
1556 bss->anqp_3gpp_cell_net = info;
1557 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1558 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1559 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
1560
1561 return 0;
1562
1563fail:
1564 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1565 line, buf);
1566 os_free(info);
1567 return -1;
1568}
1569
8047b186
JK
1570
1571static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1572{
1573 struct hostapd_nai_realm_data *realm;
1574 size_t i, j, len;
1575 int *offsets;
1576 char *pos, *end, *rpos;
1577
1578 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1579 sizeof(int));
1580 if (offsets == NULL)
1581 return -1;
1582
1583 for (i = 0; i < bss->nai_realm_count; i++) {
1584 realm = &bss->nai_realm_data[i];
1585 for (j = 0; j < MAX_NAI_REALMS; j++) {
1586 offsets[i * MAX_NAI_REALMS + j] =
1587 realm->realm[j] ?
1588 realm->realm[j] - realm->realm_buf : -1;
1589 }
1590 }
1591
1592 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1593 sizeof(struct hostapd_nai_realm_data));
1594 if (realm == NULL) {
1595 os_free(offsets);
1596 return -1;
1597 }
1598 bss->nai_realm_data = realm;
1599
1600 /* patch the pointers after realloc */
1601 for (i = 0; i < bss->nai_realm_count; i++) {
1602 realm = &bss->nai_realm_data[i];
1603 for (j = 0; j < MAX_NAI_REALMS; j++) {
1604 int offs = offsets[i * MAX_NAI_REALMS + j];
1605 if (offs >= 0)
1606 realm->realm[j] = realm->realm_buf + offs;
1607 else
1608 realm->realm[j] = NULL;
1609 }
1610 }
1611 os_free(offsets);
1612
1613 realm = &bss->nai_realm_data[bss->nai_realm_count];
1614 os_memset(realm, 0, sizeof(*realm));
1615
1616 pos = buf;
1617 realm->encoding = atoi(pos);
1618 pos = os_strchr(pos, ',');
1619 if (pos == NULL)
1620 goto fail;
1621 pos++;
1622
1623 end = os_strchr(pos, ',');
1624 if (end) {
1625 len = end - pos;
1626 *end = '\0';
1627 } else {
1628 len = os_strlen(pos);
1629 }
1630
1631 if (len > MAX_NAI_REALMLEN) {
1632 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1633 "characters)", (int) len, MAX_NAI_REALMLEN);
1634 goto fail;
1635 }
1636 os_memcpy(realm->realm_buf, pos, len);
1637
1638 if (end)
1639 pos = end + 1;
1640 else
1641 pos = NULL;
1642
1643 while (pos && *pos) {
1644 struct hostapd_nai_realm_eap *eap;
1645
1646 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1647 wpa_printf(MSG_ERROR, "Too many EAP methods");
1648 goto fail;
1649 }
1650
1651 eap = &realm->eap_method[realm->eap_method_count];
1652 realm->eap_method_count++;
1653
1654 end = os_strchr(pos, ',');
1655 if (end == NULL)
1656 end = pos + os_strlen(pos);
1657
1658 eap->eap_method = atoi(pos);
1659 for (;;) {
1660 pos = os_strchr(pos, '[');
1661 if (pos == NULL || pos > end)
1662 break;
1663 pos++;
1664 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1665 wpa_printf(MSG_ERROR, "Too many auth params");
1666 goto fail;
1667 }
1668 eap->auth_id[eap->num_auths] = atoi(pos);
1669 pos = os_strchr(pos, ':');
1670 if (pos == NULL || pos > end)
1671 goto fail;
1672 pos++;
1673 eap->auth_val[eap->num_auths] = atoi(pos);
1674 pos = os_strchr(pos, ']');
1675 if (pos == NULL || pos > end)
1676 goto fail;
1677 pos++;
1678 eap->num_auths++;
1679 }
1680
1681 if (*end != ',')
1682 break;
1683
1684 pos = end + 1;
1685 }
1686
1687 /* Split realm list into null terminated realms */
1688 rpos = realm->realm_buf;
1689 i = 0;
1690 while (*rpos) {
1691 if (i >= MAX_NAI_REALMS) {
1692 wpa_printf(MSG_ERROR, "Too many realms");
1693 goto fail;
1694 }
1695 realm->realm[i++] = rpos;
1696 rpos = os_strchr(rpos, ';');
1697 if (rpos == NULL)
1698 break;
1699 *rpos++ = '\0';
1700 }
1701
1702 bss->nai_realm_count++;
1703
1704 return 0;
1705
1706fail:
1707 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1708 return -1;
1709}
1710
c551700f 1711
695dbbea
JM
1712static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1713{
1714 char *delim;
1715 u16 infoid;
1716 size_t len;
1717 struct wpabuf *payload;
1718 struct anqp_element *elem;
1719
1720 delim = os_strchr(buf, ':');
1721 if (!delim)
1722 return -1;
1723 delim++;
1724 infoid = atoi(buf);
1725 len = os_strlen(delim);
1726 if (len & 1)
1727 return -1;
1728 len /= 2;
1729 payload = wpabuf_alloc(len);
1730 if (!payload)
1731 return -1;
1732 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1733 wpabuf_free(payload);
1734 return -1;
1735 }
1736
1737 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1738 if (elem->infoid == infoid) {
1739 /* Update existing entry */
1740 wpabuf_free(elem->payload);
1741 elem->payload = payload;
1742 return 0;
1743 }
1744 }
1745
1746 /* Add a new entry */
1747 elem = os_zalloc(sizeof(*elem));
1748 if (!elem) {
1749 wpabuf_free(payload);
1750 return -1;
1751 }
1752 elem->infoid = infoid;
1753 elem->payload = payload;
1754 dl_list_add(&bss->anqp_elem, &elem->list);
1755
1756 return 0;
1757}
1758
1759
c551700f
KP
1760static int parse_qos_map_set(struct hostapd_bss_config *bss,
1761 char *buf, int line)
1762{
1763 u8 qos_map_set[16 + 2 * 21], count = 0;
1764 char *pos = buf;
1765 int val;
1766
1767 for (;;) {
1768 if (count == sizeof(qos_map_set)) {
1769 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1770 "parameters '%s'", line, buf);
1771 return -1;
1772 }
1773
1774 val = atoi(pos);
1775 if (val > 255 || val < 0) {
1776 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1777 "'%s'", line, buf);
1778 return -1;
1779 }
1780
1781 qos_map_set[count++] = val;
1782 pos = os_strchr(pos, ',');
1783 if (!pos)
1784 break;
1785 pos++;
1786 }
1787
1788 if (count < 16 || count & 1) {
1789 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1790 line, buf);
1791 return -1;
1792 }
1793
1794 os_memcpy(bss->qos_map_set, qos_map_set, count);
1795 bss->qos_map_set_len = count;
1796
1797 return 0;
1798}
1799
4b2a77ab
JM
1800#endif /* CONFIG_INTERWORKING */
1801
1802
5ccc54aa
JK
1803#ifdef CONFIG_HS20
1804static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1805 int line)
1806{
1807 u8 *conn_cap;
1808 char *pos;
1809
1810 if (bss->hs20_connection_capability_len >= 0xfff0)
1811 return -1;
1812
1813 conn_cap = os_realloc(bss->hs20_connection_capability,
1814 bss->hs20_connection_capability_len + 4);
1815 if (conn_cap == NULL)
1816 return -1;
1817
1818 bss->hs20_connection_capability = conn_cap;
1819 conn_cap += bss->hs20_connection_capability_len;
1820 pos = buf;
1821 conn_cap[0] = atoi(pos);
1822 pos = os_strchr(pos, ':');
1823 if (pos == NULL)
1824 return -1;
1825 pos++;
1826 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1827 pos = os_strchr(pos, ':');
1828 if (pos == NULL)
1829 return -1;
1830 pos++;
1831 conn_cap[3] = atoi(pos);
1832 bss->hs20_connection_capability_len += 4;
1833
1834 return 0;
1835}
4065a309
JK
1836
1837
1838static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1839 int line)
1840{
1841 u8 *wan_metrics;
1842 char *pos;
1843
1844 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1845
1846 wan_metrics = os_zalloc(13);
1847 if (wan_metrics == NULL)
1848 return -1;
1849
1850 pos = buf;
1851 /* WAN Info */
1852 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1853 goto fail;
1854 pos += 2;
1855 if (*pos != ':')
1856 goto fail;
1857 pos++;
1858
1859 /* Downlink Speed */
1860 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1861 pos = os_strchr(pos, ':');
1862 if (pos == NULL)
1863 goto fail;
1864 pos++;
1865
1866 /* Uplink Speed */
1867 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1868 pos = os_strchr(pos, ':');
1869 if (pos == NULL)
1870 goto fail;
1871 pos++;
1872
1873 /* Downlink Load */
1874 wan_metrics[9] = atoi(pos);
1875 pos = os_strchr(pos, ':');
1876 if (pos == NULL)
1877 goto fail;
1878 pos++;
1879
1880 /* Uplink Load */
1881 wan_metrics[10] = atoi(pos);
1882 pos = os_strchr(pos, ':');
1883 if (pos == NULL)
1884 goto fail;
1885 pos++;
1886
1887 /* LMD */
1888 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1889
1890 os_free(bss->hs20_wan_metrics);
1891 bss->hs20_wan_metrics = wan_metrics;
1892
1893 return 0;
1894
1895fail:
1896 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
5cfc87b7 1897 line, buf);
4065a309
JK
1898 os_free(wan_metrics);
1899 return -1;
1900}
a9277e85
JK
1901
1902
1903static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1904 char *pos, int line)
1905{
1906 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1907 &bss->hs20_oper_friendly_name_count, pos)) {
1908 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1909 "hs20_oper_friendly_name '%s'", line, pos);
1910 return -1;
1911 }
1912 return 0;
1913}
f7bd7a01
JM
1914
1915
1916static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1917{
1918 struct hs20_icon *icon;
1919 char *end;
1920
1921 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1922 sizeof(struct hs20_icon));
1923 if (icon == NULL)
1924 return -1;
1925 bss->hs20_icons = icon;
1926 icon = &bss->hs20_icons[bss->hs20_icons_count];
1927 os_memset(icon, 0, sizeof(*icon));
1928
1929 icon->width = atoi(pos);
1930 pos = os_strchr(pos, ':');
1931 if (pos == NULL)
1932 return -1;
1933 pos++;
1934
1935 icon->height = atoi(pos);
1936 pos = os_strchr(pos, ':');
1937 if (pos == NULL)
1938 return -1;
1939 pos++;
1940
1941 end = os_strchr(pos, ':');
1942 if (end == NULL || end - pos > 3)
1943 return -1;
1944 os_memcpy(icon->language, pos, end - pos);
1945 pos = end + 1;
1946
1947 end = os_strchr(pos, ':');
1948 if (end == NULL || end - pos > 255)
1949 return -1;
1950 os_memcpy(icon->type, pos, end - pos);
1951 pos = end + 1;
1952
1953 end = os_strchr(pos, ':');
1954 if (end == NULL || end - pos > 255)
1955 return -1;
1956 os_memcpy(icon->name, pos, end - pos);
1957 pos = end + 1;
1958
1959 if (os_strlen(pos) > 255)
1960 return -1;
1961 os_memcpy(icon->file, pos, os_strlen(pos));
1962
1963 bss->hs20_icons_count++;
1964
1965 return 0;
1966}
1967
ae6d15c7
JM
1968
1969static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1970 char *pos, int line)
1971{
1972 size_t slen;
1973 char *str;
1974
1975 str = wpa_config_parse_string(pos, &slen);
81847c22 1976 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
ae6d15c7 1977 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
b2e32cde 1978 os_free(str);
ae6d15c7
JM
1979 return -1;
1980 }
1981
1982 os_memcpy(bss->osu_ssid, str, slen);
1983 bss->osu_ssid_len = slen;
1984 os_free(str);
1985
1986 return 0;
1987}
1988
1989
1990static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1991 char *pos, int line)
1992{
1993 struct hs20_osu_provider *p;
1994
1995 p = os_realloc_array(bss->hs20_osu_providers,
1996 bss->hs20_osu_providers_count + 1, sizeof(*p));
1997 if (p == NULL)
1998 return -1;
1999
2000 bss->hs20_osu_providers = p;
2001 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
2002 bss->hs20_osu_providers_count++;
2003 os_memset(bss->last_osu, 0, sizeof(*p));
2004 bss->last_osu->server_uri = os_strdup(pos);
2005
2006 return 0;
2007}
2008
2009
2010static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
2011 char *pos, int line)
2012{
2013 if (bss->last_osu == NULL) {
2014 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2015 return -1;
2016 }
2017
2018 if (parse_lang_string(&bss->last_osu->friendly_name,
2019 &bss->last_osu->friendly_name_count, pos)) {
2020 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
2021 line, pos);
2022 return -1;
2023 }
2024
2025 return 0;
2026}
2027
2028
2029static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
2030 char *pos, int line)
2031{
2032 if (bss->last_osu == NULL) {
2033 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2034 return -1;
2035 }
2036
2037 os_free(bss->last_osu->osu_nai);
2038 bss->last_osu->osu_nai = os_strdup(pos);
2039 if (bss->last_osu->osu_nai == NULL)
2040 return -1;
2041
2042 return 0;
2043}
2044
2045
2046static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
2047 int line)
2048{
2049 if (bss->last_osu == NULL) {
2050 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2051 return -1;
2052 }
2053
2054 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
2055 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
2056 return -1;
2057 }
2058
2059 return 0;
2060}
2061
2062
2063static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
2064 int line)
2065{
2066 char **n;
2067 struct hs20_osu_provider *p = bss->last_osu;
2068
2069 if (p == NULL) {
2070 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2071 return -1;
2072 }
2073
2074 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
2075 if (n == NULL)
2076 return -1;
2077 p->icons = n;
2078 p->icons[p->icons_count] = os_strdup(pos);
2079 if (p->icons[p->icons_count] == NULL)
2080 return -1;
2081 p->icons_count++;
2082
2083 return 0;
2084}
2085
2086
2087static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
2088 char *pos, int line)
2089{
2090 if (bss->last_osu == NULL) {
2091 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2092 return -1;
2093 }
2094
2095 if (parse_lang_string(&bss->last_osu->service_desc,
2096 &bss->last_osu->service_desc_count, pos)) {
2097 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
2098 line, pos);
2099 return -1;
2100 }
2101
2102 return 0;
2103}
2104
0e450db2
JM
2105
2106static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
2107 int line)
2108{
2109 char **n;
2110
2111 n = os_realloc_array(bss->hs20_operator_icon,
2112 bss->hs20_operator_icon_count + 1, sizeof(char *));
2113 if (!n)
2114 return -1;
2115 bss->hs20_operator_icon = n;
2116 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
2117 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
2118 return -1;
2119 bss->hs20_operator_icon_count++;
2120
2121 return 0;
2122}
2123
5ccc54aa
JK
2124#endif /* CONFIG_HS20 */
2125
2126
68fa00c3
JM
2127#ifdef CONFIG_ACS
2128static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
2129 char *pos)
2130{
2131 struct acs_bias *bias = NULL, *tmp;
2132 unsigned int num = 0;
2133 char *end;
2134
2135 while (*pos) {
2136 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2137 if (!tmp)
2138 goto fail;
2139 bias = tmp;
2140
2141 bias[num].channel = atoi(pos);
2142 if (bias[num].channel <= 0)
2143 goto fail;
2144 pos = os_strchr(pos, ':');
2145 if (!pos)
2146 goto fail;
2147 pos++;
2148 bias[num].bias = strtod(pos, &end);
2149 if (end == pos || bias[num].bias < 0.0)
2150 goto fail;
2151 pos = end;
2152 if (*pos != ' ' && *pos != '\0')
2153 goto fail;
2154 num++;
2155 }
2156
2157 os_free(conf->acs_chan_bias);
2158 conf->acs_chan_bias = bias;
2159 conf->num_acs_chan_bias = num;
2160
2161 return 0;
2162fail:
2163 os_free(bias);
2164 return -1;
2165}
2166#endif /* CONFIG_ACS */
2167
2168
4ac33989
JM
2169static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2170 const char *val)
2171{
2172 struct wpabuf *elems;
2173
2174 if (val[0] == '\0') {
2175 wpabuf_free(*buf);
2176 *buf = NULL;
2177 return 0;
2178 }
2179
2180 elems = wpabuf_parse_bin(val);
2181 if (!elems) {
2182 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2183 line, name, val);
2184 return -1;
2185 }
2186
2187 wpabuf_free(*buf);
2188 *buf = elems;
2189
2190 return 0;
2191}
2192
2193
26bf70e3
JM
2194#ifdef CONFIG_FILS
2195static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2196{
2197 struct fils_realm *realm;
2198 size_t len;
2199
2200 len = os_strlen(val);
2201 realm = os_zalloc(sizeof(*realm) + len + 1);
2202 if (!realm)
2203 return -1;
2204
2205 os_memcpy(realm->realm, val, len);
2206 if (fils_domain_name_hash(val, realm->hash) < 0) {
2207 os_free(realm);
2208 return -1;
2209 }
2210 dl_list_add_tail(&bss->fils_realms, &realm->list);
2211
2212 return 0;
2213}
2214#endif /* CONFIG_FILS */
2215
2216
6418400d
JM
2217#ifdef EAP_SERVER
2218static unsigned int parse_tls_flags(const char *val)
2219{
2220 unsigned int flags = 0;
2221
d501c27c
JM
2222 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2223 * This can be enabled by default once the implementation has been fully
2224 * completed and tested with other implementations. */
2225 flags |= TLS_CONN_DISABLE_TLSv1_3;
2226
6418400d
JM
2227 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2228 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2229 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2230 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2231 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2232 flags |= TLS_CONN_DISABLE_TLSv1_0;
2233 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2234 flags |= TLS_CONN_DISABLE_TLSv1_1;
2235 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2236 flags |= TLS_CONN_DISABLE_TLSv1_2;
bbbc7e80
JM
2237 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2238 flags |= TLS_CONN_DISABLE_TLSv1_3;
d501c27c
JM
2239 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2240 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
6418400d
JM
2241 if (os_strstr(val, "[SUITEB]"))
2242 flags |= TLS_CONN_SUITEB;
2ed70c75
JM
2243 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2244 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
6418400d
JM
2245
2246 return flags;
2247}
2248#endif /* EAP_SERVER */
2249
2250
9be19d0b
JM
2251#ifdef CONFIG_SAE
2252static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2253{
2254 struct sae_password_entry *pw;
2255 const char *pos = val, *pos2, *end = NULL;
2256
2257 pw = os_zalloc(sizeof(*pw));
2258 if (!pw)
2259 return -1;
2260 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2261
2262 pos2 = os_strstr(pos, "|mac=");
2263 if (pos2) {
2264 end = pos2;
2265 pos2 += 5;
2266 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2267 goto fail;
2268 pos = pos2 + ETH_ALEN * 3 - 1;
2269 }
2270
2271 pos2 = os_strstr(pos, "|id=");
2272 if (pos2) {
2273 if (!end)
2274 end = pos2;
2275 pos2 += 4;
2276 pw->identifier = os_strdup(pos2);
2277 if (!pw->identifier)
2278 goto fail;
2279 }
2280
2281 if (!end) {
2282 pw->password = os_strdup(val);
2283 if (!pw->password)
2284 goto fail;
2285 } else {
2286 pw->password = os_malloc(end - val + 1);
2287 if (!pw->password)
2288 goto fail;
2289 os_memcpy(pw->password, val, end - val);
2290 pw->password[end - val] = '\0';
2291 }
2292
2293 pw->next = bss->sae_passwords;
2294 bss->sae_passwords = pw;
2295
2296 return 0;
2297fail:
2298 str_clear_free(pw->password);
2299 os_free(pw->identifier);
2300 os_free(pw);
2301 return -1;
2302}
2303#endif /* CONFIG_SAE */
2304
2305
ef45bc89
SP
2306static int hostapd_config_fill(struct hostapd_config *conf,
2307 struct hostapd_bss_config *bss,
63e169e1 2308 const char *buf, char *pos, int line)
41d719d6 2309{
599f40db
JM
2310 if (os_strcmp(buf, "interface") == 0) {
2311 os_strlcpy(conf->bss[0]->iface, pos,
2312 sizeof(conf->bss[0]->iface));
2313 } else if (os_strcmp(buf, "bridge") == 0) {
2314 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2315 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2316 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2317 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2318 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2319 } else if (os_strcmp(buf, "driver") == 0) {
2320 int j;
8628555f
JM
2321 const struct wpa_driver_ops *driver = NULL;
2322
599f40db
JM
2323 for (j = 0; wpa_drivers[j]; j++) {
2324 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
8628555f 2325 driver = wpa_drivers[j];
599f40db 2326 break;
41d719d6 2327 }
599f40db 2328 }
8628555f 2329 if (!driver) {
599f40db
JM
2330 wpa_printf(MSG_ERROR,
2331 "Line %d: invalid/unknown driver '%s'",
2332 line, pos);
a0b728b7 2333 return 1;
599f40db 2334 }
8628555f 2335 conf->driver = driver;
0ecff8d7
JM
2336 } else if (os_strcmp(buf, "driver_params") == 0) {
2337 os_free(conf->driver_params);
2338 conf->driver_params = os_strdup(pos);
599f40db
JM
2339 } else if (os_strcmp(buf, "debug") == 0) {
2340 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2341 line);
2342 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2343 bss->logger_syslog_level = atoi(pos);
2344 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2345 bss->logger_stdout_level = atoi(pos);
2346 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2347 bss->logger_syslog = atoi(pos);
2348 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2349 bss->logger_stdout = atoi(pos);
2350 } else if (os_strcmp(buf, "dump_file") == 0) {
2351 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2352 line);
2353 } else if (os_strcmp(buf, "ssid") == 0) {
2354 bss->ssid.ssid_len = os_strlen(pos);
81847c22 2355 if (bss->ssid.ssid_len > SSID_MAX_LEN ||
599f40db
JM
2356 bss->ssid.ssid_len < 1) {
2357 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2358 line, pos);
a0b728b7 2359 return 1;
599f40db 2360 }
b4c26ef9
JM
2361 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
2362 bss->ssid.ssid_set = 1;
599f40db
JM
2363 } else if (os_strcmp(buf, "ssid2") == 0) {
2364 size_t slen;
2365 char *str = wpa_config_parse_string(pos, &slen);
81847c22 2366 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
599f40db
JM
2367 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2368 line, pos);
b2e32cde 2369 os_free(str);
a0b728b7 2370 return 1;
599f40db 2371 }
b2e32cde
JM
2372 os_memcpy(bss->ssid.ssid, str, slen);
2373 bss->ssid.ssid_len = slen;
2374 bss->ssid.ssid_set = 1;
599f40db
JM
2375 os_free(str);
2376 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2377 bss->ssid.utf8_ssid = atoi(pos) > 0;
2378 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
9266d00b
JM
2379 enum macaddr_acl acl = atoi(pos);
2380
2381 if (acl != ACCEPT_UNLESS_DENIED &&
2382 acl != DENY_UNLESS_ACCEPTED &&
2383 acl != USE_EXTERNAL_RADIUS_AUTH) {
599f40db 2384 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
9266d00b
JM
2385 line, acl);
2386 return 1;
599f40db 2387 }
9266d00b 2388 bss->macaddr_acl = acl;
599f40db
JM
2389 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2390 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2391 &bss->num_accept_mac)) {
2392 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2393 line, pos);
a0b728b7 2394 return 1;
599f40db
JM
2395 }
2396 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2397 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2398 &bss->num_deny_mac)) {
2399 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2400 line, pos);
a0b728b7 2401 return 1;
599f40db
JM
2402 }
2403 } else if (os_strcmp(buf, "wds_sta") == 0) {
2404 bss->wds_sta = atoi(pos);
2405 } else if (os_strcmp(buf, "start_disabled") == 0) {
2406 bss->start_disabled = atoi(pos);
2407 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2408 bss->isolate = atoi(pos);
2409 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2410 bss->ap_max_inactivity = atoi(pos);
2411 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2412 bss->skip_inactivity_poll = atoi(pos);
2413 } else if (os_strcmp(buf, "country_code") == 0) {
2414 os_memcpy(conf->country, pos, 2);
ff936bc7
JM
2415 } else if (os_strcmp(buf, "country3") == 0) {
2416 conf->country[2] = strtol(pos, NULL, 16);
599f40db
JM
2417 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2418 conf->ieee80211d = atoi(pos);
2419 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2420 conf->ieee80211h = atoi(pos);
2421 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2422 bss->ieee802_1x = atoi(pos);
2423 } else if (os_strcmp(buf, "eapol_version") == 0) {
e0ba7efe
JM
2424 int eapol_version = atoi(pos);
2425
2426 if (eapol_version < 1 || eapol_version > 2) {
599f40db
JM
2427 wpa_printf(MSG_ERROR,
2428 "Line %d: invalid EAPOL version (%d): '%s'.",
e0ba7efe 2429 line, eapol_version, pos);
a0b728b7 2430 return 1;
b4c26ef9 2431 }
e0ba7efe 2432 bss->eapol_version = eapol_version;
b4c26ef9 2433 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
41d719d6 2434#ifdef EAP_SERVER
599f40db
JM
2435 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2436 bss->eap_server = atoi(pos);
2437 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2438 } else if (os_strcmp(buf, "eap_server") == 0) {
2439 bss->eap_server = atoi(pos);
2440 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2441 if (hostapd_config_read_eap_user(pos, bss))
a0b728b7 2442 return 1;
599f40db
JM
2443 } else if (os_strcmp(buf, "ca_cert") == 0) {
2444 os_free(bss->ca_cert);
2445 bss->ca_cert = os_strdup(pos);
2446 } else if (os_strcmp(buf, "server_cert") == 0) {
2447 os_free(bss->server_cert);
2448 bss->server_cert = os_strdup(pos);
2449 } else if (os_strcmp(buf, "private_key") == 0) {
2450 os_free(bss->private_key);
2451 bss->private_key = os_strdup(pos);
2452 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2453 os_free(bss->private_key_passwd);
2454 bss->private_key_passwd = os_strdup(pos);
2455 } else if (os_strcmp(buf, "check_crl") == 0) {
2456 bss->check_crl = atoi(pos);
681e199d
JM
2457 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2458 bss->tls_session_lifetime = atoi(pos);
6418400d
JM
2459 } else if (os_strcmp(buf, "tls_flags") == 0) {
2460 bss->tls_flags = parse_tls_flags(pos);
599f40db
JM
2461 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2462 os_free(bss->ocsp_stapling_response);
2463 bss->ocsp_stapling_response = os_strdup(pos);
5addb0df
JM
2464 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2465 os_free(bss->ocsp_stapling_response_multi);
2466 bss->ocsp_stapling_response_multi = os_strdup(pos);
599f40db
JM
2467 } else if (os_strcmp(buf, "dh_file") == 0) {
2468 os_free(bss->dh_file);
2469 bss->dh_file = os_strdup(pos);
f8995f8f
JM
2470 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2471 os_free(bss->openssl_ciphers);
2472 bss->openssl_ciphers = os_strdup(pos);
599f40db
JM
2473 } else if (os_strcmp(buf, "fragment_size") == 0) {
2474 bss->fragment_size = atoi(pos);
41d719d6 2475#ifdef EAP_SERVER_FAST
599f40db
JM
2476 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2477 os_free(bss->pac_opaque_encr_key);
2478 bss->pac_opaque_encr_key = os_malloc(16);
2479 if (bss->pac_opaque_encr_key == NULL) {
2480 wpa_printf(MSG_ERROR,
2481 "Line %d: No memory for pac_opaque_encr_key",
2482 line);
a0b728b7 2483 return 1;
599f40db
JM
2484 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2485 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2486 line);
a0b728b7 2487 return 1;
599f40db
JM
2488 }
2489 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2490 size_t idlen = os_strlen(pos);
2491 if (idlen & 1) {
2492 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2493 line);
a0b728b7 2494 return 1;
b4c26ef9
JM
2495 }
2496 os_free(bss->eap_fast_a_id);
2497 bss->eap_fast_a_id = os_malloc(idlen / 2);
2498 if (bss->eap_fast_a_id == NULL ||
2499 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2500 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2501 line);
599f40db 2502 os_free(bss->eap_fast_a_id);
b4c26ef9
JM
2503 bss->eap_fast_a_id = NULL;
2504 return 1;
2505 } else {
2506 bss->eap_fast_a_id_len = idlen / 2;
599f40db
JM
2507 }
2508 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2509 os_free(bss->eap_fast_a_id_info);
2510 bss->eap_fast_a_id_info = os_strdup(pos);
2511 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2512 bss->eap_fast_prov = atoi(pos);
2513 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2514 bss->pac_key_lifetime = atoi(pos);
2515 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2516 bss->pac_key_refresh_time = atoi(pos);
41d719d6
JM
2517#endif /* EAP_SERVER_FAST */
2518#ifdef EAP_SERVER_SIM
599f40db
JM
2519 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2520 os_free(bss->eap_sim_db);
2521 bss->eap_sim_db = os_strdup(pos);
7b0f5500
FL
2522 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2523 bss->eap_sim_db_timeout = atoi(pos);
599f40db
JM
2524 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2525 bss->eap_sim_aka_result_ind = atoi(pos);
41d719d6
JM
2526#endif /* EAP_SERVER_SIM */
2527#ifdef EAP_SERVER_TNC
599f40db
JM
2528 } else if (os_strcmp(buf, "tnc") == 0) {
2529 bss->tnc = atoi(pos);
41d719d6 2530#endif /* EAP_SERVER_TNC */
df684d82 2531#ifdef EAP_SERVER_PWD
599f40db
JM
2532 } else if (os_strcmp(buf, "pwd_group") == 0) {
2533 bss->pwd_group = atoi(pos);
df684d82 2534#endif /* EAP_SERVER_PWD */
427729ee 2535#ifdef CONFIG_ERP
d3bddd8b
JM
2536 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2537 bss->eap_server_erp = atoi(pos);
427729ee 2538#endif /* CONFIG_ERP */
41d719d6 2539#endif /* EAP_SERVER */
599f40db
JM
2540 } else if (os_strcmp(buf, "eap_message") == 0) {
2541 char *term;
5784b9a4 2542 os_free(bss->eap_req_id_text);
599f40db
JM
2543 bss->eap_req_id_text = os_strdup(pos);
2544 if (bss->eap_req_id_text == NULL) {
2545 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2546 line);
a0b728b7 2547 return 1;
599f40db
JM
2548 }
2549 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2550 term = os_strstr(bss->eap_req_id_text, "\\0");
2551 if (term) {
2552 *term++ = '\0';
2553 os_memmove(term, term + 1,
2554 bss->eap_req_id_text_len -
2555 (term - bss->eap_req_id_text) - 1);
2556 bss->eap_req_id_text_len--;
2557 }
2a5156a6
JM
2558 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2559 bss->erp_send_reauth_start = atoi(pos);
2560 } else if (os_strcmp(buf, "erp_domain") == 0) {
2561 os_free(bss->erp_domain);
2562 bss->erp_domain = os_strdup(pos);
599f40db 2563 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
f78402ac
JM
2564 int val = atoi(pos);
2565
2566 if (val < 0 || val > 13) {
2567 wpa_printf(MSG_ERROR,
2568 "Line %d: invalid WEP key len %d (= %d bits)",
2569 line, val, val * 8);
a0b728b7 2570 return 1;
599f40db 2571 }
f78402ac 2572 bss->default_wep_key_len = val;
599f40db 2573 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
a5861afc
JM
2574 int val = atoi(pos);
2575
2576 if (val < 0 || val > 13) {
2577 wpa_printf(MSG_ERROR,
2578 "Line %d: invalid WEP key len %d (= %d bits)",
2579 line, val, val * 8);
a0b728b7 2580 return 1;
599f40db 2581 }
a5861afc 2582 bss->individual_wep_key_len = val;
599f40db
JM
2583 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2584 bss->wep_rekeying_period = atoi(pos);
2585 if (bss->wep_rekeying_period < 0) {
2586 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2587 line, bss->wep_rekeying_period);
a0b728b7 2588 return 1;
599f40db
JM
2589 }
2590 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2591 bss->eap_reauth_period = atoi(pos);
2592 if (bss->eap_reauth_period < 0) {
2593 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2594 line, bss->eap_reauth_period);
a0b728b7 2595 return 1;
599f40db
JM
2596 }
2597 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2598 bss->eapol_key_index_workaround = atoi(pos);
41d719d6 2599#ifdef CONFIG_IAPP
599f40db
JM
2600 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2601 bss->ieee802_11f = 1;
2602 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
41d719d6 2603#endif /* CONFIG_IAPP */
599f40db
JM
2604 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2605 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2606 wpa_printf(MSG_ERROR,
2607 "Line %d: invalid IP address '%s'",
2608 line, pos);
a0b728b7 2609 return 1;
599f40db
JM
2610 }
2611 } else if (os_strcmp(buf, "nas_identifier") == 0) {
5784b9a4 2612 os_free(bss->nas_identifier);
599f40db 2613 bss->nas_identifier = os_strdup(pos);
41d719d6 2614#ifndef CONFIG_NO_RADIUS
9836cb53
JM
2615 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2616 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2617 wpa_printf(MSG_ERROR,
2618 "Line %d: invalid IP address '%s'",
2619 line, pos);
2620 return 1;
2621 }
2622 bss->radius->force_client_addr = 1;
599f40db
JM
2623 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2624 if (hostapd_config_read_radius_addr(
2625 &bss->radius->auth_servers,
2626 &bss->radius->num_auth_servers, pos, 1812,
2627 &bss->radius->auth_server)) {
2628 wpa_printf(MSG_ERROR,
2629 "Line %d: invalid IP address '%s'",
2630 line, pos);
a0b728b7 2631 return 1;
599f40db 2632 }
bbee36e3
JM
2633 } else if (bss->radius->auth_server &&
2634 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2635 if (hostapd_parse_ip_addr(pos,
2636 &bss->radius->auth_server->addr)) {
2637 wpa_printf(MSG_ERROR,
2638 "Line %d: invalid IP address '%s'",
2639 line, pos);
2640 return 1;
2641 }
599f40db
JM
2642 } else if (bss->radius->auth_server &&
2643 os_strcmp(buf, "auth_server_port") == 0) {
2644 bss->radius->auth_server->port = atoi(pos);
2645 } else if (bss->radius->auth_server &&
2646 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2647 int len = os_strlen(pos);
2648 if (len == 0) {
2649 /* RFC 2865, Ch. 3 */
2650 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2651 line);
a0b728b7 2652 return 1;
599f40db 2653 }
5784b9a4 2654 os_free(bss->radius->auth_server->shared_secret);
599f40db
JM
2655 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2656 bss->radius->auth_server->shared_secret_len = len;
2657 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2658 if (hostapd_config_read_radius_addr(
2659 &bss->radius->acct_servers,
2660 &bss->radius->num_acct_servers, pos, 1813,
2661 &bss->radius->acct_server)) {
2662 wpa_printf(MSG_ERROR,
2663 "Line %d: invalid IP address '%s'",
2664 line, pos);
a0b728b7 2665 return 1;
bbee36e3
JM
2666 }
2667 } else if (bss->radius->acct_server &&
2668 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2669 if (hostapd_parse_ip_addr(pos,
2670 &bss->radius->acct_server->addr)) {
2671 wpa_printf(MSG_ERROR,
2672 "Line %d: invalid IP address '%s'",
2673 line, pos);
2674 return 1;
599f40db
JM
2675 }
2676 } else if (bss->radius->acct_server &&
2677 os_strcmp(buf, "acct_server_port") == 0) {
2678 bss->radius->acct_server->port = atoi(pos);
2679 } else if (bss->radius->acct_server &&
2680 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2681 int len = os_strlen(pos);
2682 if (len == 0) {
2683 /* RFC 2865, Ch. 3 */
2684 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2685 line);
a0b728b7 2686 return 1;
599f40db 2687 }
5784b9a4 2688 os_free(bss->radius->acct_server->shared_secret);
599f40db
JM
2689 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2690 bss->radius->acct_server->shared_secret_len = len;
2691 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2692 bss->radius->retry_primary_interval = atoi(pos);
2693 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2694 bss->acct_interim_interval = atoi(pos);
2695 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2696 bss->radius_request_cui = atoi(pos);
2697 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2698 struct hostapd_radius_attr *attr, *a;
2699 attr = hostapd_parse_radius_attr(pos);
2700 if (attr == NULL) {
2701 wpa_printf(MSG_ERROR,
2702 "Line %d: invalid radius_auth_req_attr",
2703 line);
a0b728b7 2704 return 1;
599f40db
JM
2705 } else if (bss->radius_auth_req_attr == NULL) {
2706 bss->radius_auth_req_attr = attr;
2707 } else {
2708 a = bss->radius_auth_req_attr;
2709 while (a->next)
2710 a = a->next;
2711 a->next = attr;
2712 }
2713 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2714 struct hostapd_radius_attr *attr, *a;
2715 attr = hostapd_parse_radius_attr(pos);
2716 if (attr == NULL) {
2717 wpa_printf(MSG_ERROR,
2718 "Line %d: invalid radius_acct_req_attr",
2719 line);
a0b728b7 2720 return 1;
599f40db
JM
2721 } else if (bss->radius_acct_req_attr == NULL) {
2722 bss->radius_acct_req_attr = attr;
2723 } else {
2724 a = bss->radius_acct_req_attr;
2725 while (a->next)
2726 a = a->next;
2727 a->next = attr;
2728 }
2729 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2730 bss->radius_das_port = atoi(pos);
2731 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2732 if (hostapd_parse_das_client(bss, pos) < 0) {
2733 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2734 line);
a0b728b7 2735 return 1;
599f40db
JM
2736 }
2737 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2738 bss->radius_das_time_window = atoi(pos);
2739 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2740 bss->radius_das_require_event_timestamp = atoi(pos);
42d30e9e
NL
2741 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2742 0) {
2743 bss->radius_das_require_message_authenticator = atoi(pos);
41d719d6 2744#endif /* CONFIG_NO_RADIUS */
599f40db
JM
2745 } else if (os_strcmp(buf, "auth_algs") == 0) {
2746 bss->auth_algs = atoi(pos);
2747 if (bss->auth_algs == 0) {
2748 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2749 line);
a0b728b7 2750 return 1;
599f40db
JM
2751 }
2752 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2753 bss->max_num_sta = atoi(pos);
2754 if (bss->max_num_sta < 0 ||
2755 bss->max_num_sta > MAX_STA_COUNT) {
2756 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2757 line, bss->max_num_sta, MAX_STA_COUNT);
a0b728b7 2758 return 1;
599f40db
JM
2759 }
2760 } else if (os_strcmp(buf, "wpa") == 0) {
2761 bss->wpa = atoi(pos);
2762 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2763 bss->wpa_group_rekey = atoi(pos);
90f837b0 2764 bss->wpa_group_rekey_set = 1;
599f40db
JM
2765 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2766 bss->wpa_strict_rekey = atoi(pos);
2767 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2768 bss->wpa_gmk_rekey = atoi(pos);
2769 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2770 bss->wpa_ptk_rekey = atoi(pos);
41f140d3
GK
2771 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2772 char *endp;
2773 unsigned long val = strtoul(pos, &endp, 0);
2774
2775 if (*endp || val < 1 || val > (u32) -1) {
2776 wpa_printf(MSG_ERROR,
2777 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2778 line, val);
2779 return 1;
2780 }
2781 bss->wpa_group_update_count = (u32) val;
2782 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2783 char *endp;
2784 unsigned long val = strtoul(pos, &endp, 0);
2785
2786 if (*endp || val < 1 || val > (u32) -1) {
2787 wpa_printf(MSG_ERROR,
2788 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2789 line, val);
2790 return 1;
2791 }
2792 bss->wpa_pairwise_update_count = (u32) val;
6f234c1e
JM
2793 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2794 bss->wpa_disable_eapol_key_retries = atoi(pos);
599f40db
JM
2795 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2796 int len = os_strlen(pos);
2797 if (len < 8 || len > 63) {
2798 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2799 line, len);
a0b728b7 2800 return 1;
b4c26ef9
JM
2801 }
2802 os_free(bss->ssid.wpa_passphrase);
2803 bss->ssid.wpa_passphrase = os_strdup(pos);
2804 if (bss->ssid.wpa_passphrase) {
891dfb33 2805 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
b4c26ef9 2806 bss->ssid.wpa_passphrase_set = 1;
599f40db
JM
2807 }
2808 } else if (os_strcmp(buf, "wpa_psk") == 0) {
891dfb33 2809 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
599f40db
JM
2810 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2811 if (bss->ssid.wpa_psk == NULL)
a0b728b7 2812 return 1;
b4c26ef9
JM
2813 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2814 pos[PMK_LEN * 2] != '\0') {
599f40db
JM
2815 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2816 line, pos);
891dfb33 2817 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
a0b728b7 2818 return 1;
599f40db 2819 }
b4c26ef9
JM
2820 bss->ssid.wpa_psk->group = 1;
2821 os_free(bss->ssid.wpa_passphrase);
2822 bss->ssid.wpa_passphrase = NULL;
2823 bss->ssid.wpa_psk_set = 1;
599f40db
JM
2824 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2825 os_free(bss->ssid.wpa_psk_file);
2826 bss->ssid.wpa_psk_file = os_strdup(pos);
2827 if (!bss->ssid.wpa_psk_file) {
2828 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2829 line);
a0b728b7 2830 return 1;
599f40db
JM
2831 }
2832 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2833 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2834 if (bss->wpa_key_mgmt == -1)
a0b728b7 2835 return 1;
599f40db
JM
2836 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2837 bss->wpa_psk_radius = atoi(pos);
2838 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2839 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2840 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2841 wpa_printf(MSG_ERROR,
2842 "Line %d: unknown wpa_psk_radius %d",
2843 line, bss->wpa_psk_radius);
a0b728b7 2844 return 1;
599f40db
JM
2845 }
2846 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2847 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2848 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
a0b728b7 2849 return 1;
b4c26ef9
JM
2850 if (bss->wpa_pairwise &
2851 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
599f40db 2852 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
a7297ae5 2853 line, pos);
a0b728b7 2854 return 1;
599f40db
JM
2855 }
2856 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2857 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2858 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
a0b728b7 2859 return 1;
b4c26ef9
JM
2860 if (bss->rsn_pairwise &
2861 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
599f40db 2862 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
a7297ae5 2863 line, pos);
a0b728b7 2864 return 1;
599f40db 2865 }
27781c0a
JM
2866 } else if (os_strcmp(buf, "group_cipher") == 0) {
2867 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2868 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2869 return 1;
2870 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2871 bss->group_cipher != WPA_CIPHER_CCMP &&
2872 bss->group_cipher != WPA_CIPHER_GCMP &&
2873 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2874 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2875 wpa_printf(MSG_ERROR,
2876 "Line %d: unsupported group cipher suite '%s'",
2877 line, pos);
2878 return 1;
2879 }
41d719d6 2880#ifdef CONFIG_RSN_PREAUTH
599f40db
JM
2881 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2882 bss->rsn_preauth = atoi(pos);
2883 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
5784b9a4 2884 os_free(bss->rsn_preauth_interfaces);
599f40db 2885 bss->rsn_preauth_interfaces = os_strdup(pos);
41d719d6 2886#endif /* CONFIG_RSN_PREAUTH */
599f40db 2887 } else if (os_strcmp(buf, "peerkey") == 0) {
a0bf1b68
JM
2888 wpa_printf(MSG_INFO,
2889 "Line %d: Obsolete peerkey parameter ignored", line);
d503eeea 2890#ifdef CONFIG_IEEE80211R_AP
599f40db
JM
2891 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2892 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2893 hexstr2bin(pos, bss->mobility_domain,
2894 MOBILITY_DOMAIN_ID_LEN) != 0) {
2895 wpa_printf(MSG_ERROR,
2896 "Line %d: Invalid mobility_domain '%s'",
2897 line, pos);
a0b728b7 2898 return 1;
599f40db
JM
2899 }
2900 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2901 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2902 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2903 wpa_printf(MSG_ERROR,
2904 "Line %d: Invalid r1_key_holder '%s'",
2905 line, pos);
a0b728b7 2906 return 1;
599f40db
JM
2907 }
2908 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
83fe4bd3
MB
2909 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
2910 bss->r0_key_lifetime = atoi(pos) * 60;
2911 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
599f40db 2912 bss->r0_key_lifetime = atoi(pos);
3a3e2832
MB
2913 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
2914 bss->r1_max_key_lifetime = atoi(pos);
599f40db
JM
2915 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2916 bss->reassociation_deadline = atoi(pos);
3a46cf93
MB
2917 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
2918 bss->rkh_pos_timeout = atoi(pos);
2919 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
2920 bss->rkh_neg_timeout = atoi(pos);
2921 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
2922 bss->rkh_pull_timeout = atoi(pos);
2923 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
2924 bss->rkh_pull_retries = atoi(pos);
599f40db
JM
2925 } else if (os_strcmp(buf, "r0kh") == 0) {
2926 if (add_r0kh(bss, pos) < 0) {
2927 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2928 line, pos);
a0b728b7 2929 return 1;
599f40db
JM
2930 }
2931 } else if (os_strcmp(buf, "r1kh") == 0) {
2932 if (add_r1kh(bss, pos) < 0) {
2933 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2934 line, pos);
a0b728b7 2935 return 1;
599f40db
JM
2936 }
2937 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2938 bss->pmk_r1_push = atoi(pos);
2939 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2940 bss->ft_over_ds = atoi(pos);
96590564
MB
2941 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
2942 bss->ft_psk_generate_local = atoi(pos);
d503eeea 2943#endif /* CONFIG_IEEE80211R_AP */
41d719d6 2944#ifndef CONFIG_NO_CTRL_IFACE
599f40db
JM
2945 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2946 os_free(bss->ctrl_interface);
2947 bss->ctrl_interface = os_strdup(pos);
2948 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
41d719d6 2949#ifndef CONFIG_NATIVE_WINDOWS
599f40db
JM
2950 struct group *grp;
2951 char *endp;
2952 const char *group = pos;
41d719d6 2953
599f40db
JM
2954 grp = getgrnam(group);
2955 if (grp) {
2956 bss->ctrl_interface_gid = grp->gr_gid;
41d719d6 2957 bss->ctrl_interface_gid_set = 1;
599f40db
JM
2958 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2959 bss->ctrl_interface_gid, group);
2960 return 0;
2961 }
2962
2963 /* Group name not found - try to parse this as gid */
2964 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2965 if (*group == '\0' || *endp != '\0') {
2966 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2967 line, group);
2968 return 1;
2969 }
2970 bss->ctrl_interface_gid_set = 1;
2971 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2972 bss->ctrl_interface_gid);
41d719d6
JM
2973#endif /* CONFIG_NATIVE_WINDOWS */
2974#endif /* CONFIG_NO_CTRL_IFACE */
2975#ifdef RADIUS_SERVER
599f40db
JM
2976 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2977 os_free(bss->radius_server_clients);
2978 bss->radius_server_clients = os_strdup(pos);
2979 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2980 bss->radius_server_auth_port = atoi(pos);
2981 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2982 bss->radius_server_acct_port = atoi(pos);
2983 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2984 bss->radius_server_ipv6 = atoi(pos);
41d719d6 2985#endif /* RADIUS_SERVER */
599f40db
JM
2986 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2987 bss->use_pae_group_addr = atoi(pos);
2988 } else if (os_strcmp(buf, "hw_mode") == 0) {
2989 if (os_strcmp(pos, "a") == 0)
2990 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2991 else if (os_strcmp(pos, "b") == 0)
2992 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2993 else if (os_strcmp(pos, "g") == 0)
2994 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2995 else if (os_strcmp(pos, "ad") == 0)
2996 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
3784c058
PX
2997 else if (os_strcmp(pos, "any") == 0)
2998 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
599f40db
JM
2999 else {
3000 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3001 line, pos);
a0b728b7 3002 return 1;
599f40db
JM
3003 }
3004 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
01a02593
HK
3005 if (os_strcmp(pos, "ad") == 0)
3006 bss->wps_rf_bands = WPS_RF_60GHZ;
3007 else if (os_strcmp(pos, "a") == 0)
599f40db
JM
3008 bss->wps_rf_bands = WPS_RF_50GHZ;
3009 else if (os_strcmp(pos, "g") == 0 ||
3010 os_strcmp(pos, "b") == 0)
3011 bss->wps_rf_bands = WPS_RF_24GHZ;
3012 else if (os_strcmp(pos, "ag") == 0 ||
3013 os_strcmp(pos, "ga") == 0)
3014 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3015 else {
3016 wpa_printf(MSG_ERROR,
3017 "Line %d: unknown wps_rf_band '%s'",
3018 line, pos);
a0b728b7 3019 return 1;
599f40db 3020 }
2d18ab40
SD
3021 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3022 conf->acs_exclude_dfs = atoi(pos);
599f40db
JM
3023 } else if (os_strcmp(buf, "channel") == 0) {
3024 if (os_strcmp(pos, "acs_survey") == 0) {
50f4f2a0 3025#ifndef CONFIG_ACS
599f40db
JM
3026 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3027 line);
a0b728b7 3028 return 1;
9670f877 3029#else /* CONFIG_ACS */
857d9422 3030 conf->acs = 1;
599f40db 3031 conf->channel = 0;
9670f877 3032#endif /* CONFIG_ACS */
857d9422 3033 } else {
599f40db 3034 conf->channel = atoi(pos);
857d9422
MM
3035 conf->acs = conf->channel == 0;
3036 }
599f40db 3037 } else if (os_strcmp(buf, "chanlist") == 0) {
857d9422 3038 if (hostapd_parse_chanlist(conf, pos)) {
599f40db
JM
3039 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3040 line);
a0b728b7 3041 return 1;
599f40db
JM
3042 }
3043 } else if (os_strcmp(buf, "beacon_int") == 0) {
3044 int val = atoi(pos);
3045 /* MIB defines range as 1..65535, but very small values
3046 * cause problems with the current implementation.
3047 * Since it is unlikely that this small numbers are
3048 * useful in real life scenarios, do not allow beacon
3049 * period to be set below 15 TU. */
3050 if (val < 15 || val > 65535) {
3051 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
3052 line, val);
a0b728b7 3053 return 1;
b4c26ef9
JM
3054 }
3055 conf->beacon_int = val;
50f4f2a0 3056#ifdef CONFIG_ACS
599f40db
JM
3057 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3058 int val = atoi(pos);
3059 if (val <= 0 || val > 100) {
3060 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3061 line, val);
a0b728b7 3062 return 1;
b4c26ef9
JM
3063 }
3064 conf->acs_num_scans = val;
68fa00c3
JM
3065 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3066 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3067 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3068 line);
3069 return -1;
3070 }
50f4f2a0 3071#endif /* CONFIG_ACS */
599f40db 3072 } else if (os_strcmp(buf, "dtim_period") == 0) {
546680f8
JM
3073 int val = atoi(pos);
3074
3075 if (val < 1 || val > 255) {
599f40db 3076 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
546680f8 3077 line, val);
a0b728b7 3078 return 1;
599f40db 3079 }
546680f8 3080 bss->dtim_period = val;
ec8f36af 3081 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
778d8705
JM
3082 int val = atoi(pos);
3083
3084 if (val < 0 || val > 100) {
ec8f36af
KP
3085 wpa_printf(MSG_ERROR,
3086 "Line %d: invalid bss_load_update_period %d",
778d8705 3087 line, val);
ec8f36af
KP
3088 return 1;
3089 }
778d8705 3090 bss->bss_load_update_period = val;
af832aa9
BP
3091 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3092 int val = atoi(pos);
3093
3094 if (val < 0) {
3095 wpa_printf(MSG_ERROR,
3096 "Line %d: invalid chan_util_avg_period",
3097 line);
3098 return 1;
3099 }
3100 bss->chan_util_avg_period = val;
599f40db
JM
3101 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3102 conf->rts_threshold = atoi(pos);
bc50bb0a 3103 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
599f40db
JM
3104 wpa_printf(MSG_ERROR,
3105 "Line %d: invalid rts_threshold %d",
3106 line, conf->rts_threshold);
a0b728b7 3107 return 1;
599f40db
JM
3108 }
3109 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3110 conf->fragm_threshold = atoi(pos);
95be79f1
MM
3111 if (conf->fragm_threshold == -1) {
3112 /* allow a value of -1 */
3113 } else if (conf->fragm_threshold < 256 ||
3114 conf->fragm_threshold > 2346) {
599f40db
JM
3115 wpa_printf(MSG_ERROR,
3116 "Line %d: invalid fragm_threshold %d",
3117 line, conf->fragm_threshold);
a0b728b7 3118 return 1;
599f40db
JM
3119 }
3120 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3121 int val = atoi(pos);
3122 if (val != 0 && val != 1) {
3123 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3124 line, val);
b4c26ef9
JM
3125 return 1;
3126 }
3127 conf->send_probe_response = val;
599f40db
JM
3128 } else if (os_strcmp(buf, "supported_rates") == 0) {
3129 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3130 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3131 line);
a0b728b7 3132 return 1;
599f40db
JM
3133 }
3134 } else if (os_strcmp(buf, "basic_rates") == 0) {
3135 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3136 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3137 line);
a0b728b7 3138 return 1;
599f40db 3139 }
29483a56
PK
3140 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3141 int val;
3142
3143 if (os_strncmp(pos, "ht:", 3) == 0) {
3144 val = atoi(pos + 3);
3145 if (val < 0 || val > 31) {
3146 wpa_printf(MSG_ERROR,
3147 "Line %d: invalid beacon_rate HT-MCS %d",
3148 line, val);
3149 return 1;
3150 }
3151 conf->rate_type = BEACON_RATE_HT;
3152 conf->beacon_rate = val;
3153 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3154 val = atoi(pos + 4);
3155 if (val < 0 || val > 9) {
3156 wpa_printf(MSG_ERROR,
3157 "Line %d: invalid beacon_rate VHT-MCS %d",
3158 line, val);
3159 return 1;
3160 }
3161 conf->rate_type = BEACON_RATE_VHT;
3162 conf->beacon_rate = val;
3163 } else {
3164 val = atoi(pos);
3165 if (val < 10 || val > 10000) {
3166 wpa_printf(MSG_ERROR,
3167 "Line %d: invalid legacy beacon_rate %d",
3168 line, val);
3169 return 1;
3170 }
3171 conf->rate_type = BEACON_RATE_LEGACY;
3172 conf->beacon_rate = val;
3173 }
599f40db
JM
3174 } else if (os_strcmp(buf, "preamble") == 0) {
3175 if (atoi(pos))
3176 conf->preamble = SHORT_PREAMBLE;
3177 else
3178 conf->preamble = LONG_PREAMBLE;
3179 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3180 bss->ignore_broadcast_ssid = atoi(pos);
9b7a1bd7
JM
3181 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3182 bss->no_probe_resp_if_max_sta = atoi(pos);
599f40db
JM
3183 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3184 bss->ssid.wep.idx = atoi(pos);
3185 if (bss->ssid.wep.idx > 3) {
3186 wpa_printf(MSG_ERROR,
3187 "Invalid wep_default_key index %d",
3188 bss->ssid.wep.idx);
a0b728b7 3189 return 1;
599f40db
JM
3190 }
3191 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3192 os_strcmp(buf, "wep_key1") == 0 ||
3193 os_strcmp(buf, "wep_key2") == 0 ||
3194 os_strcmp(buf, "wep_key3") == 0) {
3195 if (hostapd_config_read_wep(&bss->ssid.wep,
3196 buf[7] - '0', pos)) {
3197 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3198 line, buf);
a0b728b7 3199 return 1;
599f40db 3200 }
41d719d6 3201#ifndef CONFIG_NO_VLAN
599f40db
JM
3202 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3203 bss->ssid.dynamic_vlan = atoi(pos);
8be640b7
MB
3204 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3205 bss->ssid.per_sta_vif = atoi(pos);
599f40db
JM
3206 } else if (os_strcmp(buf, "vlan_file") == 0) {
3207 if (hostapd_config_read_vlan_file(bss, pos)) {
3208 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3209 line, pos);
a0b728b7 3210 return 1;
599f40db
JM
3211 }
3212 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3213 bss->ssid.vlan_naming = atoi(pos);
3214 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3215 bss->ssid.vlan_naming < 0) {
3216 wpa_printf(MSG_ERROR,
3217 "Line %d: invalid naming scheme %d",
3218 line, bss->ssid.vlan_naming);
a0b728b7 3219 return 1;
599f40db 3220 }
41d719d6 3221#ifdef CONFIG_FULL_DYNAMIC_VLAN
599f40db 3222 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
5784b9a4 3223 os_free(bss->ssid.vlan_tagged_interface);
599f40db 3224 bss->ssid.vlan_tagged_interface = os_strdup(pos);
41d719d6
JM
3225#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3226#endif /* CONFIG_NO_VLAN */
599f40db
JM
3227 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3228 conf->ap_table_max_size = atoi(pos);
3229 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3230 conf->ap_table_expiration_time = atoi(pos);
3231 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
3232 if (hostapd_config_tx_queue(conf, buf, pos)) {
3233 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3234 line);
a0b728b7 3235 return 1;
599f40db
JM
3236 }
3237 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3238 os_strcmp(buf, "wmm_enabled") == 0) {
3239 bss->wmm_enabled = atoi(pos);
3240 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3241 bss->wmm_uapsd = atoi(pos);
3242 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3243 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3244 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3245 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3246 line);
a0b728b7 3247 return 1;
599f40db
JM
3248 }
3249 } else if (os_strcmp(buf, "bss") == 0) {
3250 if (hostapd_config_bss(conf, pos)) {
3251 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3252 line);
a0b728b7 3253 return 1;
599f40db
JM
3254 }
3255 } else if (os_strcmp(buf, "bssid") == 0) {
3256 if (hwaddr_aton(pos, bss->bssid)) {
3257 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3258 line);
a0b728b7 3259 return 1;
599f40db 3260 }
6448e064
EP
3261 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3262 conf->use_driver_iface_addr = atoi(pos);
41d719d6 3263#ifdef CONFIG_IEEE80211W
599f40db
JM
3264 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3265 bss->ieee80211w = atoi(pos);
8dd9f9cd
JM
3266 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3267 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3268 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3269 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3270 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3271 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3272 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3273 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3274 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3275 } else {
3276 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3277 line, pos);
3278 return 1;
3279 }
599f40db
JM
3280 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3281 bss->assoc_sa_query_max_timeout = atoi(pos);
3282 if (bss->assoc_sa_query_max_timeout == 0) {
3283 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3284 line);
a0b728b7 3285 return 1;
599f40db
JM
3286 }
3287 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3288 bss->assoc_sa_query_retry_timeout = atoi(pos);
3289 if (bss->assoc_sa_query_retry_timeout == 0) {
3290 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3291 line);
a0b728b7 3292 return 1;
599f40db 3293 }
41d719d6
JM
3294#endif /* CONFIG_IEEE80211W */
3295#ifdef CONFIG_IEEE80211N
599f40db
JM
3296 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3297 conf->ieee80211n = atoi(pos);
3298 } else if (os_strcmp(buf, "ht_capab") == 0) {
3299 if (hostapd_config_ht_capab(conf, pos) < 0) {
3300 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3301 line);
a0b728b7 3302 return 1;
599f40db
JM
3303 }
3304 } else if (os_strcmp(buf, "require_ht") == 0) {
3305 conf->require_ht = atoi(pos);
3306 } else if (os_strcmp(buf, "obss_interval") == 0) {
3307 conf->obss_interval = atoi(pos);
41d719d6 3308#endif /* CONFIG_IEEE80211N */
efe45d14 3309#ifdef CONFIG_IEEE80211AC
599f40db
JM
3310 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3311 conf->ieee80211ac = atoi(pos);
3312 } else if (os_strcmp(buf, "vht_capab") == 0) {
3313 if (hostapd_config_vht_capab(conf, pos) < 0) {
3314 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3315 line);
a0b728b7 3316 return 1;
599f40db
JM
3317 }
3318 } else if (os_strcmp(buf, "require_vht") == 0) {
3319 conf->require_vht = atoi(pos);
3320 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3321 conf->vht_oper_chwidth = atoi(pos);
3322 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3323 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3324 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3325 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
e7d0e97b
YL
3326 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3327 bss->vendor_vht = atoi(pos);
fc72a48a
T
3328 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3329 bss->use_sta_nsts = atoi(pos);
efe45d14 3330#endif /* CONFIG_IEEE80211AC */
94380cb4
PX
3331#ifdef CONFIG_IEEE80211AX
3332 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3333 conf->ieee80211ax = atoi(pos);
3334 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3335 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3336 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3337 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3338 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3339 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3340 } else if (os_strcmp(buf, "he_bss_color") == 0) {
3341 conf->he_op.he_bss_color = atoi(pos);
3342 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3343 conf->he_op.he_default_pe_duration = atoi(pos);
3344 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3345 conf->he_op.he_twt_required = atoi(pos);
3346 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3347 conf->he_op.he_rts_threshold = atoi(pos);
3348#endif /* CONFIG_IEEE80211AX */
599f40db
JM
3349 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3350 bss->max_listen_interval = atoi(pos);
3351 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3352 bss->disable_pmksa_caching = atoi(pos);
3353 } else if (os_strcmp(buf, "okc") == 0) {
3354 bss->okc = atoi(pos);
41d719d6 3355#ifdef CONFIG_WPS
599f40db
JM
3356 } else if (os_strcmp(buf, "wps_state") == 0) {
3357 bss->wps_state = atoi(pos);
3358 if (bss->wps_state < 0 || bss->wps_state > 2) {
3359 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3360 line);
a0b728b7 3361 return 1;
599f40db
JM
3362 }
3363 } else if (os_strcmp(buf, "wps_independent") == 0) {
3364 bss->wps_independent = atoi(pos);
3365 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3366 bss->ap_setup_locked = atoi(pos);
3367 } else if (os_strcmp(buf, "uuid") == 0) {
3368 if (uuid_str2bin(pos, bss->uuid)) {
3369 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
a0b728b7 3370 return 1;
599f40db
JM
3371 }
3372 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3373 os_free(bss->wps_pin_requests);
3374 bss->wps_pin_requests = os_strdup(pos);
3375 } else if (os_strcmp(buf, "device_name") == 0) {
cc6f2438 3376 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
599f40db
JM
3377 wpa_printf(MSG_ERROR, "Line %d: Too long "
3378 "device_name", line);
a0b728b7 3379 return 1;
599f40db
JM
3380 }
3381 os_free(bss->device_name);
3382 bss->device_name = os_strdup(pos);
3383 } else if (os_strcmp(buf, "manufacturer") == 0) {
3384 if (os_strlen(pos) > 64) {
3385 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3386 line);
a0b728b7 3387 return 1;
599f40db
JM
3388 }
3389 os_free(bss->manufacturer);
3390 bss->manufacturer = os_strdup(pos);
3391 } else if (os_strcmp(buf, "model_name") == 0) {
3392 if (os_strlen(pos) > 32) {
3393 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3394 line);
a0b728b7 3395 return 1;
599f40db
JM
3396 }
3397 os_free(bss->model_name);
3398 bss->model_name = os_strdup(pos);
3399 } else if (os_strcmp(buf, "model_number") == 0) {
3400 if (os_strlen(pos) > 32) {
3401 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3402 line);
a0b728b7 3403 return 1;
599f40db
JM
3404 }
3405 os_free(bss->model_number);
3406 bss->model_number = os_strdup(pos);
3407 } else if (os_strcmp(buf, "serial_number") == 0) {
3408 if (os_strlen(pos) > 32) {
3409 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3410 line);
a0b728b7 3411 return 1;
599f40db
JM
3412 }
3413 os_free(bss->serial_number);
3414 bss->serial_number = os_strdup(pos);
3415 } else if (os_strcmp(buf, "device_type") == 0) {
3416 if (wps_dev_type_str2bin(pos, bss->device_type))
a0b728b7 3417 return 1;
599f40db
JM
3418 } else if (os_strcmp(buf, "config_methods") == 0) {
3419 os_free(bss->config_methods);
3420 bss->config_methods = os_strdup(pos);
3421 } else if (os_strcmp(buf, "os_version") == 0) {
3422 if (hexstr2bin(pos, bss->os_version, 4)) {
3423 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3424 line);
a0b728b7 3425 return 1;
599f40db
JM
3426 }
3427 } else if (os_strcmp(buf, "ap_pin") == 0) {
3428 os_free(bss->ap_pin);
ae048257
JM
3429 if (*pos == '\0')
3430 bss->ap_pin = NULL;
3431 else
3432 bss->ap_pin = os_strdup(pos);
599f40db
JM
3433 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3434 bss->skip_cred_build = atoi(pos);
3435 } else if (os_strcmp(buf, "extra_cred") == 0) {
3436 os_free(bss->extra_cred);
3437 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3438 if (bss->extra_cred == NULL) {
3439 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3440 line, pos);
a0b728b7 3441 return 1;
599f40db
JM
3442 }
3443 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3444 bss->wps_cred_processing = atoi(pos);
3445 } else if (os_strcmp(buf, "ap_settings") == 0) {
3446 os_free(bss->ap_settings);
3447 bss->ap_settings =
3448 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3449 if (bss->ap_settings == NULL) {
3450 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3451 line, pos);
a0b728b7 3452 return 1;
599f40db
JM
3453 }
3454 } else if (os_strcmp(buf, "upnp_iface") == 0) {
5784b9a4 3455 os_free(bss->upnp_iface);
599f40db
JM
3456 bss->upnp_iface = os_strdup(pos);
3457 } else if (os_strcmp(buf, "friendly_name") == 0) {
3458 os_free(bss->friendly_name);
3459 bss->friendly_name = os_strdup(pos);
3460 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3461 os_free(bss->manufacturer_url);
3462 bss->manufacturer_url = os_strdup(pos);
3463 } else if (os_strcmp(buf, "model_description") == 0) {
3464 os_free(bss->model_description);
3465 bss->model_description = os_strdup(pos);
3466 } else if (os_strcmp(buf, "model_url") == 0) {
3467 os_free(bss->model_url);
3468 bss->model_url = os_strdup(pos);
3469 } else if (os_strcmp(buf, "upc") == 0) {
3470 os_free(bss->upc);
3471 bss->upc = os_strdup(pos);
3472 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3473 bss->pbc_in_m1 = atoi(pos);
3474 } else if (os_strcmp(buf, "server_id") == 0) {
3475 os_free(bss->server_id);
3476 bss->server_id = os_strdup(pos);
ffdaa05a 3477#ifdef CONFIG_WPS_NFC
599f40db
JM
3478 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3479 bss->wps_nfc_dev_pw_id = atoi(pos);
3480 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3481 bss->wps_nfc_dev_pw_id > 0xffff) {
3482 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3483 line);
a0b728b7 3484 return 1;
599f40db
JM
3485 }
3486 bss->wps_nfc_pw_from_config = 1;
3487 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3488 wpabuf_free(bss->wps_nfc_dh_pubkey);
9d955f75 3489 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
599f40db
JM
3490 bss->wps_nfc_pw_from_config = 1;
3491 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3492 wpabuf_free(bss->wps_nfc_dh_privkey);
9d955f75 3493 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
599f40db
JM
3494 bss->wps_nfc_pw_from_config = 1;
3495 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3496 wpabuf_free(bss->wps_nfc_dev_pw);
9d955f75 3497 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
599f40db 3498 bss->wps_nfc_pw_from_config = 1;
ffdaa05a 3499#endif /* CONFIG_WPS_NFC */
41d719d6 3500#endif /* CONFIG_WPS */
962473c1 3501#ifdef CONFIG_P2P_MANAGER
599f40db 3502 } else if (os_strcmp(buf, "manage_p2p") == 0) {
b4c26ef9 3503 if (atoi(pos))
599f40db
JM
3504 bss->p2p |= P2P_MANAGE;
3505 else
3506 bss->p2p &= ~P2P_MANAGE;
3507 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3508 if (atoi(pos))
3509 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3510 else
3511 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
962473c1 3512#endif /* CONFIG_P2P_MANAGER */
599f40db
JM
3513 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3514 bss->disassoc_low_ack = atoi(pos);
3515 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
b4c26ef9 3516 if (atoi(pos))
599f40db
JM
3517 bss->tdls |= TDLS_PROHIBIT;
3518 else
3519 bss->tdls &= ~TDLS_PROHIBIT;
3520 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
b4c26ef9 3521 if (atoi(pos))
599f40db
JM
3522 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3523 else
3524 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
cd9fc786 3525#ifdef CONFIG_RSN_TESTING
599f40db
JM
3526 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3527 extern int rsn_testing;
3528 rsn_testing = atoi(pos);
cd9fc786 3529#endif /* CONFIG_RSN_TESTING */
599f40db
JM
3530 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3531 bss->time_advertisement = atoi(pos);
3532 } else if (os_strcmp(buf, "time_zone") == 0) {
3533 size_t tz_len = os_strlen(pos);
3534 if (tz_len < 4 || tz_len > 255) {
3535 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3536 line);
a0b728b7 3537 return 1;
599f40db
JM
3538 }
3539 os_free(bss->time_zone);
3540 bss->time_zone = os_strdup(pos);
3541 if (bss->time_zone == NULL)
a0b728b7 3542 return 1;
b5bf84ba 3543#ifdef CONFIG_WNM_AP
599f40db
JM
3544 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3545 bss->wnm_sleep_mode = atoi(pos);
348c9384
JM
3546 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3547 bss->wnm_sleep_mode_no_keys = atoi(pos);
599f40db
JM
3548 } else if (os_strcmp(buf, "bss_transition") == 0) {
3549 bss->bss_transition = atoi(pos);
b5bf84ba 3550#endif /* CONFIG_WNM_AP */
b83e3e93 3551#ifdef CONFIG_INTERWORKING
599f40db
JM
3552 } else if (os_strcmp(buf, "interworking") == 0) {
3553 bss->interworking = atoi(pos);
3554 } else if (os_strcmp(buf, "access_network_type") == 0) {
3555 bss->access_network_type = atoi(pos);
3556 if (bss->access_network_type < 0 ||
3557 bss->access_network_type > 15) {
3558 wpa_printf(MSG_ERROR,
3559 "Line %d: invalid access_network_type",
3560 line);
a0b728b7 3561 return 1;
599f40db
JM
3562 }
3563 } else if (os_strcmp(buf, "internet") == 0) {
3564 bss->internet = atoi(pos);
3565 } else if (os_strcmp(buf, "asra") == 0) {
3566 bss->asra = atoi(pos);
3567 } else if (os_strcmp(buf, "esr") == 0) {
3568 bss->esr = atoi(pos);
3569 } else if (os_strcmp(buf, "uesa") == 0) {
3570 bss->uesa = atoi(pos);
3571 } else if (os_strcmp(buf, "venue_group") == 0) {
3572 bss->venue_group = atoi(pos);
3573 bss->venue_info_set = 1;
3574 } else if (os_strcmp(buf, "venue_type") == 0) {
3575 bss->venue_type = atoi(pos);
3576 bss->venue_info_set = 1;
3577 } else if (os_strcmp(buf, "hessid") == 0) {
3578 if (hwaddr_aton(pos, bss->hessid)) {
3579 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
a0b728b7 3580 return 1;
599f40db
JM
3581 }
3582 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3583 if (parse_roaming_consortium(bss, pos, line) < 0)
a0b728b7 3584 return 1;
599f40db
JM
3585 } else if (os_strcmp(buf, "venue_name") == 0) {
3586 if (parse_venue_name(bss, pos, line) < 0)
a0b728b7 3587 return 1;
7e1d3ee9
JM
3588 } else if (os_strcmp(buf, "venue_url") == 0) {
3589 if (parse_venue_url(bss, pos, line) < 0)
3590 return 1;
599f40db
JM
3591 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3592 u8 auth_type;
3593 u16 redirect_url_len;
3594 if (hexstr2bin(pos, &auth_type, 1)) {
3595 wpa_printf(MSG_ERROR,
3596 "Line %d: Invalid network_auth_type '%s'",
3597 line, pos);
a0b728b7 3598 return 1;
599f40db
JM
3599 }
3600 if (auth_type == 0 || auth_type == 2)
3601 redirect_url_len = os_strlen(pos + 2);
3602 else
3603 redirect_url_len = 0;
3604 os_free(bss->network_auth_type);
3605 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
a0b728b7
JM
3606 if (bss->network_auth_type == NULL)
3607 return 1;
599f40db
JM
3608 *bss->network_auth_type = auth_type;
3609 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3610 if (redirect_url_len)
3611 os_memcpy(bss->network_auth_type + 3, pos + 2,
3612 redirect_url_len);
3613 bss->network_auth_type_len = 3 + redirect_url_len;
3614 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3615 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3616 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3617 line, pos);
3618 bss->ipaddr_type_configured = 0;
a0b728b7 3619 return 1;
599f40db
JM
3620 }
3621 bss->ipaddr_type_configured = 1;
b4c26ef9 3622 } else if (os_strcmp(buf, "domain_name") == 0) {
599f40db
JM
3623 int j, num_domains, domain_len, domain_list_len = 0;
3624 char *tok_start, *tok_prev;
3625 u8 *domain_list, *domain_ptr;
26fac8b6 3626
599f40db
JM
3627 domain_list_len = os_strlen(pos) + 1;
3628 domain_list = os_malloc(domain_list_len);
a0b728b7
JM
3629 if (domain_list == NULL)
3630 return 1;
26fac8b6 3631
599f40db
JM
3632 domain_ptr = domain_list;
3633 tok_prev = pos;
3634 num_domains = 1;
3635 while ((tok_prev = os_strchr(tok_prev, ','))) {
3636 num_domains++;
3637 tok_prev++;
3638 }
3639 tok_prev = pos;
3640 for (j = 0; j < num_domains; j++) {
3641 tok_start = os_strchr(tok_prev, ',');
3642 if (tok_start) {
3643 domain_len = tok_start - tok_prev;
3644 *domain_ptr = domain_len;
3645 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3646 domain_ptr += domain_len + 1;
3647 tok_prev = ++tok_start;
3648 } else {
3649 domain_len = os_strlen(tok_prev);
3650 *domain_ptr = domain_len;
3651 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3652 domain_ptr += domain_len + 1;
26fac8b6 3653 }
599f40db 3654 }
26fac8b6 3655
599f40db
JM
3656 os_free(bss->domain_name);
3657 bss->domain_name = domain_list;
3658 bss->domain_name_len = domain_list_len;
3659 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3660 if (parse_3gpp_cell_net(bss, pos, line) < 0)
a0b728b7 3661 return 1;
599f40db
JM
3662 } else if (os_strcmp(buf, "nai_realm") == 0) {
3663 if (parse_nai_realm(bss, pos, line) < 0)
a0b728b7 3664 return 1;
695dbbea
JM
3665 } else if (os_strcmp(buf, "anqp_elem") == 0) {
3666 if (parse_anqp_elem(bss, pos, line) < 0)
3667 return 1;
599f40db 3668 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
2977f519
JM
3669 int val = atoi(pos);
3670
3671 if (val <= 0) {
3672 wpa_printf(MSG_ERROR,
3673 "Line %d: Invalid gas_frag_limit '%s'",
3674 line, pos);
3675 return 1;
3676 }
3677 bss->gas_frag_limit = val;
599f40db
JM
3678 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3679 bss->gas_comeback_delay = atoi(pos);
3680 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3681 if (parse_qos_map_set(bss, pos, line) < 0)
a0b728b7 3682 return 1;
b83e3e93 3683#endif /* CONFIG_INTERWORKING */
505a3694 3684#ifdef CONFIG_RADIUS_TEST
599f40db
JM
3685 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3686 os_free(bss->dump_msk_file);
3687 bss->dump_msk_file = os_strdup(pos);
505a3694 3688#endif /* CONFIG_RADIUS_TEST */
7b991b47
MW
3689#ifdef CONFIG_PROXYARP
3690 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3691 bss->proxy_arp = atoi(pos);
3692#endif /* CONFIG_PROXYARP */
159c89ab 3693#ifdef CONFIG_HS20
599f40db
JM
3694 } else if (os_strcmp(buf, "hs20") == 0) {
3695 bss->hs20 = atoi(pos);
3696 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3697 bss->disable_dgaf = atoi(pos);
4a7ce984
JM
3698 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
3699 bss->na_mcast_to_ucast = atoi(pos);
599f40db
JM
3700 } else if (os_strcmp(buf, "osen") == 0) {
3701 bss->osen = atoi(pos);
3702 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3703 bss->anqp_domain_id = atoi(pos);
3704 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3705 bss->hs20_deauth_req_timeout = atoi(pos);
3706 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3707 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
a0b728b7 3708 return 1;
599f40db 3709 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
a0b728b7
JM
3710 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3711 return 1;
599f40db
JM
3712 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3713 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
a0b728b7 3714 return 1;
599f40db
JM
3715 }
3716 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3717 u8 *oper_class;
3718 size_t oper_class_len;
3719 oper_class_len = os_strlen(pos);
3720 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3721 wpa_printf(MSG_ERROR,
3722 "Line %d: Invalid hs20_operating_class '%s'",
3723 line, pos);
a0b728b7 3724 return 1;
599f40db
JM
3725 }
3726 oper_class_len /= 2;
3727 oper_class = os_malloc(oper_class_len);
a0b728b7
JM
3728 if (oper_class == NULL)
3729 return 1;
599f40db
JM
3730 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3731 wpa_printf(MSG_ERROR,
3732 "Line %d: Invalid hs20_operating_class '%s'",
3733 line, pos);
3734 os_free(oper_class);
a0b728b7 3735 return 1;
599f40db
JM
3736 }
3737 os_free(bss->hs20_operating_class);
3738 bss->hs20_operating_class = oper_class;
3739 bss->hs20_operating_class_len = oper_class_len;
3740 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3741 if (hs20_parse_icon(bss, pos) < 0) {
3742 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3743 line, pos);
a0b728b7 3744 return 1;
599f40db
JM
3745 }
3746 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3747 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
a0b728b7 3748 return 1;
599f40db
JM
3749 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3750 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
a0b728b7 3751 return 1;
599f40db
JM
3752 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3753 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
a0b728b7 3754 return 1;
599f40db
JM
3755 } else if (os_strcmp(buf, "osu_nai") == 0) {
3756 if (hs20_parse_osu_nai(bss, pos, line) < 0)
a0b728b7 3757 return 1;
599f40db
JM
3758 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3759 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
a0b728b7 3760 return 1;
599f40db
JM
3761 } else if (os_strcmp(buf, "osu_icon") == 0) {
3762 if (hs20_parse_osu_icon(bss, pos, line) < 0)
a0b728b7 3763 return 1;
599f40db
JM
3764 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3765 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
a0b728b7 3766 return 1;
0e450db2
JM
3767 } else if (os_strcmp(buf, "operator_icon") == 0) {
3768 if (hs20_parse_operator_icon(bss, pos, line) < 0)
3769 return 1;
599f40db
JM
3770 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3771 os_free(bss->subscr_remediation_url);
3772 bss->subscr_remediation_url = os_strdup(pos);
3773 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3774 bss->subscr_remediation_method = atoi(pos);
6cb8f4f3
JM
3775 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
3776 os_free(bss->t_c_filename);
3777 bss->t_c_filename = os_strdup(pos);
3778 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
3779 bss->t_c_timestamp = strtol(pos, NULL, 0);
8760b984
JM
3780 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
3781 os_free(bss->t_c_server_url);
3782 bss->t_c_server_url = os_strdup(pos);
159c89ab 3783#endif /* CONFIG_HS20 */
fb9a1c3e
AS
3784#ifdef CONFIG_MBO
3785 } else if (os_strcmp(buf, "mbo") == 0) {
3786 bss->mbo_enabled = atoi(pos);
941caed9
JM
3787 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
3788 bss->mbo_cell_data_conn_pref = atoi(pos);
65833d71
AP
3789 } else if (os_strcmp(buf, "oce") == 0) {
3790 bss->oce = atoi(pos);
fb9a1c3e 3791#endif /* CONFIG_MBO */
c2aff6b1 3792#ifdef CONFIG_TESTING_OPTIONS
599f40db
JM
3793#define PARSE_TEST_PROBABILITY(_val) \
3794 } else if (os_strcmp(buf, #_val) == 0) { \
3795 char *end; \
3796 \
3797 conf->_val = strtod(pos, &end); \
06df2aa6
JM
3798 if (*end || conf->_val < 0.0 || \
3799 conf->_val > 1.0) { \
599f40db
JM
3800 wpa_printf(MSG_ERROR, \
3801 "Line %d: Invalid value '%s'", \
3802 line, pos); \
a0b728b7 3803 return 1; \
599f40db
JM
3804 }
3805 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3806 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3807 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3808 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3809 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
2b6e1216
JB
3810 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
3811 conf->ecsa_ie_only = atoi(pos);
599f40db
JM
3812 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3813 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3814 pos = os_strchr(pos, ':');
3815 if (pos == NULL) {
3816 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3817 line);
3818 return 1;
3819 }
3820 pos++;
3821 bss->bss_load_test[2] = atoi(pos);
3822 pos = os_strchr(pos, ':');
3823 if (pos == NULL) {
3824 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3825 line);
3826 return 1;
3827 }
3828 pos++;
3829 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3830 bss->bss_load_test_set = 1;
0629eeb4 3831 } else if (os_strcmp(buf, "radio_measurements") == 0) {
01018212
DS
3832 /*
3833 * DEPRECATED: This parameter will be removed in the future.
3834 * Use rrm_neighbor_report instead.
3835 */
3836 int val = atoi(pos);
3837
3838 if (val & BIT(0))
3839 bss->radio_measurements[0] |=
3840 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
bc02843e
JM
3841 } else if (os_strcmp(buf, "own_ie_override") == 0) {
3842 struct wpabuf *tmp;
3843 size_t len = os_strlen(pos) / 2;
3844
3845 tmp = wpabuf_alloc(len);
3846 if (!tmp)
3847 return 1;
3848
3849 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
3850 wpabuf_free(tmp);
3851 wpa_printf(MSG_ERROR,
3852 "Line %d: Invalid own_ie_override '%s'",
3853 line, pos);
3854 return 1;
3855 }
3856
3857 wpabuf_free(bss->own_ie_override);
3858 bss->own_ie_override = tmp;
e7533538
JM
3859 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
3860 bss->sae_reflection_attack = atoi(pos);
3648d8a1
JM
3861 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
3862 wpabuf_free(bss->sae_commit_override);
3863 bss->sae_commit_override = wpabuf_parse_bin(pos);
9be19d0b 3864#ifdef CONFIG_SAE
2377c1ca 3865 } else if (os_strcmp(buf, "sae_password") == 0) {
9be19d0b
JM
3866 if (parse_sae_password(bss, pos) < 0) {
3867 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
3868 line);
3869 return 1;
3870 }
3871#endif /* CONFIG_SAE */
c2aff6b1 3872#endif /* CONFIG_TESTING_OPTIONS */
599f40db 3873 } else if (os_strcmp(buf, "vendor_elements") == 0) {
4ac33989 3874 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
599f40db 3875 return 1;
a9112270 3876 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4ac33989 3877 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
a9112270 3878 return 1;
599f40db
JM
3879 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3880 bss->sae_anti_clogging_threshold = atoi(pos);
d8b841eb
JM
3881 } else if (os_strcmp(buf, "sae_sync") == 0) {
3882 bss->sae_sync = atoi(pos);
599f40db
JM
3883 } else if (os_strcmp(buf, "sae_groups") == 0) {
3884 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3885 wpa_printf(MSG_ERROR,
3886 "Line %d: Invalid sae_groups value '%s'",
3887 line, pos);
3888 return 1;
41d719d6 3889 }
ba3d435f
JM
3890 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
3891 bss->sae_require_mfp = atoi(pos);
599f40db
JM
3892 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3893 int val = atoi(pos);
3894 if (val < 0 || val > 255) {
3895 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3896 line, val);
3897 return 1;
3898 }
3899 conf->local_pwr_constraint = val;
3900 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3901 conf->spectrum_mgmt_required = atoi(pos);
88cb27c7
DS
3902 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3903 os_free(bss->wowlan_triggers);
3904 bss->wowlan_triggers = os_strdup(pos);
104bef45
AN
3905#ifdef CONFIG_FST
3906 } else if (os_strcmp(buf, "fst_group_id") == 0) {
3907 size_t len = os_strlen(pos);
3908
3909 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
3910 wpa_printf(MSG_ERROR,
3911 "Line %d: Invalid fst_group_id value '%s'",
3912 line, pos);
3913 return 1;
3914 }
3915
3916 if (conf->fst_cfg.group_id[0]) {
3917 wpa_printf(MSG_ERROR,
3918 "Line %d: Duplicate fst_group value '%s'",
3919 line, pos);
3920 return 1;
3921 }
3922
3923 os_strlcpy(conf->fst_cfg.group_id, pos,
3924 sizeof(conf->fst_cfg.group_id));
3925 } else if (os_strcmp(buf, "fst_priority") == 0) {
3926 char *endp;
3927 long int val;
3928
3929 if (!*pos) {
3930 wpa_printf(MSG_ERROR,
3931 "Line %d: fst_priority value not supplied (expected 1..%u)",
3932 line, FST_MAX_PRIO_VALUE);
3933 return -1;
3934 }
3935
3936 val = strtol(pos, &endp, 0);
3937 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
3938 wpa_printf(MSG_ERROR,
3939 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
3940 line, val, pos, FST_MAX_PRIO_VALUE);
3941 return 1;
3942 }
3943 conf->fst_cfg.priority = (u8) val;
3944 } else if (os_strcmp(buf, "fst_llt") == 0) {
3945 char *endp;
3946 long int val;
3947
3948 if (!*pos) {
3949 wpa_printf(MSG_ERROR,
3950 "Line %d: fst_llt value not supplied (expected 1..%u)",
3951 line, FST_MAX_LLT_MS);
3952 return -1;
3953 }
3954 val = strtol(pos, &endp, 0);
24bce46e
JM
3955 if (*endp || val < 1 ||
3956 (unsigned long int) val > FST_MAX_LLT_MS) {
104bef45
AN
3957 wpa_printf(MSG_ERROR,
3958 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
3959 line, val, pos, FST_MAX_LLT_MS);
3960 return 1;
3961 }
3962 conf->fst_cfg.llt = (u32) val;
3963#endif /* CONFIG_FST */
a65a9b8d
JM
3964 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
3965 conf->track_sta_max_num = atoi(pos);
3966 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
3967 conf->track_sta_max_age = atoi(pos);
964f64e2
JM
3968 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
3969 os_free(bss->no_probe_resp_if_seen_on);
3970 bss->no_probe_resp_if_seen_on = os_strdup(pos);
0e2412d0
JM
3971 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
3972 os_free(bss->no_auth_if_seen_on);
3973 bss->no_auth_if_seen_on = os_strdup(pos);
74e982d8
DS
3974 } else if (os_strcmp(buf, "lci") == 0) {
3975 wpabuf_free(conf->lci);
9d955f75 3976 conf->lci = wpabuf_parse_bin(pos);
5cb59370
IP
3977 if (conf->lci && wpabuf_len(conf->lci) == 0) {
3978 wpabuf_free(conf->lci);
3979 conf->lci = NULL;
3980 }
74e982d8
DS
3981 } else if (os_strcmp(buf, "civic") == 0) {
3982 wpabuf_free(conf->civic);
9d955f75 3983 conf->civic = wpabuf_parse_bin(pos);
5cb59370
IP
3984 if (conf->civic && wpabuf_len(conf->civic) == 0) {
3985 wpabuf_free(conf->civic);
3986 conf->civic = NULL;
3987 }
01018212
DS
3988 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
3989 if (atoi(pos))
3990 bss->radio_measurements[0] |=
3991 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
73a27a63
JM
3992 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
3993 if (atoi(pos))
3994 bss->radio_measurements[0] |=
3995 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
3996 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
3997 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
83594725
JM
3998 } else if (os_strcmp(buf, "gas_address3") == 0) {
3999 bss->gas_address3 = atoi(pos);
451a27b1
DS
4000 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4001 conf->stationary_ap = atoi(pos);
faecb392
LD
4002 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4003 bss->ftm_responder = atoi(pos);
4004 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4005 bss->ftm_initiator = atoi(pos);
903ecbe8
JM
4006#ifdef CONFIG_FILS
4007 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4008 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4009 wpa_printf(MSG_ERROR,
4010 "Line %d: Invalid fils_cache_id '%s'",
4011 line, pos);
4012 return 1;
4013 }
4014 bss->fils_cache_id_set = 1;
26bf70e3
JM
4015 } else if (os_strcmp(buf, "fils_realm") == 0) {
4016 if (parse_fils_realm(bss, pos) < 0)
4017 return 1;
1764559e
JM
4018 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4019 bss->fils_dh_group = atoi(pos);
91d91abf
JM
4020 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4021 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4022 wpa_printf(MSG_ERROR,
4023 "Line %d: invalid IP address '%s'",
4024 line, pos);
4025 return 1;
4026 }
4027 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4028 bss->dhcp_rapid_commit_proxy = atoi(pos);
4029 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4030 bss->fils_hlp_wait_time = atoi(pos);
4031 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4032 bss->dhcp_server_port = atoi(pos);
4033 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4034 bss->dhcp_relay_port = atoi(pos);
903ecbe8 4035#endif /* CONFIG_FILS */
34f7c699
MB
4036 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4037 bss->multicast_to_unicast = atoi(pos);
57a2aaca
JM
4038 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4039 bss->broadcast_deauth = atoi(pos);
56c75495
JM
4040#ifdef CONFIG_DPP
4041 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4042 os_free(bss->dpp_connector);
4043 bss->dpp_connector = os_strdup(pos);
4044 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4045 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4046 return 1;
4047 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4048 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4049 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4050 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4051 return 1;
56c75495 4052#endif /* CONFIG_DPP */
ea079153
JM
4053#ifdef CONFIG_OWE
4054 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4055 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4056 wpa_printf(MSG_ERROR,
4057 "Line %d: invalid owe_transition_bssid",
4058 line);
4059 return 1;
4060 }
4061 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4062 size_t slen;
4063 char *str = wpa_config_parse_string(pos, &slen);
4064
4065 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4066 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4067 line, pos);
4068 os_free(str);
4069 return 1;
4070 }
4071 os_memcpy(bss->owe_transition_ssid, str, slen);
4072 bss->owe_transition_ssid_len = slen;
4073 os_free(str);
a8913881
JM
4074 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4075 os_strlcpy(bss->owe_transition_ifname, pos,
4076 sizeof(bss->owe_transition_ifname));
91cc34bf
JM
4077 } else if (os_strcmp(buf, "owe_groups") == 0) {
4078 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4079 wpa_printf(MSG_ERROR,
4080 "Line %d: Invalid owe_groups value '%s'",
4081 line, pos);
4082 return 1;
4083 }
ea079153 4084#endif /* CONFIG_OWE */
599f40db
JM
4085 } else {
4086 wpa_printf(MSG_ERROR,
4087 "Line %d: unknown configuration item '%s'",
4088 line, buf);
a0b728b7 4089 return 1;
41d719d6
JM
4090 }
4091
a0b728b7 4092 return 0;
ef45bc89
SP
4093}
4094
4095
4096/**
4097 * hostapd_config_read - Read and parse a configuration file
4098 * @fname: Configuration file name (including path, if needed)
4099 * Returns: Allocated configuration data structure
4100 */
4101struct hostapd_config * hostapd_config_read(const char *fname)
4102{
4103 struct hostapd_config *conf;
ef45bc89 4104 FILE *f;
ef50e410 4105 char buf[4096], *pos;
ef45bc89
SP
4106 int line = 0;
4107 int errors = 0;
ef45bc89
SP
4108 size_t i;
4109
4110 f = fopen(fname, "r");
4111 if (f == NULL) {
4112 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4113 "for reading.", fname);
4114 return NULL;
4115 }
4116
4117 conf = hostapd_config_defaults();
4118 if (conf == NULL) {
4119 fclose(f);
4120 return NULL;
4121 }
4122
4123 /* set default driver based on configuration */
4124 conf->driver = wpa_drivers[0];
4125 if (conf->driver == NULL) {
4126 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4127 hostapd_config_free(conf);
4128 fclose(f);
4129 return NULL;
4130 }
4131
df756b37 4132 conf->last_bss = conf->bss[0];
ef45bc89
SP
4133
4134 while (fgets(buf, sizeof(buf), f)) {
df756b37
JM
4135 struct hostapd_bss_config *bss;
4136
ef45bc89
SP
4137 bss = conf->last_bss;
4138 line++;
4139
4140 if (buf[0] == '#')
4141 continue;
4142 pos = buf;
4143 while (*pos != '\0') {
4144 if (*pos == '\n') {
4145 *pos = '\0';
4146 break;
4147 }
4148 pos++;
4149 }
4150 if (buf[0] == '\0')
4151 continue;
4152
4153 pos = os_strchr(buf, '=');
4154 if (pos == NULL) {
4155 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4156 line, buf);
4157 errors++;
4158 continue;
4159 }
4160 *pos = '\0';
4161 pos++;
4162 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4163 }
4164
41d719d6
JM
4165 fclose(f);
4166
a7f5b74d 4167 for (i = 0; i < conf->num_bss; i++)
5d67bf15 4168 hostapd_set_security_params(conf->bss[i], 1);
41d719d6 4169
08081ad8 4170 if (hostapd_config_check(conf, 1))
41d719d6
JM
4171 errors++;
4172
ae6e1bee 4173#ifndef WPA_IGNORE_CONFIG_ERRORS
41d719d6
JM
4174 if (errors) {
4175 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4176 "'%s'", errors, fname);
4177 hostapd_config_free(conf);
4178 conf = NULL;
4179 }
ae6e1bee 4180#endif /* WPA_IGNORE_CONFIG_ERRORS */
41d719d6
JM
4181
4182 return conf;
4183}
31b79e11
SP
4184
4185
4186int hostapd_set_iface(struct hostapd_config *conf,
63e169e1
JM
4187 struct hostapd_bss_config *bss, const char *field,
4188 char *value)
31b79e11 4189{
4929898d 4190 int errors;
31b79e11
SP
4191 size_t i;
4192
4193 errors = hostapd_config_fill(conf, bss, field, value, 0);
4194 if (errors) {
4195 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4196 "to value '%s'", field, value);
4197 return -1;
4198 }
4199
4200 for (i = 0; i < conf->num_bss; i++)
5d67bf15 4201 hostapd_set_security_params(conf->bss[i], 0);
31b79e11 4202
08081ad8 4203 if (hostapd_config_check(conf, 0)) {
31b79e11 4204 wpa_printf(MSG_ERROR, "Configuration check failed");
17706d1c 4205 return -1;
31b79e11
SP
4206 }
4207
4208 return 0;
4209}