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