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