blob: ce32f3c04d2c9193218e590a5a0a7e25137ef654 [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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 else {
758 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
759 line, start);
760 os_free(buf);
761 return -1;
762 }
763
764 if (last)
765 break;
766 start = end + 1;
767 }
768
769 os_free(buf);
770 if (val == 0) {
771 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
772 "configured.", line);
773 return -1;
774 }
775
776 return val;
777}
778
779
780static int hostapd_config_parse_cipher(int line, const char *value)
781{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800782 int val = wpa_parse_cipher(value);
783 if (val < 0) {
784 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
785 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 if (val == 0) {
789 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
790 line);
791 return -1;
792 }
793 return val;
794}
795
796
Hai Shalomfdcde762020-04-02 11:19:20 -0700797#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
799 char *val)
800{
801 size_t len = os_strlen(val);
802
Dmitry Shmidt29333592017-01-09 12:27:11 -0800803 if (keyidx < 0 || keyidx > 3)
804 return -1;
805
806 if (len == 0) {
807 int i, set = 0;
808
809 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
810 wep->key[keyidx] = NULL;
811 wep->len[keyidx] = 0;
812 for (i = 0; i < NUM_WEP_KEYS; i++) {
813 if (wep->key[i])
814 set++;
815 }
816 if (!set)
817 wep->keys_set = 0;
818 return 0;
819 }
820
821 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 return -1;
823
824 if (val[0] == '"') {
825 if (len < 2 || val[len - 1] != '"')
826 return -1;
827 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700828 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 if (wep->key[keyidx] == NULL)
830 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831 wep->len[keyidx] = len;
832 } else {
833 if (len & 1)
834 return -1;
835 len /= 2;
836 wep->key[keyidx] = os_malloc(len);
837 if (wep->key[keyidx] == NULL)
838 return -1;
839 wep->len[keyidx] = len;
840 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
841 return -1;
842 }
843
844 wep->keys_set++;
845
846 return 0;
847}
Hai Shalomfdcde762020-04-02 11:19:20 -0700848#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849
850
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700851static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
852{
853 char *pos;
854
855 /* for backwards compatibility, translate ' ' in conf str to ',' */
856 pos = val;
857 while (pos) {
858 pos = os_strchr(pos, ' ');
859 if (pos)
860 *pos++ = ',';
861 }
862 if (freq_range_list_parse(&conf->acs_ch_list, val))
863 return -1;
864
865 return 0;
866}
867
868
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700869static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870{
871 int *list;
872 int count;
873 char *pos, *end;
874
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700875 os_free(*int_list);
876 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877
878 pos = val;
879 count = 0;
880 while (*pos != '\0') {
881 if (*pos == ' ')
882 count++;
883 pos++;
884 }
885
886 list = os_malloc(sizeof(int) * (count + 2));
887 if (list == NULL)
888 return -1;
889 pos = val;
890 count = 0;
891 while (*pos != '\0') {
892 end = os_strchr(pos, ' ');
893 if (end)
894 *end = '\0';
895
896 list[count++] = atoi(pos);
897 if (!end)
898 break;
899 pos = end + 1;
900 }
901 list[count] = -1;
902
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700903 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 return 0;
905}
906
907
908static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
909{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800910 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700911
912 if (*ifname == '\0')
913 return -1;
914
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800915 all = os_realloc_array(conf->bss, conf->num_bss + 1,
916 sizeof(struct hostapd_bss_config *));
917 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
919 "multi-BSS entry");
920 return -1;
921 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800922 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800924 bss = os_zalloc(sizeof(*bss));
925 if (bss == NULL)
926 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927 bss->radius = os_zalloc(sizeof(*bss->radius));
928 if (bss->radius == NULL) {
929 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
930 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800931 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 return -1;
933 }
934
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800935 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936 conf->last_bss = bss;
937
938 hostapd_config_defaults_bss(bss);
939 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
940 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
941
942 return 0;
943}
944
945
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800946#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700947
948static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
949{
950 u8 oldkey[16];
951 int ret;
952
953 if (!hexstr2bin(pos, key, key_len))
954 return 0;
955
956 /* Try to use old short key for backwards compatibility */
957 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
958 return -1;
959
960 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
961 key, key_len);
962 os_memset(oldkey, 0, sizeof(oldkey));
963 return ret;
964}
965
966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967static int add_r0kh(struct hostapd_bss_config *bss, char *value)
968{
969 struct ft_remote_r0kh *r0kh;
970 char *pos, *next;
971
972 r0kh = os_zalloc(sizeof(*r0kh));
973 if (r0kh == NULL)
974 return -1;
975
976 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
977 pos = value;
978 next = os_strchr(pos, ' ');
979 if (next)
980 *next++ = '\0';
981 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
982 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
983 os_free(r0kh);
984 return -1;
985 }
986
987 pos = next;
988 next = os_strchr(pos, ' ');
989 if (next)
990 *next++ = '\0';
991 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
992 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
993 os_free(r0kh);
994 return -1;
995 }
996 r0kh->id_len = next - pos - 1;
997 os_memcpy(r0kh->id, pos, r0kh->id_len);
998
999 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001000 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1002 os_free(r0kh);
1003 return -1;
1004 }
1005
1006 r0kh->next = bss->r0kh_list;
1007 bss->r0kh_list = r0kh;
1008
1009 return 0;
1010}
1011
1012
1013static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1014{
1015 struct ft_remote_r1kh *r1kh;
1016 char *pos, *next;
1017
1018 r1kh = os_zalloc(sizeof(*r1kh));
1019 if (r1kh == NULL)
1020 return -1;
1021
1022 /* 02:01:02:03:04:05 02:01:02:03:04:05
1023 * 000102030405060708090a0b0c0d0e0f */
1024 pos = value;
1025 next = os_strchr(pos, ' ');
1026 if (next)
1027 *next++ = '\0';
1028 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1029 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1030 os_free(r1kh);
1031 return -1;
1032 }
1033
1034 pos = next;
1035 next = os_strchr(pos, ' ');
1036 if (next)
1037 *next++ = '\0';
1038 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1039 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1040 os_free(r1kh);
1041 return -1;
1042 }
1043
1044 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001045 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1047 os_free(r1kh);
1048 return -1;
1049 }
1050
1051 r1kh->next = bss->r1kh_list;
1052 bss->r1kh_list = r1kh;
1053
1054 return 0;
1055}
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001056#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057
1058
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059static int hostapd_config_ht_capab(struct hostapd_config *conf,
1060 const char *capab)
1061{
1062 if (os_strstr(capab, "[LDPC]"))
1063 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1064 if (os_strstr(capab, "[HT40-]")) {
1065 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1066 conf->secondary_channel = -1;
1067 }
1068 if (os_strstr(capab, "[HT40+]")) {
1069 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1070 conf->secondary_channel = 1;
1071 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001072 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1073 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1074 conf->ht40_plus_minus_allowed = 1;
1075 }
Hai Shalomce48b4a2018-09-05 11:41:35 -07001076 if (!os_strstr(capab, "[HT40+]") && !os_strstr(capab, "[HT40-]"))
1077 conf->secondary_channel = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078 if (os_strstr(capab, "[GF]"))
1079 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1080 if (os_strstr(capab, "[SHORT-GI-20]"))
1081 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1082 if (os_strstr(capab, "[SHORT-GI-40]"))
1083 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1084 if (os_strstr(capab, "[TX-STBC]"))
1085 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1086 if (os_strstr(capab, "[RX-STBC1]")) {
1087 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1088 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1089 }
1090 if (os_strstr(capab, "[RX-STBC12]")) {
1091 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1092 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1093 }
1094 if (os_strstr(capab, "[RX-STBC123]")) {
1095 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1096 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1097 }
1098 if (os_strstr(capab, "[DELAYED-BA]"))
1099 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1100 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1101 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1102 if (os_strstr(capab, "[DSSS_CCK-40]"))
1103 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001104 if (os_strstr(capab, "[40-INTOLERANT]"))
1105 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001106 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1107 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1108
1109 return 0;
1110}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111
1112
Dmitry Shmidt04949592012-07-19 12:16:46 -07001113#ifdef CONFIG_IEEE80211AC
1114static int hostapd_config_vht_capab(struct hostapd_config *conf,
1115 const char *capab)
1116{
1117 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1118 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1119 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1120 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1121 if (os_strstr(capab, "[VHT160]"))
1122 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1123 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1124 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001125 if (os_strstr(capab, "[RXLDPC]"))
1126 conf->vht_capab |= VHT_CAP_RXLDPC;
1127 if (os_strstr(capab, "[SHORT-GI-80]"))
1128 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1129 if (os_strstr(capab, "[SHORT-GI-160]"))
1130 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1131 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1132 conf->vht_capab |= VHT_CAP_TXSTBC;
1133 if (os_strstr(capab, "[RX-STBC-1]"))
1134 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1135 if (os_strstr(capab, "[RX-STBC-12]"))
1136 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1137 if (os_strstr(capab, "[RX-STBC-123]"))
1138 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1139 if (os_strstr(capab, "[RX-STBC-1234]"))
1140 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1141 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001142 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001143 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001144 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001145 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001146 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1147 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001148 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1149 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1150 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1151 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1152 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1153 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001154 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001155 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1156 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001157 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1158 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1159 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1160 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1161 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1162 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001163 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1164 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001165 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1166 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1167 if (os_strstr(capab, "[HTC-VHT]"))
1168 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001169 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1170 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1171 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1172 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1173 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1174 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1175 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1176 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1177 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1178 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1179 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1180 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1181 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1182 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001183 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1184 (conf->vht_capab & VHT_CAP_HTC_VHT))
1185 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1186 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1187 (conf->vht_capab & VHT_CAP_HTC_VHT))
1188 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1189 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1190 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1191 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1192 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1193 return 0;
1194}
1195#endif /* CONFIG_IEEE80211AC */
1196
1197
Hai Shalom74f70d42019-02-11 14:42:39 -08001198#ifdef CONFIG_IEEE80211AX
1199
1200static u8 find_bit_offset(u8 val)
1201{
1202 u8 res = 0;
1203
1204 for (; val; val >>= 1) {
1205 if (val & 1)
1206 break;
1207 res++;
1208 }
1209
1210 return res;
1211}
1212
1213
1214static u8 set_he_cap(int val, u8 mask)
1215{
1216 return (u8) (mask & (val << find_bit_offset(mask)));
1217}
1218
1219#endif /* CONFIG_IEEE80211AX */
1220
1221
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001222#ifdef CONFIG_INTERWORKING
1223static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1224 int line)
1225{
1226 size_t len = os_strlen(pos);
1227 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1228
1229 struct hostapd_roaming_consortium *rc;
1230
1231 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1232 hexstr2bin(pos, oi, len / 2)) {
1233 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1234 "'%s'", line, pos);
1235 return -1;
1236 }
1237 len /= 2;
1238
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001239 rc = os_realloc_array(bss->roaming_consortium,
1240 bss->roaming_consortium_count + 1,
1241 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001242 if (rc == NULL)
1243 return -1;
1244
1245 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1246 rc[bss->roaming_consortium_count].len = len;
1247
1248 bss->roaming_consortium = rc;
1249 bss->roaming_consortium_count++;
1250
1251 return 0;
1252}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001253
1254
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001255static int parse_lang_string(struct hostapd_lang_string **array,
1256 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001257{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001258 char *sep, *str = NULL;
1259 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001260 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001261 int ret = -1;
1262
1263 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1264 str = wpa_config_parse_string(pos, &slen);
1265 if (!str)
1266 return -1;
1267 pos = str;
1268 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001269
1270 sep = os_strchr(pos, ':');
1271 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001272 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001273 *sep++ = '\0';
1274
1275 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001276 if (clen < 2 || clen > sizeof(ls->lang))
1277 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001278 nlen = os_strlen(sep);
1279 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001280 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001281
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001282 ls = os_realloc_array(*array, *count + 1,
1283 sizeof(struct hostapd_lang_string));
1284 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001285 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001286
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001287 *array = ls;
1288 ls = &(*array)[*count];
1289 (*count)++;
1290
1291 os_memset(ls->lang, 0, sizeof(ls->lang));
1292 os_memcpy(ls->lang, pos, clen);
1293 ls->name_len = nlen;
1294 os_memcpy(ls->name, sep, nlen);
1295
Dmitry Shmidt56052862013-10-04 10:23:25 -07001296 ret = 0;
1297fail:
1298 os_free(str);
1299 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300}
1301
1302
1303static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1304 int line)
1305{
1306 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1307 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1308 line, pos);
1309 return -1;
1310 }
1311 return 0;
1312}
1313
1314
Roshan Pius3a1667e2018-07-03 15:17:14 -07001315static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1316 int line)
1317{
1318 char *sep;
1319 size_t nlen;
1320 struct hostapd_venue_url *url;
1321 int ret = -1;
1322
1323 sep = os_strchr(pos, ':');
1324 if (!sep)
1325 goto fail;
1326 *sep++ = '\0';
1327
1328 nlen = os_strlen(sep);
1329 if (nlen > 254)
1330 goto fail;
1331
1332 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1333 sizeof(struct hostapd_venue_url));
1334 if (!url)
1335 goto fail;
1336
1337 bss->venue_url = url;
1338 url = &bss->venue_url[bss->venue_url_count++];
1339
1340 url->venue_number = atoi(pos);
1341 url->url_len = nlen;
1342 os_memcpy(url->url, sep, nlen);
1343
1344 ret = 0;
1345fail:
1346 if (ret)
1347 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1348 line, pos);
1349 return ret;
1350}
1351
1352
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001353static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1354 int line)
1355{
1356 size_t count;
1357 char *pos;
1358 u8 *info = NULL, *ipos;
1359
1360 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1361
1362 count = 1;
1363 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001364 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001365 goto fail;
1366 if (*pos == ';')
1367 count++;
1368 }
1369 if (1 + count * 3 > 0x7f)
1370 goto fail;
1371
1372 info = os_zalloc(2 + 3 + count * 3);
1373 if (info == NULL)
1374 return -1;
1375
1376 ipos = info;
1377 *ipos++ = 0; /* GUD - Version 1 */
1378 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1379 *ipos++ = 0; /* PLMN List IEI */
1380 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1381 *ipos++ = 1 + count * 3;
1382 *ipos++ = count; /* Number of PLMNs */
1383
1384 pos = buf;
1385 while (pos && *pos) {
1386 char *mcc, *mnc;
1387 size_t mnc_len;
1388
1389 mcc = pos;
1390 mnc = os_strchr(pos, ',');
1391 if (mnc == NULL)
1392 goto fail;
1393 *mnc++ = '\0';
1394 pos = os_strchr(mnc, ';');
1395 if (pos)
1396 *pos++ = '\0';
1397
1398 mnc_len = os_strlen(mnc);
1399 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1400 goto fail;
1401
1402 /* BC coded MCC,MNC */
1403 /* MCC digit 2 | MCC digit 1 */
1404 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1405 /* MNC digit 3 | MCC digit 3 */
1406 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1407 (mcc[2] - '0');
1408 /* MNC digit 2 | MNC digit 1 */
1409 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1410 }
1411
1412 os_free(bss->anqp_3gpp_cell_net);
1413 bss->anqp_3gpp_cell_net = info;
1414 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1415 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1416 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001417
1418 return 0;
1419
1420fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001421 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1422 line, buf);
1423 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001424 return -1;
1425}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001426
1427
1428static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1429{
1430 struct hostapd_nai_realm_data *realm;
1431 size_t i, j, len;
1432 int *offsets;
1433 char *pos, *end, *rpos;
1434
1435 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1436 sizeof(int));
1437 if (offsets == NULL)
1438 return -1;
1439
1440 for (i = 0; i < bss->nai_realm_count; i++) {
1441 realm = &bss->nai_realm_data[i];
1442 for (j = 0; j < MAX_NAI_REALMS; j++) {
1443 offsets[i * MAX_NAI_REALMS + j] =
1444 realm->realm[j] ?
1445 realm->realm[j] - realm->realm_buf : -1;
1446 }
1447 }
1448
1449 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1450 sizeof(struct hostapd_nai_realm_data));
1451 if (realm == NULL) {
1452 os_free(offsets);
1453 return -1;
1454 }
1455 bss->nai_realm_data = realm;
1456
1457 /* patch the pointers after realloc */
1458 for (i = 0; i < bss->nai_realm_count; i++) {
1459 realm = &bss->nai_realm_data[i];
1460 for (j = 0; j < MAX_NAI_REALMS; j++) {
1461 int offs = offsets[i * MAX_NAI_REALMS + j];
1462 if (offs >= 0)
1463 realm->realm[j] = realm->realm_buf + offs;
1464 else
1465 realm->realm[j] = NULL;
1466 }
1467 }
1468 os_free(offsets);
1469
1470 realm = &bss->nai_realm_data[bss->nai_realm_count];
1471 os_memset(realm, 0, sizeof(*realm));
1472
1473 pos = buf;
1474 realm->encoding = atoi(pos);
1475 pos = os_strchr(pos, ',');
1476 if (pos == NULL)
1477 goto fail;
1478 pos++;
1479
1480 end = os_strchr(pos, ',');
1481 if (end) {
1482 len = end - pos;
1483 *end = '\0';
1484 } else {
1485 len = os_strlen(pos);
1486 }
1487
1488 if (len > MAX_NAI_REALMLEN) {
1489 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1490 "characters)", (int) len, MAX_NAI_REALMLEN);
1491 goto fail;
1492 }
1493 os_memcpy(realm->realm_buf, pos, len);
1494
1495 if (end)
1496 pos = end + 1;
1497 else
1498 pos = NULL;
1499
1500 while (pos && *pos) {
1501 struct hostapd_nai_realm_eap *eap;
1502
1503 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1504 wpa_printf(MSG_ERROR, "Too many EAP methods");
1505 goto fail;
1506 }
1507
1508 eap = &realm->eap_method[realm->eap_method_count];
1509 realm->eap_method_count++;
1510
1511 end = os_strchr(pos, ',');
1512 if (end == NULL)
1513 end = pos + os_strlen(pos);
1514
1515 eap->eap_method = atoi(pos);
1516 for (;;) {
1517 pos = os_strchr(pos, '[');
1518 if (pos == NULL || pos > end)
1519 break;
1520 pos++;
1521 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1522 wpa_printf(MSG_ERROR, "Too many auth params");
1523 goto fail;
1524 }
1525 eap->auth_id[eap->num_auths] = atoi(pos);
1526 pos = os_strchr(pos, ':');
1527 if (pos == NULL || pos > end)
1528 goto fail;
1529 pos++;
1530 eap->auth_val[eap->num_auths] = atoi(pos);
1531 pos = os_strchr(pos, ']');
1532 if (pos == NULL || pos > end)
1533 goto fail;
1534 pos++;
1535 eap->num_auths++;
1536 }
1537
1538 if (*end != ',')
1539 break;
1540
1541 pos = end + 1;
1542 }
1543
1544 /* Split realm list into null terminated realms */
1545 rpos = realm->realm_buf;
1546 i = 0;
1547 while (*rpos) {
1548 if (i >= MAX_NAI_REALMS) {
1549 wpa_printf(MSG_ERROR, "Too many realms");
1550 goto fail;
1551 }
1552 realm->realm[i++] = rpos;
1553 rpos = os_strchr(rpos, ';');
1554 if (rpos == NULL)
1555 break;
1556 *rpos++ = '\0';
1557 }
1558
1559 bss->nai_realm_count++;
1560
1561 return 0;
1562
1563fail:
1564 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1565 return -1;
1566}
1567
Dmitry Shmidt051af732013-10-22 13:52:46 -07001568
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001569static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1570{
1571 char *delim;
1572 u16 infoid;
1573 size_t len;
1574 struct wpabuf *payload;
1575 struct anqp_element *elem;
1576
1577 delim = os_strchr(buf, ':');
1578 if (!delim)
1579 return -1;
1580 delim++;
1581 infoid = atoi(buf);
1582 len = os_strlen(delim);
1583 if (len & 1)
1584 return -1;
1585 len /= 2;
1586 payload = wpabuf_alloc(len);
1587 if (!payload)
1588 return -1;
1589 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1590 wpabuf_free(payload);
1591 return -1;
1592 }
1593
1594 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1595 if (elem->infoid == infoid) {
1596 /* Update existing entry */
1597 wpabuf_free(elem->payload);
1598 elem->payload = payload;
1599 return 0;
1600 }
1601 }
1602
1603 /* Add a new entry */
1604 elem = os_zalloc(sizeof(*elem));
1605 if (!elem) {
1606 wpabuf_free(payload);
1607 return -1;
1608 }
1609 elem->infoid = infoid;
1610 elem->payload = payload;
1611 dl_list_add(&bss->anqp_elem, &elem->list);
1612
1613 return 0;
1614}
1615
1616
Dmitry Shmidt051af732013-10-22 13:52:46 -07001617static int parse_qos_map_set(struct hostapd_bss_config *bss,
1618 char *buf, int line)
1619{
1620 u8 qos_map_set[16 + 2 * 21], count = 0;
1621 char *pos = buf;
1622 int val;
1623
1624 for (;;) {
1625 if (count == sizeof(qos_map_set)) {
1626 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1627 "parameters '%s'", line, buf);
1628 return -1;
1629 }
1630
1631 val = atoi(pos);
1632 if (val > 255 || val < 0) {
1633 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1634 "'%s'", line, buf);
1635 return -1;
1636 }
1637
1638 qos_map_set[count++] = val;
1639 pos = os_strchr(pos, ',');
1640 if (!pos)
1641 break;
1642 pos++;
1643 }
1644
1645 if (count < 16 || count & 1) {
1646 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1647 line, buf);
1648 return -1;
1649 }
1650
1651 os_memcpy(bss->qos_map_set, qos_map_set, count);
1652 bss->qos_map_set_len = count;
1653
1654 return 0;
1655}
1656
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001657#endif /* CONFIG_INTERWORKING */
1658
1659
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001660#ifdef CONFIG_HS20
1661static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1662 int line)
1663{
1664 u8 *conn_cap;
1665 char *pos;
1666
1667 if (bss->hs20_connection_capability_len >= 0xfff0)
1668 return -1;
1669
1670 conn_cap = os_realloc(bss->hs20_connection_capability,
1671 bss->hs20_connection_capability_len + 4);
1672 if (conn_cap == NULL)
1673 return -1;
1674
1675 bss->hs20_connection_capability = conn_cap;
1676 conn_cap += bss->hs20_connection_capability_len;
1677 pos = buf;
1678 conn_cap[0] = atoi(pos);
1679 pos = os_strchr(pos, ':');
1680 if (pos == NULL)
1681 return -1;
1682 pos++;
1683 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1684 pos = os_strchr(pos, ':');
1685 if (pos == NULL)
1686 return -1;
1687 pos++;
1688 conn_cap[3] = atoi(pos);
1689 bss->hs20_connection_capability_len += 4;
1690
1691 return 0;
1692}
1693
1694
1695static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1696 int line)
1697{
1698 u8 *wan_metrics;
1699 char *pos;
1700
1701 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1702
1703 wan_metrics = os_zalloc(13);
1704 if (wan_metrics == NULL)
1705 return -1;
1706
1707 pos = buf;
1708 /* WAN Info */
1709 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1710 goto fail;
1711 pos += 2;
1712 if (*pos != ':')
1713 goto fail;
1714 pos++;
1715
1716 /* Downlink Speed */
1717 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1718 pos = os_strchr(pos, ':');
1719 if (pos == NULL)
1720 goto fail;
1721 pos++;
1722
1723 /* Uplink Speed */
1724 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1725 pos = os_strchr(pos, ':');
1726 if (pos == NULL)
1727 goto fail;
1728 pos++;
1729
1730 /* Downlink Load */
1731 wan_metrics[9] = atoi(pos);
1732 pos = os_strchr(pos, ':');
1733 if (pos == NULL)
1734 goto fail;
1735 pos++;
1736
1737 /* Uplink Load */
1738 wan_metrics[10] = atoi(pos);
1739 pos = os_strchr(pos, ':');
1740 if (pos == NULL)
1741 goto fail;
1742 pos++;
1743
1744 /* LMD */
1745 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1746
1747 os_free(bss->hs20_wan_metrics);
1748 bss->hs20_wan_metrics = wan_metrics;
1749
1750 return 0;
1751
1752fail:
1753 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001754 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001755 os_free(wan_metrics);
1756 return -1;
1757}
1758
1759
1760static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1761 char *pos, int line)
1762{
1763 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1764 &bss->hs20_oper_friendly_name_count, pos)) {
1765 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1766 "hs20_oper_friendly_name '%s'", line, pos);
1767 return -1;
1768 }
1769 return 0;
1770}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001771
1772
1773static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1774{
1775 struct hs20_icon *icon;
1776 char *end;
1777
1778 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1779 sizeof(struct hs20_icon));
1780 if (icon == NULL)
1781 return -1;
1782 bss->hs20_icons = icon;
1783 icon = &bss->hs20_icons[bss->hs20_icons_count];
1784 os_memset(icon, 0, sizeof(*icon));
1785
1786 icon->width = atoi(pos);
1787 pos = os_strchr(pos, ':');
1788 if (pos == NULL)
1789 return -1;
1790 pos++;
1791
1792 icon->height = atoi(pos);
1793 pos = os_strchr(pos, ':');
1794 if (pos == NULL)
1795 return -1;
1796 pos++;
1797
1798 end = os_strchr(pos, ':');
1799 if (end == NULL || end - pos > 3)
1800 return -1;
1801 os_memcpy(icon->language, pos, end - pos);
1802 pos = end + 1;
1803
1804 end = os_strchr(pos, ':');
1805 if (end == NULL || end - pos > 255)
1806 return -1;
1807 os_memcpy(icon->type, pos, end - pos);
1808 pos = end + 1;
1809
1810 end = os_strchr(pos, ':');
1811 if (end == NULL || end - pos > 255)
1812 return -1;
1813 os_memcpy(icon->name, pos, end - pos);
1814 pos = end + 1;
1815
1816 if (os_strlen(pos) > 255)
1817 return -1;
1818 os_memcpy(icon->file, pos, os_strlen(pos));
1819
1820 bss->hs20_icons_count++;
1821
1822 return 0;
1823}
1824
1825
1826static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1827 char *pos, int line)
1828{
1829 size_t slen;
1830 char *str;
1831
1832 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001833 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001834 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001835 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001836 return -1;
1837 }
1838
1839 os_memcpy(bss->osu_ssid, str, slen);
1840 bss->osu_ssid_len = slen;
1841 os_free(str);
1842
1843 return 0;
1844}
1845
1846
1847static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1848 char *pos, int line)
1849{
1850 struct hs20_osu_provider *p;
1851
1852 p = os_realloc_array(bss->hs20_osu_providers,
1853 bss->hs20_osu_providers_count + 1, sizeof(*p));
1854 if (p == NULL)
1855 return -1;
1856
1857 bss->hs20_osu_providers = p;
1858 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1859 bss->hs20_osu_providers_count++;
1860 os_memset(bss->last_osu, 0, sizeof(*p));
1861 bss->last_osu->server_uri = os_strdup(pos);
1862
1863 return 0;
1864}
1865
1866
1867static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1868 char *pos, int line)
1869{
1870 if (bss->last_osu == NULL) {
1871 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1872 return -1;
1873 }
1874
1875 if (parse_lang_string(&bss->last_osu->friendly_name,
1876 &bss->last_osu->friendly_name_count, pos)) {
1877 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1878 line, pos);
1879 return -1;
1880 }
1881
1882 return 0;
1883}
1884
1885
1886static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1887 char *pos, int line)
1888{
1889 if (bss->last_osu == NULL) {
1890 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1891 return -1;
1892 }
1893
1894 os_free(bss->last_osu->osu_nai);
1895 bss->last_osu->osu_nai = os_strdup(pos);
1896 if (bss->last_osu->osu_nai == NULL)
1897 return -1;
1898
1899 return 0;
1900}
1901
1902
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001903static int hs20_parse_osu_nai2(struct hostapd_bss_config *bss,
1904 char *pos, int line)
1905{
1906 if (bss->last_osu == NULL) {
1907 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1908 return -1;
1909 }
1910
1911 os_free(bss->last_osu->osu_nai2);
1912 bss->last_osu->osu_nai2 = os_strdup(pos);
1913 if (bss->last_osu->osu_nai2 == NULL)
1914 return -1;
1915 bss->hs20_osu_providers_nai_count++;
1916
1917 return 0;
1918}
1919
1920
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001921static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1922 int line)
1923{
1924 if (bss->last_osu == NULL) {
1925 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1926 return -1;
1927 }
1928
1929 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1930 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1931 return -1;
1932 }
1933
1934 return 0;
1935}
1936
1937
1938static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1939 int line)
1940{
1941 char **n;
1942 struct hs20_osu_provider *p = bss->last_osu;
1943
1944 if (p == NULL) {
1945 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1946 return -1;
1947 }
1948
1949 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1950 if (n == NULL)
1951 return -1;
1952 p->icons = n;
1953 p->icons[p->icons_count] = os_strdup(pos);
1954 if (p->icons[p->icons_count] == NULL)
1955 return -1;
1956 p->icons_count++;
1957
1958 return 0;
1959}
1960
1961
1962static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1963 char *pos, int line)
1964{
1965 if (bss->last_osu == NULL) {
1966 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1967 return -1;
1968 }
1969
1970 if (parse_lang_string(&bss->last_osu->service_desc,
1971 &bss->last_osu->service_desc_count, pos)) {
1972 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1973 line, pos);
1974 return -1;
1975 }
1976
1977 return 0;
1978}
1979
Roshan Pius3a1667e2018-07-03 15:17:14 -07001980
1981static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
1982 int line)
1983{
1984 char **n;
1985
1986 n = os_realloc_array(bss->hs20_operator_icon,
1987 bss->hs20_operator_icon_count + 1, sizeof(char *));
1988 if (!n)
1989 return -1;
1990 bss->hs20_operator_icon = n;
1991 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
1992 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
1993 return -1;
1994 bss->hs20_operator_icon_count++;
1995
1996 return 0;
1997}
1998
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001999#endif /* CONFIG_HS20 */
2000
2001
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002002#ifdef CONFIG_ACS
2003static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
2004 char *pos)
2005{
2006 struct acs_bias *bias = NULL, *tmp;
2007 unsigned int num = 0;
2008 char *end;
2009
2010 while (*pos) {
2011 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2012 if (!tmp)
2013 goto fail;
2014 bias = tmp;
2015
2016 bias[num].channel = atoi(pos);
2017 if (bias[num].channel <= 0)
2018 goto fail;
2019 pos = os_strchr(pos, ':');
2020 if (!pos)
2021 goto fail;
2022 pos++;
2023 bias[num].bias = strtod(pos, &end);
2024 if (end == pos || bias[num].bias < 0.0)
2025 goto fail;
2026 pos = end;
2027 if (*pos != ' ' && *pos != '\0')
2028 goto fail;
2029 num++;
2030 }
2031
2032 os_free(conf->acs_chan_bias);
2033 conf->acs_chan_bias = bias;
2034 conf->num_acs_chan_bias = num;
2035
2036 return 0;
2037fail:
2038 os_free(bias);
2039 return -1;
2040}
2041#endif /* CONFIG_ACS */
2042
2043
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002044static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2045 const char *val)
2046{
2047 struct wpabuf *elems;
2048
2049 if (val[0] == '\0') {
2050 wpabuf_free(*buf);
2051 *buf = NULL;
2052 return 0;
2053 }
2054
2055 elems = wpabuf_parse_bin(val);
2056 if (!elems) {
2057 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2058 line, name, val);
2059 return -1;
2060 }
2061
2062 wpabuf_free(*buf);
2063 *buf = elems;
2064
2065 return 0;
2066}
2067
2068
Dmitry Shmidt29333592017-01-09 12:27:11 -08002069#ifdef CONFIG_FILS
2070static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2071{
2072 struct fils_realm *realm;
2073 size_t len;
2074
2075 len = os_strlen(val);
2076 realm = os_zalloc(sizeof(*realm) + len + 1);
2077 if (!realm)
2078 return -1;
2079
2080 os_memcpy(realm->realm, val, len);
2081 if (fils_domain_name_hash(val, realm->hash) < 0) {
2082 os_free(realm);
2083 return -1;
2084 }
2085 dl_list_add_tail(&bss->fils_realms, &realm->list);
2086
2087 return 0;
2088}
2089#endif /* CONFIG_FILS */
2090
2091
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002092#ifdef EAP_SERVER
2093static unsigned int parse_tls_flags(const char *val)
2094{
2095 unsigned int flags = 0;
2096
Roshan Pius3a1667e2018-07-03 15:17:14 -07002097 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2098 * This can be enabled by default once the implementation has been fully
2099 * completed and tested with other implementations. */
2100 flags |= TLS_CONN_DISABLE_TLSv1_3;
2101
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002102 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2103 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2104 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2105 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2106 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2107 flags |= TLS_CONN_DISABLE_TLSv1_0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002108 if (os_strstr(val, "[ENABLE-TLSv1.0]"))
2109 flags |= TLS_CONN_ENABLE_TLSv1_0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002110 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2111 flags |= TLS_CONN_DISABLE_TLSv1_1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002112 if (os_strstr(val, "[ENABLE-TLSv1.1]"))
2113 flags |= TLS_CONN_ENABLE_TLSv1_1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002114 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2115 flags |= TLS_CONN_DISABLE_TLSv1_2;
Hai Shalom74f70d42019-02-11 14:42:39 -08002116 if (os_strstr(val, "[ENABLE-TLSv1.2]"))
2117 flags |= TLS_CONN_ENABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002118 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2119 flags |= TLS_CONN_DISABLE_TLSv1_3;
2120 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2121 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002122 if (os_strstr(val, "[SUITEB]"))
2123 flags |= TLS_CONN_SUITEB;
2124 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2125 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2126
2127 return flags;
2128}
2129#endif /* EAP_SERVER */
2130
2131
Hai Shalom81f62d82019-07-22 12:10:00 -07002132#ifdef CONFIG_AIRTIME_POLICY
2133static int add_airtime_weight(struct hostapd_bss_config *bss, char *value)
2134{
2135 struct airtime_sta_weight *wt;
2136 char *pos, *next;
2137
2138 wt = os_zalloc(sizeof(*wt));
2139 if (!wt)
2140 return -1;
2141
2142 /* 02:01:02:03:04:05 10 */
2143 pos = value;
2144 next = os_strchr(pos, ' ');
2145 if (next)
2146 *next++ = '\0';
2147 if (!next || hwaddr_aton(pos, wt->addr)) {
2148 wpa_printf(MSG_ERROR, "Invalid station address: '%s'", pos);
2149 os_free(wt);
2150 return -1;
2151 }
2152
2153 pos = next;
2154 wt->weight = atoi(pos);
2155 if (!wt->weight) {
2156 wpa_printf(MSG_ERROR, "Invalid weight: '%s'", pos);
2157 os_free(wt);
2158 return -1;
2159 }
2160
2161 wt->next = bss->airtime_weight_list;
2162 bss->airtime_weight_list = wt;
2163 return 0;
2164}
2165#endif /* CONFIG_AIRTIME_POLICY */
2166
2167
Roshan Pius3a1667e2018-07-03 15:17:14 -07002168#ifdef CONFIG_SAE
2169static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2170{
2171 struct sae_password_entry *pw;
2172 const char *pos = val, *pos2, *end = NULL;
2173
2174 pw = os_zalloc(sizeof(*pw));
2175 if (!pw)
2176 return -1;
2177 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2178
2179 pos2 = os_strstr(pos, "|mac=");
2180 if (pos2) {
2181 end = pos2;
2182 pos2 += 5;
2183 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2184 goto fail;
2185 pos = pos2 + ETH_ALEN * 3 - 1;
2186 }
2187
Hai Shalom021b0b52019-04-10 11:17:58 -07002188 pos2 = os_strstr(pos, "|vlanid=");
2189 if (pos2) {
2190 if (!end)
2191 end = pos2;
2192 pos2 += 8;
2193 pw->vlan_id = atoi(pos2);
2194 }
2195
Hai Shalom899fcc72020-10-19 14:38:18 -07002196#ifdef CONFIG_SAE_PK
2197 pos2 = os_strstr(pos, "|pk=");
2198 if (pos2) {
2199 const char *epos;
2200 char *tmp;
2201
2202 if (!end)
2203 end = pos2;
2204 pos2 += 4;
2205 epos = os_strchr(pos2, '|');
2206 if (epos) {
2207 tmp = os_malloc(epos - pos2 + 1);
2208 if (!tmp)
2209 goto fail;
2210 os_memcpy(tmp, pos2, epos - pos2);
2211 tmp[epos - pos2] = '\0';
2212 } else {
2213 tmp = os_strdup(pos2);
2214 if (!tmp)
2215 goto fail;
2216 }
2217
2218 pw->pk = sae_parse_pk(tmp);
2219 str_clear_free(tmp);
2220 if (!pw->pk)
2221 goto fail;
2222 }
2223#endif /* CONFIG_SAE_PK */
2224
Roshan Pius3a1667e2018-07-03 15:17:14 -07002225 pos2 = os_strstr(pos, "|id=");
2226 if (pos2) {
2227 if (!end)
2228 end = pos2;
2229 pos2 += 4;
2230 pw->identifier = os_strdup(pos2);
2231 if (!pw->identifier)
2232 goto fail;
2233 }
2234
2235 if (!end) {
2236 pw->password = os_strdup(val);
2237 if (!pw->password)
2238 goto fail;
2239 } else {
2240 pw->password = os_malloc(end - val + 1);
2241 if (!pw->password)
2242 goto fail;
2243 os_memcpy(pw->password, val, end - val);
2244 pw->password[end - val] = '\0';
2245 }
2246
Hai Shalom899fcc72020-10-19 14:38:18 -07002247#ifdef CONFIG_SAE_PK
2248 if (pw->pk &&
2249#ifdef CONFIG_TESTING_OPTIONS
2250 !bss->sae_pk_password_check_skip &&
2251#endif /* CONFIG_TESTING_OPTIONS */
2252 !sae_pk_valid_password(pw->password)) {
2253 wpa_printf(MSG_INFO,
2254 "Invalid SAE password for a SAE-PK sae_password entry");
2255 goto fail;
2256 }
2257#endif /* CONFIG_SAE_PK */
2258
Roshan Pius3a1667e2018-07-03 15:17:14 -07002259 pw->next = bss->sae_passwords;
2260 bss->sae_passwords = pw;
2261
2262 return 0;
2263fail:
2264 str_clear_free(pw->password);
2265 os_free(pw->identifier);
Hai Shalom899fcc72020-10-19 14:38:18 -07002266#ifdef CONFIG_SAE_PK
2267 sae_deinit_pk(pw->pk);
2268#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002269 os_free(pw);
2270 return -1;
2271}
2272#endif /* CONFIG_SAE */
2273
2274
Hai Shalom81f62d82019-07-22 12:10:00 -07002275#ifdef CONFIG_DPP2
2276static int hostapd_dpp_controller_parse(struct hostapd_bss_config *bss,
2277 const char *pos)
2278{
2279 struct dpp_controller_conf *conf;
2280 char *val;
2281
2282 conf = os_zalloc(sizeof(*conf));
2283 if (!conf)
2284 return -1;
2285 val = get_param(pos, "ipaddr=");
2286 if (!val || hostapd_parse_ip_addr(val, &conf->ipaddr))
2287 goto fail;
2288 os_free(val);
2289 val = get_param(pos, "pkhash=");
2290 if (!val || os_strlen(val) != 2 * SHA256_MAC_LEN ||
2291 hexstr2bin(val, conf->pkhash, SHA256_MAC_LEN) < 0)
2292 goto fail;
2293 os_free(val);
2294 conf->next = bss->dpp_controller;
2295 bss->dpp_controller = conf;
2296 return 0;
2297fail:
2298 os_free(val);
2299 os_free(conf);
2300 return -1;
2301}
2302#endif /* CONFIG_DPP2 */
2303
2304
Dmitry Shmidt04949592012-07-19 12:16:46 -07002305static int hostapd_config_fill(struct hostapd_config *conf,
2306 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002307 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002308{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002309 if (os_strcmp(buf, "interface") == 0) {
2310 os_strlcpy(conf->bss[0]->iface, pos,
2311 sizeof(conf->bss[0]->iface));
2312 } else if (os_strcmp(buf, "bridge") == 0) {
2313 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2314 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2315 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2316 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2317 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2318 } else if (os_strcmp(buf, "driver") == 0) {
2319 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002320 const struct wpa_driver_ops *driver = NULL;
2321
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002322 for (j = 0; wpa_drivers[j]; j++) {
2323 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002324 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002325 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002326 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002327 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002328 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002329 wpa_printf(MSG_ERROR,
2330 "Line %d: invalid/unknown driver '%s'",
2331 line, pos);
2332 return 1;
2333 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002334 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002335 } else if (os_strcmp(buf, "driver_params") == 0) {
2336 os_free(conf->driver_params);
2337 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002338 } else if (os_strcmp(buf, "debug") == 0) {
2339 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2340 line);
2341 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2342 bss->logger_syslog_level = atoi(pos);
2343 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2344 bss->logger_stdout_level = atoi(pos);
2345 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2346 bss->logger_syslog = atoi(pos);
2347 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2348 bss->logger_stdout = atoi(pos);
2349 } else if (os_strcmp(buf, "dump_file") == 0) {
2350 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2351 line);
2352 } else if (os_strcmp(buf, "ssid") == 0) {
2353 bss->ssid.ssid_len = os_strlen(pos);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002354 if (bss->ssid.ssid_len > SSID_MAX_LEN ||
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002355 bss->ssid.ssid_len < 1) {
2356 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2357 line, pos);
2358 return 1;
2359 }
2360 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
2361 bss->ssid.ssid_set = 1;
2362 } else if (os_strcmp(buf, "ssid2") == 0) {
2363 size_t slen;
2364 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002365 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002366 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2367 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002368 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002369 return 1;
2370 }
2371 os_memcpy(bss->ssid.ssid, str, slen);
2372 bss->ssid.ssid_len = slen;
2373 bss->ssid.ssid_set = 1;
2374 os_free(str);
2375 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2376 bss->ssid.utf8_ssid = atoi(pos) > 0;
2377 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002378 enum macaddr_acl acl = atoi(pos);
2379
2380 if (acl != ACCEPT_UNLESS_DENIED &&
2381 acl != DENY_UNLESS_ACCEPTED &&
2382 acl != USE_EXTERNAL_RADIUS_AUTH) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002383 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002384 line, acl);
2385 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002386 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002387 bss->macaddr_acl = acl;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002388 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2389 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2390 &bss->num_accept_mac)) {
2391 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2392 line, pos);
2393 return 1;
2394 }
2395 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2396 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2397 &bss->num_deny_mac)) {
2398 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2399 line, pos);
2400 return 1;
2401 }
2402 } else if (os_strcmp(buf, "wds_sta") == 0) {
2403 bss->wds_sta = atoi(pos);
2404 } else if (os_strcmp(buf, "start_disabled") == 0) {
2405 bss->start_disabled = atoi(pos);
2406 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2407 bss->isolate = atoi(pos);
2408 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2409 bss->ap_max_inactivity = atoi(pos);
2410 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2411 bss->skip_inactivity_poll = atoi(pos);
2412 } else if (os_strcmp(buf, "country_code") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002413 if (pos[0] < 'A' || pos[0] > 'Z' ||
2414 pos[1] < 'A' || pos[1] > 'Z') {
2415 wpa_printf(MSG_ERROR,
2416 "Line %d: Invalid country_code '%s'",
2417 line, pos);
2418 return 1;
2419 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002420 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002421 } else if (os_strcmp(buf, "country3") == 0) {
2422 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002423 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2424 conf->ieee80211d = atoi(pos);
2425 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2426 conf->ieee80211h = atoi(pos);
2427 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2428 bss->ieee802_1x = atoi(pos);
2429 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002430 int eapol_version = atoi(pos);
2431
Hai Shalom81f62d82019-07-22 12:10:00 -07002432#ifdef CONFIG_MACSEC
2433 if (eapol_version < 1 || eapol_version > 3) {
2434#else /* CONFIG_MACSEC */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002435 if (eapol_version < 1 || eapol_version > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002436#endif /* CONFIG_MACSEC */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002437 wpa_printf(MSG_ERROR,
2438 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002439 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002440 return 1;
2441 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002442 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002443 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002444#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002445 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2446 bss->eap_server = atoi(pos);
2447 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2448 } else if (os_strcmp(buf, "eap_server") == 0) {
2449 bss->eap_server = atoi(pos);
2450 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2451 if (hostapd_config_read_eap_user(pos, bss))
2452 return 1;
2453 } else if (os_strcmp(buf, "ca_cert") == 0) {
2454 os_free(bss->ca_cert);
2455 bss->ca_cert = os_strdup(pos);
2456 } else if (os_strcmp(buf, "server_cert") == 0) {
2457 os_free(bss->server_cert);
2458 bss->server_cert = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002459 } else if (os_strcmp(buf, "server_cert2") == 0) {
2460 os_free(bss->server_cert2);
2461 bss->server_cert2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002462 } else if (os_strcmp(buf, "private_key") == 0) {
2463 os_free(bss->private_key);
2464 bss->private_key = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002465 } else if (os_strcmp(buf, "private_key2") == 0) {
2466 os_free(bss->private_key2);
2467 bss->private_key2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002468 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2469 os_free(bss->private_key_passwd);
2470 bss->private_key_passwd = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002471 } else if (os_strcmp(buf, "private_key_passwd2") == 0) {
2472 os_free(bss->private_key_passwd2);
2473 bss->private_key_passwd2 = os_strdup(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07002474 } else if (os_strcmp(buf, "check_cert_subject") == 0) {
2475 if (!pos[0]) {
2476 wpa_printf(MSG_ERROR, "Line %d: unknown check_cert_subject '%s'",
2477 line, pos);
2478 return 1;
2479 }
2480 os_free(bss->check_cert_subject);
2481 bss->check_cert_subject = os_strdup(pos);
2482 if (!bss->check_cert_subject)
2483 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002484 } else if (os_strcmp(buf, "check_crl") == 0) {
2485 bss->check_crl = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002486 } else if (os_strcmp(buf, "check_crl_strict") == 0) {
2487 bss->check_crl_strict = atoi(pos);
2488 } else if (os_strcmp(buf, "crl_reload_interval") == 0) {
2489 bss->crl_reload_interval = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002490 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2491 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002492 } else if (os_strcmp(buf, "tls_flags") == 0) {
2493 bss->tls_flags = parse_tls_flags(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002494 } else if (os_strcmp(buf, "max_auth_rounds") == 0) {
2495 bss->max_auth_rounds = atoi(pos);
2496 } else if (os_strcmp(buf, "max_auth_rounds_short") == 0) {
2497 bss->max_auth_rounds_short = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002498 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2499 os_free(bss->ocsp_stapling_response);
2500 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002501 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2502 os_free(bss->ocsp_stapling_response_multi);
2503 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002504 } else if (os_strcmp(buf, "dh_file") == 0) {
2505 os_free(bss->dh_file);
2506 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002507 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2508 os_free(bss->openssl_ciphers);
2509 bss->openssl_ciphers = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002510 } else if (os_strcmp(buf, "openssl_ecdh_curves") == 0) {
2511 os_free(bss->openssl_ecdh_curves);
2512 bss->openssl_ecdh_curves = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002513 } else if (os_strcmp(buf, "fragment_size") == 0) {
2514 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002515#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002516 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2517 os_free(bss->pac_opaque_encr_key);
2518 bss->pac_opaque_encr_key = os_malloc(16);
2519 if (bss->pac_opaque_encr_key == NULL) {
2520 wpa_printf(MSG_ERROR,
2521 "Line %d: No memory for pac_opaque_encr_key",
2522 line);
2523 return 1;
2524 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2525 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2526 line);
2527 return 1;
2528 }
2529 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2530 size_t idlen = os_strlen(pos);
2531 if (idlen & 1) {
2532 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2533 line);
2534 return 1;
2535 }
2536 os_free(bss->eap_fast_a_id);
2537 bss->eap_fast_a_id = os_malloc(idlen / 2);
2538 if (bss->eap_fast_a_id == NULL ||
2539 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2540 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2541 line);
2542 os_free(bss->eap_fast_a_id);
2543 bss->eap_fast_a_id = NULL;
2544 return 1;
2545 } else {
2546 bss->eap_fast_a_id_len = idlen / 2;
2547 }
2548 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2549 os_free(bss->eap_fast_a_id_info);
2550 bss->eap_fast_a_id_info = os_strdup(pos);
2551 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2552 bss->eap_fast_prov = atoi(pos);
2553 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2554 bss->pac_key_lifetime = atoi(pos);
2555 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2556 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557#endif /* EAP_SERVER_FAST */
Hai Shalom81f62d82019-07-22 12:10:00 -07002558#ifdef EAP_SERVER_TEAP
2559 } else if (os_strcmp(buf, "eap_teap_auth") == 0) {
2560 int val = atoi(pos);
2561
Hai Shalom899fcc72020-10-19 14:38:18 -07002562 if (val < 0 || val > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002563 wpa_printf(MSG_ERROR,
2564 "Line %d: Invalid eap_teap_auth value",
2565 line);
2566 return 1;
2567 }
2568 bss->eap_teap_auth = val;
2569 } else if (os_strcmp(buf, "eap_teap_pac_no_inner") == 0) {
2570 bss->eap_teap_pac_no_inner = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002571 } else if (os_strcmp(buf, "eap_teap_separate_result") == 0) {
2572 bss->eap_teap_separate_result = atoi(pos);
2573 } else if (os_strcmp(buf, "eap_teap_id") == 0) {
2574 bss->eap_teap_id = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002575#endif /* EAP_SERVER_TEAP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002577 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2578 os_free(bss->eap_sim_db);
2579 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002580 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2581 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002582 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2583 bss->eap_sim_aka_result_ind = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002584 } else if (os_strcmp(buf, "eap_sim_id") == 0) {
2585 bss->eap_sim_id = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586#endif /* EAP_SERVER_SIM */
2587#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002588 } else if (os_strcmp(buf, "tnc") == 0) {
2589 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002590#endif /* EAP_SERVER_TNC */
2591#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002592 } else if (os_strcmp(buf, "pwd_group") == 0) {
2593 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002594#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002595#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002596 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2597 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002598#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002599#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002600 } else if (os_strcmp(buf, "eap_message") == 0) {
2601 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002602 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002603 bss->eap_req_id_text = os_strdup(pos);
2604 if (bss->eap_req_id_text == NULL) {
2605 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2606 line);
2607 return 1;
2608 }
2609 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2610 term = os_strstr(bss->eap_req_id_text, "\\0");
2611 if (term) {
2612 *term++ = '\0';
2613 os_memmove(term, term + 1,
2614 bss->eap_req_id_text_len -
2615 (term - bss->eap_req_id_text) - 1);
2616 bss->eap_req_id_text_len--;
2617 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002618 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2619 bss->erp_send_reauth_start = atoi(pos);
2620 } else if (os_strcmp(buf, "erp_domain") == 0) {
2621 os_free(bss->erp_domain);
2622 bss->erp_domain = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002623#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002624 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002625 int val = atoi(pos);
2626
2627 if (val < 0 || val > 13) {
2628 wpa_printf(MSG_ERROR,
2629 "Line %d: invalid WEP key len %d (= %d bits)",
2630 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002631 return 1;
2632 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002633 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002634 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002635 int val = atoi(pos);
2636
2637 if (val < 0 || val > 13) {
2638 wpa_printf(MSG_ERROR,
2639 "Line %d: invalid WEP key len %d (= %d bits)",
2640 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002641 return 1;
2642 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002643 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002644 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2645 bss->wep_rekeying_period = atoi(pos);
2646 if (bss->wep_rekeying_period < 0) {
2647 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2648 line, bss->wep_rekeying_period);
2649 return 1;
2650 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002651#endif /* CONFIG_WEP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002652 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2653 bss->eap_reauth_period = atoi(pos);
2654 if (bss->eap_reauth_period < 0) {
2655 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2656 line, bss->eap_reauth_period);
2657 return 1;
2658 }
2659 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2660 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002661#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002662 } else if (os_strcmp(buf, "iapp_interface") == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07002663 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002664#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002665 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2666 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2667 wpa_printf(MSG_ERROR,
2668 "Line %d: invalid IP address '%s'",
2669 line, pos);
2670 return 1;
2671 }
2672 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002673 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002674 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002676 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2677 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2678 wpa_printf(MSG_ERROR,
2679 "Line %d: invalid IP address '%s'",
2680 line, pos);
2681 return 1;
2682 }
2683 bss->radius->force_client_addr = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002684 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2685 if (hostapd_config_read_radius_addr(
2686 &bss->radius->auth_servers,
2687 &bss->radius->num_auth_servers, pos, 1812,
2688 &bss->radius->auth_server)) {
2689 wpa_printf(MSG_ERROR,
2690 "Line %d: invalid IP address '%s'",
2691 line, pos);
2692 return 1;
2693 }
2694 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002695 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2696 if (hostapd_parse_ip_addr(pos,
2697 &bss->radius->auth_server->addr)) {
2698 wpa_printf(MSG_ERROR,
2699 "Line %d: invalid IP address '%s'",
2700 line, pos);
2701 return 1;
2702 }
2703 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002704 os_strcmp(buf, "auth_server_port") == 0) {
2705 bss->radius->auth_server->port = atoi(pos);
2706 } else if (bss->radius->auth_server &&
2707 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2708 int len = os_strlen(pos);
2709 if (len == 0) {
2710 /* RFC 2865, Ch. 3 */
2711 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2712 line);
2713 return 1;
2714 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002715 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002716 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2717 bss->radius->auth_server->shared_secret_len = len;
2718 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2719 if (hostapd_config_read_radius_addr(
2720 &bss->radius->acct_servers,
2721 &bss->radius->num_acct_servers, pos, 1813,
2722 &bss->radius->acct_server)) {
2723 wpa_printf(MSG_ERROR,
2724 "Line %d: invalid IP address '%s'",
2725 line, pos);
2726 return 1;
2727 }
2728 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002729 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2730 if (hostapd_parse_ip_addr(pos,
2731 &bss->radius->acct_server->addr)) {
2732 wpa_printf(MSG_ERROR,
2733 "Line %d: invalid IP address '%s'",
2734 line, pos);
2735 return 1;
2736 }
2737 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002738 os_strcmp(buf, "acct_server_port") == 0) {
2739 bss->radius->acct_server->port = atoi(pos);
2740 } else if (bss->radius->acct_server &&
2741 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2742 int len = os_strlen(pos);
2743 if (len == 0) {
2744 /* RFC 2865, Ch. 3 */
2745 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2746 line);
2747 return 1;
2748 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002749 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002750 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2751 bss->radius->acct_server->shared_secret_len = len;
2752 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2753 bss->radius->retry_primary_interval = atoi(pos);
2754 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2755 bss->acct_interim_interval = atoi(pos);
2756 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2757 bss->radius_request_cui = atoi(pos);
2758 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2759 struct hostapd_radius_attr *attr, *a;
2760 attr = hostapd_parse_radius_attr(pos);
2761 if (attr == NULL) {
2762 wpa_printf(MSG_ERROR,
2763 "Line %d: invalid radius_auth_req_attr",
2764 line);
2765 return 1;
2766 } else if (bss->radius_auth_req_attr == NULL) {
2767 bss->radius_auth_req_attr = attr;
2768 } else {
2769 a = bss->radius_auth_req_attr;
2770 while (a->next)
2771 a = a->next;
2772 a->next = attr;
2773 }
2774 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2775 struct hostapd_radius_attr *attr, *a;
2776 attr = hostapd_parse_radius_attr(pos);
2777 if (attr == NULL) {
2778 wpa_printf(MSG_ERROR,
2779 "Line %d: invalid radius_acct_req_attr",
2780 line);
2781 return 1;
2782 } else if (bss->radius_acct_req_attr == NULL) {
2783 bss->radius_acct_req_attr = attr;
2784 } else {
2785 a = bss->radius_acct_req_attr;
2786 while (a->next)
2787 a = a->next;
2788 a->next = attr;
2789 }
Hai Shalomc3565922019-10-28 11:58:20 -07002790 } else if (os_strcmp(buf, "radius_req_attr_sqlite") == 0) {
2791 os_free(bss->radius_req_attr_sqlite);
2792 bss->radius_req_attr_sqlite = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002793 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2794 bss->radius_das_port = atoi(pos);
2795 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2796 if (hostapd_parse_das_client(bss, pos) < 0) {
2797 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2798 line);
2799 return 1;
2800 }
2801 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2802 bss->radius_das_time_window = atoi(pos);
2803 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2804 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002805 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2806 0) {
2807 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002809 } else if (os_strcmp(buf, "auth_algs") == 0) {
2810 bss->auth_algs = atoi(pos);
2811 if (bss->auth_algs == 0) {
2812 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2813 line);
2814 return 1;
2815 }
2816 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2817 bss->max_num_sta = atoi(pos);
2818 if (bss->max_num_sta < 0 ||
2819 bss->max_num_sta > MAX_STA_COUNT) {
2820 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2821 line, bss->max_num_sta, MAX_STA_COUNT);
2822 return 1;
2823 }
2824 } else if (os_strcmp(buf, "wpa") == 0) {
2825 bss->wpa = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002826 } else if (os_strcmp(buf, "extended_key_id") == 0) {
2827 int val = atoi(pos);
2828
2829 if (val < 0 || val > 2) {
2830 wpa_printf(MSG_ERROR,
2831 "Line %d: Invalid extended_key_id=%d; allowed range 0..2",
2832 line, val);
2833 return 1;
2834 }
2835 bss->extended_key_id = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002836 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2837 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002838 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002839 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2840 bss->wpa_strict_rekey = atoi(pos);
2841 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2842 bss->wpa_gmk_rekey = atoi(pos);
2843 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2844 bss->wpa_ptk_rekey = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002845 } else if (os_strcmp(buf, "wpa_deny_ptk0_rekey") == 0) {
2846 bss->wpa_deny_ptk0_rekey = atoi(pos);
2847 if (bss->wpa_deny_ptk0_rekey < 0 ||
2848 bss->wpa_deny_ptk0_rekey > 2) {
2849 wpa_printf(MSG_ERROR,
2850 "Line %d: Invalid wpa_deny_ptk0_rekey=%d; allowed range 0..2",
2851 line, bss->wpa_deny_ptk0_rekey);
2852 return 1;
2853 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002854 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2855 char *endp;
2856 unsigned long val = strtoul(pos, &endp, 0);
2857
2858 if (*endp || val < 1 || val > (u32) -1) {
2859 wpa_printf(MSG_ERROR,
2860 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2861 line, val);
2862 return 1;
2863 }
2864 bss->wpa_group_update_count = (u32) val;
2865 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2866 char *endp;
2867 unsigned long val = strtoul(pos, &endp, 0);
2868
2869 if (*endp || val < 1 || val > (u32) -1) {
2870 wpa_printf(MSG_ERROR,
2871 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2872 line, val);
2873 return 1;
2874 }
2875 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002876 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2877 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002878 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2879 int len = os_strlen(pos);
2880 if (len < 8 || len > 63) {
2881 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2882 line, len);
2883 return 1;
2884 }
2885 os_free(bss->ssid.wpa_passphrase);
2886 bss->ssid.wpa_passphrase = os_strdup(pos);
2887 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002888 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002889 bss->ssid.wpa_passphrase_set = 1;
2890 }
2891 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002892 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002893 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2894 if (bss->ssid.wpa_psk == NULL)
2895 return 1;
2896 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2897 pos[PMK_LEN * 2] != '\0') {
2898 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2899 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002900 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002901 return 1;
2902 }
2903 bss->ssid.wpa_psk->group = 1;
2904 os_free(bss->ssid.wpa_passphrase);
2905 bss->ssid.wpa_passphrase = NULL;
2906 bss->ssid.wpa_psk_set = 1;
2907 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2908 os_free(bss->ssid.wpa_psk_file);
2909 bss->ssid.wpa_psk_file = os_strdup(pos);
2910 if (!bss->ssid.wpa_psk_file) {
2911 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2912 line);
2913 return 1;
2914 }
2915 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2916 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2917 if (bss->wpa_key_mgmt == -1)
2918 return 1;
2919 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2920 bss->wpa_psk_radius = atoi(pos);
2921 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2922 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2923 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2924 wpa_printf(MSG_ERROR,
2925 "Line %d: unknown wpa_psk_radius %d",
2926 line, bss->wpa_psk_radius);
2927 return 1;
2928 }
2929 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2930 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2931 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2932 return 1;
2933 if (bss->wpa_pairwise &
2934 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2935 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002936 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002937 return 1;
2938 }
2939 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2940 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2941 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2942 return 1;
2943 if (bss->rsn_pairwise &
2944 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2945 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002946 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002947 return 1;
2948 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002949 } else if (os_strcmp(buf, "group_cipher") == 0) {
2950 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2951 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2952 return 1;
2953 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2954 bss->group_cipher != WPA_CIPHER_CCMP &&
2955 bss->group_cipher != WPA_CIPHER_GCMP &&
2956 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2957 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2958 wpa_printf(MSG_ERROR,
2959 "Line %d: unsupported group cipher suite '%s'",
2960 line, pos);
2961 return 1;
2962 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002963#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002964 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2965 bss->rsn_preauth = atoi(pos);
2966 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002967 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002968 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002969#endif /* CONFIG_RSN_PREAUTH */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002970 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002971 wpa_printf(MSG_INFO,
2972 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002973#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002974 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2975 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2976 hexstr2bin(pos, bss->mobility_domain,
2977 MOBILITY_DOMAIN_ID_LEN) != 0) {
2978 wpa_printf(MSG_ERROR,
2979 "Line %d: Invalid mobility_domain '%s'",
2980 line, pos);
2981 return 1;
2982 }
2983 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2984 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2985 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2986 wpa_printf(MSG_ERROR,
2987 "Line %d: Invalid r1_key_holder '%s'",
2988 line, pos);
2989 return 1;
2990 }
2991 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002992 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
2993 bss->r0_key_lifetime = atoi(pos) * 60;
2994 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002995 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002996 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
2997 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002998 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2999 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003000 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
3001 bss->rkh_pos_timeout = atoi(pos);
3002 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
3003 bss->rkh_neg_timeout = atoi(pos);
3004 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
3005 bss->rkh_pull_timeout = atoi(pos);
3006 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
3007 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003008 } else if (os_strcmp(buf, "r0kh") == 0) {
3009 if (add_r0kh(bss, pos) < 0) {
3010 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
3011 line, pos);
3012 return 1;
3013 }
3014 } else if (os_strcmp(buf, "r1kh") == 0) {
3015 if (add_r1kh(bss, pos) < 0) {
3016 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
3017 line, pos);
3018 return 1;
3019 }
3020 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
3021 bss->pmk_r1_push = atoi(pos);
3022 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
3023 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003024 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
3025 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003026#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003027#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003028 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
3029 os_free(bss->ctrl_interface);
3030 bss->ctrl_interface = os_strdup(pos);
3031 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003032#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003033 struct group *grp;
3034 char *endp;
3035 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003036
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003037 grp = getgrnam(group);
3038 if (grp) {
3039 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003040 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003041 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
3042 bss->ctrl_interface_gid, group);
3043 return 0;
3044 }
3045
3046 /* Group name not found - try to parse this as gid */
3047 bss->ctrl_interface_gid = strtol(group, &endp, 10);
3048 if (*group == '\0' || *endp != '\0') {
3049 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
3050 line, group);
3051 return 1;
3052 }
3053 bss->ctrl_interface_gid_set = 1;
3054 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
3055 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003056#endif /* CONFIG_NATIVE_WINDOWS */
3057#endif /* CONFIG_NO_CTRL_IFACE */
3058#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003059 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
3060 os_free(bss->radius_server_clients);
3061 bss->radius_server_clients = os_strdup(pos);
3062 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
3063 bss->radius_server_auth_port = atoi(pos);
3064 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
3065 bss->radius_server_acct_port = atoi(pos);
3066 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
3067 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003068#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003069 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
3070 bss->use_pae_group_addr = atoi(pos);
3071 } else if (os_strcmp(buf, "hw_mode") == 0) {
3072 if (os_strcmp(pos, "a") == 0)
3073 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
3074 else if (os_strcmp(pos, "b") == 0)
3075 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
3076 else if (os_strcmp(pos, "g") == 0)
3077 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
3078 else if (os_strcmp(pos, "ad") == 0)
3079 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003080 else if (os_strcmp(pos, "any") == 0)
3081 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003082 else {
3083 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3084 line, pos);
3085 return 1;
3086 }
3087 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003088 if (os_strcmp(pos, "ad") == 0)
3089 bss->wps_rf_bands = WPS_RF_60GHZ;
3090 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003091 bss->wps_rf_bands = WPS_RF_50GHZ;
3092 else if (os_strcmp(pos, "g") == 0 ||
3093 os_strcmp(pos, "b") == 0)
3094 bss->wps_rf_bands = WPS_RF_24GHZ;
3095 else if (os_strcmp(pos, "ag") == 0 ||
3096 os_strcmp(pos, "ga") == 0)
3097 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3098 else {
3099 wpa_printf(MSG_ERROR,
3100 "Line %d: unknown wps_rf_band '%s'",
3101 line, pos);
3102 return 1;
3103 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003104 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3105 conf->acs_exclude_dfs = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07003106 } else if (os_strcmp(buf, "op_class") == 0) {
3107 conf->op_class = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003108 } else if (os_strcmp(buf, "channel") == 0) {
3109 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003110#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003111 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3112 line);
3113 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003114#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003115 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003116 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003117#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003118 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003119 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003120 conf->acs = conf->channel == 0;
3121 }
Hai Shalomc3565922019-10-28 11:58:20 -07003122 } else if (os_strcmp(buf, "edmg_channel") == 0) {
3123 conf->edmg_channel = atoi(pos);
3124 } else if (os_strcmp(buf, "enable_edmg") == 0) {
3125 conf->enable_edmg = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003126 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003127 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003128 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3129 line);
3130 return 1;
3131 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003132 } else if (os_strcmp(buf, "freqlist") == 0) {
3133 if (freq_range_list_parse(&conf->acs_freq_list, pos)) {
3134 wpa_printf(MSG_ERROR, "Line %d: invalid frequency list",
3135 line);
3136 return 1;
3137 }
3138 conf->acs_freq_list_present = 1;
3139 } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) {
3140 conf->acs_exclude_6ghz_non_psc = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003141 } else if (os_strcmp(buf, "beacon_int") == 0) {
3142 int val = atoi(pos);
3143 /* MIB defines range as 1..65535, but very small values
3144 * cause problems with the current implementation.
3145 * Since it is unlikely that this small numbers are
3146 * useful in real life scenarios, do not allow beacon
Hai Shalom021b0b52019-04-10 11:17:58 -07003147 * period to be set below 10 TU. */
3148 if (val < 10 || val > 65535) {
3149 wpa_printf(MSG_ERROR,
3150 "Line %d: invalid beacon_int %d (expected 10..65535)",
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003151 line, val);
3152 return 1;
3153 }
3154 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003155#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003156 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3157 int val = atoi(pos);
3158 if (val <= 0 || val > 100) {
3159 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3160 line, val);
3161 return 1;
3162 }
3163 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003164 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3165 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3166 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3167 line);
3168 return -1;
3169 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003170#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003171 } else if (os_strcmp(buf, "dtim_period") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003172 int val = atoi(pos);
3173
3174 if (val < 1 || val > 255) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003175 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08003176 line, val);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003177 return 1;
3178 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08003179 bss->dtim_period = val;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003180 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003181 int val = atoi(pos);
3182
3183 if (val < 0 || val > 100) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003184 wpa_printf(MSG_ERROR,
3185 "Line %d: invalid bss_load_update_period %d",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003186 line, val);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003187 return 1;
3188 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003189 bss->bss_load_update_period = val;
3190 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3191 int val = atoi(pos);
3192
3193 if (val < 0) {
3194 wpa_printf(MSG_ERROR,
3195 "Line %d: invalid chan_util_avg_period",
3196 line);
3197 return 1;
3198 }
3199 bss->chan_util_avg_period = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003200 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3201 conf->rts_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003202 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003203 wpa_printf(MSG_ERROR,
3204 "Line %d: invalid rts_threshold %d",
3205 line, conf->rts_threshold);
3206 return 1;
3207 }
3208 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3209 conf->fragm_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003210 if (conf->fragm_threshold == -1) {
3211 /* allow a value of -1 */
3212 } else if (conf->fragm_threshold < 256 ||
3213 conf->fragm_threshold > 2346) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003214 wpa_printf(MSG_ERROR,
3215 "Line %d: invalid fragm_threshold %d",
3216 line, conf->fragm_threshold);
3217 return 1;
3218 }
3219 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3220 int val = atoi(pos);
3221 if (val != 0 && val != 1) {
3222 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3223 line, val);
3224 return 1;
3225 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003226 bss->send_probe_response = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003227 } else if (os_strcmp(buf, "supported_rates") == 0) {
3228 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3229 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3230 line);
3231 return 1;
3232 }
3233 } else if (os_strcmp(buf, "basic_rates") == 0) {
3234 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3235 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3236 line);
3237 return 1;
3238 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003239 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3240 int val;
3241
3242 if (os_strncmp(pos, "ht:", 3) == 0) {
3243 val = atoi(pos + 3);
3244 if (val < 0 || val > 31) {
3245 wpa_printf(MSG_ERROR,
3246 "Line %d: invalid beacon_rate HT-MCS %d",
3247 line, val);
3248 return 1;
3249 }
3250 conf->rate_type = BEACON_RATE_HT;
3251 conf->beacon_rate = val;
3252 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3253 val = atoi(pos + 4);
3254 if (val < 0 || val > 9) {
3255 wpa_printf(MSG_ERROR,
3256 "Line %d: invalid beacon_rate VHT-MCS %d",
3257 line, val);
3258 return 1;
3259 }
3260 conf->rate_type = BEACON_RATE_VHT;
3261 conf->beacon_rate = val;
3262 } else {
3263 val = atoi(pos);
3264 if (val < 10 || val > 10000) {
3265 wpa_printf(MSG_ERROR,
3266 "Line %d: invalid legacy beacon_rate %d",
3267 line, val);
3268 return 1;
3269 }
3270 conf->rate_type = BEACON_RATE_LEGACY;
3271 conf->beacon_rate = val;
3272 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003273 } else if (os_strcmp(buf, "preamble") == 0) {
3274 if (atoi(pos))
3275 conf->preamble = SHORT_PREAMBLE;
3276 else
3277 conf->preamble = LONG_PREAMBLE;
3278 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3279 bss->ignore_broadcast_ssid = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003280 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3281 bss->no_probe_resp_if_max_sta = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003282#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003283 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3284 bss->ssid.wep.idx = atoi(pos);
3285 if (bss->ssid.wep.idx > 3) {
3286 wpa_printf(MSG_ERROR,
3287 "Invalid wep_default_key index %d",
3288 bss->ssid.wep.idx);
3289 return 1;
3290 }
3291 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3292 os_strcmp(buf, "wep_key1") == 0 ||
3293 os_strcmp(buf, "wep_key2") == 0 ||
3294 os_strcmp(buf, "wep_key3") == 0) {
3295 if (hostapd_config_read_wep(&bss->ssid.wep,
3296 buf[7] - '0', pos)) {
3297 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3298 line, buf);
3299 return 1;
3300 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003301#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003302#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003303 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3304 bss->ssid.dynamic_vlan = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003305 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3306 bss->ssid.per_sta_vif = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003307 } else if (os_strcmp(buf, "vlan_file") == 0) {
3308 if (hostapd_config_read_vlan_file(bss, pos)) {
3309 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3310 line, pos);
3311 return 1;
3312 }
3313 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3314 bss->ssid.vlan_naming = atoi(pos);
3315 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3316 bss->ssid.vlan_naming < 0) {
3317 wpa_printf(MSG_ERROR,
3318 "Line %d: invalid naming scheme %d",
3319 line, bss->ssid.vlan_naming);
3320 return 1;
3321 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003322#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003323 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003324 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003325 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003326#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3327#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003328 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3329 conf->ap_table_max_size = atoi(pos);
3330 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3331 conf->ap_table_expiration_time = atoi(pos);
3332 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003333 if (hostapd_config_tx_queue(conf->tx_queue, buf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003334 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3335 line);
3336 return 1;
3337 }
3338 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3339 os_strcmp(buf, "wmm_enabled") == 0) {
3340 bss->wmm_enabled = atoi(pos);
3341 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3342 bss->wmm_uapsd = atoi(pos);
3343 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3344 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3345 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3346 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3347 line);
3348 return 1;
3349 }
3350 } else if (os_strcmp(buf, "bss") == 0) {
3351 if (hostapd_config_bss(conf, pos)) {
3352 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3353 line);
3354 return 1;
3355 }
3356 } else if (os_strcmp(buf, "bssid") == 0) {
3357 if (hwaddr_aton(pos, bss->bssid)) {
3358 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3359 line);
3360 return 1;
3361 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003362 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3363 conf->use_driver_iface_addr = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003364 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3365 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003366 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3367 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3368 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3369 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3370 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3371 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3372 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3373 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3374 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3375 } else {
3376 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3377 line, pos);
3378 return 1;
3379 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003380 } else if (os_strcmp(buf, "beacon_prot") == 0) {
3381 bss->beacon_prot = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003382 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3383 bss->assoc_sa_query_max_timeout = atoi(pos);
3384 if (bss->assoc_sa_query_max_timeout == 0) {
3385 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3386 line);
3387 return 1;
3388 }
3389 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3390 bss->assoc_sa_query_retry_timeout = atoi(pos);
3391 if (bss->assoc_sa_query_retry_timeout == 0) {
3392 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3393 line);
3394 return 1;
3395 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003396#ifdef CONFIG_OCV
3397 } else if (os_strcmp(buf, "ocv") == 0) {
3398 bss->ocv = atoi(pos);
3399 if (bss->ocv && !bss->ieee80211w)
3400 bss->ieee80211w = 1;
3401#endif /* CONFIG_OCV */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003402 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3403 conf->ieee80211n = atoi(pos);
3404 } else if (os_strcmp(buf, "ht_capab") == 0) {
3405 if (hostapd_config_ht_capab(conf, pos) < 0) {
3406 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3407 line);
3408 return 1;
3409 }
3410 } else if (os_strcmp(buf, "require_ht") == 0) {
3411 conf->require_ht = atoi(pos);
3412 } else if (os_strcmp(buf, "obss_interval") == 0) {
3413 conf->obss_interval = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003414#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003415 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3416 conf->ieee80211ac = atoi(pos);
3417 } else if (os_strcmp(buf, "vht_capab") == 0) {
3418 if (hostapd_config_vht_capab(conf, pos) < 0) {
3419 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3420 line);
3421 return 1;
3422 }
3423 } else if (os_strcmp(buf, "require_vht") == 0) {
3424 conf->require_vht = atoi(pos);
3425 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3426 conf->vht_oper_chwidth = atoi(pos);
3427 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3428 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3429 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3430 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003431 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3432 bss->vendor_vht = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003433 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3434 bss->use_sta_nsts = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003435#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003436#ifdef CONFIG_IEEE80211AX
3437 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3438 conf->ieee80211ax = atoi(pos);
3439 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3440 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3441 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3442 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3443 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3444 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3445 } else if (os_strcmp(buf, "he_bss_color") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003446 conf->he_op.he_bss_color = atoi(pos) & 0x3f;
3447 conf->he_op.he_bss_color_disabled = 0;
3448 } else if (os_strcmp(buf, "he_bss_color_partial") == 0) {
3449 conf->he_op.he_bss_color_partial = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003450 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3451 conf->he_op.he_default_pe_duration = atoi(pos);
3452 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3453 conf->he_op.he_twt_required = atoi(pos);
3454 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3455 conf->he_op.he_rts_threshold = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003456 } else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
3457 conf->he_op.he_basic_mcs_nss_set = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003458 } else if (os_strcmp(buf, "he_mu_edca_qos_info_param_count") == 0) {
3459 conf->he_mu_edca.he_qos_info |=
3460 set_he_cap(atoi(pos), HE_QOS_INFO_EDCA_PARAM_SET_COUNT);
3461 } else if (os_strcmp(buf, "he_mu_edca_qos_info_q_ack") == 0) {
3462 conf->he_mu_edca.he_qos_info |=
3463 set_he_cap(atoi(pos), HE_QOS_INFO_Q_ACK);
3464 } else if (os_strcmp(buf, "he_mu_edca_qos_info_queue_request") == 0) {
3465 conf->he_mu_edca.he_qos_info |=
3466 set_he_cap(atoi(pos), HE_QOS_INFO_QUEUE_REQUEST);
3467 } else if (os_strcmp(buf, "he_mu_edca_qos_info_txop_request") == 0) {
3468 conf->he_mu_edca.he_qos_info |=
3469 set_he_cap(atoi(pos), HE_QOS_INFO_TXOP_REQUEST);
3470 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aifsn") == 0) {
3471 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3472 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3473 } else if (os_strcmp(buf, "he_mu_edca_ac_be_acm") == 0) {
3474 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3475 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3476 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aci") == 0) {
3477 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3478 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3479 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmin") == 0) {
3480 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3481 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3482 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmax") == 0) {
3483 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3484 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3485 } else if (os_strcmp(buf, "he_mu_edca_ac_be_timer") == 0) {
3486 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_TIMER_IDX] =
3487 atoi(pos) & 0xff;
3488 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aifsn") == 0) {
3489 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3490 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3491 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_acm") == 0) {
3492 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3493 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3494 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aci") == 0) {
3495 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3496 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3497 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmin") == 0) {
3498 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3499 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3500 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmax") == 0) {
3501 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3502 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3503 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_timer") == 0) {
3504 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_TIMER_IDX] =
3505 atoi(pos) & 0xff;
3506 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aifsn") == 0) {
3507 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3508 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3509 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_acm") == 0) {
3510 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3511 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3512 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aci") == 0) {
3513 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3514 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3515 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmin") == 0) {
3516 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3517 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3518 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmax") == 0) {
3519 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3520 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3521 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_timer") == 0) {
3522 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_TIMER_IDX] =
3523 atoi(pos) & 0xff;
3524 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aifsn") == 0) {
3525 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3526 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3527 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_acm") == 0) {
3528 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3529 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3530 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aci") == 0) {
3531 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3532 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3533 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmin") == 0) {
3534 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3535 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3536 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmax") == 0) {
3537 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3538 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3539 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_timer") == 0) {
3540 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_TIMER_IDX] =
3541 atoi(pos) & 0xff;
Hai Shalom81f62d82019-07-22 12:10:00 -07003542 } else if (os_strcmp(buf, "he_spr_sr_control") == 0) {
3543 conf->spr.sr_control = atoi(pos) & 0xff;
3544 } else if (os_strcmp(buf, "he_spr_non_srg_obss_pd_max_offset") == 0) {
3545 conf->spr.non_srg_obss_pd_max_offset = atoi(pos);
3546 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_min_offset") == 0) {
3547 conf->spr.srg_obss_pd_min_offset = atoi(pos);
3548 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_max_offset") == 0) {
3549 conf->spr.srg_obss_pd_max_offset = atoi(pos);
3550 } else if (os_strcmp(buf, "he_oper_chwidth") == 0) {
3551 conf->he_oper_chwidth = atoi(pos);
3552 } else if (os_strcmp(buf, "he_oper_centr_freq_seg0_idx") == 0) {
3553 conf->he_oper_centr_freq_seg0_idx = atoi(pos);
3554 } else if (os_strcmp(buf, "he_oper_centr_freq_seg1_idx") == 0) {
3555 conf->he_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003556#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003557 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3558 bss->max_listen_interval = atoi(pos);
3559 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3560 bss->disable_pmksa_caching = atoi(pos);
3561 } else if (os_strcmp(buf, "okc") == 0) {
3562 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003563#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003564 } else if (os_strcmp(buf, "wps_state") == 0) {
3565 bss->wps_state = atoi(pos);
3566 if (bss->wps_state < 0 || bss->wps_state > 2) {
3567 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3568 line);
3569 return 1;
3570 }
3571 } else if (os_strcmp(buf, "wps_independent") == 0) {
3572 bss->wps_independent = atoi(pos);
3573 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3574 bss->ap_setup_locked = atoi(pos);
3575 } else if (os_strcmp(buf, "uuid") == 0) {
3576 if (uuid_str2bin(pos, bss->uuid)) {
3577 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3578 return 1;
3579 }
3580 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3581 os_free(bss->wps_pin_requests);
3582 bss->wps_pin_requests = os_strdup(pos);
3583 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003584 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003585 wpa_printf(MSG_ERROR, "Line %d: Too long "
3586 "device_name", line);
3587 return 1;
3588 }
3589 os_free(bss->device_name);
3590 bss->device_name = os_strdup(pos);
3591 } else if (os_strcmp(buf, "manufacturer") == 0) {
3592 if (os_strlen(pos) > 64) {
3593 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3594 line);
3595 return 1;
3596 }
3597 os_free(bss->manufacturer);
3598 bss->manufacturer = os_strdup(pos);
3599 } else if (os_strcmp(buf, "model_name") == 0) {
3600 if (os_strlen(pos) > 32) {
3601 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3602 line);
3603 return 1;
3604 }
3605 os_free(bss->model_name);
3606 bss->model_name = os_strdup(pos);
3607 } else if (os_strcmp(buf, "model_number") == 0) {
3608 if (os_strlen(pos) > 32) {
3609 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3610 line);
3611 return 1;
3612 }
3613 os_free(bss->model_number);
3614 bss->model_number = os_strdup(pos);
3615 } else if (os_strcmp(buf, "serial_number") == 0) {
3616 if (os_strlen(pos) > 32) {
3617 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3618 line);
3619 return 1;
3620 }
3621 os_free(bss->serial_number);
3622 bss->serial_number = os_strdup(pos);
3623 } else if (os_strcmp(buf, "device_type") == 0) {
3624 if (wps_dev_type_str2bin(pos, bss->device_type))
3625 return 1;
3626 } else if (os_strcmp(buf, "config_methods") == 0) {
3627 os_free(bss->config_methods);
3628 bss->config_methods = os_strdup(pos);
3629 } else if (os_strcmp(buf, "os_version") == 0) {
3630 if (hexstr2bin(pos, bss->os_version, 4)) {
3631 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3632 line);
3633 return 1;
3634 }
3635 } else if (os_strcmp(buf, "ap_pin") == 0) {
3636 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003637 if (*pos == '\0')
3638 bss->ap_pin = NULL;
3639 else
3640 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003641 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3642 bss->skip_cred_build = atoi(pos);
3643 } else if (os_strcmp(buf, "extra_cred") == 0) {
3644 os_free(bss->extra_cred);
3645 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3646 if (bss->extra_cred == NULL) {
3647 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3648 line, pos);
3649 return 1;
3650 }
3651 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3652 bss->wps_cred_processing = atoi(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07003653 } else if (os_strcmp(buf, "wps_cred_add_sae") == 0) {
3654 bss->wps_cred_add_sae = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003655 } else if (os_strcmp(buf, "ap_settings") == 0) {
3656 os_free(bss->ap_settings);
3657 bss->ap_settings =
3658 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3659 if (bss->ap_settings == NULL) {
3660 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3661 line, pos);
3662 return 1;
3663 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003664 } else if (os_strcmp(buf, "multi_ap_backhaul_ssid") == 0) {
3665 size_t slen;
3666 char *str = wpa_config_parse_string(pos, &slen);
3667
3668 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
3669 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
3670 line, pos);
3671 os_free(str);
3672 return 1;
3673 }
3674 os_memcpy(bss->multi_ap_backhaul_ssid.ssid, str, slen);
3675 bss->multi_ap_backhaul_ssid.ssid_len = slen;
3676 bss->multi_ap_backhaul_ssid.ssid_set = 1;
3677 os_free(str);
3678 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_passphrase") == 0) {
3679 int len = os_strlen(pos);
3680
3681 if (len < 8 || len > 63) {
3682 wpa_printf(MSG_ERROR,
3683 "Line %d: invalid WPA passphrase length %d (expected 8..63)",
3684 line, len);
3685 return 1;
3686 }
3687 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3688 bss->multi_ap_backhaul_ssid.wpa_passphrase = os_strdup(pos);
3689 if (bss->multi_ap_backhaul_ssid.wpa_passphrase) {
3690 hostapd_config_clear_wpa_psk(
3691 &bss->multi_ap_backhaul_ssid.wpa_psk);
3692 bss->multi_ap_backhaul_ssid.wpa_passphrase_set = 1;
3693 }
3694 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_psk") == 0) {
3695 hostapd_config_clear_wpa_psk(
3696 &bss->multi_ap_backhaul_ssid.wpa_psk);
3697 bss->multi_ap_backhaul_ssid.wpa_psk =
3698 os_zalloc(sizeof(struct hostapd_wpa_psk));
3699 if (!bss->multi_ap_backhaul_ssid.wpa_psk)
3700 return 1;
3701 if (hexstr2bin(pos, bss->multi_ap_backhaul_ssid.wpa_psk->psk,
3702 PMK_LEN) ||
3703 pos[PMK_LEN * 2] != '\0') {
3704 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
3705 line, pos);
3706 hostapd_config_clear_wpa_psk(
3707 &bss->multi_ap_backhaul_ssid.wpa_psk);
3708 return 1;
3709 }
3710 bss->multi_ap_backhaul_ssid.wpa_psk->group = 1;
3711 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3712 bss->multi_ap_backhaul_ssid.wpa_passphrase = NULL;
3713 bss->multi_ap_backhaul_ssid.wpa_psk_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003714 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003715 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003716 bss->upnp_iface = os_strdup(pos);
3717 } else if (os_strcmp(buf, "friendly_name") == 0) {
3718 os_free(bss->friendly_name);
3719 bss->friendly_name = os_strdup(pos);
3720 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3721 os_free(bss->manufacturer_url);
3722 bss->manufacturer_url = os_strdup(pos);
3723 } else if (os_strcmp(buf, "model_description") == 0) {
3724 os_free(bss->model_description);
3725 bss->model_description = os_strdup(pos);
3726 } else if (os_strcmp(buf, "model_url") == 0) {
3727 os_free(bss->model_url);
3728 bss->model_url = os_strdup(pos);
3729 } else if (os_strcmp(buf, "upc") == 0) {
3730 os_free(bss->upc);
3731 bss->upc = os_strdup(pos);
3732 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3733 bss->pbc_in_m1 = atoi(pos);
3734 } else if (os_strcmp(buf, "server_id") == 0) {
3735 os_free(bss->server_id);
3736 bss->server_id = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003737 } else if (os_strcmp(buf, "wps_application_ext") == 0) {
3738 wpabuf_free(bss->wps_application_ext);
3739 bss->wps_application_ext = wpabuf_parse_bin(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003740#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003741 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3742 bss->wps_nfc_dev_pw_id = atoi(pos);
3743 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3744 bss->wps_nfc_dev_pw_id > 0xffff) {
3745 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3746 line);
3747 return 1;
3748 }
3749 bss->wps_nfc_pw_from_config = 1;
3750 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3751 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003752 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003753 bss->wps_nfc_pw_from_config = 1;
3754 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3755 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003756 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003757 bss->wps_nfc_pw_from_config = 1;
3758 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3759 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003760 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003761 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003762#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003763#endif /* CONFIG_WPS */
3764#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003765 } else if (os_strcmp(buf, "manage_p2p") == 0) {
3766 if (atoi(pos))
3767 bss->p2p |= P2P_MANAGE;
3768 else
3769 bss->p2p &= ~P2P_MANAGE;
3770 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3771 if (atoi(pos))
3772 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3773 else
3774 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003776 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3777 bss->disassoc_low_ack = atoi(pos);
3778 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
3779 if (atoi(pos))
3780 bss->tdls |= TDLS_PROHIBIT;
3781 else
3782 bss->tdls &= ~TDLS_PROHIBIT;
3783 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
3784 if (atoi(pos))
3785 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3786 else
3787 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003788#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003789 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3790 extern int rsn_testing;
3791 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003792#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003793 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3794 bss->time_advertisement = atoi(pos);
3795 } else if (os_strcmp(buf, "time_zone") == 0) {
3796 size_t tz_len = os_strlen(pos);
3797 if (tz_len < 4 || tz_len > 255) {
3798 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3799 line);
3800 return 1;
3801 }
3802 os_free(bss->time_zone);
3803 bss->time_zone = os_strdup(pos);
3804 if (bss->time_zone == NULL)
3805 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003806#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003807 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3808 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003809 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3810 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003811 } else if (os_strcmp(buf, "bss_transition") == 0) {
3812 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003813#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003814#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003815 } else if (os_strcmp(buf, "interworking") == 0) {
3816 bss->interworking = atoi(pos);
3817 } else if (os_strcmp(buf, "access_network_type") == 0) {
3818 bss->access_network_type = atoi(pos);
3819 if (bss->access_network_type < 0 ||
3820 bss->access_network_type > 15) {
3821 wpa_printf(MSG_ERROR,
3822 "Line %d: invalid access_network_type",
3823 line);
3824 return 1;
3825 }
3826 } else if (os_strcmp(buf, "internet") == 0) {
3827 bss->internet = atoi(pos);
3828 } else if (os_strcmp(buf, "asra") == 0) {
3829 bss->asra = atoi(pos);
3830 } else if (os_strcmp(buf, "esr") == 0) {
3831 bss->esr = atoi(pos);
3832 } else if (os_strcmp(buf, "uesa") == 0) {
3833 bss->uesa = atoi(pos);
3834 } else if (os_strcmp(buf, "venue_group") == 0) {
3835 bss->venue_group = atoi(pos);
3836 bss->venue_info_set = 1;
3837 } else if (os_strcmp(buf, "venue_type") == 0) {
3838 bss->venue_type = atoi(pos);
3839 bss->venue_info_set = 1;
3840 } else if (os_strcmp(buf, "hessid") == 0) {
3841 if (hwaddr_aton(pos, bss->hessid)) {
3842 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3843 return 1;
3844 }
3845 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3846 if (parse_roaming_consortium(bss, pos, line) < 0)
3847 return 1;
3848 } else if (os_strcmp(buf, "venue_name") == 0) {
3849 if (parse_venue_name(bss, pos, line) < 0)
3850 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003851 } else if (os_strcmp(buf, "venue_url") == 0) {
3852 if (parse_venue_url(bss, pos, line) < 0)
3853 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003854 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3855 u8 auth_type;
3856 u16 redirect_url_len;
3857 if (hexstr2bin(pos, &auth_type, 1)) {
3858 wpa_printf(MSG_ERROR,
3859 "Line %d: Invalid network_auth_type '%s'",
3860 line, pos);
3861 return 1;
3862 }
3863 if (auth_type == 0 || auth_type == 2)
3864 redirect_url_len = os_strlen(pos + 2);
3865 else
3866 redirect_url_len = 0;
3867 os_free(bss->network_auth_type);
3868 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3869 if (bss->network_auth_type == NULL)
3870 return 1;
3871 *bss->network_auth_type = auth_type;
3872 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3873 if (redirect_url_len)
3874 os_memcpy(bss->network_auth_type + 3, pos + 2,
3875 redirect_url_len);
3876 bss->network_auth_type_len = 3 + redirect_url_len;
3877 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3878 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3879 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3880 line, pos);
3881 bss->ipaddr_type_configured = 0;
3882 return 1;
3883 }
3884 bss->ipaddr_type_configured = 1;
3885 } else if (os_strcmp(buf, "domain_name") == 0) {
3886 int j, num_domains, domain_len, domain_list_len = 0;
3887 char *tok_start, *tok_prev;
3888 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003889
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003890 domain_list_len = os_strlen(pos) + 1;
3891 domain_list = os_malloc(domain_list_len);
3892 if (domain_list == NULL)
3893 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003894
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003895 domain_ptr = domain_list;
3896 tok_prev = pos;
3897 num_domains = 1;
3898 while ((tok_prev = os_strchr(tok_prev, ','))) {
3899 num_domains++;
3900 tok_prev++;
3901 }
3902 tok_prev = pos;
3903 for (j = 0; j < num_domains; j++) {
3904 tok_start = os_strchr(tok_prev, ',');
3905 if (tok_start) {
3906 domain_len = tok_start - tok_prev;
3907 *domain_ptr = domain_len;
3908 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3909 domain_ptr += domain_len + 1;
3910 tok_prev = ++tok_start;
3911 } else {
3912 domain_len = os_strlen(tok_prev);
3913 *domain_ptr = domain_len;
3914 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3915 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003916 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003917 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003918
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003919 os_free(bss->domain_name);
3920 bss->domain_name = domain_list;
3921 bss->domain_name_len = domain_list_len;
3922 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3923 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3924 return 1;
3925 } else if (os_strcmp(buf, "nai_realm") == 0) {
3926 if (parse_nai_realm(bss, pos, line) < 0)
3927 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003928 } else if (os_strcmp(buf, "anqp_elem") == 0) {
3929 if (parse_anqp_elem(bss, pos, line) < 0)
3930 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003931 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003932 int val = atoi(pos);
3933
3934 if (val <= 0) {
3935 wpa_printf(MSG_ERROR,
3936 "Line %d: Invalid gas_frag_limit '%s'",
3937 line, pos);
3938 return 1;
3939 }
3940 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003941 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3942 bss->gas_comeback_delay = atoi(pos);
3943 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3944 if (parse_qos_map_set(bss, pos, line) < 0)
3945 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003946#endif /* CONFIG_INTERWORKING */
3947#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003948 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3949 os_free(bss->dump_msk_file);
3950 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003951#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08003952#ifdef CONFIG_PROXYARP
3953 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3954 bss->proxy_arp = atoi(pos);
3955#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003956#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003957 } else if (os_strcmp(buf, "hs20") == 0) {
3958 bss->hs20 = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003959 } else if (os_strcmp(buf, "hs20_release") == 0) {
3960 int val = atoi(pos);
3961
3962 if (val < 1 || val > (HS20_VERSION >> 4) + 1) {
3963 wpa_printf(MSG_ERROR,
3964 "Line %d: Unsupported hs20_release: %s",
3965 line, pos);
3966 return 1;
3967 }
3968 bss->hs20_release = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003969 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3970 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003971 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
3972 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003973 } else if (os_strcmp(buf, "osen") == 0) {
3974 bss->osen = atoi(pos);
3975 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3976 bss->anqp_domain_id = atoi(pos);
3977 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3978 bss->hs20_deauth_req_timeout = atoi(pos);
3979 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3980 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3981 return 1;
3982 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3983 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3984 return 1;
3985 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3986 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3987 return 1;
3988 }
3989 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3990 u8 *oper_class;
3991 size_t oper_class_len;
3992 oper_class_len = os_strlen(pos);
3993 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3994 wpa_printf(MSG_ERROR,
3995 "Line %d: Invalid hs20_operating_class '%s'",
3996 line, pos);
3997 return 1;
3998 }
3999 oper_class_len /= 2;
4000 oper_class = os_malloc(oper_class_len);
4001 if (oper_class == NULL)
4002 return 1;
4003 if (hexstr2bin(pos, oper_class, oper_class_len)) {
4004 wpa_printf(MSG_ERROR,
4005 "Line %d: Invalid hs20_operating_class '%s'",
4006 line, pos);
4007 os_free(oper_class);
4008 return 1;
4009 }
4010 os_free(bss->hs20_operating_class);
4011 bss->hs20_operating_class = oper_class;
4012 bss->hs20_operating_class_len = oper_class_len;
4013 } else if (os_strcmp(buf, "hs20_icon") == 0) {
4014 if (hs20_parse_icon(bss, pos) < 0) {
4015 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
4016 line, pos);
4017 return 1;
4018 }
4019 } else if (os_strcmp(buf, "osu_ssid") == 0) {
4020 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
4021 return 1;
4022 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
4023 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
4024 return 1;
4025 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
4026 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
4027 return 1;
4028 } else if (os_strcmp(buf, "osu_nai") == 0) {
4029 if (hs20_parse_osu_nai(bss, pos, line) < 0)
4030 return 1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004031 } else if (os_strcmp(buf, "osu_nai2") == 0) {
4032 if (hs20_parse_osu_nai2(bss, pos, line) < 0)
4033 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004034 } else if (os_strcmp(buf, "osu_method_list") == 0) {
4035 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
4036 return 1;
4037 } else if (os_strcmp(buf, "osu_icon") == 0) {
4038 if (hs20_parse_osu_icon(bss, pos, line) < 0)
4039 return 1;
4040 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
4041 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
4042 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004043 } else if (os_strcmp(buf, "operator_icon") == 0) {
4044 if (hs20_parse_operator_icon(bss, pos, line) < 0)
4045 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004046 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
4047 os_free(bss->subscr_remediation_url);
4048 bss->subscr_remediation_url = os_strdup(pos);
4049 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
4050 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004051 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
4052 os_free(bss->t_c_filename);
4053 bss->t_c_filename = os_strdup(pos);
4054 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
4055 bss->t_c_timestamp = strtol(pos, NULL, 0);
4056 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
4057 os_free(bss->t_c_server_url);
4058 bss->t_c_server_url = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004059 } else if (os_strcmp(buf, "hs20_sim_provisioning_url") == 0) {
4060 os_free(bss->hs20_sim_provisioning_url);
4061 bss->hs20_sim_provisioning_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004062#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004063#ifdef CONFIG_MBO
4064 } else if (os_strcmp(buf, "mbo") == 0) {
4065 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004066 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
4067 bss->mbo_cell_data_conn_pref = atoi(pos);
4068 } else if (os_strcmp(buf, "oce") == 0) {
4069 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004070#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004071#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004072#define PARSE_TEST_PROBABILITY(_val) \
4073 } else if (os_strcmp(buf, #_val) == 0) { \
4074 char *end; \
4075 \
4076 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004077 if (*end || conf->_val < 0.0 || \
4078 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004079 wpa_printf(MSG_ERROR, \
4080 "Line %d: Invalid value '%s'", \
4081 line, pos); \
4082 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004084 PARSE_TEST_PROBABILITY(ignore_probe_probability)
4085 PARSE_TEST_PROBABILITY(ignore_auth_probability)
4086 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
4087 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
4088 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004089 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
4090 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004091 } else if (os_strcmp(buf, "bss_load_test") == 0) {
4092 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
4093 pos = os_strchr(pos, ':');
4094 if (pos == NULL) {
4095 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4096 line);
4097 return 1;
4098 }
4099 pos++;
4100 bss->bss_load_test[2] = atoi(pos);
4101 pos = os_strchr(pos, ':');
4102 if (pos == NULL) {
4103 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4104 line);
4105 return 1;
4106 }
4107 pos++;
4108 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
4109 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004110 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004111 /*
4112 * DEPRECATED: This parameter will be removed in the future.
4113 * Use rrm_neighbor_report instead.
4114 */
4115 int val = atoi(pos);
4116
4117 if (val & BIT(0))
4118 bss->radio_measurements[0] |=
4119 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004120 } else if (os_strcmp(buf, "own_ie_override") == 0) {
4121 struct wpabuf *tmp;
4122 size_t len = os_strlen(pos) / 2;
4123
4124 tmp = wpabuf_alloc(len);
4125 if (!tmp)
4126 return 1;
4127
4128 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
4129 wpabuf_free(tmp);
4130 wpa_printf(MSG_ERROR,
4131 "Line %d: Invalid own_ie_override '%s'",
4132 line, pos);
4133 return 1;
4134 }
4135
4136 wpabuf_free(bss->own_ie_override);
4137 bss->own_ie_override = tmp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004138 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
4139 bss->sae_reflection_attack = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004140 } else if (os_strcmp(buf, "sae_commit_status") == 0) {
4141 bss->sae_commit_status = atoi(pos);
4142 } else if (os_strcmp(buf, "sae_pk_omit") == 0) {
4143 bss->sae_pk_omit = atoi(pos);
4144 } else if (os_strcmp(buf, "sae_pk_password_check_skip") == 0) {
4145 bss->sae_pk_password_check_skip = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004146 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
4147 wpabuf_free(bss->sae_commit_override);
4148 bss->sae_commit_override = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004149 } else if (os_strcmp(buf, "rsne_override_eapol") == 0) {
4150 wpabuf_free(bss->rsne_override_eapol);
4151 bss->rsne_override_eapol = wpabuf_parse_bin(pos);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004152 } else if (os_strcmp(buf, "rsnxe_override_eapol") == 0) {
4153 wpabuf_free(bss->rsnxe_override_eapol);
4154 bss->rsnxe_override_eapol = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004155 } else if (os_strcmp(buf, "rsne_override_ft") == 0) {
4156 wpabuf_free(bss->rsne_override_ft);
4157 bss->rsne_override_ft = wpabuf_parse_bin(pos);
4158 } else if (os_strcmp(buf, "rsnxe_override_ft") == 0) {
4159 wpabuf_free(bss->rsnxe_override_ft);
4160 bss->rsnxe_override_ft = wpabuf_parse_bin(pos);
4161 } else if (os_strcmp(buf, "gtk_rsc_override") == 0) {
4162 wpabuf_free(bss->gtk_rsc_override);
4163 bss->gtk_rsc_override = wpabuf_parse_bin(pos);
4164 } else if (os_strcmp(buf, "igtk_rsc_override") == 0) {
4165 wpabuf_free(bss->igtk_rsc_override);
4166 bss->igtk_rsc_override = wpabuf_parse_bin(pos);
4167 } else if (os_strcmp(buf, "no_beacon_rsnxe") == 0) {
4168 bss->no_beacon_rsnxe = atoi(pos);
4169 } else if (os_strcmp(buf, "skip_prune_assoc") == 0) {
4170 bss->skip_prune_assoc = atoi(pos);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004171 } else if (os_strcmp(buf, "ft_rsnxe_used") == 0) {
4172 bss->ft_rsnxe_used = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004173 } else if (os_strcmp(buf, "oci_freq_override_eapol_m3") == 0) {
4174 bss->oci_freq_override_eapol_m3 = atoi(pos);
4175 } else if (os_strcmp(buf, "oci_freq_override_eapol_g1") == 0) {
4176 bss->oci_freq_override_eapol_g1 = atoi(pos);
4177 } else if (os_strcmp(buf, "oci_freq_override_saquery_req") == 0) {
4178 bss->oci_freq_override_saquery_req = atoi(pos);
4179 } else if (os_strcmp(buf, "oci_freq_override_saquery_resp") == 0) {
4180 bss->oci_freq_override_saquery_resp = atoi(pos);
4181 } else if (os_strcmp(buf, "oci_freq_override_ft_assoc") == 0) {
4182 bss->oci_freq_override_ft_assoc = atoi(pos);
4183 } else if (os_strcmp(buf, "oci_freq_override_fils_assoc") == 0) {
4184 bss->oci_freq_override_fils_assoc = atoi(pos);
4185 } else if (os_strcmp(buf, "oci_freq_override_wnm_sleep") == 0) {
4186 bss->oci_freq_override_wnm_sleep = atoi(pos);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004187#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004188#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004189 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004190 if (parse_sae_password(bss, pos) < 0) {
4191 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
4192 line);
4193 return 1;
4194 }
4195#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004196 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004197 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004198 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004199 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4200 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004201 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004202 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
4203 bss->sae_anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004204 } else if (os_strcmp(buf, "sae_sync") == 0) {
4205 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004206 } else if (os_strcmp(buf, "sae_groups") == 0) {
4207 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
4208 wpa_printf(MSG_ERROR,
4209 "Line %d: Invalid sae_groups value '%s'",
4210 line, pos);
4211 return 1;
4212 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004213 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
4214 bss->sae_require_mfp = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07004215 } else if (os_strcmp(buf, "sae_confirm_immediate") == 0) {
4216 bss->sae_confirm_immediate = atoi(pos);
4217 } else if (os_strcmp(buf, "sae_pwe") == 0) {
4218 bss->sae_pwe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004219 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
4220 int val = atoi(pos);
4221 if (val < 0 || val > 255) {
4222 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
4223 line, val);
4224 return 1;
4225 }
4226 conf->local_pwr_constraint = val;
4227 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
4228 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07004229 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
4230 os_free(bss->wowlan_triggers);
4231 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004232#ifdef CONFIG_FST
4233 } else if (os_strcmp(buf, "fst_group_id") == 0) {
4234 size_t len = os_strlen(pos);
4235
4236 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
4237 wpa_printf(MSG_ERROR,
4238 "Line %d: Invalid fst_group_id value '%s'",
4239 line, pos);
4240 return 1;
4241 }
4242
4243 if (conf->fst_cfg.group_id[0]) {
4244 wpa_printf(MSG_ERROR,
4245 "Line %d: Duplicate fst_group value '%s'",
4246 line, pos);
4247 return 1;
4248 }
4249
4250 os_strlcpy(conf->fst_cfg.group_id, pos,
4251 sizeof(conf->fst_cfg.group_id));
4252 } else if (os_strcmp(buf, "fst_priority") == 0) {
4253 char *endp;
4254 long int val;
4255
4256 if (!*pos) {
4257 wpa_printf(MSG_ERROR,
4258 "Line %d: fst_priority value not supplied (expected 1..%u)",
4259 line, FST_MAX_PRIO_VALUE);
4260 return -1;
4261 }
4262
4263 val = strtol(pos, &endp, 0);
4264 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
4265 wpa_printf(MSG_ERROR,
4266 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
4267 line, val, pos, FST_MAX_PRIO_VALUE);
4268 return 1;
4269 }
4270 conf->fst_cfg.priority = (u8) val;
4271 } else if (os_strcmp(buf, "fst_llt") == 0) {
4272 char *endp;
4273 long int val;
4274
4275 if (!*pos) {
4276 wpa_printf(MSG_ERROR,
4277 "Line %d: fst_llt value not supplied (expected 1..%u)",
4278 line, FST_MAX_LLT_MS);
4279 return -1;
4280 }
4281 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07004282 if (*endp || val < 1 ||
4283 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004284 wpa_printf(MSG_ERROR,
4285 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
4286 line, val, pos, FST_MAX_LLT_MS);
4287 return 1;
4288 }
4289 conf->fst_cfg.llt = (u32) val;
4290#endif /* CONFIG_FST */
4291 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
4292 conf->track_sta_max_num = atoi(pos);
4293 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
4294 conf->track_sta_max_age = atoi(pos);
4295 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
4296 os_free(bss->no_probe_resp_if_seen_on);
4297 bss->no_probe_resp_if_seen_on = os_strdup(pos);
4298 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
4299 os_free(bss->no_auth_if_seen_on);
4300 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004301 } else if (os_strcmp(buf, "lci") == 0) {
4302 wpabuf_free(conf->lci);
4303 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004304 if (conf->lci && wpabuf_len(conf->lci) == 0) {
4305 wpabuf_free(conf->lci);
4306 conf->lci = NULL;
4307 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004308 } else if (os_strcmp(buf, "civic") == 0) {
4309 wpabuf_free(conf->civic);
4310 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004311 if (conf->civic && wpabuf_len(conf->civic) == 0) {
4312 wpabuf_free(conf->civic);
4313 conf->civic = NULL;
4314 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004315 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
4316 if (atoi(pos))
4317 bss->radio_measurements[0] |=
4318 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004319 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
4320 if (atoi(pos))
4321 bss->radio_measurements[0] |=
4322 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4323 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4324 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004325 } else if (os_strcmp(buf, "gas_address3") == 0) {
4326 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004327 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4328 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004329 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4330 bss->ftm_responder = atoi(pos);
4331 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4332 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004333#ifdef CONFIG_FILS
4334 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4335 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4336 wpa_printf(MSG_ERROR,
4337 "Line %d: Invalid fils_cache_id '%s'",
4338 line, pos);
4339 return 1;
4340 }
4341 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004342 } else if (os_strcmp(buf, "fils_realm") == 0) {
4343 if (parse_fils_realm(bss, pos) < 0)
4344 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004345 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4346 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004347 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4348 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4349 wpa_printf(MSG_ERROR,
4350 "Line %d: invalid IP address '%s'",
4351 line, pos);
4352 return 1;
4353 }
4354 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4355 bss->dhcp_rapid_commit_proxy = atoi(pos);
4356 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4357 bss->fils_hlp_wait_time = atoi(pos);
4358 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4359 bss->dhcp_server_port = atoi(pos);
4360 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4361 bss->dhcp_relay_port = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004362#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004363 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4364 bss->multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004365 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4366 bss->broadcast_deauth = atoi(pos);
4367#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07004368 } else if (os_strcmp(buf, "dpp_name") == 0) {
4369 os_free(bss->dpp_name);
4370 bss->dpp_name = os_strdup(pos);
4371 } else if (os_strcmp(buf, "dpp_mud_url") == 0) {
4372 os_free(bss->dpp_mud_url);
4373 bss->dpp_mud_url = os_strdup(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004374 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4375 os_free(bss->dpp_connector);
4376 bss->dpp_connector = os_strdup(pos);
4377 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4378 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4379 return 1;
4380 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4381 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4382 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4383 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4384 return 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07004385#ifdef CONFIG_DPP2
4386 } else if (os_strcmp(buf, "dpp_controller") == 0) {
4387 if (hostapd_dpp_controller_parse(bss, pos))
4388 return 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07004389 } else if (os_strcmp(buf, "dpp_configurator_connectivity") == 0) {
4390 bss->dpp_configurator_connectivity = atoi(pos);
4391 } else if (os_strcmp(buf, "dpp_pfs") == 0) {
4392 int val = atoi(pos);
4393
4394 if (val < 0 || val > 2) {
4395 wpa_printf(MSG_ERROR,
4396 "Line %d: Invalid dpp_pfs value '%s'",
4397 line, pos);
4398 return -1;
4399 }
4400 bss->dpp_pfs = val;
Hai Shalom81f62d82019-07-22 12:10:00 -07004401#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004402#endif /* CONFIG_DPP */
4403#ifdef CONFIG_OWE
4404 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4405 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4406 wpa_printf(MSG_ERROR,
4407 "Line %d: invalid owe_transition_bssid",
4408 line);
4409 return 1;
4410 }
4411 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4412 size_t slen;
4413 char *str = wpa_config_parse_string(pos, &slen);
4414
4415 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4416 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4417 line, pos);
4418 os_free(str);
4419 return 1;
4420 }
4421 os_memcpy(bss->owe_transition_ssid, str, slen);
4422 bss->owe_transition_ssid_len = slen;
4423 os_free(str);
4424 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4425 os_strlcpy(bss->owe_transition_ifname, pos,
4426 sizeof(bss->owe_transition_ifname));
4427 } else if (os_strcmp(buf, "owe_groups") == 0) {
4428 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4429 wpa_printf(MSG_ERROR,
4430 "Line %d: Invalid owe_groups value '%s'",
4431 line, pos);
4432 return 1;
4433 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004434 } else if (os_strcmp(buf, "owe_ptk_workaround") == 0) {
4435 bss->owe_ptk_workaround = atoi(pos);
4436#endif /* CONFIG_OWE */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004437 } else if (os_strcmp(buf, "coloc_intf_reporting") == 0) {
4438 bss->coloc_intf_reporting = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004439 } else if (os_strcmp(buf, "multi_ap") == 0) {
4440 int val = atoi(pos);
4441
4442 if (val < 0 || val > 3) {
4443 wpa_printf(MSG_ERROR, "Line %d: Invalid multi_ap '%s'",
4444 line, buf);
4445 return -1;
4446 }
4447
4448 bss->multi_ap = val;
4449 } else if (os_strcmp(buf, "rssi_reject_assoc_rssi") == 0) {
4450 conf->rssi_reject_assoc_rssi = atoi(pos);
4451 } else if (os_strcmp(buf, "rssi_reject_assoc_timeout") == 0) {
4452 conf->rssi_reject_assoc_timeout = atoi(pos);
4453 } else if (os_strcmp(buf, "pbss") == 0) {
4454 bss->pbss = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004455 } else if (os_strcmp(buf, "transition_disable") == 0) {
4456 bss->transition_disable = strtol(pos, NULL, 16);
Hai Shalom81f62d82019-07-22 12:10:00 -07004457#ifdef CONFIG_AIRTIME_POLICY
4458 } else if (os_strcmp(buf, "airtime_mode") == 0) {
4459 int val = atoi(pos);
4460
4461 if (val < 0 || val > AIRTIME_MODE_MAX) {
4462 wpa_printf(MSG_ERROR, "Line %d: Unknown airtime_mode",
4463 line);
4464 return 1;
4465 }
4466 conf->airtime_mode = val;
4467 } else if (os_strcmp(buf, "airtime_update_interval") == 0) {
4468 conf->airtime_update_interval = atoi(pos);
4469 } else if (os_strcmp(buf, "airtime_bss_weight") == 0) {
4470 bss->airtime_weight = atoi(pos);
4471 } else if (os_strcmp(buf, "airtime_bss_limit") == 0) {
4472 int val = atoi(pos);
4473
4474 if (val < 0 || val > 1) {
4475 wpa_printf(MSG_ERROR,
4476 "Line %d: Invalid airtime_bss_limit (must be 0 or 1)",
4477 line);
4478 return 1;
4479 }
4480 bss->airtime_limit = val;
4481 } else if (os_strcmp(buf, "airtime_sta_weight") == 0) {
4482 if (add_airtime_weight(bss, pos) < 0) {
4483 wpa_printf(MSG_ERROR,
4484 "Line %d: Invalid airtime weight '%s'",
4485 line, pos);
4486 return 1;
4487 }
4488#endif /* CONFIG_AIRTIME_POLICY */
4489#ifdef CONFIG_MACSEC
4490 } else if (os_strcmp(buf, "macsec_policy") == 0) {
4491 int macsec_policy = atoi(pos);
4492
4493 if (macsec_policy < 0 || macsec_policy > 1) {
4494 wpa_printf(MSG_ERROR,
4495 "Line %d: invalid macsec_policy (%d): '%s'.",
4496 line, macsec_policy, pos);
4497 return 1;
4498 }
4499 bss->macsec_policy = macsec_policy;
4500 } else if (os_strcmp(buf, "macsec_integ_only") == 0) {
4501 int macsec_integ_only = atoi(pos);
4502
4503 if (macsec_integ_only < 0 || macsec_integ_only > 1) {
4504 wpa_printf(MSG_ERROR,
4505 "Line %d: invalid macsec_integ_only (%d): '%s'.",
4506 line, macsec_integ_only, pos);
4507 return 1;
4508 }
4509 bss->macsec_integ_only = macsec_integ_only;
4510 } else if (os_strcmp(buf, "macsec_replay_protect") == 0) {
4511 int macsec_replay_protect = atoi(pos);
4512
4513 if (macsec_replay_protect < 0 || macsec_replay_protect > 1) {
4514 wpa_printf(MSG_ERROR,
4515 "Line %d: invalid macsec_replay_protect (%d): '%s'.",
4516 line, macsec_replay_protect, pos);
4517 return 1;
4518 }
4519 bss->macsec_replay_protect = macsec_replay_protect;
4520 } else if (os_strcmp(buf, "macsec_replay_window") == 0) {
4521 bss->macsec_replay_window = atoi(pos);
4522 } else if (os_strcmp(buf, "macsec_port") == 0) {
4523 int macsec_port = atoi(pos);
4524
4525 if (macsec_port < 1 || macsec_port > 65534) {
4526 wpa_printf(MSG_ERROR,
4527 "Line %d: invalid macsec_port (%d): '%s'.",
4528 line, macsec_port, pos);
4529 return 1;
4530 }
4531 bss->macsec_port = macsec_port;
4532 } else if (os_strcmp(buf, "mka_priority") == 0) {
4533 int mka_priority = atoi(pos);
4534
4535 if (mka_priority < 0 || mka_priority > 255) {
4536 wpa_printf(MSG_ERROR,
4537 "Line %d: invalid mka_priority (%d): '%s'.",
4538 line, mka_priority, pos);
4539 return 1;
4540 }
4541 bss->mka_priority = mka_priority;
4542 } else if (os_strcmp(buf, "mka_cak") == 0) {
4543 size_t len = os_strlen(pos);
4544
4545 if (len > 2 * MACSEC_CAK_MAX_LEN ||
4546 (len != 2 * 16 && len != 2 * 32) ||
4547 hexstr2bin(pos, bss->mka_cak, len / 2)) {
4548 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.",
4549 line, pos);
4550 return 1;
4551 }
4552 bss->mka_cak_len = len / 2;
4553 bss->mka_psk_set |= MKA_PSK_SET_CAK;
4554 } else if (os_strcmp(buf, "mka_ckn") == 0) {
4555 size_t len = os_strlen(pos);
4556
4557 if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */
4558 len < 2 || /* too short */
4559 len % 2 != 0 /* not an integral number of bytes */) {
4560 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4561 line, pos);
4562 return 1;
4563 }
4564 bss->mka_ckn_len = len / 2;
4565 if (hexstr2bin(pos, bss->mka_ckn, bss->mka_ckn_len)) {
4566 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4567 line, pos);
4568 return -1;
4569 }
4570 bss->mka_psk_set |= MKA_PSK_SET_CKN;
4571#endif /* CONFIG_MACSEC */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004572 } else {
4573 wpa_printf(MSG_ERROR,
4574 "Line %d: unknown configuration item '%s'",
4575 line, buf);
4576 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004577 }
4578
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004579 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004580}
4581
4582
Dmitry Shmidt04949592012-07-19 12:16:46 -07004583/**
4584 * hostapd_config_read - Read and parse a configuration file
4585 * @fname: Configuration file name (including path, if needed)
4586 * Returns: Allocated configuration data structure
4587 */
4588struct hostapd_config * hostapd_config_read(const char *fname)
4589{
4590 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004591 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004592 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004593 int line = 0;
4594 int errors = 0;
4595 size_t i;
4596
4597 f = fopen(fname, "r");
4598 if (f == NULL) {
4599 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4600 "for reading.", fname);
4601 return NULL;
4602 }
4603
4604 conf = hostapd_config_defaults();
4605 if (conf == NULL) {
4606 fclose(f);
4607 return NULL;
4608 }
4609
4610 /* set default driver based on configuration */
4611 conf->driver = wpa_drivers[0];
4612 if (conf->driver == NULL) {
4613 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4614 hostapd_config_free(conf);
4615 fclose(f);
4616 return NULL;
4617 }
4618
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004619 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004620
4621 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004622 struct hostapd_bss_config *bss;
4623
Dmitry Shmidt04949592012-07-19 12:16:46 -07004624 bss = conf->last_bss;
4625 line++;
4626
4627 if (buf[0] == '#')
4628 continue;
4629 pos = buf;
4630 while (*pos != '\0') {
4631 if (*pos == '\n') {
4632 *pos = '\0';
4633 break;
4634 }
4635 pos++;
4636 }
4637 if (buf[0] == '\0')
4638 continue;
4639
4640 pos = os_strchr(buf, '=');
4641 if (pos == NULL) {
4642 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4643 line, buf);
4644 errors++;
4645 continue;
4646 }
4647 *pos = '\0';
4648 pos++;
4649 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4650 }
4651
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004652 fclose(f);
4653
Dmitry Shmidt04949592012-07-19 12:16:46 -07004654 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004655 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004656
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004657 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004658 errors++;
4659
4660#ifndef WPA_IGNORE_CONFIG_ERRORS
4661 if (errors) {
4662 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4663 "'%s'", errors, fname);
4664 hostapd_config_free(conf);
4665 conf = NULL;
4666 }
4667#endif /* WPA_IGNORE_CONFIG_ERRORS */
4668
4669 return conf;
4670}
Dmitry Shmidt04949592012-07-19 12:16:46 -07004671
4672
4673int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004674 struct hostapd_bss_config *bss, const char *field,
4675 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004676{
4677 int errors;
4678 size_t i;
4679
4680 errors = hostapd_config_fill(conf, bss, field, value, 0);
4681 if (errors) {
4682 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4683 "to value '%s'", field, value);
4684 return -1;
4685 }
4686
4687 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004688 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004689
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004690 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004691 wpa_printf(MSG_ERROR, "Configuration check failed");
4692 return -1;
4693 }
4694
4695 return 0;
4696}