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