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