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