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