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