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