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