blob: 9470cae86f8b57ef42d096ea0c3d8c8a08b62c3f [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003 * Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
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"
Hai Shaloma20dcd72022-02-04 13:43:00 -080016#include "utils/crc32.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "common/ieee802_11_defs.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070018#include "common/sae.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070019#include "crypto/sha256.h"
20#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#ifndef CONFIG_NO_VLAN
30static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
31 const char *fname)
32{
33 FILE *f;
Hai Shalom74f70d42019-02-11 14:42:39 -080034 char buf[128], *pos, *pos2, *pos3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035 int line = 0, vlan_id;
36 struct hostapd_vlan *vlan;
37
38 f = fopen(fname, "r");
39 if (!f) {
40 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
41 return -1;
42 }
43
44 while (fgets(buf, sizeof(buf), f)) {
45 line++;
46
47 if (buf[0] == '#')
48 continue;
49 pos = buf;
50 while (*pos != '\0') {
51 if (*pos == '\n') {
52 *pos = '\0';
53 break;
54 }
55 pos++;
56 }
57 if (buf[0] == '\0')
58 continue;
59
60 if (buf[0] == '*') {
61 vlan_id = VLAN_ID_WILDCARD;
62 pos = buf + 1;
63 } else {
64 vlan_id = strtol(buf, &pos, 10);
65 if (buf == pos || vlan_id < 1 ||
66 vlan_id > MAX_VLAN_ID) {
67 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
68 "line %d in '%s'", line, fname);
69 fclose(f);
70 return -1;
71 }
72 }
73
74 while (*pos == ' ' || *pos == '\t')
75 pos++;
76 pos2 = pos;
77 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
78 pos2++;
Hai Shalom74f70d42019-02-11 14:42:39 -080079
80 if (*pos2 != '\0')
81 *(pos2++) = '\0';
82
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
84 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
85 "in '%s'", line, fname);
86 fclose(f);
87 return -1;
88 }
89
Hai Shalom74f70d42019-02-11 14:42:39 -080090 while (*pos2 == ' ' || *pos2 == '\t')
91 pos2++;
92 pos3 = pos2;
93 while (*pos3 != ' ' && *pos3 != '\t' && *pos3 != '\0')
94 pos3++;
95 *pos3 = '\0';
96
Dmitry Shmidt4b060592013-04-29 16:42:49 -070097 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098 if (vlan == NULL) {
99 wpa_printf(MSG_ERROR, "Out of memory while reading "
100 "VLAN interfaces from '%s'", fname);
101 fclose(f);
102 return -1;
103 }
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105 vlan->vlan_id = vlan_id;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800106 vlan->vlan_desc.untagged = vlan_id;
107 vlan->vlan_desc.notempty = !!vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Hai Shalom74f70d42019-02-11 14:42:39 -0800109 os_strlcpy(vlan->bridge, pos2, sizeof(vlan->bridge));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700110 vlan->next = bss->vlan;
111 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 }
113
114 fclose(f);
115
116 return 0;
117}
118#endif /* CONFIG_NO_VLAN */
119
120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121static int hostapd_config_read_maclist(const char *fname,
122 struct mac_acl_entry **acl, int *num)
123{
124 FILE *f;
125 char buf[128], *pos;
126 int line = 0;
127 u8 addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 int vlan_id;
129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 f = fopen(fname, "r");
131 if (!f) {
132 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
133 return -1;
134 }
135
136 while (fgets(buf, sizeof(buf), f)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700137 int rem = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139 line++;
140
141 if (buf[0] == '#')
142 continue;
143 pos = buf;
144 while (*pos != '\0') {
145 if (*pos == '\n') {
146 *pos = '\0';
147 break;
148 }
149 pos++;
150 }
151 if (buf[0] == '\0')
152 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800153 pos = buf;
154 if (buf[0] == '-') {
155 rem = 1;
156 pos++;
157 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800159 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800161 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 fclose(f);
163 return -1;
164 }
165
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800166 if (rem) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700167 hostapd_remove_acl_mac(acl, num, addr);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800168 continue;
169 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 vlan_id = 0;
171 pos = buf;
172 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
173 pos++;
174 while (*pos == ' ' || *pos == '\t')
175 pos++;
176 if (*pos != '\0')
177 vlan_id = atoi(pos);
178
Roshan Pius3a1667e2018-07-03 15:17:14 -0700179 if (hostapd_add_acl_maclist(acl, num, vlan_id, addr) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 fclose(f);
181 return -1;
182 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 }
184
185 fclose(f);
186
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800187 if (*acl)
188 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
190 return 0;
191}
192
193
194#ifdef EAP_SERVER
Roshan Pius3a1667e2018-07-03 15:17:14 -0700195
196static int hostapd_config_eap_user_salted(struct hostapd_eap_user *user,
197 const char *hash, size_t len,
198 char **pos, int line,
199 const char *fname)
200{
201 char *pos2 = *pos;
202
203 while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#')
204 pos2++;
205
206 if (pos2 - *pos < (int) (2 * (len + 1))) { /* at least 1 byte of salt */
207 wpa_printf(MSG_ERROR,
208 "Invalid salted %s hash on line %d in '%s'",
209 hash, line, fname);
210 return -1;
211 }
212
213 user->password = os_malloc(len);
214 if (!user->password) {
215 wpa_printf(MSG_ERROR,
216 "Failed to allocate memory for salted %s hash",
217 hash);
218 return -1;
219 }
220
221 if (hexstr2bin(*pos, user->password, len) < 0) {
222 wpa_printf(MSG_ERROR,
223 "Invalid salted password on line %d in '%s'",
224 line, fname);
225 return -1;
226 }
227 user->password_len = len;
228 *pos += 2 * len;
229
230 user->salt_len = (pos2 - *pos) / 2;
231 user->salt = os_malloc(user->salt_len);
232 if (!user->salt) {
233 wpa_printf(MSG_ERROR,
234 "Failed to allocate memory for salted %s hash",
235 hash);
236 return -1;
237 }
238
239 if (hexstr2bin(*pos, user->salt, user->salt_len) < 0) {
240 wpa_printf(MSG_ERROR,
241 "Invalid salt for password on line %d in '%s'",
242 line, fname);
243 return -1;
244 }
245
246 *pos = pos2;
247 return 0;
248}
249
250
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251static int hostapd_config_read_eap_user(const char *fname,
252 struct hostapd_bss_config *conf)
253{
254 FILE *f;
255 char buf[512], *pos, *start, *pos2;
256 int line = 0, ret = 0, num_methods;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800257 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800259 if (os_strncmp(fname, "sqlite:", 7) == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700260#ifdef CONFIG_SQLITE
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800261 os_free(conf->eap_user_sqlite);
262 conf->eap_user_sqlite = os_strdup(fname + 7);
263 return 0;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700264#else /* CONFIG_SQLITE */
265 wpa_printf(MSG_ERROR,
266 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
267 return -1;
268#endif /* CONFIG_SQLITE */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800269 }
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 f = fopen(fname, "r");
272 if (!f) {
273 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
274 return -1;
275 }
276
277 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
278 while (fgets(buf, sizeof(buf), f)) {
279 line++;
280
281 if (buf[0] == '#')
282 continue;
283 pos = buf;
284 while (*pos != '\0') {
285 if (*pos == '\n') {
286 *pos = '\0';
287 break;
288 }
289 pos++;
290 }
291 if (buf[0] == '\0')
292 continue;
293
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700294#ifndef CONFIG_NO_RADIUS
295 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
296 struct hostapd_radius_attr *attr, *a;
297 attr = hostapd_parse_radius_attr(buf + 19);
298 if (attr == NULL) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700299 wpa_printf(MSG_ERROR, "Invalid radius_accept_attr: %s",
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700300 buf + 19);
Dmitry Shmidt98660862014-03-11 17:26:21 -0700301 user = NULL; /* already in the BSS list */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700302 goto failed;
303 }
304 if (user->accept_attr == NULL) {
305 user->accept_attr = attr;
306 } else {
307 a = user->accept_attr;
308 while (a->next)
309 a = a->next;
310 a->next = attr;
311 }
312 continue;
313 }
314#endif /* CONFIG_NO_RADIUS */
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 user = NULL;
317
318 if (buf[0] != '"' && buf[0] != '*') {
319 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
320 "start) on line %d in '%s'", line, fname);
321 goto failed;
322 }
323
324 user = os_zalloc(sizeof(*user));
325 if (user == NULL) {
326 wpa_printf(MSG_ERROR, "EAP user allocation failed");
327 goto failed;
328 }
329 user->force_version = -1;
330
331 if (buf[0] == '*') {
332 pos = buf;
333 } else {
334 pos = buf + 1;
335 start = pos;
336 while (*pos != '"' && *pos != '\0')
337 pos++;
338 if (*pos == '\0') {
339 wpa_printf(MSG_ERROR, "Invalid EAP identity "
340 "(no \" in end) on line %d in '%s'",
341 line, fname);
342 goto failed;
343 }
344
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700345 user->identity = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 if (user->identity == NULL) {
347 wpa_printf(MSG_ERROR, "Failed to allocate "
348 "memory for EAP identity");
349 goto failed;
350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 user->identity_len = pos - start;
352
353 if (pos[0] == '"' && pos[1] == '*') {
354 user->wildcard_prefix = 1;
355 pos++;
356 }
357 }
358 pos++;
359 while (*pos == ' ' || *pos == '\t')
360 pos++;
361
362 if (*pos == '\0') {
363 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
364 "'%s'", line, fname);
365 goto failed;
366 }
367
368 start = pos;
369 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
370 pos++;
371 if (*pos == '\0') {
372 pos = NULL;
373 } else {
374 *pos = '\0';
375 pos++;
376 }
377 num_methods = 0;
378 while (*start) {
379 char *pos3 = os_strchr(start, ',');
380 if (pos3) {
381 *pos3++ = '\0';
382 }
383 user->methods[num_methods].method =
384 eap_server_get_type(
385 start,
386 &user->methods[num_methods].vendor);
387 if (user->methods[num_methods].vendor ==
388 EAP_VENDOR_IETF &&
389 user->methods[num_methods].method == EAP_TYPE_NONE)
390 {
391 if (os_strcmp(start, "TTLS-PAP") == 0) {
392 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
393 goto skip_eap;
394 }
395 if (os_strcmp(start, "TTLS-CHAP") == 0) {
396 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
397 goto skip_eap;
398 }
399 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
400 user->ttls_auth |=
401 EAP_TTLS_AUTH_MSCHAP;
402 goto skip_eap;
403 }
404 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
405 user->ttls_auth |=
406 EAP_TTLS_AUTH_MSCHAPV2;
407 goto skip_eap;
408 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700409 if (os_strcmp(start, "MACACL") == 0) {
410 user->macacl = 1;
411 goto skip_eap;
412 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 wpa_printf(MSG_ERROR, "Unsupported EAP type "
414 "'%s' on line %d in '%s'",
415 start, line, fname);
416 goto failed;
417 }
418
419 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 break;
422 skip_eap:
423 if (pos3 == NULL)
424 break;
425 start = pos3;
426 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700427 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 wpa_printf(MSG_ERROR, "No EAP types configured on "
429 "line %d in '%s'", line, fname);
430 goto failed;
431 }
432
433 if (pos == NULL)
434 goto done;
435
436 while (*pos == ' ' || *pos == '\t')
437 pos++;
438 if (*pos == '\0')
439 goto done;
440
441 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
442 user->force_version = 0;
443 goto done;
444 }
445
446 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
447 user->force_version = 1;
448 goto done;
449 }
450
451 if (os_strncmp(pos, "[2]", 3) == 0) {
452 user->phase2 = 1;
453 goto done;
454 }
455
456 if (*pos == '"') {
457 pos++;
458 start = pos;
459 while (*pos != '"' && *pos != '\0')
460 pos++;
461 if (*pos == '\0') {
462 wpa_printf(MSG_ERROR, "Invalid EAP password "
463 "(no \" in end) on line %d in '%s'",
464 line, fname);
465 goto failed;
466 }
467
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700468 user->password = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 if (user->password == NULL) {
470 wpa_printf(MSG_ERROR, "Failed to allocate "
471 "memory for EAP password");
472 goto failed;
473 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 user->password_len = pos - start;
475
476 pos++;
477 } else if (os_strncmp(pos, "hash:", 5) == 0) {
478 pos += 5;
479 pos2 = pos;
480 while (*pos2 != '\0' && *pos2 != ' ' &&
481 *pos2 != '\t' && *pos2 != '#')
482 pos2++;
483 if (pos2 - pos != 32) {
484 wpa_printf(MSG_ERROR, "Invalid password hash "
485 "on line %d in '%s'", line, fname);
486 goto failed;
487 }
488 user->password = os_malloc(16);
489 if (user->password == NULL) {
490 wpa_printf(MSG_ERROR, "Failed to allocate "
491 "memory for EAP password hash");
492 goto failed;
493 }
494 if (hexstr2bin(pos, user->password, 16) < 0) {
495 wpa_printf(MSG_ERROR, "Invalid hash password "
496 "on line %d in '%s'", line, fname);
497 goto failed;
498 }
499 user->password_len = 16;
500 user->password_hash = 1;
501 pos = pos2;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700502 } else if (os_strncmp(pos, "ssha1:", 6) == 0) {
503 pos += 6;
504 if (hostapd_config_eap_user_salted(user, "sha1", 20,
505 &pos,
506 line, fname) < 0)
507 goto failed;
508 } else if (os_strncmp(pos, "ssha256:", 8) == 0) {
509 pos += 8;
510 if (hostapd_config_eap_user_salted(user, "sha256", 32,
511 &pos,
512 line, fname) < 0)
513 goto failed;
514 } else if (os_strncmp(pos, "ssha512:", 8) == 0) {
515 pos += 8;
516 if (hostapd_config_eap_user_salted(user, "sha512", 64,
517 &pos,
518 line, fname) < 0)
519 goto failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 } else {
521 pos2 = pos;
522 while (*pos2 != '\0' && *pos2 != ' ' &&
523 *pos2 != '\t' && *pos2 != '#')
524 pos2++;
525 if ((pos2 - pos) & 1) {
526 wpa_printf(MSG_ERROR, "Invalid hex password "
527 "on line %d in '%s'", line, fname);
528 goto failed;
529 }
530 user->password = os_malloc((pos2 - pos) / 2);
531 if (user->password == NULL) {
532 wpa_printf(MSG_ERROR, "Failed to allocate "
533 "memory for EAP password");
534 goto failed;
535 }
536 if (hexstr2bin(pos, user->password,
537 (pos2 - pos) / 2) < 0) {
538 wpa_printf(MSG_ERROR, "Invalid hex password "
539 "on line %d in '%s'", line, fname);
540 goto failed;
541 }
542 user->password_len = (pos2 - pos) / 2;
543 pos = pos2;
544 }
545
546 while (*pos == ' ' || *pos == '\t')
547 pos++;
548 if (os_strncmp(pos, "[2]", 3) == 0) {
549 user->phase2 = 1;
550 }
551
552 done:
553 if (tail == NULL) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800554 tail = new_user = user;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 } else {
556 tail->next = user;
557 tail = user;
558 }
559 continue;
560
561 failed:
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700562 if (user)
563 hostapd_config_free_eap_user(user);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 ret = -1;
565 break;
566 }
567
568 fclose(f);
569
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800570 if (ret == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800571 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800572 conf->eap_user = new_user;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800573 } else {
574 hostapd_config_free_eap_users(new_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800575 }
576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 return ret;
578}
Roshan Pius3a1667e2018-07-03 15:17:14 -0700579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580#endif /* EAP_SERVER */
581
582
583#ifndef CONFIG_NO_RADIUS
584static int
585hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
586 int *num_server, const char *val, int def_port,
587 struct hostapd_radius_server **curr_serv)
588{
589 struct hostapd_radius_server *nserv;
590 int ret;
591 static int server_index = 1;
592
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700593 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 if (nserv == NULL)
595 return -1;
596
597 *server = nserv;
598 nserv = &nserv[*num_server];
599 (*num_server)++;
600 (*curr_serv) = nserv;
601
602 os_memset(nserv, 0, sizeof(*nserv));
603 nserv->port = def_port;
604 ret = hostapd_parse_ip_addr(val, &nserv->addr);
605 nserv->index = server_index++;
606
607 return ret;
608}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700609
610
Dmitry Shmidt04949592012-07-19 12:16:46 -0700611
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700612static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700613{
614 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700615
616 secret = os_strchr(val, ' ');
617 if (secret == NULL)
618 return -1;
619
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700620 *secret++ = '\0';
Dmitry Shmidt04949592012-07-19 12:16:46 -0700621
622 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
623 return -1;
624
625 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700626 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700627 if (bss->radius_das_shared_secret == NULL)
628 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700629 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700630
631 return 0;
632}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633#endif /* CONFIG_NO_RADIUS */
634
635
636static int hostapd_config_parse_key_mgmt(int line, const char *value)
637{
638 int val = 0, last;
639 char *start, *end, *buf;
640
641 buf = os_strdup(value);
642 if (buf == NULL)
643 return -1;
644 start = buf;
645
646 while (*start != '\0') {
647 while (*start == ' ' || *start == '\t')
648 start++;
649 if (*start == '\0')
650 break;
651 end = start;
652 while (*end != ' ' && *end != '\t' && *end != '\0')
653 end++;
654 last = *end == '\0';
655 *end = '\0';
656 if (os_strcmp(start, "WPA-PSK") == 0)
657 val |= WPA_KEY_MGMT_PSK;
658 else if (os_strcmp(start, "WPA-EAP") == 0)
659 val |= WPA_KEY_MGMT_IEEE8021X;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800660#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 else if (os_strcmp(start, "FT-PSK") == 0)
662 val |= WPA_KEY_MGMT_FT_PSK;
663 else if (os_strcmp(start, "FT-EAP") == 0)
664 val |= WPA_KEY_MGMT_FT_IEEE8021X;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700665#ifdef CONFIG_SHA384
666 else if (os_strcmp(start, "FT-EAP-SHA384") == 0)
667 val |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
668#endif /* CONFIG_SHA384 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800669#endif /* CONFIG_IEEE80211R_AP */
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000670#ifdef CONFIG_SHA384
671 else if (os_strcmp(start, "WPA-EAP-SHA384") == 0)
672 val |= WPA_KEY_MGMT_IEEE8021X_SHA384;
673#endif /* CONFIG_SHA384 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
675 val |= WPA_KEY_MGMT_PSK_SHA256;
676 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
677 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800678#ifdef CONFIG_SAE
679 else if (os_strcmp(start, "SAE") == 0)
680 val |= WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -0700681 else if (os_strcmp(start, "SAE-EXT-KEY") == 0)
682 val |= WPA_KEY_MGMT_SAE_EXT_KEY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800683 else if (os_strcmp(start, "FT-SAE") == 0)
684 val |= WPA_KEY_MGMT_FT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -0700685 else if (os_strcmp(start, "FT-SAE-EXT-KEY") == 0)
686 val |= WPA_KEY_MGMT_FT_SAE_EXT_KEY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800687#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800688#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800689 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
690 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800691#endif /* CONFIG_SUITEB */
692#ifdef CONFIG_SUITEB192
693 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
694 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
695#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800696#ifdef CONFIG_FILS
697 else if (os_strcmp(start, "FILS-SHA256") == 0)
698 val |= WPA_KEY_MGMT_FILS_SHA256;
699 else if (os_strcmp(start, "FILS-SHA384") == 0)
700 val |= WPA_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800701#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800702 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
703 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
704 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
705 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800706#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800707#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700708#ifdef CONFIG_OWE
709 else if (os_strcmp(start, "OWE") == 0)
710 val |= WPA_KEY_MGMT_OWE;
711#endif /* CONFIG_OWE */
712#ifdef CONFIG_DPP
713 else if (os_strcmp(start, "DPP") == 0)
714 val |= WPA_KEY_MGMT_DPP;
715#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700716#ifdef CONFIG_HS20
717 else if (os_strcmp(start, "OSEN") == 0)
718 val |= WPA_KEY_MGMT_OSEN;
719#endif /* CONFIG_HS20 */
Hai Shalom60840252021-02-19 19:02:11 -0800720#ifdef CONFIG_PASN
721 else if (os_strcmp(start, "PASN") == 0)
722 val |= WPA_KEY_MGMT_PASN;
723#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 else {
725 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
726 line, start);
727 os_free(buf);
728 return -1;
729 }
730
731 if (last)
732 break;
733 start = end + 1;
734 }
735
736 os_free(buf);
737 if (val == 0) {
738 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
739 "configured.", line);
740 return -1;
741 }
742
743 return val;
744}
745
746
747static int hostapd_config_parse_cipher(int line, const char *value)
748{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800749 int val = wpa_parse_cipher(value);
750 if (val < 0) {
751 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
752 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755 if (val == 0) {
756 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
757 line);
758 return -1;
759 }
760 return val;
761}
762
763
Hai Shalomfdcde762020-04-02 11:19:20 -0700764#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
766 char *val)
767{
768 size_t len = os_strlen(val);
769
Dmitry Shmidt29333592017-01-09 12:27:11 -0800770 if (keyidx < 0 || keyidx > 3)
771 return -1;
772
773 if (len == 0) {
774 int i, set = 0;
775
776 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
777 wep->key[keyidx] = NULL;
778 wep->len[keyidx] = 0;
779 for (i = 0; i < NUM_WEP_KEYS; i++) {
780 if (wep->key[i])
781 set++;
782 }
783 if (!set)
784 wep->keys_set = 0;
785 return 0;
786 }
787
788 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 return -1;
790
791 if (val[0] == '"') {
792 if (len < 2 || val[len - 1] != '"')
793 return -1;
794 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700795 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 if (wep->key[keyidx] == NULL)
797 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 wep->len[keyidx] = len;
799 } else {
800 if (len & 1)
801 return -1;
802 len /= 2;
803 wep->key[keyidx] = os_malloc(len);
804 if (wep->key[keyidx] == NULL)
805 return -1;
806 wep->len[keyidx] = len;
807 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
808 return -1;
809 }
810
811 wep->keys_set++;
812
813 return 0;
814}
Hai Shalomfdcde762020-04-02 11:19:20 -0700815#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816
817
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700818static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
819{
820 char *pos;
821
822 /* for backwards compatibility, translate ' ' in conf str to ',' */
823 pos = val;
824 while (pos) {
825 pos = os_strchr(pos, ' ');
826 if (pos)
827 *pos++ = ',';
828 }
829 if (freq_range_list_parse(&conf->acs_ch_list, val))
830 return -1;
831
832 return 0;
833}
834
835
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700836static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837{
838 int *list;
839 int count;
840 char *pos, *end;
841
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700842 os_free(*int_list);
843 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844
845 pos = val;
846 count = 0;
847 while (*pos != '\0') {
848 if (*pos == ' ')
849 count++;
850 pos++;
851 }
852
853 list = os_malloc(sizeof(int) * (count + 2));
854 if (list == NULL)
855 return -1;
856 pos = val;
857 count = 0;
858 while (*pos != '\0') {
859 end = os_strchr(pos, ' ');
860 if (end)
861 *end = '\0';
862
863 list[count++] = atoi(pos);
864 if (!end)
865 break;
866 pos = end + 1;
867 }
868 list[count] = -1;
869
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700870 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 return 0;
872}
873
874
875static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
876{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800877 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878
879 if (*ifname == '\0')
880 return -1;
881
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800882 all = os_realloc_array(conf->bss, conf->num_bss + 1,
883 sizeof(struct hostapd_bss_config *));
884 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
886 "multi-BSS entry");
887 return -1;
888 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800889 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800891 bss = os_zalloc(sizeof(*bss));
892 if (bss == NULL)
893 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 bss->radius = os_zalloc(sizeof(*bss->radius));
895 if (bss->radius == NULL) {
896 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
897 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800898 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 return -1;
900 }
901
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800902 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 conf->last_bss = bss;
904
905 hostapd_config_defaults_bss(bss);
906 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
907 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
908
909 return 0;
910}
911
912
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800913#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700914
915static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
916{
917 u8 oldkey[16];
918 int ret;
919
920 if (!hexstr2bin(pos, key, key_len))
921 return 0;
922
923 /* Try to use old short key for backwards compatibility */
924 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
925 return -1;
926
927 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
928 key, key_len);
929 os_memset(oldkey, 0, sizeof(oldkey));
930 return ret;
931}
932
933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934static int add_r0kh(struct hostapd_bss_config *bss, char *value)
935{
936 struct ft_remote_r0kh *r0kh;
937 char *pos, *next;
938
939 r0kh = os_zalloc(sizeof(*r0kh));
940 if (r0kh == NULL)
941 return -1;
942
943 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
944 pos = value;
945 next = os_strchr(pos, ' ');
946 if (next)
947 *next++ = '\0';
948 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
949 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
950 os_free(r0kh);
951 return -1;
952 }
953
954 pos = next;
955 next = os_strchr(pos, ' ');
956 if (next)
957 *next++ = '\0';
958 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
959 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
960 os_free(r0kh);
961 return -1;
962 }
963 r0kh->id_len = next - pos - 1;
964 os_memcpy(r0kh->id, pos, r0kh->id_len);
965
966 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700967 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700968 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
969 os_free(r0kh);
970 return -1;
971 }
972
973 r0kh->next = bss->r0kh_list;
974 bss->r0kh_list = r0kh;
975
976 return 0;
977}
978
979
980static int add_r1kh(struct hostapd_bss_config *bss, char *value)
981{
982 struct ft_remote_r1kh *r1kh;
983 char *pos, *next;
984
985 r1kh = os_zalloc(sizeof(*r1kh));
986 if (r1kh == NULL)
987 return -1;
988
989 /* 02:01:02:03:04:05 02:01:02:03:04:05
990 * 000102030405060708090a0b0c0d0e0f */
991 pos = value;
992 next = os_strchr(pos, ' ');
993 if (next)
994 *next++ = '\0';
995 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
996 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
997 os_free(r1kh);
998 return -1;
999 }
1000
1001 pos = next;
1002 next = os_strchr(pos, ' ');
1003 if (next)
1004 *next++ = '\0';
1005 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1006 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1007 os_free(r1kh);
1008 return -1;
1009 }
1010
1011 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001012 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1014 os_free(r1kh);
1015 return -1;
1016 }
1017
1018 r1kh->next = bss->r1kh_list;
1019 bss->r1kh_list = r1kh;
1020
1021 return 0;
1022}
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001023
1024
1025int hostapd_config_read_rxkh_file(struct hostapd_bss_config *conf,
1026 const char *fname)
1027{
1028 FILE *f;
1029 char buf[256], *pos;
1030 int line = 0, errors = 0;
1031
1032 if (!fname)
1033 return 0;
1034
1035 f = fopen(fname, "r");
1036 if (!f) {
1037 wpa_printf(MSG_ERROR, "rxkh file '%s' not found.", fname);
1038 return -1;
1039 }
1040
1041 while (fgets(buf, sizeof(buf), f)) {
1042 line++;
1043
1044 if (buf[0] == '#')
1045 continue;
1046 pos = buf;
1047 while (*pos != '\0') {
1048 if (*pos == '\n') {
1049 *pos = '\0';
1050 break;
1051 }
1052 pos++;
1053 }
1054 if (buf[0] == '\0')
1055 continue;
1056
1057 pos = os_strchr(buf, '=');
1058 if (!pos) {
1059 wpa_printf(MSG_ERROR, "Line %d: Invalid line '%s'",
1060 line, buf);
1061 errors++;
1062 continue;
1063 }
1064 *pos = '\0';
1065 pos++;
1066
1067 if (os_strcmp(buf, "r0kh") == 0) {
1068 if (add_r0kh(conf, pos) < 0) {
1069 wpa_printf(MSG_ERROR,
1070 "Line %d: Invalid r0kh '%s'",
1071 line, pos);
1072 errors++;
1073 }
1074 } else if (os_strcmp(buf, "r1kh") == 0) {
1075 if (add_r1kh(conf, pos) < 0) {
1076 wpa_printf(MSG_ERROR,
1077 "Line %d: Invalid r1kh '%s'",
1078 line, pos);
1079 errors++;
1080 }
1081 }
1082 }
1083
1084 fclose(f);
1085
1086 if (errors) {
1087 wpa_printf(MSG_ERROR,
1088 "%d errors in configuring RxKHs from '%s'",
1089 errors, fname);
1090 return -1;
1091 }
1092 return 0;
1093}
1094
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001095#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096
1097
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098static int hostapd_config_ht_capab(struct hostapd_config *conf,
1099 const char *capab)
1100{
1101 if (os_strstr(capab, "[LDPC]"))
1102 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1103 if (os_strstr(capab, "[HT40-]")) {
1104 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1105 conf->secondary_channel = -1;
1106 }
1107 if (os_strstr(capab, "[HT40+]")) {
1108 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1109 conf->secondary_channel = 1;
1110 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001111 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1112 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1113 conf->ht40_plus_minus_allowed = 1;
1114 }
Hai Shalomce48b4a2018-09-05 11:41:35 -07001115 if (!os_strstr(capab, "[HT40+]") && !os_strstr(capab, "[HT40-]"))
1116 conf->secondary_channel = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 if (os_strstr(capab, "[GF]"))
1118 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1119 if (os_strstr(capab, "[SHORT-GI-20]"))
1120 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1121 if (os_strstr(capab, "[SHORT-GI-40]"))
1122 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1123 if (os_strstr(capab, "[TX-STBC]"))
1124 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1125 if (os_strstr(capab, "[RX-STBC1]")) {
1126 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1127 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1128 }
1129 if (os_strstr(capab, "[RX-STBC12]")) {
1130 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1131 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1132 }
1133 if (os_strstr(capab, "[RX-STBC123]")) {
1134 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1135 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1136 }
1137 if (os_strstr(capab, "[DELAYED-BA]"))
1138 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1139 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1140 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1141 if (os_strstr(capab, "[DSSS_CCK-40]"))
1142 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001143 if (os_strstr(capab, "[40-INTOLERANT]"))
1144 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1146 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1147
1148 return 0;
1149}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150
1151
Dmitry Shmidt04949592012-07-19 12:16:46 -07001152#ifdef CONFIG_IEEE80211AC
1153static int hostapd_config_vht_capab(struct hostapd_config *conf,
1154 const char *capab)
1155{
1156 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1157 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1158 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1159 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1160 if (os_strstr(capab, "[VHT160]"))
1161 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1162 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1163 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001164 if (os_strstr(capab, "[RXLDPC]"))
1165 conf->vht_capab |= VHT_CAP_RXLDPC;
1166 if (os_strstr(capab, "[SHORT-GI-80]"))
1167 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1168 if (os_strstr(capab, "[SHORT-GI-160]"))
1169 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1170 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1171 conf->vht_capab |= VHT_CAP_TXSTBC;
1172 if (os_strstr(capab, "[RX-STBC-1]"))
1173 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1174 if (os_strstr(capab, "[RX-STBC-12]"))
1175 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1176 if (os_strstr(capab, "[RX-STBC-123]"))
1177 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1178 if (os_strstr(capab, "[RX-STBC-1234]"))
1179 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1180 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001181 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001182 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001183 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001184 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001185 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1186 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001187 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1188 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1189 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1190 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1191 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1192 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001193 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001194 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1195 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001196 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1197 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1198 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1199 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1200 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1201 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001202 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1203 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001204 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1205 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1206 if (os_strstr(capab, "[HTC-VHT]"))
1207 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001208 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1209 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1210 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1211 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1212 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1213 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1214 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1215 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1216 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1217 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1218 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1219 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1220 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1221 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001222 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1223 (conf->vht_capab & VHT_CAP_HTC_VHT))
1224 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1225 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1226 (conf->vht_capab & VHT_CAP_HTC_VHT))
1227 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1228 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1229 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1230 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1231 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1232 return 0;
1233}
1234#endif /* CONFIG_IEEE80211AC */
1235
1236
Hai Shalom74f70d42019-02-11 14:42:39 -08001237#ifdef CONFIG_IEEE80211AX
1238
1239static u8 find_bit_offset(u8 val)
1240{
1241 u8 res = 0;
1242
1243 for (; val; val >>= 1) {
1244 if (val & 1)
1245 break;
1246 res++;
1247 }
1248
1249 return res;
1250}
1251
1252
1253static u8 set_he_cap(int val, u8 mask)
1254{
1255 return (u8) (mask & (val << find_bit_offset(mask)));
1256}
1257
Hai Shalom60840252021-02-19 19:02:11 -08001258
1259static int hostapd_parse_he_srg_bitmap(u8 *bitmap, char *val)
1260{
1261 int bitpos;
1262 char *pos, *end;
1263
1264 os_memset(bitmap, 0, 8);
1265 pos = val;
1266 while (*pos != '\0') {
1267 end = os_strchr(pos, ' ');
1268 if (end)
1269 *end = '\0';
1270
1271 bitpos = atoi(pos);
1272 if (bitpos < 0 || bitpos > 64)
1273 return -1;
1274
1275 bitmap[bitpos / 8] |= BIT(bitpos % 8);
1276 if (!end)
1277 break;
1278 pos = end + 1;
1279 }
1280
1281 return 0;
1282}
1283
Hai Shalom74f70d42019-02-11 14:42:39 -08001284#endif /* CONFIG_IEEE80211AX */
1285
1286
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001287#ifdef CONFIG_INTERWORKING
1288static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1289 int line)
1290{
1291 size_t len = os_strlen(pos);
1292 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1293
1294 struct hostapd_roaming_consortium *rc;
1295
1296 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1297 hexstr2bin(pos, oi, len / 2)) {
1298 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1299 "'%s'", line, pos);
1300 return -1;
1301 }
1302 len /= 2;
1303
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001304 rc = os_realloc_array(bss->roaming_consortium,
1305 bss->roaming_consortium_count + 1,
1306 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001307 if (rc == NULL)
1308 return -1;
1309
1310 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1311 rc[bss->roaming_consortium_count].len = len;
1312
1313 bss->roaming_consortium = rc;
1314 bss->roaming_consortium_count++;
1315
1316 return 0;
1317}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001318
1319
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001320static int parse_lang_string(struct hostapd_lang_string **array,
1321 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001322{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001323 char *sep, *str = NULL;
1324 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001325 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001326 int ret = -1;
1327
1328 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1329 str = wpa_config_parse_string(pos, &slen);
1330 if (!str)
1331 return -1;
1332 pos = str;
1333 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001334
1335 sep = os_strchr(pos, ':');
1336 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001337 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001338 *sep++ = '\0';
1339
1340 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001341 if (clen < 2 || clen > sizeof(ls->lang))
1342 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001343 nlen = os_strlen(sep);
1344 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001345 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001346
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001347 ls = os_realloc_array(*array, *count + 1,
1348 sizeof(struct hostapd_lang_string));
1349 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001350 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001351
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001352 *array = ls;
1353 ls = &(*array)[*count];
1354 (*count)++;
1355
1356 os_memset(ls->lang, 0, sizeof(ls->lang));
1357 os_memcpy(ls->lang, pos, clen);
1358 ls->name_len = nlen;
1359 os_memcpy(ls->name, sep, nlen);
1360
Dmitry Shmidt56052862013-10-04 10:23:25 -07001361 ret = 0;
1362fail:
1363 os_free(str);
1364 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001365}
1366
1367
1368static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1369 int line)
1370{
1371 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1372 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1373 line, pos);
1374 return -1;
1375 }
1376 return 0;
1377}
1378
1379
Roshan Pius3a1667e2018-07-03 15:17:14 -07001380static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1381 int line)
1382{
1383 char *sep;
1384 size_t nlen;
1385 struct hostapd_venue_url *url;
1386 int ret = -1;
1387
1388 sep = os_strchr(pos, ':');
1389 if (!sep)
1390 goto fail;
1391 *sep++ = '\0';
1392
1393 nlen = os_strlen(sep);
1394 if (nlen > 254)
1395 goto fail;
1396
1397 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1398 sizeof(struct hostapd_venue_url));
1399 if (!url)
1400 goto fail;
1401
1402 bss->venue_url = url;
1403 url = &bss->venue_url[bss->venue_url_count++];
1404
1405 url->venue_number = atoi(pos);
1406 url->url_len = nlen;
1407 os_memcpy(url->url, sep, nlen);
1408
1409 ret = 0;
1410fail:
1411 if (ret)
1412 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1413 line, pos);
1414 return ret;
1415}
1416
1417
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001418static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1419 int line)
1420{
1421 size_t count;
1422 char *pos;
1423 u8 *info = NULL, *ipos;
1424
1425 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1426
1427 count = 1;
1428 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001429 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001430 goto fail;
1431 if (*pos == ';')
1432 count++;
1433 }
1434 if (1 + count * 3 > 0x7f)
1435 goto fail;
1436
1437 info = os_zalloc(2 + 3 + count * 3);
1438 if (info == NULL)
1439 return -1;
1440
1441 ipos = info;
1442 *ipos++ = 0; /* GUD - Version 1 */
1443 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1444 *ipos++ = 0; /* PLMN List IEI */
1445 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1446 *ipos++ = 1 + count * 3;
1447 *ipos++ = count; /* Number of PLMNs */
1448
1449 pos = buf;
1450 while (pos && *pos) {
1451 char *mcc, *mnc;
1452 size_t mnc_len;
1453
1454 mcc = pos;
1455 mnc = os_strchr(pos, ',');
1456 if (mnc == NULL)
1457 goto fail;
1458 *mnc++ = '\0';
1459 pos = os_strchr(mnc, ';');
1460 if (pos)
1461 *pos++ = '\0';
1462
1463 mnc_len = os_strlen(mnc);
1464 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1465 goto fail;
1466
1467 /* BC coded MCC,MNC */
1468 /* MCC digit 2 | MCC digit 1 */
1469 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1470 /* MNC digit 3 | MCC digit 3 */
1471 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1472 (mcc[2] - '0');
1473 /* MNC digit 2 | MNC digit 1 */
1474 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1475 }
1476
1477 os_free(bss->anqp_3gpp_cell_net);
1478 bss->anqp_3gpp_cell_net = info;
1479 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1480 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1481 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001482
1483 return 0;
1484
1485fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001486 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1487 line, buf);
1488 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001489 return -1;
1490}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001491
1492
1493static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1494{
1495 struct hostapd_nai_realm_data *realm;
1496 size_t i, j, len;
1497 int *offsets;
1498 char *pos, *end, *rpos;
1499
1500 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1501 sizeof(int));
1502 if (offsets == NULL)
1503 return -1;
1504
1505 for (i = 0; i < bss->nai_realm_count; i++) {
1506 realm = &bss->nai_realm_data[i];
1507 for (j = 0; j < MAX_NAI_REALMS; j++) {
1508 offsets[i * MAX_NAI_REALMS + j] =
1509 realm->realm[j] ?
1510 realm->realm[j] - realm->realm_buf : -1;
1511 }
1512 }
1513
1514 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1515 sizeof(struct hostapd_nai_realm_data));
1516 if (realm == NULL) {
1517 os_free(offsets);
1518 return -1;
1519 }
1520 bss->nai_realm_data = realm;
1521
1522 /* patch the pointers after realloc */
1523 for (i = 0; i < bss->nai_realm_count; i++) {
1524 realm = &bss->nai_realm_data[i];
1525 for (j = 0; j < MAX_NAI_REALMS; j++) {
1526 int offs = offsets[i * MAX_NAI_REALMS + j];
1527 if (offs >= 0)
1528 realm->realm[j] = realm->realm_buf + offs;
1529 else
1530 realm->realm[j] = NULL;
1531 }
1532 }
1533 os_free(offsets);
1534
1535 realm = &bss->nai_realm_data[bss->nai_realm_count];
1536 os_memset(realm, 0, sizeof(*realm));
1537
1538 pos = buf;
1539 realm->encoding = atoi(pos);
1540 pos = os_strchr(pos, ',');
1541 if (pos == NULL)
1542 goto fail;
1543 pos++;
1544
1545 end = os_strchr(pos, ',');
1546 if (end) {
1547 len = end - pos;
1548 *end = '\0';
1549 } else {
1550 len = os_strlen(pos);
1551 }
1552
1553 if (len > MAX_NAI_REALMLEN) {
1554 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1555 "characters)", (int) len, MAX_NAI_REALMLEN);
1556 goto fail;
1557 }
1558 os_memcpy(realm->realm_buf, pos, len);
1559
1560 if (end)
1561 pos = end + 1;
1562 else
1563 pos = NULL;
1564
1565 while (pos && *pos) {
1566 struct hostapd_nai_realm_eap *eap;
1567
1568 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1569 wpa_printf(MSG_ERROR, "Too many EAP methods");
1570 goto fail;
1571 }
1572
1573 eap = &realm->eap_method[realm->eap_method_count];
1574 realm->eap_method_count++;
1575
1576 end = os_strchr(pos, ',');
1577 if (end == NULL)
1578 end = pos + os_strlen(pos);
1579
1580 eap->eap_method = atoi(pos);
1581 for (;;) {
1582 pos = os_strchr(pos, '[');
1583 if (pos == NULL || pos > end)
1584 break;
1585 pos++;
1586 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1587 wpa_printf(MSG_ERROR, "Too many auth params");
1588 goto fail;
1589 }
1590 eap->auth_id[eap->num_auths] = atoi(pos);
1591 pos = os_strchr(pos, ':');
1592 if (pos == NULL || pos > end)
1593 goto fail;
1594 pos++;
1595 eap->auth_val[eap->num_auths] = atoi(pos);
1596 pos = os_strchr(pos, ']');
1597 if (pos == NULL || pos > end)
1598 goto fail;
1599 pos++;
1600 eap->num_auths++;
1601 }
1602
1603 if (*end != ',')
1604 break;
1605
1606 pos = end + 1;
1607 }
1608
1609 /* Split realm list into null terminated realms */
1610 rpos = realm->realm_buf;
1611 i = 0;
1612 while (*rpos) {
1613 if (i >= MAX_NAI_REALMS) {
1614 wpa_printf(MSG_ERROR, "Too many realms");
1615 goto fail;
1616 }
1617 realm->realm[i++] = rpos;
1618 rpos = os_strchr(rpos, ';');
1619 if (rpos == NULL)
1620 break;
1621 *rpos++ = '\0';
1622 }
1623
1624 bss->nai_realm_count++;
1625
1626 return 0;
1627
1628fail:
1629 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1630 return -1;
1631}
1632
Dmitry Shmidt051af732013-10-22 13:52:46 -07001633
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001634static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1635{
1636 char *delim;
1637 u16 infoid;
1638 size_t len;
1639 struct wpabuf *payload;
1640 struct anqp_element *elem;
1641
1642 delim = os_strchr(buf, ':');
1643 if (!delim)
1644 return -1;
1645 delim++;
1646 infoid = atoi(buf);
1647 len = os_strlen(delim);
1648 if (len & 1)
1649 return -1;
1650 len /= 2;
1651 payload = wpabuf_alloc(len);
1652 if (!payload)
1653 return -1;
1654 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1655 wpabuf_free(payload);
1656 return -1;
1657 }
1658
1659 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1660 if (elem->infoid == infoid) {
1661 /* Update existing entry */
1662 wpabuf_free(elem->payload);
1663 elem->payload = payload;
1664 return 0;
1665 }
1666 }
1667
1668 /* Add a new entry */
1669 elem = os_zalloc(sizeof(*elem));
1670 if (!elem) {
1671 wpabuf_free(payload);
1672 return -1;
1673 }
1674 elem->infoid = infoid;
1675 elem->payload = payload;
1676 dl_list_add(&bss->anqp_elem, &elem->list);
1677
1678 return 0;
1679}
1680
Sunil Ravi99c035e2024-07-12 01:42:03 +00001681#endif /* CONFIG_INTERWORKING */
1682
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001683
Dmitry Shmidt051af732013-10-22 13:52:46 -07001684static int parse_qos_map_set(struct hostapd_bss_config *bss,
1685 char *buf, int line)
1686{
1687 u8 qos_map_set[16 + 2 * 21], count = 0;
1688 char *pos = buf;
1689 int val;
1690
1691 for (;;) {
1692 if (count == sizeof(qos_map_set)) {
1693 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1694 "parameters '%s'", line, buf);
1695 return -1;
1696 }
1697
1698 val = atoi(pos);
1699 if (val > 255 || val < 0) {
1700 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1701 "'%s'", line, buf);
1702 return -1;
1703 }
1704
1705 qos_map_set[count++] = val;
1706 pos = os_strchr(pos, ',');
1707 if (!pos)
1708 break;
1709 pos++;
1710 }
1711
1712 if (count < 16 || count & 1) {
1713 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1714 line, buf);
1715 return -1;
1716 }
1717
1718 os_memcpy(bss->qos_map_set, qos_map_set, count);
1719 bss->qos_map_set_len = count;
1720
1721 return 0;
1722}
1723
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001724
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001725#ifdef CONFIG_HS20
1726static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1727 int line)
1728{
1729 u8 *conn_cap;
1730 char *pos;
1731
1732 if (bss->hs20_connection_capability_len >= 0xfff0)
1733 return -1;
1734
1735 conn_cap = os_realloc(bss->hs20_connection_capability,
1736 bss->hs20_connection_capability_len + 4);
1737 if (conn_cap == NULL)
1738 return -1;
1739
1740 bss->hs20_connection_capability = conn_cap;
1741 conn_cap += bss->hs20_connection_capability_len;
1742 pos = buf;
1743 conn_cap[0] = atoi(pos);
1744 pos = os_strchr(pos, ':');
1745 if (pos == NULL)
1746 return -1;
1747 pos++;
1748 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1749 pos = os_strchr(pos, ':');
1750 if (pos == NULL)
1751 return -1;
1752 pos++;
1753 conn_cap[3] = atoi(pos);
1754 bss->hs20_connection_capability_len += 4;
1755
1756 return 0;
1757}
1758
1759
1760static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1761 int line)
1762{
1763 u8 *wan_metrics;
1764 char *pos;
1765
1766 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1767
1768 wan_metrics = os_zalloc(13);
1769 if (wan_metrics == NULL)
1770 return -1;
1771
1772 pos = buf;
1773 /* WAN Info */
1774 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1775 goto fail;
1776 pos += 2;
1777 if (*pos != ':')
1778 goto fail;
1779 pos++;
1780
1781 /* Downlink Speed */
1782 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1783 pos = os_strchr(pos, ':');
1784 if (pos == NULL)
1785 goto fail;
1786 pos++;
1787
1788 /* Uplink Speed */
1789 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1790 pos = os_strchr(pos, ':');
1791 if (pos == NULL)
1792 goto fail;
1793 pos++;
1794
1795 /* Downlink Load */
1796 wan_metrics[9] = atoi(pos);
1797 pos = os_strchr(pos, ':');
1798 if (pos == NULL)
1799 goto fail;
1800 pos++;
1801
1802 /* Uplink Load */
1803 wan_metrics[10] = atoi(pos);
1804 pos = os_strchr(pos, ':');
1805 if (pos == NULL)
1806 goto fail;
1807 pos++;
1808
1809 /* LMD */
1810 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1811
1812 os_free(bss->hs20_wan_metrics);
1813 bss->hs20_wan_metrics = wan_metrics;
1814
1815 return 0;
1816
1817fail:
1818 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001819 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001820 os_free(wan_metrics);
1821 return -1;
1822}
1823
1824
1825static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1826 char *pos, int line)
1827{
1828 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1829 &bss->hs20_oper_friendly_name_count, pos)) {
1830 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1831 "hs20_oper_friendly_name '%s'", line, pos);
1832 return -1;
1833 }
1834 return 0;
1835}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001836
1837
1838static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1839{
1840 struct hs20_icon *icon;
1841 char *end;
1842
1843 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1844 sizeof(struct hs20_icon));
1845 if (icon == NULL)
1846 return -1;
1847 bss->hs20_icons = icon;
1848 icon = &bss->hs20_icons[bss->hs20_icons_count];
1849 os_memset(icon, 0, sizeof(*icon));
1850
1851 icon->width = atoi(pos);
1852 pos = os_strchr(pos, ':');
1853 if (pos == NULL)
1854 return -1;
1855 pos++;
1856
1857 icon->height = atoi(pos);
1858 pos = os_strchr(pos, ':');
1859 if (pos == NULL)
1860 return -1;
1861 pos++;
1862
1863 end = os_strchr(pos, ':');
1864 if (end == NULL || end - pos > 3)
1865 return -1;
1866 os_memcpy(icon->language, pos, end - pos);
1867 pos = end + 1;
1868
1869 end = os_strchr(pos, ':');
1870 if (end == NULL || end - pos > 255)
1871 return -1;
1872 os_memcpy(icon->type, 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->name, pos, end - pos);
1879 pos = end + 1;
1880
1881 if (os_strlen(pos) > 255)
1882 return -1;
1883 os_memcpy(icon->file, pos, os_strlen(pos));
1884
1885 bss->hs20_icons_count++;
1886
1887 return 0;
1888}
1889
1890
1891static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1892 char *pos, int line)
1893{
1894 size_t slen;
1895 char *str;
1896
1897 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001898 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001899 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001900 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001901 return -1;
1902 }
1903
1904 os_memcpy(bss->osu_ssid, str, slen);
1905 bss->osu_ssid_len = slen;
1906 os_free(str);
1907
1908 return 0;
1909}
1910
1911
1912static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1913 char *pos, int line)
1914{
1915 struct hs20_osu_provider *p;
1916
1917 p = os_realloc_array(bss->hs20_osu_providers,
1918 bss->hs20_osu_providers_count + 1, sizeof(*p));
1919 if (p == NULL)
1920 return -1;
1921
1922 bss->hs20_osu_providers = p;
1923 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1924 bss->hs20_osu_providers_count++;
1925 os_memset(bss->last_osu, 0, sizeof(*p));
1926 bss->last_osu->server_uri = os_strdup(pos);
1927
1928 return 0;
1929}
1930
1931
1932static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1933 char *pos, int line)
1934{
1935 if (bss->last_osu == NULL) {
1936 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1937 return -1;
1938 }
1939
1940 if (parse_lang_string(&bss->last_osu->friendly_name,
1941 &bss->last_osu->friendly_name_count, pos)) {
1942 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1943 line, pos);
1944 return -1;
1945 }
1946
1947 return 0;
1948}
1949
1950
1951static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1952 char *pos, int line)
1953{
1954 if (bss->last_osu == NULL) {
1955 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1956 return -1;
1957 }
1958
1959 os_free(bss->last_osu->osu_nai);
1960 bss->last_osu->osu_nai = os_strdup(pos);
1961 if (bss->last_osu->osu_nai == NULL)
1962 return -1;
1963
1964 return 0;
1965}
1966
1967
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001968static int hs20_parse_osu_nai2(struct hostapd_bss_config *bss,
1969 char *pos, int line)
1970{
1971 if (bss->last_osu == NULL) {
1972 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1973 return -1;
1974 }
1975
1976 os_free(bss->last_osu->osu_nai2);
1977 bss->last_osu->osu_nai2 = os_strdup(pos);
1978 if (bss->last_osu->osu_nai2 == NULL)
1979 return -1;
1980 bss->hs20_osu_providers_nai_count++;
1981
1982 return 0;
1983}
1984
1985
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001986static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1987 int line)
1988{
1989 if (bss->last_osu == NULL) {
1990 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1991 return -1;
1992 }
1993
1994 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1995 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1996 return -1;
1997 }
1998
1999 return 0;
2000}
2001
2002
2003static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
2004 int line)
2005{
2006 char **n;
2007 struct hs20_osu_provider *p = bss->last_osu;
2008
2009 if (p == NULL) {
2010 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2011 return -1;
2012 }
2013
2014 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
2015 if (n == NULL)
2016 return -1;
2017 p->icons = n;
2018 p->icons[p->icons_count] = os_strdup(pos);
2019 if (p->icons[p->icons_count] == NULL)
2020 return -1;
2021 p->icons_count++;
2022
2023 return 0;
2024}
2025
2026
2027static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
2028 char *pos, int line)
2029{
2030 if (bss->last_osu == NULL) {
2031 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2032 return -1;
2033 }
2034
2035 if (parse_lang_string(&bss->last_osu->service_desc,
2036 &bss->last_osu->service_desc_count, pos)) {
2037 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
2038 line, pos);
2039 return -1;
2040 }
2041
2042 return 0;
2043}
2044
Roshan Pius3a1667e2018-07-03 15:17:14 -07002045
2046static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
2047 int line)
2048{
2049 char **n;
2050
2051 n = os_realloc_array(bss->hs20_operator_icon,
2052 bss->hs20_operator_icon_count + 1, sizeof(char *));
2053 if (!n)
2054 return -1;
2055 bss->hs20_operator_icon = n;
2056 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
2057 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
2058 return -1;
2059 bss->hs20_operator_icon_count++;
2060
2061 return 0;
2062}
2063
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002064#endif /* CONFIG_HS20 */
2065
2066
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002067#ifdef CONFIG_ACS
2068static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
2069 char *pos)
2070{
2071 struct acs_bias *bias = NULL, *tmp;
2072 unsigned int num = 0;
2073 char *end;
2074
2075 while (*pos) {
2076 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2077 if (!tmp)
2078 goto fail;
2079 bias = tmp;
2080
2081 bias[num].channel = atoi(pos);
2082 if (bias[num].channel <= 0)
2083 goto fail;
2084 pos = os_strchr(pos, ':');
2085 if (!pos)
2086 goto fail;
2087 pos++;
2088 bias[num].bias = strtod(pos, &end);
2089 if (end == pos || bias[num].bias < 0.0)
2090 goto fail;
2091 pos = end;
2092 if (*pos != ' ' && *pos != '\0')
2093 goto fail;
2094 num++;
2095 }
2096
2097 os_free(conf->acs_chan_bias);
2098 conf->acs_chan_bias = bias;
2099 conf->num_acs_chan_bias = num;
2100
2101 return 0;
2102fail:
2103 os_free(bias);
2104 return -1;
2105}
2106#endif /* CONFIG_ACS */
2107
2108
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002109static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2110 const char *val)
2111{
2112 struct wpabuf *elems;
2113
2114 if (val[0] == '\0') {
2115 wpabuf_free(*buf);
2116 *buf = NULL;
2117 return 0;
2118 }
2119
2120 elems = wpabuf_parse_bin(val);
2121 if (!elems) {
2122 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2123 line, name, val);
2124 return -1;
2125 }
2126
2127 wpabuf_free(*buf);
2128 *buf = elems;
2129
2130 return 0;
2131}
2132
2133
Dmitry Shmidt29333592017-01-09 12:27:11 -08002134#ifdef CONFIG_FILS
2135static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2136{
2137 struct fils_realm *realm;
2138 size_t len;
2139
2140 len = os_strlen(val);
2141 realm = os_zalloc(sizeof(*realm) + len + 1);
2142 if (!realm)
2143 return -1;
2144
2145 os_memcpy(realm->realm, val, len);
2146 if (fils_domain_name_hash(val, realm->hash) < 0) {
2147 os_free(realm);
2148 return -1;
2149 }
2150 dl_list_add_tail(&bss->fils_realms, &realm->list);
2151
2152 return 0;
2153}
2154#endif /* CONFIG_FILS */
2155
2156
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002157#ifdef EAP_SERVER
2158static unsigned int parse_tls_flags(const char *val)
2159{
2160 unsigned int flags = 0;
2161
Roshan Pius3a1667e2018-07-03 15:17:14 -07002162 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2163 * This can be enabled by default once the implementation has been fully
2164 * completed and tested with other implementations. */
2165 flags |= TLS_CONN_DISABLE_TLSv1_3;
2166
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002167 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2168 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2169 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2170 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2171 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2172 flags |= TLS_CONN_DISABLE_TLSv1_0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002173 if (os_strstr(val, "[ENABLE-TLSv1.0]"))
2174 flags |= TLS_CONN_ENABLE_TLSv1_0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002175 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2176 flags |= TLS_CONN_DISABLE_TLSv1_1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002177 if (os_strstr(val, "[ENABLE-TLSv1.1]"))
2178 flags |= TLS_CONN_ENABLE_TLSv1_1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002179 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2180 flags |= TLS_CONN_DISABLE_TLSv1_2;
Hai Shalom74f70d42019-02-11 14:42:39 -08002181 if (os_strstr(val, "[ENABLE-TLSv1.2]"))
2182 flags |= TLS_CONN_ENABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002183 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2184 flags |= TLS_CONN_DISABLE_TLSv1_3;
2185 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2186 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002187 if (os_strstr(val, "[SUITEB]"))
2188 flags |= TLS_CONN_SUITEB;
2189 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2190 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2191
2192 return flags;
2193}
2194#endif /* EAP_SERVER */
2195
2196
Hai Shalom81f62d82019-07-22 12:10:00 -07002197#ifdef CONFIG_AIRTIME_POLICY
2198static int add_airtime_weight(struct hostapd_bss_config *bss, char *value)
2199{
2200 struct airtime_sta_weight *wt;
2201 char *pos, *next;
2202
2203 wt = os_zalloc(sizeof(*wt));
2204 if (!wt)
2205 return -1;
2206
2207 /* 02:01:02:03:04:05 10 */
2208 pos = value;
2209 next = os_strchr(pos, ' ');
2210 if (next)
2211 *next++ = '\0';
2212 if (!next || hwaddr_aton(pos, wt->addr)) {
2213 wpa_printf(MSG_ERROR, "Invalid station address: '%s'", pos);
2214 os_free(wt);
2215 return -1;
2216 }
2217
2218 pos = next;
2219 wt->weight = atoi(pos);
2220 if (!wt->weight) {
2221 wpa_printf(MSG_ERROR, "Invalid weight: '%s'", pos);
2222 os_free(wt);
2223 return -1;
2224 }
2225
2226 wt->next = bss->airtime_weight_list;
2227 bss->airtime_weight_list = wt;
2228 return 0;
2229}
2230#endif /* CONFIG_AIRTIME_POLICY */
2231
2232
Roshan Pius3a1667e2018-07-03 15:17:14 -07002233#ifdef CONFIG_SAE
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002234
Roshan Pius3a1667e2018-07-03 15:17:14 -07002235static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2236{
2237 struct sae_password_entry *pw;
2238 const char *pos = val, *pos2, *end = NULL;
2239
2240 pw = os_zalloc(sizeof(*pw));
2241 if (!pw)
2242 return -1;
2243 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2244
2245 pos2 = os_strstr(pos, "|mac=");
2246 if (pos2) {
2247 end = pos2;
2248 pos2 += 5;
2249 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2250 goto fail;
2251 pos = pos2 + ETH_ALEN * 3 - 1;
2252 }
2253
Hai Shalom021b0b52019-04-10 11:17:58 -07002254 pos2 = os_strstr(pos, "|vlanid=");
2255 if (pos2) {
2256 if (!end)
2257 end = pos2;
2258 pos2 += 8;
2259 pw->vlan_id = atoi(pos2);
2260 }
2261
Hai Shalom899fcc72020-10-19 14:38:18 -07002262#ifdef CONFIG_SAE_PK
2263 pos2 = os_strstr(pos, "|pk=");
2264 if (pos2) {
2265 const char *epos;
2266 char *tmp;
2267
2268 if (!end)
2269 end = pos2;
2270 pos2 += 4;
2271 epos = os_strchr(pos2, '|');
2272 if (epos) {
2273 tmp = os_malloc(epos - pos2 + 1);
2274 if (!tmp)
2275 goto fail;
2276 os_memcpy(tmp, pos2, epos - pos2);
2277 tmp[epos - pos2] = '\0';
2278 } else {
2279 tmp = os_strdup(pos2);
2280 if (!tmp)
2281 goto fail;
2282 }
2283
2284 pw->pk = sae_parse_pk(tmp);
2285 str_clear_free(tmp);
2286 if (!pw->pk)
2287 goto fail;
2288 }
2289#endif /* CONFIG_SAE_PK */
2290
Roshan Pius3a1667e2018-07-03 15:17:14 -07002291 pos2 = os_strstr(pos, "|id=");
2292 if (pos2) {
2293 if (!end)
2294 end = pos2;
2295 pos2 += 4;
2296 pw->identifier = os_strdup(pos2);
2297 if (!pw->identifier)
2298 goto fail;
2299 }
2300
2301 if (!end) {
2302 pw->password = os_strdup(val);
2303 if (!pw->password)
2304 goto fail;
2305 } else {
2306 pw->password = os_malloc(end - val + 1);
2307 if (!pw->password)
2308 goto fail;
2309 os_memcpy(pw->password, val, end - val);
2310 pw->password[end - val] = '\0';
2311 }
2312
Hai Shalom899fcc72020-10-19 14:38:18 -07002313#ifdef CONFIG_SAE_PK
2314 if (pw->pk &&
2315#ifdef CONFIG_TESTING_OPTIONS
2316 !bss->sae_pk_password_check_skip &&
2317#endif /* CONFIG_TESTING_OPTIONS */
2318 !sae_pk_valid_password(pw->password)) {
2319 wpa_printf(MSG_INFO,
2320 "Invalid SAE password for a SAE-PK sae_password entry");
2321 goto fail;
2322 }
2323#endif /* CONFIG_SAE_PK */
2324
Roshan Pius3a1667e2018-07-03 15:17:14 -07002325 pw->next = bss->sae_passwords;
2326 bss->sae_passwords = pw;
2327
2328 return 0;
2329fail:
2330 str_clear_free(pw->password);
2331 os_free(pw->identifier);
Hai Shalom899fcc72020-10-19 14:38:18 -07002332#ifdef CONFIG_SAE_PK
2333 sae_deinit_pk(pw->pk);
2334#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002335 os_free(pw);
2336 return -1;
2337}
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002338
2339
2340static int parse_sae_password_file(struct hostapd_bss_config *bss,
2341 const char *fname)
2342{
2343 FILE *f;
2344 char buf[500], *pos;
2345 unsigned int line = 0;
2346
2347 f = fopen(fname, "r");
2348 if (!f) {
2349 wpa_printf(MSG_ERROR, "sae_password_file '%s' not found.",
2350 fname);
2351 return -1;
2352 }
2353
2354 while (fgets(buf, sizeof(buf), f)) {
2355 pos = os_strchr(buf, '\n');
2356 if (pos)
2357 *pos = '\0';
2358 line++;
2359 if (parse_sae_password(bss, buf)) {
2360 wpa_printf(MSG_ERROR,
2361 "Invalid SAE password at line %d in '%s'",
2362 line, fname);
2363 fclose(f);
2364 return -1;
2365 }
2366 }
2367
2368 fclose(f);
2369 return 0;
2370}
2371
Roshan Pius3a1667e2018-07-03 15:17:14 -07002372#endif /* CONFIG_SAE */
2373
2374
Hai Shalom81f62d82019-07-22 12:10:00 -07002375#ifdef CONFIG_DPP2
2376static int hostapd_dpp_controller_parse(struct hostapd_bss_config *bss,
2377 const char *pos)
2378{
2379 struct dpp_controller_conf *conf;
2380 char *val;
2381
2382 conf = os_zalloc(sizeof(*conf));
2383 if (!conf)
2384 return -1;
2385 val = get_param(pos, "ipaddr=");
2386 if (!val || hostapd_parse_ip_addr(val, &conf->ipaddr))
2387 goto fail;
2388 os_free(val);
2389 val = get_param(pos, "pkhash=");
2390 if (!val || os_strlen(val) != 2 * SHA256_MAC_LEN ||
2391 hexstr2bin(val, conf->pkhash, SHA256_MAC_LEN) < 0)
2392 goto fail;
2393 os_free(val);
2394 conf->next = bss->dpp_controller;
2395 bss->dpp_controller = conf;
2396 return 0;
2397fail:
2398 os_free(val);
2399 os_free(conf);
2400 return -1;
2401}
2402#endif /* CONFIG_DPP2 */
2403
2404
Hai Shaloma20dcd72022-02-04 13:43:00 -08002405static int get_hex_config(u8 *buf, size_t max_len, int line,
2406 const char *field, const char *val)
2407{
2408 size_t hlen = os_strlen(val), len = hlen / 2;
2409 u8 tmp[EXT_CAPA_MAX_LEN];
2410
2411 os_memset(tmp, 0, EXT_CAPA_MAX_LEN);
2412 if (hlen & 1 || len > EXT_CAPA_MAX_LEN || hexstr2bin(val, tmp, len)) {
2413 wpa_printf(MSG_ERROR, "Line %d: Invalid %s", line, field);
2414 return -1;
2415 }
2416 os_memcpy(buf, tmp, EXT_CAPA_MAX_LEN);
2417 return 0;
2418}
2419
2420
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002421#ifdef CONFIG_IEEE80211BE
2422static int get_u16(const char *pos, int line, u16 *ret_val)
2423{
2424 char *end;
2425 long int val = strtol(pos, &end, 0);
2426
2427 if (*end || val < 0 || val > 0xffff) {
2428 wpa_printf(MSG_ERROR, "Line %d: Invalid value '%s'",
2429 line, pos);
2430 return -1;
2431 }
2432
2433 *ret_val = val;
2434 return 0;
2435}
2436#endif /* CONFIG_IEEE80211BE */
2437
2438
Sunil Ravic0f5d412024-09-11 22:12:49 +00002439#ifdef CONFIG_TESTING_OPTIONS
2440static bool get_hexstream(const char *val, struct wpabuf **var,
2441 const char *name, int line)
2442{
2443 struct wpabuf *tmp;
2444 size_t len = os_strlen(val) / 2;
2445
2446 tmp = wpabuf_alloc(len);
2447 if (!tmp)
2448 return false;
2449
2450 if (hexstr2bin(val, wpabuf_put(tmp, len), len)) {
2451 wpabuf_free(tmp);
2452 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2453 line, name, val);
2454 return false;
2455 }
2456
2457 wpabuf_free(*var);
2458 *var = tmp;
2459 return true;
2460}
2461#endif /* CONFIG_TESTING_OPTIONS */
2462
2463
Dmitry Shmidt04949592012-07-19 12:16:46 -07002464static int hostapd_config_fill(struct hostapd_config *conf,
2465 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002466 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002467{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002468 if (os_strcmp(buf, "interface") == 0) {
2469 os_strlcpy(conf->bss[0]->iface, pos,
2470 sizeof(conf->bss[0]->iface));
2471 } else if (os_strcmp(buf, "bridge") == 0) {
2472 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
Sunil Ravi036cec52023-03-29 11:35:17 -07002473 } else if (os_strcmp(buf, "bridge_hairpin") == 0) {
2474 bss->bridge_hairpin = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002475 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2476 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2477 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2478 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2479 } else if (os_strcmp(buf, "driver") == 0) {
2480 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002481 const struct wpa_driver_ops *driver = NULL;
2482
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002483 for (j = 0; wpa_drivers[j]; j++) {
2484 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002485 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002486 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002487 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002488 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002489 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002490 wpa_printf(MSG_ERROR,
2491 "Line %d: invalid/unknown driver '%s'",
2492 line, pos);
2493 return 1;
2494 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002495 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002496 } else if (os_strcmp(buf, "driver_params") == 0) {
2497 os_free(conf->driver_params);
2498 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002499 } else if (os_strcmp(buf, "debug") == 0) {
2500 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2501 line);
2502 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2503 bss->logger_syslog_level = atoi(pos);
2504 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2505 bss->logger_stdout_level = atoi(pos);
2506 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2507 bss->logger_syslog = atoi(pos);
2508 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2509 bss->logger_stdout = atoi(pos);
2510 } else if (os_strcmp(buf, "dump_file") == 0) {
2511 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2512 line);
2513 } else if (os_strcmp(buf, "ssid") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002514 struct hostapd_ssid *ssid = &bss->ssid;
2515
2516 ssid->ssid_len = os_strlen(pos);
2517 if (ssid->ssid_len > SSID_MAX_LEN || ssid->ssid_len < 1) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002518 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2519 line, pos);
2520 return 1;
2521 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002522 os_memcpy(ssid->ssid, pos, ssid->ssid_len);
2523 ssid->ssid_set = 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07002524 ssid->short_ssid = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002525 } else if (os_strcmp(buf, "ssid2") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002526 struct hostapd_ssid *ssid = &bss->ssid;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002527 size_t slen;
2528 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002529 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002530 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2531 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002532 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002533 return 1;
2534 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002535 os_memcpy(ssid->ssid, str, slen);
2536 ssid->ssid_len = slen;
2537 ssid->ssid_set = 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07002538 ssid->short_ssid = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002539 os_free(str);
2540 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2541 bss->ssid.utf8_ssid = atoi(pos) > 0;
2542 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002543 enum macaddr_acl acl = atoi(pos);
2544
2545 if (acl != ACCEPT_UNLESS_DENIED &&
2546 acl != DENY_UNLESS_ACCEPTED &&
2547 acl != USE_EXTERNAL_RADIUS_AUTH) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002548 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002549 line, acl);
2550 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002551 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002552 bss->macaddr_acl = acl;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002553 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2554 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2555 &bss->num_accept_mac)) {
2556 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2557 line, pos);
2558 return 1;
2559 }
2560 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2561 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2562 &bss->num_deny_mac)) {
2563 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2564 line, pos);
2565 return 1;
2566 }
2567 } else if (os_strcmp(buf, "wds_sta") == 0) {
2568 bss->wds_sta = atoi(pos);
2569 } else if (os_strcmp(buf, "start_disabled") == 0) {
2570 bss->start_disabled = atoi(pos);
2571 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2572 bss->isolate = atoi(pos);
2573 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2574 bss->ap_max_inactivity = atoi(pos);
2575 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2576 bss->skip_inactivity_poll = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00002577 } else if (os_strcmp(buf, "bss_max_idle") == 0) {
2578 int val = atoi(pos);
2579
2580 if (val < 0 || val > 2) {
2581 wpa_printf(MSG_ERROR,
2582 "Line %d: Invalid bss_max_idle value", line);
2583 return 1;
2584 }
2585 bss->bss_max_idle = val;
2586 } else if (os_strcmp(buf, "max_acceptable_idle_period") == 0) {
2587 bss->max_acceptable_idle_period = atoi(pos);
2588 } else if (os_strcmp(buf, "no_disconnect_on_group_keyerror") == 0) {
2589 int val = atoi(pos);
2590
2591 if (val < 0 || val > 1) {
2592 wpa_printf(MSG_ERROR,
2593 "Line %d: Invalid no_disconnect_on_group_keyerror",
2594 line);
2595 return 1;
2596 }
2597 bss->no_disconnect_on_group_keyerror = val;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002598 } else if (os_strcmp(buf, "config_id") == 0) {
2599 os_free(bss->config_id);
2600 bss->config_id = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002601 } else if (os_strcmp(buf, "country_code") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002602 if (pos[0] < 'A' || pos[0] > 'Z' ||
2603 pos[1] < 'A' || pos[1] > 'Z') {
2604 wpa_printf(MSG_ERROR,
2605 "Line %d: Invalid country_code '%s'",
2606 line, pos);
2607 return 1;
2608 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002609 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002610 } else if (os_strcmp(buf, "country3") == 0) {
2611 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002612 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2613 conf->ieee80211d = atoi(pos);
2614 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2615 conf->ieee80211h = atoi(pos);
2616 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2617 bss->ieee802_1x = atoi(pos);
2618 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002619 int eapol_version = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002620#ifdef CONFIG_MACSEC
Hai Shaloma20dcd72022-02-04 13:43:00 -08002621 int max_ver = 3;
Hai Shalom81f62d82019-07-22 12:10:00 -07002622#else /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002623 int max_ver = 2;
Hai Shalom81f62d82019-07-22 12:10:00 -07002624#endif /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002625
2626 if (eapol_version < 1 || eapol_version > max_ver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002627 wpa_printf(MSG_ERROR,
2628 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002629 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002630 return 1;
2631 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002632 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002633 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002634#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002635 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2636 bss->eap_server = atoi(pos);
2637 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2638 } else if (os_strcmp(buf, "eap_server") == 0) {
2639 bss->eap_server = atoi(pos);
2640 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2641 if (hostapd_config_read_eap_user(pos, bss))
2642 return 1;
2643 } else if (os_strcmp(buf, "ca_cert") == 0) {
2644 os_free(bss->ca_cert);
2645 bss->ca_cert = os_strdup(pos);
2646 } else if (os_strcmp(buf, "server_cert") == 0) {
2647 os_free(bss->server_cert);
2648 bss->server_cert = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002649 } else if (os_strcmp(buf, "server_cert2") == 0) {
2650 os_free(bss->server_cert2);
2651 bss->server_cert2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002652 } else if (os_strcmp(buf, "private_key") == 0) {
2653 os_free(bss->private_key);
2654 bss->private_key = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002655 } else if (os_strcmp(buf, "private_key2") == 0) {
2656 os_free(bss->private_key2);
2657 bss->private_key2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002658 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2659 os_free(bss->private_key_passwd);
2660 bss->private_key_passwd = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002661 } else if (os_strcmp(buf, "private_key_passwd2") == 0) {
2662 os_free(bss->private_key_passwd2);
2663 bss->private_key_passwd2 = os_strdup(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07002664 } else if (os_strcmp(buf, "check_cert_subject") == 0) {
2665 if (!pos[0]) {
2666 wpa_printf(MSG_ERROR, "Line %d: unknown check_cert_subject '%s'",
2667 line, pos);
2668 return 1;
2669 }
2670 os_free(bss->check_cert_subject);
2671 bss->check_cert_subject = os_strdup(pos);
2672 if (!bss->check_cert_subject)
2673 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002674 } else if (os_strcmp(buf, "check_crl") == 0) {
2675 bss->check_crl = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002676 } else if (os_strcmp(buf, "check_crl_strict") == 0) {
2677 bss->check_crl_strict = atoi(pos);
2678 } else if (os_strcmp(buf, "crl_reload_interval") == 0) {
2679 bss->crl_reload_interval = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002680 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2681 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002682 } else if (os_strcmp(buf, "tls_flags") == 0) {
2683 bss->tls_flags = parse_tls_flags(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002684 } else if (os_strcmp(buf, "max_auth_rounds") == 0) {
2685 bss->max_auth_rounds = atoi(pos);
2686 } else if (os_strcmp(buf, "max_auth_rounds_short") == 0) {
2687 bss->max_auth_rounds_short = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002688 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2689 os_free(bss->ocsp_stapling_response);
2690 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002691 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2692 os_free(bss->ocsp_stapling_response_multi);
2693 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002694 } else if (os_strcmp(buf, "dh_file") == 0) {
2695 os_free(bss->dh_file);
2696 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002697 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2698 os_free(bss->openssl_ciphers);
2699 bss->openssl_ciphers = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002700 } else if (os_strcmp(buf, "openssl_ecdh_curves") == 0) {
2701 os_free(bss->openssl_ecdh_curves);
2702 bss->openssl_ecdh_curves = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002703 } else if (os_strcmp(buf, "fragment_size") == 0) {
2704 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002705#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002706 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2707 os_free(bss->pac_opaque_encr_key);
2708 bss->pac_opaque_encr_key = os_malloc(16);
2709 if (bss->pac_opaque_encr_key == NULL) {
2710 wpa_printf(MSG_ERROR,
2711 "Line %d: No memory for pac_opaque_encr_key",
2712 line);
2713 return 1;
2714 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2715 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2716 line);
2717 return 1;
2718 }
2719 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2720 size_t idlen = os_strlen(pos);
2721 if (idlen & 1) {
2722 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2723 line);
2724 return 1;
2725 }
2726 os_free(bss->eap_fast_a_id);
2727 bss->eap_fast_a_id = os_malloc(idlen / 2);
2728 if (bss->eap_fast_a_id == NULL ||
2729 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2730 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2731 line);
2732 os_free(bss->eap_fast_a_id);
2733 bss->eap_fast_a_id = NULL;
2734 return 1;
2735 } else {
2736 bss->eap_fast_a_id_len = idlen / 2;
2737 }
2738 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2739 os_free(bss->eap_fast_a_id_info);
2740 bss->eap_fast_a_id_info = os_strdup(pos);
2741 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2742 bss->eap_fast_prov = atoi(pos);
2743 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2744 bss->pac_key_lifetime = atoi(pos);
2745 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2746 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002747#endif /* EAP_SERVER_FAST */
Hai Shalom81f62d82019-07-22 12:10:00 -07002748#ifdef EAP_SERVER_TEAP
2749 } else if (os_strcmp(buf, "eap_teap_auth") == 0) {
2750 int val = atoi(pos);
2751
Hai Shalom899fcc72020-10-19 14:38:18 -07002752 if (val < 0 || val > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002753 wpa_printf(MSG_ERROR,
2754 "Line %d: Invalid eap_teap_auth value",
2755 line);
2756 return 1;
2757 }
2758 bss->eap_teap_auth = val;
2759 } else if (os_strcmp(buf, "eap_teap_pac_no_inner") == 0) {
2760 bss->eap_teap_pac_no_inner = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002761 } else if (os_strcmp(buf, "eap_teap_separate_result") == 0) {
2762 bss->eap_teap_separate_result = atoi(pos);
2763 } else if (os_strcmp(buf, "eap_teap_id") == 0) {
2764 bss->eap_teap_id = atoi(pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002765 } else if (os_strcmp(buf, "eap_teap_method_sequence") == 0) {
2766 bss->eap_teap_method_sequence = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002767#endif /* EAP_SERVER_TEAP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002769 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2770 os_free(bss->eap_sim_db);
2771 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002772 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2773 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002774 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2775 bss->eap_sim_aka_result_ind = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002776 } else if (os_strcmp(buf, "eap_sim_id") == 0) {
2777 bss->eap_sim_id = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07002778 } else if (os_strcmp(buf, "imsi_privacy_key") == 0) {
2779 os_free(bss->imsi_privacy_key);
2780 bss->imsi_privacy_key = os_strdup(pos);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002781 } else if (os_strcmp(buf, "eap_sim_aka_fast_reauth_limit") == 0) {
2782 bss->eap_sim_aka_fast_reauth_limit = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783#endif /* EAP_SERVER_SIM */
2784#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002785 } else if (os_strcmp(buf, "tnc") == 0) {
2786 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002787#endif /* EAP_SERVER_TNC */
2788#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002789 } else if (os_strcmp(buf, "pwd_group") == 0) {
2790 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002791#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002792#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002793 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2794 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002795#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002796#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002797 } else if (os_strcmp(buf, "eap_message") == 0) {
2798 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002799 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002800 bss->eap_req_id_text = os_strdup(pos);
2801 if (bss->eap_req_id_text == NULL) {
2802 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2803 line);
2804 return 1;
2805 }
2806 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2807 term = os_strstr(bss->eap_req_id_text, "\\0");
2808 if (term) {
2809 *term++ = '\0';
2810 os_memmove(term, term + 1,
2811 bss->eap_req_id_text_len -
2812 (term - bss->eap_req_id_text) - 1);
2813 bss->eap_req_id_text_len--;
2814 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002815 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2816 bss->erp_send_reauth_start = atoi(pos);
2817 } else if (os_strcmp(buf, "erp_domain") == 0) {
2818 os_free(bss->erp_domain);
2819 bss->erp_domain = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002820#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002821 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002822 int val = atoi(pos);
2823
2824 if (val < 0 || val > 13) {
2825 wpa_printf(MSG_ERROR,
2826 "Line %d: invalid WEP key len %d (= %d bits)",
2827 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002828 return 1;
2829 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002830 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002831 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002832 int val = atoi(pos);
2833
2834 if (val < 0 || val > 13) {
2835 wpa_printf(MSG_ERROR,
2836 "Line %d: invalid WEP key len %d (= %d bits)",
2837 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002838 return 1;
2839 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002840 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002841 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2842 bss->wep_rekeying_period = atoi(pos);
2843 if (bss->wep_rekeying_period < 0) {
2844 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2845 line, bss->wep_rekeying_period);
2846 return 1;
2847 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002848#endif /* CONFIG_WEP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002849 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2850 bss->eap_reauth_period = atoi(pos);
2851 if (bss->eap_reauth_period < 0) {
2852 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2853 line, bss->eap_reauth_period);
2854 return 1;
2855 }
2856 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2857 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002859 } else if (os_strcmp(buf, "iapp_interface") == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07002860 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002862 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2863 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2864 wpa_printf(MSG_ERROR,
2865 "Line %d: invalid IP address '%s'",
2866 line, pos);
2867 return 1;
2868 }
2869 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002870 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002871 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002873 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2874 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2875 wpa_printf(MSG_ERROR,
2876 "Line %d: invalid IP address '%s'",
2877 line, pos);
2878 return 1;
2879 }
2880 bss->radius->force_client_addr = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002881 } else if (os_strcmp(buf, "radius_client_dev") == 0) {
2882 os_free(bss->radius->force_client_dev);
2883 bss->radius->force_client_dev = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002884 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2885 if (hostapd_config_read_radius_addr(
2886 &bss->radius->auth_servers,
2887 &bss->radius->num_auth_servers, pos, 1812,
2888 &bss->radius->auth_server)) {
2889 wpa_printf(MSG_ERROR,
2890 "Line %d: invalid IP address '%s'",
2891 line, pos);
2892 return 1;
2893 }
2894 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002895 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2896 if (hostapd_parse_ip_addr(pos,
2897 &bss->radius->auth_server->addr)) {
2898 wpa_printf(MSG_ERROR,
2899 "Line %d: invalid IP address '%s'",
2900 line, pos);
2901 return 1;
2902 }
2903 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002904 os_strcmp(buf, "auth_server_port") == 0) {
2905 bss->radius->auth_server->port = atoi(pos);
2906 } else if (bss->radius->auth_server &&
2907 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2908 int len = os_strlen(pos);
2909 if (len == 0) {
2910 /* RFC 2865, Ch. 3 */
2911 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2912 line);
2913 return 1;
2914 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002915 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002916 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2917 bss->radius->auth_server->shared_secret_len = len;
Sunil Ravi99c035e2024-07-12 01:42:03 +00002918 } else if (bss->radius->auth_server &&
2919 os_strcmp(buf, "auth_server_type") == 0) {
2920 if (os_strcmp(pos, "UDP") == 0) {
2921 bss->radius->auth_server->tls = false;
2922#ifdef CONFIG_RADIUS_TLS
2923 } else if (os_strcmp(pos, "TLS") == 0) {
2924 bss->radius->auth_server->tls = true;
2925#endif /* CONFIG_RADIUS_TLS */
2926 } else {
2927 wpa_printf(MSG_ERROR, "Line %d: unsupported RADIUS type '%s'",
2928 line, pos);
2929 return 1;
2930 }
2931#ifdef CONFIG_RADIUS_TLS
2932 } else if (bss->radius->auth_server &&
2933 os_strcmp(buf, "auth_server_ca_cert") == 0) {
2934 os_free(bss->radius->auth_server->ca_cert);
2935 bss->radius->auth_server->ca_cert = os_strdup(pos);
2936 } else if (bss->radius->auth_server &&
2937 os_strcmp(buf, "auth_server_client_cert") == 0) {
2938 os_free(bss->radius->auth_server->client_cert);
2939 bss->radius->auth_server->client_cert = os_strdup(pos);
2940 } else if (bss->radius->auth_server &&
2941 os_strcmp(buf, "auth_server_private_key") == 0) {
2942 os_free(bss->radius->auth_server->private_key);
2943 bss->radius->auth_server->private_key = os_strdup(pos);
2944 } else if (bss->radius->auth_server &&
2945 os_strcmp(buf, "auth_server_private_key_passwd") == 0) {
2946 os_free(bss->radius->auth_server->private_key_passwd);
2947 bss->radius->auth_server->private_key_passwd = os_strdup(pos);
2948#endif /* CONFIG_RADIUS_TLS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002949 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2950 if (hostapd_config_read_radius_addr(
2951 &bss->radius->acct_servers,
2952 &bss->radius->num_acct_servers, pos, 1813,
2953 &bss->radius->acct_server)) {
2954 wpa_printf(MSG_ERROR,
2955 "Line %d: invalid IP address '%s'",
2956 line, pos);
2957 return 1;
2958 }
2959 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002960 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2961 if (hostapd_parse_ip_addr(pos,
2962 &bss->radius->acct_server->addr)) {
2963 wpa_printf(MSG_ERROR,
2964 "Line %d: invalid IP address '%s'",
2965 line, pos);
2966 return 1;
2967 }
2968 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002969 os_strcmp(buf, "acct_server_port") == 0) {
2970 bss->radius->acct_server->port = atoi(pos);
2971 } else if (bss->radius->acct_server &&
2972 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2973 int len = os_strlen(pos);
2974 if (len == 0) {
2975 /* RFC 2865, Ch. 3 */
2976 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2977 line);
2978 return 1;
2979 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002980 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002981 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2982 bss->radius->acct_server->shared_secret_len = len;
Sunil Ravi99c035e2024-07-12 01:42:03 +00002983 } else if (bss->radius->acct_server &&
2984 os_strcmp(buf, "acct_server_type") == 0) {
2985 if (os_strcmp(pos, "UDP") == 0) {
2986 bss->radius->acct_server->tls = false;
2987#ifdef CONFIG_RADIUS_TLS
2988 } else if (os_strcmp(pos, "TLS") == 0) {
2989 bss->radius->acct_server->tls = true;
2990#endif /* CONFIG_RADIUS_TLS */
2991 } else {
2992 wpa_printf(MSG_ERROR, "Line %d: unsupported RADIUS type '%s'",
2993 line, pos);
2994 return 1;
2995 }
2996#ifdef CONFIG_RADIUS_TLS
2997 } else if (bss->radius->acct_server &&
2998 os_strcmp(buf, "acct_server_ca_cert") == 0) {
2999 os_free(bss->radius->acct_server->ca_cert);
3000 bss->radius->acct_server->ca_cert = os_strdup(pos);
3001 } else if (bss->radius->acct_server &&
3002 os_strcmp(buf, "acct_server_client_cert") == 0) {
3003 os_free(bss->radius->acct_server->client_cert);
3004 bss->radius->acct_server->client_cert = os_strdup(pos);
3005 } else if (bss->radius->acct_server &&
3006 os_strcmp(buf, "acct_server_private_key") == 0) {
3007 os_free(bss->radius->acct_server->private_key);
3008 bss->radius->acct_server->private_key = os_strdup(pos);
3009 } else if (bss->radius->acct_server &&
3010 os_strcmp(buf, "acct_server_private_key_passwd") == 0) {
3011 os_free(bss->radius->acct_server->private_key_passwd);
3012 bss->radius->acct_server->private_key_passwd = os_strdup(pos);
3013#endif /* CONFIG_RADIUS_TLS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003014 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
3015 bss->radius->retry_primary_interval = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00003016 } else if (os_strcmp(buf,
3017 "radius_require_message_authenticator") == 0) {
3018 bss->radius_require_message_authenticator = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003019 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
3020 bss->acct_interim_interval = atoi(pos);
3021 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
3022 bss->radius_request_cui = atoi(pos);
3023 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
3024 struct hostapd_radius_attr *attr, *a;
3025 attr = hostapd_parse_radius_attr(pos);
3026 if (attr == NULL) {
3027 wpa_printf(MSG_ERROR,
3028 "Line %d: invalid radius_auth_req_attr",
3029 line);
3030 return 1;
3031 } else if (bss->radius_auth_req_attr == NULL) {
3032 bss->radius_auth_req_attr = attr;
3033 } else {
3034 a = bss->radius_auth_req_attr;
3035 while (a->next)
3036 a = a->next;
3037 a->next = attr;
3038 }
3039 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
3040 struct hostapd_radius_attr *attr, *a;
3041 attr = hostapd_parse_radius_attr(pos);
3042 if (attr == NULL) {
3043 wpa_printf(MSG_ERROR,
3044 "Line %d: invalid radius_acct_req_attr",
3045 line);
3046 return 1;
3047 } else if (bss->radius_acct_req_attr == NULL) {
3048 bss->radius_acct_req_attr = attr;
3049 } else {
3050 a = bss->radius_acct_req_attr;
3051 while (a->next)
3052 a = a->next;
3053 a->next = attr;
3054 }
Hai Shalomc3565922019-10-28 11:58:20 -07003055 } else if (os_strcmp(buf, "radius_req_attr_sqlite") == 0) {
3056 os_free(bss->radius_req_attr_sqlite);
3057 bss->radius_req_attr_sqlite = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003058 } else if (os_strcmp(buf, "radius_das_port") == 0) {
3059 bss->radius_das_port = atoi(pos);
3060 } else if (os_strcmp(buf, "radius_das_client") == 0) {
3061 if (hostapd_parse_das_client(bss, pos) < 0) {
3062 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
3063 line);
3064 return 1;
3065 }
3066 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
3067 bss->radius_das_time_window = atoi(pos);
3068 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
3069 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003070 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
3071 0) {
3072 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003074 } else if (os_strcmp(buf, "auth_algs") == 0) {
3075 bss->auth_algs = atoi(pos);
3076 if (bss->auth_algs == 0) {
3077 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
3078 line);
3079 return 1;
3080 }
3081 } else if (os_strcmp(buf, "max_num_sta") == 0) {
3082 bss->max_num_sta = atoi(pos);
3083 if (bss->max_num_sta < 0 ||
3084 bss->max_num_sta > MAX_STA_COUNT) {
3085 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
3086 line, bss->max_num_sta, MAX_STA_COUNT);
3087 return 1;
3088 }
3089 } else if (os_strcmp(buf, "wpa") == 0) {
3090 bss->wpa = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003091 } else if (os_strcmp(buf, "extended_key_id") == 0) {
3092 int val = atoi(pos);
3093
3094 if (val < 0 || val > 2) {
3095 wpa_printf(MSG_ERROR,
3096 "Line %d: Invalid extended_key_id=%d; allowed range 0..2",
3097 line, val);
3098 return 1;
3099 }
3100 bss->extended_key_id = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003101 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
3102 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003103 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003104 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
3105 bss->wpa_strict_rekey = atoi(pos);
3106 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
3107 bss->wpa_gmk_rekey = atoi(pos);
3108 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
3109 bss->wpa_ptk_rekey = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003110 } else if (os_strcmp(buf, "wpa_deny_ptk0_rekey") == 0) {
3111 bss->wpa_deny_ptk0_rekey = atoi(pos);
3112 if (bss->wpa_deny_ptk0_rekey < 0 ||
3113 bss->wpa_deny_ptk0_rekey > 2) {
3114 wpa_printf(MSG_ERROR,
3115 "Line %d: Invalid wpa_deny_ptk0_rekey=%d; allowed range 0..2",
3116 line, bss->wpa_deny_ptk0_rekey);
3117 return 1;
3118 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003119 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
3120 char *endp;
3121 unsigned long val = strtoul(pos, &endp, 0);
3122
3123 if (*endp || val < 1 || val > (u32) -1) {
3124 wpa_printf(MSG_ERROR,
3125 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
3126 line, val);
3127 return 1;
3128 }
3129 bss->wpa_group_update_count = (u32) val;
3130 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
3131 char *endp;
3132 unsigned long val = strtoul(pos, &endp, 0);
3133
3134 if (*endp || val < 1 || val > (u32) -1) {
3135 wpa_printf(MSG_ERROR,
3136 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
3137 line, val);
3138 return 1;
3139 }
3140 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003141 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
3142 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003143 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
3144 int len = os_strlen(pos);
3145 if (len < 8 || len > 63) {
3146 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
3147 line, len);
3148 return 1;
3149 }
3150 os_free(bss->ssid.wpa_passphrase);
3151 bss->ssid.wpa_passphrase = os_strdup(pos);
3152 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003153 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003154 bss->ssid.wpa_passphrase_set = 1;
3155 }
3156 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003157 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003158 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
3159 if (bss->ssid.wpa_psk == NULL)
3160 return 1;
3161 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
3162 pos[PMK_LEN * 2] != '\0') {
3163 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
3164 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003165 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003166 return 1;
3167 }
3168 bss->ssid.wpa_psk->group = 1;
3169 os_free(bss->ssid.wpa_passphrase);
3170 bss->ssid.wpa_passphrase = NULL;
3171 bss->ssid.wpa_psk_set = 1;
3172 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
3173 os_free(bss->ssid.wpa_psk_file);
3174 bss->ssid.wpa_psk_file = os_strdup(pos);
3175 if (!bss->ssid.wpa_psk_file) {
3176 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
3177 line);
3178 return 1;
3179 }
3180 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
3181 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
3182 if (bss->wpa_key_mgmt == -1)
3183 return 1;
Sunil Ravi7f769292024-07-23 22:21:32 +00003184 } else if (os_strcmp(buf, "rsn_override_key_mgmt") == 0) {
3185 bss->rsn_override_key_mgmt =
3186 hostapd_config_parse_key_mgmt(line, pos);
3187 if (bss->rsn_override_key_mgmt == -1)
3188 return 1;
3189 } else if (os_strcmp(buf, "rsn_override_key_mgmt_2") == 0) {
3190 bss->rsn_override_key_mgmt_2 =
3191 hostapd_config_parse_key_mgmt(line, pos);
3192 if (bss->rsn_override_key_mgmt_2 == -1)
3193 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003194 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
3195 bss->wpa_psk_radius = atoi(pos);
3196 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
3197 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07003198 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED &&
3199 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003200 wpa_printf(MSG_ERROR,
3201 "Line %d: unknown wpa_psk_radius %d",
3202 line, bss->wpa_psk_radius);
3203 return 1;
3204 }
3205 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
3206 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
3207 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
3208 return 1;
3209 if (bss->wpa_pairwise &
3210 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
3211 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003212 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003213 return 1;
3214 }
3215 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
3216 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
3217 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
3218 return 1;
3219 if (bss->rsn_pairwise &
3220 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
3221 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003222 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003223 return 1;
3224 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003225 } else if (os_strcmp(buf, "rsn_override_pairwise") == 0) {
3226 bss->rsn_override_pairwise =
3227 hostapd_config_parse_cipher(line, pos);
3228 if (bss->rsn_override_pairwise == -1 ||
3229 bss->rsn_override_pairwise == 0)
3230 return 1;
3231 if (bss->rsn_override_pairwise &
3232 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
3233 wpa_printf(MSG_ERROR,
3234 "Line %d: unsupported pairwise cipher suite '%s'",
3235 line, pos);
3236 return 1;
3237 }
3238 } else if (os_strcmp(buf, "rsn_override_pairwise_2") == 0) {
3239 bss->rsn_override_pairwise_2 =
3240 hostapd_config_parse_cipher(line, pos);
3241 if (bss->rsn_override_pairwise_2 == -1 ||
3242 bss->rsn_override_pairwise_2 == 0)
3243 return 1;
3244 if (bss->rsn_override_pairwise_2 &
3245 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
3246 wpa_printf(MSG_ERROR,
3247 "Line %d: unsupported pairwise cipher suite '%s'",
3248 line, pos);
3249 return 1;
3250 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003251 } else if (os_strcmp(buf, "group_cipher") == 0) {
3252 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
3253 if (bss->group_cipher == -1 || bss->group_cipher == 0)
3254 return 1;
3255 if (bss->group_cipher != WPA_CIPHER_TKIP &&
3256 bss->group_cipher != WPA_CIPHER_CCMP &&
3257 bss->group_cipher != WPA_CIPHER_GCMP &&
3258 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
3259 bss->group_cipher != WPA_CIPHER_CCMP_256) {
3260 wpa_printf(MSG_ERROR,
3261 "Line %d: unsupported group cipher suite '%s'",
3262 line, pos);
3263 return 1;
3264 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003265#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003266 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
3267 bss->rsn_preauth = atoi(pos);
3268 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003269 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003270 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003271#endif /* CONFIG_RSN_PREAUTH */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003272 } else if (os_strcmp(buf, "rsn_override_omit_rsnxe") == 0) {
3273 bss->rsn_override_omit_rsnxe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003274 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003275 wpa_printf(MSG_INFO,
3276 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003277#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003278 } else if (os_strcmp(buf, "mobility_domain") == 0) {
3279 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
3280 hexstr2bin(pos, bss->mobility_domain,
3281 MOBILITY_DOMAIN_ID_LEN) != 0) {
3282 wpa_printf(MSG_ERROR,
3283 "Line %d: Invalid mobility_domain '%s'",
3284 line, pos);
3285 return 1;
3286 }
3287 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
3288 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
3289 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
3290 wpa_printf(MSG_ERROR,
3291 "Line %d: Invalid r1_key_holder '%s'",
3292 line, pos);
3293 return 1;
3294 }
3295 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003296 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
3297 bss->r0_key_lifetime = atoi(pos) * 60;
3298 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003299 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003300 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
3301 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003302 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
3303 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003304 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
3305 bss->rkh_pos_timeout = atoi(pos);
3306 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
3307 bss->rkh_neg_timeout = atoi(pos);
3308 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
3309 bss->rkh_pull_timeout = atoi(pos);
3310 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
3311 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003312 } else if (os_strcmp(buf, "r0kh") == 0) {
3313 if (add_r0kh(bss, pos) < 0) {
3314 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
3315 line, pos);
3316 return 1;
3317 }
3318 } else if (os_strcmp(buf, "r1kh") == 0) {
3319 if (add_r1kh(bss, pos) < 0) {
3320 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
3321 line, pos);
3322 return 1;
3323 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003324 } else if (os_strcmp(buf, "rxkh_file") == 0) {
3325 os_free(bss->rxkh_file);
3326 bss->rxkh_file = os_strdup(pos);
3327 if (!bss->rxkh_file) {
3328 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
3329 line);
3330 return 1;
3331 }
3332 if (hostapd_config_read_rxkh_file(bss, pos)) {
3333 wpa_printf(MSG_DEBUG,
3334 "Line %d: failed to read rxkh_file '%s'",
3335 line, pos);
3336 /* Allow the file to be created later and read into
3337 * already operating AP context. */
3338 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003339 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
3340 bss->pmk_r1_push = atoi(pos);
3341 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
3342 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003343 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
3344 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003345#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003346#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003347 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
3348 os_free(bss->ctrl_interface);
3349 bss->ctrl_interface = os_strdup(pos);
3350 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003351#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003352 struct group *grp;
3353 char *endp;
3354 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003356 grp = getgrnam(group);
3357 if (grp) {
3358 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003360 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
3361 bss->ctrl_interface_gid, group);
3362 return 0;
3363 }
3364
3365 /* Group name not found - try to parse this as gid */
3366 bss->ctrl_interface_gid = strtol(group, &endp, 10);
3367 if (*group == '\0' || *endp != '\0') {
3368 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
3369 line, group);
3370 return 1;
3371 }
3372 bss->ctrl_interface_gid_set = 1;
3373 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
3374 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375#endif /* CONFIG_NATIVE_WINDOWS */
3376#endif /* CONFIG_NO_CTRL_IFACE */
3377#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003378 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
3379 os_free(bss->radius_server_clients);
3380 bss->radius_server_clients = os_strdup(pos);
3381 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
3382 bss->radius_server_auth_port = atoi(pos);
3383 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
3384 bss->radius_server_acct_port = atoi(pos);
3385 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
3386 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003388 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
3389 bss->use_pae_group_addr = atoi(pos);
3390 } else if (os_strcmp(buf, "hw_mode") == 0) {
3391 if (os_strcmp(pos, "a") == 0)
3392 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
3393 else if (os_strcmp(pos, "b") == 0)
3394 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
3395 else if (os_strcmp(pos, "g") == 0)
3396 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
3397 else if (os_strcmp(pos, "ad") == 0)
3398 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003399 else if (os_strcmp(pos, "any") == 0)
3400 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003401 else {
3402 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3403 line, pos);
3404 return 1;
3405 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003406 conf->hw_mode_set = true;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003407 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003408 if (os_strcmp(pos, "ad") == 0)
3409 bss->wps_rf_bands = WPS_RF_60GHZ;
3410 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003411 bss->wps_rf_bands = WPS_RF_50GHZ;
3412 else if (os_strcmp(pos, "g") == 0 ||
3413 os_strcmp(pos, "b") == 0)
3414 bss->wps_rf_bands = WPS_RF_24GHZ;
3415 else if (os_strcmp(pos, "ag") == 0 ||
3416 os_strcmp(pos, "ga") == 0)
3417 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3418 else {
3419 wpa_printf(MSG_ERROR,
3420 "Line %d: unknown wps_rf_band '%s'",
3421 line, pos);
3422 return 1;
3423 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003424 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3425 conf->acs_exclude_dfs = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07003426 } else if (os_strcmp(buf, "op_class") == 0) {
3427 conf->op_class = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003428 } else if (os_strcmp(buf, "channel") == 0) {
3429 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003430#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003431 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3432 line);
3433 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003434#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003435 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003436 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003437#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003438 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003439 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003440 conf->acs = conf->channel == 0;
3441 }
Hai Shalomc3565922019-10-28 11:58:20 -07003442 } else if (os_strcmp(buf, "edmg_channel") == 0) {
3443 conf->edmg_channel = atoi(pos);
3444 } else if (os_strcmp(buf, "enable_edmg") == 0) {
3445 conf->enable_edmg = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003446 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003447 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003448 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3449 line);
3450 return 1;
3451 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003452 } else if (os_strcmp(buf, "freqlist") == 0) {
3453 if (freq_range_list_parse(&conf->acs_freq_list, pos)) {
3454 wpa_printf(MSG_ERROR, "Line %d: invalid frequency list",
3455 line);
3456 return 1;
3457 }
3458 conf->acs_freq_list_present = 1;
3459 } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) {
3460 conf->acs_exclude_6ghz_non_psc = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07003461 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
3462 conf->enable_background_radar = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003463 } else if (os_strcmp(buf, "min_tx_power") == 0) {
3464 int val = atoi(pos);
3465
3466 if (val < 0 || val > 255) {
3467 wpa_printf(MSG_ERROR,
3468 "Line %d: invalid min_tx_power %d (expected 0..255)",
3469 line, val);
3470 return 1;
3471 }
3472 conf->min_tx_power = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003473 } else if (os_strcmp(buf, "beacon_int") == 0) {
3474 int val = atoi(pos);
3475 /* MIB defines range as 1..65535, but very small values
3476 * cause problems with the current implementation.
3477 * Since it is unlikely that this small numbers are
3478 * useful in real life scenarios, do not allow beacon
Hai Shalom021b0b52019-04-10 11:17:58 -07003479 * period to be set below 10 TU. */
3480 if (val < 10 || val > 65535) {
3481 wpa_printf(MSG_ERROR,
3482 "Line %d: invalid beacon_int %d (expected 10..65535)",
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003483 line, val);
3484 return 1;
3485 }
3486 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003487#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003488 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3489 int val = atoi(pos);
3490 if (val <= 0 || val > 100) {
3491 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3492 line, val);
3493 return 1;
3494 }
3495 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003496 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3497 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3498 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3499 line);
3500 return -1;
3501 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003502#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003503 } else if (os_strcmp(buf, "dtim_period") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003504 int val = atoi(pos);
3505
3506 if (val < 1 || val > 255) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003507 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08003508 line, val);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003509 return 1;
3510 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08003511 bss->dtim_period = val;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003512 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003513 int val = atoi(pos);
3514
3515 if (val < 0 || val > 100) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003516 wpa_printf(MSG_ERROR,
3517 "Line %d: invalid bss_load_update_period %d",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003518 line, val);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003519 return 1;
3520 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003521 bss->bss_load_update_period = val;
3522 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3523 int val = atoi(pos);
3524
3525 if (val < 0) {
3526 wpa_printf(MSG_ERROR,
3527 "Line %d: invalid chan_util_avg_period",
3528 line);
3529 return 1;
3530 }
3531 bss->chan_util_avg_period = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003532 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3533 conf->rts_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003534 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003535 wpa_printf(MSG_ERROR,
3536 "Line %d: invalid rts_threshold %d",
3537 line, conf->rts_threshold);
3538 return 1;
3539 }
3540 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3541 conf->fragm_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003542 if (conf->fragm_threshold == -1) {
3543 /* allow a value of -1 */
3544 } else if (conf->fragm_threshold < 256 ||
3545 conf->fragm_threshold > 2346) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003546 wpa_printf(MSG_ERROR,
3547 "Line %d: invalid fragm_threshold %d",
3548 line, conf->fragm_threshold);
3549 return 1;
3550 }
3551 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3552 int val = atoi(pos);
3553 if (val != 0 && val != 1) {
3554 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3555 line, val);
3556 return 1;
3557 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003558 bss->send_probe_response = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003559 } else if (os_strcmp(buf, "supported_rates") == 0) {
3560 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3561 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3562 line);
3563 return 1;
3564 }
3565 } else if (os_strcmp(buf, "basic_rates") == 0) {
3566 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3567 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3568 line);
3569 return 1;
3570 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003571 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3572 int val;
3573
3574 if (os_strncmp(pos, "ht:", 3) == 0) {
3575 val = atoi(pos + 3);
3576 if (val < 0 || val > 31) {
3577 wpa_printf(MSG_ERROR,
3578 "Line %d: invalid beacon_rate HT-MCS %d",
3579 line, val);
3580 return 1;
3581 }
3582 conf->rate_type = BEACON_RATE_HT;
3583 conf->beacon_rate = val;
3584 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3585 val = atoi(pos + 4);
3586 if (val < 0 || val > 9) {
3587 wpa_printf(MSG_ERROR,
3588 "Line %d: invalid beacon_rate VHT-MCS %d",
3589 line, val);
3590 return 1;
3591 }
3592 conf->rate_type = BEACON_RATE_VHT;
3593 conf->beacon_rate = val;
Hai Shalom60840252021-02-19 19:02:11 -08003594 } else if (os_strncmp(pos, "he:", 3) == 0) {
3595 val = atoi(pos + 3);
3596 if (val < 0 || val > 11) {
3597 wpa_printf(MSG_ERROR,
3598 "Line %d: invalid beacon_rate HE-MCS %d",
3599 line, val);
3600 return 1;
3601 }
3602 conf->rate_type = BEACON_RATE_HE;
3603 conf->beacon_rate = val;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003604 } else {
3605 val = atoi(pos);
3606 if (val < 10 || val > 10000) {
3607 wpa_printf(MSG_ERROR,
3608 "Line %d: invalid legacy beacon_rate %d",
3609 line, val);
3610 return 1;
3611 }
3612 conf->rate_type = BEACON_RATE_LEGACY;
3613 conf->beacon_rate = val;
3614 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003615 } else if (os_strcmp(buf, "preamble") == 0) {
3616 if (atoi(pos))
3617 conf->preamble = SHORT_PREAMBLE;
3618 else
3619 conf->preamble = LONG_PREAMBLE;
3620 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3621 bss->ignore_broadcast_ssid = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003622 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3623 bss->no_probe_resp_if_max_sta = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003624#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003625 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3626 bss->ssid.wep.idx = atoi(pos);
3627 if (bss->ssid.wep.idx > 3) {
3628 wpa_printf(MSG_ERROR,
3629 "Invalid wep_default_key index %d",
3630 bss->ssid.wep.idx);
3631 return 1;
3632 }
3633 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3634 os_strcmp(buf, "wep_key1") == 0 ||
3635 os_strcmp(buf, "wep_key2") == 0 ||
3636 os_strcmp(buf, "wep_key3") == 0) {
3637 if (hostapd_config_read_wep(&bss->ssid.wep,
3638 buf[7] - '0', pos)) {
3639 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3640 line, buf);
3641 return 1;
3642 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003643#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003645 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3646 bss->ssid.dynamic_vlan = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003647 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3648 bss->ssid.per_sta_vif = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003649 } else if (os_strcmp(buf, "vlan_file") == 0) {
3650 if (hostapd_config_read_vlan_file(bss, pos)) {
3651 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3652 line, pos);
3653 return 1;
3654 }
3655 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3656 bss->ssid.vlan_naming = atoi(pos);
3657 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3658 bss->ssid.vlan_naming < 0) {
3659 wpa_printf(MSG_ERROR,
3660 "Line %d: invalid naming scheme %d",
3661 line, bss->ssid.vlan_naming);
3662 return 1;
3663 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003664#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003665 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003666 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003667 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003668#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3669#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003670 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3671 conf->ap_table_max_size = atoi(pos);
3672 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3673 conf->ap_table_expiration_time = atoi(pos);
3674 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003675 if (hostapd_config_tx_queue(conf->tx_queue, buf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003676 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3677 line);
3678 return 1;
3679 }
3680 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3681 os_strcmp(buf, "wmm_enabled") == 0) {
3682 bss->wmm_enabled = atoi(pos);
3683 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3684 bss->wmm_uapsd = atoi(pos);
3685 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3686 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3687 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3688 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3689 line);
3690 return 1;
3691 }
3692 } else if (os_strcmp(buf, "bss") == 0) {
3693 if (hostapd_config_bss(conf, pos)) {
3694 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3695 line);
3696 return 1;
3697 }
3698 } else if (os_strcmp(buf, "bssid") == 0) {
3699 if (hwaddr_aton(pos, bss->bssid)) {
3700 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3701 line);
3702 return 1;
3703 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003704 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3705 conf->use_driver_iface_addr = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003706 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3707 bss->ieee80211w = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00003708 } else if (os_strcmp(buf, "rsn_override_mfp") == 0) {
3709 bss->rsn_override_mfp = atoi(pos);
3710 } else if (os_strcmp(buf, "rsn_override_mfp_2") == 0) {
3711 bss->rsn_override_mfp_2 = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003712 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3713 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3714 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3715 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3716 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3717 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3718 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3719 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3720 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3721 } else {
3722 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3723 line, pos);
3724 return 1;
3725 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003726 } else if (os_strcmp(buf, "beacon_prot") == 0) {
3727 bss->beacon_prot = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003728 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3729 bss->assoc_sa_query_max_timeout = atoi(pos);
3730 if (bss->assoc_sa_query_max_timeout == 0) {
3731 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3732 line);
3733 return 1;
3734 }
3735 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3736 bss->assoc_sa_query_retry_timeout = atoi(pos);
3737 if (bss->assoc_sa_query_retry_timeout == 0) {
3738 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3739 line);
3740 return 1;
3741 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003742#ifdef CONFIG_OCV
3743 } else if (os_strcmp(buf, "ocv") == 0) {
3744 bss->ocv = atoi(pos);
3745 if (bss->ocv && !bss->ieee80211w)
3746 bss->ieee80211w = 1;
3747#endif /* CONFIG_OCV */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003748 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3749 conf->ieee80211n = atoi(pos);
3750 } else if (os_strcmp(buf, "ht_capab") == 0) {
3751 if (hostapd_config_ht_capab(conf, pos) < 0) {
3752 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3753 line);
3754 return 1;
3755 }
3756 } else if (os_strcmp(buf, "require_ht") == 0) {
3757 conf->require_ht = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00003758 } else if (os_strcmp(buf, "ht_vht_twt_responder") == 0) {
3759 conf->ht_vht_twt_responder = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003760 } else if (os_strcmp(buf, "obss_interval") == 0) {
3761 conf->obss_interval = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003762#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003763 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3764 conf->ieee80211ac = atoi(pos);
3765 } else if (os_strcmp(buf, "vht_capab") == 0) {
3766 if (hostapd_config_vht_capab(conf, pos) < 0) {
3767 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3768 line);
3769 return 1;
3770 }
3771 } else if (os_strcmp(buf, "require_vht") == 0) {
3772 conf->require_vht = atoi(pos);
3773 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3774 conf->vht_oper_chwidth = atoi(pos);
3775 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3776 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3777 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3778 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003779 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3780 bss->vendor_vht = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003781 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3782 bss->use_sta_nsts = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003783#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003784#ifdef CONFIG_IEEE80211AX
3785 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3786 conf->ieee80211ax = atoi(pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003787 } else if (os_strcmp(buf, "require_he") == 0) {
3788 conf->require_he = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003789 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3790 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3791 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3792 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3793 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3794 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3795 } else if (os_strcmp(buf, "he_bss_color") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003796 conf->he_op.he_bss_color = atoi(pos) & 0x3f;
3797 conf->he_op.he_bss_color_disabled = 0;
3798 } else if (os_strcmp(buf, "he_bss_color_partial") == 0) {
3799 conf->he_op.he_bss_color_partial = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003800 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3801 conf->he_op.he_default_pe_duration = atoi(pos);
3802 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3803 conf->he_op.he_twt_required = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003804 } else if (os_strcmp(buf, "he_twt_responder") == 0) {
3805 conf->he_op.he_twt_responder = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003806 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3807 conf->he_op.he_rts_threshold = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003808 } else if (os_strcmp(buf, "he_er_su_disable") == 0) {
3809 conf->he_op.he_er_su_disable = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003810 } else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
3811 conf->he_op.he_basic_mcs_nss_set = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003812 } else if (os_strcmp(buf, "he_mu_edca_qos_info_param_count") == 0) {
3813 conf->he_mu_edca.he_qos_info |=
3814 set_he_cap(atoi(pos), HE_QOS_INFO_EDCA_PARAM_SET_COUNT);
3815 } else if (os_strcmp(buf, "he_mu_edca_qos_info_q_ack") == 0) {
3816 conf->he_mu_edca.he_qos_info |=
3817 set_he_cap(atoi(pos), HE_QOS_INFO_Q_ACK);
3818 } else if (os_strcmp(buf, "he_mu_edca_qos_info_queue_request") == 0) {
3819 conf->he_mu_edca.he_qos_info |=
3820 set_he_cap(atoi(pos), HE_QOS_INFO_QUEUE_REQUEST);
3821 } else if (os_strcmp(buf, "he_mu_edca_qos_info_txop_request") == 0) {
3822 conf->he_mu_edca.he_qos_info |=
3823 set_he_cap(atoi(pos), HE_QOS_INFO_TXOP_REQUEST);
3824 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aifsn") == 0) {
3825 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3826 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3827 } else if (os_strcmp(buf, "he_mu_edca_ac_be_acm") == 0) {
3828 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3829 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3830 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aci") == 0) {
3831 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3832 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3833 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmin") == 0) {
3834 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3835 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3836 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmax") == 0) {
3837 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3838 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3839 } else if (os_strcmp(buf, "he_mu_edca_ac_be_timer") == 0) {
3840 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_TIMER_IDX] =
3841 atoi(pos) & 0xff;
3842 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aifsn") == 0) {
3843 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3844 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3845 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_acm") == 0) {
3846 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3847 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3848 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aci") == 0) {
3849 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3850 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3851 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmin") == 0) {
3852 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3853 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3854 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmax") == 0) {
3855 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3856 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3857 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_timer") == 0) {
3858 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_TIMER_IDX] =
3859 atoi(pos) & 0xff;
3860 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aifsn") == 0) {
3861 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3862 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3863 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_acm") == 0) {
3864 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3865 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3866 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aci") == 0) {
3867 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3868 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3869 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmin") == 0) {
3870 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3871 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3872 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmax") == 0) {
3873 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3874 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3875 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_timer") == 0) {
3876 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_TIMER_IDX] =
3877 atoi(pos) & 0xff;
3878 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aifsn") == 0) {
3879 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3880 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3881 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_acm") == 0) {
3882 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3883 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3884 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aci") == 0) {
3885 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3886 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3887 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmin") == 0) {
3888 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3889 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3890 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmax") == 0) {
3891 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3892 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3893 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_timer") == 0) {
3894 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_TIMER_IDX] =
3895 atoi(pos) & 0xff;
Hai Shalom81f62d82019-07-22 12:10:00 -07003896 } else if (os_strcmp(buf, "he_spr_sr_control") == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003897 conf->spr.sr_control = atoi(pos) & 0x1f;
Hai Shalom81f62d82019-07-22 12:10:00 -07003898 } else if (os_strcmp(buf, "he_spr_non_srg_obss_pd_max_offset") == 0) {
3899 conf->spr.non_srg_obss_pd_max_offset = atoi(pos);
3900 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_min_offset") == 0) {
3901 conf->spr.srg_obss_pd_min_offset = atoi(pos);
3902 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_max_offset") == 0) {
3903 conf->spr.srg_obss_pd_max_offset = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003904 } else if (os_strcmp(buf, "he_spr_srg_bss_colors") == 0) {
3905 if (hostapd_parse_he_srg_bitmap(
3906 conf->spr.srg_bss_color_bitmap, pos)) {
3907 wpa_printf(MSG_ERROR,
3908 "Line %d: Invalid srg bss colors list '%s'",
3909 line, pos);
3910 return 1;
3911 }
3912 } else if (os_strcmp(buf, "he_spr_srg_partial_bssid") == 0) {
3913 if (hostapd_parse_he_srg_bitmap(
3914 conf->spr.srg_partial_bssid_bitmap, pos)) {
3915 wpa_printf(MSG_ERROR,
3916 "Line %d: Invalid srg partial bssid list '%s'",
3917 line, pos);
3918 return 1;
3919 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003920 } else if (os_strcmp(buf, "he_6ghz_reg_pwr_type") == 0) {
3921 conf->he_6ghz_reg_pwr_type = atoi(pos);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003922 if (conf->he_6ghz_reg_pwr_type > HE_REG_INFO_6GHZ_AP_TYPE_MAX) {
3923 wpa_printf(MSG_ERROR,
3924 "Line %d: invalid he_6ghz_reg_pwr_type value",
3925 line);
3926 return 1;
3927 }
3928 } else if (os_strcmp(buf, "reg_def_cli_eirp_psd") == 0) {
3929 conf->reg_def_cli_eirp_psd = atoi(pos);
3930 } else if (os_strcmp(buf, "reg_sub_cli_eirp_psd") == 0) {
3931 conf->reg_sub_cli_eirp_psd = atoi(pos);
3932 } else if (os_strcmp(buf, "reg_def_cli_eirp") == 0) {
3933 conf->reg_def_cli_eirp = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003934 } else if (os_strcmp(buf, "he_oper_chwidth") == 0) {
3935 conf->he_oper_chwidth = atoi(pos);
3936 } else if (os_strcmp(buf, "he_oper_centr_freq_seg0_idx") == 0) {
3937 conf->he_oper_centr_freq_seg0_idx = atoi(pos);
3938 } else if (os_strcmp(buf, "he_oper_centr_freq_seg1_idx") == 0) {
3939 conf->he_oper_centr_freq_seg1_idx = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003940 } else if (os_strcmp(buf, "he_6ghz_max_mpdu") == 0) {
3941 conf->he_6ghz_max_mpdu = atoi(pos);
3942 } else if (os_strcmp(buf, "he_6ghz_max_ampdu_len_exp") == 0) {
3943 conf->he_6ghz_max_ampdu_len_exp = atoi(pos);
3944 } else if (os_strcmp(buf, "he_6ghz_rx_ant_pat") == 0) {
3945 conf->he_6ghz_rx_ant_pat = atoi(pos);
3946 } else if (os_strcmp(buf, "he_6ghz_tx_ant_pat") == 0) {
3947 conf->he_6ghz_tx_ant_pat = atoi(pos);
3948 } else if (os_strcmp(buf, "unsol_bcast_probe_resp_interval") == 0) {
3949 int val = atoi(pos);
3950
3951 if (val < 0 || val > 20) {
3952 wpa_printf(MSG_ERROR,
3953 "Line %d: invalid unsol_bcast_probe_resp_interval value",
3954 line);
3955 return 1;
3956 }
3957 bss->unsol_bcast_probe_resp_interval = val;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003958 } else if (os_strcmp(buf, "mbssid") == 0) {
3959 int mbssid = atoi(pos);
3960 if (mbssid < 0 || mbssid > ENHANCED_MBSSID_ENABLED) {
3961 wpa_printf(MSG_ERROR,
3962 "Line %d: invalid mbssid (%d): '%s'.",
3963 line, mbssid, pos);
3964 return 1;
3965 }
3966 conf->mbssid = mbssid;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003967#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003968 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3969 bss->max_listen_interval = atoi(pos);
3970 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3971 bss->disable_pmksa_caching = atoi(pos);
3972 } else if (os_strcmp(buf, "okc") == 0) {
3973 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003974#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003975 } else if (os_strcmp(buf, "wps_state") == 0) {
3976 bss->wps_state = atoi(pos);
3977 if (bss->wps_state < 0 || bss->wps_state > 2) {
3978 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3979 line);
3980 return 1;
3981 }
3982 } else if (os_strcmp(buf, "wps_independent") == 0) {
3983 bss->wps_independent = atoi(pos);
3984 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3985 bss->ap_setup_locked = atoi(pos);
3986 } else if (os_strcmp(buf, "uuid") == 0) {
3987 if (uuid_str2bin(pos, bss->uuid)) {
3988 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3989 return 1;
3990 }
3991 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3992 os_free(bss->wps_pin_requests);
3993 bss->wps_pin_requests = os_strdup(pos);
3994 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003995 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003996 wpa_printf(MSG_ERROR, "Line %d: Too long "
3997 "device_name", line);
3998 return 1;
3999 }
4000 os_free(bss->device_name);
4001 bss->device_name = os_strdup(pos);
4002 } else if (os_strcmp(buf, "manufacturer") == 0) {
4003 if (os_strlen(pos) > 64) {
4004 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
4005 line);
4006 return 1;
4007 }
4008 os_free(bss->manufacturer);
4009 bss->manufacturer = os_strdup(pos);
4010 } else if (os_strcmp(buf, "model_name") == 0) {
4011 if (os_strlen(pos) > 32) {
4012 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
4013 line);
4014 return 1;
4015 }
4016 os_free(bss->model_name);
4017 bss->model_name = os_strdup(pos);
4018 } else if (os_strcmp(buf, "model_number") == 0) {
4019 if (os_strlen(pos) > 32) {
4020 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
4021 line);
4022 return 1;
4023 }
4024 os_free(bss->model_number);
4025 bss->model_number = os_strdup(pos);
4026 } else if (os_strcmp(buf, "serial_number") == 0) {
4027 if (os_strlen(pos) > 32) {
4028 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
4029 line);
4030 return 1;
4031 }
4032 os_free(bss->serial_number);
4033 bss->serial_number = os_strdup(pos);
4034 } else if (os_strcmp(buf, "device_type") == 0) {
4035 if (wps_dev_type_str2bin(pos, bss->device_type))
4036 return 1;
4037 } else if (os_strcmp(buf, "config_methods") == 0) {
4038 os_free(bss->config_methods);
4039 bss->config_methods = os_strdup(pos);
4040 } else if (os_strcmp(buf, "os_version") == 0) {
4041 if (hexstr2bin(pos, bss->os_version, 4)) {
4042 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
4043 line);
4044 return 1;
4045 }
4046 } else if (os_strcmp(buf, "ap_pin") == 0) {
4047 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004048 if (*pos == '\0')
4049 bss->ap_pin = NULL;
4050 else
4051 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004052 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
4053 bss->skip_cred_build = atoi(pos);
4054 } else if (os_strcmp(buf, "extra_cred") == 0) {
4055 os_free(bss->extra_cred);
4056 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
4057 if (bss->extra_cred == NULL) {
4058 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
4059 line, pos);
4060 return 1;
4061 }
4062 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
4063 bss->wps_cred_processing = atoi(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07004064 } else if (os_strcmp(buf, "wps_cred_add_sae") == 0) {
4065 bss->wps_cred_add_sae = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004066 } else if (os_strcmp(buf, "ap_settings") == 0) {
4067 os_free(bss->ap_settings);
4068 bss->ap_settings =
4069 (u8 *) os_readfile(pos, &bss->ap_settings_len);
4070 if (bss->ap_settings == NULL) {
4071 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
4072 line, pos);
4073 return 1;
4074 }
Hai Shalom021b0b52019-04-10 11:17:58 -07004075 } else if (os_strcmp(buf, "multi_ap_backhaul_ssid") == 0) {
4076 size_t slen;
4077 char *str = wpa_config_parse_string(pos, &slen);
4078
4079 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4080 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4081 line, pos);
4082 os_free(str);
4083 return 1;
4084 }
4085 os_memcpy(bss->multi_ap_backhaul_ssid.ssid, str, slen);
4086 bss->multi_ap_backhaul_ssid.ssid_len = slen;
4087 bss->multi_ap_backhaul_ssid.ssid_set = 1;
4088 os_free(str);
4089 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_passphrase") == 0) {
4090 int len = os_strlen(pos);
4091
4092 if (len < 8 || len > 63) {
4093 wpa_printf(MSG_ERROR,
4094 "Line %d: invalid WPA passphrase length %d (expected 8..63)",
4095 line, len);
4096 return 1;
4097 }
4098 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
4099 bss->multi_ap_backhaul_ssid.wpa_passphrase = os_strdup(pos);
4100 if (bss->multi_ap_backhaul_ssid.wpa_passphrase) {
4101 hostapd_config_clear_wpa_psk(
4102 &bss->multi_ap_backhaul_ssid.wpa_psk);
4103 bss->multi_ap_backhaul_ssid.wpa_passphrase_set = 1;
4104 }
4105 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_psk") == 0) {
4106 hostapd_config_clear_wpa_psk(
4107 &bss->multi_ap_backhaul_ssid.wpa_psk);
4108 bss->multi_ap_backhaul_ssid.wpa_psk =
4109 os_zalloc(sizeof(struct hostapd_wpa_psk));
4110 if (!bss->multi_ap_backhaul_ssid.wpa_psk)
4111 return 1;
4112 if (hexstr2bin(pos, bss->multi_ap_backhaul_ssid.wpa_psk->psk,
4113 PMK_LEN) ||
4114 pos[PMK_LEN * 2] != '\0') {
4115 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
4116 line, pos);
4117 hostapd_config_clear_wpa_psk(
4118 &bss->multi_ap_backhaul_ssid.wpa_psk);
4119 return 1;
4120 }
4121 bss->multi_ap_backhaul_ssid.wpa_psk->group = 1;
4122 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
4123 bss->multi_ap_backhaul_ssid.wpa_passphrase = NULL;
4124 bss->multi_ap_backhaul_ssid.wpa_psk_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004125 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07004126 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004127 bss->upnp_iface = os_strdup(pos);
4128 } else if (os_strcmp(buf, "friendly_name") == 0) {
4129 os_free(bss->friendly_name);
4130 bss->friendly_name = os_strdup(pos);
4131 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
4132 os_free(bss->manufacturer_url);
4133 bss->manufacturer_url = os_strdup(pos);
4134 } else if (os_strcmp(buf, "model_description") == 0) {
4135 os_free(bss->model_description);
4136 bss->model_description = os_strdup(pos);
4137 } else if (os_strcmp(buf, "model_url") == 0) {
4138 os_free(bss->model_url);
4139 bss->model_url = os_strdup(pos);
4140 } else if (os_strcmp(buf, "upc") == 0) {
4141 os_free(bss->upc);
4142 bss->upc = os_strdup(pos);
4143 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
4144 bss->pbc_in_m1 = atoi(pos);
4145 } else if (os_strcmp(buf, "server_id") == 0) {
4146 os_free(bss->server_id);
4147 bss->server_id = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004148 } else if (os_strcmp(buf, "wps_application_ext") == 0) {
4149 wpabuf_free(bss->wps_application_ext);
4150 bss->wps_application_ext = wpabuf_parse_bin(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004151#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004152 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
4153 bss->wps_nfc_dev_pw_id = atoi(pos);
4154 if (bss->wps_nfc_dev_pw_id < 0x10 ||
4155 bss->wps_nfc_dev_pw_id > 0xffff) {
4156 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
4157 line);
4158 return 1;
4159 }
4160 bss->wps_nfc_pw_from_config = 1;
4161 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
4162 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004163 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004164 bss->wps_nfc_pw_from_config = 1;
4165 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
4166 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004167 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004168 bss->wps_nfc_pw_from_config = 1;
4169 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
4170 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004171 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004172 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004173#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004174#endif /* CONFIG_WPS */
4175#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004176 } else if (os_strcmp(buf, "manage_p2p") == 0) {
4177 if (atoi(pos))
4178 bss->p2p |= P2P_MANAGE;
4179 else
4180 bss->p2p &= ~P2P_MANAGE;
4181 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
4182 if (atoi(pos))
4183 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
4184 else
4185 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004186#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004187 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
4188 bss->disassoc_low_ack = atoi(pos);
4189 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
4190 if (atoi(pos))
4191 bss->tdls |= TDLS_PROHIBIT;
4192 else
4193 bss->tdls &= ~TDLS_PROHIBIT;
4194 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
4195 if (atoi(pos))
4196 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
4197 else
4198 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004199#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004200 } else if (os_strcmp(buf, "rsn_testing") == 0) {
4201 extern int rsn_testing;
4202 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004203#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004204 } else if (os_strcmp(buf, "time_advertisement") == 0) {
4205 bss->time_advertisement = atoi(pos);
4206 } else if (os_strcmp(buf, "time_zone") == 0) {
4207 size_t tz_len = os_strlen(pos);
4208 if (tz_len < 4 || tz_len > 255) {
4209 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
4210 line);
4211 return 1;
4212 }
4213 os_free(bss->time_zone);
4214 bss->time_zone = os_strdup(pos);
4215 if (bss->time_zone == NULL)
4216 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004217#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004218 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
4219 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004220 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
4221 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004222 } else if (os_strcmp(buf, "bss_transition") == 0) {
4223 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004224#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004225#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004226 } else if (os_strcmp(buf, "interworking") == 0) {
4227 bss->interworking = atoi(pos);
4228 } else if (os_strcmp(buf, "access_network_type") == 0) {
4229 bss->access_network_type = atoi(pos);
4230 if (bss->access_network_type < 0 ||
4231 bss->access_network_type > 15) {
4232 wpa_printf(MSG_ERROR,
4233 "Line %d: invalid access_network_type",
4234 line);
4235 return 1;
4236 }
4237 } else if (os_strcmp(buf, "internet") == 0) {
4238 bss->internet = atoi(pos);
4239 } else if (os_strcmp(buf, "asra") == 0) {
4240 bss->asra = atoi(pos);
4241 } else if (os_strcmp(buf, "esr") == 0) {
4242 bss->esr = atoi(pos);
4243 } else if (os_strcmp(buf, "uesa") == 0) {
4244 bss->uesa = atoi(pos);
4245 } else if (os_strcmp(buf, "venue_group") == 0) {
4246 bss->venue_group = atoi(pos);
4247 bss->venue_info_set = 1;
4248 } else if (os_strcmp(buf, "venue_type") == 0) {
4249 bss->venue_type = atoi(pos);
4250 bss->venue_info_set = 1;
4251 } else if (os_strcmp(buf, "hessid") == 0) {
4252 if (hwaddr_aton(pos, bss->hessid)) {
4253 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
4254 return 1;
4255 }
4256 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
4257 if (parse_roaming_consortium(bss, pos, line) < 0)
4258 return 1;
4259 } else if (os_strcmp(buf, "venue_name") == 0) {
4260 if (parse_venue_name(bss, pos, line) < 0)
4261 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004262 } else if (os_strcmp(buf, "venue_url") == 0) {
4263 if (parse_venue_url(bss, pos, line) < 0)
4264 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004265 } else if (os_strcmp(buf, "network_auth_type") == 0) {
4266 u8 auth_type;
4267 u16 redirect_url_len;
4268 if (hexstr2bin(pos, &auth_type, 1)) {
4269 wpa_printf(MSG_ERROR,
4270 "Line %d: Invalid network_auth_type '%s'",
4271 line, pos);
4272 return 1;
4273 }
4274 if (auth_type == 0 || auth_type == 2)
4275 redirect_url_len = os_strlen(pos + 2);
4276 else
4277 redirect_url_len = 0;
4278 os_free(bss->network_auth_type);
4279 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
4280 if (bss->network_auth_type == NULL)
4281 return 1;
4282 *bss->network_auth_type = auth_type;
4283 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
4284 if (redirect_url_len)
4285 os_memcpy(bss->network_auth_type + 3, pos + 2,
4286 redirect_url_len);
4287 bss->network_auth_type_len = 3 + redirect_url_len;
4288 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
4289 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
4290 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
4291 line, pos);
4292 bss->ipaddr_type_configured = 0;
4293 return 1;
4294 }
4295 bss->ipaddr_type_configured = 1;
4296 } else if (os_strcmp(buf, "domain_name") == 0) {
4297 int j, num_domains, domain_len, domain_list_len = 0;
4298 char *tok_start, *tok_prev;
4299 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004300
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004301 domain_list_len = os_strlen(pos) + 1;
4302 domain_list = os_malloc(domain_list_len);
4303 if (domain_list == NULL)
4304 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004305
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004306 domain_ptr = domain_list;
4307 tok_prev = pos;
4308 num_domains = 1;
4309 while ((tok_prev = os_strchr(tok_prev, ','))) {
4310 num_domains++;
4311 tok_prev++;
4312 }
4313 tok_prev = pos;
4314 for (j = 0; j < num_domains; j++) {
4315 tok_start = os_strchr(tok_prev, ',');
4316 if (tok_start) {
4317 domain_len = tok_start - tok_prev;
4318 *domain_ptr = domain_len;
4319 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
4320 domain_ptr += domain_len + 1;
4321 tok_prev = ++tok_start;
4322 } else {
4323 domain_len = os_strlen(tok_prev);
4324 *domain_ptr = domain_len;
4325 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
4326 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004327 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004328 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004329
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004330 os_free(bss->domain_name);
4331 bss->domain_name = domain_list;
4332 bss->domain_name_len = domain_list_len;
4333 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
4334 if (parse_3gpp_cell_net(bss, pos, line) < 0)
4335 return 1;
4336 } else if (os_strcmp(buf, "nai_realm") == 0) {
4337 if (parse_nai_realm(bss, pos, line) < 0)
4338 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004339 } else if (os_strcmp(buf, "anqp_elem") == 0) {
4340 if (parse_anqp_elem(bss, pos, line) < 0)
4341 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004342 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004343 int val = atoi(pos);
4344
4345 if (val <= 0) {
4346 wpa_printf(MSG_ERROR,
4347 "Line %d: Invalid gas_frag_limit '%s'",
4348 line, pos);
4349 return 1;
4350 }
4351 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004352 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
4353 bss->gas_comeback_delay = atoi(pos);
Sunil Ravi99c035e2024-07-12 01:42:03 +00004354#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004355 } else if (os_strcmp(buf, "qos_map_set") == 0) {
4356 if (parse_qos_map_set(bss, pos, line) < 0)
4357 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004358#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004359 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
4360 os_free(bss->dump_msk_file);
4361 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004362#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004363#ifdef CONFIG_PROXYARP
4364 } else if (os_strcmp(buf, "proxy_arp") == 0) {
4365 bss->proxy_arp = atoi(pos);
4366#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004367#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004368 } else if (os_strcmp(buf, "hs20") == 0) {
4369 bss->hs20 = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004370 } else if (os_strcmp(buf, "hs20_release") == 0) {
4371 int val = atoi(pos);
4372
4373 if (val < 1 || val > (HS20_VERSION >> 4) + 1) {
4374 wpa_printf(MSG_ERROR,
4375 "Line %d: Unsupported hs20_release: %s",
4376 line, pos);
4377 return 1;
4378 }
4379 bss->hs20_release = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004380 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
4381 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004382 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
4383 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004384 } else if (os_strcmp(buf, "osen") == 0) {
4385 bss->osen = atoi(pos);
4386 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
4387 bss->anqp_domain_id = atoi(pos);
4388 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
4389 bss->hs20_deauth_req_timeout = atoi(pos);
4390 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
4391 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
4392 return 1;
4393 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
4394 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
4395 return 1;
4396 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
4397 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
4398 return 1;
4399 }
4400 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
4401 u8 *oper_class;
4402 size_t oper_class_len;
4403 oper_class_len = os_strlen(pos);
4404 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
4405 wpa_printf(MSG_ERROR,
4406 "Line %d: Invalid hs20_operating_class '%s'",
4407 line, pos);
4408 return 1;
4409 }
4410 oper_class_len /= 2;
4411 oper_class = os_malloc(oper_class_len);
4412 if (oper_class == NULL)
4413 return 1;
4414 if (hexstr2bin(pos, oper_class, oper_class_len)) {
4415 wpa_printf(MSG_ERROR,
4416 "Line %d: Invalid hs20_operating_class '%s'",
4417 line, pos);
4418 os_free(oper_class);
4419 return 1;
4420 }
4421 os_free(bss->hs20_operating_class);
4422 bss->hs20_operating_class = oper_class;
4423 bss->hs20_operating_class_len = oper_class_len;
4424 } else if (os_strcmp(buf, "hs20_icon") == 0) {
4425 if (hs20_parse_icon(bss, pos) < 0) {
4426 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
4427 line, pos);
4428 return 1;
4429 }
4430 } else if (os_strcmp(buf, "osu_ssid") == 0) {
4431 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
4432 return 1;
4433 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
4434 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
4435 return 1;
4436 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
4437 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
4438 return 1;
4439 } else if (os_strcmp(buf, "osu_nai") == 0) {
4440 if (hs20_parse_osu_nai(bss, pos, line) < 0)
4441 return 1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004442 } else if (os_strcmp(buf, "osu_nai2") == 0) {
4443 if (hs20_parse_osu_nai2(bss, pos, line) < 0)
4444 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004445 } else if (os_strcmp(buf, "osu_method_list") == 0) {
4446 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
4447 return 1;
4448 } else if (os_strcmp(buf, "osu_icon") == 0) {
4449 if (hs20_parse_osu_icon(bss, pos, line) < 0)
4450 return 1;
4451 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
4452 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
4453 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004454 } else if (os_strcmp(buf, "operator_icon") == 0) {
4455 if (hs20_parse_operator_icon(bss, pos, line) < 0)
4456 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004457 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
4458 os_free(bss->subscr_remediation_url);
4459 bss->subscr_remediation_url = os_strdup(pos);
4460 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
4461 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004462 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
4463 os_free(bss->t_c_filename);
4464 bss->t_c_filename = os_strdup(pos);
4465 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
4466 bss->t_c_timestamp = strtol(pos, NULL, 0);
4467 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
4468 os_free(bss->t_c_server_url);
4469 bss->t_c_server_url = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004470 } else if (os_strcmp(buf, "hs20_sim_provisioning_url") == 0) {
4471 os_free(bss->hs20_sim_provisioning_url);
4472 bss->hs20_sim_provisioning_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004473#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004474#ifdef CONFIG_MBO
4475 } else if (os_strcmp(buf, "mbo") == 0) {
4476 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004477 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
4478 bss->mbo_cell_data_conn_pref = atoi(pos);
4479 } else if (os_strcmp(buf, "oce") == 0) {
4480 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004481#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004482#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004483#define PARSE_TEST_PROBABILITY(_val) \
4484 } else if (os_strcmp(buf, #_val) == 0) { \
4485 char *end; \
4486 \
4487 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004488 if (*end || conf->_val < 0.0 || \
4489 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004490 wpa_printf(MSG_ERROR, \
4491 "Line %d: Invalid value '%s'", \
4492 line, pos); \
4493 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004494 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004495 PARSE_TEST_PROBABILITY(ignore_probe_probability)
4496 PARSE_TEST_PROBABILITY(ignore_auth_probability)
4497 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
4498 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
4499 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004500 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
4501 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004502 } else if (os_strcmp(buf, "bss_load_test") == 0) {
4503 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
4504 pos = os_strchr(pos, ':');
4505 if (pos == NULL) {
4506 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4507 line);
4508 return 1;
4509 }
4510 pos++;
4511 bss->bss_load_test[2] = atoi(pos);
4512 pos = os_strchr(pos, ':');
4513 if (pos == NULL) {
4514 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4515 line);
4516 return 1;
4517 }
4518 pos++;
4519 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
4520 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004521 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004522 /*
4523 * DEPRECATED: This parameter will be removed in the future.
4524 * Use rrm_neighbor_report instead.
4525 */
4526 int val = atoi(pos);
4527
4528 if (val & BIT(0))
4529 bss->radio_measurements[0] |=
4530 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004531 } else if (os_strcmp(buf, "own_ie_override") == 0) {
Sunil Ravic0f5d412024-09-11 22:12:49 +00004532 if (!get_hexstream(pos, &bss->own_ie_override,
4533 "own_ie_override", line))
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004534 return 1;
Sunil Ravic0f5d412024-09-11 22:12:49 +00004535 } else if (os_strcmp(buf, "rsne_override") == 0) {
4536 if (!get_hexstream(pos, &bss->rsne_override,
4537 "rsne_override", line))
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004538 return 1;
Sunil Ravic0f5d412024-09-11 22:12:49 +00004539 } else if (os_strcmp(buf, "rsnoe_override") == 0) {
4540 if (!get_hexstream(pos, &bss->rsnoe_override,
4541 "rsnoe_override", line))
4542 return 1;
4543 } else if (os_strcmp(buf, "rsno2e_override") == 0) {
4544 if (!get_hexstream(pos, &bss->rsno2e_override,
4545 "rsno2e_override", line))
4546 return 1;
4547 } else if (os_strcmp(buf, "rsnxe_override") == 0) {
4548 if (!get_hexstream(pos, &bss->rsnxe_override,
4549 "rsnxe_override", line))
4550 return 1;
4551 } else if (os_strcmp(buf, "rsnxoe_override") == 0) {
4552 if (!get_hexstream(pos, &bss->rsnxoe_override,
4553 "rsnxoe_override", line))
4554 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004555 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
4556 bss->sae_reflection_attack = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004557 } else if (os_strcmp(buf, "sae_commit_status") == 0) {
4558 bss->sae_commit_status = atoi(pos);
4559 } else if (os_strcmp(buf, "sae_pk_omit") == 0) {
4560 bss->sae_pk_omit = atoi(pos);
4561 } else if (os_strcmp(buf, "sae_pk_password_check_skip") == 0) {
4562 bss->sae_pk_password_check_skip = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004563 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
4564 wpabuf_free(bss->sae_commit_override);
4565 bss->sae_commit_override = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004566 } else if (os_strcmp(buf, "rsne_override_eapol") == 0) {
4567 wpabuf_free(bss->rsne_override_eapol);
4568 bss->rsne_override_eapol = wpabuf_parse_bin(pos);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004569 } else if (os_strcmp(buf, "rsnxe_override_eapol") == 0) {
4570 wpabuf_free(bss->rsnxe_override_eapol);
4571 bss->rsnxe_override_eapol = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004572 } else if (os_strcmp(buf, "rsne_override_ft") == 0) {
4573 wpabuf_free(bss->rsne_override_ft);
4574 bss->rsne_override_ft = wpabuf_parse_bin(pos);
4575 } else if (os_strcmp(buf, "rsnxe_override_ft") == 0) {
4576 wpabuf_free(bss->rsnxe_override_ft);
4577 bss->rsnxe_override_ft = wpabuf_parse_bin(pos);
4578 } else if (os_strcmp(buf, "gtk_rsc_override") == 0) {
4579 wpabuf_free(bss->gtk_rsc_override);
4580 bss->gtk_rsc_override = wpabuf_parse_bin(pos);
4581 } else if (os_strcmp(buf, "igtk_rsc_override") == 0) {
4582 wpabuf_free(bss->igtk_rsc_override);
4583 bss->igtk_rsc_override = wpabuf_parse_bin(pos);
4584 } else if (os_strcmp(buf, "no_beacon_rsnxe") == 0) {
4585 bss->no_beacon_rsnxe = atoi(pos);
4586 } else if (os_strcmp(buf, "skip_prune_assoc") == 0) {
4587 bss->skip_prune_assoc = atoi(pos);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004588 } else if (os_strcmp(buf, "ft_rsnxe_used") == 0) {
4589 bss->ft_rsnxe_used = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004590 } else if (os_strcmp(buf, "oci_freq_override_eapol_m3") == 0) {
4591 bss->oci_freq_override_eapol_m3 = atoi(pos);
4592 } else if (os_strcmp(buf, "oci_freq_override_eapol_g1") == 0) {
4593 bss->oci_freq_override_eapol_g1 = atoi(pos);
4594 } else if (os_strcmp(buf, "oci_freq_override_saquery_req") == 0) {
4595 bss->oci_freq_override_saquery_req = atoi(pos);
4596 } else if (os_strcmp(buf, "oci_freq_override_saquery_resp") == 0) {
4597 bss->oci_freq_override_saquery_resp = atoi(pos);
4598 } else if (os_strcmp(buf, "oci_freq_override_ft_assoc") == 0) {
4599 bss->oci_freq_override_ft_assoc = atoi(pos);
4600 } else if (os_strcmp(buf, "oci_freq_override_fils_assoc") == 0) {
4601 bss->oci_freq_override_fils_assoc = atoi(pos);
4602 } else if (os_strcmp(buf, "oci_freq_override_wnm_sleep") == 0) {
4603 bss->oci_freq_override_wnm_sleep = atoi(pos);
Kai Shie75b0652020-11-24 20:31:29 -08004604 } else if (os_strcmp(buf, "skip_send_eapol") == 0) {
4605 conf->skip_send_eapol = atoi(pos);
4606 } else if (os_strcmp(buf, "enable_eapol_large_timeout") == 0) {
4607 conf->enable_eapol_large_timeout = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004608 } else if (os_strcmp(buf, "eap_skip_prot_success") == 0) {
4609 bss->eap_skip_prot_success = atoi(pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004610 } else if (os_strcmp(buf, "delay_eapol_tx") == 0) {
4611 conf->delay_eapol_tx = atoi(pos);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004612 } else if (os_strcmp(buf, "eapol_m1_elements") == 0) {
4613 if (parse_wpabuf_hex(line, buf, &bss->eapol_m1_elements, pos))
4614 return 1;
4615 } else if (os_strcmp(buf, "eapol_m3_elements") == 0) {
4616 if (parse_wpabuf_hex(line, buf, &bss->eapol_m3_elements, pos))
4617 return 1;
4618 } else if (os_strcmp(buf, "eapol_m3_no_encrypt") == 0) {
4619 bss->eapol_m3_no_encrypt = atoi(pos);
Sunil Ravic0f5d412024-09-11 22:12:49 +00004620 } else if (os_strcmp(buf, "eapol_key_reserved_random") == 0) {
4621 bss->eapol_key_reserved_random = atoi(pos);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004622 } else if (os_strcmp(buf, "test_assoc_comeback_type") == 0) {
4623 bss->test_assoc_comeback_type = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00004624 } else if (os_strcmp(buf, "presp_elements") == 0) {
4625 if (parse_wpabuf_hex(line, buf, &bss->presp_elements, pos))
4626 return 1;
Hai Shalomce48b4a2018-09-05 11:41:35 -07004627#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004628#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004629 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004630 if (parse_sae_password(bss, pos) < 0) {
4631 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
4632 line);
4633 return 1;
4634 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004635 } else if (os_strcmp(buf, "sae_password_file") == 0) {
4636 if (parse_sae_password_file(bss, pos) < 0) {
4637 wpa_printf(MSG_ERROR,
4638 "Line %d: Invalid sae_password in file",
4639 line);
4640 return 1;
4641 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004642#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004643 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004644 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004645 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004646 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4647 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004648 return 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08004649 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0 ||
4650 os_strcmp(buf, "anti_clogging_threshold") == 0) {
4651 bss->anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004652 } else if (os_strcmp(buf, "sae_sync") == 0) {
4653 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004654 } else if (os_strcmp(buf, "sae_groups") == 0) {
4655 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
4656 wpa_printf(MSG_ERROR,
4657 "Line %d: Invalid sae_groups value '%s'",
4658 line, pos);
4659 return 1;
4660 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004661 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
4662 bss->sae_require_mfp = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07004663 } else if (os_strcmp(buf, "sae_confirm_immediate") == 0) {
4664 bss->sae_confirm_immediate = atoi(pos);
4665 } else if (os_strcmp(buf, "sae_pwe") == 0) {
4666 bss->sae_pwe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004667 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
4668 int val = atoi(pos);
4669 if (val < 0 || val > 255) {
4670 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
4671 line, val);
4672 return 1;
4673 }
4674 conf->local_pwr_constraint = val;
4675 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
4676 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07004677 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
4678 os_free(bss->wowlan_triggers);
4679 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004680#ifdef CONFIG_FST
4681 } else if (os_strcmp(buf, "fst_group_id") == 0) {
4682 size_t len = os_strlen(pos);
4683
4684 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
4685 wpa_printf(MSG_ERROR,
4686 "Line %d: Invalid fst_group_id value '%s'",
4687 line, pos);
4688 return 1;
4689 }
4690
4691 if (conf->fst_cfg.group_id[0]) {
4692 wpa_printf(MSG_ERROR,
4693 "Line %d: Duplicate fst_group value '%s'",
4694 line, pos);
4695 return 1;
4696 }
4697
4698 os_strlcpy(conf->fst_cfg.group_id, pos,
4699 sizeof(conf->fst_cfg.group_id));
4700 } else if (os_strcmp(buf, "fst_priority") == 0) {
4701 char *endp;
4702 long int val;
4703
4704 if (!*pos) {
4705 wpa_printf(MSG_ERROR,
4706 "Line %d: fst_priority value not supplied (expected 1..%u)",
4707 line, FST_MAX_PRIO_VALUE);
4708 return -1;
4709 }
4710
4711 val = strtol(pos, &endp, 0);
4712 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
4713 wpa_printf(MSG_ERROR,
4714 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
4715 line, val, pos, FST_MAX_PRIO_VALUE);
4716 return 1;
4717 }
4718 conf->fst_cfg.priority = (u8) val;
4719 } else if (os_strcmp(buf, "fst_llt") == 0) {
4720 char *endp;
4721 long int val;
4722
4723 if (!*pos) {
4724 wpa_printf(MSG_ERROR,
4725 "Line %d: fst_llt value not supplied (expected 1..%u)",
4726 line, FST_MAX_LLT_MS);
4727 return -1;
4728 }
4729 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07004730 if (*endp || val < 1 ||
4731 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004732 wpa_printf(MSG_ERROR,
4733 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
4734 line, val, pos, FST_MAX_LLT_MS);
4735 return 1;
4736 }
4737 conf->fst_cfg.llt = (u32) val;
4738#endif /* CONFIG_FST */
4739 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
4740 conf->track_sta_max_num = atoi(pos);
4741 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
4742 conf->track_sta_max_age = atoi(pos);
4743 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
4744 os_free(bss->no_probe_resp_if_seen_on);
4745 bss->no_probe_resp_if_seen_on = os_strdup(pos);
4746 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
4747 os_free(bss->no_auth_if_seen_on);
4748 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004749 } else if (os_strcmp(buf, "lci") == 0) {
4750 wpabuf_free(conf->lci);
4751 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004752 if (conf->lci && wpabuf_len(conf->lci) == 0) {
4753 wpabuf_free(conf->lci);
4754 conf->lci = NULL;
4755 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004756 } else if (os_strcmp(buf, "civic") == 0) {
4757 wpabuf_free(conf->civic);
4758 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004759 if (conf->civic && wpabuf_len(conf->civic) == 0) {
4760 wpabuf_free(conf->civic);
4761 conf->civic = NULL;
4762 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004763 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
4764 if (atoi(pos))
4765 bss->radio_measurements[0] |=
4766 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004767 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
4768 if (atoi(pos))
4769 bss->radio_measurements[0] |=
4770 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4771 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4772 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Sunil Ravi99c035e2024-07-12 01:42:03 +00004773 } else if (os_strcmp(buf, "rrm_link_measurement_report") == 0) {
4774 if (atoi(pos))
4775 bss->radio_measurements[0] |=
4776 WLAN_RRM_CAPS_LINK_MEASUREMENT;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004777 } else if (os_strcmp(buf, "gas_address3") == 0) {
4778 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004779 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4780 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004781 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4782 bss->ftm_responder = atoi(pos);
4783 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4784 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004785#ifdef CONFIG_FILS
4786 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4787 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4788 wpa_printf(MSG_ERROR,
4789 "Line %d: Invalid fils_cache_id '%s'",
4790 line, pos);
4791 return 1;
4792 }
4793 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004794 } else if (os_strcmp(buf, "fils_realm") == 0) {
4795 if (parse_fils_realm(bss, pos) < 0)
4796 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004797 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4798 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004799 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4800 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4801 wpa_printf(MSG_ERROR,
4802 "Line %d: invalid IP address '%s'",
4803 line, pos);
4804 return 1;
4805 }
4806 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4807 bss->dhcp_rapid_commit_proxy = atoi(pos);
4808 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4809 bss->fils_hlp_wait_time = atoi(pos);
4810 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4811 bss->dhcp_server_port = atoi(pos);
4812 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4813 bss->dhcp_relay_port = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004814 } else if (os_strcmp(buf, "fils_discovery_min_interval") == 0) {
4815 bss->fils_discovery_min_int = atoi(pos);
4816 } else if (os_strcmp(buf, "fils_discovery_max_interval") == 0) {
4817 bss->fils_discovery_max_int = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004818#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004819 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4820 bss->multicast_to_unicast = atoi(pos);
Sunil Ravi036cec52023-03-29 11:35:17 -07004821 } else if (os_strcmp(buf, "bridge_multicast_to_unicast") == 0) {
4822 bss->bridge_multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004823 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4824 bss->broadcast_deauth = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004825 } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
4826 bss->notify_mgmt_frames = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004827#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07004828 } else if (os_strcmp(buf, "dpp_name") == 0) {
4829 os_free(bss->dpp_name);
4830 bss->dpp_name = os_strdup(pos);
4831 } else if (os_strcmp(buf, "dpp_mud_url") == 0) {
4832 os_free(bss->dpp_mud_url);
4833 bss->dpp_mud_url = os_strdup(pos);
Sunil Ravi89eba102022-09-13 21:04:37 -07004834 } else if (os_strcmp(buf, "dpp_extra_conf_req_name") == 0) {
4835 os_free(bss->dpp_extra_conf_req_name);
4836 bss->dpp_extra_conf_req_name = os_strdup(pos);
4837 } else if (os_strcmp(buf, "dpp_extra_conf_req_value") == 0) {
4838 os_free(bss->dpp_extra_conf_req_value);
4839 bss->dpp_extra_conf_req_value = os_strdup(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004840 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4841 os_free(bss->dpp_connector);
4842 bss->dpp_connector = os_strdup(pos);
4843 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4844 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4845 return 1;
4846 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4847 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4848 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4849 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4850 return 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07004851#ifdef CONFIG_DPP2
4852 } else if (os_strcmp(buf, "dpp_controller") == 0) {
4853 if (hostapd_dpp_controller_parse(bss, pos))
4854 return 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07004855 } else if (os_strcmp(buf, "dpp_relay_port") == 0) {
4856 bss->dpp_relay_port = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004857 } else if (os_strcmp(buf, "dpp_configurator_connectivity") == 0) {
4858 bss->dpp_configurator_connectivity = atoi(pos);
4859 } else if (os_strcmp(buf, "dpp_pfs") == 0) {
4860 int val = atoi(pos);
4861
4862 if (val < 0 || val > 2) {
4863 wpa_printf(MSG_ERROR,
4864 "Line %d: Invalid dpp_pfs value '%s'",
4865 line, pos);
4866 return -1;
4867 }
4868 bss->dpp_pfs = val;
Hai Shalom81f62d82019-07-22 12:10:00 -07004869#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004870#endif /* CONFIG_DPP */
4871#ifdef CONFIG_OWE
4872 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4873 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4874 wpa_printf(MSG_ERROR,
4875 "Line %d: invalid owe_transition_bssid",
4876 line);
4877 return 1;
4878 }
4879 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4880 size_t slen;
4881 char *str = wpa_config_parse_string(pos, &slen);
4882
4883 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4884 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4885 line, pos);
4886 os_free(str);
4887 return 1;
4888 }
4889 os_memcpy(bss->owe_transition_ssid, str, slen);
4890 bss->owe_transition_ssid_len = slen;
4891 os_free(str);
4892 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4893 os_strlcpy(bss->owe_transition_ifname, pos,
4894 sizeof(bss->owe_transition_ifname));
4895 } else if (os_strcmp(buf, "owe_groups") == 0) {
4896 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4897 wpa_printf(MSG_ERROR,
4898 "Line %d: Invalid owe_groups value '%s'",
4899 line, pos);
4900 return 1;
4901 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004902 } else if (os_strcmp(buf, "owe_ptk_workaround") == 0) {
4903 bss->owe_ptk_workaround = atoi(pos);
4904#endif /* CONFIG_OWE */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004905 } else if (os_strcmp(buf, "coloc_intf_reporting") == 0) {
4906 bss->coloc_intf_reporting = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004907 } else if (os_strcmp(buf, "multi_ap") == 0) {
4908 int val = atoi(pos);
4909
4910 if (val < 0 || val > 3) {
4911 wpa_printf(MSG_ERROR, "Line %d: Invalid multi_ap '%s'",
4912 line, buf);
4913 return -1;
4914 }
4915
4916 bss->multi_ap = val;
Sunil Ravi99c035e2024-07-12 01:42:03 +00004917 } else if (os_strcmp(buf, "multi_ap_profile") == 0) {
4918 int val = atoi(pos);
4919
4920 if (val < MULTI_AP_PROFILE_1 || val > MULTI_AP_PROFILE_MAX) {
4921 wpa_printf(MSG_ERROR,
4922 "Line %d: Invalid multi_ap_profile '%s'",
4923 line, buf);
4924 return -1;
4925 }
4926 bss->multi_ap_profile = val;
4927 } else if (os_strcmp(buf, "multi_ap_client_disallow") == 0) {
4928 int val = atoi(pos);
4929
4930 if (val < 0 || val > 3) {
4931 wpa_printf(MSG_ERROR,
4932 "Line %d: Invalid multi_ap_client_allow '%s'",
4933 line, buf);
4934 return -1;
4935 }
4936 bss->multi_ap_client_disallow = val;
4937 } else if (os_strcmp(buf, "multi_ap_vlanid") == 0) {
4938 int val = atoi(pos);
4939
4940 if (val < 0 || val > MAX_VLAN_ID) {
4941 wpa_printf(MSG_ERROR,
4942 "Line %d: Invalid multi_ap_vlan_id '%s'",
4943 line, buf);
4944 return -1;
4945 }
4946 bss->multi_ap_vlanid = val;
Hai Shalom74f70d42019-02-11 14:42:39 -08004947 } else if (os_strcmp(buf, "rssi_reject_assoc_rssi") == 0) {
4948 conf->rssi_reject_assoc_rssi = atoi(pos);
4949 } else if (os_strcmp(buf, "rssi_reject_assoc_timeout") == 0) {
4950 conf->rssi_reject_assoc_timeout = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004951 } else if (os_strcmp(buf, "rssi_ignore_probe_request") == 0) {
4952 conf->rssi_ignore_probe_request = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004953 } else if (os_strcmp(buf, "pbss") == 0) {
4954 bss->pbss = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004955 } else if (os_strcmp(buf, "transition_disable") == 0) {
4956 bss->transition_disable = strtol(pos, NULL, 16);
Hai Shalom81f62d82019-07-22 12:10:00 -07004957#ifdef CONFIG_AIRTIME_POLICY
4958 } else if (os_strcmp(buf, "airtime_mode") == 0) {
4959 int val = atoi(pos);
4960
4961 if (val < 0 || val > AIRTIME_MODE_MAX) {
4962 wpa_printf(MSG_ERROR, "Line %d: Unknown airtime_mode",
4963 line);
4964 return 1;
4965 }
4966 conf->airtime_mode = val;
4967 } else if (os_strcmp(buf, "airtime_update_interval") == 0) {
4968 conf->airtime_update_interval = atoi(pos);
4969 } else if (os_strcmp(buf, "airtime_bss_weight") == 0) {
4970 bss->airtime_weight = atoi(pos);
4971 } else if (os_strcmp(buf, "airtime_bss_limit") == 0) {
4972 int val = atoi(pos);
4973
4974 if (val < 0 || val > 1) {
4975 wpa_printf(MSG_ERROR,
4976 "Line %d: Invalid airtime_bss_limit (must be 0 or 1)",
4977 line);
4978 return 1;
4979 }
4980 bss->airtime_limit = val;
4981 } else if (os_strcmp(buf, "airtime_sta_weight") == 0) {
4982 if (add_airtime_weight(bss, pos) < 0) {
4983 wpa_printf(MSG_ERROR,
4984 "Line %d: Invalid airtime weight '%s'",
4985 line, pos);
4986 return 1;
4987 }
4988#endif /* CONFIG_AIRTIME_POLICY */
4989#ifdef CONFIG_MACSEC
4990 } else if (os_strcmp(buf, "macsec_policy") == 0) {
4991 int macsec_policy = atoi(pos);
4992
4993 if (macsec_policy < 0 || macsec_policy > 1) {
4994 wpa_printf(MSG_ERROR,
4995 "Line %d: invalid macsec_policy (%d): '%s'.",
4996 line, macsec_policy, pos);
4997 return 1;
4998 }
4999 bss->macsec_policy = macsec_policy;
5000 } else if (os_strcmp(buf, "macsec_integ_only") == 0) {
5001 int macsec_integ_only = atoi(pos);
5002
5003 if (macsec_integ_only < 0 || macsec_integ_only > 1) {
5004 wpa_printf(MSG_ERROR,
5005 "Line %d: invalid macsec_integ_only (%d): '%s'.",
5006 line, macsec_integ_only, pos);
5007 return 1;
5008 }
5009 bss->macsec_integ_only = macsec_integ_only;
5010 } else if (os_strcmp(buf, "macsec_replay_protect") == 0) {
5011 int macsec_replay_protect = atoi(pos);
5012
5013 if (macsec_replay_protect < 0 || macsec_replay_protect > 1) {
5014 wpa_printf(MSG_ERROR,
5015 "Line %d: invalid macsec_replay_protect (%d): '%s'.",
5016 line, macsec_replay_protect, pos);
5017 return 1;
5018 }
5019 bss->macsec_replay_protect = macsec_replay_protect;
5020 } else if (os_strcmp(buf, "macsec_replay_window") == 0) {
5021 bss->macsec_replay_window = atoi(pos);
Sunil Ravi036cec52023-03-29 11:35:17 -07005022 } else if (os_strcmp(buf, "macsec_offload") == 0) {
5023 int macsec_offload = atoi(pos);
5024
5025 if (macsec_offload < 0 || macsec_offload > 2) {
5026 wpa_printf(MSG_ERROR,
5027 "Line %d: invalid macsec_offload (%d): '%s'.",
5028 line, macsec_offload, pos);
5029 return 1;
5030 }
5031 bss->macsec_offload = macsec_offload;
Hai Shalom81f62d82019-07-22 12:10:00 -07005032 } else if (os_strcmp(buf, "macsec_port") == 0) {
5033 int macsec_port = atoi(pos);
5034
5035 if (macsec_port < 1 || macsec_port > 65534) {
5036 wpa_printf(MSG_ERROR,
5037 "Line %d: invalid macsec_port (%d): '%s'.",
5038 line, macsec_port, pos);
5039 return 1;
5040 }
5041 bss->macsec_port = macsec_port;
5042 } else if (os_strcmp(buf, "mka_priority") == 0) {
5043 int mka_priority = atoi(pos);
5044
5045 if (mka_priority < 0 || mka_priority > 255) {
5046 wpa_printf(MSG_ERROR,
5047 "Line %d: invalid mka_priority (%d): '%s'.",
5048 line, mka_priority, pos);
5049 return 1;
5050 }
5051 bss->mka_priority = mka_priority;
Sunil Ravia04bd252022-05-02 22:54:18 -07005052 } else if (os_strcmp(buf, "macsec_csindex") == 0) {
5053 int macsec_csindex = atoi(pos);
5054
5055 if (macsec_csindex < 0 || macsec_csindex > 1) {
5056 wpa_printf(MSG_ERROR,
5057 "Line %d: invalid macsec_csindex (%d): '%s'.",
5058 line, macsec_csindex, pos);
5059 return 1;
5060 }
5061 bss->macsec_csindex = macsec_csindex;
Hai Shalom81f62d82019-07-22 12:10:00 -07005062 } else if (os_strcmp(buf, "mka_cak") == 0) {
5063 size_t len = os_strlen(pos);
5064
5065 if (len > 2 * MACSEC_CAK_MAX_LEN ||
5066 (len != 2 * 16 && len != 2 * 32) ||
5067 hexstr2bin(pos, bss->mka_cak, len / 2)) {
5068 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.",
5069 line, pos);
5070 return 1;
5071 }
5072 bss->mka_cak_len = len / 2;
5073 bss->mka_psk_set |= MKA_PSK_SET_CAK;
5074 } else if (os_strcmp(buf, "mka_ckn") == 0) {
5075 size_t len = os_strlen(pos);
5076
5077 if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */
5078 len < 2 || /* too short */
5079 len % 2 != 0 /* not an integral number of bytes */) {
5080 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
5081 line, pos);
5082 return 1;
5083 }
5084 bss->mka_ckn_len = len / 2;
5085 if (hexstr2bin(pos, bss->mka_ckn, bss->mka_ckn_len)) {
5086 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
5087 line, pos);
5088 return -1;
5089 }
5090 bss->mka_psk_set |= MKA_PSK_SET_CKN;
5091#endif /* CONFIG_MACSEC */
Hai Shalom60840252021-02-19 19:02:11 -08005092 } else if (os_strcmp(buf, "disable_11n") == 0) {
5093 bss->disable_11n = !!atoi(pos);
5094 } else if (os_strcmp(buf, "disable_11ac") == 0) {
5095 bss->disable_11ac = !!atoi(pos);
5096 } else if (os_strcmp(buf, "disable_11ax") == 0) {
5097 bss->disable_11ax = !!atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07005098 } else if (os_strcmp(buf, "disable_11be") == 0) {
5099 bss->disable_11be = !!atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08005100#ifdef CONFIG_PASN
5101#ifdef CONFIG_TESTING_OPTIONS
5102 } else if (os_strcmp(buf, "force_kdk_derivation") == 0) {
5103 bss->force_kdk_derivation = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005104 } else if (os_strcmp(buf, "pasn_corrupt_mic") == 0) {
5105 bss->pasn_corrupt_mic = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08005106#endif /* CONFIG_TESTING_OPTIONS */
5107 } else if (os_strcmp(buf, "pasn_groups") == 0) {
5108 if (hostapd_parse_intlist(&bss->pasn_groups, pos)) {
5109 wpa_printf(MSG_ERROR,
5110 "Line %d: Invalid pasn_groups value '%s'",
5111 line, pos);
5112 return 1;
5113 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08005114 } else if (os_strcmp(buf, "pasn_comeback_after") == 0) {
5115 bss->pasn_comeback_after = atoi(pos);
Sunil Ravi640215c2023-06-28 23:08:09 +00005116 } else if (os_strcmp(buf, "pasn_noauth") == 0) {
5117 bss->pasn_noauth = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08005118#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -08005119 } else if (os_strcmp(buf, "ext_capa_mask") == 0) {
5120 if (get_hex_config(bss->ext_capa_mask, EXT_CAPA_MAX_LEN,
5121 line, "ext_capa_mask", pos))
5122 return 1;
5123 } else if (os_strcmp(buf, "ext_capa") == 0) {
5124 if (get_hex_config(bss->ext_capa, EXT_CAPA_MAX_LEN,
5125 line, "ext_capa", pos))
5126 return 1;
5127 } else if (os_strcmp(buf, "rnr") == 0) {
5128 bss->rnr = atoi(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00005129 } else if (os_strcmp(buf, "ssid_protection") == 0) {
5130 int val = atoi(pos);
5131
5132 if (val < 0 || val > 1)
5133 return 1;
5134 bss->ssid_protection = val;
Sunil Ravia04bd252022-05-02 22:54:18 -07005135#ifdef CONFIG_IEEE80211BE
5136 } else if (os_strcmp(buf, "ieee80211be") == 0) {
5137 conf->ieee80211be = atoi(pos);
5138 } else if (os_strcmp(buf, "eht_oper_chwidth") == 0) {
5139 conf->eht_oper_chwidth = atoi(pos);
5140 } else if (os_strcmp(buf, "eht_oper_centr_freq_seg0_idx") == 0) {
5141 conf->eht_oper_centr_freq_seg0_idx = atoi(pos);
5142 } else if (os_strcmp(buf, "eht_su_beamformer") == 0) {
5143 conf->eht_phy_capab.su_beamformer = atoi(pos);
5144 } else if (os_strcmp(buf, "eht_su_beamformee") == 0) {
5145 conf->eht_phy_capab.su_beamformee = atoi(pos);
5146 } else if (os_strcmp(buf, "eht_mu_beamformer") == 0) {
5147 conf->eht_phy_capab.mu_beamformer = atoi(pos);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005148 } else if (os_strcmp(buf, "eht_default_pe_duration") == 0) {
5149 conf->eht_default_pe_duration = atoi(pos);
Sunil Ravi036cec52023-03-29 11:35:17 -07005150 } else if (os_strcmp(buf, "punct_bitmap") == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005151 if (get_u16(pos, line, &conf->punct_bitmap))
5152 return 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07005153 } else if (os_strcmp(buf, "punct_acs_threshold") == 0) {
5154 int val = atoi(pos);
5155
5156 if (val < 0 || val > 100) {
5157 wpa_printf(MSG_ERROR,
5158 "Line %d: punct_acs_threshold must be between 0 and 100",
5159 line);
5160 return 1;
5161 }
5162 conf->punct_acs_threshold = val;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005163 } else if (os_strcmp(buf, "mld_ap") == 0) {
5164 bss->mld_ap = !!atoi(pos);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005165 } else if (os_strcmp(buf, "mld_addr") == 0) {
5166 if (hwaddr_aton(pos, bss->mld_addr)) {
5167 wpa_printf(MSG_ERROR, "Line %d: Invalid mld_addr",
5168 line);
5169 return 1;
5170 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005171 } else if (os_strcmp(buf, "eht_bw320_offset") == 0) {
5172 conf->eht_bw320_offset = atoi(pos);
5173#ifdef CONFIG_TESTING_OPTIONS
5174 } else if (os_strcmp(buf, "eht_oper_puncturing_override") == 0) {
5175 if (get_u16(pos, line, &bss->eht_oper_puncturing_override))
5176 return 1;
5177 } else if (os_strcmp(buf, "mld_indicate_disabled") == 0) {
5178 bss->mld_indicate_disabled = atoi(pos);
5179#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07005180#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07005181 } else {
5182 wpa_printf(MSG_ERROR,
5183 "Line %d: unknown configuration item '%s'",
5184 line, buf);
5185 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005186 }
5187
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07005188 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005189}
5190
5191
Dmitry Shmidt04949592012-07-19 12:16:46 -07005192/**
5193 * hostapd_config_read - Read and parse a configuration file
5194 * @fname: Configuration file name (including path, if needed)
5195 * Returns: Allocated configuration data structure
5196 */
5197struct hostapd_config * hostapd_config_read(const char *fname)
5198{
5199 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005200 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005201 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005202 int line = 0;
5203 int errors = 0;
5204 size_t i;
5205
5206 f = fopen(fname, "r");
5207 if (f == NULL) {
5208 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
5209 "for reading.", fname);
5210 return NULL;
5211 }
5212
5213 conf = hostapd_config_defaults();
5214 if (conf == NULL) {
5215 fclose(f);
5216 return NULL;
5217 }
5218
5219 /* set default driver based on configuration */
5220 conf->driver = wpa_drivers[0];
5221 if (conf->driver == NULL) {
5222 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
5223 hostapd_config_free(conf);
5224 fclose(f);
5225 return NULL;
5226 }
5227
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005228 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07005229
5230 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005231 struct hostapd_bss_config *bss;
5232
Dmitry Shmidt04949592012-07-19 12:16:46 -07005233 bss = conf->last_bss;
5234 line++;
5235
5236 if (buf[0] == '#')
5237 continue;
5238 pos = buf;
5239 while (*pos != '\0') {
5240 if (*pos == '\n') {
5241 *pos = '\0';
5242 break;
5243 }
5244 pos++;
5245 }
5246 if (buf[0] == '\0')
5247 continue;
5248
5249 pos = os_strchr(buf, '=');
5250 if (pos == NULL) {
5251 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
5252 line, buf);
5253 errors++;
5254 continue;
5255 }
5256 *pos = '\0';
5257 pos++;
5258 errors += hostapd_config_fill(conf, bss, buf, pos, line);
5259 }
5260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005261 fclose(f);
5262
Dmitry Shmidt04949592012-07-19 12:16:46 -07005263 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07005264 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005265
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005266 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005267 errors++;
5268
5269#ifndef WPA_IGNORE_CONFIG_ERRORS
5270 if (errors) {
5271 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
5272 "'%s'", errors, fname);
5273 hostapd_config_free(conf);
5274 conf = NULL;
5275 }
5276#endif /* WPA_IGNORE_CONFIG_ERRORS */
5277
5278 return conf;
5279}
Dmitry Shmidt04949592012-07-19 12:16:46 -07005280
5281
5282int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005283 struct hostapd_bss_config *bss, const char *field,
5284 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005285{
5286 int errors;
5287 size_t i;
5288
5289 errors = hostapd_config_fill(conf, bss, field, value, 0);
5290 if (errors) {
5291 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
5292 "to value '%s'", field, value);
5293 return -1;
5294 }
5295
5296 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07005297 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005298
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005299 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07005300 wpa_printf(MSG_ERROR, "Configuration check failed");
5301 return -1;
5302 }
5303
5304 return 0;
5305}