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