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