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