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