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