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