blob: 03371e1d524c067038b8fdca02ccec3c1fdc8ccb [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"
16#include "common/ieee802_11_defs.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070017#include "common/sae.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070018#include "crypto/sha256.h"
19#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "drivers/driver.h"
21#include "eap_server/eap.h"
22#include "radius/radius_client.h"
23#include "ap/wpa_auth.h"
24#include "ap/ap_config.h"
25#include "config_file.h"
26
27
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#ifndef CONFIG_NO_VLAN
29static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
30 const char *fname)
31{
32 FILE *f;
Hai Shalom74f70d42019-02-11 14:42:39 -080033 char buf[128], *pos, *pos2, *pos3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034 int line = 0, vlan_id;
35 struct hostapd_vlan *vlan;
36
37 f = fopen(fname, "r");
38 if (!f) {
39 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
40 return -1;
41 }
42
43 while (fgets(buf, sizeof(buf), f)) {
44 line++;
45
46 if (buf[0] == '#')
47 continue;
48 pos = buf;
49 while (*pos != '\0') {
50 if (*pos == '\n') {
51 *pos = '\0';
52 break;
53 }
54 pos++;
55 }
56 if (buf[0] == '\0')
57 continue;
58
59 if (buf[0] == '*') {
60 vlan_id = VLAN_ID_WILDCARD;
61 pos = buf + 1;
62 } else {
63 vlan_id = strtol(buf, &pos, 10);
64 if (buf == pos || vlan_id < 1 ||
65 vlan_id > MAX_VLAN_ID) {
66 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
67 "line %d in '%s'", line, fname);
68 fclose(f);
69 return -1;
70 }
71 }
72
73 while (*pos == ' ' || *pos == '\t')
74 pos++;
75 pos2 = pos;
76 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
77 pos2++;
Hai Shalom74f70d42019-02-11 14:42:39 -080078
79 if (*pos2 != '\0')
80 *(pos2++) = '\0';
81
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
83 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
84 "in '%s'", line, fname);
85 fclose(f);
86 return -1;
87 }
88
Hai Shalom74f70d42019-02-11 14:42:39 -080089 while (*pos2 == ' ' || *pos2 == '\t')
90 pos2++;
91 pos3 = pos2;
92 while (*pos3 != ' ' && *pos3 != '\t' && *pos3 != '\0')
93 pos3++;
94 *pos3 = '\0';
95
Dmitry Shmidt4b060592013-04-29 16:42:49 -070096 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 if (vlan == NULL) {
98 wpa_printf(MSG_ERROR, "Out of memory while reading "
99 "VLAN interfaces from '%s'", fname);
100 fclose(f);
101 return -1;
102 }
103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 vlan->vlan_id = vlan_id;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800105 vlan->vlan_desc.untagged = vlan_id;
106 vlan->vlan_desc.notempty = !!vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Hai Shalom74f70d42019-02-11 14:42:39 -0800108 os_strlcpy(vlan->bridge, pos2, sizeof(vlan->bridge));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700109 vlan->next = bss->vlan;
110 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111 }
112
113 fclose(f);
114
115 return 0;
116}
117#endif /* CONFIG_NO_VLAN */
118
119
Roshan Pius3a1667e2018-07-03 15:17:14 -0700120int hostapd_acl_comp(const void *a, const void *b)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121{
122 const struct mac_acl_entry *aa = a;
123 const struct mac_acl_entry *bb = b;
124 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
125}
126
127
Roshan Pius3a1667e2018-07-03 15:17:14 -0700128int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
129 int vlan_id, const u8 *addr)
130{
131 struct mac_acl_entry *newacl;
132
133 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
134 if (!newacl) {
135 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
136 return -1;
137 }
138
139 *acl = newacl;
140 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
141 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
142 (*acl)[*num].vlan_id.untagged = vlan_id;
143 (*acl)[*num].vlan_id.notempty = !!vlan_id;
144 (*num)++;
145
146 return 0;
147}
148
149
150void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
151 const u8 *addr)
152{
153 int i = 0;
154
155 while (i < *num) {
156 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
157 os_remove_in_array(*acl, *num, sizeof(**acl), i);
158 (*num)--;
159 } else {
160 i++;
161 }
162 }
163}
164
165
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166static int hostapd_config_read_maclist(const char *fname,
167 struct mac_acl_entry **acl, int *num)
168{
169 FILE *f;
170 char buf[128], *pos;
171 int line = 0;
172 u8 addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173 int vlan_id;
174
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175 f = fopen(fname, "r");
176 if (!f) {
177 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
178 return -1;
179 }
180
181 while (fgets(buf, sizeof(buf), f)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700182 int rem = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184 line++;
185
186 if (buf[0] == '#')
187 continue;
188 pos = buf;
189 while (*pos != '\0') {
190 if (*pos == '\n') {
191 *pos = '\0';
192 break;
193 }
194 pos++;
195 }
196 if (buf[0] == '\0')
197 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800198 pos = buf;
199 if (buf[0] == '-') {
200 rem = 1;
201 pos++;
202 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800204 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800206 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207 fclose(f);
208 return -1;
209 }
210
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800211 if (rem) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700212 hostapd_remove_acl_mac(acl, num, addr);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800213 continue;
214 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215 vlan_id = 0;
216 pos = buf;
217 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
218 pos++;
219 while (*pos == ' ' || *pos == '\t')
220 pos++;
221 if (*pos != '\0')
222 vlan_id = atoi(pos);
223
Roshan Pius3a1667e2018-07-03 15:17:14 -0700224 if (hostapd_add_acl_maclist(acl, num, vlan_id, addr) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225 fclose(f);
226 return -1;
227 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 }
229
230 fclose(f);
231
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800232 if (*acl)
233 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234
235 return 0;
236}
237
238
239#ifdef EAP_SERVER
Roshan Pius3a1667e2018-07-03 15:17:14 -0700240
241static int hostapd_config_eap_user_salted(struct hostapd_eap_user *user,
242 const char *hash, size_t len,
243 char **pos, int line,
244 const char *fname)
245{
246 char *pos2 = *pos;
247
248 while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#')
249 pos2++;
250
251 if (pos2 - *pos < (int) (2 * (len + 1))) { /* at least 1 byte of salt */
252 wpa_printf(MSG_ERROR,
253 "Invalid salted %s hash on line %d in '%s'",
254 hash, line, fname);
255 return -1;
256 }
257
258 user->password = os_malloc(len);
259 if (!user->password) {
260 wpa_printf(MSG_ERROR,
261 "Failed to allocate memory for salted %s hash",
262 hash);
263 return -1;
264 }
265
266 if (hexstr2bin(*pos, user->password, len) < 0) {
267 wpa_printf(MSG_ERROR,
268 "Invalid salted password on line %d in '%s'",
269 line, fname);
270 return -1;
271 }
272 user->password_len = len;
273 *pos += 2 * len;
274
275 user->salt_len = (pos2 - *pos) / 2;
276 user->salt = os_malloc(user->salt_len);
277 if (!user->salt) {
278 wpa_printf(MSG_ERROR,
279 "Failed to allocate memory for salted %s hash",
280 hash);
281 return -1;
282 }
283
284 if (hexstr2bin(*pos, user->salt, user->salt_len) < 0) {
285 wpa_printf(MSG_ERROR,
286 "Invalid salt for password on line %d in '%s'",
287 line, fname);
288 return -1;
289 }
290
291 *pos = pos2;
292 return 0;
293}
294
295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296static int hostapd_config_read_eap_user(const char *fname,
297 struct hostapd_bss_config *conf)
298{
299 FILE *f;
300 char buf[512], *pos, *start, *pos2;
301 int line = 0, ret = 0, num_methods;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800302 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800304 if (os_strncmp(fname, "sqlite:", 7) == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700305#ifdef CONFIG_SQLITE
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800306 os_free(conf->eap_user_sqlite);
307 conf->eap_user_sqlite = os_strdup(fname + 7);
308 return 0;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700309#else /* CONFIG_SQLITE */
310 wpa_printf(MSG_ERROR,
311 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
312 return -1;
313#endif /* CONFIG_SQLITE */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800314 }
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 f = fopen(fname, "r");
317 if (!f) {
318 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
319 return -1;
320 }
321
322 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
323 while (fgets(buf, sizeof(buf), f)) {
324 line++;
325
326 if (buf[0] == '#')
327 continue;
328 pos = buf;
329 while (*pos != '\0') {
330 if (*pos == '\n') {
331 *pos = '\0';
332 break;
333 }
334 pos++;
335 }
336 if (buf[0] == '\0')
337 continue;
338
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700339#ifndef CONFIG_NO_RADIUS
340 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
341 struct hostapd_radius_attr *attr, *a;
342 attr = hostapd_parse_radius_attr(buf + 19);
343 if (attr == NULL) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700344 wpa_printf(MSG_ERROR, "Invalid radius_accept_attr: %s",
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700345 buf + 19);
Dmitry Shmidt98660862014-03-11 17:26:21 -0700346 user = NULL; /* already in the BSS list */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700347 goto failed;
348 }
349 if (user->accept_attr == NULL) {
350 user->accept_attr = attr;
351 } else {
352 a = user->accept_attr;
353 while (a->next)
354 a = a->next;
355 a->next = attr;
356 }
357 continue;
358 }
359#endif /* CONFIG_NO_RADIUS */
360
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361 user = NULL;
362
363 if (buf[0] != '"' && buf[0] != '*') {
364 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
365 "start) on line %d in '%s'", line, fname);
366 goto failed;
367 }
368
369 user = os_zalloc(sizeof(*user));
370 if (user == NULL) {
371 wpa_printf(MSG_ERROR, "EAP user allocation failed");
372 goto failed;
373 }
374 user->force_version = -1;
375
376 if (buf[0] == '*') {
377 pos = buf;
378 } else {
379 pos = buf + 1;
380 start = pos;
381 while (*pos != '"' && *pos != '\0')
382 pos++;
383 if (*pos == '\0') {
384 wpa_printf(MSG_ERROR, "Invalid EAP identity "
385 "(no \" in end) on line %d in '%s'",
386 line, fname);
387 goto failed;
388 }
389
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700390 user->identity = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391 if (user->identity == NULL) {
392 wpa_printf(MSG_ERROR, "Failed to allocate "
393 "memory for EAP identity");
394 goto failed;
395 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 user->identity_len = pos - start;
397
398 if (pos[0] == '"' && pos[1] == '*') {
399 user->wildcard_prefix = 1;
400 pos++;
401 }
402 }
403 pos++;
404 while (*pos == ' ' || *pos == '\t')
405 pos++;
406
407 if (*pos == '\0') {
408 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
409 "'%s'", line, fname);
410 goto failed;
411 }
412
413 start = pos;
414 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
415 pos++;
416 if (*pos == '\0') {
417 pos = NULL;
418 } else {
419 *pos = '\0';
420 pos++;
421 }
422 num_methods = 0;
423 while (*start) {
424 char *pos3 = os_strchr(start, ',');
425 if (pos3) {
426 *pos3++ = '\0';
427 }
428 user->methods[num_methods].method =
429 eap_server_get_type(
430 start,
431 &user->methods[num_methods].vendor);
432 if (user->methods[num_methods].vendor ==
433 EAP_VENDOR_IETF &&
434 user->methods[num_methods].method == EAP_TYPE_NONE)
435 {
436 if (os_strcmp(start, "TTLS-PAP") == 0) {
437 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
438 goto skip_eap;
439 }
440 if (os_strcmp(start, "TTLS-CHAP") == 0) {
441 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
442 goto skip_eap;
443 }
444 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
445 user->ttls_auth |=
446 EAP_TTLS_AUTH_MSCHAP;
447 goto skip_eap;
448 }
449 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
450 user->ttls_auth |=
451 EAP_TTLS_AUTH_MSCHAPV2;
452 goto skip_eap;
453 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700454 if (os_strcmp(start, "MACACL") == 0) {
455 user->macacl = 1;
456 goto skip_eap;
457 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458 wpa_printf(MSG_ERROR, "Unsupported EAP type "
459 "'%s' on line %d in '%s'",
460 start, line, fname);
461 goto failed;
462 }
463
464 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800465 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 break;
467 skip_eap:
468 if (pos3 == NULL)
469 break;
470 start = pos3;
471 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700472 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 wpa_printf(MSG_ERROR, "No EAP types configured on "
474 "line %d in '%s'", line, fname);
475 goto failed;
476 }
477
478 if (pos == NULL)
479 goto done;
480
481 while (*pos == ' ' || *pos == '\t')
482 pos++;
483 if (*pos == '\0')
484 goto done;
485
486 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
487 user->force_version = 0;
488 goto done;
489 }
490
491 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
492 user->force_version = 1;
493 goto done;
494 }
495
496 if (os_strncmp(pos, "[2]", 3) == 0) {
497 user->phase2 = 1;
498 goto done;
499 }
500
501 if (*pos == '"') {
502 pos++;
503 start = pos;
504 while (*pos != '"' && *pos != '\0')
505 pos++;
506 if (*pos == '\0') {
507 wpa_printf(MSG_ERROR, "Invalid EAP password "
508 "(no \" in end) on line %d in '%s'",
509 line, fname);
510 goto failed;
511 }
512
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700513 user->password = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 if (user->password == NULL) {
515 wpa_printf(MSG_ERROR, "Failed to allocate "
516 "memory for EAP password");
517 goto failed;
518 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 user->password_len = pos - start;
520
521 pos++;
522 } else if (os_strncmp(pos, "hash:", 5) == 0) {
523 pos += 5;
524 pos2 = pos;
525 while (*pos2 != '\0' && *pos2 != ' ' &&
526 *pos2 != '\t' && *pos2 != '#')
527 pos2++;
528 if (pos2 - pos != 32) {
529 wpa_printf(MSG_ERROR, "Invalid password hash "
530 "on line %d in '%s'", line, fname);
531 goto failed;
532 }
533 user->password = os_malloc(16);
534 if (user->password == NULL) {
535 wpa_printf(MSG_ERROR, "Failed to allocate "
536 "memory for EAP password hash");
537 goto failed;
538 }
539 if (hexstr2bin(pos, user->password, 16) < 0) {
540 wpa_printf(MSG_ERROR, "Invalid hash password "
541 "on line %d in '%s'", line, fname);
542 goto failed;
543 }
544 user->password_len = 16;
545 user->password_hash = 1;
546 pos = pos2;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700547 } else if (os_strncmp(pos, "ssha1:", 6) == 0) {
548 pos += 6;
549 if (hostapd_config_eap_user_salted(user, "sha1", 20,
550 &pos,
551 line, fname) < 0)
552 goto failed;
553 } else if (os_strncmp(pos, "ssha256:", 8) == 0) {
554 pos += 8;
555 if (hostapd_config_eap_user_salted(user, "sha256", 32,
556 &pos,
557 line, fname) < 0)
558 goto failed;
559 } else if (os_strncmp(pos, "ssha512:", 8) == 0) {
560 pos += 8;
561 if (hostapd_config_eap_user_salted(user, "sha512", 64,
562 &pos,
563 line, fname) < 0)
564 goto failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565 } else {
566 pos2 = pos;
567 while (*pos2 != '\0' && *pos2 != ' ' &&
568 *pos2 != '\t' && *pos2 != '#')
569 pos2++;
570 if ((pos2 - pos) & 1) {
571 wpa_printf(MSG_ERROR, "Invalid hex password "
572 "on line %d in '%s'", line, fname);
573 goto failed;
574 }
575 user->password = os_malloc((pos2 - pos) / 2);
576 if (user->password == NULL) {
577 wpa_printf(MSG_ERROR, "Failed to allocate "
578 "memory for EAP password");
579 goto failed;
580 }
581 if (hexstr2bin(pos, user->password,
582 (pos2 - pos) / 2) < 0) {
583 wpa_printf(MSG_ERROR, "Invalid hex password "
584 "on line %d in '%s'", line, fname);
585 goto failed;
586 }
587 user->password_len = (pos2 - pos) / 2;
588 pos = pos2;
589 }
590
591 while (*pos == ' ' || *pos == '\t')
592 pos++;
593 if (os_strncmp(pos, "[2]", 3) == 0) {
594 user->phase2 = 1;
595 }
596
597 done:
598 if (tail == NULL) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800599 tail = new_user = user;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 } else {
601 tail->next = user;
602 tail = user;
603 }
604 continue;
605
606 failed:
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700607 if (user)
608 hostapd_config_free_eap_user(user);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 ret = -1;
610 break;
611 }
612
613 fclose(f);
614
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800615 if (ret == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800616 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800617 conf->eap_user = new_user;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800618 } else {
619 hostapd_config_free_eap_users(new_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800620 }
621
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700622 return ret;
623}
Roshan Pius3a1667e2018-07-03 15:17:14 -0700624
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625#endif /* EAP_SERVER */
626
627
628#ifndef CONFIG_NO_RADIUS
629static int
630hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
631 int *num_server, const char *val, int def_port,
632 struct hostapd_radius_server **curr_serv)
633{
634 struct hostapd_radius_server *nserv;
635 int ret;
636 static int server_index = 1;
637
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700638 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 if (nserv == NULL)
640 return -1;
641
642 *server = nserv;
643 nserv = &nserv[*num_server];
644 (*num_server)++;
645 (*curr_serv) = nserv;
646
647 os_memset(nserv, 0, sizeof(*nserv));
648 nserv->port = def_port;
649 ret = hostapd_parse_ip_addr(val, &nserv->addr);
650 nserv->index = server_index++;
651
652 return ret;
653}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700654
655
Dmitry Shmidt04949592012-07-19 12:16:46 -0700656
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700657static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700658{
659 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700660
661 secret = os_strchr(val, ' ');
662 if (secret == NULL)
663 return -1;
664
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700665 *secret++ = '\0';
Dmitry Shmidt04949592012-07-19 12:16:46 -0700666
667 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
668 return -1;
669
670 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700671 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700672 if (bss->radius_das_shared_secret == NULL)
673 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700674 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700675
676 return 0;
677}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678#endif /* CONFIG_NO_RADIUS */
679
680
681static int hostapd_config_parse_key_mgmt(int line, const char *value)
682{
683 int val = 0, last;
684 char *start, *end, *buf;
685
686 buf = os_strdup(value);
687 if (buf == NULL)
688 return -1;
689 start = buf;
690
691 while (*start != '\0') {
692 while (*start == ' ' || *start == '\t')
693 start++;
694 if (*start == '\0')
695 break;
696 end = start;
697 while (*end != ' ' && *end != '\t' && *end != '\0')
698 end++;
699 last = *end == '\0';
700 *end = '\0';
701 if (os_strcmp(start, "WPA-PSK") == 0)
702 val |= WPA_KEY_MGMT_PSK;
703 else if (os_strcmp(start, "WPA-EAP") == 0)
704 val |= WPA_KEY_MGMT_IEEE8021X;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800705#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 else if (os_strcmp(start, "FT-PSK") == 0)
707 val |= WPA_KEY_MGMT_FT_PSK;
708 else if (os_strcmp(start, "FT-EAP") == 0)
709 val |= WPA_KEY_MGMT_FT_IEEE8021X;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700710#ifdef CONFIG_SHA384
711 else if (os_strcmp(start, "FT-EAP-SHA384") == 0)
712 val |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
713#endif /* CONFIG_SHA384 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
716 val |= WPA_KEY_MGMT_PSK_SHA256;
717 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
718 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800719#ifdef CONFIG_SAE
720 else if (os_strcmp(start, "SAE") == 0)
721 val |= WPA_KEY_MGMT_SAE;
722 else if (os_strcmp(start, "FT-SAE") == 0)
723 val |= WPA_KEY_MGMT_FT_SAE;
724#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800725#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800726 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
727 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800728#endif /* CONFIG_SUITEB */
729#ifdef CONFIG_SUITEB192
730 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
731 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
732#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800733#ifdef CONFIG_FILS
734 else if (os_strcmp(start, "FILS-SHA256") == 0)
735 val |= WPA_KEY_MGMT_FILS_SHA256;
736 else if (os_strcmp(start, "FILS-SHA384") == 0)
737 val |= WPA_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800738#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800739 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
740 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
741 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
742 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800743#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800744#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700745#ifdef CONFIG_OWE
746 else if (os_strcmp(start, "OWE") == 0)
747 val |= WPA_KEY_MGMT_OWE;
748#endif /* CONFIG_OWE */
749#ifdef CONFIG_DPP
750 else if (os_strcmp(start, "DPP") == 0)
751 val |= WPA_KEY_MGMT_DPP;
752#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700753#ifdef CONFIG_HS20
754 else if (os_strcmp(start, "OSEN") == 0)
755 val |= WPA_KEY_MGMT_OSEN;
756#endif /* CONFIG_HS20 */
Hai Shalom60840252021-02-19 19:02:11 -0800757#ifdef CONFIG_PASN
758 else if (os_strcmp(start, "PASN") == 0)
759 val |= WPA_KEY_MGMT_PASN;
760#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 else {
762 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
763 line, start);
764 os_free(buf);
765 return -1;
766 }
767
768 if (last)
769 break;
770 start = end + 1;
771 }
772
773 os_free(buf);
774 if (val == 0) {
775 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
776 "configured.", line);
777 return -1;
778 }
779
780 return val;
781}
782
783
784static int hostapd_config_parse_cipher(int line, const char *value)
785{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800786 int val = wpa_parse_cipher(value);
787 if (val < 0) {
788 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
789 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792 if (val == 0) {
793 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
794 line);
795 return -1;
796 }
797 return val;
798}
799
800
Hai Shalomfdcde762020-04-02 11:19:20 -0700801#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
803 char *val)
804{
805 size_t len = os_strlen(val);
806
Dmitry Shmidt29333592017-01-09 12:27:11 -0800807 if (keyidx < 0 || keyidx > 3)
808 return -1;
809
810 if (len == 0) {
811 int i, set = 0;
812
813 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
814 wep->key[keyidx] = NULL;
815 wep->len[keyidx] = 0;
816 for (i = 0; i < NUM_WEP_KEYS; i++) {
817 if (wep->key[i])
818 set++;
819 }
820 if (!set)
821 wep->keys_set = 0;
822 return 0;
823 }
824
825 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826 return -1;
827
828 if (val[0] == '"') {
829 if (len < 2 || val[len - 1] != '"')
830 return -1;
831 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700832 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 if (wep->key[keyidx] == NULL)
834 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 wep->len[keyidx] = len;
836 } else {
837 if (len & 1)
838 return -1;
839 len /= 2;
840 wep->key[keyidx] = os_malloc(len);
841 if (wep->key[keyidx] == NULL)
842 return -1;
843 wep->len[keyidx] = len;
844 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
845 return -1;
846 }
847
848 wep->keys_set++;
849
850 return 0;
851}
Hai Shalomfdcde762020-04-02 11:19:20 -0700852#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853
854
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700855static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
856{
857 char *pos;
858
859 /* for backwards compatibility, translate ' ' in conf str to ',' */
860 pos = val;
861 while (pos) {
862 pos = os_strchr(pos, ' ');
863 if (pos)
864 *pos++ = ',';
865 }
866 if (freq_range_list_parse(&conf->acs_ch_list, val))
867 return -1;
868
869 return 0;
870}
871
872
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700873static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874{
875 int *list;
876 int count;
877 char *pos, *end;
878
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700879 os_free(*int_list);
880 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881
882 pos = val;
883 count = 0;
884 while (*pos != '\0') {
885 if (*pos == ' ')
886 count++;
887 pos++;
888 }
889
890 list = os_malloc(sizeof(int) * (count + 2));
891 if (list == NULL)
892 return -1;
893 pos = val;
894 count = 0;
895 while (*pos != '\0') {
896 end = os_strchr(pos, ' ');
897 if (end)
898 *end = '\0';
899
900 list[count++] = atoi(pos);
901 if (!end)
902 break;
903 pos = end + 1;
904 }
905 list[count] = -1;
906
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700907 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 return 0;
909}
910
911
912static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
913{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800914 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915
916 if (*ifname == '\0')
917 return -1;
918
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800919 all = os_realloc_array(conf->bss, conf->num_bss + 1,
920 sizeof(struct hostapd_bss_config *));
921 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
923 "multi-BSS entry");
924 return -1;
925 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800926 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800928 bss = os_zalloc(sizeof(*bss));
929 if (bss == NULL)
930 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 bss->radius = os_zalloc(sizeof(*bss->radius));
932 if (bss->radius == NULL) {
933 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
934 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800935 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936 return -1;
937 }
938
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800939 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 conf->last_bss = bss;
941
942 hostapd_config_defaults_bss(bss);
943 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
944 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
945
946 return 0;
947}
948
949
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800950#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700951
952static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
953{
954 u8 oldkey[16];
955 int ret;
956
957 if (!hexstr2bin(pos, key, key_len))
958 return 0;
959
960 /* Try to use old short key for backwards compatibility */
961 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
962 return -1;
963
964 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
965 key, key_len);
966 os_memset(oldkey, 0, sizeof(oldkey));
967 return ret;
968}
969
970
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971static int add_r0kh(struct hostapd_bss_config *bss, char *value)
972{
973 struct ft_remote_r0kh *r0kh;
974 char *pos, *next;
975
976 r0kh = os_zalloc(sizeof(*r0kh));
977 if (r0kh == NULL)
978 return -1;
979
980 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
981 pos = value;
982 next = os_strchr(pos, ' ');
983 if (next)
984 *next++ = '\0';
985 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
986 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
987 os_free(r0kh);
988 return -1;
989 }
990
991 pos = next;
992 next = os_strchr(pos, ' ');
993 if (next)
994 *next++ = '\0';
995 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
996 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
997 os_free(r0kh);
998 return -1;
999 }
1000 r0kh->id_len = next - pos - 1;
1001 os_memcpy(r0kh->id, pos, r0kh->id_len);
1002
1003 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001004 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1006 os_free(r0kh);
1007 return -1;
1008 }
1009
1010 r0kh->next = bss->r0kh_list;
1011 bss->r0kh_list = r0kh;
1012
1013 return 0;
1014}
1015
1016
1017static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1018{
1019 struct ft_remote_r1kh *r1kh;
1020 char *pos, *next;
1021
1022 r1kh = os_zalloc(sizeof(*r1kh));
1023 if (r1kh == NULL)
1024 return -1;
1025
1026 /* 02:01:02:03:04:05 02:01:02:03:04:05
1027 * 000102030405060708090a0b0c0d0e0f */
1028 pos = value;
1029 next = os_strchr(pos, ' ');
1030 if (next)
1031 *next++ = '\0';
1032 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1033 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1034 os_free(r1kh);
1035 return -1;
1036 }
1037
1038 pos = next;
1039 next = os_strchr(pos, ' ');
1040 if (next)
1041 *next++ = '\0';
1042 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1043 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1044 os_free(r1kh);
1045 return -1;
1046 }
1047
1048 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001049 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1051 os_free(r1kh);
1052 return -1;
1053 }
1054
1055 r1kh->next = bss->r1kh_list;
1056 bss->r1kh_list = r1kh;
1057
1058 return 0;
1059}
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001060#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061
1062
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063static int hostapd_config_ht_capab(struct hostapd_config *conf,
1064 const char *capab)
1065{
1066 if (os_strstr(capab, "[LDPC]"))
1067 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1068 if (os_strstr(capab, "[HT40-]")) {
1069 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1070 conf->secondary_channel = -1;
1071 }
1072 if (os_strstr(capab, "[HT40+]")) {
1073 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1074 conf->secondary_channel = 1;
1075 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001076 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1077 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1078 conf->ht40_plus_minus_allowed = 1;
1079 }
Hai Shalomce48b4a2018-09-05 11:41:35 -07001080 if (!os_strstr(capab, "[HT40+]") && !os_strstr(capab, "[HT40-]"))
1081 conf->secondary_channel = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082 if (os_strstr(capab, "[GF]"))
1083 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1084 if (os_strstr(capab, "[SHORT-GI-20]"))
1085 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1086 if (os_strstr(capab, "[SHORT-GI-40]"))
1087 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1088 if (os_strstr(capab, "[TX-STBC]"))
1089 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1090 if (os_strstr(capab, "[RX-STBC1]")) {
1091 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1092 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1093 }
1094 if (os_strstr(capab, "[RX-STBC12]")) {
1095 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1096 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1097 }
1098 if (os_strstr(capab, "[RX-STBC123]")) {
1099 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1100 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1101 }
1102 if (os_strstr(capab, "[DELAYED-BA]"))
1103 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1104 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1105 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1106 if (os_strstr(capab, "[DSSS_CCK-40]"))
1107 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001108 if (os_strstr(capab, "[40-INTOLERANT]"))
1109 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1111 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1112
1113 return 0;
1114}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001115
1116
Dmitry Shmidt04949592012-07-19 12:16:46 -07001117#ifdef CONFIG_IEEE80211AC
1118static int hostapd_config_vht_capab(struct hostapd_config *conf,
1119 const char *capab)
1120{
1121 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1122 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1123 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1124 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1125 if (os_strstr(capab, "[VHT160]"))
1126 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1127 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1128 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001129 if (os_strstr(capab, "[RXLDPC]"))
1130 conf->vht_capab |= VHT_CAP_RXLDPC;
1131 if (os_strstr(capab, "[SHORT-GI-80]"))
1132 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1133 if (os_strstr(capab, "[SHORT-GI-160]"))
1134 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1135 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1136 conf->vht_capab |= VHT_CAP_TXSTBC;
1137 if (os_strstr(capab, "[RX-STBC-1]"))
1138 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1139 if (os_strstr(capab, "[RX-STBC-12]"))
1140 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1141 if (os_strstr(capab, "[RX-STBC-123]"))
1142 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1143 if (os_strstr(capab, "[RX-STBC-1234]"))
1144 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1145 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001146 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001147 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001148 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001149 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001150 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1151 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001152 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1153 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1154 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1155 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1156 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1157 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001158 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001159 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1160 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001161 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1162 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1163 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1164 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1165 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1166 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001167 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1168 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001169 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1170 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1171 if (os_strstr(capab, "[HTC-VHT]"))
1172 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001173 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1174 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1175 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1176 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1177 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1178 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1179 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1180 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1181 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1182 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1183 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1184 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1185 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1186 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001187 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1188 (conf->vht_capab & VHT_CAP_HTC_VHT))
1189 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1190 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1191 (conf->vht_capab & VHT_CAP_HTC_VHT))
1192 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1193 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1194 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1195 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1196 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1197 return 0;
1198}
1199#endif /* CONFIG_IEEE80211AC */
1200
1201
Hai Shalom74f70d42019-02-11 14:42:39 -08001202#ifdef CONFIG_IEEE80211AX
1203
1204static u8 find_bit_offset(u8 val)
1205{
1206 u8 res = 0;
1207
1208 for (; val; val >>= 1) {
1209 if (val & 1)
1210 break;
1211 res++;
1212 }
1213
1214 return res;
1215}
1216
1217
1218static u8 set_he_cap(int val, u8 mask)
1219{
1220 return (u8) (mask & (val << find_bit_offset(mask)));
1221}
1222
Hai Shalom60840252021-02-19 19:02:11 -08001223
1224static int hostapd_parse_he_srg_bitmap(u8 *bitmap, char *val)
1225{
1226 int bitpos;
1227 char *pos, *end;
1228
1229 os_memset(bitmap, 0, 8);
1230 pos = val;
1231 while (*pos != '\0') {
1232 end = os_strchr(pos, ' ');
1233 if (end)
1234 *end = '\0';
1235
1236 bitpos = atoi(pos);
1237 if (bitpos < 0 || bitpos > 64)
1238 return -1;
1239
1240 bitmap[bitpos / 8] |= BIT(bitpos % 8);
1241 if (!end)
1242 break;
1243 pos = end + 1;
1244 }
1245
1246 return 0;
1247}
1248
Hai Shalom74f70d42019-02-11 14:42:39 -08001249#endif /* CONFIG_IEEE80211AX */
1250
1251
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001252#ifdef CONFIG_INTERWORKING
1253static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1254 int line)
1255{
1256 size_t len = os_strlen(pos);
1257 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1258
1259 struct hostapd_roaming_consortium *rc;
1260
1261 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1262 hexstr2bin(pos, oi, len / 2)) {
1263 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1264 "'%s'", line, pos);
1265 return -1;
1266 }
1267 len /= 2;
1268
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001269 rc = os_realloc_array(bss->roaming_consortium,
1270 bss->roaming_consortium_count + 1,
1271 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001272 if (rc == NULL)
1273 return -1;
1274
1275 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1276 rc[bss->roaming_consortium_count].len = len;
1277
1278 bss->roaming_consortium = rc;
1279 bss->roaming_consortium_count++;
1280
1281 return 0;
1282}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001283
1284
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001285static int parse_lang_string(struct hostapd_lang_string **array,
1286 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001287{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001288 char *sep, *str = NULL;
1289 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001290 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001291 int ret = -1;
1292
1293 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1294 str = wpa_config_parse_string(pos, &slen);
1295 if (!str)
1296 return -1;
1297 pos = str;
1298 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001299
1300 sep = os_strchr(pos, ':');
1301 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001302 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001303 *sep++ = '\0';
1304
1305 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001306 if (clen < 2 || clen > sizeof(ls->lang))
1307 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001308 nlen = os_strlen(sep);
1309 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001310 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001311
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001312 ls = os_realloc_array(*array, *count + 1,
1313 sizeof(struct hostapd_lang_string));
1314 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001315 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001316
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001317 *array = ls;
1318 ls = &(*array)[*count];
1319 (*count)++;
1320
1321 os_memset(ls->lang, 0, sizeof(ls->lang));
1322 os_memcpy(ls->lang, pos, clen);
1323 ls->name_len = nlen;
1324 os_memcpy(ls->name, sep, nlen);
1325
Dmitry Shmidt56052862013-10-04 10:23:25 -07001326 ret = 0;
1327fail:
1328 os_free(str);
1329 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001330}
1331
1332
1333static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1334 int line)
1335{
1336 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1337 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1338 line, pos);
1339 return -1;
1340 }
1341 return 0;
1342}
1343
1344
Roshan Pius3a1667e2018-07-03 15:17:14 -07001345static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1346 int line)
1347{
1348 char *sep;
1349 size_t nlen;
1350 struct hostapd_venue_url *url;
1351 int ret = -1;
1352
1353 sep = os_strchr(pos, ':');
1354 if (!sep)
1355 goto fail;
1356 *sep++ = '\0';
1357
1358 nlen = os_strlen(sep);
1359 if (nlen > 254)
1360 goto fail;
1361
1362 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1363 sizeof(struct hostapd_venue_url));
1364 if (!url)
1365 goto fail;
1366
1367 bss->venue_url = url;
1368 url = &bss->venue_url[bss->venue_url_count++];
1369
1370 url->venue_number = atoi(pos);
1371 url->url_len = nlen;
1372 os_memcpy(url->url, sep, nlen);
1373
1374 ret = 0;
1375fail:
1376 if (ret)
1377 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1378 line, pos);
1379 return ret;
1380}
1381
1382
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001383static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1384 int line)
1385{
1386 size_t count;
1387 char *pos;
1388 u8 *info = NULL, *ipos;
1389
1390 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1391
1392 count = 1;
1393 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001394 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001395 goto fail;
1396 if (*pos == ';')
1397 count++;
1398 }
1399 if (1 + count * 3 > 0x7f)
1400 goto fail;
1401
1402 info = os_zalloc(2 + 3 + count * 3);
1403 if (info == NULL)
1404 return -1;
1405
1406 ipos = info;
1407 *ipos++ = 0; /* GUD - Version 1 */
1408 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1409 *ipos++ = 0; /* PLMN List IEI */
1410 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1411 *ipos++ = 1 + count * 3;
1412 *ipos++ = count; /* Number of PLMNs */
1413
1414 pos = buf;
1415 while (pos && *pos) {
1416 char *mcc, *mnc;
1417 size_t mnc_len;
1418
1419 mcc = pos;
1420 mnc = os_strchr(pos, ',');
1421 if (mnc == NULL)
1422 goto fail;
1423 *mnc++ = '\0';
1424 pos = os_strchr(mnc, ';');
1425 if (pos)
1426 *pos++ = '\0';
1427
1428 mnc_len = os_strlen(mnc);
1429 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1430 goto fail;
1431
1432 /* BC coded MCC,MNC */
1433 /* MCC digit 2 | MCC digit 1 */
1434 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1435 /* MNC digit 3 | MCC digit 3 */
1436 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1437 (mcc[2] - '0');
1438 /* MNC digit 2 | MNC digit 1 */
1439 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1440 }
1441
1442 os_free(bss->anqp_3gpp_cell_net);
1443 bss->anqp_3gpp_cell_net = info;
1444 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1445 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1446 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001447
1448 return 0;
1449
1450fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001451 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1452 line, buf);
1453 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001454 return -1;
1455}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001456
1457
1458static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1459{
1460 struct hostapd_nai_realm_data *realm;
1461 size_t i, j, len;
1462 int *offsets;
1463 char *pos, *end, *rpos;
1464
1465 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1466 sizeof(int));
1467 if (offsets == NULL)
1468 return -1;
1469
1470 for (i = 0; i < bss->nai_realm_count; i++) {
1471 realm = &bss->nai_realm_data[i];
1472 for (j = 0; j < MAX_NAI_REALMS; j++) {
1473 offsets[i * MAX_NAI_REALMS + j] =
1474 realm->realm[j] ?
1475 realm->realm[j] - realm->realm_buf : -1;
1476 }
1477 }
1478
1479 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1480 sizeof(struct hostapd_nai_realm_data));
1481 if (realm == NULL) {
1482 os_free(offsets);
1483 return -1;
1484 }
1485 bss->nai_realm_data = realm;
1486
1487 /* patch the pointers after realloc */
1488 for (i = 0; i < bss->nai_realm_count; i++) {
1489 realm = &bss->nai_realm_data[i];
1490 for (j = 0; j < MAX_NAI_REALMS; j++) {
1491 int offs = offsets[i * MAX_NAI_REALMS + j];
1492 if (offs >= 0)
1493 realm->realm[j] = realm->realm_buf + offs;
1494 else
1495 realm->realm[j] = NULL;
1496 }
1497 }
1498 os_free(offsets);
1499
1500 realm = &bss->nai_realm_data[bss->nai_realm_count];
1501 os_memset(realm, 0, sizeof(*realm));
1502
1503 pos = buf;
1504 realm->encoding = atoi(pos);
1505 pos = os_strchr(pos, ',');
1506 if (pos == NULL)
1507 goto fail;
1508 pos++;
1509
1510 end = os_strchr(pos, ',');
1511 if (end) {
1512 len = end - pos;
1513 *end = '\0';
1514 } else {
1515 len = os_strlen(pos);
1516 }
1517
1518 if (len > MAX_NAI_REALMLEN) {
1519 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1520 "characters)", (int) len, MAX_NAI_REALMLEN);
1521 goto fail;
1522 }
1523 os_memcpy(realm->realm_buf, pos, len);
1524
1525 if (end)
1526 pos = end + 1;
1527 else
1528 pos = NULL;
1529
1530 while (pos && *pos) {
1531 struct hostapd_nai_realm_eap *eap;
1532
1533 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1534 wpa_printf(MSG_ERROR, "Too many EAP methods");
1535 goto fail;
1536 }
1537
1538 eap = &realm->eap_method[realm->eap_method_count];
1539 realm->eap_method_count++;
1540
1541 end = os_strchr(pos, ',');
1542 if (end == NULL)
1543 end = pos + os_strlen(pos);
1544
1545 eap->eap_method = atoi(pos);
1546 for (;;) {
1547 pos = os_strchr(pos, '[');
1548 if (pos == NULL || pos > end)
1549 break;
1550 pos++;
1551 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1552 wpa_printf(MSG_ERROR, "Too many auth params");
1553 goto fail;
1554 }
1555 eap->auth_id[eap->num_auths] = atoi(pos);
1556 pos = os_strchr(pos, ':');
1557 if (pos == NULL || pos > end)
1558 goto fail;
1559 pos++;
1560 eap->auth_val[eap->num_auths] = atoi(pos);
1561 pos = os_strchr(pos, ']');
1562 if (pos == NULL || pos > end)
1563 goto fail;
1564 pos++;
1565 eap->num_auths++;
1566 }
1567
1568 if (*end != ',')
1569 break;
1570
1571 pos = end + 1;
1572 }
1573
1574 /* Split realm list into null terminated realms */
1575 rpos = realm->realm_buf;
1576 i = 0;
1577 while (*rpos) {
1578 if (i >= MAX_NAI_REALMS) {
1579 wpa_printf(MSG_ERROR, "Too many realms");
1580 goto fail;
1581 }
1582 realm->realm[i++] = rpos;
1583 rpos = os_strchr(rpos, ';');
1584 if (rpos == NULL)
1585 break;
1586 *rpos++ = '\0';
1587 }
1588
1589 bss->nai_realm_count++;
1590
1591 return 0;
1592
1593fail:
1594 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1595 return -1;
1596}
1597
Dmitry Shmidt051af732013-10-22 13:52:46 -07001598
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001599static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1600{
1601 char *delim;
1602 u16 infoid;
1603 size_t len;
1604 struct wpabuf *payload;
1605 struct anqp_element *elem;
1606
1607 delim = os_strchr(buf, ':');
1608 if (!delim)
1609 return -1;
1610 delim++;
1611 infoid = atoi(buf);
1612 len = os_strlen(delim);
1613 if (len & 1)
1614 return -1;
1615 len /= 2;
1616 payload = wpabuf_alloc(len);
1617 if (!payload)
1618 return -1;
1619 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1620 wpabuf_free(payload);
1621 return -1;
1622 }
1623
1624 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1625 if (elem->infoid == infoid) {
1626 /* Update existing entry */
1627 wpabuf_free(elem->payload);
1628 elem->payload = payload;
1629 return 0;
1630 }
1631 }
1632
1633 /* Add a new entry */
1634 elem = os_zalloc(sizeof(*elem));
1635 if (!elem) {
1636 wpabuf_free(payload);
1637 return -1;
1638 }
1639 elem->infoid = infoid;
1640 elem->payload = payload;
1641 dl_list_add(&bss->anqp_elem, &elem->list);
1642
1643 return 0;
1644}
1645
1646
Dmitry Shmidt051af732013-10-22 13:52:46 -07001647static int parse_qos_map_set(struct hostapd_bss_config *bss,
1648 char *buf, int line)
1649{
1650 u8 qos_map_set[16 + 2 * 21], count = 0;
1651 char *pos = buf;
1652 int val;
1653
1654 for (;;) {
1655 if (count == sizeof(qos_map_set)) {
1656 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1657 "parameters '%s'", line, buf);
1658 return -1;
1659 }
1660
1661 val = atoi(pos);
1662 if (val > 255 || val < 0) {
1663 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1664 "'%s'", line, buf);
1665 return -1;
1666 }
1667
1668 qos_map_set[count++] = val;
1669 pos = os_strchr(pos, ',');
1670 if (!pos)
1671 break;
1672 pos++;
1673 }
1674
1675 if (count < 16 || count & 1) {
1676 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1677 line, buf);
1678 return -1;
1679 }
1680
1681 os_memcpy(bss->qos_map_set, qos_map_set, count);
1682 bss->qos_map_set_len = count;
1683
1684 return 0;
1685}
1686
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001687#endif /* CONFIG_INTERWORKING */
1688
1689
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001690#ifdef CONFIG_HS20
1691static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1692 int line)
1693{
1694 u8 *conn_cap;
1695 char *pos;
1696
1697 if (bss->hs20_connection_capability_len >= 0xfff0)
1698 return -1;
1699
1700 conn_cap = os_realloc(bss->hs20_connection_capability,
1701 bss->hs20_connection_capability_len + 4);
1702 if (conn_cap == NULL)
1703 return -1;
1704
1705 bss->hs20_connection_capability = conn_cap;
1706 conn_cap += bss->hs20_connection_capability_len;
1707 pos = buf;
1708 conn_cap[0] = atoi(pos);
1709 pos = os_strchr(pos, ':');
1710 if (pos == NULL)
1711 return -1;
1712 pos++;
1713 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1714 pos = os_strchr(pos, ':');
1715 if (pos == NULL)
1716 return -1;
1717 pos++;
1718 conn_cap[3] = atoi(pos);
1719 bss->hs20_connection_capability_len += 4;
1720
1721 return 0;
1722}
1723
1724
1725static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1726 int line)
1727{
1728 u8 *wan_metrics;
1729 char *pos;
1730
1731 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1732
1733 wan_metrics = os_zalloc(13);
1734 if (wan_metrics == NULL)
1735 return -1;
1736
1737 pos = buf;
1738 /* WAN Info */
1739 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1740 goto fail;
1741 pos += 2;
1742 if (*pos != ':')
1743 goto fail;
1744 pos++;
1745
1746 /* Downlink Speed */
1747 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1748 pos = os_strchr(pos, ':');
1749 if (pos == NULL)
1750 goto fail;
1751 pos++;
1752
1753 /* Uplink Speed */
1754 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1755 pos = os_strchr(pos, ':');
1756 if (pos == NULL)
1757 goto fail;
1758 pos++;
1759
1760 /* Downlink Load */
1761 wan_metrics[9] = atoi(pos);
1762 pos = os_strchr(pos, ':');
1763 if (pos == NULL)
1764 goto fail;
1765 pos++;
1766
1767 /* Uplink Load */
1768 wan_metrics[10] = atoi(pos);
1769 pos = os_strchr(pos, ':');
1770 if (pos == NULL)
1771 goto fail;
1772 pos++;
1773
1774 /* LMD */
1775 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1776
1777 os_free(bss->hs20_wan_metrics);
1778 bss->hs20_wan_metrics = wan_metrics;
1779
1780 return 0;
1781
1782fail:
1783 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001784 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001785 os_free(wan_metrics);
1786 return -1;
1787}
1788
1789
1790static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1791 char *pos, int line)
1792{
1793 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1794 &bss->hs20_oper_friendly_name_count, pos)) {
1795 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1796 "hs20_oper_friendly_name '%s'", line, pos);
1797 return -1;
1798 }
1799 return 0;
1800}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001801
1802
1803static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1804{
1805 struct hs20_icon *icon;
1806 char *end;
1807
1808 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1809 sizeof(struct hs20_icon));
1810 if (icon == NULL)
1811 return -1;
1812 bss->hs20_icons = icon;
1813 icon = &bss->hs20_icons[bss->hs20_icons_count];
1814 os_memset(icon, 0, sizeof(*icon));
1815
1816 icon->width = atoi(pos);
1817 pos = os_strchr(pos, ':');
1818 if (pos == NULL)
1819 return -1;
1820 pos++;
1821
1822 icon->height = atoi(pos);
1823 pos = os_strchr(pos, ':');
1824 if (pos == NULL)
1825 return -1;
1826 pos++;
1827
1828 end = os_strchr(pos, ':');
1829 if (end == NULL || end - pos > 3)
1830 return -1;
1831 os_memcpy(icon->language, pos, end - pos);
1832 pos = end + 1;
1833
1834 end = os_strchr(pos, ':');
1835 if (end == NULL || end - pos > 255)
1836 return -1;
1837 os_memcpy(icon->type, pos, end - pos);
1838 pos = end + 1;
1839
1840 end = os_strchr(pos, ':');
1841 if (end == NULL || end - pos > 255)
1842 return -1;
1843 os_memcpy(icon->name, pos, end - pos);
1844 pos = end + 1;
1845
1846 if (os_strlen(pos) > 255)
1847 return -1;
1848 os_memcpy(icon->file, pos, os_strlen(pos));
1849
1850 bss->hs20_icons_count++;
1851
1852 return 0;
1853}
1854
1855
1856static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1857 char *pos, int line)
1858{
1859 size_t slen;
1860 char *str;
1861
1862 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001863 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001864 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001865 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001866 return -1;
1867 }
1868
1869 os_memcpy(bss->osu_ssid, str, slen);
1870 bss->osu_ssid_len = slen;
1871 os_free(str);
1872
1873 return 0;
1874}
1875
1876
1877static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1878 char *pos, int line)
1879{
1880 struct hs20_osu_provider *p;
1881
1882 p = os_realloc_array(bss->hs20_osu_providers,
1883 bss->hs20_osu_providers_count + 1, sizeof(*p));
1884 if (p == NULL)
1885 return -1;
1886
1887 bss->hs20_osu_providers = p;
1888 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1889 bss->hs20_osu_providers_count++;
1890 os_memset(bss->last_osu, 0, sizeof(*p));
1891 bss->last_osu->server_uri = os_strdup(pos);
1892
1893 return 0;
1894}
1895
1896
1897static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1898 char *pos, int line)
1899{
1900 if (bss->last_osu == NULL) {
1901 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1902 return -1;
1903 }
1904
1905 if (parse_lang_string(&bss->last_osu->friendly_name,
1906 &bss->last_osu->friendly_name_count, pos)) {
1907 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1908 line, pos);
1909 return -1;
1910 }
1911
1912 return 0;
1913}
1914
1915
1916static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1917 char *pos, int line)
1918{
1919 if (bss->last_osu == NULL) {
1920 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1921 return -1;
1922 }
1923
1924 os_free(bss->last_osu->osu_nai);
1925 bss->last_osu->osu_nai = os_strdup(pos);
1926 if (bss->last_osu->osu_nai == NULL)
1927 return -1;
1928
1929 return 0;
1930}
1931
1932
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001933static int hs20_parse_osu_nai2(struct hostapd_bss_config *bss,
1934 char *pos, int line)
1935{
1936 if (bss->last_osu == NULL) {
1937 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1938 return -1;
1939 }
1940
1941 os_free(bss->last_osu->osu_nai2);
1942 bss->last_osu->osu_nai2 = os_strdup(pos);
1943 if (bss->last_osu->osu_nai2 == NULL)
1944 return -1;
1945 bss->hs20_osu_providers_nai_count++;
1946
1947 return 0;
1948}
1949
1950
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001951static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1952 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 (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1960 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1961 return -1;
1962 }
1963
1964 return 0;
1965}
1966
1967
1968static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1969 int line)
1970{
1971 char **n;
1972 struct hs20_osu_provider *p = bss->last_osu;
1973
1974 if (p == NULL) {
1975 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1976 return -1;
1977 }
1978
1979 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1980 if (n == NULL)
1981 return -1;
1982 p->icons = n;
1983 p->icons[p->icons_count] = os_strdup(pos);
1984 if (p->icons[p->icons_count] == NULL)
1985 return -1;
1986 p->icons_count++;
1987
1988 return 0;
1989}
1990
1991
1992static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1993 char *pos, int line)
1994{
1995 if (bss->last_osu == NULL) {
1996 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1997 return -1;
1998 }
1999
2000 if (parse_lang_string(&bss->last_osu->service_desc,
2001 &bss->last_osu->service_desc_count, pos)) {
2002 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
2003 line, pos);
2004 return -1;
2005 }
2006
2007 return 0;
2008}
2009
Roshan Pius3a1667e2018-07-03 15:17:14 -07002010
2011static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
2012 int line)
2013{
2014 char **n;
2015
2016 n = os_realloc_array(bss->hs20_operator_icon,
2017 bss->hs20_operator_icon_count + 1, sizeof(char *));
2018 if (!n)
2019 return -1;
2020 bss->hs20_operator_icon = n;
2021 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
2022 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
2023 return -1;
2024 bss->hs20_operator_icon_count++;
2025
2026 return 0;
2027}
2028
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002029#endif /* CONFIG_HS20 */
2030
2031
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002032#ifdef CONFIG_ACS
2033static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
2034 char *pos)
2035{
2036 struct acs_bias *bias = NULL, *tmp;
2037 unsigned int num = 0;
2038 char *end;
2039
2040 while (*pos) {
2041 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2042 if (!tmp)
2043 goto fail;
2044 bias = tmp;
2045
2046 bias[num].channel = atoi(pos);
2047 if (bias[num].channel <= 0)
2048 goto fail;
2049 pos = os_strchr(pos, ':');
2050 if (!pos)
2051 goto fail;
2052 pos++;
2053 bias[num].bias = strtod(pos, &end);
2054 if (end == pos || bias[num].bias < 0.0)
2055 goto fail;
2056 pos = end;
2057 if (*pos != ' ' && *pos != '\0')
2058 goto fail;
2059 num++;
2060 }
2061
2062 os_free(conf->acs_chan_bias);
2063 conf->acs_chan_bias = bias;
2064 conf->num_acs_chan_bias = num;
2065
2066 return 0;
2067fail:
2068 os_free(bias);
2069 return -1;
2070}
2071#endif /* CONFIG_ACS */
2072
2073
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002074static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2075 const char *val)
2076{
2077 struct wpabuf *elems;
2078
2079 if (val[0] == '\0') {
2080 wpabuf_free(*buf);
2081 *buf = NULL;
2082 return 0;
2083 }
2084
2085 elems = wpabuf_parse_bin(val);
2086 if (!elems) {
2087 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2088 line, name, val);
2089 return -1;
2090 }
2091
2092 wpabuf_free(*buf);
2093 *buf = elems;
2094
2095 return 0;
2096}
2097
2098
Dmitry Shmidt29333592017-01-09 12:27:11 -08002099#ifdef CONFIG_FILS
2100static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2101{
2102 struct fils_realm *realm;
2103 size_t len;
2104
2105 len = os_strlen(val);
2106 realm = os_zalloc(sizeof(*realm) + len + 1);
2107 if (!realm)
2108 return -1;
2109
2110 os_memcpy(realm->realm, val, len);
2111 if (fils_domain_name_hash(val, realm->hash) < 0) {
2112 os_free(realm);
2113 return -1;
2114 }
2115 dl_list_add_tail(&bss->fils_realms, &realm->list);
2116
2117 return 0;
2118}
2119#endif /* CONFIG_FILS */
2120
2121
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002122#ifdef EAP_SERVER
2123static unsigned int parse_tls_flags(const char *val)
2124{
2125 unsigned int flags = 0;
2126
Roshan Pius3a1667e2018-07-03 15:17:14 -07002127 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2128 * This can be enabled by default once the implementation has been fully
2129 * completed and tested with other implementations. */
2130 flags |= TLS_CONN_DISABLE_TLSv1_3;
2131
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002132 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2133 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2134 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2135 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2136 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2137 flags |= TLS_CONN_DISABLE_TLSv1_0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002138 if (os_strstr(val, "[ENABLE-TLSv1.0]"))
2139 flags |= TLS_CONN_ENABLE_TLSv1_0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002140 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2141 flags |= TLS_CONN_DISABLE_TLSv1_1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002142 if (os_strstr(val, "[ENABLE-TLSv1.1]"))
2143 flags |= TLS_CONN_ENABLE_TLSv1_1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002144 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2145 flags |= TLS_CONN_DISABLE_TLSv1_2;
Hai Shalom74f70d42019-02-11 14:42:39 -08002146 if (os_strstr(val, "[ENABLE-TLSv1.2]"))
2147 flags |= TLS_CONN_ENABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002148 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2149 flags |= TLS_CONN_DISABLE_TLSv1_3;
2150 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2151 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002152 if (os_strstr(val, "[SUITEB]"))
2153 flags |= TLS_CONN_SUITEB;
2154 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2155 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2156
2157 return flags;
2158}
2159#endif /* EAP_SERVER */
2160
2161
Hai Shalom81f62d82019-07-22 12:10:00 -07002162#ifdef CONFIG_AIRTIME_POLICY
2163static int add_airtime_weight(struct hostapd_bss_config *bss, char *value)
2164{
2165 struct airtime_sta_weight *wt;
2166 char *pos, *next;
2167
2168 wt = os_zalloc(sizeof(*wt));
2169 if (!wt)
2170 return -1;
2171
2172 /* 02:01:02:03:04:05 10 */
2173 pos = value;
2174 next = os_strchr(pos, ' ');
2175 if (next)
2176 *next++ = '\0';
2177 if (!next || hwaddr_aton(pos, wt->addr)) {
2178 wpa_printf(MSG_ERROR, "Invalid station address: '%s'", pos);
2179 os_free(wt);
2180 return -1;
2181 }
2182
2183 pos = next;
2184 wt->weight = atoi(pos);
2185 if (!wt->weight) {
2186 wpa_printf(MSG_ERROR, "Invalid weight: '%s'", pos);
2187 os_free(wt);
2188 return -1;
2189 }
2190
2191 wt->next = bss->airtime_weight_list;
2192 bss->airtime_weight_list = wt;
2193 return 0;
2194}
2195#endif /* CONFIG_AIRTIME_POLICY */
2196
2197
Roshan Pius3a1667e2018-07-03 15:17:14 -07002198#ifdef CONFIG_SAE
2199static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2200{
2201 struct sae_password_entry *pw;
2202 const char *pos = val, *pos2, *end = NULL;
2203
2204 pw = os_zalloc(sizeof(*pw));
2205 if (!pw)
2206 return -1;
2207 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2208
2209 pos2 = os_strstr(pos, "|mac=");
2210 if (pos2) {
2211 end = pos2;
2212 pos2 += 5;
2213 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2214 goto fail;
2215 pos = pos2 + ETH_ALEN * 3 - 1;
2216 }
2217
Hai Shalom021b0b52019-04-10 11:17:58 -07002218 pos2 = os_strstr(pos, "|vlanid=");
2219 if (pos2) {
2220 if (!end)
2221 end = pos2;
2222 pos2 += 8;
2223 pw->vlan_id = atoi(pos2);
2224 }
2225
Hai Shalom899fcc72020-10-19 14:38:18 -07002226#ifdef CONFIG_SAE_PK
2227 pos2 = os_strstr(pos, "|pk=");
2228 if (pos2) {
2229 const char *epos;
2230 char *tmp;
2231
2232 if (!end)
2233 end = pos2;
2234 pos2 += 4;
2235 epos = os_strchr(pos2, '|');
2236 if (epos) {
2237 tmp = os_malloc(epos - pos2 + 1);
2238 if (!tmp)
2239 goto fail;
2240 os_memcpy(tmp, pos2, epos - pos2);
2241 tmp[epos - pos2] = '\0';
2242 } else {
2243 tmp = os_strdup(pos2);
2244 if (!tmp)
2245 goto fail;
2246 }
2247
2248 pw->pk = sae_parse_pk(tmp);
2249 str_clear_free(tmp);
2250 if (!pw->pk)
2251 goto fail;
2252 }
2253#endif /* CONFIG_SAE_PK */
2254
Roshan Pius3a1667e2018-07-03 15:17:14 -07002255 pos2 = os_strstr(pos, "|id=");
2256 if (pos2) {
2257 if (!end)
2258 end = pos2;
2259 pos2 += 4;
2260 pw->identifier = os_strdup(pos2);
2261 if (!pw->identifier)
2262 goto fail;
2263 }
2264
2265 if (!end) {
2266 pw->password = os_strdup(val);
2267 if (!pw->password)
2268 goto fail;
2269 } else {
2270 pw->password = os_malloc(end - val + 1);
2271 if (!pw->password)
2272 goto fail;
2273 os_memcpy(pw->password, val, end - val);
2274 pw->password[end - val] = '\0';
2275 }
2276
Hai Shalom899fcc72020-10-19 14:38:18 -07002277#ifdef CONFIG_SAE_PK
2278 if (pw->pk &&
2279#ifdef CONFIG_TESTING_OPTIONS
2280 !bss->sae_pk_password_check_skip &&
2281#endif /* CONFIG_TESTING_OPTIONS */
2282 !sae_pk_valid_password(pw->password)) {
2283 wpa_printf(MSG_INFO,
2284 "Invalid SAE password for a SAE-PK sae_password entry");
2285 goto fail;
2286 }
2287#endif /* CONFIG_SAE_PK */
2288
Roshan Pius3a1667e2018-07-03 15:17:14 -07002289 pw->next = bss->sae_passwords;
2290 bss->sae_passwords = pw;
2291
2292 return 0;
2293fail:
2294 str_clear_free(pw->password);
2295 os_free(pw->identifier);
Hai Shalom899fcc72020-10-19 14:38:18 -07002296#ifdef CONFIG_SAE_PK
2297 sae_deinit_pk(pw->pk);
2298#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002299 os_free(pw);
2300 return -1;
2301}
2302#endif /* CONFIG_SAE */
2303
2304
Hai Shalom81f62d82019-07-22 12:10:00 -07002305#ifdef CONFIG_DPP2
2306static int hostapd_dpp_controller_parse(struct hostapd_bss_config *bss,
2307 const char *pos)
2308{
2309 struct dpp_controller_conf *conf;
2310 char *val;
2311
2312 conf = os_zalloc(sizeof(*conf));
2313 if (!conf)
2314 return -1;
2315 val = get_param(pos, "ipaddr=");
2316 if (!val || hostapd_parse_ip_addr(val, &conf->ipaddr))
2317 goto fail;
2318 os_free(val);
2319 val = get_param(pos, "pkhash=");
2320 if (!val || os_strlen(val) != 2 * SHA256_MAC_LEN ||
2321 hexstr2bin(val, conf->pkhash, SHA256_MAC_LEN) < 0)
2322 goto fail;
2323 os_free(val);
2324 conf->next = bss->dpp_controller;
2325 bss->dpp_controller = conf;
2326 return 0;
2327fail:
2328 os_free(val);
2329 os_free(conf);
2330 return -1;
2331}
2332#endif /* CONFIG_DPP2 */
2333
2334
Dmitry Shmidt04949592012-07-19 12:16:46 -07002335static int hostapd_config_fill(struct hostapd_config *conf,
2336 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002337 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002338{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002339 if (os_strcmp(buf, "interface") == 0) {
2340 os_strlcpy(conf->bss[0]->iface, pos,
2341 sizeof(conf->bss[0]->iface));
2342 } else if (os_strcmp(buf, "bridge") == 0) {
2343 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2344 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2345 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2346 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2347 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2348 } else if (os_strcmp(buf, "driver") == 0) {
2349 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002350 const struct wpa_driver_ops *driver = NULL;
2351
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002352 for (j = 0; wpa_drivers[j]; j++) {
2353 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002354 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002355 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002357 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002358 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002359 wpa_printf(MSG_ERROR,
2360 "Line %d: invalid/unknown driver '%s'",
2361 line, pos);
2362 return 1;
2363 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002364 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002365 } else if (os_strcmp(buf, "driver_params") == 0) {
2366 os_free(conf->driver_params);
2367 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002368 } else if (os_strcmp(buf, "debug") == 0) {
2369 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2370 line);
2371 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2372 bss->logger_syslog_level = atoi(pos);
2373 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2374 bss->logger_stdout_level = atoi(pos);
2375 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2376 bss->logger_syslog = atoi(pos);
2377 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2378 bss->logger_stdout = atoi(pos);
2379 } else if (os_strcmp(buf, "dump_file") == 0) {
2380 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2381 line);
2382 } else if (os_strcmp(buf, "ssid") == 0) {
2383 bss->ssid.ssid_len = os_strlen(pos);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002384 if (bss->ssid.ssid_len > SSID_MAX_LEN ||
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002385 bss->ssid.ssid_len < 1) {
2386 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2387 line, pos);
2388 return 1;
2389 }
2390 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
2391 bss->ssid.ssid_set = 1;
2392 } else if (os_strcmp(buf, "ssid2") == 0) {
2393 size_t slen;
2394 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002395 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002396 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2397 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002398 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002399 return 1;
2400 }
2401 os_memcpy(bss->ssid.ssid, str, slen);
2402 bss->ssid.ssid_len = slen;
2403 bss->ssid.ssid_set = 1;
2404 os_free(str);
2405 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2406 bss->ssid.utf8_ssid = atoi(pos) > 0;
2407 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002408 enum macaddr_acl acl = atoi(pos);
2409
2410 if (acl != ACCEPT_UNLESS_DENIED &&
2411 acl != DENY_UNLESS_ACCEPTED &&
2412 acl != USE_EXTERNAL_RADIUS_AUTH) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002413 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002414 line, acl);
2415 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002416 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002417 bss->macaddr_acl = acl;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002418 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2419 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2420 &bss->num_accept_mac)) {
2421 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2422 line, pos);
2423 return 1;
2424 }
2425 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2426 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2427 &bss->num_deny_mac)) {
2428 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2429 line, pos);
2430 return 1;
2431 }
2432 } else if (os_strcmp(buf, "wds_sta") == 0) {
2433 bss->wds_sta = atoi(pos);
2434 } else if (os_strcmp(buf, "start_disabled") == 0) {
2435 bss->start_disabled = atoi(pos);
2436 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2437 bss->isolate = atoi(pos);
2438 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2439 bss->ap_max_inactivity = atoi(pos);
2440 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2441 bss->skip_inactivity_poll = atoi(pos);
2442 } else if (os_strcmp(buf, "country_code") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002443 if (pos[0] < 'A' || pos[0] > 'Z' ||
2444 pos[1] < 'A' || pos[1] > 'Z') {
2445 wpa_printf(MSG_ERROR,
2446 "Line %d: Invalid country_code '%s'",
2447 line, pos);
2448 return 1;
2449 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002450 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002451 } else if (os_strcmp(buf, "country3") == 0) {
2452 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002453 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2454 conf->ieee80211d = atoi(pos);
2455 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2456 conf->ieee80211h = atoi(pos);
2457 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2458 bss->ieee802_1x = atoi(pos);
2459 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002460 int eapol_version = atoi(pos);
2461
Hai Shalom81f62d82019-07-22 12:10:00 -07002462#ifdef CONFIG_MACSEC
2463 if (eapol_version < 1 || eapol_version > 3) {
2464#else /* CONFIG_MACSEC */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002465 if (eapol_version < 1 || eapol_version > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002466#endif /* CONFIG_MACSEC */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002467 wpa_printf(MSG_ERROR,
2468 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002469 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002470 return 1;
2471 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002472 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002473 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002474#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002475 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2476 bss->eap_server = atoi(pos);
2477 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2478 } else if (os_strcmp(buf, "eap_server") == 0) {
2479 bss->eap_server = atoi(pos);
2480 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2481 if (hostapd_config_read_eap_user(pos, bss))
2482 return 1;
2483 } else if (os_strcmp(buf, "ca_cert") == 0) {
2484 os_free(bss->ca_cert);
2485 bss->ca_cert = os_strdup(pos);
2486 } else if (os_strcmp(buf, "server_cert") == 0) {
2487 os_free(bss->server_cert);
2488 bss->server_cert = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002489 } else if (os_strcmp(buf, "server_cert2") == 0) {
2490 os_free(bss->server_cert2);
2491 bss->server_cert2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002492 } else if (os_strcmp(buf, "private_key") == 0) {
2493 os_free(bss->private_key);
2494 bss->private_key = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002495 } else if (os_strcmp(buf, "private_key2") == 0) {
2496 os_free(bss->private_key2);
2497 bss->private_key2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002498 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2499 os_free(bss->private_key_passwd);
2500 bss->private_key_passwd = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002501 } else if (os_strcmp(buf, "private_key_passwd2") == 0) {
2502 os_free(bss->private_key_passwd2);
2503 bss->private_key_passwd2 = os_strdup(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07002504 } else if (os_strcmp(buf, "check_cert_subject") == 0) {
2505 if (!pos[0]) {
2506 wpa_printf(MSG_ERROR, "Line %d: unknown check_cert_subject '%s'",
2507 line, pos);
2508 return 1;
2509 }
2510 os_free(bss->check_cert_subject);
2511 bss->check_cert_subject = os_strdup(pos);
2512 if (!bss->check_cert_subject)
2513 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002514 } else if (os_strcmp(buf, "check_crl") == 0) {
2515 bss->check_crl = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002516 } else if (os_strcmp(buf, "check_crl_strict") == 0) {
2517 bss->check_crl_strict = atoi(pos);
2518 } else if (os_strcmp(buf, "crl_reload_interval") == 0) {
2519 bss->crl_reload_interval = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002520 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2521 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002522 } else if (os_strcmp(buf, "tls_flags") == 0) {
2523 bss->tls_flags = parse_tls_flags(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002524 } else if (os_strcmp(buf, "max_auth_rounds") == 0) {
2525 bss->max_auth_rounds = atoi(pos);
2526 } else if (os_strcmp(buf, "max_auth_rounds_short") == 0) {
2527 bss->max_auth_rounds_short = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002528 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2529 os_free(bss->ocsp_stapling_response);
2530 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002531 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2532 os_free(bss->ocsp_stapling_response_multi);
2533 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002534 } else if (os_strcmp(buf, "dh_file") == 0) {
2535 os_free(bss->dh_file);
2536 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002537 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2538 os_free(bss->openssl_ciphers);
2539 bss->openssl_ciphers = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002540 } else if (os_strcmp(buf, "openssl_ecdh_curves") == 0) {
2541 os_free(bss->openssl_ecdh_curves);
2542 bss->openssl_ecdh_curves = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002543 } else if (os_strcmp(buf, "fragment_size") == 0) {
2544 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002546 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2547 os_free(bss->pac_opaque_encr_key);
2548 bss->pac_opaque_encr_key = os_malloc(16);
2549 if (bss->pac_opaque_encr_key == NULL) {
2550 wpa_printf(MSG_ERROR,
2551 "Line %d: No memory for pac_opaque_encr_key",
2552 line);
2553 return 1;
2554 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2555 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2556 line);
2557 return 1;
2558 }
2559 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2560 size_t idlen = os_strlen(pos);
2561 if (idlen & 1) {
2562 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2563 line);
2564 return 1;
2565 }
2566 os_free(bss->eap_fast_a_id);
2567 bss->eap_fast_a_id = os_malloc(idlen / 2);
2568 if (bss->eap_fast_a_id == NULL ||
2569 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2570 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2571 line);
2572 os_free(bss->eap_fast_a_id);
2573 bss->eap_fast_a_id = NULL;
2574 return 1;
2575 } else {
2576 bss->eap_fast_a_id_len = idlen / 2;
2577 }
2578 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2579 os_free(bss->eap_fast_a_id_info);
2580 bss->eap_fast_a_id_info = os_strdup(pos);
2581 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2582 bss->eap_fast_prov = atoi(pos);
2583 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2584 bss->pac_key_lifetime = atoi(pos);
2585 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2586 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002587#endif /* EAP_SERVER_FAST */
Hai Shalom81f62d82019-07-22 12:10:00 -07002588#ifdef EAP_SERVER_TEAP
2589 } else if (os_strcmp(buf, "eap_teap_auth") == 0) {
2590 int val = atoi(pos);
2591
Hai Shalom899fcc72020-10-19 14:38:18 -07002592 if (val < 0 || val > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002593 wpa_printf(MSG_ERROR,
2594 "Line %d: Invalid eap_teap_auth value",
2595 line);
2596 return 1;
2597 }
2598 bss->eap_teap_auth = val;
2599 } else if (os_strcmp(buf, "eap_teap_pac_no_inner") == 0) {
2600 bss->eap_teap_pac_no_inner = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002601 } else if (os_strcmp(buf, "eap_teap_separate_result") == 0) {
2602 bss->eap_teap_separate_result = atoi(pos);
2603 } else if (os_strcmp(buf, "eap_teap_id") == 0) {
2604 bss->eap_teap_id = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002605#endif /* EAP_SERVER_TEAP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002606#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002607 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2608 os_free(bss->eap_sim_db);
2609 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002610 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2611 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002612 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2613 bss->eap_sim_aka_result_ind = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002614 } else if (os_strcmp(buf, "eap_sim_id") == 0) {
2615 bss->eap_sim_id = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002616#endif /* EAP_SERVER_SIM */
2617#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002618 } else if (os_strcmp(buf, "tnc") == 0) {
2619 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002620#endif /* EAP_SERVER_TNC */
2621#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002622 } else if (os_strcmp(buf, "pwd_group") == 0) {
2623 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002624#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002625#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002626 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2627 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002628#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002630 } else if (os_strcmp(buf, "eap_message") == 0) {
2631 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002632 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002633 bss->eap_req_id_text = os_strdup(pos);
2634 if (bss->eap_req_id_text == NULL) {
2635 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2636 line);
2637 return 1;
2638 }
2639 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2640 term = os_strstr(bss->eap_req_id_text, "\\0");
2641 if (term) {
2642 *term++ = '\0';
2643 os_memmove(term, term + 1,
2644 bss->eap_req_id_text_len -
2645 (term - bss->eap_req_id_text) - 1);
2646 bss->eap_req_id_text_len--;
2647 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002648 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2649 bss->erp_send_reauth_start = atoi(pos);
2650 } else if (os_strcmp(buf, "erp_domain") == 0) {
2651 os_free(bss->erp_domain);
2652 bss->erp_domain = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002653#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002654 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002655 int val = atoi(pos);
2656
2657 if (val < 0 || val > 13) {
2658 wpa_printf(MSG_ERROR,
2659 "Line %d: invalid WEP key len %d (= %d bits)",
2660 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002661 return 1;
2662 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002663 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002664 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002665 int val = atoi(pos);
2666
2667 if (val < 0 || val > 13) {
2668 wpa_printf(MSG_ERROR,
2669 "Line %d: invalid WEP key len %d (= %d bits)",
2670 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002671 return 1;
2672 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002673 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002674 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2675 bss->wep_rekeying_period = atoi(pos);
2676 if (bss->wep_rekeying_period < 0) {
2677 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2678 line, bss->wep_rekeying_period);
2679 return 1;
2680 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002681#endif /* CONFIG_WEP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002682 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2683 bss->eap_reauth_period = atoi(pos);
2684 if (bss->eap_reauth_period < 0) {
2685 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2686 line, bss->eap_reauth_period);
2687 return 1;
2688 }
2689 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2690 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002692 } else if (os_strcmp(buf, "iapp_interface") == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07002693 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002695 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2696 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2697 wpa_printf(MSG_ERROR,
2698 "Line %d: invalid IP address '%s'",
2699 line, pos);
2700 return 1;
2701 }
2702 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002703 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002704 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002705#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002706 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2707 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2708 wpa_printf(MSG_ERROR,
2709 "Line %d: invalid IP address '%s'",
2710 line, pos);
2711 return 1;
2712 }
2713 bss->radius->force_client_addr = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002714 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2715 if (hostapd_config_read_radius_addr(
2716 &bss->radius->auth_servers,
2717 &bss->radius->num_auth_servers, pos, 1812,
2718 &bss->radius->auth_server)) {
2719 wpa_printf(MSG_ERROR,
2720 "Line %d: invalid IP address '%s'",
2721 line, pos);
2722 return 1;
2723 }
2724 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002725 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2726 if (hostapd_parse_ip_addr(pos,
2727 &bss->radius->auth_server->addr)) {
2728 wpa_printf(MSG_ERROR,
2729 "Line %d: invalid IP address '%s'",
2730 line, pos);
2731 return 1;
2732 }
2733 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002734 os_strcmp(buf, "auth_server_port") == 0) {
2735 bss->radius->auth_server->port = atoi(pos);
2736 } else if (bss->radius->auth_server &&
2737 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2738 int len = os_strlen(pos);
2739 if (len == 0) {
2740 /* RFC 2865, Ch. 3 */
2741 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2742 line);
2743 return 1;
2744 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002745 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002746 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2747 bss->radius->auth_server->shared_secret_len = len;
2748 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2749 if (hostapd_config_read_radius_addr(
2750 &bss->radius->acct_servers,
2751 &bss->radius->num_acct_servers, pos, 1813,
2752 &bss->radius->acct_server)) {
2753 wpa_printf(MSG_ERROR,
2754 "Line %d: invalid IP address '%s'",
2755 line, pos);
2756 return 1;
2757 }
2758 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002759 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2760 if (hostapd_parse_ip_addr(pos,
2761 &bss->radius->acct_server->addr)) {
2762 wpa_printf(MSG_ERROR,
2763 "Line %d: invalid IP address '%s'",
2764 line, pos);
2765 return 1;
2766 }
2767 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002768 os_strcmp(buf, "acct_server_port") == 0) {
2769 bss->radius->acct_server->port = atoi(pos);
2770 } else if (bss->radius->acct_server &&
2771 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2772 int len = os_strlen(pos);
2773 if (len == 0) {
2774 /* RFC 2865, Ch. 3 */
2775 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2776 line);
2777 return 1;
2778 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002779 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002780 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2781 bss->radius->acct_server->shared_secret_len = len;
2782 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2783 bss->radius->retry_primary_interval = atoi(pos);
2784 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2785 bss->acct_interim_interval = atoi(pos);
2786 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2787 bss->radius_request_cui = atoi(pos);
2788 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2789 struct hostapd_radius_attr *attr, *a;
2790 attr = hostapd_parse_radius_attr(pos);
2791 if (attr == NULL) {
2792 wpa_printf(MSG_ERROR,
2793 "Line %d: invalid radius_auth_req_attr",
2794 line);
2795 return 1;
2796 } else if (bss->radius_auth_req_attr == NULL) {
2797 bss->radius_auth_req_attr = attr;
2798 } else {
2799 a = bss->radius_auth_req_attr;
2800 while (a->next)
2801 a = a->next;
2802 a->next = attr;
2803 }
2804 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2805 struct hostapd_radius_attr *attr, *a;
2806 attr = hostapd_parse_radius_attr(pos);
2807 if (attr == NULL) {
2808 wpa_printf(MSG_ERROR,
2809 "Line %d: invalid radius_acct_req_attr",
2810 line);
2811 return 1;
2812 } else if (bss->radius_acct_req_attr == NULL) {
2813 bss->radius_acct_req_attr = attr;
2814 } else {
2815 a = bss->radius_acct_req_attr;
2816 while (a->next)
2817 a = a->next;
2818 a->next = attr;
2819 }
Hai Shalomc3565922019-10-28 11:58:20 -07002820 } else if (os_strcmp(buf, "radius_req_attr_sqlite") == 0) {
2821 os_free(bss->radius_req_attr_sqlite);
2822 bss->radius_req_attr_sqlite = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002823 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2824 bss->radius_das_port = atoi(pos);
2825 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2826 if (hostapd_parse_das_client(bss, pos) < 0) {
2827 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2828 line);
2829 return 1;
2830 }
2831 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2832 bss->radius_das_time_window = atoi(pos);
2833 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2834 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002835 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2836 0) {
2837 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002838#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002839 } else if (os_strcmp(buf, "auth_algs") == 0) {
2840 bss->auth_algs = atoi(pos);
2841 if (bss->auth_algs == 0) {
2842 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2843 line);
2844 return 1;
2845 }
2846 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2847 bss->max_num_sta = atoi(pos);
2848 if (bss->max_num_sta < 0 ||
2849 bss->max_num_sta > MAX_STA_COUNT) {
2850 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2851 line, bss->max_num_sta, MAX_STA_COUNT);
2852 return 1;
2853 }
2854 } else if (os_strcmp(buf, "wpa") == 0) {
2855 bss->wpa = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002856 } else if (os_strcmp(buf, "extended_key_id") == 0) {
2857 int val = atoi(pos);
2858
2859 if (val < 0 || val > 2) {
2860 wpa_printf(MSG_ERROR,
2861 "Line %d: Invalid extended_key_id=%d; allowed range 0..2",
2862 line, val);
2863 return 1;
2864 }
2865 bss->extended_key_id = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002866 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2867 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002868 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002869 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2870 bss->wpa_strict_rekey = atoi(pos);
2871 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2872 bss->wpa_gmk_rekey = atoi(pos);
2873 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2874 bss->wpa_ptk_rekey = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002875 } else if (os_strcmp(buf, "wpa_deny_ptk0_rekey") == 0) {
2876 bss->wpa_deny_ptk0_rekey = atoi(pos);
2877 if (bss->wpa_deny_ptk0_rekey < 0 ||
2878 bss->wpa_deny_ptk0_rekey > 2) {
2879 wpa_printf(MSG_ERROR,
2880 "Line %d: Invalid wpa_deny_ptk0_rekey=%d; allowed range 0..2",
2881 line, bss->wpa_deny_ptk0_rekey);
2882 return 1;
2883 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002884 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2885 char *endp;
2886 unsigned long val = strtoul(pos, &endp, 0);
2887
2888 if (*endp || val < 1 || val > (u32) -1) {
2889 wpa_printf(MSG_ERROR,
2890 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2891 line, val);
2892 return 1;
2893 }
2894 bss->wpa_group_update_count = (u32) val;
2895 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2896 char *endp;
2897 unsigned long val = strtoul(pos, &endp, 0);
2898
2899 if (*endp || val < 1 || val > (u32) -1) {
2900 wpa_printf(MSG_ERROR,
2901 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2902 line, val);
2903 return 1;
2904 }
2905 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002906 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2907 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002908 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2909 int len = os_strlen(pos);
2910 if (len < 8 || len > 63) {
2911 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2912 line, len);
2913 return 1;
2914 }
2915 os_free(bss->ssid.wpa_passphrase);
2916 bss->ssid.wpa_passphrase = os_strdup(pos);
2917 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002918 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002919 bss->ssid.wpa_passphrase_set = 1;
2920 }
2921 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002922 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002923 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2924 if (bss->ssid.wpa_psk == NULL)
2925 return 1;
2926 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2927 pos[PMK_LEN * 2] != '\0') {
2928 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2929 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002930 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002931 return 1;
2932 }
2933 bss->ssid.wpa_psk->group = 1;
2934 os_free(bss->ssid.wpa_passphrase);
2935 bss->ssid.wpa_passphrase = NULL;
2936 bss->ssid.wpa_psk_set = 1;
2937 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2938 os_free(bss->ssid.wpa_psk_file);
2939 bss->ssid.wpa_psk_file = os_strdup(pos);
2940 if (!bss->ssid.wpa_psk_file) {
2941 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2942 line);
2943 return 1;
2944 }
2945 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2946 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2947 if (bss->wpa_key_mgmt == -1)
2948 return 1;
2949 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2950 bss->wpa_psk_radius = atoi(pos);
2951 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2952 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2953 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2954 wpa_printf(MSG_ERROR,
2955 "Line %d: unknown wpa_psk_radius %d",
2956 line, bss->wpa_psk_radius);
2957 return 1;
2958 }
2959 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2960 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2961 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2962 return 1;
2963 if (bss->wpa_pairwise &
2964 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2965 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002966 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002967 return 1;
2968 }
2969 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2970 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2971 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2972 return 1;
2973 if (bss->rsn_pairwise &
2974 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2975 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002976 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002977 return 1;
2978 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002979 } else if (os_strcmp(buf, "group_cipher") == 0) {
2980 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2981 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2982 return 1;
2983 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2984 bss->group_cipher != WPA_CIPHER_CCMP &&
2985 bss->group_cipher != WPA_CIPHER_GCMP &&
2986 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2987 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2988 wpa_printf(MSG_ERROR,
2989 "Line %d: unsupported group cipher suite '%s'",
2990 line, pos);
2991 return 1;
2992 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002994 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2995 bss->rsn_preauth = atoi(pos);
2996 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002997 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002998 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002999#endif /* CONFIG_RSN_PREAUTH */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003000 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003001 wpa_printf(MSG_INFO,
3002 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003003#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003004 } else if (os_strcmp(buf, "mobility_domain") == 0) {
3005 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
3006 hexstr2bin(pos, bss->mobility_domain,
3007 MOBILITY_DOMAIN_ID_LEN) != 0) {
3008 wpa_printf(MSG_ERROR,
3009 "Line %d: Invalid mobility_domain '%s'",
3010 line, pos);
3011 return 1;
3012 }
3013 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
3014 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
3015 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
3016 wpa_printf(MSG_ERROR,
3017 "Line %d: Invalid r1_key_holder '%s'",
3018 line, pos);
3019 return 1;
3020 }
3021 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003022 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
3023 bss->r0_key_lifetime = atoi(pos) * 60;
3024 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003025 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003026 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
3027 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003028 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
3029 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003030 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
3031 bss->rkh_pos_timeout = atoi(pos);
3032 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
3033 bss->rkh_neg_timeout = atoi(pos);
3034 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
3035 bss->rkh_pull_timeout = atoi(pos);
3036 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
3037 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003038 } else if (os_strcmp(buf, "r0kh") == 0) {
3039 if (add_r0kh(bss, pos) < 0) {
3040 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
3041 line, pos);
3042 return 1;
3043 }
3044 } else if (os_strcmp(buf, "r1kh") == 0) {
3045 if (add_r1kh(bss, pos) < 0) {
3046 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
3047 line, pos);
3048 return 1;
3049 }
3050 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
3051 bss->pmk_r1_push = atoi(pos);
3052 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
3053 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003054 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
3055 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003056#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003057#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003058 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
3059 os_free(bss->ctrl_interface);
3060 bss->ctrl_interface = os_strdup(pos);
3061 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003062#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003063 struct group *grp;
3064 char *endp;
3065 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003067 grp = getgrnam(group);
3068 if (grp) {
3069 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003071 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
3072 bss->ctrl_interface_gid, group);
3073 return 0;
3074 }
3075
3076 /* Group name not found - try to parse this as gid */
3077 bss->ctrl_interface_gid = strtol(group, &endp, 10);
3078 if (*group == '\0' || *endp != '\0') {
3079 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
3080 line, group);
3081 return 1;
3082 }
3083 bss->ctrl_interface_gid_set = 1;
3084 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
3085 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003086#endif /* CONFIG_NATIVE_WINDOWS */
3087#endif /* CONFIG_NO_CTRL_IFACE */
3088#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003089 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
3090 os_free(bss->radius_server_clients);
3091 bss->radius_server_clients = os_strdup(pos);
3092 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
3093 bss->radius_server_auth_port = atoi(pos);
3094 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
3095 bss->radius_server_acct_port = atoi(pos);
3096 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
3097 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003098#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003099 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
3100 bss->use_pae_group_addr = atoi(pos);
3101 } else if (os_strcmp(buf, "hw_mode") == 0) {
3102 if (os_strcmp(pos, "a") == 0)
3103 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
3104 else if (os_strcmp(pos, "b") == 0)
3105 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
3106 else if (os_strcmp(pos, "g") == 0)
3107 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
3108 else if (os_strcmp(pos, "ad") == 0)
3109 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003110 else if (os_strcmp(pos, "any") == 0)
3111 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003112 else {
3113 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3114 line, pos);
3115 return 1;
3116 }
3117 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003118 if (os_strcmp(pos, "ad") == 0)
3119 bss->wps_rf_bands = WPS_RF_60GHZ;
3120 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003121 bss->wps_rf_bands = WPS_RF_50GHZ;
3122 else if (os_strcmp(pos, "g") == 0 ||
3123 os_strcmp(pos, "b") == 0)
3124 bss->wps_rf_bands = WPS_RF_24GHZ;
3125 else if (os_strcmp(pos, "ag") == 0 ||
3126 os_strcmp(pos, "ga") == 0)
3127 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3128 else {
3129 wpa_printf(MSG_ERROR,
3130 "Line %d: unknown wps_rf_band '%s'",
3131 line, pos);
3132 return 1;
3133 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003134 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3135 conf->acs_exclude_dfs = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07003136 } else if (os_strcmp(buf, "op_class") == 0) {
3137 conf->op_class = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003138 } else if (os_strcmp(buf, "channel") == 0) {
3139 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003140#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003141 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3142 line);
3143 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003144#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003145 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003146 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003147#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003148 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003149 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003150 conf->acs = conf->channel == 0;
3151 }
Hai Shalomc3565922019-10-28 11:58:20 -07003152 } else if (os_strcmp(buf, "edmg_channel") == 0) {
3153 conf->edmg_channel = atoi(pos);
3154 } else if (os_strcmp(buf, "enable_edmg") == 0) {
3155 conf->enable_edmg = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003156 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003157 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003158 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3159 line);
3160 return 1;
3161 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003162 } else if (os_strcmp(buf, "freqlist") == 0) {
3163 if (freq_range_list_parse(&conf->acs_freq_list, pos)) {
3164 wpa_printf(MSG_ERROR, "Line %d: invalid frequency list",
3165 line);
3166 return 1;
3167 }
3168 conf->acs_freq_list_present = 1;
3169 } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) {
3170 conf->acs_exclude_6ghz_non_psc = atoi(pos);
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);
3494 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3495 conf->he_op.he_rts_threshold = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003496 } else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
3497 conf->he_op.he_basic_mcs_nss_set = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003498 } else if (os_strcmp(buf, "he_mu_edca_qos_info_param_count") == 0) {
3499 conf->he_mu_edca.he_qos_info |=
3500 set_he_cap(atoi(pos), HE_QOS_INFO_EDCA_PARAM_SET_COUNT);
3501 } else if (os_strcmp(buf, "he_mu_edca_qos_info_q_ack") == 0) {
3502 conf->he_mu_edca.he_qos_info |=
3503 set_he_cap(atoi(pos), HE_QOS_INFO_Q_ACK);
3504 } else if (os_strcmp(buf, "he_mu_edca_qos_info_queue_request") == 0) {
3505 conf->he_mu_edca.he_qos_info |=
3506 set_he_cap(atoi(pos), HE_QOS_INFO_QUEUE_REQUEST);
3507 } else if (os_strcmp(buf, "he_mu_edca_qos_info_txop_request") == 0) {
3508 conf->he_mu_edca.he_qos_info |=
3509 set_he_cap(atoi(pos), HE_QOS_INFO_TXOP_REQUEST);
3510 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aifsn") == 0) {
3511 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3512 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3513 } else if (os_strcmp(buf, "he_mu_edca_ac_be_acm") == 0) {
3514 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3515 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3516 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aci") == 0) {
3517 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3518 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3519 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmin") == 0) {
3520 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3521 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3522 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmax") == 0) {
3523 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3524 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3525 } else if (os_strcmp(buf, "he_mu_edca_ac_be_timer") == 0) {
3526 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_TIMER_IDX] =
3527 atoi(pos) & 0xff;
3528 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aifsn") == 0) {
3529 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3530 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3531 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_acm") == 0) {
3532 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3533 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3534 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aci") == 0) {
3535 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3536 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3537 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmin") == 0) {
3538 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3539 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3540 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmax") == 0) {
3541 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3542 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3543 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_timer") == 0) {
3544 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_TIMER_IDX] =
3545 atoi(pos) & 0xff;
3546 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aifsn") == 0) {
3547 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3548 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3549 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_acm") == 0) {
3550 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3551 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3552 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aci") == 0) {
3553 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3554 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3555 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmin") == 0) {
3556 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3557 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3558 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmax") == 0) {
3559 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3560 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3561 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_timer") == 0) {
3562 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_TIMER_IDX] =
3563 atoi(pos) & 0xff;
3564 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aifsn") == 0) {
3565 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3566 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3567 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_acm") == 0) {
3568 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3569 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3570 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aci") == 0) {
3571 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3572 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3573 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmin") == 0) {
3574 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3575 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3576 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmax") == 0) {
3577 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3578 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3579 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_timer") == 0) {
3580 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_TIMER_IDX] =
3581 atoi(pos) & 0xff;
Hai Shalom81f62d82019-07-22 12:10:00 -07003582 } else if (os_strcmp(buf, "he_spr_sr_control") == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003583 conf->spr.sr_control = atoi(pos) & 0x1f;
Hai Shalom81f62d82019-07-22 12:10:00 -07003584 } else if (os_strcmp(buf, "he_spr_non_srg_obss_pd_max_offset") == 0) {
3585 conf->spr.non_srg_obss_pd_max_offset = atoi(pos);
3586 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_min_offset") == 0) {
3587 conf->spr.srg_obss_pd_min_offset = atoi(pos);
3588 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_max_offset") == 0) {
3589 conf->spr.srg_obss_pd_max_offset = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003590 } else if (os_strcmp(buf, "he_spr_srg_bss_colors") == 0) {
3591 if (hostapd_parse_he_srg_bitmap(
3592 conf->spr.srg_bss_color_bitmap, pos)) {
3593 wpa_printf(MSG_ERROR,
3594 "Line %d: Invalid srg bss colors list '%s'",
3595 line, pos);
3596 return 1;
3597 }
3598 } else if (os_strcmp(buf, "he_spr_srg_partial_bssid") == 0) {
3599 if (hostapd_parse_he_srg_bitmap(
3600 conf->spr.srg_partial_bssid_bitmap, pos)) {
3601 wpa_printf(MSG_ERROR,
3602 "Line %d: Invalid srg partial bssid list '%s'",
3603 line, pos);
3604 return 1;
3605 }
Hai Shalom81f62d82019-07-22 12:10:00 -07003606 } else if (os_strcmp(buf, "he_oper_chwidth") == 0) {
3607 conf->he_oper_chwidth = atoi(pos);
3608 } else if (os_strcmp(buf, "he_oper_centr_freq_seg0_idx") == 0) {
3609 conf->he_oper_centr_freq_seg0_idx = atoi(pos);
3610 } else if (os_strcmp(buf, "he_oper_centr_freq_seg1_idx") == 0) {
3611 conf->he_oper_centr_freq_seg1_idx = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003612 } else if (os_strcmp(buf, "he_6ghz_max_mpdu") == 0) {
3613 conf->he_6ghz_max_mpdu = atoi(pos);
3614 } else if (os_strcmp(buf, "he_6ghz_max_ampdu_len_exp") == 0) {
3615 conf->he_6ghz_max_ampdu_len_exp = atoi(pos);
3616 } else if (os_strcmp(buf, "he_6ghz_rx_ant_pat") == 0) {
3617 conf->he_6ghz_rx_ant_pat = atoi(pos);
3618 } else if (os_strcmp(buf, "he_6ghz_tx_ant_pat") == 0) {
3619 conf->he_6ghz_tx_ant_pat = atoi(pos);
3620 } else if (os_strcmp(buf, "unsol_bcast_probe_resp_interval") == 0) {
3621 int val = atoi(pos);
3622
3623 if (val < 0 || val > 20) {
3624 wpa_printf(MSG_ERROR,
3625 "Line %d: invalid unsol_bcast_probe_resp_interval value",
3626 line);
3627 return 1;
3628 }
3629 bss->unsol_bcast_probe_resp_interval = val;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003630#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003631 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3632 bss->max_listen_interval = atoi(pos);
3633 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3634 bss->disable_pmksa_caching = atoi(pos);
3635 } else if (os_strcmp(buf, "okc") == 0) {
3636 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003637#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003638 } else if (os_strcmp(buf, "wps_state") == 0) {
3639 bss->wps_state = atoi(pos);
3640 if (bss->wps_state < 0 || bss->wps_state > 2) {
3641 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3642 line);
3643 return 1;
3644 }
3645 } else if (os_strcmp(buf, "wps_independent") == 0) {
3646 bss->wps_independent = atoi(pos);
3647 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3648 bss->ap_setup_locked = atoi(pos);
3649 } else if (os_strcmp(buf, "uuid") == 0) {
3650 if (uuid_str2bin(pos, bss->uuid)) {
3651 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3652 return 1;
3653 }
3654 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3655 os_free(bss->wps_pin_requests);
3656 bss->wps_pin_requests = os_strdup(pos);
3657 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003658 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003659 wpa_printf(MSG_ERROR, "Line %d: Too long "
3660 "device_name", line);
3661 return 1;
3662 }
3663 os_free(bss->device_name);
3664 bss->device_name = os_strdup(pos);
3665 } else if (os_strcmp(buf, "manufacturer") == 0) {
3666 if (os_strlen(pos) > 64) {
3667 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3668 line);
3669 return 1;
3670 }
3671 os_free(bss->manufacturer);
3672 bss->manufacturer = os_strdup(pos);
3673 } else if (os_strcmp(buf, "model_name") == 0) {
3674 if (os_strlen(pos) > 32) {
3675 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3676 line);
3677 return 1;
3678 }
3679 os_free(bss->model_name);
3680 bss->model_name = os_strdup(pos);
3681 } else if (os_strcmp(buf, "model_number") == 0) {
3682 if (os_strlen(pos) > 32) {
3683 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3684 line);
3685 return 1;
3686 }
3687 os_free(bss->model_number);
3688 bss->model_number = os_strdup(pos);
3689 } else if (os_strcmp(buf, "serial_number") == 0) {
3690 if (os_strlen(pos) > 32) {
3691 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3692 line);
3693 return 1;
3694 }
3695 os_free(bss->serial_number);
3696 bss->serial_number = os_strdup(pos);
3697 } else if (os_strcmp(buf, "device_type") == 0) {
3698 if (wps_dev_type_str2bin(pos, bss->device_type))
3699 return 1;
3700 } else if (os_strcmp(buf, "config_methods") == 0) {
3701 os_free(bss->config_methods);
3702 bss->config_methods = os_strdup(pos);
3703 } else if (os_strcmp(buf, "os_version") == 0) {
3704 if (hexstr2bin(pos, bss->os_version, 4)) {
3705 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3706 line);
3707 return 1;
3708 }
3709 } else if (os_strcmp(buf, "ap_pin") == 0) {
3710 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003711 if (*pos == '\0')
3712 bss->ap_pin = NULL;
3713 else
3714 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003715 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3716 bss->skip_cred_build = atoi(pos);
3717 } else if (os_strcmp(buf, "extra_cred") == 0) {
3718 os_free(bss->extra_cred);
3719 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3720 if (bss->extra_cred == NULL) {
3721 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3722 line, pos);
3723 return 1;
3724 }
3725 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3726 bss->wps_cred_processing = atoi(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07003727 } else if (os_strcmp(buf, "wps_cred_add_sae") == 0) {
3728 bss->wps_cred_add_sae = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003729 } else if (os_strcmp(buf, "ap_settings") == 0) {
3730 os_free(bss->ap_settings);
3731 bss->ap_settings =
3732 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3733 if (bss->ap_settings == NULL) {
3734 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3735 line, pos);
3736 return 1;
3737 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003738 } else if (os_strcmp(buf, "multi_ap_backhaul_ssid") == 0) {
3739 size_t slen;
3740 char *str = wpa_config_parse_string(pos, &slen);
3741
3742 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
3743 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
3744 line, pos);
3745 os_free(str);
3746 return 1;
3747 }
3748 os_memcpy(bss->multi_ap_backhaul_ssid.ssid, str, slen);
3749 bss->multi_ap_backhaul_ssid.ssid_len = slen;
3750 bss->multi_ap_backhaul_ssid.ssid_set = 1;
3751 os_free(str);
3752 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_passphrase") == 0) {
3753 int len = os_strlen(pos);
3754
3755 if (len < 8 || len > 63) {
3756 wpa_printf(MSG_ERROR,
3757 "Line %d: invalid WPA passphrase length %d (expected 8..63)",
3758 line, len);
3759 return 1;
3760 }
3761 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3762 bss->multi_ap_backhaul_ssid.wpa_passphrase = os_strdup(pos);
3763 if (bss->multi_ap_backhaul_ssid.wpa_passphrase) {
3764 hostapd_config_clear_wpa_psk(
3765 &bss->multi_ap_backhaul_ssid.wpa_psk);
3766 bss->multi_ap_backhaul_ssid.wpa_passphrase_set = 1;
3767 }
3768 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_psk") == 0) {
3769 hostapd_config_clear_wpa_psk(
3770 &bss->multi_ap_backhaul_ssid.wpa_psk);
3771 bss->multi_ap_backhaul_ssid.wpa_psk =
3772 os_zalloc(sizeof(struct hostapd_wpa_psk));
3773 if (!bss->multi_ap_backhaul_ssid.wpa_psk)
3774 return 1;
3775 if (hexstr2bin(pos, bss->multi_ap_backhaul_ssid.wpa_psk->psk,
3776 PMK_LEN) ||
3777 pos[PMK_LEN * 2] != '\0') {
3778 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
3779 line, pos);
3780 hostapd_config_clear_wpa_psk(
3781 &bss->multi_ap_backhaul_ssid.wpa_psk);
3782 return 1;
3783 }
3784 bss->multi_ap_backhaul_ssid.wpa_psk->group = 1;
3785 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3786 bss->multi_ap_backhaul_ssid.wpa_passphrase = NULL;
3787 bss->multi_ap_backhaul_ssid.wpa_psk_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003788 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003789 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003790 bss->upnp_iface = os_strdup(pos);
3791 } else if (os_strcmp(buf, "friendly_name") == 0) {
3792 os_free(bss->friendly_name);
3793 bss->friendly_name = os_strdup(pos);
3794 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3795 os_free(bss->manufacturer_url);
3796 bss->manufacturer_url = os_strdup(pos);
3797 } else if (os_strcmp(buf, "model_description") == 0) {
3798 os_free(bss->model_description);
3799 bss->model_description = os_strdup(pos);
3800 } else if (os_strcmp(buf, "model_url") == 0) {
3801 os_free(bss->model_url);
3802 bss->model_url = os_strdup(pos);
3803 } else if (os_strcmp(buf, "upc") == 0) {
3804 os_free(bss->upc);
3805 bss->upc = os_strdup(pos);
3806 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3807 bss->pbc_in_m1 = atoi(pos);
3808 } else if (os_strcmp(buf, "server_id") == 0) {
3809 os_free(bss->server_id);
3810 bss->server_id = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003811 } else if (os_strcmp(buf, "wps_application_ext") == 0) {
3812 wpabuf_free(bss->wps_application_ext);
3813 bss->wps_application_ext = wpabuf_parse_bin(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003814#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003815 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3816 bss->wps_nfc_dev_pw_id = atoi(pos);
3817 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3818 bss->wps_nfc_dev_pw_id > 0xffff) {
3819 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3820 line);
3821 return 1;
3822 }
3823 bss->wps_nfc_pw_from_config = 1;
3824 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3825 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003826 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003827 bss->wps_nfc_pw_from_config = 1;
3828 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3829 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003830 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003831 bss->wps_nfc_pw_from_config = 1;
3832 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3833 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003834 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003835 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003836#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003837#endif /* CONFIG_WPS */
3838#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003839 } else if (os_strcmp(buf, "manage_p2p") == 0) {
3840 if (atoi(pos))
3841 bss->p2p |= P2P_MANAGE;
3842 else
3843 bss->p2p &= ~P2P_MANAGE;
3844 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3845 if (atoi(pos))
3846 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3847 else
3848 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003849#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003850 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3851 bss->disassoc_low_ack = atoi(pos);
3852 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
3853 if (atoi(pos))
3854 bss->tdls |= TDLS_PROHIBIT;
3855 else
3856 bss->tdls &= ~TDLS_PROHIBIT;
3857 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
3858 if (atoi(pos))
3859 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3860 else
3861 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003862#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003863 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3864 extern int rsn_testing;
3865 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003866#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003867 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3868 bss->time_advertisement = atoi(pos);
3869 } else if (os_strcmp(buf, "time_zone") == 0) {
3870 size_t tz_len = os_strlen(pos);
3871 if (tz_len < 4 || tz_len > 255) {
3872 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3873 line);
3874 return 1;
3875 }
3876 os_free(bss->time_zone);
3877 bss->time_zone = os_strdup(pos);
3878 if (bss->time_zone == NULL)
3879 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003880#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003881 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3882 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003883 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3884 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003885 } else if (os_strcmp(buf, "bss_transition") == 0) {
3886 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003887#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003888#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003889 } else if (os_strcmp(buf, "interworking") == 0) {
3890 bss->interworking = atoi(pos);
3891 } else if (os_strcmp(buf, "access_network_type") == 0) {
3892 bss->access_network_type = atoi(pos);
3893 if (bss->access_network_type < 0 ||
3894 bss->access_network_type > 15) {
3895 wpa_printf(MSG_ERROR,
3896 "Line %d: invalid access_network_type",
3897 line);
3898 return 1;
3899 }
3900 } else if (os_strcmp(buf, "internet") == 0) {
3901 bss->internet = atoi(pos);
3902 } else if (os_strcmp(buf, "asra") == 0) {
3903 bss->asra = atoi(pos);
3904 } else if (os_strcmp(buf, "esr") == 0) {
3905 bss->esr = atoi(pos);
3906 } else if (os_strcmp(buf, "uesa") == 0) {
3907 bss->uesa = atoi(pos);
3908 } else if (os_strcmp(buf, "venue_group") == 0) {
3909 bss->venue_group = atoi(pos);
3910 bss->venue_info_set = 1;
3911 } else if (os_strcmp(buf, "venue_type") == 0) {
3912 bss->venue_type = atoi(pos);
3913 bss->venue_info_set = 1;
3914 } else if (os_strcmp(buf, "hessid") == 0) {
3915 if (hwaddr_aton(pos, bss->hessid)) {
3916 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3917 return 1;
3918 }
3919 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3920 if (parse_roaming_consortium(bss, pos, line) < 0)
3921 return 1;
3922 } else if (os_strcmp(buf, "venue_name") == 0) {
3923 if (parse_venue_name(bss, pos, line) < 0)
3924 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003925 } else if (os_strcmp(buf, "venue_url") == 0) {
3926 if (parse_venue_url(bss, pos, line) < 0)
3927 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003928 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3929 u8 auth_type;
3930 u16 redirect_url_len;
3931 if (hexstr2bin(pos, &auth_type, 1)) {
3932 wpa_printf(MSG_ERROR,
3933 "Line %d: Invalid network_auth_type '%s'",
3934 line, pos);
3935 return 1;
3936 }
3937 if (auth_type == 0 || auth_type == 2)
3938 redirect_url_len = os_strlen(pos + 2);
3939 else
3940 redirect_url_len = 0;
3941 os_free(bss->network_auth_type);
3942 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3943 if (bss->network_auth_type == NULL)
3944 return 1;
3945 *bss->network_auth_type = auth_type;
3946 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3947 if (redirect_url_len)
3948 os_memcpy(bss->network_auth_type + 3, pos + 2,
3949 redirect_url_len);
3950 bss->network_auth_type_len = 3 + redirect_url_len;
3951 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3952 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3953 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3954 line, pos);
3955 bss->ipaddr_type_configured = 0;
3956 return 1;
3957 }
3958 bss->ipaddr_type_configured = 1;
3959 } else if (os_strcmp(buf, "domain_name") == 0) {
3960 int j, num_domains, domain_len, domain_list_len = 0;
3961 char *tok_start, *tok_prev;
3962 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003963
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003964 domain_list_len = os_strlen(pos) + 1;
3965 domain_list = os_malloc(domain_list_len);
3966 if (domain_list == NULL)
3967 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003968
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003969 domain_ptr = domain_list;
3970 tok_prev = pos;
3971 num_domains = 1;
3972 while ((tok_prev = os_strchr(tok_prev, ','))) {
3973 num_domains++;
3974 tok_prev++;
3975 }
3976 tok_prev = pos;
3977 for (j = 0; j < num_domains; j++) {
3978 tok_start = os_strchr(tok_prev, ',');
3979 if (tok_start) {
3980 domain_len = tok_start - tok_prev;
3981 *domain_ptr = domain_len;
3982 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3983 domain_ptr += domain_len + 1;
3984 tok_prev = ++tok_start;
3985 } else {
3986 domain_len = os_strlen(tok_prev);
3987 *domain_ptr = domain_len;
3988 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3989 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003990 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003991 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003992
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003993 os_free(bss->domain_name);
3994 bss->domain_name = domain_list;
3995 bss->domain_name_len = domain_list_len;
3996 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3997 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3998 return 1;
3999 } else if (os_strcmp(buf, "nai_realm") == 0) {
4000 if (parse_nai_realm(bss, pos, line) < 0)
4001 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004002 } else if (os_strcmp(buf, "anqp_elem") == 0) {
4003 if (parse_anqp_elem(bss, pos, line) < 0)
4004 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004005 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004006 int val = atoi(pos);
4007
4008 if (val <= 0) {
4009 wpa_printf(MSG_ERROR,
4010 "Line %d: Invalid gas_frag_limit '%s'",
4011 line, pos);
4012 return 1;
4013 }
4014 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004015 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
4016 bss->gas_comeback_delay = atoi(pos);
4017 } else if (os_strcmp(buf, "qos_map_set") == 0) {
4018 if (parse_qos_map_set(bss, pos, line) < 0)
4019 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004020#endif /* CONFIG_INTERWORKING */
4021#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004022 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
4023 os_free(bss->dump_msk_file);
4024 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004025#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004026#ifdef CONFIG_PROXYARP
4027 } else if (os_strcmp(buf, "proxy_arp") == 0) {
4028 bss->proxy_arp = atoi(pos);
4029#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004030#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004031 } else if (os_strcmp(buf, "hs20") == 0) {
4032 bss->hs20 = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004033 } else if (os_strcmp(buf, "hs20_release") == 0) {
4034 int val = atoi(pos);
4035
4036 if (val < 1 || val > (HS20_VERSION >> 4) + 1) {
4037 wpa_printf(MSG_ERROR,
4038 "Line %d: Unsupported hs20_release: %s",
4039 line, pos);
4040 return 1;
4041 }
4042 bss->hs20_release = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004043 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
4044 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004045 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
4046 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004047 } else if (os_strcmp(buf, "osen") == 0) {
4048 bss->osen = atoi(pos);
4049 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
4050 bss->anqp_domain_id = atoi(pos);
4051 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
4052 bss->hs20_deauth_req_timeout = atoi(pos);
4053 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
4054 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
4055 return 1;
4056 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
4057 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
4058 return 1;
4059 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
4060 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
4061 return 1;
4062 }
4063 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
4064 u8 *oper_class;
4065 size_t oper_class_len;
4066 oper_class_len = os_strlen(pos);
4067 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
4068 wpa_printf(MSG_ERROR,
4069 "Line %d: Invalid hs20_operating_class '%s'",
4070 line, pos);
4071 return 1;
4072 }
4073 oper_class_len /= 2;
4074 oper_class = os_malloc(oper_class_len);
4075 if (oper_class == NULL)
4076 return 1;
4077 if (hexstr2bin(pos, oper_class, oper_class_len)) {
4078 wpa_printf(MSG_ERROR,
4079 "Line %d: Invalid hs20_operating_class '%s'",
4080 line, pos);
4081 os_free(oper_class);
4082 return 1;
4083 }
4084 os_free(bss->hs20_operating_class);
4085 bss->hs20_operating_class = oper_class;
4086 bss->hs20_operating_class_len = oper_class_len;
4087 } else if (os_strcmp(buf, "hs20_icon") == 0) {
4088 if (hs20_parse_icon(bss, pos) < 0) {
4089 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
4090 line, pos);
4091 return 1;
4092 }
4093 } else if (os_strcmp(buf, "osu_ssid") == 0) {
4094 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
4095 return 1;
4096 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
4097 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
4098 return 1;
4099 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
4100 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
4101 return 1;
4102 } else if (os_strcmp(buf, "osu_nai") == 0) {
4103 if (hs20_parse_osu_nai(bss, pos, line) < 0)
4104 return 1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004105 } else if (os_strcmp(buf, "osu_nai2") == 0) {
4106 if (hs20_parse_osu_nai2(bss, pos, line) < 0)
4107 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004108 } else if (os_strcmp(buf, "osu_method_list") == 0) {
4109 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
4110 return 1;
4111 } else if (os_strcmp(buf, "osu_icon") == 0) {
4112 if (hs20_parse_osu_icon(bss, pos, line) < 0)
4113 return 1;
4114 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
4115 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
4116 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004117 } else if (os_strcmp(buf, "operator_icon") == 0) {
4118 if (hs20_parse_operator_icon(bss, pos, line) < 0)
4119 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004120 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
4121 os_free(bss->subscr_remediation_url);
4122 bss->subscr_remediation_url = os_strdup(pos);
4123 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
4124 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004125 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
4126 os_free(bss->t_c_filename);
4127 bss->t_c_filename = os_strdup(pos);
4128 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
4129 bss->t_c_timestamp = strtol(pos, NULL, 0);
4130 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
4131 os_free(bss->t_c_server_url);
4132 bss->t_c_server_url = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004133 } else if (os_strcmp(buf, "hs20_sim_provisioning_url") == 0) {
4134 os_free(bss->hs20_sim_provisioning_url);
4135 bss->hs20_sim_provisioning_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004136#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004137#ifdef CONFIG_MBO
4138 } else if (os_strcmp(buf, "mbo") == 0) {
4139 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004140 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
4141 bss->mbo_cell_data_conn_pref = atoi(pos);
4142 } else if (os_strcmp(buf, "oce") == 0) {
4143 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004144#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004145#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004146#define PARSE_TEST_PROBABILITY(_val) \
4147 } else if (os_strcmp(buf, #_val) == 0) { \
4148 char *end; \
4149 \
4150 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004151 if (*end || conf->_val < 0.0 || \
4152 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004153 wpa_printf(MSG_ERROR, \
4154 "Line %d: Invalid value '%s'", \
4155 line, pos); \
4156 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004157 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004158 PARSE_TEST_PROBABILITY(ignore_probe_probability)
4159 PARSE_TEST_PROBABILITY(ignore_auth_probability)
4160 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
4161 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
4162 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004163 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
4164 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004165 } else if (os_strcmp(buf, "bss_load_test") == 0) {
4166 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
4167 pos = os_strchr(pos, ':');
4168 if (pos == NULL) {
4169 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4170 line);
4171 return 1;
4172 }
4173 pos++;
4174 bss->bss_load_test[2] = atoi(pos);
4175 pos = os_strchr(pos, ':');
4176 if (pos == NULL) {
4177 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4178 line);
4179 return 1;
4180 }
4181 pos++;
4182 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
4183 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004184 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004185 /*
4186 * DEPRECATED: This parameter will be removed in the future.
4187 * Use rrm_neighbor_report instead.
4188 */
4189 int val = atoi(pos);
4190
4191 if (val & BIT(0))
4192 bss->radio_measurements[0] |=
4193 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004194 } else if (os_strcmp(buf, "own_ie_override") == 0) {
4195 struct wpabuf *tmp;
4196 size_t len = os_strlen(pos) / 2;
4197
4198 tmp = wpabuf_alloc(len);
4199 if (!tmp)
4200 return 1;
4201
4202 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
4203 wpabuf_free(tmp);
4204 wpa_printf(MSG_ERROR,
4205 "Line %d: Invalid own_ie_override '%s'",
4206 line, pos);
4207 return 1;
4208 }
4209
4210 wpabuf_free(bss->own_ie_override);
4211 bss->own_ie_override = tmp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004212 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
4213 bss->sae_reflection_attack = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004214 } else if (os_strcmp(buf, "sae_commit_status") == 0) {
4215 bss->sae_commit_status = atoi(pos);
4216 } else if (os_strcmp(buf, "sae_pk_omit") == 0) {
4217 bss->sae_pk_omit = atoi(pos);
4218 } else if (os_strcmp(buf, "sae_pk_password_check_skip") == 0) {
4219 bss->sae_pk_password_check_skip = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004220 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
4221 wpabuf_free(bss->sae_commit_override);
4222 bss->sae_commit_override = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004223 } else if (os_strcmp(buf, "rsne_override_eapol") == 0) {
4224 wpabuf_free(bss->rsne_override_eapol);
4225 bss->rsne_override_eapol = wpabuf_parse_bin(pos);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004226 } else if (os_strcmp(buf, "rsnxe_override_eapol") == 0) {
4227 wpabuf_free(bss->rsnxe_override_eapol);
4228 bss->rsnxe_override_eapol = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004229 } else if (os_strcmp(buf, "rsne_override_ft") == 0) {
4230 wpabuf_free(bss->rsne_override_ft);
4231 bss->rsne_override_ft = wpabuf_parse_bin(pos);
4232 } else if (os_strcmp(buf, "rsnxe_override_ft") == 0) {
4233 wpabuf_free(bss->rsnxe_override_ft);
4234 bss->rsnxe_override_ft = wpabuf_parse_bin(pos);
4235 } else if (os_strcmp(buf, "gtk_rsc_override") == 0) {
4236 wpabuf_free(bss->gtk_rsc_override);
4237 bss->gtk_rsc_override = wpabuf_parse_bin(pos);
4238 } else if (os_strcmp(buf, "igtk_rsc_override") == 0) {
4239 wpabuf_free(bss->igtk_rsc_override);
4240 bss->igtk_rsc_override = wpabuf_parse_bin(pos);
4241 } else if (os_strcmp(buf, "no_beacon_rsnxe") == 0) {
4242 bss->no_beacon_rsnxe = atoi(pos);
4243 } else if (os_strcmp(buf, "skip_prune_assoc") == 0) {
4244 bss->skip_prune_assoc = atoi(pos);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004245 } else if (os_strcmp(buf, "ft_rsnxe_used") == 0) {
4246 bss->ft_rsnxe_used = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004247 } else if (os_strcmp(buf, "oci_freq_override_eapol_m3") == 0) {
4248 bss->oci_freq_override_eapol_m3 = atoi(pos);
4249 } else if (os_strcmp(buf, "oci_freq_override_eapol_g1") == 0) {
4250 bss->oci_freq_override_eapol_g1 = atoi(pos);
4251 } else if (os_strcmp(buf, "oci_freq_override_saquery_req") == 0) {
4252 bss->oci_freq_override_saquery_req = atoi(pos);
4253 } else if (os_strcmp(buf, "oci_freq_override_saquery_resp") == 0) {
4254 bss->oci_freq_override_saquery_resp = atoi(pos);
4255 } else if (os_strcmp(buf, "oci_freq_override_ft_assoc") == 0) {
4256 bss->oci_freq_override_ft_assoc = atoi(pos);
4257 } else if (os_strcmp(buf, "oci_freq_override_fils_assoc") == 0) {
4258 bss->oci_freq_override_fils_assoc = atoi(pos);
4259 } else if (os_strcmp(buf, "oci_freq_override_wnm_sleep") == 0) {
4260 bss->oci_freq_override_wnm_sleep = atoi(pos);
Kai Shie75b0652020-11-24 20:31:29 -08004261 } else if (os_strcmp(buf, "skip_send_eapol") == 0) {
4262 conf->skip_send_eapol = atoi(pos);
4263 } else if (os_strcmp(buf, "enable_eapol_large_timeout") == 0) {
4264 conf->enable_eapol_large_timeout = atoi(pos);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004265#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004266#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004267 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004268 if (parse_sae_password(bss, pos) < 0) {
4269 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
4270 line);
4271 return 1;
4272 }
4273#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004274 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004275 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004276 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004277 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4278 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004279 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004280 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
4281 bss->sae_anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004282 } else if (os_strcmp(buf, "sae_sync") == 0) {
4283 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004284 } else if (os_strcmp(buf, "sae_groups") == 0) {
4285 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
4286 wpa_printf(MSG_ERROR,
4287 "Line %d: Invalid sae_groups value '%s'",
4288 line, pos);
4289 return 1;
4290 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004291 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
4292 bss->sae_require_mfp = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07004293 } else if (os_strcmp(buf, "sae_confirm_immediate") == 0) {
4294 bss->sae_confirm_immediate = atoi(pos);
4295 } else if (os_strcmp(buf, "sae_pwe") == 0) {
4296 bss->sae_pwe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004297 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
4298 int val = atoi(pos);
4299 if (val < 0 || val > 255) {
4300 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
4301 line, val);
4302 return 1;
4303 }
4304 conf->local_pwr_constraint = val;
4305 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
4306 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07004307 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
4308 os_free(bss->wowlan_triggers);
4309 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004310#ifdef CONFIG_FST
4311 } else if (os_strcmp(buf, "fst_group_id") == 0) {
4312 size_t len = os_strlen(pos);
4313
4314 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
4315 wpa_printf(MSG_ERROR,
4316 "Line %d: Invalid fst_group_id value '%s'",
4317 line, pos);
4318 return 1;
4319 }
4320
4321 if (conf->fst_cfg.group_id[0]) {
4322 wpa_printf(MSG_ERROR,
4323 "Line %d: Duplicate fst_group value '%s'",
4324 line, pos);
4325 return 1;
4326 }
4327
4328 os_strlcpy(conf->fst_cfg.group_id, pos,
4329 sizeof(conf->fst_cfg.group_id));
4330 } else if (os_strcmp(buf, "fst_priority") == 0) {
4331 char *endp;
4332 long int val;
4333
4334 if (!*pos) {
4335 wpa_printf(MSG_ERROR,
4336 "Line %d: fst_priority value not supplied (expected 1..%u)",
4337 line, FST_MAX_PRIO_VALUE);
4338 return -1;
4339 }
4340
4341 val = strtol(pos, &endp, 0);
4342 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
4343 wpa_printf(MSG_ERROR,
4344 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
4345 line, val, pos, FST_MAX_PRIO_VALUE);
4346 return 1;
4347 }
4348 conf->fst_cfg.priority = (u8) val;
4349 } else if (os_strcmp(buf, "fst_llt") == 0) {
4350 char *endp;
4351 long int val;
4352
4353 if (!*pos) {
4354 wpa_printf(MSG_ERROR,
4355 "Line %d: fst_llt value not supplied (expected 1..%u)",
4356 line, FST_MAX_LLT_MS);
4357 return -1;
4358 }
4359 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07004360 if (*endp || val < 1 ||
4361 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004362 wpa_printf(MSG_ERROR,
4363 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
4364 line, val, pos, FST_MAX_LLT_MS);
4365 return 1;
4366 }
4367 conf->fst_cfg.llt = (u32) val;
4368#endif /* CONFIG_FST */
4369 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
4370 conf->track_sta_max_num = atoi(pos);
4371 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
4372 conf->track_sta_max_age = atoi(pos);
4373 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
4374 os_free(bss->no_probe_resp_if_seen_on);
4375 bss->no_probe_resp_if_seen_on = os_strdup(pos);
4376 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
4377 os_free(bss->no_auth_if_seen_on);
4378 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004379 } else if (os_strcmp(buf, "lci") == 0) {
4380 wpabuf_free(conf->lci);
4381 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004382 if (conf->lci && wpabuf_len(conf->lci) == 0) {
4383 wpabuf_free(conf->lci);
4384 conf->lci = NULL;
4385 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004386 } else if (os_strcmp(buf, "civic") == 0) {
4387 wpabuf_free(conf->civic);
4388 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004389 if (conf->civic && wpabuf_len(conf->civic) == 0) {
4390 wpabuf_free(conf->civic);
4391 conf->civic = NULL;
4392 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004393 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
4394 if (atoi(pos))
4395 bss->radio_measurements[0] |=
4396 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004397 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
4398 if (atoi(pos))
4399 bss->radio_measurements[0] |=
4400 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4401 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4402 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004403 } else if (os_strcmp(buf, "gas_address3") == 0) {
4404 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004405 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4406 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004407 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4408 bss->ftm_responder = atoi(pos);
4409 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4410 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004411#ifdef CONFIG_FILS
4412 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4413 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4414 wpa_printf(MSG_ERROR,
4415 "Line %d: Invalid fils_cache_id '%s'",
4416 line, pos);
4417 return 1;
4418 }
4419 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004420 } else if (os_strcmp(buf, "fils_realm") == 0) {
4421 if (parse_fils_realm(bss, pos) < 0)
4422 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004423 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4424 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004425 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4426 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4427 wpa_printf(MSG_ERROR,
4428 "Line %d: invalid IP address '%s'",
4429 line, pos);
4430 return 1;
4431 }
4432 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4433 bss->dhcp_rapid_commit_proxy = atoi(pos);
4434 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4435 bss->fils_hlp_wait_time = atoi(pos);
4436 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4437 bss->dhcp_server_port = atoi(pos);
4438 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4439 bss->dhcp_relay_port = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004440 } else if (os_strcmp(buf, "fils_discovery_min_interval") == 0) {
4441 bss->fils_discovery_min_int = atoi(pos);
4442 } else if (os_strcmp(buf, "fils_discovery_max_interval") == 0) {
4443 bss->fils_discovery_max_int = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004444#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004445 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4446 bss->multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004447 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4448 bss->broadcast_deauth = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004449 } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
4450 bss->notify_mgmt_frames = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004451#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07004452 } else if (os_strcmp(buf, "dpp_name") == 0) {
4453 os_free(bss->dpp_name);
4454 bss->dpp_name = os_strdup(pos);
4455 } else if (os_strcmp(buf, "dpp_mud_url") == 0) {
4456 os_free(bss->dpp_mud_url);
4457 bss->dpp_mud_url = os_strdup(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004458 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4459 os_free(bss->dpp_connector);
4460 bss->dpp_connector = os_strdup(pos);
4461 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4462 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4463 return 1;
4464 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4465 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4466 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4467 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4468 return 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07004469#ifdef CONFIG_DPP2
4470 } else if (os_strcmp(buf, "dpp_controller") == 0) {
4471 if (hostapd_dpp_controller_parse(bss, pos))
4472 return 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07004473 } else if (os_strcmp(buf, "dpp_configurator_connectivity") == 0) {
4474 bss->dpp_configurator_connectivity = atoi(pos);
4475 } else if (os_strcmp(buf, "dpp_pfs") == 0) {
4476 int val = atoi(pos);
4477
4478 if (val < 0 || val > 2) {
4479 wpa_printf(MSG_ERROR,
4480 "Line %d: Invalid dpp_pfs value '%s'",
4481 line, pos);
4482 return -1;
4483 }
4484 bss->dpp_pfs = val;
Hai Shalom81f62d82019-07-22 12:10:00 -07004485#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004486#endif /* CONFIG_DPP */
4487#ifdef CONFIG_OWE
4488 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4489 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4490 wpa_printf(MSG_ERROR,
4491 "Line %d: invalid owe_transition_bssid",
4492 line);
4493 return 1;
4494 }
4495 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4496 size_t slen;
4497 char *str = wpa_config_parse_string(pos, &slen);
4498
4499 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4500 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4501 line, pos);
4502 os_free(str);
4503 return 1;
4504 }
4505 os_memcpy(bss->owe_transition_ssid, str, slen);
4506 bss->owe_transition_ssid_len = slen;
4507 os_free(str);
4508 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4509 os_strlcpy(bss->owe_transition_ifname, pos,
4510 sizeof(bss->owe_transition_ifname));
4511 } else if (os_strcmp(buf, "owe_groups") == 0) {
4512 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4513 wpa_printf(MSG_ERROR,
4514 "Line %d: Invalid owe_groups value '%s'",
4515 line, pos);
4516 return 1;
4517 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004518 } else if (os_strcmp(buf, "owe_ptk_workaround") == 0) {
4519 bss->owe_ptk_workaround = atoi(pos);
4520#endif /* CONFIG_OWE */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004521 } else if (os_strcmp(buf, "coloc_intf_reporting") == 0) {
4522 bss->coloc_intf_reporting = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004523 } else if (os_strcmp(buf, "multi_ap") == 0) {
4524 int val = atoi(pos);
4525
4526 if (val < 0 || val > 3) {
4527 wpa_printf(MSG_ERROR, "Line %d: Invalid multi_ap '%s'",
4528 line, buf);
4529 return -1;
4530 }
4531
4532 bss->multi_ap = val;
4533 } else if (os_strcmp(buf, "rssi_reject_assoc_rssi") == 0) {
4534 conf->rssi_reject_assoc_rssi = atoi(pos);
4535 } else if (os_strcmp(buf, "rssi_reject_assoc_timeout") == 0) {
4536 conf->rssi_reject_assoc_timeout = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004537 } else if (os_strcmp(buf, "rssi_ignore_probe_request") == 0) {
4538 conf->rssi_ignore_probe_request = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004539 } else if (os_strcmp(buf, "pbss") == 0) {
4540 bss->pbss = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004541 } else if (os_strcmp(buf, "transition_disable") == 0) {
4542 bss->transition_disable = strtol(pos, NULL, 16);
Hai Shalom81f62d82019-07-22 12:10:00 -07004543#ifdef CONFIG_AIRTIME_POLICY
4544 } else if (os_strcmp(buf, "airtime_mode") == 0) {
4545 int val = atoi(pos);
4546
4547 if (val < 0 || val > AIRTIME_MODE_MAX) {
4548 wpa_printf(MSG_ERROR, "Line %d: Unknown airtime_mode",
4549 line);
4550 return 1;
4551 }
4552 conf->airtime_mode = val;
4553 } else if (os_strcmp(buf, "airtime_update_interval") == 0) {
4554 conf->airtime_update_interval = atoi(pos);
4555 } else if (os_strcmp(buf, "airtime_bss_weight") == 0) {
4556 bss->airtime_weight = atoi(pos);
4557 } else if (os_strcmp(buf, "airtime_bss_limit") == 0) {
4558 int val = atoi(pos);
4559
4560 if (val < 0 || val > 1) {
4561 wpa_printf(MSG_ERROR,
4562 "Line %d: Invalid airtime_bss_limit (must be 0 or 1)",
4563 line);
4564 return 1;
4565 }
4566 bss->airtime_limit = val;
4567 } else if (os_strcmp(buf, "airtime_sta_weight") == 0) {
4568 if (add_airtime_weight(bss, pos) < 0) {
4569 wpa_printf(MSG_ERROR,
4570 "Line %d: Invalid airtime weight '%s'",
4571 line, pos);
4572 return 1;
4573 }
4574#endif /* CONFIG_AIRTIME_POLICY */
4575#ifdef CONFIG_MACSEC
4576 } else if (os_strcmp(buf, "macsec_policy") == 0) {
4577 int macsec_policy = atoi(pos);
4578
4579 if (macsec_policy < 0 || macsec_policy > 1) {
4580 wpa_printf(MSG_ERROR,
4581 "Line %d: invalid macsec_policy (%d): '%s'.",
4582 line, macsec_policy, pos);
4583 return 1;
4584 }
4585 bss->macsec_policy = macsec_policy;
4586 } else if (os_strcmp(buf, "macsec_integ_only") == 0) {
4587 int macsec_integ_only = atoi(pos);
4588
4589 if (macsec_integ_only < 0 || macsec_integ_only > 1) {
4590 wpa_printf(MSG_ERROR,
4591 "Line %d: invalid macsec_integ_only (%d): '%s'.",
4592 line, macsec_integ_only, pos);
4593 return 1;
4594 }
4595 bss->macsec_integ_only = macsec_integ_only;
4596 } else if (os_strcmp(buf, "macsec_replay_protect") == 0) {
4597 int macsec_replay_protect = atoi(pos);
4598
4599 if (macsec_replay_protect < 0 || macsec_replay_protect > 1) {
4600 wpa_printf(MSG_ERROR,
4601 "Line %d: invalid macsec_replay_protect (%d): '%s'.",
4602 line, macsec_replay_protect, pos);
4603 return 1;
4604 }
4605 bss->macsec_replay_protect = macsec_replay_protect;
4606 } else if (os_strcmp(buf, "macsec_replay_window") == 0) {
4607 bss->macsec_replay_window = atoi(pos);
4608 } else if (os_strcmp(buf, "macsec_port") == 0) {
4609 int macsec_port = atoi(pos);
4610
4611 if (macsec_port < 1 || macsec_port > 65534) {
4612 wpa_printf(MSG_ERROR,
4613 "Line %d: invalid macsec_port (%d): '%s'.",
4614 line, macsec_port, pos);
4615 return 1;
4616 }
4617 bss->macsec_port = macsec_port;
4618 } else if (os_strcmp(buf, "mka_priority") == 0) {
4619 int mka_priority = atoi(pos);
4620
4621 if (mka_priority < 0 || mka_priority > 255) {
4622 wpa_printf(MSG_ERROR,
4623 "Line %d: invalid mka_priority (%d): '%s'.",
4624 line, mka_priority, pos);
4625 return 1;
4626 }
4627 bss->mka_priority = mka_priority;
4628 } else if (os_strcmp(buf, "mka_cak") == 0) {
4629 size_t len = os_strlen(pos);
4630
4631 if (len > 2 * MACSEC_CAK_MAX_LEN ||
4632 (len != 2 * 16 && len != 2 * 32) ||
4633 hexstr2bin(pos, bss->mka_cak, len / 2)) {
4634 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.",
4635 line, pos);
4636 return 1;
4637 }
4638 bss->mka_cak_len = len / 2;
4639 bss->mka_psk_set |= MKA_PSK_SET_CAK;
4640 } else if (os_strcmp(buf, "mka_ckn") == 0) {
4641 size_t len = os_strlen(pos);
4642
4643 if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */
4644 len < 2 || /* too short */
4645 len % 2 != 0 /* not an integral number of bytes */) {
4646 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4647 line, pos);
4648 return 1;
4649 }
4650 bss->mka_ckn_len = len / 2;
4651 if (hexstr2bin(pos, bss->mka_ckn, bss->mka_ckn_len)) {
4652 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4653 line, pos);
4654 return -1;
4655 }
4656 bss->mka_psk_set |= MKA_PSK_SET_CKN;
4657#endif /* CONFIG_MACSEC */
Hai Shalom60840252021-02-19 19:02:11 -08004658 } else if (os_strcmp(buf, "disable_11n") == 0) {
4659 bss->disable_11n = !!atoi(pos);
4660 } else if (os_strcmp(buf, "disable_11ac") == 0) {
4661 bss->disable_11ac = !!atoi(pos);
4662 } else if (os_strcmp(buf, "disable_11ax") == 0) {
4663 bss->disable_11ax = !!atoi(pos);
4664#ifdef CONFIG_PASN
4665#ifdef CONFIG_TESTING_OPTIONS
4666 } else if (os_strcmp(buf, "force_kdk_derivation") == 0) {
4667 bss->force_kdk_derivation = atoi(pos);
4668#endif /* CONFIG_TESTING_OPTIONS */
4669 } else if (os_strcmp(buf, "pasn_groups") == 0) {
4670 if (hostapd_parse_intlist(&bss->pasn_groups, pos)) {
4671 wpa_printf(MSG_ERROR,
4672 "Line %d: Invalid pasn_groups value '%s'",
4673 line, pos);
4674 return 1;
4675 }
4676#endif /* CONFIG_PASN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004677 } else {
4678 wpa_printf(MSG_ERROR,
4679 "Line %d: unknown configuration item '%s'",
4680 line, buf);
4681 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004682 }
4683
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004684 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004685}
4686
4687
Dmitry Shmidt04949592012-07-19 12:16:46 -07004688/**
4689 * hostapd_config_read - Read and parse a configuration file
4690 * @fname: Configuration file name (including path, if needed)
4691 * Returns: Allocated configuration data structure
4692 */
4693struct hostapd_config * hostapd_config_read(const char *fname)
4694{
4695 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004696 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004697 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004698 int line = 0;
4699 int errors = 0;
4700 size_t i;
4701
4702 f = fopen(fname, "r");
4703 if (f == NULL) {
4704 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4705 "for reading.", fname);
4706 return NULL;
4707 }
4708
4709 conf = hostapd_config_defaults();
4710 if (conf == NULL) {
4711 fclose(f);
4712 return NULL;
4713 }
4714
4715 /* set default driver based on configuration */
4716 conf->driver = wpa_drivers[0];
4717 if (conf->driver == NULL) {
4718 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4719 hostapd_config_free(conf);
4720 fclose(f);
4721 return NULL;
4722 }
4723
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004724 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004725
4726 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004727 struct hostapd_bss_config *bss;
4728
Dmitry Shmidt04949592012-07-19 12:16:46 -07004729 bss = conf->last_bss;
4730 line++;
4731
4732 if (buf[0] == '#')
4733 continue;
4734 pos = buf;
4735 while (*pos != '\0') {
4736 if (*pos == '\n') {
4737 *pos = '\0';
4738 break;
4739 }
4740 pos++;
4741 }
4742 if (buf[0] == '\0')
4743 continue;
4744
4745 pos = os_strchr(buf, '=');
4746 if (pos == NULL) {
4747 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4748 line, buf);
4749 errors++;
4750 continue;
4751 }
4752 *pos = '\0';
4753 pos++;
4754 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4755 }
4756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004757 fclose(f);
4758
Dmitry Shmidt04949592012-07-19 12:16:46 -07004759 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004760 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004761
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004762 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004763 errors++;
4764
4765#ifndef WPA_IGNORE_CONFIG_ERRORS
4766 if (errors) {
4767 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4768 "'%s'", errors, fname);
4769 hostapd_config_free(conf);
4770 conf = NULL;
4771 }
4772#endif /* WPA_IGNORE_CONFIG_ERRORS */
4773
4774 return conf;
4775}
Dmitry Shmidt04949592012-07-19 12:16:46 -07004776
4777
4778int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004779 struct hostapd_bss_config *bss, const char *field,
4780 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004781{
4782 int errors;
4783 size_t i;
4784
4785 errors = hostapd_config_fill(conf, bss, field, value, 0);
4786 if (errors) {
4787 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4788 "to value '%s'", field, value);
4789 return -1;
4790 }
4791
4792 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004793 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004794
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004795 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004796 wpa_printf(MSG_ERROR, "Configuration check failed");
4797 return -1;
4798 }
4799
4800 return 0;
4801}