blob: 24fd29707cec4037ad55c9f88f76507ff968c038 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2003-2018, 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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
671 val |= WPA_KEY_MGMT_PSK_SHA256;
672 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
673 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800674#ifdef CONFIG_SAE
675 else if (os_strcmp(start, "SAE") == 0)
676 val |= WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -0700677 else if (os_strcmp(start, "SAE-EXT-KEY") == 0)
678 val |= WPA_KEY_MGMT_SAE_EXT_KEY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800679 else if (os_strcmp(start, "FT-SAE") == 0)
680 val |= WPA_KEY_MGMT_FT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -0700681 else if (os_strcmp(start, "FT-SAE-EXT-KEY") == 0)
682 val |= WPA_KEY_MGMT_FT_SAE_EXT_KEY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800683#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800684#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800685 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
686 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800687#endif /* CONFIG_SUITEB */
688#ifdef CONFIG_SUITEB192
689 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
690 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
691#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800692#ifdef CONFIG_FILS
693 else if (os_strcmp(start, "FILS-SHA256") == 0)
694 val |= WPA_KEY_MGMT_FILS_SHA256;
695 else if (os_strcmp(start, "FILS-SHA384") == 0)
696 val |= WPA_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800697#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800698 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
699 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
700 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
701 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800702#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800703#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700704#ifdef CONFIG_OWE
705 else if (os_strcmp(start, "OWE") == 0)
706 val |= WPA_KEY_MGMT_OWE;
707#endif /* CONFIG_OWE */
708#ifdef CONFIG_DPP
709 else if (os_strcmp(start, "DPP") == 0)
710 val |= WPA_KEY_MGMT_DPP;
711#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700712#ifdef CONFIG_HS20
713 else if (os_strcmp(start, "OSEN") == 0)
714 val |= WPA_KEY_MGMT_OSEN;
715#endif /* CONFIG_HS20 */
Hai Shalom60840252021-02-19 19:02:11 -0800716#ifdef CONFIG_PASN
717 else if (os_strcmp(start, "PASN") == 0)
718 val |= WPA_KEY_MGMT_PASN;
719#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 else {
721 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
722 line, start);
723 os_free(buf);
724 return -1;
725 }
726
727 if (last)
728 break;
729 start = end + 1;
730 }
731
732 os_free(buf);
733 if (val == 0) {
734 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
735 "configured.", line);
736 return -1;
737 }
738
739 return val;
740}
741
742
743static int hostapd_config_parse_cipher(int line, const char *value)
744{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800745 int val = wpa_parse_cipher(value);
746 if (val < 0) {
747 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
748 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751 if (val == 0) {
752 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
753 line);
754 return -1;
755 }
756 return val;
757}
758
759
Hai Shalomfdcde762020-04-02 11:19:20 -0700760#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
762 char *val)
763{
764 size_t len = os_strlen(val);
765
Dmitry Shmidt29333592017-01-09 12:27:11 -0800766 if (keyidx < 0 || keyidx > 3)
767 return -1;
768
769 if (len == 0) {
770 int i, set = 0;
771
772 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
773 wep->key[keyidx] = NULL;
774 wep->len[keyidx] = 0;
775 for (i = 0; i < NUM_WEP_KEYS; i++) {
776 if (wep->key[i])
777 set++;
778 }
779 if (!set)
780 wep->keys_set = 0;
781 return 0;
782 }
783
784 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 return -1;
786
787 if (val[0] == '"') {
788 if (len < 2 || val[len - 1] != '"')
789 return -1;
790 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700791 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792 if (wep->key[keyidx] == NULL)
793 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 wep->len[keyidx] = len;
795 } else {
796 if (len & 1)
797 return -1;
798 len /= 2;
799 wep->key[keyidx] = os_malloc(len);
800 if (wep->key[keyidx] == NULL)
801 return -1;
802 wep->len[keyidx] = len;
803 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
804 return -1;
805 }
806
807 wep->keys_set++;
808
809 return 0;
810}
Hai Shalomfdcde762020-04-02 11:19:20 -0700811#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812
813
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700814static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
815{
816 char *pos;
817
818 /* for backwards compatibility, translate ' ' in conf str to ',' */
819 pos = val;
820 while (pos) {
821 pos = os_strchr(pos, ' ');
822 if (pos)
823 *pos++ = ',';
824 }
825 if (freq_range_list_parse(&conf->acs_ch_list, val))
826 return -1;
827
828 return 0;
829}
830
831
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700832static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833{
834 int *list;
835 int count;
836 char *pos, *end;
837
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700838 os_free(*int_list);
839 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840
841 pos = val;
842 count = 0;
843 while (*pos != '\0') {
844 if (*pos == ' ')
845 count++;
846 pos++;
847 }
848
849 list = os_malloc(sizeof(int) * (count + 2));
850 if (list == NULL)
851 return -1;
852 pos = val;
853 count = 0;
854 while (*pos != '\0') {
855 end = os_strchr(pos, ' ');
856 if (end)
857 *end = '\0';
858
859 list[count++] = atoi(pos);
860 if (!end)
861 break;
862 pos = end + 1;
863 }
864 list[count] = -1;
865
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700866 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867 return 0;
868}
869
870
871static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
872{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800873 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874
875 if (*ifname == '\0')
876 return -1;
877
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800878 all = os_realloc_array(conf->bss, conf->num_bss + 1,
879 sizeof(struct hostapd_bss_config *));
880 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
882 "multi-BSS entry");
883 return -1;
884 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800885 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800887 bss = os_zalloc(sizeof(*bss));
888 if (bss == NULL)
889 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890 bss->radius = os_zalloc(sizeof(*bss->radius));
891 if (bss->radius == NULL) {
892 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
893 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800894 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 return -1;
896 }
897
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800898 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 conf->last_bss = bss;
900
901 hostapd_config_defaults_bss(bss);
902 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
903 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
904
905 return 0;
906}
907
908
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800909#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700910
911static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
912{
913 u8 oldkey[16];
914 int ret;
915
916 if (!hexstr2bin(pos, key, key_len))
917 return 0;
918
919 /* Try to use old short key for backwards compatibility */
920 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
921 return -1;
922
923 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
924 key, key_len);
925 os_memset(oldkey, 0, sizeof(oldkey));
926 return ret;
927}
928
929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930static int add_r0kh(struct hostapd_bss_config *bss, char *value)
931{
932 struct ft_remote_r0kh *r0kh;
933 char *pos, *next;
934
935 r0kh = os_zalloc(sizeof(*r0kh));
936 if (r0kh == NULL)
937 return -1;
938
939 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
940 pos = value;
941 next = os_strchr(pos, ' ');
942 if (next)
943 *next++ = '\0';
944 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
945 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
946 os_free(r0kh);
947 return -1;
948 }
949
950 pos = next;
951 next = os_strchr(pos, ' ');
952 if (next)
953 *next++ = '\0';
954 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
955 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
956 os_free(r0kh);
957 return -1;
958 }
959 r0kh->id_len = next - pos - 1;
960 os_memcpy(r0kh->id, pos, r0kh->id_len);
961
962 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700963 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700964 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
965 os_free(r0kh);
966 return -1;
967 }
968
969 r0kh->next = bss->r0kh_list;
970 bss->r0kh_list = r0kh;
971
972 return 0;
973}
974
975
976static int add_r1kh(struct hostapd_bss_config *bss, char *value)
977{
978 struct ft_remote_r1kh *r1kh;
979 char *pos, *next;
980
981 r1kh = os_zalloc(sizeof(*r1kh));
982 if (r1kh == NULL)
983 return -1;
984
985 /* 02:01:02:03:04:05 02:01:02:03:04:05
986 * 000102030405060708090a0b0c0d0e0f */
987 pos = value;
988 next = os_strchr(pos, ' ');
989 if (next)
990 *next++ = '\0';
991 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
992 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
993 os_free(r1kh);
994 return -1;
995 }
996
997 pos = next;
998 next = os_strchr(pos, ' ');
999 if (next)
1000 *next++ = '\0';
1001 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1002 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1003 os_free(r1kh);
1004 return -1;
1005 }
1006
1007 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001008 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1010 os_free(r1kh);
1011 return -1;
1012 }
1013
1014 r1kh->next = bss->r1kh_list;
1015 bss->r1kh_list = r1kh;
1016
1017 return 0;
1018}
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001019#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020
1021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022static int hostapd_config_ht_capab(struct hostapd_config *conf,
1023 const char *capab)
1024{
1025 if (os_strstr(capab, "[LDPC]"))
1026 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1027 if (os_strstr(capab, "[HT40-]")) {
1028 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1029 conf->secondary_channel = -1;
1030 }
1031 if (os_strstr(capab, "[HT40+]")) {
1032 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1033 conf->secondary_channel = 1;
1034 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001035 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1036 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1037 conf->ht40_plus_minus_allowed = 1;
1038 }
Hai Shalomce48b4a2018-09-05 11:41:35 -07001039 if (!os_strstr(capab, "[HT40+]") && !os_strstr(capab, "[HT40-]"))
1040 conf->secondary_channel = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041 if (os_strstr(capab, "[GF]"))
1042 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1043 if (os_strstr(capab, "[SHORT-GI-20]"))
1044 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1045 if (os_strstr(capab, "[SHORT-GI-40]"))
1046 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1047 if (os_strstr(capab, "[TX-STBC]"))
1048 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1049 if (os_strstr(capab, "[RX-STBC1]")) {
1050 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1051 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1052 }
1053 if (os_strstr(capab, "[RX-STBC12]")) {
1054 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1055 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1056 }
1057 if (os_strstr(capab, "[RX-STBC123]")) {
1058 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1059 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1060 }
1061 if (os_strstr(capab, "[DELAYED-BA]"))
1062 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1063 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1064 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1065 if (os_strstr(capab, "[DSSS_CCK-40]"))
1066 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001067 if (os_strstr(capab, "[40-INTOLERANT]"))
1068 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1070 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1071
1072 return 0;
1073}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074
1075
Dmitry Shmidt04949592012-07-19 12:16:46 -07001076#ifdef CONFIG_IEEE80211AC
1077static int hostapd_config_vht_capab(struct hostapd_config *conf,
1078 const char *capab)
1079{
1080 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1081 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1082 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1083 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1084 if (os_strstr(capab, "[VHT160]"))
1085 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1086 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1087 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001088 if (os_strstr(capab, "[RXLDPC]"))
1089 conf->vht_capab |= VHT_CAP_RXLDPC;
1090 if (os_strstr(capab, "[SHORT-GI-80]"))
1091 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1092 if (os_strstr(capab, "[SHORT-GI-160]"))
1093 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1094 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1095 conf->vht_capab |= VHT_CAP_TXSTBC;
1096 if (os_strstr(capab, "[RX-STBC-1]"))
1097 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1098 if (os_strstr(capab, "[RX-STBC-12]"))
1099 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1100 if (os_strstr(capab, "[RX-STBC-123]"))
1101 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1102 if (os_strstr(capab, "[RX-STBC-1234]"))
1103 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1104 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001105 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001106 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001107 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001108 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001109 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1110 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001111 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1112 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1113 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1114 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1115 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1116 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001117 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001118 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1119 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001120 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1121 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1122 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1123 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1124 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1125 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001126 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1127 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001128 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1129 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1130 if (os_strstr(capab, "[HTC-VHT]"))
1131 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001132 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1133 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1134 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1135 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1136 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1137 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1138 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1139 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1140 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1141 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1142 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1143 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1144 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1145 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001146 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1147 (conf->vht_capab & VHT_CAP_HTC_VHT))
1148 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1149 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1150 (conf->vht_capab & VHT_CAP_HTC_VHT))
1151 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1152 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1153 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1154 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1155 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1156 return 0;
1157}
1158#endif /* CONFIG_IEEE80211AC */
1159
1160
Hai Shalom74f70d42019-02-11 14:42:39 -08001161#ifdef CONFIG_IEEE80211AX
1162
1163static u8 find_bit_offset(u8 val)
1164{
1165 u8 res = 0;
1166
1167 for (; val; val >>= 1) {
1168 if (val & 1)
1169 break;
1170 res++;
1171 }
1172
1173 return res;
1174}
1175
1176
1177static u8 set_he_cap(int val, u8 mask)
1178{
1179 return (u8) (mask & (val << find_bit_offset(mask)));
1180}
1181
Hai Shalom60840252021-02-19 19:02:11 -08001182
1183static int hostapd_parse_he_srg_bitmap(u8 *bitmap, char *val)
1184{
1185 int bitpos;
1186 char *pos, *end;
1187
1188 os_memset(bitmap, 0, 8);
1189 pos = val;
1190 while (*pos != '\0') {
1191 end = os_strchr(pos, ' ');
1192 if (end)
1193 *end = '\0';
1194
1195 bitpos = atoi(pos);
1196 if (bitpos < 0 || bitpos > 64)
1197 return -1;
1198
1199 bitmap[bitpos / 8] |= BIT(bitpos % 8);
1200 if (!end)
1201 break;
1202 pos = end + 1;
1203 }
1204
1205 return 0;
1206}
1207
Hai Shalom74f70d42019-02-11 14:42:39 -08001208#endif /* CONFIG_IEEE80211AX */
1209
1210
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001211#ifdef CONFIG_INTERWORKING
1212static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1213 int line)
1214{
1215 size_t len = os_strlen(pos);
1216 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1217
1218 struct hostapd_roaming_consortium *rc;
1219
1220 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1221 hexstr2bin(pos, oi, len / 2)) {
1222 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1223 "'%s'", line, pos);
1224 return -1;
1225 }
1226 len /= 2;
1227
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001228 rc = os_realloc_array(bss->roaming_consortium,
1229 bss->roaming_consortium_count + 1,
1230 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001231 if (rc == NULL)
1232 return -1;
1233
1234 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1235 rc[bss->roaming_consortium_count].len = len;
1236
1237 bss->roaming_consortium = rc;
1238 bss->roaming_consortium_count++;
1239
1240 return 0;
1241}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001242
1243
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001244static int parse_lang_string(struct hostapd_lang_string **array,
1245 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001246{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001247 char *sep, *str = NULL;
1248 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001249 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001250 int ret = -1;
1251
1252 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1253 str = wpa_config_parse_string(pos, &slen);
1254 if (!str)
1255 return -1;
1256 pos = str;
1257 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001258
1259 sep = os_strchr(pos, ':');
1260 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001261 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001262 *sep++ = '\0';
1263
1264 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001265 if (clen < 2 || clen > sizeof(ls->lang))
1266 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001267 nlen = os_strlen(sep);
1268 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001269 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001270
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001271 ls = os_realloc_array(*array, *count + 1,
1272 sizeof(struct hostapd_lang_string));
1273 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001274 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001275
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001276 *array = ls;
1277 ls = &(*array)[*count];
1278 (*count)++;
1279
1280 os_memset(ls->lang, 0, sizeof(ls->lang));
1281 os_memcpy(ls->lang, pos, clen);
1282 ls->name_len = nlen;
1283 os_memcpy(ls->name, sep, nlen);
1284
Dmitry Shmidt56052862013-10-04 10:23:25 -07001285 ret = 0;
1286fail:
1287 os_free(str);
1288 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001289}
1290
1291
1292static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1293 int line)
1294{
1295 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1296 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1297 line, pos);
1298 return -1;
1299 }
1300 return 0;
1301}
1302
1303
Roshan Pius3a1667e2018-07-03 15:17:14 -07001304static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1305 int line)
1306{
1307 char *sep;
1308 size_t nlen;
1309 struct hostapd_venue_url *url;
1310 int ret = -1;
1311
1312 sep = os_strchr(pos, ':');
1313 if (!sep)
1314 goto fail;
1315 *sep++ = '\0';
1316
1317 nlen = os_strlen(sep);
1318 if (nlen > 254)
1319 goto fail;
1320
1321 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1322 sizeof(struct hostapd_venue_url));
1323 if (!url)
1324 goto fail;
1325
1326 bss->venue_url = url;
1327 url = &bss->venue_url[bss->venue_url_count++];
1328
1329 url->venue_number = atoi(pos);
1330 url->url_len = nlen;
1331 os_memcpy(url->url, sep, nlen);
1332
1333 ret = 0;
1334fail:
1335 if (ret)
1336 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1337 line, pos);
1338 return ret;
1339}
1340
1341
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001342static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1343 int line)
1344{
1345 size_t count;
1346 char *pos;
1347 u8 *info = NULL, *ipos;
1348
1349 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1350
1351 count = 1;
1352 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001353 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001354 goto fail;
1355 if (*pos == ';')
1356 count++;
1357 }
1358 if (1 + count * 3 > 0x7f)
1359 goto fail;
1360
1361 info = os_zalloc(2 + 3 + count * 3);
1362 if (info == NULL)
1363 return -1;
1364
1365 ipos = info;
1366 *ipos++ = 0; /* GUD - Version 1 */
1367 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1368 *ipos++ = 0; /* PLMN List IEI */
1369 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1370 *ipos++ = 1 + count * 3;
1371 *ipos++ = count; /* Number of PLMNs */
1372
1373 pos = buf;
1374 while (pos && *pos) {
1375 char *mcc, *mnc;
1376 size_t mnc_len;
1377
1378 mcc = pos;
1379 mnc = os_strchr(pos, ',');
1380 if (mnc == NULL)
1381 goto fail;
1382 *mnc++ = '\0';
1383 pos = os_strchr(mnc, ';');
1384 if (pos)
1385 *pos++ = '\0';
1386
1387 mnc_len = os_strlen(mnc);
1388 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1389 goto fail;
1390
1391 /* BC coded MCC,MNC */
1392 /* MCC digit 2 | MCC digit 1 */
1393 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1394 /* MNC digit 3 | MCC digit 3 */
1395 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1396 (mcc[2] - '0');
1397 /* MNC digit 2 | MNC digit 1 */
1398 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1399 }
1400
1401 os_free(bss->anqp_3gpp_cell_net);
1402 bss->anqp_3gpp_cell_net = info;
1403 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1404 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1405 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001406
1407 return 0;
1408
1409fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001410 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1411 line, buf);
1412 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001413 return -1;
1414}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001415
1416
1417static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1418{
1419 struct hostapd_nai_realm_data *realm;
1420 size_t i, j, len;
1421 int *offsets;
1422 char *pos, *end, *rpos;
1423
1424 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1425 sizeof(int));
1426 if (offsets == NULL)
1427 return -1;
1428
1429 for (i = 0; i < bss->nai_realm_count; i++) {
1430 realm = &bss->nai_realm_data[i];
1431 for (j = 0; j < MAX_NAI_REALMS; j++) {
1432 offsets[i * MAX_NAI_REALMS + j] =
1433 realm->realm[j] ?
1434 realm->realm[j] - realm->realm_buf : -1;
1435 }
1436 }
1437
1438 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1439 sizeof(struct hostapd_nai_realm_data));
1440 if (realm == NULL) {
1441 os_free(offsets);
1442 return -1;
1443 }
1444 bss->nai_realm_data = realm;
1445
1446 /* patch the pointers after realloc */
1447 for (i = 0; i < bss->nai_realm_count; i++) {
1448 realm = &bss->nai_realm_data[i];
1449 for (j = 0; j < MAX_NAI_REALMS; j++) {
1450 int offs = offsets[i * MAX_NAI_REALMS + j];
1451 if (offs >= 0)
1452 realm->realm[j] = realm->realm_buf + offs;
1453 else
1454 realm->realm[j] = NULL;
1455 }
1456 }
1457 os_free(offsets);
1458
1459 realm = &bss->nai_realm_data[bss->nai_realm_count];
1460 os_memset(realm, 0, sizeof(*realm));
1461
1462 pos = buf;
1463 realm->encoding = atoi(pos);
1464 pos = os_strchr(pos, ',');
1465 if (pos == NULL)
1466 goto fail;
1467 pos++;
1468
1469 end = os_strchr(pos, ',');
1470 if (end) {
1471 len = end - pos;
1472 *end = '\0';
1473 } else {
1474 len = os_strlen(pos);
1475 }
1476
1477 if (len > MAX_NAI_REALMLEN) {
1478 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1479 "characters)", (int) len, MAX_NAI_REALMLEN);
1480 goto fail;
1481 }
1482 os_memcpy(realm->realm_buf, pos, len);
1483
1484 if (end)
1485 pos = end + 1;
1486 else
1487 pos = NULL;
1488
1489 while (pos && *pos) {
1490 struct hostapd_nai_realm_eap *eap;
1491
1492 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1493 wpa_printf(MSG_ERROR, "Too many EAP methods");
1494 goto fail;
1495 }
1496
1497 eap = &realm->eap_method[realm->eap_method_count];
1498 realm->eap_method_count++;
1499
1500 end = os_strchr(pos, ',');
1501 if (end == NULL)
1502 end = pos + os_strlen(pos);
1503
1504 eap->eap_method = atoi(pos);
1505 for (;;) {
1506 pos = os_strchr(pos, '[');
1507 if (pos == NULL || pos > end)
1508 break;
1509 pos++;
1510 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1511 wpa_printf(MSG_ERROR, "Too many auth params");
1512 goto fail;
1513 }
1514 eap->auth_id[eap->num_auths] = atoi(pos);
1515 pos = os_strchr(pos, ':');
1516 if (pos == NULL || pos > end)
1517 goto fail;
1518 pos++;
1519 eap->auth_val[eap->num_auths] = atoi(pos);
1520 pos = os_strchr(pos, ']');
1521 if (pos == NULL || pos > end)
1522 goto fail;
1523 pos++;
1524 eap->num_auths++;
1525 }
1526
1527 if (*end != ',')
1528 break;
1529
1530 pos = end + 1;
1531 }
1532
1533 /* Split realm list into null terminated realms */
1534 rpos = realm->realm_buf;
1535 i = 0;
1536 while (*rpos) {
1537 if (i >= MAX_NAI_REALMS) {
1538 wpa_printf(MSG_ERROR, "Too many realms");
1539 goto fail;
1540 }
1541 realm->realm[i++] = rpos;
1542 rpos = os_strchr(rpos, ';');
1543 if (rpos == NULL)
1544 break;
1545 *rpos++ = '\0';
1546 }
1547
1548 bss->nai_realm_count++;
1549
1550 return 0;
1551
1552fail:
1553 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1554 return -1;
1555}
1556
Dmitry Shmidt051af732013-10-22 13:52:46 -07001557
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001558static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1559{
1560 char *delim;
1561 u16 infoid;
1562 size_t len;
1563 struct wpabuf *payload;
1564 struct anqp_element *elem;
1565
1566 delim = os_strchr(buf, ':');
1567 if (!delim)
1568 return -1;
1569 delim++;
1570 infoid = atoi(buf);
1571 len = os_strlen(delim);
1572 if (len & 1)
1573 return -1;
1574 len /= 2;
1575 payload = wpabuf_alloc(len);
1576 if (!payload)
1577 return -1;
1578 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1579 wpabuf_free(payload);
1580 return -1;
1581 }
1582
1583 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1584 if (elem->infoid == infoid) {
1585 /* Update existing entry */
1586 wpabuf_free(elem->payload);
1587 elem->payload = payload;
1588 return 0;
1589 }
1590 }
1591
1592 /* Add a new entry */
1593 elem = os_zalloc(sizeof(*elem));
1594 if (!elem) {
1595 wpabuf_free(payload);
1596 return -1;
1597 }
1598 elem->infoid = infoid;
1599 elem->payload = payload;
1600 dl_list_add(&bss->anqp_elem, &elem->list);
1601
1602 return 0;
1603}
1604
1605
Dmitry Shmidt051af732013-10-22 13:52:46 -07001606static int parse_qos_map_set(struct hostapd_bss_config *bss,
1607 char *buf, int line)
1608{
1609 u8 qos_map_set[16 + 2 * 21], count = 0;
1610 char *pos = buf;
1611 int val;
1612
1613 for (;;) {
1614 if (count == sizeof(qos_map_set)) {
1615 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1616 "parameters '%s'", line, buf);
1617 return -1;
1618 }
1619
1620 val = atoi(pos);
1621 if (val > 255 || val < 0) {
1622 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1623 "'%s'", line, buf);
1624 return -1;
1625 }
1626
1627 qos_map_set[count++] = val;
1628 pos = os_strchr(pos, ',');
1629 if (!pos)
1630 break;
1631 pos++;
1632 }
1633
1634 if (count < 16 || count & 1) {
1635 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1636 line, buf);
1637 return -1;
1638 }
1639
1640 os_memcpy(bss->qos_map_set, qos_map_set, count);
1641 bss->qos_map_set_len = count;
1642
1643 return 0;
1644}
1645
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001646#endif /* CONFIG_INTERWORKING */
1647
1648
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001649#ifdef CONFIG_HS20
1650static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1651 int line)
1652{
1653 u8 *conn_cap;
1654 char *pos;
1655
1656 if (bss->hs20_connection_capability_len >= 0xfff0)
1657 return -1;
1658
1659 conn_cap = os_realloc(bss->hs20_connection_capability,
1660 bss->hs20_connection_capability_len + 4);
1661 if (conn_cap == NULL)
1662 return -1;
1663
1664 bss->hs20_connection_capability = conn_cap;
1665 conn_cap += bss->hs20_connection_capability_len;
1666 pos = buf;
1667 conn_cap[0] = atoi(pos);
1668 pos = os_strchr(pos, ':');
1669 if (pos == NULL)
1670 return -1;
1671 pos++;
1672 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1673 pos = os_strchr(pos, ':');
1674 if (pos == NULL)
1675 return -1;
1676 pos++;
1677 conn_cap[3] = atoi(pos);
1678 bss->hs20_connection_capability_len += 4;
1679
1680 return 0;
1681}
1682
1683
1684static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1685 int line)
1686{
1687 u8 *wan_metrics;
1688 char *pos;
1689
1690 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1691
1692 wan_metrics = os_zalloc(13);
1693 if (wan_metrics == NULL)
1694 return -1;
1695
1696 pos = buf;
1697 /* WAN Info */
1698 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1699 goto fail;
1700 pos += 2;
1701 if (*pos != ':')
1702 goto fail;
1703 pos++;
1704
1705 /* Downlink Speed */
1706 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1707 pos = os_strchr(pos, ':');
1708 if (pos == NULL)
1709 goto fail;
1710 pos++;
1711
1712 /* Uplink Speed */
1713 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1714 pos = os_strchr(pos, ':');
1715 if (pos == NULL)
1716 goto fail;
1717 pos++;
1718
1719 /* Downlink Load */
1720 wan_metrics[9] = atoi(pos);
1721 pos = os_strchr(pos, ':');
1722 if (pos == NULL)
1723 goto fail;
1724 pos++;
1725
1726 /* Uplink Load */
1727 wan_metrics[10] = atoi(pos);
1728 pos = os_strchr(pos, ':');
1729 if (pos == NULL)
1730 goto fail;
1731 pos++;
1732
1733 /* LMD */
1734 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1735
1736 os_free(bss->hs20_wan_metrics);
1737 bss->hs20_wan_metrics = wan_metrics;
1738
1739 return 0;
1740
1741fail:
1742 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001743 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001744 os_free(wan_metrics);
1745 return -1;
1746}
1747
1748
1749static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1750 char *pos, int line)
1751{
1752 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1753 &bss->hs20_oper_friendly_name_count, pos)) {
1754 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1755 "hs20_oper_friendly_name '%s'", line, pos);
1756 return -1;
1757 }
1758 return 0;
1759}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001760
1761
1762static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1763{
1764 struct hs20_icon *icon;
1765 char *end;
1766
1767 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1768 sizeof(struct hs20_icon));
1769 if (icon == NULL)
1770 return -1;
1771 bss->hs20_icons = icon;
1772 icon = &bss->hs20_icons[bss->hs20_icons_count];
1773 os_memset(icon, 0, sizeof(*icon));
1774
1775 icon->width = atoi(pos);
1776 pos = os_strchr(pos, ':');
1777 if (pos == NULL)
1778 return -1;
1779 pos++;
1780
1781 icon->height = atoi(pos);
1782 pos = os_strchr(pos, ':');
1783 if (pos == NULL)
1784 return -1;
1785 pos++;
1786
1787 end = os_strchr(pos, ':');
1788 if (end == NULL || end - pos > 3)
1789 return -1;
1790 os_memcpy(icon->language, pos, end - pos);
1791 pos = end + 1;
1792
1793 end = os_strchr(pos, ':');
1794 if (end == NULL || end - pos > 255)
1795 return -1;
1796 os_memcpy(icon->type, pos, end - pos);
1797 pos = end + 1;
1798
1799 end = os_strchr(pos, ':');
1800 if (end == NULL || end - pos > 255)
1801 return -1;
1802 os_memcpy(icon->name, pos, end - pos);
1803 pos = end + 1;
1804
1805 if (os_strlen(pos) > 255)
1806 return -1;
1807 os_memcpy(icon->file, pos, os_strlen(pos));
1808
1809 bss->hs20_icons_count++;
1810
1811 return 0;
1812}
1813
1814
1815static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1816 char *pos, int line)
1817{
1818 size_t slen;
1819 char *str;
1820
1821 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001822 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001823 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001824 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001825 return -1;
1826 }
1827
1828 os_memcpy(bss->osu_ssid, str, slen);
1829 bss->osu_ssid_len = slen;
1830 os_free(str);
1831
1832 return 0;
1833}
1834
1835
1836static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1837 char *pos, int line)
1838{
1839 struct hs20_osu_provider *p;
1840
1841 p = os_realloc_array(bss->hs20_osu_providers,
1842 bss->hs20_osu_providers_count + 1, sizeof(*p));
1843 if (p == NULL)
1844 return -1;
1845
1846 bss->hs20_osu_providers = p;
1847 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1848 bss->hs20_osu_providers_count++;
1849 os_memset(bss->last_osu, 0, sizeof(*p));
1850 bss->last_osu->server_uri = os_strdup(pos);
1851
1852 return 0;
1853}
1854
1855
1856static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1857 char *pos, int line)
1858{
1859 if (bss->last_osu == NULL) {
1860 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1861 return -1;
1862 }
1863
1864 if (parse_lang_string(&bss->last_osu->friendly_name,
1865 &bss->last_osu->friendly_name_count, pos)) {
1866 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1867 line, pos);
1868 return -1;
1869 }
1870
1871 return 0;
1872}
1873
1874
1875static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1876 char *pos, int line)
1877{
1878 if (bss->last_osu == NULL) {
1879 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1880 return -1;
1881 }
1882
1883 os_free(bss->last_osu->osu_nai);
1884 bss->last_osu->osu_nai = os_strdup(pos);
1885 if (bss->last_osu->osu_nai == NULL)
1886 return -1;
1887
1888 return 0;
1889}
1890
1891
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001892static int hs20_parse_osu_nai2(struct hostapd_bss_config *bss,
1893 char *pos, int line)
1894{
1895 if (bss->last_osu == NULL) {
1896 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1897 return -1;
1898 }
1899
1900 os_free(bss->last_osu->osu_nai2);
1901 bss->last_osu->osu_nai2 = os_strdup(pos);
1902 if (bss->last_osu->osu_nai2 == NULL)
1903 return -1;
1904 bss->hs20_osu_providers_nai_count++;
1905
1906 return 0;
1907}
1908
1909
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001910static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1911 int line)
1912{
1913 if (bss->last_osu == NULL) {
1914 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1915 return -1;
1916 }
1917
1918 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1919 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1920 return -1;
1921 }
1922
1923 return 0;
1924}
1925
1926
1927static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1928 int line)
1929{
1930 char **n;
1931 struct hs20_osu_provider *p = bss->last_osu;
1932
1933 if (p == NULL) {
1934 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1935 return -1;
1936 }
1937
1938 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1939 if (n == NULL)
1940 return -1;
1941 p->icons = n;
1942 p->icons[p->icons_count] = os_strdup(pos);
1943 if (p->icons[p->icons_count] == NULL)
1944 return -1;
1945 p->icons_count++;
1946
1947 return 0;
1948}
1949
1950
1951static int hs20_parse_osu_service_desc(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 if (parse_lang_string(&bss->last_osu->service_desc,
1960 &bss->last_osu->service_desc_count, pos)) {
1961 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1962 line, pos);
1963 return -1;
1964 }
1965
1966 return 0;
1967}
1968
Roshan Pius3a1667e2018-07-03 15:17:14 -07001969
1970static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
1971 int line)
1972{
1973 char **n;
1974
1975 n = os_realloc_array(bss->hs20_operator_icon,
1976 bss->hs20_operator_icon_count + 1, sizeof(char *));
1977 if (!n)
1978 return -1;
1979 bss->hs20_operator_icon = n;
1980 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
1981 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
1982 return -1;
1983 bss->hs20_operator_icon_count++;
1984
1985 return 0;
1986}
1987
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001988#endif /* CONFIG_HS20 */
1989
1990
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001991#ifdef CONFIG_ACS
1992static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
1993 char *pos)
1994{
1995 struct acs_bias *bias = NULL, *tmp;
1996 unsigned int num = 0;
1997 char *end;
1998
1999 while (*pos) {
2000 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2001 if (!tmp)
2002 goto fail;
2003 bias = tmp;
2004
2005 bias[num].channel = atoi(pos);
2006 if (bias[num].channel <= 0)
2007 goto fail;
2008 pos = os_strchr(pos, ':');
2009 if (!pos)
2010 goto fail;
2011 pos++;
2012 bias[num].bias = strtod(pos, &end);
2013 if (end == pos || bias[num].bias < 0.0)
2014 goto fail;
2015 pos = end;
2016 if (*pos != ' ' && *pos != '\0')
2017 goto fail;
2018 num++;
2019 }
2020
2021 os_free(conf->acs_chan_bias);
2022 conf->acs_chan_bias = bias;
2023 conf->num_acs_chan_bias = num;
2024
2025 return 0;
2026fail:
2027 os_free(bias);
2028 return -1;
2029}
2030#endif /* CONFIG_ACS */
2031
2032
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002033static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2034 const char *val)
2035{
2036 struct wpabuf *elems;
2037
2038 if (val[0] == '\0') {
2039 wpabuf_free(*buf);
2040 *buf = NULL;
2041 return 0;
2042 }
2043
2044 elems = wpabuf_parse_bin(val);
2045 if (!elems) {
2046 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2047 line, name, val);
2048 return -1;
2049 }
2050
2051 wpabuf_free(*buf);
2052 *buf = elems;
2053
2054 return 0;
2055}
2056
2057
Dmitry Shmidt29333592017-01-09 12:27:11 -08002058#ifdef CONFIG_FILS
2059static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2060{
2061 struct fils_realm *realm;
2062 size_t len;
2063
2064 len = os_strlen(val);
2065 realm = os_zalloc(sizeof(*realm) + len + 1);
2066 if (!realm)
2067 return -1;
2068
2069 os_memcpy(realm->realm, val, len);
2070 if (fils_domain_name_hash(val, realm->hash) < 0) {
2071 os_free(realm);
2072 return -1;
2073 }
2074 dl_list_add_tail(&bss->fils_realms, &realm->list);
2075
2076 return 0;
2077}
2078#endif /* CONFIG_FILS */
2079
2080
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002081#ifdef EAP_SERVER
2082static unsigned int parse_tls_flags(const char *val)
2083{
2084 unsigned int flags = 0;
2085
Roshan Pius3a1667e2018-07-03 15:17:14 -07002086 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2087 * This can be enabled by default once the implementation has been fully
2088 * completed and tested with other implementations. */
2089 flags |= TLS_CONN_DISABLE_TLSv1_3;
2090
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002091 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2092 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2093 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2094 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2095 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2096 flags |= TLS_CONN_DISABLE_TLSv1_0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002097 if (os_strstr(val, "[ENABLE-TLSv1.0]"))
2098 flags |= TLS_CONN_ENABLE_TLSv1_0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002099 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2100 flags |= TLS_CONN_DISABLE_TLSv1_1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002101 if (os_strstr(val, "[ENABLE-TLSv1.1]"))
2102 flags |= TLS_CONN_ENABLE_TLSv1_1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002103 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2104 flags |= TLS_CONN_DISABLE_TLSv1_2;
Hai Shalom74f70d42019-02-11 14:42:39 -08002105 if (os_strstr(val, "[ENABLE-TLSv1.2]"))
2106 flags |= TLS_CONN_ENABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002107 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2108 flags |= TLS_CONN_DISABLE_TLSv1_3;
2109 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2110 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002111 if (os_strstr(val, "[SUITEB]"))
2112 flags |= TLS_CONN_SUITEB;
2113 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2114 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2115
2116 return flags;
2117}
2118#endif /* EAP_SERVER */
2119
2120
Hai Shalom81f62d82019-07-22 12:10:00 -07002121#ifdef CONFIG_AIRTIME_POLICY
2122static int add_airtime_weight(struct hostapd_bss_config *bss, char *value)
2123{
2124 struct airtime_sta_weight *wt;
2125 char *pos, *next;
2126
2127 wt = os_zalloc(sizeof(*wt));
2128 if (!wt)
2129 return -1;
2130
2131 /* 02:01:02:03:04:05 10 */
2132 pos = value;
2133 next = os_strchr(pos, ' ');
2134 if (next)
2135 *next++ = '\0';
2136 if (!next || hwaddr_aton(pos, wt->addr)) {
2137 wpa_printf(MSG_ERROR, "Invalid station address: '%s'", pos);
2138 os_free(wt);
2139 return -1;
2140 }
2141
2142 pos = next;
2143 wt->weight = atoi(pos);
2144 if (!wt->weight) {
2145 wpa_printf(MSG_ERROR, "Invalid weight: '%s'", pos);
2146 os_free(wt);
2147 return -1;
2148 }
2149
2150 wt->next = bss->airtime_weight_list;
2151 bss->airtime_weight_list = wt;
2152 return 0;
2153}
2154#endif /* CONFIG_AIRTIME_POLICY */
2155
2156
Roshan Pius3a1667e2018-07-03 15:17:14 -07002157#ifdef CONFIG_SAE
2158static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2159{
2160 struct sae_password_entry *pw;
2161 const char *pos = val, *pos2, *end = NULL;
2162
2163 pw = os_zalloc(sizeof(*pw));
2164 if (!pw)
2165 return -1;
2166 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2167
2168 pos2 = os_strstr(pos, "|mac=");
2169 if (pos2) {
2170 end = pos2;
2171 pos2 += 5;
2172 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2173 goto fail;
2174 pos = pos2 + ETH_ALEN * 3 - 1;
2175 }
2176
Hai Shalom021b0b52019-04-10 11:17:58 -07002177 pos2 = os_strstr(pos, "|vlanid=");
2178 if (pos2) {
2179 if (!end)
2180 end = pos2;
2181 pos2 += 8;
2182 pw->vlan_id = atoi(pos2);
2183 }
2184
Hai Shalom899fcc72020-10-19 14:38:18 -07002185#ifdef CONFIG_SAE_PK
2186 pos2 = os_strstr(pos, "|pk=");
2187 if (pos2) {
2188 const char *epos;
2189 char *tmp;
2190
2191 if (!end)
2192 end = pos2;
2193 pos2 += 4;
2194 epos = os_strchr(pos2, '|');
2195 if (epos) {
2196 tmp = os_malloc(epos - pos2 + 1);
2197 if (!tmp)
2198 goto fail;
2199 os_memcpy(tmp, pos2, epos - pos2);
2200 tmp[epos - pos2] = '\0';
2201 } else {
2202 tmp = os_strdup(pos2);
2203 if (!tmp)
2204 goto fail;
2205 }
2206
2207 pw->pk = sae_parse_pk(tmp);
2208 str_clear_free(tmp);
2209 if (!pw->pk)
2210 goto fail;
2211 }
2212#endif /* CONFIG_SAE_PK */
2213
Roshan Pius3a1667e2018-07-03 15:17:14 -07002214 pos2 = os_strstr(pos, "|id=");
2215 if (pos2) {
2216 if (!end)
2217 end = pos2;
2218 pos2 += 4;
2219 pw->identifier = os_strdup(pos2);
2220 if (!pw->identifier)
2221 goto fail;
2222 }
2223
2224 if (!end) {
2225 pw->password = os_strdup(val);
2226 if (!pw->password)
2227 goto fail;
2228 } else {
2229 pw->password = os_malloc(end - val + 1);
2230 if (!pw->password)
2231 goto fail;
2232 os_memcpy(pw->password, val, end - val);
2233 pw->password[end - val] = '\0';
2234 }
2235
Hai Shalom899fcc72020-10-19 14:38:18 -07002236#ifdef CONFIG_SAE_PK
2237 if (pw->pk &&
2238#ifdef CONFIG_TESTING_OPTIONS
2239 !bss->sae_pk_password_check_skip &&
2240#endif /* CONFIG_TESTING_OPTIONS */
2241 !sae_pk_valid_password(pw->password)) {
2242 wpa_printf(MSG_INFO,
2243 "Invalid SAE password for a SAE-PK sae_password entry");
2244 goto fail;
2245 }
2246#endif /* CONFIG_SAE_PK */
2247
Roshan Pius3a1667e2018-07-03 15:17:14 -07002248 pw->next = bss->sae_passwords;
2249 bss->sae_passwords = pw;
2250
2251 return 0;
2252fail:
2253 str_clear_free(pw->password);
2254 os_free(pw->identifier);
Hai Shalom899fcc72020-10-19 14:38:18 -07002255#ifdef CONFIG_SAE_PK
2256 sae_deinit_pk(pw->pk);
2257#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002258 os_free(pw);
2259 return -1;
2260}
2261#endif /* CONFIG_SAE */
2262
2263
Hai Shalom81f62d82019-07-22 12:10:00 -07002264#ifdef CONFIG_DPP2
2265static int hostapd_dpp_controller_parse(struct hostapd_bss_config *bss,
2266 const char *pos)
2267{
2268 struct dpp_controller_conf *conf;
2269 char *val;
2270
2271 conf = os_zalloc(sizeof(*conf));
2272 if (!conf)
2273 return -1;
2274 val = get_param(pos, "ipaddr=");
2275 if (!val || hostapd_parse_ip_addr(val, &conf->ipaddr))
2276 goto fail;
2277 os_free(val);
2278 val = get_param(pos, "pkhash=");
2279 if (!val || os_strlen(val) != 2 * SHA256_MAC_LEN ||
2280 hexstr2bin(val, conf->pkhash, SHA256_MAC_LEN) < 0)
2281 goto fail;
2282 os_free(val);
2283 conf->next = bss->dpp_controller;
2284 bss->dpp_controller = conf;
2285 return 0;
2286fail:
2287 os_free(val);
2288 os_free(conf);
2289 return -1;
2290}
2291#endif /* CONFIG_DPP2 */
2292
2293
Hai Shaloma20dcd72022-02-04 13:43:00 -08002294static int get_hex_config(u8 *buf, size_t max_len, int line,
2295 const char *field, const char *val)
2296{
2297 size_t hlen = os_strlen(val), len = hlen / 2;
2298 u8 tmp[EXT_CAPA_MAX_LEN];
2299
2300 os_memset(tmp, 0, EXT_CAPA_MAX_LEN);
2301 if (hlen & 1 || len > EXT_CAPA_MAX_LEN || hexstr2bin(val, tmp, len)) {
2302 wpa_printf(MSG_ERROR, "Line %d: Invalid %s", line, field);
2303 return -1;
2304 }
2305 os_memcpy(buf, tmp, EXT_CAPA_MAX_LEN);
2306 return 0;
2307}
2308
2309
Dmitry Shmidt04949592012-07-19 12:16:46 -07002310static int hostapd_config_fill(struct hostapd_config *conf,
2311 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002312 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002313{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002314 if (os_strcmp(buf, "interface") == 0) {
2315 os_strlcpy(conf->bss[0]->iface, pos,
2316 sizeof(conf->bss[0]->iface));
2317 } else if (os_strcmp(buf, "bridge") == 0) {
2318 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2319 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2320 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2321 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2322 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2323 } else if (os_strcmp(buf, "driver") == 0) {
2324 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002325 const struct wpa_driver_ops *driver = NULL;
2326
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002327 for (j = 0; wpa_drivers[j]; j++) {
2328 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002329 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002330 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002332 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002333 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002334 wpa_printf(MSG_ERROR,
2335 "Line %d: invalid/unknown driver '%s'",
2336 line, pos);
2337 return 1;
2338 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002339 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002340 } else if (os_strcmp(buf, "driver_params") == 0) {
2341 os_free(conf->driver_params);
2342 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002343 } else if (os_strcmp(buf, "debug") == 0) {
2344 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2345 line);
2346 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2347 bss->logger_syslog_level = atoi(pos);
2348 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2349 bss->logger_stdout_level = atoi(pos);
2350 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2351 bss->logger_syslog = atoi(pos);
2352 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2353 bss->logger_stdout = atoi(pos);
2354 } else if (os_strcmp(buf, "dump_file") == 0) {
2355 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2356 line);
2357 } else if (os_strcmp(buf, "ssid") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002358 struct hostapd_ssid *ssid = &bss->ssid;
2359
2360 ssid->ssid_len = os_strlen(pos);
2361 if (ssid->ssid_len > SSID_MAX_LEN || ssid->ssid_len < 1) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002362 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2363 line, pos);
2364 return 1;
2365 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002366 os_memcpy(ssid->ssid, pos, ssid->ssid_len);
2367 ssid->ssid_set = 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07002368 ssid->short_ssid = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002369 } else if (os_strcmp(buf, "ssid2") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002370 struct hostapd_ssid *ssid = &bss->ssid;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002371 size_t slen;
2372 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002373 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002374 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2375 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002376 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002377 return 1;
2378 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002379 os_memcpy(ssid->ssid, str, slen);
2380 ssid->ssid_len = slen;
2381 ssid->ssid_set = 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07002382 ssid->short_ssid = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002383 os_free(str);
2384 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2385 bss->ssid.utf8_ssid = atoi(pos) > 0;
2386 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002387 enum macaddr_acl acl = atoi(pos);
2388
2389 if (acl != ACCEPT_UNLESS_DENIED &&
2390 acl != DENY_UNLESS_ACCEPTED &&
2391 acl != USE_EXTERNAL_RADIUS_AUTH) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002392 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002393 line, acl);
2394 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002395 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002396 bss->macaddr_acl = acl;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002397 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2398 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2399 &bss->num_accept_mac)) {
2400 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2401 line, pos);
2402 return 1;
2403 }
2404 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2405 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2406 &bss->num_deny_mac)) {
2407 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2408 line, pos);
2409 return 1;
2410 }
2411 } else if (os_strcmp(buf, "wds_sta") == 0) {
2412 bss->wds_sta = atoi(pos);
2413 } else if (os_strcmp(buf, "start_disabled") == 0) {
2414 bss->start_disabled = atoi(pos);
2415 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2416 bss->isolate = atoi(pos);
2417 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2418 bss->ap_max_inactivity = atoi(pos);
2419 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2420 bss->skip_inactivity_poll = atoi(pos);
2421 } else if (os_strcmp(buf, "country_code") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002422 if (pos[0] < 'A' || pos[0] > 'Z' ||
2423 pos[1] < 'A' || pos[1] > 'Z') {
2424 wpa_printf(MSG_ERROR,
2425 "Line %d: Invalid country_code '%s'",
2426 line, pos);
2427 return 1;
2428 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002429 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002430 } else if (os_strcmp(buf, "country3") == 0) {
2431 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002432 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2433 conf->ieee80211d = atoi(pos);
2434 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2435 conf->ieee80211h = atoi(pos);
2436 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2437 bss->ieee802_1x = atoi(pos);
2438 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002439 int eapol_version = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002440#ifdef CONFIG_MACSEC
Hai Shaloma20dcd72022-02-04 13:43:00 -08002441 int max_ver = 3;
Hai Shalom81f62d82019-07-22 12:10:00 -07002442#else /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002443 int max_ver = 2;
Hai Shalom81f62d82019-07-22 12:10:00 -07002444#endif /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002445
2446 if (eapol_version < 1 || eapol_version > max_ver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002447 wpa_printf(MSG_ERROR,
2448 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002449 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002450 return 1;
2451 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002452 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002453 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002454#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002455 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2456 bss->eap_server = atoi(pos);
2457 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2458 } else if (os_strcmp(buf, "eap_server") == 0) {
2459 bss->eap_server = atoi(pos);
2460 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2461 if (hostapd_config_read_eap_user(pos, bss))
2462 return 1;
2463 } else if (os_strcmp(buf, "ca_cert") == 0) {
2464 os_free(bss->ca_cert);
2465 bss->ca_cert = os_strdup(pos);
2466 } else if (os_strcmp(buf, "server_cert") == 0) {
2467 os_free(bss->server_cert);
2468 bss->server_cert = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002469 } else if (os_strcmp(buf, "server_cert2") == 0) {
2470 os_free(bss->server_cert2);
2471 bss->server_cert2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002472 } else if (os_strcmp(buf, "private_key") == 0) {
2473 os_free(bss->private_key);
2474 bss->private_key = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002475 } else if (os_strcmp(buf, "private_key2") == 0) {
2476 os_free(bss->private_key2);
2477 bss->private_key2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002478 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2479 os_free(bss->private_key_passwd);
2480 bss->private_key_passwd = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002481 } else if (os_strcmp(buf, "private_key_passwd2") == 0) {
2482 os_free(bss->private_key_passwd2);
2483 bss->private_key_passwd2 = os_strdup(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07002484 } else if (os_strcmp(buf, "check_cert_subject") == 0) {
2485 if (!pos[0]) {
2486 wpa_printf(MSG_ERROR, "Line %d: unknown check_cert_subject '%s'",
2487 line, pos);
2488 return 1;
2489 }
2490 os_free(bss->check_cert_subject);
2491 bss->check_cert_subject = os_strdup(pos);
2492 if (!bss->check_cert_subject)
2493 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002494 } else if (os_strcmp(buf, "check_crl") == 0) {
2495 bss->check_crl = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002496 } else if (os_strcmp(buf, "check_crl_strict") == 0) {
2497 bss->check_crl_strict = atoi(pos);
2498 } else if (os_strcmp(buf, "crl_reload_interval") == 0) {
2499 bss->crl_reload_interval = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002500 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2501 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002502 } else if (os_strcmp(buf, "tls_flags") == 0) {
2503 bss->tls_flags = parse_tls_flags(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002504 } else if (os_strcmp(buf, "max_auth_rounds") == 0) {
2505 bss->max_auth_rounds = atoi(pos);
2506 } else if (os_strcmp(buf, "max_auth_rounds_short") == 0) {
2507 bss->max_auth_rounds_short = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002508 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2509 os_free(bss->ocsp_stapling_response);
2510 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002511 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2512 os_free(bss->ocsp_stapling_response_multi);
2513 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002514 } else if (os_strcmp(buf, "dh_file") == 0) {
2515 os_free(bss->dh_file);
2516 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002517 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2518 os_free(bss->openssl_ciphers);
2519 bss->openssl_ciphers = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002520 } else if (os_strcmp(buf, "openssl_ecdh_curves") == 0) {
2521 os_free(bss->openssl_ecdh_curves);
2522 bss->openssl_ecdh_curves = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002523 } else if (os_strcmp(buf, "fragment_size") == 0) {
2524 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002525#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002526 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2527 os_free(bss->pac_opaque_encr_key);
2528 bss->pac_opaque_encr_key = os_malloc(16);
2529 if (bss->pac_opaque_encr_key == NULL) {
2530 wpa_printf(MSG_ERROR,
2531 "Line %d: No memory for pac_opaque_encr_key",
2532 line);
2533 return 1;
2534 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2535 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2536 line);
2537 return 1;
2538 }
2539 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2540 size_t idlen = os_strlen(pos);
2541 if (idlen & 1) {
2542 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2543 line);
2544 return 1;
2545 }
2546 os_free(bss->eap_fast_a_id);
2547 bss->eap_fast_a_id = os_malloc(idlen / 2);
2548 if (bss->eap_fast_a_id == NULL ||
2549 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2550 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2551 line);
2552 os_free(bss->eap_fast_a_id);
2553 bss->eap_fast_a_id = NULL;
2554 return 1;
2555 } else {
2556 bss->eap_fast_a_id_len = idlen / 2;
2557 }
2558 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2559 os_free(bss->eap_fast_a_id_info);
2560 bss->eap_fast_a_id_info = os_strdup(pos);
2561 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2562 bss->eap_fast_prov = atoi(pos);
2563 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2564 bss->pac_key_lifetime = atoi(pos);
2565 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2566 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002567#endif /* EAP_SERVER_FAST */
Hai Shalom81f62d82019-07-22 12:10:00 -07002568#ifdef EAP_SERVER_TEAP
2569 } else if (os_strcmp(buf, "eap_teap_auth") == 0) {
2570 int val = atoi(pos);
2571
Hai Shalom899fcc72020-10-19 14:38:18 -07002572 if (val < 0 || val > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002573 wpa_printf(MSG_ERROR,
2574 "Line %d: Invalid eap_teap_auth value",
2575 line);
2576 return 1;
2577 }
2578 bss->eap_teap_auth = val;
2579 } else if (os_strcmp(buf, "eap_teap_pac_no_inner") == 0) {
2580 bss->eap_teap_pac_no_inner = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002581 } else if (os_strcmp(buf, "eap_teap_separate_result") == 0) {
2582 bss->eap_teap_separate_result = atoi(pos);
2583 } else if (os_strcmp(buf, "eap_teap_id") == 0) {
2584 bss->eap_teap_id = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002585#endif /* EAP_SERVER_TEAP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002587 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2588 os_free(bss->eap_sim_db);
2589 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002590 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2591 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002592 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2593 bss->eap_sim_aka_result_ind = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002594 } else if (os_strcmp(buf, "eap_sim_id") == 0) {
2595 bss->eap_sim_id = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07002596 } else if (os_strcmp(buf, "imsi_privacy_key") == 0) {
2597 os_free(bss->imsi_privacy_key);
2598 bss->imsi_privacy_key = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002599#endif /* EAP_SERVER_SIM */
2600#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002601 } else if (os_strcmp(buf, "tnc") == 0) {
2602 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603#endif /* EAP_SERVER_TNC */
2604#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002605 } else if (os_strcmp(buf, "pwd_group") == 0) {
2606 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002608#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002609 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2610 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002611#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002613 } else if (os_strcmp(buf, "eap_message") == 0) {
2614 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002615 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002616 bss->eap_req_id_text = os_strdup(pos);
2617 if (bss->eap_req_id_text == NULL) {
2618 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2619 line);
2620 return 1;
2621 }
2622 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2623 term = os_strstr(bss->eap_req_id_text, "\\0");
2624 if (term) {
2625 *term++ = '\0';
2626 os_memmove(term, term + 1,
2627 bss->eap_req_id_text_len -
2628 (term - bss->eap_req_id_text) - 1);
2629 bss->eap_req_id_text_len--;
2630 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002631 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2632 bss->erp_send_reauth_start = atoi(pos);
2633 } else if (os_strcmp(buf, "erp_domain") == 0) {
2634 os_free(bss->erp_domain);
2635 bss->erp_domain = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002636#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002637 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002638 int val = atoi(pos);
2639
2640 if (val < 0 || val > 13) {
2641 wpa_printf(MSG_ERROR,
2642 "Line %d: invalid WEP key len %d (= %d bits)",
2643 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002644 return 1;
2645 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002646 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002647 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002648 int val = atoi(pos);
2649
2650 if (val < 0 || val > 13) {
2651 wpa_printf(MSG_ERROR,
2652 "Line %d: invalid WEP key len %d (= %d bits)",
2653 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002654 return 1;
2655 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002656 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002657 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2658 bss->wep_rekeying_period = atoi(pos);
2659 if (bss->wep_rekeying_period < 0) {
2660 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2661 line, bss->wep_rekeying_period);
2662 return 1;
2663 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002664#endif /* CONFIG_WEP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002665 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2666 bss->eap_reauth_period = atoi(pos);
2667 if (bss->eap_reauth_period < 0) {
2668 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2669 line, bss->eap_reauth_period);
2670 return 1;
2671 }
2672 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2673 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002675 } else if (os_strcmp(buf, "iapp_interface") == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07002676 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002677#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002678 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2679 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2680 wpa_printf(MSG_ERROR,
2681 "Line %d: invalid IP address '%s'",
2682 line, pos);
2683 return 1;
2684 }
2685 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002686 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002687 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002689 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2690 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2691 wpa_printf(MSG_ERROR,
2692 "Line %d: invalid IP address '%s'",
2693 line, pos);
2694 return 1;
2695 }
2696 bss->radius->force_client_addr = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002697 } else if (os_strcmp(buf, "radius_client_dev") == 0) {
2698 os_free(bss->radius->force_client_dev);
2699 bss->radius->force_client_dev = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002700 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2701 if (hostapd_config_read_radius_addr(
2702 &bss->radius->auth_servers,
2703 &bss->radius->num_auth_servers, pos, 1812,
2704 &bss->radius->auth_server)) {
2705 wpa_printf(MSG_ERROR,
2706 "Line %d: invalid IP address '%s'",
2707 line, pos);
2708 return 1;
2709 }
2710 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002711 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2712 if (hostapd_parse_ip_addr(pos,
2713 &bss->radius->auth_server->addr)) {
2714 wpa_printf(MSG_ERROR,
2715 "Line %d: invalid IP address '%s'",
2716 line, pos);
2717 return 1;
2718 }
2719 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002720 os_strcmp(buf, "auth_server_port") == 0) {
2721 bss->radius->auth_server->port = atoi(pos);
2722 } else if (bss->radius->auth_server &&
2723 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2724 int len = os_strlen(pos);
2725 if (len == 0) {
2726 /* RFC 2865, Ch. 3 */
2727 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2728 line);
2729 return 1;
2730 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002731 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002732 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2733 bss->radius->auth_server->shared_secret_len = len;
2734 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2735 if (hostapd_config_read_radius_addr(
2736 &bss->radius->acct_servers,
2737 &bss->radius->num_acct_servers, pos, 1813,
2738 &bss->radius->acct_server)) {
2739 wpa_printf(MSG_ERROR,
2740 "Line %d: invalid IP address '%s'",
2741 line, pos);
2742 return 1;
2743 }
2744 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002745 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2746 if (hostapd_parse_ip_addr(pos,
2747 &bss->radius->acct_server->addr)) {
2748 wpa_printf(MSG_ERROR,
2749 "Line %d: invalid IP address '%s'",
2750 line, pos);
2751 return 1;
2752 }
2753 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002754 os_strcmp(buf, "acct_server_port") == 0) {
2755 bss->radius->acct_server->port = atoi(pos);
2756 } else if (bss->radius->acct_server &&
2757 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2758 int len = os_strlen(pos);
2759 if (len == 0) {
2760 /* RFC 2865, Ch. 3 */
2761 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2762 line);
2763 return 1;
2764 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002765 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002766 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2767 bss->radius->acct_server->shared_secret_len = len;
2768 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2769 bss->radius->retry_primary_interval = atoi(pos);
2770 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2771 bss->acct_interim_interval = atoi(pos);
2772 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2773 bss->radius_request_cui = atoi(pos);
2774 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2775 struct hostapd_radius_attr *attr, *a;
2776 attr = hostapd_parse_radius_attr(pos);
2777 if (attr == NULL) {
2778 wpa_printf(MSG_ERROR,
2779 "Line %d: invalid radius_auth_req_attr",
2780 line);
2781 return 1;
2782 } else if (bss->radius_auth_req_attr == NULL) {
2783 bss->radius_auth_req_attr = attr;
2784 } else {
2785 a = bss->radius_auth_req_attr;
2786 while (a->next)
2787 a = a->next;
2788 a->next = attr;
2789 }
2790 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2791 struct hostapd_radius_attr *attr, *a;
2792 attr = hostapd_parse_radius_attr(pos);
2793 if (attr == NULL) {
2794 wpa_printf(MSG_ERROR,
2795 "Line %d: invalid radius_acct_req_attr",
2796 line);
2797 return 1;
2798 } else if (bss->radius_acct_req_attr == NULL) {
2799 bss->radius_acct_req_attr = attr;
2800 } else {
2801 a = bss->radius_acct_req_attr;
2802 while (a->next)
2803 a = a->next;
2804 a->next = attr;
2805 }
Hai Shalomc3565922019-10-28 11:58:20 -07002806 } else if (os_strcmp(buf, "radius_req_attr_sqlite") == 0) {
2807 os_free(bss->radius_req_attr_sqlite);
2808 bss->radius_req_attr_sqlite = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002809 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2810 bss->radius_das_port = atoi(pos);
2811 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2812 if (hostapd_parse_das_client(bss, pos) < 0) {
2813 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2814 line);
2815 return 1;
2816 }
2817 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2818 bss->radius_das_time_window = atoi(pos);
2819 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2820 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002821 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2822 0) {
2823 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002825 } else if (os_strcmp(buf, "auth_algs") == 0) {
2826 bss->auth_algs = atoi(pos);
2827 if (bss->auth_algs == 0) {
2828 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2829 line);
2830 return 1;
2831 }
2832 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2833 bss->max_num_sta = atoi(pos);
2834 if (bss->max_num_sta < 0 ||
2835 bss->max_num_sta > MAX_STA_COUNT) {
2836 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2837 line, bss->max_num_sta, MAX_STA_COUNT);
2838 return 1;
2839 }
2840 } else if (os_strcmp(buf, "wpa") == 0) {
2841 bss->wpa = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002842 } else if (os_strcmp(buf, "extended_key_id") == 0) {
2843 int val = atoi(pos);
2844
2845 if (val < 0 || val > 2) {
2846 wpa_printf(MSG_ERROR,
2847 "Line %d: Invalid extended_key_id=%d; allowed range 0..2",
2848 line, val);
2849 return 1;
2850 }
2851 bss->extended_key_id = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002852 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2853 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002854 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002855 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2856 bss->wpa_strict_rekey = atoi(pos);
2857 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2858 bss->wpa_gmk_rekey = atoi(pos);
2859 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2860 bss->wpa_ptk_rekey = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002861 } else if (os_strcmp(buf, "wpa_deny_ptk0_rekey") == 0) {
2862 bss->wpa_deny_ptk0_rekey = atoi(pos);
2863 if (bss->wpa_deny_ptk0_rekey < 0 ||
2864 bss->wpa_deny_ptk0_rekey > 2) {
2865 wpa_printf(MSG_ERROR,
2866 "Line %d: Invalid wpa_deny_ptk0_rekey=%d; allowed range 0..2",
2867 line, bss->wpa_deny_ptk0_rekey);
2868 return 1;
2869 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002870 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2871 char *endp;
2872 unsigned long val = strtoul(pos, &endp, 0);
2873
2874 if (*endp || val < 1 || val > (u32) -1) {
2875 wpa_printf(MSG_ERROR,
2876 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2877 line, val);
2878 return 1;
2879 }
2880 bss->wpa_group_update_count = (u32) val;
2881 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2882 char *endp;
2883 unsigned long val = strtoul(pos, &endp, 0);
2884
2885 if (*endp || val < 1 || val > (u32) -1) {
2886 wpa_printf(MSG_ERROR,
2887 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2888 line, val);
2889 return 1;
2890 }
2891 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002892 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2893 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002894 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2895 int len = os_strlen(pos);
2896 if (len < 8 || len > 63) {
2897 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2898 line, len);
2899 return 1;
2900 }
2901 os_free(bss->ssid.wpa_passphrase);
2902 bss->ssid.wpa_passphrase = os_strdup(pos);
2903 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002904 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002905 bss->ssid.wpa_passphrase_set = 1;
2906 }
2907 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002908 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002909 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2910 if (bss->ssid.wpa_psk == NULL)
2911 return 1;
2912 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2913 pos[PMK_LEN * 2] != '\0') {
2914 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2915 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002916 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002917 return 1;
2918 }
2919 bss->ssid.wpa_psk->group = 1;
2920 os_free(bss->ssid.wpa_passphrase);
2921 bss->ssid.wpa_passphrase = NULL;
2922 bss->ssid.wpa_psk_set = 1;
2923 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2924 os_free(bss->ssid.wpa_psk_file);
2925 bss->ssid.wpa_psk_file = os_strdup(pos);
2926 if (!bss->ssid.wpa_psk_file) {
2927 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2928 line);
2929 return 1;
2930 }
2931 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2932 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2933 if (bss->wpa_key_mgmt == -1)
2934 return 1;
2935 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2936 bss->wpa_psk_radius = atoi(pos);
2937 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2938 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07002939 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED &&
2940 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002941 wpa_printf(MSG_ERROR,
2942 "Line %d: unknown wpa_psk_radius %d",
2943 line, bss->wpa_psk_radius);
2944 return 1;
2945 }
2946 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2947 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2948 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2949 return 1;
2950 if (bss->wpa_pairwise &
2951 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2952 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002953 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002954 return 1;
2955 }
2956 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2957 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2958 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2959 return 1;
2960 if (bss->rsn_pairwise &
2961 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2962 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002963 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002964 return 1;
2965 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002966 } else if (os_strcmp(buf, "group_cipher") == 0) {
2967 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2968 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2969 return 1;
2970 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2971 bss->group_cipher != WPA_CIPHER_CCMP &&
2972 bss->group_cipher != WPA_CIPHER_GCMP &&
2973 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2974 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2975 wpa_printf(MSG_ERROR,
2976 "Line %d: unsupported group cipher suite '%s'",
2977 line, pos);
2978 return 1;
2979 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002981 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2982 bss->rsn_preauth = atoi(pos);
2983 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002984 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002985 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002986#endif /* CONFIG_RSN_PREAUTH */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002987 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002988 wpa_printf(MSG_INFO,
2989 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002990#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002991 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2992 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2993 hexstr2bin(pos, bss->mobility_domain,
2994 MOBILITY_DOMAIN_ID_LEN) != 0) {
2995 wpa_printf(MSG_ERROR,
2996 "Line %d: Invalid mobility_domain '%s'",
2997 line, pos);
2998 return 1;
2999 }
3000 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
3001 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
3002 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
3003 wpa_printf(MSG_ERROR,
3004 "Line %d: Invalid r1_key_holder '%s'",
3005 line, pos);
3006 return 1;
3007 }
3008 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003009 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
3010 bss->r0_key_lifetime = atoi(pos) * 60;
3011 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003012 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003013 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
3014 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003015 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
3016 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003017 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
3018 bss->rkh_pos_timeout = atoi(pos);
3019 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
3020 bss->rkh_neg_timeout = atoi(pos);
3021 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
3022 bss->rkh_pull_timeout = atoi(pos);
3023 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
3024 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003025 } else if (os_strcmp(buf, "r0kh") == 0) {
3026 if (add_r0kh(bss, pos) < 0) {
3027 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
3028 line, pos);
3029 return 1;
3030 }
3031 } else if (os_strcmp(buf, "r1kh") == 0) {
3032 if (add_r1kh(bss, pos) < 0) {
3033 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
3034 line, pos);
3035 return 1;
3036 }
3037 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
3038 bss->pmk_r1_push = atoi(pos);
3039 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
3040 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003041 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
3042 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003043#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003045 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
3046 os_free(bss->ctrl_interface);
3047 bss->ctrl_interface = os_strdup(pos);
3048 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003049#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003050 struct group *grp;
3051 char *endp;
3052 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003054 grp = getgrnam(group);
3055 if (grp) {
3056 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003057 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003058 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
3059 bss->ctrl_interface_gid, group);
3060 return 0;
3061 }
3062
3063 /* Group name not found - try to parse this as gid */
3064 bss->ctrl_interface_gid = strtol(group, &endp, 10);
3065 if (*group == '\0' || *endp != '\0') {
3066 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
3067 line, group);
3068 return 1;
3069 }
3070 bss->ctrl_interface_gid_set = 1;
3071 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
3072 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073#endif /* CONFIG_NATIVE_WINDOWS */
3074#endif /* CONFIG_NO_CTRL_IFACE */
3075#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003076 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
3077 os_free(bss->radius_server_clients);
3078 bss->radius_server_clients = os_strdup(pos);
3079 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
3080 bss->radius_server_auth_port = atoi(pos);
3081 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
3082 bss->radius_server_acct_port = atoi(pos);
3083 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
3084 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003086 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
3087 bss->use_pae_group_addr = atoi(pos);
3088 } else if (os_strcmp(buf, "hw_mode") == 0) {
3089 if (os_strcmp(pos, "a") == 0)
3090 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
3091 else if (os_strcmp(pos, "b") == 0)
3092 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
3093 else if (os_strcmp(pos, "g") == 0)
3094 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
3095 else if (os_strcmp(pos, "ad") == 0)
3096 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003097 else if (os_strcmp(pos, "any") == 0)
3098 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003099 else {
3100 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3101 line, pos);
3102 return 1;
3103 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003104 conf->hw_mode_set = true;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003105 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003106 if (os_strcmp(pos, "ad") == 0)
3107 bss->wps_rf_bands = WPS_RF_60GHZ;
3108 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003109 bss->wps_rf_bands = WPS_RF_50GHZ;
3110 else if (os_strcmp(pos, "g") == 0 ||
3111 os_strcmp(pos, "b") == 0)
3112 bss->wps_rf_bands = WPS_RF_24GHZ;
3113 else if (os_strcmp(pos, "ag") == 0 ||
3114 os_strcmp(pos, "ga") == 0)
3115 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3116 else {
3117 wpa_printf(MSG_ERROR,
3118 "Line %d: unknown wps_rf_band '%s'",
3119 line, pos);
3120 return 1;
3121 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003122 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3123 conf->acs_exclude_dfs = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07003124 } else if (os_strcmp(buf, "op_class") == 0) {
3125 conf->op_class = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003126 } else if (os_strcmp(buf, "channel") == 0) {
3127 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003128#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003129 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3130 line);
3131 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003132#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003133 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003134 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003135#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003136 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003137 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003138 conf->acs = conf->channel == 0;
3139 }
Hai Shalomc3565922019-10-28 11:58:20 -07003140 } else if (os_strcmp(buf, "edmg_channel") == 0) {
3141 conf->edmg_channel = atoi(pos);
3142 } else if (os_strcmp(buf, "enable_edmg") == 0) {
3143 conf->enable_edmg = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003144 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003145 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003146 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3147 line);
3148 return 1;
3149 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003150 } else if (os_strcmp(buf, "freqlist") == 0) {
3151 if (freq_range_list_parse(&conf->acs_freq_list, pos)) {
3152 wpa_printf(MSG_ERROR, "Line %d: invalid frequency list",
3153 line);
3154 return 1;
3155 }
3156 conf->acs_freq_list_present = 1;
3157 } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) {
3158 conf->acs_exclude_6ghz_non_psc = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07003159 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
3160 conf->enable_background_radar = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003161 } else if (os_strcmp(buf, "min_tx_power") == 0) {
3162 int val = atoi(pos);
3163
3164 if (val < 0 || val > 255) {
3165 wpa_printf(MSG_ERROR,
3166 "Line %d: invalid min_tx_power %d (expected 0..255)",
3167 line, val);
3168 return 1;
3169 }
3170 conf->min_tx_power = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003171 } else if (os_strcmp(buf, "beacon_int") == 0) {
3172 int val = atoi(pos);
3173 /* MIB defines range as 1..65535, but very small values
3174 * cause problems with the current implementation.
3175 * Since it is unlikely that this small numbers are
3176 * useful in real life scenarios, do not allow beacon
Hai Shalom021b0b52019-04-10 11:17:58 -07003177 * period to be set below 10 TU. */
3178 if (val < 10 || val > 65535) {
3179 wpa_printf(MSG_ERROR,
3180 "Line %d: invalid beacon_int %d (expected 10..65535)",
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003181 line, val);
3182 return 1;
3183 }
3184 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003185#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003186 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3187 int val = atoi(pos);
3188 if (val <= 0 || val > 100) {
3189 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3190 line, val);
3191 return 1;
3192 }
3193 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003194 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3195 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3196 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3197 line);
3198 return -1;
3199 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003200#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003201 } else if (os_strcmp(buf, "dtim_period") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003202 int val = atoi(pos);
3203
3204 if (val < 1 || val > 255) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003205 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08003206 line, val);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003207 return 1;
3208 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08003209 bss->dtim_period = val;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003210 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003211 int val = atoi(pos);
3212
3213 if (val < 0 || val > 100) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003214 wpa_printf(MSG_ERROR,
3215 "Line %d: invalid bss_load_update_period %d",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003216 line, val);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003217 return 1;
3218 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003219 bss->bss_load_update_period = val;
3220 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3221 int val = atoi(pos);
3222
3223 if (val < 0) {
3224 wpa_printf(MSG_ERROR,
3225 "Line %d: invalid chan_util_avg_period",
3226 line);
3227 return 1;
3228 }
3229 bss->chan_util_avg_period = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003230 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3231 conf->rts_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003232 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003233 wpa_printf(MSG_ERROR,
3234 "Line %d: invalid rts_threshold %d",
3235 line, conf->rts_threshold);
3236 return 1;
3237 }
3238 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3239 conf->fragm_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003240 if (conf->fragm_threshold == -1) {
3241 /* allow a value of -1 */
3242 } else if (conf->fragm_threshold < 256 ||
3243 conf->fragm_threshold > 2346) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003244 wpa_printf(MSG_ERROR,
3245 "Line %d: invalid fragm_threshold %d",
3246 line, conf->fragm_threshold);
3247 return 1;
3248 }
3249 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3250 int val = atoi(pos);
3251 if (val != 0 && val != 1) {
3252 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3253 line, val);
3254 return 1;
3255 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003256 bss->send_probe_response = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003257 } else if (os_strcmp(buf, "supported_rates") == 0) {
3258 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3259 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3260 line);
3261 return 1;
3262 }
3263 } else if (os_strcmp(buf, "basic_rates") == 0) {
3264 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3265 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3266 line);
3267 return 1;
3268 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003269 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3270 int val;
3271
3272 if (os_strncmp(pos, "ht:", 3) == 0) {
3273 val = atoi(pos + 3);
3274 if (val < 0 || val > 31) {
3275 wpa_printf(MSG_ERROR,
3276 "Line %d: invalid beacon_rate HT-MCS %d",
3277 line, val);
3278 return 1;
3279 }
3280 conf->rate_type = BEACON_RATE_HT;
3281 conf->beacon_rate = val;
3282 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3283 val = atoi(pos + 4);
3284 if (val < 0 || val > 9) {
3285 wpa_printf(MSG_ERROR,
3286 "Line %d: invalid beacon_rate VHT-MCS %d",
3287 line, val);
3288 return 1;
3289 }
3290 conf->rate_type = BEACON_RATE_VHT;
3291 conf->beacon_rate = val;
Hai Shalom60840252021-02-19 19:02:11 -08003292 } else if (os_strncmp(pos, "he:", 3) == 0) {
3293 val = atoi(pos + 3);
3294 if (val < 0 || val > 11) {
3295 wpa_printf(MSG_ERROR,
3296 "Line %d: invalid beacon_rate HE-MCS %d",
3297 line, val);
3298 return 1;
3299 }
3300 conf->rate_type = BEACON_RATE_HE;
3301 conf->beacon_rate = val;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003302 } else {
3303 val = atoi(pos);
3304 if (val < 10 || val > 10000) {
3305 wpa_printf(MSG_ERROR,
3306 "Line %d: invalid legacy beacon_rate %d",
3307 line, val);
3308 return 1;
3309 }
3310 conf->rate_type = BEACON_RATE_LEGACY;
3311 conf->beacon_rate = val;
3312 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003313 } else if (os_strcmp(buf, "preamble") == 0) {
3314 if (atoi(pos))
3315 conf->preamble = SHORT_PREAMBLE;
3316 else
3317 conf->preamble = LONG_PREAMBLE;
3318 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3319 bss->ignore_broadcast_ssid = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003320 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3321 bss->no_probe_resp_if_max_sta = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003322#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003323 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3324 bss->ssid.wep.idx = atoi(pos);
3325 if (bss->ssid.wep.idx > 3) {
3326 wpa_printf(MSG_ERROR,
3327 "Invalid wep_default_key index %d",
3328 bss->ssid.wep.idx);
3329 return 1;
3330 }
3331 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3332 os_strcmp(buf, "wep_key1") == 0 ||
3333 os_strcmp(buf, "wep_key2") == 0 ||
3334 os_strcmp(buf, "wep_key3") == 0) {
3335 if (hostapd_config_read_wep(&bss->ssid.wep,
3336 buf[7] - '0', pos)) {
3337 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3338 line, buf);
3339 return 1;
3340 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003341#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003343 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3344 bss->ssid.dynamic_vlan = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003345 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3346 bss->ssid.per_sta_vif = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003347 } else if (os_strcmp(buf, "vlan_file") == 0) {
3348 if (hostapd_config_read_vlan_file(bss, pos)) {
3349 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3350 line, pos);
3351 return 1;
3352 }
3353 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3354 bss->ssid.vlan_naming = atoi(pos);
3355 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3356 bss->ssid.vlan_naming < 0) {
3357 wpa_printf(MSG_ERROR,
3358 "Line %d: invalid naming scheme %d",
3359 line, bss->ssid.vlan_naming);
3360 return 1;
3361 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003363 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003364 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003365 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003366#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3367#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003368 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3369 conf->ap_table_max_size = atoi(pos);
3370 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3371 conf->ap_table_expiration_time = atoi(pos);
3372 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003373 if (hostapd_config_tx_queue(conf->tx_queue, buf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003374 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3375 line);
3376 return 1;
3377 }
3378 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3379 os_strcmp(buf, "wmm_enabled") == 0) {
3380 bss->wmm_enabled = atoi(pos);
3381 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3382 bss->wmm_uapsd = atoi(pos);
3383 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3384 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3385 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3386 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3387 line);
3388 return 1;
3389 }
3390 } else if (os_strcmp(buf, "bss") == 0) {
3391 if (hostapd_config_bss(conf, pos)) {
3392 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3393 line);
3394 return 1;
3395 }
3396 } else if (os_strcmp(buf, "bssid") == 0) {
3397 if (hwaddr_aton(pos, bss->bssid)) {
3398 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3399 line);
3400 return 1;
3401 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003402 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3403 conf->use_driver_iface_addr = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003404 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3405 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003406 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3407 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3408 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3409 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3410 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3411 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3412 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3413 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3414 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3415 } else {
3416 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3417 line, pos);
3418 return 1;
3419 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003420 } else if (os_strcmp(buf, "beacon_prot") == 0) {
3421 bss->beacon_prot = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003422 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3423 bss->assoc_sa_query_max_timeout = atoi(pos);
3424 if (bss->assoc_sa_query_max_timeout == 0) {
3425 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3426 line);
3427 return 1;
3428 }
3429 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3430 bss->assoc_sa_query_retry_timeout = atoi(pos);
3431 if (bss->assoc_sa_query_retry_timeout == 0) {
3432 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3433 line);
3434 return 1;
3435 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003436#ifdef CONFIG_OCV
3437 } else if (os_strcmp(buf, "ocv") == 0) {
3438 bss->ocv = atoi(pos);
3439 if (bss->ocv && !bss->ieee80211w)
3440 bss->ieee80211w = 1;
3441#endif /* CONFIG_OCV */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003442 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3443 conf->ieee80211n = atoi(pos);
3444 } else if (os_strcmp(buf, "ht_capab") == 0) {
3445 if (hostapd_config_ht_capab(conf, pos) < 0) {
3446 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3447 line);
3448 return 1;
3449 }
3450 } else if (os_strcmp(buf, "require_ht") == 0) {
3451 conf->require_ht = atoi(pos);
3452 } else if (os_strcmp(buf, "obss_interval") == 0) {
3453 conf->obss_interval = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003454#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003455 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3456 conf->ieee80211ac = atoi(pos);
3457 } else if (os_strcmp(buf, "vht_capab") == 0) {
3458 if (hostapd_config_vht_capab(conf, pos) < 0) {
3459 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3460 line);
3461 return 1;
3462 }
3463 } else if (os_strcmp(buf, "require_vht") == 0) {
3464 conf->require_vht = atoi(pos);
3465 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3466 conf->vht_oper_chwidth = atoi(pos);
3467 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3468 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3469 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3470 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003471 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3472 bss->vendor_vht = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003473 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3474 bss->use_sta_nsts = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003475#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003476#ifdef CONFIG_IEEE80211AX
3477 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3478 conf->ieee80211ax = atoi(pos);
3479 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3480 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3481 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3482 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3483 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3484 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3485 } else if (os_strcmp(buf, "he_bss_color") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003486 conf->he_op.he_bss_color = atoi(pos) & 0x3f;
3487 conf->he_op.he_bss_color_disabled = 0;
3488 } else if (os_strcmp(buf, "he_bss_color_partial") == 0) {
3489 conf->he_op.he_bss_color_partial = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003490 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3491 conf->he_op.he_default_pe_duration = atoi(pos);
3492 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3493 conf->he_op.he_twt_required = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003494 } else if (os_strcmp(buf, "he_twt_responder") == 0) {
3495 conf->he_op.he_twt_responder = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003496 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3497 conf->he_op.he_rts_threshold = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003498 } else if (os_strcmp(buf, "he_er_su_disable") == 0) {
3499 conf->he_op.he_er_su_disable = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003500 } else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
3501 conf->he_op.he_basic_mcs_nss_set = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003502 } else if (os_strcmp(buf, "he_mu_edca_qos_info_param_count") == 0) {
3503 conf->he_mu_edca.he_qos_info |=
3504 set_he_cap(atoi(pos), HE_QOS_INFO_EDCA_PARAM_SET_COUNT);
3505 } else if (os_strcmp(buf, "he_mu_edca_qos_info_q_ack") == 0) {
3506 conf->he_mu_edca.he_qos_info |=
3507 set_he_cap(atoi(pos), HE_QOS_INFO_Q_ACK);
3508 } else if (os_strcmp(buf, "he_mu_edca_qos_info_queue_request") == 0) {
3509 conf->he_mu_edca.he_qos_info |=
3510 set_he_cap(atoi(pos), HE_QOS_INFO_QUEUE_REQUEST);
3511 } else if (os_strcmp(buf, "he_mu_edca_qos_info_txop_request") == 0) {
3512 conf->he_mu_edca.he_qos_info |=
3513 set_he_cap(atoi(pos), HE_QOS_INFO_TXOP_REQUEST);
3514 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aifsn") == 0) {
3515 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3516 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3517 } else if (os_strcmp(buf, "he_mu_edca_ac_be_acm") == 0) {
3518 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3519 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3520 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aci") == 0) {
3521 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3522 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3523 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmin") == 0) {
3524 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3525 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3526 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmax") == 0) {
3527 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3528 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3529 } else if (os_strcmp(buf, "he_mu_edca_ac_be_timer") == 0) {
3530 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_TIMER_IDX] =
3531 atoi(pos) & 0xff;
3532 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aifsn") == 0) {
3533 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3534 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3535 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_acm") == 0) {
3536 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3537 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3538 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aci") == 0) {
3539 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3540 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3541 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmin") == 0) {
3542 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3543 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3544 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmax") == 0) {
3545 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3546 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3547 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_timer") == 0) {
3548 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_TIMER_IDX] =
3549 atoi(pos) & 0xff;
3550 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aifsn") == 0) {
3551 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3552 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3553 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_acm") == 0) {
3554 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3555 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3556 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aci") == 0) {
3557 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3558 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3559 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmin") == 0) {
3560 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3561 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3562 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmax") == 0) {
3563 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3564 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3565 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_timer") == 0) {
3566 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_TIMER_IDX] =
3567 atoi(pos) & 0xff;
3568 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aifsn") == 0) {
3569 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3570 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3571 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_acm") == 0) {
3572 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3573 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3574 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aci") == 0) {
3575 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3576 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3577 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmin") == 0) {
3578 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3579 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3580 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmax") == 0) {
3581 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3582 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3583 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_timer") == 0) {
3584 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_TIMER_IDX] =
3585 atoi(pos) & 0xff;
Hai Shalom81f62d82019-07-22 12:10:00 -07003586 } else if (os_strcmp(buf, "he_spr_sr_control") == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003587 conf->spr.sr_control = atoi(pos) & 0x1f;
Hai Shalom81f62d82019-07-22 12:10:00 -07003588 } else if (os_strcmp(buf, "he_spr_non_srg_obss_pd_max_offset") == 0) {
3589 conf->spr.non_srg_obss_pd_max_offset = atoi(pos);
3590 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_min_offset") == 0) {
3591 conf->spr.srg_obss_pd_min_offset = atoi(pos);
3592 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_max_offset") == 0) {
3593 conf->spr.srg_obss_pd_max_offset = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003594 } else if (os_strcmp(buf, "he_spr_srg_bss_colors") == 0) {
3595 if (hostapd_parse_he_srg_bitmap(
3596 conf->spr.srg_bss_color_bitmap, pos)) {
3597 wpa_printf(MSG_ERROR,
3598 "Line %d: Invalid srg bss colors list '%s'",
3599 line, pos);
3600 return 1;
3601 }
3602 } else if (os_strcmp(buf, "he_spr_srg_partial_bssid") == 0) {
3603 if (hostapd_parse_he_srg_bitmap(
3604 conf->spr.srg_partial_bssid_bitmap, pos)) {
3605 wpa_printf(MSG_ERROR,
3606 "Line %d: Invalid srg partial bssid list '%s'",
3607 line, pos);
3608 return 1;
3609 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003610 } else if (os_strcmp(buf, "he_6ghz_reg_pwr_type") == 0) {
3611 conf->he_6ghz_reg_pwr_type = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003612 } else if (os_strcmp(buf, "he_oper_chwidth") == 0) {
3613 conf->he_oper_chwidth = atoi(pos);
3614 } else if (os_strcmp(buf, "he_oper_centr_freq_seg0_idx") == 0) {
3615 conf->he_oper_centr_freq_seg0_idx = atoi(pos);
3616 } else if (os_strcmp(buf, "he_oper_centr_freq_seg1_idx") == 0) {
3617 conf->he_oper_centr_freq_seg1_idx = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003618 } else if (os_strcmp(buf, "he_6ghz_max_mpdu") == 0) {
3619 conf->he_6ghz_max_mpdu = atoi(pos);
3620 } else if (os_strcmp(buf, "he_6ghz_max_ampdu_len_exp") == 0) {
3621 conf->he_6ghz_max_ampdu_len_exp = atoi(pos);
3622 } else if (os_strcmp(buf, "he_6ghz_rx_ant_pat") == 0) {
3623 conf->he_6ghz_rx_ant_pat = atoi(pos);
3624 } else if (os_strcmp(buf, "he_6ghz_tx_ant_pat") == 0) {
3625 conf->he_6ghz_tx_ant_pat = atoi(pos);
3626 } else if (os_strcmp(buf, "unsol_bcast_probe_resp_interval") == 0) {
3627 int val = atoi(pos);
3628
3629 if (val < 0 || val > 20) {
3630 wpa_printf(MSG_ERROR,
3631 "Line %d: invalid unsol_bcast_probe_resp_interval value",
3632 line);
3633 return 1;
3634 }
3635 bss->unsol_bcast_probe_resp_interval = val;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003636#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003637 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3638 bss->max_listen_interval = atoi(pos);
3639 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3640 bss->disable_pmksa_caching = atoi(pos);
3641 } else if (os_strcmp(buf, "okc") == 0) {
3642 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003643#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003644 } else if (os_strcmp(buf, "wps_state") == 0) {
3645 bss->wps_state = atoi(pos);
3646 if (bss->wps_state < 0 || bss->wps_state > 2) {
3647 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3648 line);
3649 return 1;
3650 }
3651 } else if (os_strcmp(buf, "wps_independent") == 0) {
3652 bss->wps_independent = atoi(pos);
3653 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3654 bss->ap_setup_locked = atoi(pos);
3655 } else if (os_strcmp(buf, "uuid") == 0) {
3656 if (uuid_str2bin(pos, bss->uuid)) {
3657 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3658 return 1;
3659 }
3660 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3661 os_free(bss->wps_pin_requests);
3662 bss->wps_pin_requests = os_strdup(pos);
3663 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003664 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003665 wpa_printf(MSG_ERROR, "Line %d: Too long "
3666 "device_name", line);
3667 return 1;
3668 }
3669 os_free(bss->device_name);
3670 bss->device_name = os_strdup(pos);
3671 } else if (os_strcmp(buf, "manufacturer") == 0) {
3672 if (os_strlen(pos) > 64) {
3673 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3674 line);
3675 return 1;
3676 }
3677 os_free(bss->manufacturer);
3678 bss->manufacturer = os_strdup(pos);
3679 } else if (os_strcmp(buf, "model_name") == 0) {
3680 if (os_strlen(pos) > 32) {
3681 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3682 line);
3683 return 1;
3684 }
3685 os_free(bss->model_name);
3686 bss->model_name = os_strdup(pos);
3687 } else if (os_strcmp(buf, "model_number") == 0) {
3688 if (os_strlen(pos) > 32) {
3689 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3690 line);
3691 return 1;
3692 }
3693 os_free(bss->model_number);
3694 bss->model_number = os_strdup(pos);
3695 } else if (os_strcmp(buf, "serial_number") == 0) {
3696 if (os_strlen(pos) > 32) {
3697 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3698 line);
3699 return 1;
3700 }
3701 os_free(bss->serial_number);
3702 bss->serial_number = os_strdup(pos);
3703 } else if (os_strcmp(buf, "device_type") == 0) {
3704 if (wps_dev_type_str2bin(pos, bss->device_type))
3705 return 1;
3706 } else if (os_strcmp(buf, "config_methods") == 0) {
3707 os_free(bss->config_methods);
3708 bss->config_methods = os_strdup(pos);
3709 } else if (os_strcmp(buf, "os_version") == 0) {
3710 if (hexstr2bin(pos, bss->os_version, 4)) {
3711 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3712 line);
3713 return 1;
3714 }
3715 } else if (os_strcmp(buf, "ap_pin") == 0) {
3716 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003717 if (*pos == '\0')
3718 bss->ap_pin = NULL;
3719 else
3720 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003721 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3722 bss->skip_cred_build = atoi(pos);
3723 } else if (os_strcmp(buf, "extra_cred") == 0) {
3724 os_free(bss->extra_cred);
3725 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3726 if (bss->extra_cred == NULL) {
3727 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3728 line, pos);
3729 return 1;
3730 }
3731 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3732 bss->wps_cred_processing = atoi(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07003733 } else if (os_strcmp(buf, "wps_cred_add_sae") == 0) {
3734 bss->wps_cred_add_sae = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003735 } else if (os_strcmp(buf, "ap_settings") == 0) {
3736 os_free(bss->ap_settings);
3737 bss->ap_settings =
3738 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3739 if (bss->ap_settings == NULL) {
3740 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3741 line, pos);
3742 return 1;
3743 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003744 } else if (os_strcmp(buf, "multi_ap_backhaul_ssid") == 0) {
3745 size_t slen;
3746 char *str = wpa_config_parse_string(pos, &slen);
3747
3748 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
3749 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
3750 line, pos);
3751 os_free(str);
3752 return 1;
3753 }
3754 os_memcpy(bss->multi_ap_backhaul_ssid.ssid, str, slen);
3755 bss->multi_ap_backhaul_ssid.ssid_len = slen;
3756 bss->multi_ap_backhaul_ssid.ssid_set = 1;
3757 os_free(str);
3758 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_passphrase") == 0) {
3759 int len = os_strlen(pos);
3760
3761 if (len < 8 || len > 63) {
3762 wpa_printf(MSG_ERROR,
3763 "Line %d: invalid WPA passphrase length %d (expected 8..63)",
3764 line, len);
3765 return 1;
3766 }
3767 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3768 bss->multi_ap_backhaul_ssid.wpa_passphrase = os_strdup(pos);
3769 if (bss->multi_ap_backhaul_ssid.wpa_passphrase) {
3770 hostapd_config_clear_wpa_psk(
3771 &bss->multi_ap_backhaul_ssid.wpa_psk);
3772 bss->multi_ap_backhaul_ssid.wpa_passphrase_set = 1;
3773 }
3774 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_psk") == 0) {
3775 hostapd_config_clear_wpa_psk(
3776 &bss->multi_ap_backhaul_ssid.wpa_psk);
3777 bss->multi_ap_backhaul_ssid.wpa_psk =
3778 os_zalloc(sizeof(struct hostapd_wpa_psk));
3779 if (!bss->multi_ap_backhaul_ssid.wpa_psk)
3780 return 1;
3781 if (hexstr2bin(pos, bss->multi_ap_backhaul_ssid.wpa_psk->psk,
3782 PMK_LEN) ||
3783 pos[PMK_LEN * 2] != '\0') {
3784 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
3785 line, pos);
3786 hostapd_config_clear_wpa_psk(
3787 &bss->multi_ap_backhaul_ssid.wpa_psk);
3788 return 1;
3789 }
3790 bss->multi_ap_backhaul_ssid.wpa_psk->group = 1;
3791 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3792 bss->multi_ap_backhaul_ssid.wpa_passphrase = NULL;
3793 bss->multi_ap_backhaul_ssid.wpa_psk_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003794 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003795 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003796 bss->upnp_iface = os_strdup(pos);
3797 } else if (os_strcmp(buf, "friendly_name") == 0) {
3798 os_free(bss->friendly_name);
3799 bss->friendly_name = os_strdup(pos);
3800 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3801 os_free(bss->manufacturer_url);
3802 bss->manufacturer_url = os_strdup(pos);
3803 } else if (os_strcmp(buf, "model_description") == 0) {
3804 os_free(bss->model_description);
3805 bss->model_description = os_strdup(pos);
3806 } else if (os_strcmp(buf, "model_url") == 0) {
3807 os_free(bss->model_url);
3808 bss->model_url = os_strdup(pos);
3809 } else if (os_strcmp(buf, "upc") == 0) {
3810 os_free(bss->upc);
3811 bss->upc = os_strdup(pos);
3812 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3813 bss->pbc_in_m1 = atoi(pos);
3814 } else if (os_strcmp(buf, "server_id") == 0) {
3815 os_free(bss->server_id);
3816 bss->server_id = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003817 } else if (os_strcmp(buf, "wps_application_ext") == 0) {
3818 wpabuf_free(bss->wps_application_ext);
3819 bss->wps_application_ext = wpabuf_parse_bin(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003820#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003821 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3822 bss->wps_nfc_dev_pw_id = atoi(pos);
3823 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3824 bss->wps_nfc_dev_pw_id > 0xffff) {
3825 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3826 line);
3827 return 1;
3828 }
3829 bss->wps_nfc_pw_from_config = 1;
3830 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3831 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003832 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003833 bss->wps_nfc_pw_from_config = 1;
3834 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3835 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003836 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003837 bss->wps_nfc_pw_from_config = 1;
3838 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3839 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003840 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003841 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003842#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003843#endif /* CONFIG_WPS */
3844#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003845 } else if (os_strcmp(buf, "manage_p2p") == 0) {
3846 if (atoi(pos))
3847 bss->p2p |= P2P_MANAGE;
3848 else
3849 bss->p2p &= ~P2P_MANAGE;
3850 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3851 if (atoi(pos))
3852 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3853 else
3854 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003855#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003856 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3857 bss->disassoc_low_ack = atoi(pos);
3858 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
3859 if (atoi(pos))
3860 bss->tdls |= TDLS_PROHIBIT;
3861 else
3862 bss->tdls &= ~TDLS_PROHIBIT;
3863 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
3864 if (atoi(pos))
3865 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3866 else
3867 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003868#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003869 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3870 extern int rsn_testing;
3871 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003872#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003873 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3874 bss->time_advertisement = atoi(pos);
3875 } else if (os_strcmp(buf, "time_zone") == 0) {
3876 size_t tz_len = os_strlen(pos);
3877 if (tz_len < 4 || tz_len > 255) {
3878 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3879 line);
3880 return 1;
3881 }
3882 os_free(bss->time_zone);
3883 bss->time_zone = os_strdup(pos);
3884 if (bss->time_zone == NULL)
3885 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003886#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003887 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3888 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003889 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3890 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003891 } else if (os_strcmp(buf, "bss_transition") == 0) {
3892 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003893#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003894#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003895 } else if (os_strcmp(buf, "interworking") == 0) {
3896 bss->interworking = atoi(pos);
3897 } else if (os_strcmp(buf, "access_network_type") == 0) {
3898 bss->access_network_type = atoi(pos);
3899 if (bss->access_network_type < 0 ||
3900 bss->access_network_type > 15) {
3901 wpa_printf(MSG_ERROR,
3902 "Line %d: invalid access_network_type",
3903 line);
3904 return 1;
3905 }
3906 } else if (os_strcmp(buf, "internet") == 0) {
3907 bss->internet = atoi(pos);
3908 } else if (os_strcmp(buf, "asra") == 0) {
3909 bss->asra = atoi(pos);
3910 } else if (os_strcmp(buf, "esr") == 0) {
3911 bss->esr = atoi(pos);
3912 } else if (os_strcmp(buf, "uesa") == 0) {
3913 bss->uesa = atoi(pos);
3914 } else if (os_strcmp(buf, "venue_group") == 0) {
3915 bss->venue_group = atoi(pos);
3916 bss->venue_info_set = 1;
3917 } else if (os_strcmp(buf, "venue_type") == 0) {
3918 bss->venue_type = atoi(pos);
3919 bss->venue_info_set = 1;
3920 } else if (os_strcmp(buf, "hessid") == 0) {
3921 if (hwaddr_aton(pos, bss->hessid)) {
3922 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3923 return 1;
3924 }
3925 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3926 if (parse_roaming_consortium(bss, pos, line) < 0)
3927 return 1;
3928 } else if (os_strcmp(buf, "venue_name") == 0) {
3929 if (parse_venue_name(bss, pos, line) < 0)
3930 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003931 } else if (os_strcmp(buf, "venue_url") == 0) {
3932 if (parse_venue_url(bss, pos, line) < 0)
3933 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003934 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3935 u8 auth_type;
3936 u16 redirect_url_len;
3937 if (hexstr2bin(pos, &auth_type, 1)) {
3938 wpa_printf(MSG_ERROR,
3939 "Line %d: Invalid network_auth_type '%s'",
3940 line, pos);
3941 return 1;
3942 }
3943 if (auth_type == 0 || auth_type == 2)
3944 redirect_url_len = os_strlen(pos + 2);
3945 else
3946 redirect_url_len = 0;
3947 os_free(bss->network_auth_type);
3948 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3949 if (bss->network_auth_type == NULL)
3950 return 1;
3951 *bss->network_auth_type = auth_type;
3952 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3953 if (redirect_url_len)
3954 os_memcpy(bss->network_auth_type + 3, pos + 2,
3955 redirect_url_len);
3956 bss->network_auth_type_len = 3 + redirect_url_len;
3957 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3958 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3959 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3960 line, pos);
3961 bss->ipaddr_type_configured = 0;
3962 return 1;
3963 }
3964 bss->ipaddr_type_configured = 1;
3965 } else if (os_strcmp(buf, "domain_name") == 0) {
3966 int j, num_domains, domain_len, domain_list_len = 0;
3967 char *tok_start, *tok_prev;
3968 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003969
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003970 domain_list_len = os_strlen(pos) + 1;
3971 domain_list = os_malloc(domain_list_len);
3972 if (domain_list == NULL)
3973 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003974
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003975 domain_ptr = domain_list;
3976 tok_prev = pos;
3977 num_domains = 1;
3978 while ((tok_prev = os_strchr(tok_prev, ','))) {
3979 num_domains++;
3980 tok_prev++;
3981 }
3982 tok_prev = pos;
3983 for (j = 0; j < num_domains; j++) {
3984 tok_start = os_strchr(tok_prev, ',');
3985 if (tok_start) {
3986 domain_len = tok_start - tok_prev;
3987 *domain_ptr = domain_len;
3988 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3989 domain_ptr += domain_len + 1;
3990 tok_prev = ++tok_start;
3991 } else {
3992 domain_len = os_strlen(tok_prev);
3993 *domain_ptr = domain_len;
3994 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3995 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003996 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003997 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003998
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003999 os_free(bss->domain_name);
4000 bss->domain_name = domain_list;
4001 bss->domain_name_len = domain_list_len;
4002 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
4003 if (parse_3gpp_cell_net(bss, pos, line) < 0)
4004 return 1;
4005 } else if (os_strcmp(buf, "nai_realm") == 0) {
4006 if (parse_nai_realm(bss, pos, line) < 0)
4007 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004008 } else if (os_strcmp(buf, "anqp_elem") == 0) {
4009 if (parse_anqp_elem(bss, pos, line) < 0)
4010 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004011 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004012 int val = atoi(pos);
4013
4014 if (val <= 0) {
4015 wpa_printf(MSG_ERROR,
4016 "Line %d: Invalid gas_frag_limit '%s'",
4017 line, pos);
4018 return 1;
4019 }
4020 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004021 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
4022 bss->gas_comeback_delay = atoi(pos);
4023 } else if (os_strcmp(buf, "qos_map_set") == 0) {
4024 if (parse_qos_map_set(bss, pos, line) < 0)
4025 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004026#endif /* CONFIG_INTERWORKING */
4027#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004028 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
4029 os_free(bss->dump_msk_file);
4030 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004031#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004032#ifdef CONFIG_PROXYARP
4033 } else if (os_strcmp(buf, "proxy_arp") == 0) {
4034 bss->proxy_arp = atoi(pos);
4035#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004036#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004037 } else if (os_strcmp(buf, "hs20") == 0) {
4038 bss->hs20 = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004039 } else if (os_strcmp(buf, "hs20_release") == 0) {
4040 int val = atoi(pos);
4041
4042 if (val < 1 || val > (HS20_VERSION >> 4) + 1) {
4043 wpa_printf(MSG_ERROR,
4044 "Line %d: Unsupported hs20_release: %s",
4045 line, pos);
4046 return 1;
4047 }
4048 bss->hs20_release = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004049 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
4050 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004051 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
4052 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004053 } else if (os_strcmp(buf, "osen") == 0) {
4054 bss->osen = atoi(pos);
4055 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
4056 bss->anqp_domain_id = atoi(pos);
4057 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
4058 bss->hs20_deauth_req_timeout = atoi(pos);
4059 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
4060 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
4061 return 1;
4062 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
4063 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
4064 return 1;
4065 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
4066 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
4067 return 1;
4068 }
4069 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
4070 u8 *oper_class;
4071 size_t oper_class_len;
4072 oper_class_len = os_strlen(pos);
4073 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
4074 wpa_printf(MSG_ERROR,
4075 "Line %d: Invalid hs20_operating_class '%s'",
4076 line, pos);
4077 return 1;
4078 }
4079 oper_class_len /= 2;
4080 oper_class = os_malloc(oper_class_len);
4081 if (oper_class == NULL)
4082 return 1;
4083 if (hexstr2bin(pos, oper_class, oper_class_len)) {
4084 wpa_printf(MSG_ERROR,
4085 "Line %d: Invalid hs20_operating_class '%s'",
4086 line, pos);
4087 os_free(oper_class);
4088 return 1;
4089 }
4090 os_free(bss->hs20_operating_class);
4091 bss->hs20_operating_class = oper_class;
4092 bss->hs20_operating_class_len = oper_class_len;
4093 } else if (os_strcmp(buf, "hs20_icon") == 0) {
4094 if (hs20_parse_icon(bss, pos) < 0) {
4095 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
4096 line, pos);
4097 return 1;
4098 }
4099 } else if (os_strcmp(buf, "osu_ssid") == 0) {
4100 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
4101 return 1;
4102 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
4103 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
4104 return 1;
4105 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
4106 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
4107 return 1;
4108 } else if (os_strcmp(buf, "osu_nai") == 0) {
4109 if (hs20_parse_osu_nai(bss, pos, line) < 0)
4110 return 1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004111 } else if (os_strcmp(buf, "osu_nai2") == 0) {
4112 if (hs20_parse_osu_nai2(bss, pos, line) < 0)
4113 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004114 } else if (os_strcmp(buf, "osu_method_list") == 0) {
4115 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
4116 return 1;
4117 } else if (os_strcmp(buf, "osu_icon") == 0) {
4118 if (hs20_parse_osu_icon(bss, pos, line) < 0)
4119 return 1;
4120 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
4121 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
4122 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004123 } else if (os_strcmp(buf, "operator_icon") == 0) {
4124 if (hs20_parse_operator_icon(bss, pos, line) < 0)
4125 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004126 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
4127 os_free(bss->subscr_remediation_url);
4128 bss->subscr_remediation_url = os_strdup(pos);
4129 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
4130 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004131 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
4132 os_free(bss->t_c_filename);
4133 bss->t_c_filename = os_strdup(pos);
4134 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
4135 bss->t_c_timestamp = strtol(pos, NULL, 0);
4136 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
4137 os_free(bss->t_c_server_url);
4138 bss->t_c_server_url = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004139 } else if (os_strcmp(buf, "hs20_sim_provisioning_url") == 0) {
4140 os_free(bss->hs20_sim_provisioning_url);
4141 bss->hs20_sim_provisioning_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004142#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004143#ifdef CONFIG_MBO
4144 } else if (os_strcmp(buf, "mbo") == 0) {
4145 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004146 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
4147 bss->mbo_cell_data_conn_pref = atoi(pos);
4148 } else if (os_strcmp(buf, "oce") == 0) {
4149 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004150#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004151#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004152#define PARSE_TEST_PROBABILITY(_val) \
4153 } else if (os_strcmp(buf, #_val) == 0) { \
4154 char *end; \
4155 \
4156 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004157 if (*end || conf->_val < 0.0 || \
4158 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004159 wpa_printf(MSG_ERROR, \
4160 "Line %d: Invalid value '%s'", \
4161 line, pos); \
4162 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004163 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004164 PARSE_TEST_PROBABILITY(ignore_probe_probability)
4165 PARSE_TEST_PROBABILITY(ignore_auth_probability)
4166 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
4167 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
4168 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004169 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
4170 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004171 } else if (os_strcmp(buf, "bss_load_test") == 0) {
4172 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
4173 pos = os_strchr(pos, ':');
4174 if (pos == NULL) {
4175 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4176 line);
4177 return 1;
4178 }
4179 pos++;
4180 bss->bss_load_test[2] = atoi(pos);
4181 pos = os_strchr(pos, ':');
4182 if (pos == NULL) {
4183 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4184 line);
4185 return 1;
4186 }
4187 pos++;
4188 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
4189 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004190 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004191 /*
4192 * DEPRECATED: This parameter will be removed in the future.
4193 * Use rrm_neighbor_report instead.
4194 */
4195 int val = atoi(pos);
4196
4197 if (val & BIT(0))
4198 bss->radio_measurements[0] |=
4199 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004200 } else if (os_strcmp(buf, "own_ie_override") == 0) {
4201 struct wpabuf *tmp;
4202 size_t len = os_strlen(pos) / 2;
4203
4204 tmp = wpabuf_alloc(len);
4205 if (!tmp)
4206 return 1;
4207
4208 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
4209 wpabuf_free(tmp);
4210 wpa_printf(MSG_ERROR,
4211 "Line %d: Invalid own_ie_override '%s'",
4212 line, pos);
4213 return 1;
4214 }
4215
4216 wpabuf_free(bss->own_ie_override);
4217 bss->own_ie_override = tmp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004218 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
4219 bss->sae_reflection_attack = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004220 } else if (os_strcmp(buf, "sae_commit_status") == 0) {
4221 bss->sae_commit_status = atoi(pos);
4222 } else if (os_strcmp(buf, "sae_pk_omit") == 0) {
4223 bss->sae_pk_omit = atoi(pos);
4224 } else if (os_strcmp(buf, "sae_pk_password_check_skip") == 0) {
4225 bss->sae_pk_password_check_skip = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004226 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
4227 wpabuf_free(bss->sae_commit_override);
4228 bss->sae_commit_override = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004229 } else if (os_strcmp(buf, "rsne_override_eapol") == 0) {
4230 wpabuf_free(bss->rsne_override_eapol);
4231 bss->rsne_override_eapol = wpabuf_parse_bin(pos);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004232 } else if (os_strcmp(buf, "rsnxe_override_eapol") == 0) {
4233 wpabuf_free(bss->rsnxe_override_eapol);
4234 bss->rsnxe_override_eapol = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004235 } else if (os_strcmp(buf, "rsne_override_ft") == 0) {
4236 wpabuf_free(bss->rsne_override_ft);
4237 bss->rsne_override_ft = wpabuf_parse_bin(pos);
4238 } else if (os_strcmp(buf, "rsnxe_override_ft") == 0) {
4239 wpabuf_free(bss->rsnxe_override_ft);
4240 bss->rsnxe_override_ft = wpabuf_parse_bin(pos);
4241 } else if (os_strcmp(buf, "gtk_rsc_override") == 0) {
4242 wpabuf_free(bss->gtk_rsc_override);
4243 bss->gtk_rsc_override = wpabuf_parse_bin(pos);
4244 } else if (os_strcmp(buf, "igtk_rsc_override") == 0) {
4245 wpabuf_free(bss->igtk_rsc_override);
4246 bss->igtk_rsc_override = wpabuf_parse_bin(pos);
4247 } else if (os_strcmp(buf, "no_beacon_rsnxe") == 0) {
4248 bss->no_beacon_rsnxe = atoi(pos);
4249 } else if (os_strcmp(buf, "skip_prune_assoc") == 0) {
4250 bss->skip_prune_assoc = atoi(pos);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004251 } else if (os_strcmp(buf, "ft_rsnxe_used") == 0) {
4252 bss->ft_rsnxe_used = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004253 } else if (os_strcmp(buf, "oci_freq_override_eapol_m3") == 0) {
4254 bss->oci_freq_override_eapol_m3 = atoi(pos);
4255 } else if (os_strcmp(buf, "oci_freq_override_eapol_g1") == 0) {
4256 bss->oci_freq_override_eapol_g1 = atoi(pos);
4257 } else if (os_strcmp(buf, "oci_freq_override_saquery_req") == 0) {
4258 bss->oci_freq_override_saquery_req = atoi(pos);
4259 } else if (os_strcmp(buf, "oci_freq_override_saquery_resp") == 0) {
4260 bss->oci_freq_override_saquery_resp = atoi(pos);
4261 } else if (os_strcmp(buf, "oci_freq_override_ft_assoc") == 0) {
4262 bss->oci_freq_override_ft_assoc = atoi(pos);
4263 } else if (os_strcmp(buf, "oci_freq_override_fils_assoc") == 0) {
4264 bss->oci_freq_override_fils_assoc = atoi(pos);
4265 } else if (os_strcmp(buf, "oci_freq_override_wnm_sleep") == 0) {
4266 bss->oci_freq_override_wnm_sleep = atoi(pos);
Kai Shie75b0652020-11-24 20:31:29 -08004267 } else if (os_strcmp(buf, "skip_send_eapol") == 0) {
4268 conf->skip_send_eapol = atoi(pos);
4269 } else if (os_strcmp(buf, "enable_eapol_large_timeout") == 0) {
4270 conf->enable_eapol_large_timeout = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004271 } else if (os_strcmp(buf, "eap_skip_prot_success") == 0) {
4272 bss->eap_skip_prot_success = atoi(pos);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004273#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004274#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004275 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004276 if (parse_sae_password(bss, pos) < 0) {
4277 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
4278 line);
4279 return 1;
4280 }
4281#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004282 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004283 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004284 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004285 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4286 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004287 return 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08004288 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0 ||
4289 os_strcmp(buf, "anti_clogging_threshold") == 0) {
4290 bss->anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004291 } else if (os_strcmp(buf, "sae_sync") == 0) {
4292 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004293 } else if (os_strcmp(buf, "sae_groups") == 0) {
4294 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
4295 wpa_printf(MSG_ERROR,
4296 "Line %d: Invalid sae_groups value '%s'",
4297 line, pos);
4298 return 1;
4299 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004300 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
4301 bss->sae_require_mfp = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07004302 } else if (os_strcmp(buf, "sae_confirm_immediate") == 0) {
4303 bss->sae_confirm_immediate = atoi(pos);
4304 } else if (os_strcmp(buf, "sae_pwe") == 0) {
4305 bss->sae_pwe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004306 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
4307 int val = atoi(pos);
4308 if (val < 0 || val > 255) {
4309 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
4310 line, val);
4311 return 1;
4312 }
4313 conf->local_pwr_constraint = val;
4314 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
4315 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07004316 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
4317 os_free(bss->wowlan_triggers);
4318 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004319#ifdef CONFIG_FST
4320 } else if (os_strcmp(buf, "fst_group_id") == 0) {
4321 size_t len = os_strlen(pos);
4322
4323 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
4324 wpa_printf(MSG_ERROR,
4325 "Line %d: Invalid fst_group_id value '%s'",
4326 line, pos);
4327 return 1;
4328 }
4329
4330 if (conf->fst_cfg.group_id[0]) {
4331 wpa_printf(MSG_ERROR,
4332 "Line %d: Duplicate fst_group value '%s'",
4333 line, pos);
4334 return 1;
4335 }
4336
4337 os_strlcpy(conf->fst_cfg.group_id, pos,
4338 sizeof(conf->fst_cfg.group_id));
4339 } else if (os_strcmp(buf, "fst_priority") == 0) {
4340 char *endp;
4341 long int val;
4342
4343 if (!*pos) {
4344 wpa_printf(MSG_ERROR,
4345 "Line %d: fst_priority value not supplied (expected 1..%u)",
4346 line, FST_MAX_PRIO_VALUE);
4347 return -1;
4348 }
4349
4350 val = strtol(pos, &endp, 0);
4351 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
4352 wpa_printf(MSG_ERROR,
4353 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
4354 line, val, pos, FST_MAX_PRIO_VALUE);
4355 return 1;
4356 }
4357 conf->fst_cfg.priority = (u8) val;
4358 } else if (os_strcmp(buf, "fst_llt") == 0) {
4359 char *endp;
4360 long int val;
4361
4362 if (!*pos) {
4363 wpa_printf(MSG_ERROR,
4364 "Line %d: fst_llt value not supplied (expected 1..%u)",
4365 line, FST_MAX_LLT_MS);
4366 return -1;
4367 }
4368 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07004369 if (*endp || val < 1 ||
4370 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004371 wpa_printf(MSG_ERROR,
4372 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
4373 line, val, pos, FST_MAX_LLT_MS);
4374 return 1;
4375 }
4376 conf->fst_cfg.llt = (u32) val;
4377#endif /* CONFIG_FST */
4378 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
4379 conf->track_sta_max_num = atoi(pos);
4380 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
4381 conf->track_sta_max_age = atoi(pos);
4382 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
4383 os_free(bss->no_probe_resp_if_seen_on);
4384 bss->no_probe_resp_if_seen_on = os_strdup(pos);
4385 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
4386 os_free(bss->no_auth_if_seen_on);
4387 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004388 } else if (os_strcmp(buf, "lci") == 0) {
4389 wpabuf_free(conf->lci);
4390 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004391 if (conf->lci && wpabuf_len(conf->lci) == 0) {
4392 wpabuf_free(conf->lci);
4393 conf->lci = NULL;
4394 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004395 } else if (os_strcmp(buf, "civic") == 0) {
4396 wpabuf_free(conf->civic);
4397 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004398 if (conf->civic && wpabuf_len(conf->civic) == 0) {
4399 wpabuf_free(conf->civic);
4400 conf->civic = NULL;
4401 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004402 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
4403 if (atoi(pos))
4404 bss->radio_measurements[0] |=
4405 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004406 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
4407 if (atoi(pos))
4408 bss->radio_measurements[0] |=
4409 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4410 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4411 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004412 } else if (os_strcmp(buf, "gas_address3") == 0) {
4413 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004414 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4415 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004416 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4417 bss->ftm_responder = atoi(pos);
4418 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4419 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004420#ifdef CONFIG_FILS
4421 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4422 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4423 wpa_printf(MSG_ERROR,
4424 "Line %d: Invalid fils_cache_id '%s'",
4425 line, pos);
4426 return 1;
4427 }
4428 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004429 } else if (os_strcmp(buf, "fils_realm") == 0) {
4430 if (parse_fils_realm(bss, pos) < 0)
4431 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004432 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4433 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004434 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4435 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4436 wpa_printf(MSG_ERROR,
4437 "Line %d: invalid IP address '%s'",
4438 line, pos);
4439 return 1;
4440 }
4441 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4442 bss->dhcp_rapid_commit_proxy = atoi(pos);
4443 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4444 bss->fils_hlp_wait_time = atoi(pos);
4445 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4446 bss->dhcp_server_port = atoi(pos);
4447 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4448 bss->dhcp_relay_port = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004449 } else if (os_strcmp(buf, "fils_discovery_min_interval") == 0) {
4450 bss->fils_discovery_min_int = atoi(pos);
4451 } else if (os_strcmp(buf, "fils_discovery_max_interval") == 0) {
4452 bss->fils_discovery_max_int = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004453#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004454 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4455 bss->multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004456 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4457 bss->broadcast_deauth = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004458 } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
4459 bss->notify_mgmt_frames = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004460#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07004461 } else if (os_strcmp(buf, "dpp_name") == 0) {
4462 os_free(bss->dpp_name);
4463 bss->dpp_name = os_strdup(pos);
4464 } else if (os_strcmp(buf, "dpp_mud_url") == 0) {
4465 os_free(bss->dpp_mud_url);
4466 bss->dpp_mud_url = os_strdup(pos);
Sunil Ravi89eba102022-09-13 21:04:37 -07004467 } else if (os_strcmp(buf, "dpp_extra_conf_req_name") == 0) {
4468 os_free(bss->dpp_extra_conf_req_name);
4469 bss->dpp_extra_conf_req_name = os_strdup(pos);
4470 } else if (os_strcmp(buf, "dpp_extra_conf_req_value") == 0) {
4471 os_free(bss->dpp_extra_conf_req_value);
4472 bss->dpp_extra_conf_req_value = os_strdup(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004473 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4474 os_free(bss->dpp_connector);
4475 bss->dpp_connector = os_strdup(pos);
4476 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4477 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4478 return 1;
4479 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4480 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4481 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4482 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4483 return 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07004484#ifdef CONFIG_DPP2
4485 } else if (os_strcmp(buf, "dpp_controller") == 0) {
4486 if (hostapd_dpp_controller_parse(bss, pos))
4487 return 1;
Sunil Ravi89eba102022-09-13 21:04:37 -07004488 } else if (os_strcmp(buf, "dpp_relay_port") == 0) {
4489 bss->dpp_relay_port = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004490 } else if (os_strcmp(buf, "dpp_configurator_connectivity") == 0) {
4491 bss->dpp_configurator_connectivity = atoi(pos);
4492 } else if (os_strcmp(buf, "dpp_pfs") == 0) {
4493 int val = atoi(pos);
4494
4495 if (val < 0 || val > 2) {
4496 wpa_printf(MSG_ERROR,
4497 "Line %d: Invalid dpp_pfs value '%s'",
4498 line, pos);
4499 return -1;
4500 }
4501 bss->dpp_pfs = val;
Hai Shalom81f62d82019-07-22 12:10:00 -07004502#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004503#endif /* CONFIG_DPP */
4504#ifdef CONFIG_OWE
4505 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4506 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4507 wpa_printf(MSG_ERROR,
4508 "Line %d: invalid owe_transition_bssid",
4509 line);
4510 return 1;
4511 }
4512 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4513 size_t slen;
4514 char *str = wpa_config_parse_string(pos, &slen);
4515
4516 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4517 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4518 line, pos);
4519 os_free(str);
4520 return 1;
4521 }
4522 os_memcpy(bss->owe_transition_ssid, str, slen);
4523 bss->owe_transition_ssid_len = slen;
4524 os_free(str);
4525 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4526 os_strlcpy(bss->owe_transition_ifname, pos,
4527 sizeof(bss->owe_transition_ifname));
4528 } else if (os_strcmp(buf, "owe_groups") == 0) {
4529 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4530 wpa_printf(MSG_ERROR,
4531 "Line %d: Invalid owe_groups value '%s'",
4532 line, pos);
4533 return 1;
4534 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004535 } else if (os_strcmp(buf, "owe_ptk_workaround") == 0) {
4536 bss->owe_ptk_workaround = atoi(pos);
4537#endif /* CONFIG_OWE */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004538 } else if (os_strcmp(buf, "coloc_intf_reporting") == 0) {
4539 bss->coloc_intf_reporting = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004540 } else if (os_strcmp(buf, "multi_ap") == 0) {
4541 int val = atoi(pos);
4542
4543 if (val < 0 || val > 3) {
4544 wpa_printf(MSG_ERROR, "Line %d: Invalid multi_ap '%s'",
4545 line, buf);
4546 return -1;
4547 }
4548
4549 bss->multi_ap = val;
4550 } else if (os_strcmp(buf, "rssi_reject_assoc_rssi") == 0) {
4551 conf->rssi_reject_assoc_rssi = atoi(pos);
4552 } else if (os_strcmp(buf, "rssi_reject_assoc_timeout") == 0) {
4553 conf->rssi_reject_assoc_timeout = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004554 } else if (os_strcmp(buf, "rssi_ignore_probe_request") == 0) {
4555 conf->rssi_ignore_probe_request = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004556 } else if (os_strcmp(buf, "pbss") == 0) {
4557 bss->pbss = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004558 } else if (os_strcmp(buf, "transition_disable") == 0) {
4559 bss->transition_disable = strtol(pos, NULL, 16);
Hai Shalom81f62d82019-07-22 12:10:00 -07004560#ifdef CONFIG_AIRTIME_POLICY
4561 } else if (os_strcmp(buf, "airtime_mode") == 0) {
4562 int val = atoi(pos);
4563
4564 if (val < 0 || val > AIRTIME_MODE_MAX) {
4565 wpa_printf(MSG_ERROR, "Line %d: Unknown airtime_mode",
4566 line);
4567 return 1;
4568 }
4569 conf->airtime_mode = val;
4570 } else if (os_strcmp(buf, "airtime_update_interval") == 0) {
4571 conf->airtime_update_interval = atoi(pos);
4572 } else if (os_strcmp(buf, "airtime_bss_weight") == 0) {
4573 bss->airtime_weight = atoi(pos);
4574 } else if (os_strcmp(buf, "airtime_bss_limit") == 0) {
4575 int val = atoi(pos);
4576
4577 if (val < 0 || val > 1) {
4578 wpa_printf(MSG_ERROR,
4579 "Line %d: Invalid airtime_bss_limit (must be 0 or 1)",
4580 line);
4581 return 1;
4582 }
4583 bss->airtime_limit = val;
4584 } else if (os_strcmp(buf, "airtime_sta_weight") == 0) {
4585 if (add_airtime_weight(bss, pos) < 0) {
4586 wpa_printf(MSG_ERROR,
4587 "Line %d: Invalid airtime weight '%s'",
4588 line, pos);
4589 return 1;
4590 }
4591#endif /* CONFIG_AIRTIME_POLICY */
4592#ifdef CONFIG_MACSEC
4593 } else if (os_strcmp(buf, "macsec_policy") == 0) {
4594 int macsec_policy = atoi(pos);
4595
4596 if (macsec_policy < 0 || macsec_policy > 1) {
4597 wpa_printf(MSG_ERROR,
4598 "Line %d: invalid macsec_policy (%d): '%s'.",
4599 line, macsec_policy, pos);
4600 return 1;
4601 }
4602 bss->macsec_policy = macsec_policy;
4603 } else if (os_strcmp(buf, "macsec_integ_only") == 0) {
4604 int macsec_integ_only = atoi(pos);
4605
4606 if (macsec_integ_only < 0 || macsec_integ_only > 1) {
4607 wpa_printf(MSG_ERROR,
4608 "Line %d: invalid macsec_integ_only (%d): '%s'.",
4609 line, macsec_integ_only, pos);
4610 return 1;
4611 }
4612 bss->macsec_integ_only = macsec_integ_only;
4613 } else if (os_strcmp(buf, "macsec_replay_protect") == 0) {
4614 int macsec_replay_protect = atoi(pos);
4615
4616 if (macsec_replay_protect < 0 || macsec_replay_protect > 1) {
4617 wpa_printf(MSG_ERROR,
4618 "Line %d: invalid macsec_replay_protect (%d): '%s'.",
4619 line, macsec_replay_protect, pos);
4620 return 1;
4621 }
4622 bss->macsec_replay_protect = macsec_replay_protect;
4623 } else if (os_strcmp(buf, "macsec_replay_window") == 0) {
4624 bss->macsec_replay_window = atoi(pos);
4625 } else if (os_strcmp(buf, "macsec_port") == 0) {
4626 int macsec_port = atoi(pos);
4627
4628 if (macsec_port < 1 || macsec_port > 65534) {
4629 wpa_printf(MSG_ERROR,
4630 "Line %d: invalid macsec_port (%d): '%s'.",
4631 line, macsec_port, pos);
4632 return 1;
4633 }
4634 bss->macsec_port = macsec_port;
4635 } else if (os_strcmp(buf, "mka_priority") == 0) {
4636 int mka_priority = atoi(pos);
4637
4638 if (mka_priority < 0 || mka_priority > 255) {
4639 wpa_printf(MSG_ERROR,
4640 "Line %d: invalid mka_priority (%d): '%s'.",
4641 line, mka_priority, pos);
4642 return 1;
4643 }
4644 bss->mka_priority = mka_priority;
Sunil Ravia04bd252022-05-02 22:54:18 -07004645 } else if (os_strcmp(buf, "macsec_csindex") == 0) {
4646 int macsec_csindex = atoi(pos);
4647
4648 if (macsec_csindex < 0 || macsec_csindex > 1) {
4649 wpa_printf(MSG_ERROR,
4650 "Line %d: invalid macsec_csindex (%d): '%s'.",
4651 line, macsec_csindex, pos);
4652 return 1;
4653 }
4654 bss->macsec_csindex = macsec_csindex;
Hai Shalom81f62d82019-07-22 12:10:00 -07004655 } else if (os_strcmp(buf, "mka_cak") == 0) {
4656 size_t len = os_strlen(pos);
4657
4658 if (len > 2 * MACSEC_CAK_MAX_LEN ||
4659 (len != 2 * 16 && len != 2 * 32) ||
4660 hexstr2bin(pos, bss->mka_cak, len / 2)) {
4661 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.",
4662 line, pos);
4663 return 1;
4664 }
4665 bss->mka_cak_len = len / 2;
4666 bss->mka_psk_set |= MKA_PSK_SET_CAK;
4667 } else if (os_strcmp(buf, "mka_ckn") == 0) {
4668 size_t len = os_strlen(pos);
4669
4670 if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */
4671 len < 2 || /* too short */
4672 len % 2 != 0 /* not an integral number of bytes */) {
4673 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4674 line, pos);
4675 return 1;
4676 }
4677 bss->mka_ckn_len = len / 2;
4678 if (hexstr2bin(pos, bss->mka_ckn, bss->mka_ckn_len)) {
4679 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4680 line, pos);
4681 return -1;
4682 }
4683 bss->mka_psk_set |= MKA_PSK_SET_CKN;
4684#endif /* CONFIG_MACSEC */
Hai Shalom60840252021-02-19 19:02:11 -08004685 } else if (os_strcmp(buf, "disable_11n") == 0) {
4686 bss->disable_11n = !!atoi(pos);
4687 } else if (os_strcmp(buf, "disable_11ac") == 0) {
4688 bss->disable_11ac = !!atoi(pos);
4689 } else if (os_strcmp(buf, "disable_11ax") == 0) {
4690 bss->disable_11ax = !!atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004691 } else if (os_strcmp(buf, "disable_11be") == 0) {
4692 bss->disable_11be = !!atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004693#ifdef CONFIG_PASN
4694#ifdef CONFIG_TESTING_OPTIONS
4695 } else if (os_strcmp(buf, "force_kdk_derivation") == 0) {
4696 bss->force_kdk_derivation = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08004697 } else if (os_strcmp(buf, "pasn_corrupt_mic") == 0) {
4698 bss->pasn_corrupt_mic = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004699#endif /* CONFIG_TESTING_OPTIONS */
4700 } else if (os_strcmp(buf, "pasn_groups") == 0) {
4701 if (hostapd_parse_intlist(&bss->pasn_groups, pos)) {
4702 wpa_printf(MSG_ERROR,
4703 "Line %d: Invalid pasn_groups value '%s'",
4704 line, pos);
4705 return 1;
4706 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08004707 } else if (os_strcmp(buf, "pasn_comeback_after") == 0) {
4708 bss->pasn_comeback_after = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004709#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -08004710 } else if (os_strcmp(buf, "ext_capa_mask") == 0) {
4711 if (get_hex_config(bss->ext_capa_mask, EXT_CAPA_MAX_LEN,
4712 line, "ext_capa_mask", pos))
4713 return 1;
4714 } else if (os_strcmp(buf, "ext_capa") == 0) {
4715 if (get_hex_config(bss->ext_capa, EXT_CAPA_MAX_LEN,
4716 line, "ext_capa", pos))
4717 return 1;
4718 } else if (os_strcmp(buf, "rnr") == 0) {
4719 bss->rnr = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004720#ifdef CONFIG_IEEE80211BE
4721 } else if (os_strcmp(buf, "ieee80211be") == 0) {
4722 conf->ieee80211be = atoi(pos);
4723 } else if (os_strcmp(buf, "eht_oper_chwidth") == 0) {
4724 conf->eht_oper_chwidth = atoi(pos);
4725 } else if (os_strcmp(buf, "eht_oper_centr_freq_seg0_idx") == 0) {
4726 conf->eht_oper_centr_freq_seg0_idx = atoi(pos);
4727 } else if (os_strcmp(buf, "eht_su_beamformer") == 0) {
4728 conf->eht_phy_capab.su_beamformer = atoi(pos);
4729 } else if (os_strcmp(buf, "eht_su_beamformee") == 0) {
4730 conf->eht_phy_capab.su_beamformee = atoi(pos);
4731 } else if (os_strcmp(buf, "eht_mu_beamformer") == 0) {
4732 conf->eht_phy_capab.mu_beamformer = atoi(pos);
4733#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004734 } else {
4735 wpa_printf(MSG_ERROR,
4736 "Line %d: unknown configuration item '%s'",
4737 line, buf);
4738 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004739 }
4740
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004741 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004742}
4743
4744
Dmitry Shmidt04949592012-07-19 12:16:46 -07004745/**
4746 * hostapd_config_read - Read and parse a configuration file
4747 * @fname: Configuration file name (including path, if needed)
4748 * Returns: Allocated configuration data structure
4749 */
4750struct hostapd_config * hostapd_config_read(const char *fname)
4751{
4752 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004753 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004754 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004755 int line = 0;
4756 int errors = 0;
4757 size_t i;
4758
4759 f = fopen(fname, "r");
4760 if (f == NULL) {
4761 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4762 "for reading.", fname);
4763 return NULL;
4764 }
4765
4766 conf = hostapd_config_defaults();
4767 if (conf == NULL) {
4768 fclose(f);
4769 return NULL;
4770 }
4771
4772 /* set default driver based on configuration */
4773 conf->driver = wpa_drivers[0];
4774 if (conf->driver == NULL) {
4775 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4776 hostapd_config_free(conf);
4777 fclose(f);
4778 return NULL;
4779 }
4780
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004781 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004782
4783 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004784 struct hostapd_bss_config *bss;
4785
Dmitry Shmidt04949592012-07-19 12:16:46 -07004786 bss = conf->last_bss;
4787 line++;
4788
4789 if (buf[0] == '#')
4790 continue;
4791 pos = buf;
4792 while (*pos != '\0') {
4793 if (*pos == '\n') {
4794 *pos = '\0';
4795 break;
4796 }
4797 pos++;
4798 }
4799 if (buf[0] == '\0')
4800 continue;
4801
4802 pos = os_strchr(buf, '=');
4803 if (pos == NULL) {
4804 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4805 line, buf);
4806 errors++;
4807 continue;
4808 }
4809 *pos = '\0';
4810 pos++;
4811 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4812 }
4813
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004814 fclose(f);
4815
Dmitry Shmidt04949592012-07-19 12:16:46 -07004816 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004817 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004818
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004819 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004820 errors++;
4821
4822#ifndef WPA_IGNORE_CONFIG_ERRORS
4823 if (errors) {
4824 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4825 "'%s'", errors, fname);
4826 hostapd_config_free(conf);
4827 conf = NULL;
4828 }
4829#endif /* WPA_IGNORE_CONFIG_ERRORS */
4830
4831 return conf;
4832}
Dmitry Shmidt04949592012-07-19 12:16:46 -07004833
4834
4835int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004836 struct hostapd_bss_config *bss, const char *field,
4837 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004838{
4839 int errors;
4840 size_t i;
4841
4842 errors = hostapd_config_fill(conf, bss, field, value, 0);
4843 if (errors) {
4844 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4845 "to value '%s'", field, value);
4846 return -1;
4847 }
4848
4849 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004850 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004851
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004852 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004853 wpa_printf(MSG_ERROR, "Configuration check failed");
4854 return -1;
4855 }
4856
4857 return 0;
4858}