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