blob: 2d5a510c466d66c6cafd2b91ca0156e23a098ddf [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10#ifndef CONFIG_NATIVE_WINDOWS
11#include <grp.h>
12#endif /* CONFIG_NATIVE_WINDOWS */
13
14#include "utils/common.h"
15#include "utils/uuid.h"
Hai Shaloma20dcd72022-02-04 13:43:00 -080016#include "utils/crc32.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "common/ieee802_11_defs.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070018#include "common/sae.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070019#include "crypto/sha256.h"
20#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "drivers/driver.h"
22#include "eap_server/eap.h"
23#include "radius/radius_client.h"
24#include "ap/wpa_auth.h"
25#include "ap/ap_config.h"
26#include "config_file.h"
27
28
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#ifndef CONFIG_NO_VLAN
30static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
31 const char *fname)
32{
33 FILE *f;
Hai Shalom74f70d42019-02-11 14:42:39 -080034 char buf[128], *pos, *pos2, *pos3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035 int line = 0, vlan_id;
36 struct hostapd_vlan *vlan;
37
38 f = fopen(fname, "r");
39 if (!f) {
40 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
41 return -1;
42 }
43
44 while (fgets(buf, sizeof(buf), f)) {
45 line++;
46
47 if (buf[0] == '#')
48 continue;
49 pos = buf;
50 while (*pos != '\0') {
51 if (*pos == '\n') {
52 *pos = '\0';
53 break;
54 }
55 pos++;
56 }
57 if (buf[0] == '\0')
58 continue;
59
60 if (buf[0] == '*') {
61 vlan_id = VLAN_ID_WILDCARD;
62 pos = buf + 1;
63 } else {
64 vlan_id = strtol(buf, &pos, 10);
65 if (buf == pos || vlan_id < 1 ||
66 vlan_id > MAX_VLAN_ID) {
67 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
68 "line %d in '%s'", line, fname);
69 fclose(f);
70 return -1;
71 }
72 }
73
74 while (*pos == ' ' || *pos == '\t')
75 pos++;
76 pos2 = pos;
77 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
78 pos2++;
Hai Shalom74f70d42019-02-11 14:42:39 -080079
80 if (*pos2 != '\0')
81 *(pos2++) = '\0';
82
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
84 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
85 "in '%s'", line, fname);
86 fclose(f);
87 return -1;
88 }
89
Hai Shalom74f70d42019-02-11 14:42:39 -080090 while (*pos2 == ' ' || *pos2 == '\t')
91 pos2++;
92 pos3 = pos2;
93 while (*pos3 != ' ' && *pos3 != '\t' && *pos3 != '\0')
94 pos3++;
95 *pos3 = '\0';
96
Dmitry Shmidt4b060592013-04-29 16:42:49 -070097 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098 if (vlan == NULL) {
99 wpa_printf(MSG_ERROR, "Out of memory while reading "
100 "VLAN interfaces from '%s'", fname);
101 fclose(f);
102 return -1;
103 }
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105 vlan->vlan_id = vlan_id;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800106 vlan->vlan_desc.untagged = vlan_id;
107 vlan->vlan_desc.notempty = !!vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Hai Shalom74f70d42019-02-11 14:42:39 -0800109 os_strlcpy(vlan->bridge, pos2, sizeof(vlan->bridge));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700110 vlan->next = bss->vlan;
111 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 }
113
114 fclose(f);
115
116 return 0;
117}
118#endif /* CONFIG_NO_VLAN */
119
120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121static int hostapd_config_read_maclist(const char *fname,
122 struct mac_acl_entry **acl, int *num)
123{
124 FILE *f;
125 char buf[128], *pos;
126 int line = 0;
127 u8 addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 int vlan_id;
129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 f = fopen(fname, "r");
131 if (!f) {
132 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
133 return -1;
134 }
135
136 while (fgets(buf, sizeof(buf), f)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700137 int rem = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139 line++;
140
141 if (buf[0] == '#')
142 continue;
143 pos = buf;
144 while (*pos != '\0') {
145 if (*pos == '\n') {
146 *pos = '\0';
147 break;
148 }
149 pos++;
150 }
151 if (buf[0] == '\0')
152 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800153 pos = buf;
154 if (buf[0] == '-') {
155 rem = 1;
156 pos++;
157 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800159 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800161 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 fclose(f);
163 return -1;
164 }
165
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800166 if (rem) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700167 hostapd_remove_acl_mac(acl, num, addr);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800168 continue;
169 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 vlan_id = 0;
171 pos = buf;
172 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
173 pos++;
174 while (*pos == ' ' || *pos == '\t')
175 pos++;
176 if (*pos != '\0')
177 vlan_id = atoi(pos);
178
Roshan Pius3a1667e2018-07-03 15:17:14 -0700179 if (hostapd_add_acl_maclist(acl, num, vlan_id, addr) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 fclose(f);
181 return -1;
182 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 }
184
185 fclose(f);
186
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800187 if (*acl)
188 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
190 return 0;
191}
192
193
194#ifdef EAP_SERVER
Roshan Pius3a1667e2018-07-03 15:17:14 -0700195
196static int hostapd_config_eap_user_salted(struct hostapd_eap_user *user,
197 const char *hash, size_t len,
198 char **pos, int line,
199 const char *fname)
200{
201 char *pos2 = *pos;
202
203 while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#')
204 pos2++;
205
206 if (pos2 - *pos < (int) (2 * (len + 1))) { /* at least 1 byte of salt */
207 wpa_printf(MSG_ERROR,
208 "Invalid salted %s hash on line %d in '%s'",
209 hash, line, fname);
210 return -1;
211 }
212
213 user->password = os_malloc(len);
214 if (!user->password) {
215 wpa_printf(MSG_ERROR,
216 "Failed to allocate memory for salted %s hash",
217 hash);
218 return -1;
219 }
220
221 if (hexstr2bin(*pos, user->password, len) < 0) {
222 wpa_printf(MSG_ERROR,
223 "Invalid salted password on line %d in '%s'",
224 line, fname);
225 return -1;
226 }
227 user->password_len = len;
228 *pos += 2 * len;
229
230 user->salt_len = (pos2 - *pos) / 2;
231 user->salt = os_malloc(user->salt_len);
232 if (!user->salt) {
233 wpa_printf(MSG_ERROR,
234 "Failed to allocate memory for salted %s hash",
235 hash);
236 return -1;
237 }
238
239 if (hexstr2bin(*pos, user->salt, user->salt_len) < 0) {
240 wpa_printf(MSG_ERROR,
241 "Invalid salt for password on line %d in '%s'",
242 line, fname);
243 return -1;
244 }
245
246 *pos = pos2;
247 return 0;
248}
249
250
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251static int hostapd_config_read_eap_user(const char *fname,
252 struct hostapd_bss_config *conf)
253{
254 FILE *f;
255 char buf[512], *pos, *start, *pos2;
256 int line = 0, ret = 0, num_methods;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800257 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800259 if (os_strncmp(fname, "sqlite:", 7) == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700260#ifdef CONFIG_SQLITE
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800261 os_free(conf->eap_user_sqlite);
262 conf->eap_user_sqlite = os_strdup(fname + 7);
263 return 0;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700264#else /* CONFIG_SQLITE */
265 wpa_printf(MSG_ERROR,
266 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
267 return -1;
268#endif /* CONFIG_SQLITE */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800269 }
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 f = fopen(fname, "r");
272 if (!f) {
273 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
274 return -1;
275 }
276
277 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
278 while (fgets(buf, sizeof(buf), f)) {
279 line++;
280
281 if (buf[0] == '#')
282 continue;
283 pos = buf;
284 while (*pos != '\0') {
285 if (*pos == '\n') {
286 *pos = '\0';
287 break;
288 }
289 pos++;
290 }
291 if (buf[0] == '\0')
292 continue;
293
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700294#ifndef CONFIG_NO_RADIUS
295 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
296 struct hostapd_radius_attr *attr, *a;
297 attr = hostapd_parse_radius_attr(buf + 19);
298 if (attr == NULL) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700299 wpa_printf(MSG_ERROR, "Invalid radius_accept_attr: %s",
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700300 buf + 19);
Dmitry Shmidt98660862014-03-11 17:26:21 -0700301 user = NULL; /* already in the BSS list */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700302 goto failed;
303 }
304 if (user->accept_attr == NULL) {
305 user->accept_attr = attr;
306 } else {
307 a = user->accept_attr;
308 while (a->next)
309 a = a->next;
310 a->next = attr;
311 }
312 continue;
313 }
314#endif /* CONFIG_NO_RADIUS */
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 user = NULL;
317
318 if (buf[0] != '"' && buf[0] != '*') {
319 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
320 "start) on line %d in '%s'", line, fname);
321 goto failed;
322 }
323
324 user = os_zalloc(sizeof(*user));
325 if (user == NULL) {
326 wpa_printf(MSG_ERROR, "EAP user allocation failed");
327 goto failed;
328 }
329 user->force_version = -1;
330
331 if (buf[0] == '*') {
332 pos = buf;
333 } else {
334 pos = buf + 1;
335 start = pos;
336 while (*pos != '"' && *pos != '\0')
337 pos++;
338 if (*pos == '\0') {
339 wpa_printf(MSG_ERROR, "Invalid EAP identity "
340 "(no \" in end) on line %d in '%s'",
341 line, fname);
342 goto failed;
343 }
344
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700345 user->identity = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 if (user->identity == NULL) {
347 wpa_printf(MSG_ERROR, "Failed to allocate "
348 "memory for EAP identity");
349 goto failed;
350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 user->identity_len = pos - start;
352
353 if (pos[0] == '"' && pos[1] == '*') {
354 user->wildcard_prefix = 1;
355 pos++;
356 }
357 }
358 pos++;
359 while (*pos == ' ' || *pos == '\t')
360 pos++;
361
362 if (*pos == '\0') {
363 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
364 "'%s'", line, fname);
365 goto failed;
366 }
367
368 start = pos;
369 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
370 pos++;
371 if (*pos == '\0') {
372 pos = NULL;
373 } else {
374 *pos = '\0';
375 pos++;
376 }
377 num_methods = 0;
378 while (*start) {
379 char *pos3 = os_strchr(start, ',');
380 if (pos3) {
381 *pos3++ = '\0';
382 }
383 user->methods[num_methods].method =
384 eap_server_get_type(
385 start,
386 &user->methods[num_methods].vendor);
387 if (user->methods[num_methods].vendor ==
388 EAP_VENDOR_IETF &&
389 user->methods[num_methods].method == EAP_TYPE_NONE)
390 {
391 if (os_strcmp(start, "TTLS-PAP") == 0) {
392 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
393 goto skip_eap;
394 }
395 if (os_strcmp(start, "TTLS-CHAP") == 0) {
396 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
397 goto skip_eap;
398 }
399 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
400 user->ttls_auth |=
401 EAP_TTLS_AUTH_MSCHAP;
402 goto skip_eap;
403 }
404 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
405 user->ttls_auth |=
406 EAP_TTLS_AUTH_MSCHAPV2;
407 goto skip_eap;
408 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700409 if (os_strcmp(start, "MACACL") == 0) {
410 user->macacl = 1;
411 goto skip_eap;
412 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 wpa_printf(MSG_ERROR, "Unsupported EAP type "
414 "'%s' on line %d in '%s'",
415 start, line, fname);
416 goto failed;
417 }
418
419 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 break;
422 skip_eap:
423 if (pos3 == NULL)
424 break;
425 start = pos3;
426 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700427 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 wpa_printf(MSG_ERROR, "No EAP types configured on "
429 "line %d in '%s'", line, fname);
430 goto failed;
431 }
432
433 if (pos == NULL)
434 goto done;
435
436 while (*pos == ' ' || *pos == '\t')
437 pos++;
438 if (*pos == '\0')
439 goto done;
440
441 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
442 user->force_version = 0;
443 goto done;
444 }
445
446 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
447 user->force_version = 1;
448 goto done;
449 }
450
451 if (os_strncmp(pos, "[2]", 3) == 0) {
452 user->phase2 = 1;
453 goto done;
454 }
455
456 if (*pos == '"') {
457 pos++;
458 start = pos;
459 while (*pos != '"' && *pos != '\0')
460 pos++;
461 if (*pos == '\0') {
462 wpa_printf(MSG_ERROR, "Invalid EAP password "
463 "(no \" in end) on line %d in '%s'",
464 line, fname);
465 goto failed;
466 }
467
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700468 user->password = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 if (user->password == NULL) {
470 wpa_printf(MSG_ERROR, "Failed to allocate "
471 "memory for EAP password");
472 goto failed;
473 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 user->password_len = pos - start;
475
476 pos++;
477 } else if (os_strncmp(pos, "hash:", 5) == 0) {
478 pos += 5;
479 pos2 = pos;
480 while (*pos2 != '\0' && *pos2 != ' ' &&
481 *pos2 != '\t' && *pos2 != '#')
482 pos2++;
483 if (pos2 - pos != 32) {
484 wpa_printf(MSG_ERROR, "Invalid password hash "
485 "on line %d in '%s'", line, fname);
486 goto failed;
487 }
488 user->password = os_malloc(16);
489 if (user->password == NULL) {
490 wpa_printf(MSG_ERROR, "Failed to allocate "
491 "memory for EAP password hash");
492 goto failed;
493 }
494 if (hexstr2bin(pos, user->password, 16) < 0) {
495 wpa_printf(MSG_ERROR, "Invalid hash password "
496 "on line %d in '%s'", line, fname);
497 goto failed;
498 }
499 user->password_len = 16;
500 user->password_hash = 1;
501 pos = pos2;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700502 } else if (os_strncmp(pos, "ssha1:", 6) == 0) {
503 pos += 6;
504 if (hostapd_config_eap_user_salted(user, "sha1", 20,
505 &pos,
506 line, fname) < 0)
507 goto failed;
508 } else if (os_strncmp(pos, "ssha256:", 8) == 0) {
509 pos += 8;
510 if (hostapd_config_eap_user_salted(user, "sha256", 32,
511 &pos,
512 line, fname) < 0)
513 goto failed;
514 } else if (os_strncmp(pos, "ssha512:", 8) == 0) {
515 pos += 8;
516 if (hostapd_config_eap_user_salted(user, "sha512", 64,
517 &pos,
518 line, fname) < 0)
519 goto failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 } else {
521 pos2 = pos;
522 while (*pos2 != '\0' && *pos2 != ' ' &&
523 *pos2 != '\t' && *pos2 != '#')
524 pos2++;
525 if ((pos2 - pos) & 1) {
526 wpa_printf(MSG_ERROR, "Invalid hex password "
527 "on line %d in '%s'", line, fname);
528 goto failed;
529 }
530 user->password = os_malloc((pos2 - pos) / 2);
531 if (user->password == NULL) {
532 wpa_printf(MSG_ERROR, "Failed to allocate "
533 "memory for EAP password");
534 goto failed;
535 }
536 if (hexstr2bin(pos, user->password,
537 (pos2 - pos) / 2) < 0) {
538 wpa_printf(MSG_ERROR, "Invalid hex password "
539 "on line %d in '%s'", line, fname);
540 goto failed;
541 }
542 user->password_len = (pos2 - pos) / 2;
543 pos = pos2;
544 }
545
546 while (*pos == ' ' || *pos == '\t')
547 pos++;
548 if (os_strncmp(pos, "[2]", 3) == 0) {
549 user->phase2 = 1;
550 }
551
552 done:
553 if (tail == NULL) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800554 tail = new_user = user;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 } else {
556 tail->next = user;
557 tail = user;
558 }
559 continue;
560
561 failed:
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700562 if (user)
563 hostapd_config_free_eap_user(user);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 ret = -1;
565 break;
566 }
567
568 fclose(f);
569
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800570 if (ret == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800571 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800572 conf->eap_user = new_user;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800573 } else {
574 hostapd_config_free_eap_users(new_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800575 }
576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 return ret;
578}
Roshan Pius3a1667e2018-07-03 15:17:14 -0700579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580#endif /* EAP_SERVER */
581
582
583#ifndef CONFIG_NO_RADIUS
584static int
585hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
586 int *num_server, const char *val, int def_port,
587 struct hostapd_radius_server **curr_serv)
588{
589 struct hostapd_radius_server *nserv;
590 int ret;
591 static int server_index = 1;
592
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700593 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 if (nserv == NULL)
595 return -1;
596
597 *server = nserv;
598 nserv = &nserv[*num_server];
599 (*num_server)++;
600 (*curr_serv) = nserv;
601
602 os_memset(nserv, 0, sizeof(*nserv));
603 nserv->port = def_port;
604 ret = hostapd_parse_ip_addr(val, &nserv->addr);
605 nserv->index = server_index++;
606
607 return ret;
608}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700609
610
Dmitry Shmidt04949592012-07-19 12:16:46 -0700611
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700612static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700613{
614 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700615
616 secret = os_strchr(val, ' ');
617 if (secret == NULL)
618 return -1;
619
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700620 *secret++ = '\0';
Dmitry Shmidt04949592012-07-19 12:16:46 -0700621
622 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
623 return -1;
624
625 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700626 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700627 if (bss->radius_das_shared_secret == NULL)
628 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700629 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700630
631 return 0;
632}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633#endif /* CONFIG_NO_RADIUS */
634
635
636static int hostapd_config_parse_key_mgmt(int line, const char *value)
637{
638 int val = 0, last;
639 char *start, *end, *buf;
640
641 buf = os_strdup(value);
642 if (buf == NULL)
643 return -1;
644 start = buf;
645
646 while (*start != '\0') {
647 while (*start == ' ' || *start == '\t')
648 start++;
649 if (*start == '\0')
650 break;
651 end = start;
652 while (*end != ' ' && *end != '\t' && *end != '\0')
653 end++;
654 last = *end == '\0';
655 *end = '\0';
656 if (os_strcmp(start, "WPA-PSK") == 0)
657 val |= WPA_KEY_MGMT_PSK;
658 else if (os_strcmp(start, "WPA-EAP") == 0)
659 val |= WPA_KEY_MGMT_IEEE8021X;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800660#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 else if (os_strcmp(start, "FT-PSK") == 0)
662 val |= WPA_KEY_MGMT_FT_PSK;
663 else if (os_strcmp(start, "FT-EAP") == 0)
664 val |= WPA_KEY_MGMT_FT_IEEE8021X;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700665#ifdef CONFIG_SHA384
666 else if (os_strcmp(start, "FT-EAP-SHA384") == 0)
667 val |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
668#endif /* CONFIG_SHA384 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800669#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
671 val |= WPA_KEY_MGMT_PSK_SHA256;
672 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
673 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800674#ifdef CONFIG_SAE
675 else if (os_strcmp(start, "SAE") == 0)
676 val |= WPA_KEY_MGMT_SAE;
677 else if (os_strcmp(start, "FT-SAE") == 0)
678 val |= WPA_KEY_MGMT_FT_SAE;
679#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800680#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800681 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
682 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800683#endif /* CONFIG_SUITEB */
684#ifdef CONFIG_SUITEB192
685 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
686 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
687#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800688#ifdef CONFIG_FILS
689 else if (os_strcmp(start, "FILS-SHA256") == 0)
690 val |= WPA_KEY_MGMT_FILS_SHA256;
691 else if (os_strcmp(start, "FILS-SHA384") == 0)
692 val |= WPA_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800693#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800694 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
695 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
696 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
697 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800698#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800699#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700700#ifdef CONFIG_OWE
701 else if (os_strcmp(start, "OWE") == 0)
702 val |= WPA_KEY_MGMT_OWE;
703#endif /* CONFIG_OWE */
704#ifdef CONFIG_DPP
705 else if (os_strcmp(start, "DPP") == 0)
706 val |= WPA_KEY_MGMT_DPP;
707#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700708#ifdef CONFIG_HS20
709 else if (os_strcmp(start, "OSEN") == 0)
710 val |= WPA_KEY_MGMT_OSEN;
711#endif /* CONFIG_HS20 */
Hai Shalom60840252021-02-19 19:02:11 -0800712#ifdef CONFIG_PASN
713 else if (os_strcmp(start, "PASN") == 0)
714 val |= WPA_KEY_MGMT_PASN;
715#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716 else {
717 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
718 line, start);
719 os_free(buf);
720 return -1;
721 }
722
723 if (last)
724 break;
725 start = end + 1;
726 }
727
728 os_free(buf);
729 if (val == 0) {
730 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
731 "configured.", line);
732 return -1;
733 }
734
735 return val;
736}
737
738
739static int hostapd_config_parse_cipher(int line, const char *value)
740{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800741 int val = wpa_parse_cipher(value);
742 if (val < 0) {
743 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
744 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 if (val == 0) {
748 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
749 line);
750 return -1;
751 }
752 return val;
753}
754
755
Hai Shalomfdcde762020-04-02 11:19:20 -0700756#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
758 char *val)
759{
760 size_t len = os_strlen(val);
761
Dmitry Shmidt29333592017-01-09 12:27:11 -0800762 if (keyidx < 0 || keyidx > 3)
763 return -1;
764
765 if (len == 0) {
766 int i, set = 0;
767
768 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
769 wep->key[keyidx] = NULL;
770 wep->len[keyidx] = 0;
771 for (i = 0; i < NUM_WEP_KEYS; i++) {
772 if (wep->key[i])
773 set++;
774 }
775 if (!set)
776 wep->keys_set = 0;
777 return 0;
778 }
779
780 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781 return -1;
782
783 if (val[0] == '"') {
784 if (len < 2 || val[len - 1] != '"')
785 return -1;
786 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700787 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 if (wep->key[keyidx] == NULL)
789 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 wep->len[keyidx] = len;
791 } else {
792 if (len & 1)
793 return -1;
794 len /= 2;
795 wep->key[keyidx] = os_malloc(len);
796 if (wep->key[keyidx] == NULL)
797 return -1;
798 wep->len[keyidx] = len;
799 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
800 return -1;
801 }
802
803 wep->keys_set++;
804
805 return 0;
806}
Hai Shalomfdcde762020-04-02 11:19:20 -0700807#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808
809
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700810static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
811{
812 char *pos;
813
814 /* for backwards compatibility, translate ' ' in conf str to ',' */
815 pos = val;
816 while (pos) {
817 pos = os_strchr(pos, ' ');
818 if (pos)
819 *pos++ = ',';
820 }
821 if (freq_range_list_parse(&conf->acs_ch_list, val))
822 return -1;
823
824 return 0;
825}
826
827
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700828static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829{
830 int *list;
831 int count;
832 char *pos, *end;
833
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700834 os_free(*int_list);
835 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836
837 pos = val;
838 count = 0;
839 while (*pos != '\0') {
840 if (*pos == ' ')
841 count++;
842 pos++;
843 }
844
845 list = os_malloc(sizeof(int) * (count + 2));
846 if (list == NULL)
847 return -1;
848 pos = val;
849 count = 0;
850 while (*pos != '\0') {
851 end = os_strchr(pos, ' ');
852 if (end)
853 *end = '\0';
854
855 list[count++] = atoi(pos);
856 if (!end)
857 break;
858 pos = end + 1;
859 }
860 list[count] = -1;
861
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700862 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 return 0;
864}
865
866
867static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
868{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800869 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870
871 if (*ifname == '\0')
872 return -1;
873
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800874 all = os_realloc_array(conf->bss, conf->num_bss + 1,
875 sizeof(struct hostapd_bss_config *));
876 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
878 "multi-BSS entry");
879 return -1;
880 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800881 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800883 bss = os_zalloc(sizeof(*bss));
884 if (bss == NULL)
885 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 bss->radius = os_zalloc(sizeof(*bss->radius));
887 if (bss->radius == NULL) {
888 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
889 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800890 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891 return -1;
892 }
893
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800894 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 conf->last_bss = bss;
896
897 hostapd_config_defaults_bss(bss);
898 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
899 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
900
901 return 0;
902}
903
904
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800905#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700906
907static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
908{
909 u8 oldkey[16];
910 int ret;
911
912 if (!hexstr2bin(pos, key, key_len))
913 return 0;
914
915 /* Try to use old short key for backwards compatibility */
916 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
917 return -1;
918
919 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
920 key, key_len);
921 os_memset(oldkey, 0, sizeof(oldkey));
922 return ret;
923}
924
925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926static int add_r0kh(struct hostapd_bss_config *bss, char *value)
927{
928 struct ft_remote_r0kh *r0kh;
929 char *pos, *next;
930
931 r0kh = os_zalloc(sizeof(*r0kh));
932 if (r0kh == NULL)
933 return -1;
934
935 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
936 pos = value;
937 next = os_strchr(pos, ' ');
938 if (next)
939 *next++ = '\0';
940 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
941 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
942 os_free(r0kh);
943 return -1;
944 }
945
946 pos = next;
947 next = os_strchr(pos, ' ');
948 if (next)
949 *next++ = '\0';
950 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
951 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
952 os_free(r0kh);
953 return -1;
954 }
955 r0kh->id_len = next - pos - 1;
956 os_memcpy(r0kh->id, pos, r0kh->id_len);
957
958 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700959 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
961 os_free(r0kh);
962 return -1;
963 }
964
965 r0kh->next = bss->r0kh_list;
966 bss->r0kh_list = r0kh;
967
968 return 0;
969}
970
971
972static int add_r1kh(struct hostapd_bss_config *bss, char *value)
973{
974 struct ft_remote_r1kh *r1kh;
975 char *pos, *next;
976
977 r1kh = os_zalloc(sizeof(*r1kh));
978 if (r1kh == NULL)
979 return -1;
980
981 /* 02:01:02:03:04:05 02:01:02:03:04:05
982 * 000102030405060708090a0b0c0d0e0f */
983 pos = value;
984 next = os_strchr(pos, ' ');
985 if (next)
986 *next++ = '\0';
987 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
988 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
989 os_free(r1kh);
990 return -1;
991 }
992
993 pos = next;
994 next = os_strchr(pos, ' ');
995 if (next)
996 *next++ = '\0';
997 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
998 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
999 os_free(r1kh);
1000 return -1;
1001 }
1002
1003 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001004 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1006 os_free(r1kh);
1007 return -1;
1008 }
1009
1010 r1kh->next = bss->r1kh_list;
1011 bss->r1kh_list = r1kh;
1012
1013 return 0;
1014}
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001015#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016
1017
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018static int hostapd_config_ht_capab(struct hostapd_config *conf,
1019 const char *capab)
1020{
1021 if (os_strstr(capab, "[LDPC]"))
1022 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1023 if (os_strstr(capab, "[HT40-]")) {
1024 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1025 conf->secondary_channel = -1;
1026 }
1027 if (os_strstr(capab, "[HT40+]")) {
1028 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1029 conf->secondary_channel = 1;
1030 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001031 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1032 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1033 conf->ht40_plus_minus_allowed = 1;
1034 }
Hai Shalomce48b4a2018-09-05 11:41:35 -07001035 if (!os_strstr(capab, "[HT40+]") && !os_strstr(capab, "[HT40-]"))
1036 conf->secondary_channel = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 if (os_strstr(capab, "[GF]"))
1038 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1039 if (os_strstr(capab, "[SHORT-GI-20]"))
1040 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1041 if (os_strstr(capab, "[SHORT-GI-40]"))
1042 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1043 if (os_strstr(capab, "[TX-STBC]"))
1044 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1045 if (os_strstr(capab, "[RX-STBC1]")) {
1046 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1047 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1048 }
1049 if (os_strstr(capab, "[RX-STBC12]")) {
1050 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1051 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1052 }
1053 if (os_strstr(capab, "[RX-STBC123]")) {
1054 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1055 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1056 }
1057 if (os_strstr(capab, "[DELAYED-BA]"))
1058 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1059 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1060 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1061 if (os_strstr(capab, "[DSSS_CCK-40]"))
1062 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001063 if (os_strstr(capab, "[40-INTOLERANT]"))
1064 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1066 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1067
1068 return 0;
1069}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070
1071
Dmitry Shmidt04949592012-07-19 12:16:46 -07001072#ifdef CONFIG_IEEE80211AC
1073static int hostapd_config_vht_capab(struct hostapd_config *conf,
1074 const char *capab)
1075{
1076 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1077 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1078 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1079 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1080 if (os_strstr(capab, "[VHT160]"))
1081 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1082 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1083 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001084 if (os_strstr(capab, "[RXLDPC]"))
1085 conf->vht_capab |= VHT_CAP_RXLDPC;
1086 if (os_strstr(capab, "[SHORT-GI-80]"))
1087 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1088 if (os_strstr(capab, "[SHORT-GI-160]"))
1089 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1090 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1091 conf->vht_capab |= VHT_CAP_TXSTBC;
1092 if (os_strstr(capab, "[RX-STBC-1]"))
1093 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1094 if (os_strstr(capab, "[RX-STBC-12]"))
1095 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1096 if (os_strstr(capab, "[RX-STBC-123]"))
1097 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1098 if (os_strstr(capab, "[RX-STBC-1234]"))
1099 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1100 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001101 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001102 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001103 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001104 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001105 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1106 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001107 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1108 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1109 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1110 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1111 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1112 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001113 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001114 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1115 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001116 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1117 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1118 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1119 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1120 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1121 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001122 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1123 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001124 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1125 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1126 if (os_strstr(capab, "[HTC-VHT]"))
1127 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001128 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1129 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1130 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1131 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1132 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1133 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1134 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1135 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1136 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1137 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1138 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1139 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1140 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1141 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001142 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1143 (conf->vht_capab & VHT_CAP_HTC_VHT))
1144 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1145 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1146 (conf->vht_capab & VHT_CAP_HTC_VHT))
1147 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1148 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1149 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1150 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1151 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1152 return 0;
1153}
1154#endif /* CONFIG_IEEE80211AC */
1155
1156
Hai Shalom74f70d42019-02-11 14:42:39 -08001157#ifdef CONFIG_IEEE80211AX
1158
1159static u8 find_bit_offset(u8 val)
1160{
1161 u8 res = 0;
1162
1163 for (; val; val >>= 1) {
1164 if (val & 1)
1165 break;
1166 res++;
1167 }
1168
1169 return res;
1170}
1171
1172
1173static u8 set_he_cap(int val, u8 mask)
1174{
1175 return (u8) (mask & (val << find_bit_offset(mask)));
1176}
1177
Hai Shalom60840252021-02-19 19:02:11 -08001178
1179static int hostapd_parse_he_srg_bitmap(u8 *bitmap, char *val)
1180{
1181 int bitpos;
1182 char *pos, *end;
1183
1184 os_memset(bitmap, 0, 8);
1185 pos = val;
1186 while (*pos != '\0') {
1187 end = os_strchr(pos, ' ');
1188 if (end)
1189 *end = '\0';
1190
1191 bitpos = atoi(pos);
1192 if (bitpos < 0 || bitpos > 64)
1193 return -1;
1194
1195 bitmap[bitpos / 8] |= BIT(bitpos % 8);
1196 if (!end)
1197 break;
1198 pos = end + 1;
1199 }
1200
1201 return 0;
1202}
1203
Hai Shalom74f70d42019-02-11 14:42:39 -08001204#endif /* CONFIG_IEEE80211AX */
1205
1206
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001207#ifdef CONFIG_INTERWORKING
1208static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1209 int line)
1210{
1211 size_t len = os_strlen(pos);
1212 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1213
1214 struct hostapd_roaming_consortium *rc;
1215
1216 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1217 hexstr2bin(pos, oi, len / 2)) {
1218 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1219 "'%s'", line, pos);
1220 return -1;
1221 }
1222 len /= 2;
1223
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001224 rc = os_realloc_array(bss->roaming_consortium,
1225 bss->roaming_consortium_count + 1,
1226 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001227 if (rc == NULL)
1228 return -1;
1229
1230 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1231 rc[bss->roaming_consortium_count].len = len;
1232
1233 bss->roaming_consortium = rc;
1234 bss->roaming_consortium_count++;
1235
1236 return 0;
1237}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001238
1239
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001240static int parse_lang_string(struct hostapd_lang_string **array,
1241 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001242{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001243 char *sep, *str = NULL;
1244 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001245 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001246 int ret = -1;
1247
1248 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1249 str = wpa_config_parse_string(pos, &slen);
1250 if (!str)
1251 return -1;
1252 pos = str;
1253 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001254
1255 sep = os_strchr(pos, ':');
1256 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001257 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001258 *sep++ = '\0';
1259
1260 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001261 if (clen < 2 || clen > sizeof(ls->lang))
1262 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001263 nlen = os_strlen(sep);
1264 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001265 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001266
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001267 ls = os_realloc_array(*array, *count + 1,
1268 sizeof(struct hostapd_lang_string));
1269 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001270 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001271
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001272 *array = ls;
1273 ls = &(*array)[*count];
1274 (*count)++;
1275
1276 os_memset(ls->lang, 0, sizeof(ls->lang));
1277 os_memcpy(ls->lang, pos, clen);
1278 ls->name_len = nlen;
1279 os_memcpy(ls->name, sep, nlen);
1280
Dmitry Shmidt56052862013-10-04 10:23:25 -07001281 ret = 0;
1282fail:
1283 os_free(str);
1284 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001285}
1286
1287
1288static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1289 int line)
1290{
1291 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1292 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1293 line, pos);
1294 return -1;
1295 }
1296 return 0;
1297}
1298
1299
Roshan Pius3a1667e2018-07-03 15:17:14 -07001300static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1301 int line)
1302{
1303 char *sep;
1304 size_t nlen;
1305 struct hostapd_venue_url *url;
1306 int ret = -1;
1307
1308 sep = os_strchr(pos, ':');
1309 if (!sep)
1310 goto fail;
1311 *sep++ = '\0';
1312
1313 nlen = os_strlen(sep);
1314 if (nlen > 254)
1315 goto fail;
1316
1317 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1318 sizeof(struct hostapd_venue_url));
1319 if (!url)
1320 goto fail;
1321
1322 bss->venue_url = url;
1323 url = &bss->venue_url[bss->venue_url_count++];
1324
1325 url->venue_number = atoi(pos);
1326 url->url_len = nlen;
1327 os_memcpy(url->url, sep, nlen);
1328
1329 ret = 0;
1330fail:
1331 if (ret)
1332 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1333 line, pos);
1334 return ret;
1335}
1336
1337
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001338static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1339 int line)
1340{
1341 size_t count;
1342 char *pos;
1343 u8 *info = NULL, *ipos;
1344
1345 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1346
1347 count = 1;
1348 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001349 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001350 goto fail;
1351 if (*pos == ';')
1352 count++;
1353 }
1354 if (1 + count * 3 > 0x7f)
1355 goto fail;
1356
1357 info = os_zalloc(2 + 3 + count * 3);
1358 if (info == NULL)
1359 return -1;
1360
1361 ipos = info;
1362 *ipos++ = 0; /* GUD - Version 1 */
1363 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1364 *ipos++ = 0; /* PLMN List IEI */
1365 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1366 *ipos++ = 1 + count * 3;
1367 *ipos++ = count; /* Number of PLMNs */
1368
1369 pos = buf;
1370 while (pos && *pos) {
1371 char *mcc, *mnc;
1372 size_t mnc_len;
1373
1374 mcc = pos;
1375 mnc = os_strchr(pos, ',');
1376 if (mnc == NULL)
1377 goto fail;
1378 *mnc++ = '\0';
1379 pos = os_strchr(mnc, ';');
1380 if (pos)
1381 *pos++ = '\0';
1382
1383 mnc_len = os_strlen(mnc);
1384 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1385 goto fail;
1386
1387 /* BC coded MCC,MNC */
1388 /* MCC digit 2 | MCC digit 1 */
1389 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1390 /* MNC digit 3 | MCC digit 3 */
1391 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1392 (mcc[2] - '0');
1393 /* MNC digit 2 | MNC digit 1 */
1394 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1395 }
1396
1397 os_free(bss->anqp_3gpp_cell_net);
1398 bss->anqp_3gpp_cell_net = info;
1399 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1400 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1401 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001402
1403 return 0;
1404
1405fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001406 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1407 line, buf);
1408 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001409 return -1;
1410}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001411
1412
1413static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1414{
1415 struct hostapd_nai_realm_data *realm;
1416 size_t i, j, len;
1417 int *offsets;
1418 char *pos, *end, *rpos;
1419
1420 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1421 sizeof(int));
1422 if (offsets == NULL)
1423 return -1;
1424
1425 for (i = 0; i < bss->nai_realm_count; i++) {
1426 realm = &bss->nai_realm_data[i];
1427 for (j = 0; j < MAX_NAI_REALMS; j++) {
1428 offsets[i * MAX_NAI_REALMS + j] =
1429 realm->realm[j] ?
1430 realm->realm[j] - realm->realm_buf : -1;
1431 }
1432 }
1433
1434 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1435 sizeof(struct hostapd_nai_realm_data));
1436 if (realm == NULL) {
1437 os_free(offsets);
1438 return -1;
1439 }
1440 bss->nai_realm_data = realm;
1441
1442 /* patch the pointers after realloc */
1443 for (i = 0; i < bss->nai_realm_count; i++) {
1444 realm = &bss->nai_realm_data[i];
1445 for (j = 0; j < MAX_NAI_REALMS; j++) {
1446 int offs = offsets[i * MAX_NAI_REALMS + j];
1447 if (offs >= 0)
1448 realm->realm[j] = realm->realm_buf + offs;
1449 else
1450 realm->realm[j] = NULL;
1451 }
1452 }
1453 os_free(offsets);
1454
1455 realm = &bss->nai_realm_data[bss->nai_realm_count];
1456 os_memset(realm, 0, sizeof(*realm));
1457
1458 pos = buf;
1459 realm->encoding = atoi(pos);
1460 pos = os_strchr(pos, ',');
1461 if (pos == NULL)
1462 goto fail;
1463 pos++;
1464
1465 end = os_strchr(pos, ',');
1466 if (end) {
1467 len = end - pos;
1468 *end = '\0';
1469 } else {
1470 len = os_strlen(pos);
1471 }
1472
1473 if (len > MAX_NAI_REALMLEN) {
1474 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1475 "characters)", (int) len, MAX_NAI_REALMLEN);
1476 goto fail;
1477 }
1478 os_memcpy(realm->realm_buf, pos, len);
1479
1480 if (end)
1481 pos = end + 1;
1482 else
1483 pos = NULL;
1484
1485 while (pos && *pos) {
1486 struct hostapd_nai_realm_eap *eap;
1487
1488 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1489 wpa_printf(MSG_ERROR, "Too many EAP methods");
1490 goto fail;
1491 }
1492
1493 eap = &realm->eap_method[realm->eap_method_count];
1494 realm->eap_method_count++;
1495
1496 end = os_strchr(pos, ',');
1497 if (end == NULL)
1498 end = pos + os_strlen(pos);
1499
1500 eap->eap_method = atoi(pos);
1501 for (;;) {
1502 pos = os_strchr(pos, '[');
1503 if (pos == NULL || pos > end)
1504 break;
1505 pos++;
1506 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1507 wpa_printf(MSG_ERROR, "Too many auth params");
1508 goto fail;
1509 }
1510 eap->auth_id[eap->num_auths] = atoi(pos);
1511 pos = os_strchr(pos, ':');
1512 if (pos == NULL || pos > end)
1513 goto fail;
1514 pos++;
1515 eap->auth_val[eap->num_auths] = atoi(pos);
1516 pos = os_strchr(pos, ']');
1517 if (pos == NULL || pos > end)
1518 goto fail;
1519 pos++;
1520 eap->num_auths++;
1521 }
1522
1523 if (*end != ',')
1524 break;
1525
1526 pos = end + 1;
1527 }
1528
1529 /* Split realm list into null terminated realms */
1530 rpos = realm->realm_buf;
1531 i = 0;
1532 while (*rpos) {
1533 if (i >= MAX_NAI_REALMS) {
1534 wpa_printf(MSG_ERROR, "Too many realms");
1535 goto fail;
1536 }
1537 realm->realm[i++] = rpos;
1538 rpos = os_strchr(rpos, ';');
1539 if (rpos == NULL)
1540 break;
1541 *rpos++ = '\0';
1542 }
1543
1544 bss->nai_realm_count++;
1545
1546 return 0;
1547
1548fail:
1549 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1550 return -1;
1551}
1552
Dmitry Shmidt051af732013-10-22 13:52:46 -07001553
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001554static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1555{
1556 char *delim;
1557 u16 infoid;
1558 size_t len;
1559 struct wpabuf *payload;
1560 struct anqp_element *elem;
1561
1562 delim = os_strchr(buf, ':');
1563 if (!delim)
1564 return -1;
1565 delim++;
1566 infoid = atoi(buf);
1567 len = os_strlen(delim);
1568 if (len & 1)
1569 return -1;
1570 len /= 2;
1571 payload = wpabuf_alloc(len);
1572 if (!payload)
1573 return -1;
1574 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1575 wpabuf_free(payload);
1576 return -1;
1577 }
1578
1579 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1580 if (elem->infoid == infoid) {
1581 /* Update existing entry */
1582 wpabuf_free(elem->payload);
1583 elem->payload = payload;
1584 return 0;
1585 }
1586 }
1587
1588 /* Add a new entry */
1589 elem = os_zalloc(sizeof(*elem));
1590 if (!elem) {
1591 wpabuf_free(payload);
1592 return -1;
1593 }
1594 elem->infoid = infoid;
1595 elem->payload = payload;
1596 dl_list_add(&bss->anqp_elem, &elem->list);
1597
1598 return 0;
1599}
1600
1601
Dmitry Shmidt051af732013-10-22 13:52:46 -07001602static int parse_qos_map_set(struct hostapd_bss_config *bss,
1603 char *buf, int line)
1604{
1605 u8 qos_map_set[16 + 2 * 21], count = 0;
1606 char *pos = buf;
1607 int val;
1608
1609 for (;;) {
1610 if (count == sizeof(qos_map_set)) {
1611 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1612 "parameters '%s'", line, buf);
1613 return -1;
1614 }
1615
1616 val = atoi(pos);
1617 if (val > 255 || val < 0) {
1618 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1619 "'%s'", line, buf);
1620 return -1;
1621 }
1622
1623 qos_map_set[count++] = val;
1624 pos = os_strchr(pos, ',');
1625 if (!pos)
1626 break;
1627 pos++;
1628 }
1629
1630 if (count < 16 || count & 1) {
1631 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1632 line, buf);
1633 return -1;
1634 }
1635
1636 os_memcpy(bss->qos_map_set, qos_map_set, count);
1637 bss->qos_map_set_len = count;
1638
1639 return 0;
1640}
1641
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001642#endif /* CONFIG_INTERWORKING */
1643
1644
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001645#ifdef CONFIG_HS20
1646static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1647 int line)
1648{
1649 u8 *conn_cap;
1650 char *pos;
1651
1652 if (bss->hs20_connection_capability_len >= 0xfff0)
1653 return -1;
1654
1655 conn_cap = os_realloc(bss->hs20_connection_capability,
1656 bss->hs20_connection_capability_len + 4);
1657 if (conn_cap == NULL)
1658 return -1;
1659
1660 bss->hs20_connection_capability = conn_cap;
1661 conn_cap += bss->hs20_connection_capability_len;
1662 pos = buf;
1663 conn_cap[0] = atoi(pos);
1664 pos = os_strchr(pos, ':');
1665 if (pos == NULL)
1666 return -1;
1667 pos++;
1668 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1669 pos = os_strchr(pos, ':');
1670 if (pos == NULL)
1671 return -1;
1672 pos++;
1673 conn_cap[3] = atoi(pos);
1674 bss->hs20_connection_capability_len += 4;
1675
1676 return 0;
1677}
1678
1679
1680static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1681 int line)
1682{
1683 u8 *wan_metrics;
1684 char *pos;
1685
1686 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1687
1688 wan_metrics = os_zalloc(13);
1689 if (wan_metrics == NULL)
1690 return -1;
1691
1692 pos = buf;
1693 /* WAN Info */
1694 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1695 goto fail;
1696 pos += 2;
1697 if (*pos != ':')
1698 goto fail;
1699 pos++;
1700
1701 /* Downlink Speed */
1702 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1703 pos = os_strchr(pos, ':');
1704 if (pos == NULL)
1705 goto fail;
1706 pos++;
1707
1708 /* Uplink Speed */
1709 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1710 pos = os_strchr(pos, ':');
1711 if (pos == NULL)
1712 goto fail;
1713 pos++;
1714
1715 /* Downlink Load */
1716 wan_metrics[9] = atoi(pos);
1717 pos = os_strchr(pos, ':');
1718 if (pos == NULL)
1719 goto fail;
1720 pos++;
1721
1722 /* Uplink Load */
1723 wan_metrics[10] = atoi(pos);
1724 pos = os_strchr(pos, ':');
1725 if (pos == NULL)
1726 goto fail;
1727 pos++;
1728
1729 /* LMD */
1730 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1731
1732 os_free(bss->hs20_wan_metrics);
1733 bss->hs20_wan_metrics = wan_metrics;
1734
1735 return 0;
1736
1737fail:
1738 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001739 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001740 os_free(wan_metrics);
1741 return -1;
1742}
1743
1744
1745static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1746 char *pos, int line)
1747{
1748 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1749 &bss->hs20_oper_friendly_name_count, pos)) {
1750 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1751 "hs20_oper_friendly_name '%s'", line, pos);
1752 return -1;
1753 }
1754 return 0;
1755}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001756
1757
1758static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1759{
1760 struct hs20_icon *icon;
1761 char *end;
1762
1763 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1764 sizeof(struct hs20_icon));
1765 if (icon == NULL)
1766 return -1;
1767 bss->hs20_icons = icon;
1768 icon = &bss->hs20_icons[bss->hs20_icons_count];
1769 os_memset(icon, 0, sizeof(*icon));
1770
1771 icon->width = atoi(pos);
1772 pos = os_strchr(pos, ':');
1773 if (pos == NULL)
1774 return -1;
1775 pos++;
1776
1777 icon->height = atoi(pos);
1778 pos = os_strchr(pos, ':');
1779 if (pos == NULL)
1780 return -1;
1781 pos++;
1782
1783 end = os_strchr(pos, ':');
1784 if (end == NULL || end - pos > 3)
1785 return -1;
1786 os_memcpy(icon->language, pos, end - pos);
1787 pos = end + 1;
1788
1789 end = os_strchr(pos, ':');
1790 if (end == NULL || end - pos > 255)
1791 return -1;
1792 os_memcpy(icon->type, pos, end - pos);
1793 pos = end + 1;
1794
1795 end = os_strchr(pos, ':');
1796 if (end == NULL || end - pos > 255)
1797 return -1;
1798 os_memcpy(icon->name, pos, end - pos);
1799 pos = end + 1;
1800
1801 if (os_strlen(pos) > 255)
1802 return -1;
1803 os_memcpy(icon->file, pos, os_strlen(pos));
1804
1805 bss->hs20_icons_count++;
1806
1807 return 0;
1808}
1809
1810
1811static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1812 char *pos, int line)
1813{
1814 size_t slen;
1815 char *str;
1816
1817 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001818 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001819 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001820 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001821 return -1;
1822 }
1823
1824 os_memcpy(bss->osu_ssid, str, slen);
1825 bss->osu_ssid_len = slen;
1826 os_free(str);
1827
1828 return 0;
1829}
1830
1831
1832static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1833 char *pos, int line)
1834{
1835 struct hs20_osu_provider *p;
1836
1837 p = os_realloc_array(bss->hs20_osu_providers,
1838 bss->hs20_osu_providers_count + 1, sizeof(*p));
1839 if (p == NULL)
1840 return -1;
1841
1842 bss->hs20_osu_providers = p;
1843 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1844 bss->hs20_osu_providers_count++;
1845 os_memset(bss->last_osu, 0, sizeof(*p));
1846 bss->last_osu->server_uri = os_strdup(pos);
1847
1848 return 0;
1849}
1850
1851
1852static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1853 char *pos, int line)
1854{
1855 if (bss->last_osu == NULL) {
1856 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1857 return -1;
1858 }
1859
1860 if (parse_lang_string(&bss->last_osu->friendly_name,
1861 &bss->last_osu->friendly_name_count, pos)) {
1862 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1863 line, pos);
1864 return -1;
1865 }
1866
1867 return 0;
1868}
1869
1870
1871static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1872 char *pos, int line)
1873{
1874 if (bss->last_osu == NULL) {
1875 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1876 return -1;
1877 }
1878
1879 os_free(bss->last_osu->osu_nai);
1880 bss->last_osu->osu_nai = os_strdup(pos);
1881 if (bss->last_osu->osu_nai == NULL)
1882 return -1;
1883
1884 return 0;
1885}
1886
1887
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001888static int hs20_parse_osu_nai2(struct hostapd_bss_config *bss,
1889 char *pos, int line)
1890{
1891 if (bss->last_osu == NULL) {
1892 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1893 return -1;
1894 }
1895
1896 os_free(bss->last_osu->osu_nai2);
1897 bss->last_osu->osu_nai2 = os_strdup(pos);
1898 if (bss->last_osu->osu_nai2 == NULL)
1899 return -1;
1900 bss->hs20_osu_providers_nai_count++;
1901
1902 return 0;
1903}
1904
1905
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001906static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1907 int line)
1908{
1909 if (bss->last_osu == NULL) {
1910 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1911 return -1;
1912 }
1913
1914 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1915 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1916 return -1;
1917 }
1918
1919 return 0;
1920}
1921
1922
1923static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1924 int line)
1925{
1926 char **n;
1927 struct hs20_osu_provider *p = bss->last_osu;
1928
1929 if (p == NULL) {
1930 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1931 return -1;
1932 }
1933
1934 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1935 if (n == NULL)
1936 return -1;
1937 p->icons = n;
1938 p->icons[p->icons_count] = os_strdup(pos);
1939 if (p->icons[p->icons_count] == NULL)
1940 return -1;
1941 p->icons_count++;
1942
1943 return 0;
1944}
1945
1946
1947static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1948 char *pos, int line)
1949{
1950 if (bss->last_osu == NULL) {
1951 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1952 return -1;
1953 }
1954
1955 if (parse_lang_string(&bss->last_osu->service_desc,
1956 &bss->last_osu->service_desc_count, pos)) {
1957 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1958 line, pos);
1959 return -1;
1960 }
1961
1962 return 0;
1963}
1964
Roshan Pius3a1667e2018-07-03 15:17:14 -07001965
1966static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
1967 int line)
1968{
1969 char **n;
1970
1971 n = os_realloc_array(bss->hs20_operator_icon,
1972 bss->hs20_operator_icon_count + 1, sizeof(char *));
1973 if (!n)
1974 return -1;
1975 bss->hs20_operator_icon = n;
1976 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
1977 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
1978 return -1;
1979 bss->hs20_operator_icon_count++;
1980
1981 return 0;
1982}
1983
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001984#endif /* CONFIG_HS20 */
1985
1986
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001987#ifdef CONFIG_ACS
1988static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
1989 char *pos)
1990{
1991 struct acs_bias *bias = NULL, *tmp;
1992 unsigned int num = 0;
1993 char *end;
1994
1995 while (*pos) {
1996 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
1997 if (!tmp)
1998 goto fail;
1999 bias = tmp;
2000
2001 bias[num].channel = atoi(pos);
2002 if (bias[num].channel <= 0)
2003 goto fail;
2004 pos = os_strchr(pos, ':');
2005 if (!pos)
2006 goto fail;
2007 pos++;
2008 bias[num].bias = strtod(pos, &end);
2009 if (end == pos || bias[num].bias < 0.0)
2010 goto fail;
2011 pos = end;
2012 if (*pos != ' ' && *pos != '\0')
2013 goto fail;
2014 num++;
2015 }
2016
2017 os_free(conf->acs_chan_bias);
2018 conf->acs_chan_bias = bias;
2019 conf->num_acs_chan_bias = num;
2020
2021 return 0;
2022fail:
2023 os_free(bias);
2024 return -1;
2025}
2026#endif /* CONFIG_ACS */
2027
2028
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002029static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2030 const char *val)
2031{
2032 struct wpabuf *elems;
2033
2034 if (val[0] == '\0') {
2035 wpabuf_free(*buf);
2036 *buf = NULL;
2037 return 0;
2038 }
2039
2040 elems = wpabuf_parse_bin(val);
2041 if (!elems) {
2042 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2043 line, name, val);
2044 return -1;
2045 }
2046
2047 wpabuf_free(*buf);
2048 *buf = elems;
2049
2050 return 0;
2051}
2052
2053
Dmitry Shmidt29333592017-01-09 12:27:11 -08002054#ifdef CONFIG_FILS
2055static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2056{
2057 struct fils_realm *realm;
2058 size_t len;
2059
2060 len = os_strlen(val);
2061 realm = os_zalloc(sizeof(*realm) + len + 1);
2062 if (!realm)
2063 return -1;
2064
2065 os_memcpy(realm->realm, val, len);
2066 if (fils_domain_name_hash(val, realm->hash) < 0) {
2067 os_free(realm);
2068 return -1;
2069 }
2070 dl_list_add_tail(&bss->fils_realms, &realm->list);
2071
2072 return 0;
2073}
2074#endif /* CONFIG_FILS */
2075
2076
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002077#ifdef EAP_SERVER
2078static unsigned int parse_tls_flags(const char *val)
2079{
2080 unsigned int flags = 0;
2081
Roshan Pius3a1667e2018-07-03 15:17:14 -07002082 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2083 * This can be enabled by default once the implementation has been fully
2084 * completed and tested with other implementations. */
2085 flags |= TLS_CONN_DISABLE_TLSv1_3;
2086
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002087 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2088 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2089 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2090 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2091 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2092 flags |= TLS_CONN_DISABLE_TLSv1_0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002093 if (os_strstr(val, "[ENABLE-TLSv1.0]"))
2094 flags |= TLS_CONN_ENABLE_TLSv1_0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002095 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2096 flags |= TLS_CONN_DISABLE_TLSv1_1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002097 if (os_strstr(val, "[ENABLE-TLSv1.1]"))
2098 flags |= TLS_CONN_ENABLE_TLSv1_1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002099 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2100 flags |= TLS_CONN_DISABLE_TLSv1_2;
Hai Shalom74f70d42019-02-11 14:42:39 -08002101 if (os_strstr(val, "[ENABLE-TLSv1.2]"))
2102 flags |= TLS_CONN_ENABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002103 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2104 flags |= TLS_CONN_DISABLE_TLSv1_3;
2105 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2106 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002107 if (os_strstr(val, "[SUITEB]"))
2108 flags |= TLS_CONN_SUITEB;
2109 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2110 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2111
2112 return flags;
2113}
2114#endif /* EAP_SERVER */
2115
2116
Hai Shalom81f62d82019-07-22 12:10:00 -07002117#ifdef CONFIG_AIRTIME_POLICY
2118static int add_airtime_weight(struct hostapd_bss_config *bss, char *value)
2119{
2120 struct airtime_sta_weight *wt;
2121 char *pos, *next;
2122
2123 wt = os_zalloc(sizeof(*wt));
2124 if (!wt)
2125 return -1;
2126
2127 /* 02:01:02:03:04:05 10 */
2128 pos = value;
2129 next = os_strchr(pos, ' ');
2130 if (next)
2131 *next++ = '\0';
2132 if (!next || hwaddr_aton(pos, wt->addr)) {
2133 wpa_printf(MSG_ERROR, "Invalid station address: '%s'", pos);
2134 os_free(wt);
2135 return -1;
2136 }
2137
2138 pos = next;
2139 wt->weight = atoi(pos);
2140 if (!wt->weight) {
2141 wpa_printf(MSG_ERROR, "Invalid weight: '%s'", pos);
2142 os_free(wt);
2143 return -1;
2144 }
2145
2146 wt->next = bss->airtime_weight_list;
2147 bss->airtime_weight_list = wt;
2148 return 0;
2149}
2150#endif /* CONFIG_AIRTIME_POLICY */
2151
2152
Roshan Pius3a1667e2018-07-03 15:17:14 -07002153#ifdef CONFIG_SAE
2154static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2155{
2156 struct sae_password_entry *pw;
2157 const char *pos = val, *pos2, *end = NULL;
2158
2159 pw = os_zalloc(sizeof(*pw));
2160 if (!pw)
2161 return -1;
2162 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2163
2164 pos2 = os_strstr(pos, "|mac=");
2165 if (pos2) {
2166 end = pos2;
2167 pos2 += 5;
2168 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2169 goto fail;
2170 pos = pos2 + ETH_ALEN * 3 - 1;
2171 }
2172
Hai Shalom021b0b52019-04-10 11:17:58 -07002173 pos2 = os_strstr(pos, "|vlanid=");
2174 if (pos2) {
2175 if (!end)
2176 end = pos2;
2177 pos2 += 8;
2178 pw->vlan_id = atoi(pos2);
2179 }
2180
Hai Shalom899fcc72020-10-19 14:38:18 -07002181#ifdef CONFIG_SAE_PK
2182 pos2 = os_strstr(pos, "|pk=");
2183 if (pos2) {
2184 const char *epos;
2185 char *tmp;
2186
2187 if (!end)
2188 end = pos2;
2189 pos2 += 4;
2190 epos = os_strchr(pos2, '|');
2191 if (epos) {
2192 tmp = os_malloc(epos - pos2 + 1);
2193 if (!tmp)
2194 goto fail;
2195 os_memcpy(tmp, pos2, epos - pos2);
2196 tmp[epos - pos2] = '\0';
2197 } else {
2198 tmp = os_strdup(pos2);
2199 if (!tmp)
2200 goto fail;
2201 }
2202
2203 pw->pk = sae_parse_pk(tmp);
2204 str_clear_free(tmp);
2205 if (!pw->pk)
2206 goto fail;
2207 }
2208#endif /* CONFIG_SAE_PK */
2209
Roshan Pius3a1667e2018-07-03 15:17:14 -07002210 pos2 = os_strstr(pos, "|id=");
2211 if (pos2) {
2212 if (!end)
2213 end = pos2;
2214 pos2 += 4;
2215 pw->identifier = os_strdup(pos2);
2216 if (!pw->identifier)
2217 goto fail;
2218 }
2219
2220 if (!end) {
2221 pw->password = os_strdup(val);
2222 if (!pw->password)
2223 goto fail;
2224 } else {
2225 pw->password = os_malloc(end - val + 1);
2226 if (!pw->password)
2227 goto fail;
2228 os_memcpy(pw->password, val, end - val);
2229 pw->password[end - val] = '\0';
2230 }
2231
Hai Shalom899fcc72020-10-19 14:38:18 -07002232#ifdef CONFIG_SAE_PK
2233 if (pw->pk &&
2234#ifdef CONFIG_TESTING_OPTIONS
2235 !bss->sae_pk_password_check_skip &&
2236#endif /* CONFIG_TESTING_OPTIONS */
2237 !sae_pk_valid_password(pw->password)) {
2238 wpa_printf(MSG_INFO,
2239 "Invalid SAE password for a SAE-PK sae_password entry");
2240 goto fail;
2241 }
2242#endif /* CONFIG_SAE_PK */
2243
Roshan Pius3a1667e2018-07-03 15:17:14 -07002244 pw->next = bss->sae_passwords;
2245 bss->sae_passwords = pw;
2246
2247 return 0;
2248fail:
2249 str_clear_free(pw->password);
2250 os_free(pw->identifier);
Hai Shalom899fcc72020-10-19 14:38:18 -07002251#ifdef CONFIG_SAE_PK
2252 sae_deinit_pk(pw->pk);
2253#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002254 os_free(pw);
2255 return -1;
2256}
2257#endif /* CONFIG_SAE */
2258
2259
Hai Shalom81f62d82019-07-22 12:10:00 -07002260#ifdef CONFIG_DPP2
2261static int hostapd_dpp_controller_parse(struct hostapd_bss_config *bss,
2262 const char *pos)
2263{
2264 struct dpp_controller_conf *conf;
2265 char *val;
2266
2267 conf = os_zalloc(sizeof(*conf));
2268 if (!conf)
2269 return -1;
2270 val = get_param(pos, "ipaddr=");
2271 if (!val || hostapd_parse_ip_addr(val, &conf->ipaddr))
2272 goto fail;
2273 os_free(val);
2274 val = get_param(pos, "pkhash=");
2275 if (!val || os_strlen(val) != 2 * SHA256_MAC_LEN ||
2276 hexstr2bin(val, conf->pkhash, SHA256_MAC_LEN) < 0)
2277 goto fail;
2278 os_free(val);
2279 conf->next = bss->dpp_controller;
2280 bss->dpp_controller = conf;
2281 return 0;
2282fail:
2283 os_free(val);
2284 os_free(conf);
2285 return -1;
2286}
2287#endif /* CONFIG_DPP2 */
2288
2289
Hai Shaloma20dcd72022-02-04 13:43:00 -08002290static int get_hex_config(u8 *buf, size_t max_len, int line,
2291 const char *field, const char *val)
2292{
2293 size_t hlen = os_strlen(val), len = hlen / 2;
2294 u8 tmp[EXT_CAPA_MAX_LEN];
2295
2296 os_memset(tmp, 0, EXT_CAPA_MAX_LEN);
2297 if (hlen & 1 || len > EXT_CAPA_MAX_LEN || hexstr2bin(val, tmp, len)) {
2298 wpa_printf(MSG_ERROR, "Line %d: Invalid %s", line, field);
2299 return -1;
2300 }
2301 os_memcpy(buf, tmp, EXT_CAPA_MAX_LEN);
2302 return 0;
2303}
2304
2305
Dmitry Shmidt04949592012-07-19 12:16:46 -07002306static int hostapd_config_fill(struct hostapd_config *conf,
2307 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002308 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002309{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002310 if (os_strcmp(buf, "interface") == 0) {
2311 os_strlcpy(conf->bss[0]->iface, pos,
2312 sizeof(conf->bss[0]->iface));
2313 } else if (os_strcmp(buf, "bridge") == 0) {
2314 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2315 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2316 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2317 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2318 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2319 } else if (os_strcmp(buf, "driver") == 0) {
2320 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002321 const struct wpa_driver_ops *driver = NULL;
2322
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002323 for (j = 0; wpa_drivers[j]; j++) {
2324 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002325 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002326 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002328 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002329 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002330 wpa_printf(MSG_ERROR,
2331 "Line %d: invalid/unknown driver '%s'",
2332 line, pos);
2333 return 1;
2334 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002335 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002336 } else if (os_strcmp(buf, "driver_params") == 0) {
2337 os_free(conf->driver_params);
2338 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002339 } else if (os_strcmp(buf, "debug") == 0) {
2340 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2341 line);
2342 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2343 bss->logger_syslog_level = atoi(pos);
2344 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2345 bss->logger_stdout_level = atoi(pos);
2346 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2347 bss->logger_syslog = atoi(pos);
2348 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2349 bss->logger_stdout = atoi(pos);
2350 } else if (os_strcmp(buf, "dump_file") == 0) {
2351 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2352 line);
2353 } else if (os_strcmp(buf, "ssid") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002354 struct hostapd_ssid *ssid = &bss->ssid;
2355
2356 ssid->ssid_len = os_strlen(pos);
2357 if (ssid->ssid_len > SSID_MAX_LEN || ssid->ssid_len < 1) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002358 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2359 line, pos);
2360 return 1;
2361 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002362 os_memcpy(ssid->ssid, pos, ssid->ssid_len);
2363 ssid->ssid_set = 1;
2364 ssid->short_ssid = crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002365 } else if (os_strcmp(buf, "ssid2") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08002366 struct hostapd_ssid *ssid = &bss->ssid;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002367 size_t slen;
2368 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002369 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002370 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2371 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002372 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002373 return 1;
2374 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08002375 os_memcpy(ssid->ssid, str, slen);
2376 ssid->ssid_len = slen;
2377 ssid->ssid_set = 1;
2378 ssid->short_ssid = crc32(ssid->ssid, ssid->ssid_len);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002379 os_free(str);
2380 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
2381 bss->ssid.utf8_ssid = atoi(pos) > 0;
2382 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002383 enum macaddr_acl acl = atoi(pos);
2384
2385 if (acl != ACCEPT_UNLESS_DENIED &&
2386 acl != DENY_UNLESS_ACCEPTED &&
2387 acl != USE_EXTERNAL_RADIUS_AUTH) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002388 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002389 line, acl);
2390 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002391 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002392 bss->macaddr_acl = acl;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002393 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
2394 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2395 &bss->num_accept_mac)) {
2396 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2397 line, pos);
2398 return 1;
2399 }
2400 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2401 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2402 &bss->num_deny_mac)) {
2403 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2404 line, pos);
2405 return 1;
2406 }
2407 } else if (os_strcmp(buf, "wds_sta") == 0) {
2408 bss->wds_sta = atoi(pos);
2409 } else if (os_strcmp(buf, "start_disabled") == 0) {
2410 bss->start_disabled = atoi(pos);
2411 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2412 bss->isolate = atoi(pos);
2413 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2414 bss->ap_max_inactivity = atoi(pos);
2415 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2416 bss->skip_inactivity_poll = atoi(pos);
2417 } else if (os_strcmp(buf, "country_code") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002418 if (pos[0] < 'A' || pos[0] > 'Z' ||
2419 pos[1] < 'A' || pos[1] > 'Z') {
2420 wpa_printf(MSG_ERROR,
2421 "Line %d: Invalid country_code '%s'",
2422 line, pos);
2423 return 1;
2424 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002425 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002426 } else if (os_strcmp(buf, "country3") == 0) {
2427 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002428 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2429 conf->ieee80211d = atoi(pos);
2430 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2431 conf->ieee80211h = atoi(pos);
2432 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2433 bss->ieee802_1x = atoi(pos);
2434 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002435 int eapol_version = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002436#ifdef CONFIG_MACSEC
Hai Shaloma20dcd72022-02-04 13:43:00 -08002437 int max_ver = 3;
Hai Shalom81f62d82019-07-22 12:10:00 -07002438#else /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002439 int max_ver = 2;
Hai Shalom81f62d82019-07-22 12:10:00 -07002440#endif /* CONFIG_MACSEC */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002441
2442 if (eapol_version < 1 || eapol_version > max_ver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002443 wpa_printf(MSG_ERROR,
2444 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002445 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002446 return 1;
2447 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002448 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002449 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002450#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002451 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2452 bss->eap_server = atoi(pos);
2453 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2454 } else if (os_strcmp(buf, "eap_server") == 0) {
2455 bss->eap_server = atoi(pos);
2456 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2457 if (hostapd_config_read_eap_user(pos, bss))
2458 return 1;
2459 } else if (os_strcmp(buf, "ca_cert") == 0) {
2460 os_free(bss->ca_cert);
2461 bss->ca_cert = os_strdup(pos);
2462 } else if (os_strcmp(buf, "server_cert") == 0) {
2463 os_free(bss->server_cert);
2464 bss->server_cert = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002465 } else if (os_strcmp(buf, "server_cert2") == 0) {
2466 os_free(bss->server_cert2);
2467 bss->server_cert2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002468 } else if (os_strcmp(buf, "private_key") == 0) {
2469 os_free(bss->private_key);
2470 bss->private_key = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002471 } else if (os_strcmp(buf, "private_key2") == 0) {
2472 os_free(bss->private_key2);
2473 bss->private_key2 = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002474 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2475 os_free(bss->private_key_passwd);
2476 bss->private_key_passwd = os_strdup(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002477 } else if (os_strcmp(buf, "private_key_passwd2") == 0) {
2478 os_free(bss->private_key_passwd2);
2479 bss->private_key_passwd2 = os_strdup(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07002480 } else if (os_strcmp(buf, "check_cert_subject") == 0) {
2481 if (!pos[0]) {
2482 wpa_printf(MSG_ERROR, "Line %d: unknown check_cert_subject '%s'",
2483 line, pos);
2484 return 1;
2485 }
2486 os_free(bss->check_cert_subject);
2487 bss->check_cert_subject = os_strdup(pos);
2488 if (!bss->check_cert_subject)
2489 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002490 } else if (os_strcmp(buf, "check_crl") == 0) {
2491 bss->check_crl = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002492 } else if (os_strcmp(buf, "check_crl_strict") == 0) {
2493 bss->check_crl_strict = atoi(pos);
2494 } else if (os_strcmp(buf, "crl_reload_interval") == 0) {
2495 bss->crl_reload_interval = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002496 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2497 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002498 } else if (os_strcmp(buf, "tls_flags") == 0) {
2499 bss->tls_flags = parse_tls_flags(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002500 } else if (os_strcmp(buf, "max_auth_rounds") == 0) {
2501 bss->max_auth_rounds = atoi(pos);
2502 } else if (os_strcmp(buf, "max_auth_rounds_short") == 0) {
2503 bss->max_auth_rounds_short = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002504 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2505 os_free(bss->ocsp_stapling_response);
2506 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002507 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2508 os_free(bss->ocsp_stapling_response_multi);
2509 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002510 } else if (os_strcmp(buf, "dh_file") == 0) {
2511 os_free(bss->dh_file);
2512 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002513 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2514 os_free(bss->openssl_ciphers);
2515 bss->openssl_ciphers = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08002516 } else if (os_strcmp(buf, "openssl_ecdh_curves") == 0) {
2517 os_free(bss->openssl_ecdh_curves);
2518 bss->openssl_ecdh_curves = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002519 } else if (os_strcmp(buf, "fragment_size") == 0) {
2520 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002522 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2523 os_free(bss->pac_opaque_encr_key);
2524 bss->pac_opaque_encr_key = os_malloc(16);
2525 if (bss->pac_opaque_encr_key == NULL) {
2526 wpa_printf(MSG_ERROR,
2527 "Line %d: No memory for pac_opaque_encr_key",
2528 line);
2529 return 1;
2530 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2531 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2532 line);
2533 return 1;
2534 }
2535 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2536 size_t idlen = os_strlen(pos);
2537 if (idlen & 1) {
2538 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2539 line);
2540 return 1;
2541 }
2542 os_free(bss->eap_fast_a_id);
2543 bss->eap_fast_a_id = os_malloc(idlen / 2);
2544 if (bss->eap_fast_a_id == NULL ||
2545 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2546 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2547 line);
2548 os_free(bss->eap_fast_a_id);
2549 bss->eap_fast_a_id = NULL;
2550 return 1;
2551 } else {
2552 bss->eap_fast_a_id_len = idlen / 2;
2553 }
2554 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2555 os_free(bss->eap_fast_a_id_info);
2556 bss->eap_fast_a_id_info = os_strdup(pos);
2557 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2558 bss->eap_fast_prov = atoi(pos);
2559 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2560 bss->pac_key_lifetime = atoi(pos);
2561 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2562 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002563#endif /* EAP_SERVER_FAST */
Hai Shalom81f62d82019-07-22 12:10:00 -07002564#ifdef EAP_SERVER_TEAP
2565 } else if (os_strcmp(buf, "eap_teap_auth") == 0) {
2566 int val = atoi(pos);
2567
Hai Shalom899fcc72020-10-19 14:38:18 -07002568 if (val < 0 || val > 2) {
Hai Shalom81f62d82019-07-22 12:10:00 -07002569 wpa_printf(MSG_ERROR,
2570 "Line %d: Invalid eap_teap_auth value",
2571 line);
2572 return 1;
2573 }
2574 bss->eap_teap_auth = val;
2575 } else if (os_strcmp(buf, "eap_teap_pac_no_inner") == 0) {
2576 bss->eap_teap_pac_no_inner = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002577 } else if (os_strcmp(buf, "eap_teap_separate_result") == 0) {
2578 bss->eap_teap_separate_result = atoi(pos);
2579 } else if (os_strcmp(buf, "eap_teap_id") == 0) {
2580 bss->eap_teap_id = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07002581#endif /* EAP_SERVER_TEAP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002582#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002583 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2584 os_free(bss->eap_sim_db);
2585 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002586 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2587 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002588 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2589 bss->eap_sim_aka_result_ind = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07002590 } else if (os_strcmp(buf, "eap_sim_id") == 0) {
2591 bss->eap_sim_id = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07002592 } else if (os_strcmp(buf, "imsi_privacy_key") == 0) {
2593 os_free(bss->imsi_privacy_key);
2594 bss->imsi_privacy_key = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002595#endif /* EAP_SERVER_SIM */
2596#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002597 } else if (os_strcmp(buf, "tnc") == 0) {
2598 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002599#endif /* EAP_SERVER_TNC */
2600#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002601 } else if (os_strcmp(buf, "pwd_group") == 0) {
2602 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002604#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002605 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2606 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002607#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002609 } else if (os_strcmp(buf, "eap_message") == 0) {
2610 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002611 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002612 bss->eap_req_id_text = os_strdup(pos);
2613 if (bss->eap_req_id_text == NULL) {
2614 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2615 line);
2616 return 1;
2617 }
2618 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2619 term = os_strstr(bss->eap_req_id_text, "\\0");
2620 if (term) {
2621 *term++ = '\0';
2622 os_memmove(term, term + 1,
2623 bss->eap_req_id_text_len -
2624 (term - bss->eap_req_id_text) - 1);
2625 bss->eap_req_id_text_len--;
2626 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002627 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2628 bss->erp_send_reauth_start = atoi(pos);
2629 } else if (os_strcmp(buf, "erp_domain") == 0) {
2630 os_free(bss->erp_domain);
2631 bss->erp_domain = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002632#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002633 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002634 int val = atoi(pos);
2635
2636 if (val < 0 || val > 13) {
2637 wpa_printf(MSG_ERROR,
2638 "Line %d: invalid WEP key len %d (= %d bits)",
2639 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002640 return 1;
2641 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002642 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002643 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002644 int val = atoi(pos);
2645
2646 if (val < 0 || val > 13) {
2647 wpa_printf(MSG_ERROR,
2648 "Line %d: invalid WEP key len %d (= %d bits)",
2649 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002650 return 1;
2651 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002652 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002653 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2654 bss->wep_rekeying_period = atoi(pos);
2655 if (bss->wep_rekeying_period < 0) {
2656 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2657 line, bss->wep_rekeying_period);
2658 return 1;
2659 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002660#endif /* CONFIG_WEP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002661 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2662 bss->eap_reauth_period = atoi(pos);
2663 if (bss->eap_reauth_period < 0) {
2664 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2665 line, bss->eap_reauth_period);
2666 return 1;
2667 }
2668 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2669 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002671 } else if (os_strcmp(buf, "iapp_interface") == 0) {
Hai Shalomc3565922019-10-28 11:58:20 -07002672 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002674 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2675 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2676 wpa_printf(MSG_ERROR,
2677 "Line %d: invalid IP address '%s'",
2678 line, pos);
2679 return 1;
2680 }
2681 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002682 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002683 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002684#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002685 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2686 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2687 wpa_printf(MSG_ERROR,
2688 "Line %d: invalid IP address '%s'",
2689 line, pos);
2690 return 1;
2691 }
2692 bss->radius->force_client_addr = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002693 } else if (os_strcmp(buf, "radius_client_dev") == 0) {
2694 os_free(bss->radius->force_client_dev);
2695 bss->radius->force_client_dev = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002696 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2697 if (hostapd_config_read_radius_addr(
2698 &bss->radius->auth_servers,
2699 &bss->radius->num_auth_servers, pos, 1812,
2700 &bss->radius->auth_server)) {
2701 wpa_printf(MSG_ERROR,
2702 "Line %d: invalid IP address '%s'",
2703 line, pos);
2704 return 1;
2705 }
2706 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002707 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2708 if (hostapd_parse_ip_addr(pos,
2709 &bss->radius->auth_server->addr)) {
2710 wpa_printf(MSG_ERROR,
2711 "Line %d: invalid IP address '%s'",
2712 line, pos);
2713 return 1;
2714 }
2715 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002716 os_strcmp(buf, "auth_server_port") == 0) {
2717 bss->radius->auth_server->port = atoi(pos);
2718 } else if (bss->radius->auth_server &&
2719 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2720 int len = os_strlen(pos);
2721 if (len == 0) {
2722 /* RFC 2865, Ch. 3 */
2723 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2724 line);
2725 return 1;
2726 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002727 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002728 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2729 bss->radius->auth_server->shared_secret_len = len;
2730 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2731 if (hostapd_config_read_radius_addr(
2732 &bss->radius->acct_servers,
2733 &bss->radius->num_acct_servers, pos, 1813,
2734 &bss->radius->acct_server)) {
2735 wpa_printf(MSG_ERROR,
2736 "Line %d: invalid IP address '%s'",
2737 line, pos);
2738 return 1;
2739 }
2740 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002741 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2742 if (hostapd_parse_ip_addr(pos,
2743 &bss->radius->acct_server->addr)) {
2744 wpa_printf(MSG_ERROR,
2745 "Line %d: invalid IP address '%s'",
2746 line, pos);
2747 return 1;
2748 }
2749 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002750 os_strcmp(buf, "acct_server_port") == 0) {
2751 bss->radius->acct_server->port = atoi(pos);
2752 } else if (bss->radius->acct_server &&
2753 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2754 int len = os_strlen(pos);
2755 if (len == 0) {
2756 /* RFC 2865, Ch. 3 */
2757 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2758 line);
2759 return 1;
2760 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002761 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002762 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2763 bss->radius->acct_server->shared_secret_len = len;
2764 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2765 bss->radius->retry_primary_interval = atoi(pos);
2766 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2767 bss->acct_interim_interval = atoi(pos);
2768 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2769 bss->radius_request_cui = atoi(pos);
2770 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2771 struct hostapd_radius_attr *attr, *a;
2772 attr = hostapd_parse_radius_attr(pos);
2773 if (attr == NULL) {
2774 wpa_printf(MSG_ERROR,
2775 "Line %d: invalid radius_auth_req_attr",
2776 line);
2777 return 1;
2778 } else if (bss->radius_auth_req_attr == NULL) {
2779 bss->radius_auth_req_attr = attr;
2780 } else {
2781 a = bss->radius_auth_req_attr;
2782 while (a->next)
2783 a = a->next;
2784 a->next = attr;
2785 }
2786 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2787 struct hostapd_radius_attr *attr, *a;
2788 attr = hostapd_parse_radius_attr(pos);
2789 if (attr == NULL) {
2790 wpa_printf(MSG_ERROR,
2791 "Line %d: invalid radius_acct_req_attr",
2792 line);
2793 return 1;
2794 } else if (bss->radius_acct_req_attr == NULL) {
2795 bss->radius_acct_req_attr = attr;
2796 } else {
2797 a = bss->radius_acct_req_attr;
2798 while (a->next)
2799 a = a->next;
2800 a->next = attr;
2801 }
Hai Shalomc3565922019-10-28 11:58:20 -07002802 } else if (os_strcmp(buf, "radius_req_attr_sqlite") == 0) {
2803 os_free(bss->radius_req_attr_sqlite);
2804 bss->radius_req_attr_sqlite = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002805 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2806 bss->radius_das_port = atoi(pos);
2807 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2808 if (hostapd_parse_das_client(bss, pos) < 0) {
2809 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2810 line);
2811 return 1;
2812 }
2813 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2814 bss->radius_das_time_window = atoi(pos);
2815 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2816 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002817 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2818 0) {
2819 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002821 } else if (os_strcmp(buf, "auth_algs") == 0) {
2822 bss->auth_algs = atoi(pos);
2823 if (bss->auth_algs == 0) {
2824 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2825 line);
2826 return 1;
2827 }
2828 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2829 bss->max_num_sta = atoi(pos);
2830 if (bss->max_num_sta < 0 ||
2831 bss->max_num_sta > MAX_STA_COUNT) {
2832 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2833 line, bss->max_num_sta, MAX_STA_COUNT);
2834 return 1;
2835 }
2836 } else if (os_strcmp(buf, "wpa") == 0) {
2837 bss->wpa = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002838 } else if (os_strcmp(buf, "extended_key_id") == 0) {
2839 int val = atoi(pos);
2840
2841 if (val < 0 || val > 2) {
2842 wpa_printf(MSG_ERROR,
2843 "Line %d: Invalid extended_key_id=%d; allowed range 0..2",
2844 line, val);
2845 return 1;
2846 }
2847 bss->extended_key_id = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002848 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2849 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002850 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002851 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2852 bss->wpa_strict_rekey = atoi(pos);
2853 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2854 bss->wpa_gmk_rekey = atoi(pos);
2855 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2856 bss->wpa_ptk_rekey = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002857 } else if (os_strcmp(buf, "wpa_deny_ptk0_rekey") == 0) {
2858 bss->wpa_deny_ptk0_rekey = atoi(pos);
2859 if (bss->wpa_deny_ptk0_rekey < 0 ||
2860 bss->wpa_deny_ptk0_rekey > 2) {
2861 wpa_printf(MSG_ERROR,
2862 "Line %d: Invalid wpa_deny_ptk0_rekey=%d; allowed range 0..2",
2863 line, bss->wpa_deny_ptk0_rekey);
2864 return 1;
2865 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002866 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2867 char *endp;
2868 unsigned long val = strtoul(pos, &endp, 0);
2869
2870 if (*endp || val < 1 || val > (u32) -1) {
2871 wpa_printf(MSG_ERROR,
2872 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2873 line, val);
2874 return 1;
2875 }
2876 bss->wpa_group_update_count = (u32) val;
2877 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2878 char *endp;
2879 unsigned long val = strtoul(pos, &endp, 0);
2880
2881 if (*endp || val < 1 || val > (u32) -1) {
2882 wpa_printf(MSG_ERROR,
2883 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2884 line, val);
2885 return 1;
2886 }
2887 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002888 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2889 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002890 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2891 int len = os_strlen(pos);
2892 if (len < 8 || len > 63) {
2893 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2894 line, len);
2895 return 1;
2896 }
2897 os_free(bss->ssid.wpa_passphrase);
2898 bss->ssid.wpa_passphrase = os_strdup(pos);
2899 if (bss->ssid.wpa_passphrase) {
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 bss->ssid.wpa_passphrase_set = 1;
2902 }
2903 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002904 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002905 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2906 if (bss->ssid.wpa_psk == NULL)
2907 return 1;
2908 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2909 pos[PMK_LEN * 2] != '\0') {
2910 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2911 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002912 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002913 return 1;
2914 }
2915 bss->ssid.wpa_psk->group = 1;
2916 os_free(bss->ssid.wpa_passphrase);
2917 bss->ssid.wpa_passphrase = NULL;
2918 bss->ssid.wpa_psk_set = 1;
2919 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2920 os_free(bss->ssid.wpa_psk_file);
2921 bss->ssid.wpa_psk_file = os_strdup(pos);
2922 if (!bss->ssid.wpa_psk_file) {
2923 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2924 line);
2925 return 1;
2926 }
2927 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2928 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2929 if (bss->wpa_key_mgmt == -1)
2930 return 1;
2931 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2932 bss->wpa_psk_radius = atoi(pos);
2933 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2934 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07002935 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED &&
2936 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002937 wpa_printf(MSG_ERROR,
2938 "Line %d: unknown wpa_psk_radius %d",
2939 line, bss->wpa_psk_radius);
2940 return 1;
2941 }
2942 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2943 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2944 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2945 return 1;
2946 if (bss->wpa_pairwise &
2947 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2948 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002949 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002950 return 1;
2951 }
2952 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2953 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2954 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2955 return 1;
2956 if (bss->rsn_pairwise &
2957 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2958 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002959 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002960 return 1;
2961 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002962 } else if (os_strcmp(buf, "group_cipher") == 0) {
2963 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2964 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2965 return 1;
2966 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2967 bss->group_cipher != WPA_CIPHER_CCMP &&
2968 bss->group_cipher != WPA_CIPHER_GCMP &&
2969 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2970 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2971 wpa_printf(MSG_ERROR,
2972 "Line %d: unsupported group cipher suite '%s'",
2973 line, pos);
2974 return 1;
2975 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002977 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2978 bss->rsn_preauth = atoi(pos);
2979 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002980 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002981 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982#endif /* CONFIG_RSN_PREAUTH */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002983 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002984 wpa_printf(MSG_INFO,
2985 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002986#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002987 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2988 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2989 hexstr2bin(pos, bss->mobility_domain,
2990 MOBILITY_DOMAIN_ID_LEN) != 0) {
2991 wpa_printf(MSG_ERROR,
2992 "Line %d: Invalid mobility_domain '%s'",
2993 line, pos);
2994 return 1;
2995 }
2996 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2997 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2998 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2999 wpa_printf(MSG_ERROR,
3000 "Line %d: Invalid r1_key_holder '%s'",
3001 line, pos);
3002 return 1;
3003 }
3004 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003005 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
3006 bss->r0_key_lifetime = atoi(pos) * 60;
3007 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003008 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003009 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
3010 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003011 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
3012 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003013 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
3014 bss->rkh_pos_timeout = atoi(pos);
3015 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
3016 bss->rkh_neg_timeout = atoi(pos);
3017 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
3018 bss->rkh_pull_timeout = atoi(pos);
3019 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
3020 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003021 } else if (os_strcmp(buf, "r0kh") == 0) {
3022 if (add_r0kh(bss, pos) < 0) {
3023 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
3024 line, pos);
3025 return 1;
3026 }
3027 } else if (os_strcmp(buf, "r1kh") == 0) {
3028 if (add_r1kh(bss, pos) < 0) {
3029 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
3030 line, pos);
3031 return 1;
3032 }
3033 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
3034 bss->pmk_r1_push = atoi(pos);
3035 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
3036 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003037 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
3038 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003039#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003040#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003041 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
3042 os_free(bss->ctrl_interface);
3043 bss->ctrl_interface = os_strdup(pos);
3044 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003045#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003046 struct group *grp;
3047 char *endp;
3048 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003049
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003050 grp = getgrnam(group);
3051 if (grp) {
3052 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003054 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
3055 bss->ctrl_interface_gid, group);
3056 return 0;
3057 }
3058
3059 /* Group name not found - try to parse this as gid */
3060 bss->ctrl_interface_gid = strtol(group, &endp, 10);
3061 if (*group == '\0' || *endp != '\0') {
3062 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
3063 line, group);
3064 return 1;
3065 }
3066 bss->ctrl_interface_gid_set = 1;
3067 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
3068 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003069#endif /* CONFIG_NATIVE_WINDOWS */
3070#endif /* CONFIG_NO_CTRL_IFACE */
3071#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003072 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
3073 os_free(bss->radius_server_clients);
3074 bss->radius_server_clients = os_strdup(pos);
3075 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
3076 bss->radius_server_auth_port = atoi(pos);
3077 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
3078 bss->radius_server_acct_port = atoi(pos);
3079 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
3080 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003082 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
3083 bss->use_pae_group_addr = atoi(pos);
3084 } else if (os_strcmp(buf, "hw_mode") == 0) {
3085 if (os_strcmp(pos, "a") == 0)
3086 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
3087 else if (os_strcmp(pos, "b") == 0)
3088 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
3089 else if (os_strcmp(pos, "g") == 0)
3090 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
3091 else if (os_strcmp(pos, "ad") == 0)
3092 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003093 else if (os_strcmp(pos, "any") == 0)
3094 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003095 else {
3096 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3097 line, pos);
3098 return 1;
3099 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003100 conf->hw_mode_set = true;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003101 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003102 if (os_strcmp(pos, "ad") == 0)
3103 bss->wps_rf_bands = WPS_RF_60GHZ;
3104 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003105 bss->wps_rf_bands = WPS_RF_50GHZ;
3106 else if (os_strcmp(pos, "g") == 0 ||
3107 os_strcmp(pos, "b") == 0)
3108 bss->wps_rf_bands = WPS_RF_24GHZ;
3109 else if (os_strcmp(pos, "ag") == 0 ||
3110 os_strcmp(pos, "ga") == 0)
3111 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3112 else {
3113 wpa_printf(MSG_ERROR,
3114 "Line %d: unknown wps_rf_band '%s'",
3115 line, pos);
3116 return 1;
3117 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003118 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3119 conf->acs_exclude_dfs = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07003120 } else if (os_strcmp(buf, "op_class") == 0) {
3121 conf->op_class = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003122 } else if (os_strcmp(buf, "channel") == 0) {
3123 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003124#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003125 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3126 line);
3127 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003128#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003129 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003130 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003131#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003132 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003133 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003134 conf->acs = conf->channel == 0;
3135 }
Hai Shalomc3565922019-10-28 11:58:20 -07003136 } else if (os_strcmp(buf, "edmg_channel") == 0) {
3137 conf->edmg_channel = atoi(pos);
3138 } else if (os_strcmp(buf, "enable_edmg") == 0) {
3139 conf->enable_edmg = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003140 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003141 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003142 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3143 line);
3144 return 1;
3145 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003146 } else if (os_strcmp(buf, "freqlist") == 0) {
3147 if (freq_range_list_parse(&conf->acs_freq_list, pos)) {
3148 wpa_printf(MSG_ERROR, "Line %d: invalid frequency list",
3149 line);
3150 return 1;
3151 }
3152 conf->acs_freq_list_present = 1;
3153 } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) {
3154 conf->acs_exclude_6ghz_non_psc = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07003155 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
3156 conf->enable_background_radar = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003157 } else if (os_strcmp(buf, "min_tx_power") == 0) {
3158 int val = atoi(pos);
3159
3160 if (val < 0 || val > 255) {
3161 wpa_printf(MSG_ERROR,
3162 "Line %d: invalid min_tx_power %d (expected 0..255)",
3163 line, val);
3164 return 1;
3165 }
3166 conf->min_tx_power = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003167 } else if (os_strcmp(buf, "beacon_int") == 0) {
3168 int val = atoi(pos);
3169 /* MIB defines range as 1..65535, but very small values
3170 * cause problems with the current implementation.
3171 * Since it is unlikely that this small numbers are
3172 * useful in real life scenarios, do not allow beacon
Hai Shalom021b0b52019-04-10 11:17:58 -07003173 * period to be set below 10 TU. */
3174 if (val < 10 || val > 65535) {
3175 wpa_printf(MSG_ERROR,
3176 "Line %d: invalid beacon_int %d (expected 10..65535)",
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003177 line, val);
3178 return 1;
3179 }
3180 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003181#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003182 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3183 int val = atoi(pos);
3184 if (val <= 0 || val > 100) {
3185 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3186 line, val);
3187 return 1;
3188 }
3189 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003190 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3191 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3192 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3193 line);
3194 return -1;
3195 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003196#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003197 } else if (os_strcmp(buf, "dtim_period") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003198 int val = atoi(pos);
3199
3200 if (val < 1 || val > 255) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003201 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08003202 line, val);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003203 return 1;
3204 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08003205 bss->dtim_period = val;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003206 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003207 int val = atoi(pos);
3208
3209 if (val < 0 || val > 100) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003210 wpa_printf(MSG_ERROR,
3211 "Line %d: invalid bss_load_update_period %d",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003212 line, val);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003213 return 1;
3214 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003215 bss->bss_load_update_period = val;
3216 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3217 int val = atoi(pos);
3218
3219 if (val < 0) {
3220 wpa_printf(MSG_ERROR,
3221 "Line %d: invalid chan_util_avg_period",
3222 line);
3223 return 1;
3224 }
3225 bss->chan_util_avg_period = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003226 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3227 conf->rts_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003228 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003229 wpa_printf(MSG_ERROR,
3230 "Line %d: invalid rts_threshold %d",
3231 line, conf->rts_threshold);
3232 return 1;
3233 }
3234 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3235 conf->fragm_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003236 if (conf->fragm_threshold == -1) {
3237 /* allow a value of -1 */
3238 } else if (conf->fragm_threshold < 256 ||
3239 conf->fragm_threshold > 2346) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003240 wpa_printf(MSG_ERROR,
3241 "Line %d: invalid fragm_threshold %d",
3242 line, conf->fragm_threshold);
3243 return 1;
3244 }
3245 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3246 int val = atoi(pos);
3247 if (val != 0 && val != 1) {
3248 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3249 line, val);
3250 return 1;
3251 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003252 bss->send_probe_response = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003253 } else if (os_strcmp(buf, "supported_rates") == 0) {
3254 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3255 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3256 line);
3257 return 1;
3258 }
3259 } else if (os_strcmp(buf, "basic_rates") == 0) {
3260 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3261 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3262 line);
3263 return 1;
3264 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003265 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3266 int val;
3267
3268 if (os_strncmp(pos, "ht:", 3) == 0) {
3269 val = atoi(pos + 3);
3270 if (val < 0 || val > 31) {
3271 wpa_printf(MSG_ERROR,
3272 "Line %d: invalid beacon_rate HT-MCS %d",
3273 line, val);
3274 return 1;
3275 }
3276 conf->rate_type = BEACON_RATE_HT;
3277 conf->beacon_rate = val;
3278 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3279 val = atoi(pos + 4);
3280 if (val < 0 || val > 9) {
3281 wpa_printf(MSG_ERROR,
3282 "Line %d: invalid beacon_rate VHT-MCS %d",
3283 line, val);
3284 return 1;
3285 }
3286 conf->rate_type = BEACON_RATE_VHT;
3287 conf->beacon_rate = val;
Hai Shalom60840252021-02-19 19:02:11 -08003288 } else if (os_strncmp(pos, "he:", 3) == 0) {
3289 val = atoi(pos + 3);
3290 if (val < 0 || val > 11) {
3291 wpa_printf(MSG_ERROR,
3292 "Line %d: invalid beacon_rate HE-MCS %d",
3293 line, val);
3294 return 1;
3295 }
3296 conf->rate_type = BEACON_RATE_HE;
3297 conf->beacon_rate = val;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003298 } else {
3299 val = atoi(pos);
3300 if (val < 10 || val > 10000) {
3301 wpa_printf(MSG_ERROR,
3302 "Line %d: invalid legacy beacon_rate %d",
3303 line, val);
3304 return 1;
3305 }
3306 conf->rate_type = BEACON_RATE_LEGACY;
3307 conf->beacon_rate = val;
3308 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003309 } else if (os_strcmp(buf, "preamble") == 0) {
3310 if (atoi(pos))
3311 conf->preamble = SHORT_PREAMBLE;
3312 else
3313 conf->preamble = LONG_PREAMBLE;
3314 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3315 bss->ignore_broadcast_ssid = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003316 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3317 bss->no_probe_resp_if_max_sta = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003318#ifdef CONFIG_WEP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003319 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3320 bss->ssid.wep.idx = atoi(pos);
3321 if (bss->ssid.wep.idx > 3) {
3322 wpa_printf(MSG_ERROR,
3323 "Invalid wep_default_key index %d",
3324 bss->ssid.wep.idx);
3325 return 1;
3326 }
3327 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3328 os_strcmp(buf, "wep_key1") == 0 ||
3329 os_strcmp(buf, "wep_key2") == 0 ||
3330 os_strcmp(buf, "wep_key3") == 0) {
3331 if (hostapd_config_read_wep(&bss->ssid.wep,
3332 buf[7] - '0', pos)) {
3333 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3334 line, buf);
3335 return 1;
3336 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003337#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003338#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003339 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3340 bss->ssid.dynamic_vlan = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003341 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3342 bss->ssid.per_sta_vif = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003343 } else if (os_strcmp(buf, "vlan_file") == 0) {
3344 if (hostapd_config_read_vlan_file(bss, pos)) {
3345 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3346 line, pos);
3347 return 1;
3348 }
3349 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3350 bss->ssid.vlan_naming = atoi(pos);
3351 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3352 bss->ssid.vlan_naming < 0) {
3353 wpa_printf(MSG_ERROR,
3354 "Line %d: invalid naming scheme %d",
3355 line, bss->ssid.vlan_naming);
3356 return 1;
3357 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003359 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003360 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003361 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3363#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003364 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3365 conf->ap_table_max_size = atoi(pos);
3366 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3367 conf->ap_table_expiration_time = atoi(pos);
3368 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003369 if (hostapd_config_tx_queue(conf->tx_queue, buf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003370 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3371 line);
3372 return 1;
3373 }
3374 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3375 os_strcmp(buf, "wmm_enabled") == 0) {
3376 bss->wmm_enabled = atoi(pos);
3377 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3378 bss->wmm_uapsd = atoi(pos);
3379 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3380 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3381 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3382 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3383 line);
3384 return 1;
3385 }
3386 } else if (os_strcmp(buf, "bss") == 0) {
3387 if (hostapd_config_bss(conf, pos)) {
3388 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3389 line);
3390 return 1;
3391 }
3392 } else if (os_strcmp(buf, "bssid") == 0) {
3393 if (hwaddr_aton(pos, bss->bssid)) {
3394 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3395 line);
3396 return 1;
3397 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003398 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3399 conf->use_driver_iface_addr = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003400 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3401 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003402 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3403 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3404 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3405 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3406 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3407 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3408 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3409 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3410 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3411 } else {
3412 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3413 line, pos);
3414 return 1;
3415 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003416 } else if (os_strcmp(buf, "beacon_prot") == 0) {
3417 bss->beacon_prot = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003418 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3419 bss->assoc_sa_query_max_timeout = atoi(pos);
3420 if (bss->assoc_sa_query_max_timeout == 0) {
3421 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3422 line);
3423 return 1;
3424 }
3425 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3426 bss->assoc_sa_query_retry_timeout = atoi(pos);
3427 if (bss->assoc_sa_query_retry_timeout == 0) {
3428 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3429 line);
3430 return 1;
3431 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003432#ifdef CONFIG_OCV
3433 } else if (os_strcmp(buf, "ocv") == 0) {
3434 bss->ocv = atoi(pos);
3435 if (bss->ocv && !bss->ieee80211w)
3436 bss->ieee80211w = 1;
3437#endif /* CONFIG_OCV */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003438 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3439 conf->ieee80211n = atoi(pos);
3440 } else if (os_strcmp(buf, "ht_capab") == 0) {
3441 if (hostapd_config_ht_capab(conf, pos) < 0) {
3442 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3443 line);
3444 return 1;
3445 }
3446 } else if (os_strcmp(buf, "require_ht") == 0) {
3447 conf->require_ht = atoi(pos);
3448 } else if (os_strcmp(buf, "obss_interval") == 0) {
3449 conf->obss_interval = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003450#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003451 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3452 conf->ieee80211ac = atoi(pos);
3453 } else if (os_strcmp(buf, "vht_capab") == 0) {
3454 if (hostapd_config_vht_capab(conf, pos) < 0) {
3455 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3456 line);
3457 return 1;
3458 }
3459 } else if (os_strcmp(buf, "require_vht") == 0) {
3460 conf->require_vht = atoi(pos);
3461 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3462 conf->vht_oper_chwidth = atoi(pos);
3463 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3464 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3465 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3466 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003467 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3468 bss->vendor_vht = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003469 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3470 bss->use_sta_nsts = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003471#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003472#ifdef CONFIG_IEEE80211AX
3473 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3474 conf->ieee80211ax = atoi(pos);
3475 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3476 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3477 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3478 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3479 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3480 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3481 } else if (os_strcmp(buf, "he_bss_color") == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003482 conf->he_op.he_bss_color = atoi(pos) & 0x3f;
3483 conf->he_op.he_bss_color_disabled = 0;
3484 } else if (os_strcmp(buf, "he_bss_color_partial") == 0) {
3485 conf->he_op.he_bss_color_partial = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003486 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3487 conf->he_op.he_default_pe_duration = atoi(pos);
3488 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3489 conf->he_op.he_twt_required = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003490 } else if (os_strcmp(buf, "he_twt_responder") == 0) {
3491 conf->he_op.he_twt_responder = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003492 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3493 conf->he_op.he_rts_threshold = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003494 } else if (os_strcmp(buf, "he_er_su_disable") == 0) {
3495 conf->he_op.he_er_su_disable = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003496 } else if (os_strcmp(buf, "he_basic_mcs_nss_set") == 0) {
3497 conf->he_op.he_basic_mcs_nss_set = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08003498 } else if (os_strcmp(buf, "he_mu_edca_qos_info_param_count") == 0) {
3499 conf->he_mu_edca.he_qos_info |=
3500 set_he_cap(atoi(pos), HE_QOS_INFO_EDCA_PARAM_SET_COUNT);
3501 } else if (os_strcmp(buf, "he_mu_edca_qos_info_q_ack") == 0) {
3502 conf->he_mu_edca.he_qos_info |=
3503 set_he_cap(atoi(pos), HE_QOS_INFO_Q_ACK);
3504 } else if (os_strcmp(buf, "he_mu_edca_qos_info_queue_request") == 0) {
3505 conf->he_mu_edca.he_qos_info |=
3506 set_he_cap(atoi(pos), HE_QOS_INFO_QUEUE_REQUEST);
3507 } else if (os_strcmp(buf, "he_mu_edca_qos_info_txop_request") == 0) {
3508 conf->he_mu_edca.he_qos_info |=
3509 set_he_cap(atoi(pos), HE_QOS_INFO_TXOP_REQUEST);
3510 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aifsn") == 0) {
3511 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3512 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3513 } else if (os_strcmp(buf, "he_mu_edca_ac_be_acm") == 0) {
3514 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3515 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3516 } else if (os_strcmp(buf, "he_mu_edca_ac_be_aci") == 0) {
3517 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ACI_IDX] |=
3518 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3519 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmin") == 0) {
3520 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3521 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3522 } else if (os_strcmp(buf, "he_mu_edca_ac_be_ecwmax") == 0) {
3523 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_ECW_IDX] |=
3524 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3525 } else if (os_strcmp(buf, "he_mu_edca_ac_be_timer") == 0) {
3526 conf->he_mu_edca.he_mu_ac_be_param[HE_MU_AC_PARAM_TIMER_IDX] =
3527 atoi(pos) & 0xff;
3528 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aifsn") == 0) {
3529 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3530 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3531 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_acm") == 0) {
3532 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3533 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3534 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_aci") == 0) {
3535 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ACI_IDX] |=
3536 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3537 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmin") == 0) {
3538 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3539 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3540 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_ecwmax") == 0) {
3541 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_ECW_IDX] |=
3542 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3543 } else if (os_strcmp(buf, "he_mu_edca_ac_bk_timer") == 0) {
3544 conf->he_mu_edca.he_mu_ac_bk_param[HE_MU_AC_PARAM_TIMER_IDX] =
3545 atoi(pos) & 0xff;
3546 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aifsn") == 0) {
3547 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3548 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3549 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_acm") == 0) {
3550 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3551 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3552 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_aci") == 0) {
3553 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ACI_IDX] |=
3554 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3555 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmin") == 0) {
3556 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3557 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3558 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_ecwmax") == 0) {
3559 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_ECW_IDX] |=
3560 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3561 } else if (os_strcmp(buf, "he_mu_edca_ac_vi_timer") == 0) {
3562 conf->he_mu_edca.he_mu_ac_vi_param[HE_MU_AC_PARAM_TIMER_IDX] =
3563 atoi(pos) & 0xff;
3564 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aifsn") == 0) {
3565 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3566 set_he_cap(atoi(pos), HE_MU_AC_PARAM_AIFSN);
3567 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_acm") == 0) {
3568 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3569 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACM);
3570 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_aci") == 0) {
3571 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ACI_IDX] |=
3572 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ACI);
3573 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmin") == 0) {
3574 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3575 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMIN);
3576 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_ecwmax") == 0) {
3577 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_ECW_IDX] |=
3578 set_he_cap(atoi(pos), HE_MU_AC_PARAM_ECWMAX);
3579 } else if (os_strcmp(buf, "he_mu_edca_ac_vo_timer") == 0) {
3580 conf->he_mu_edca.he_mu_ac_vo_param[HE_MU_AC_PARAM_TIMER_IDX] =
3581 atoi(pos) & 0xff;
Hai Shalom81f62d82019-07-22 12:10:00 -07003582 } else if (os_strcmp(buf, "he_spr_sr_control") == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003583 conf->spr.sr_control = atoi(pos) & 0x1f;
Hai Shalom81f62d82019-07-22 12:10:00 -07003584 } else if (os_strcmp(buf, "he_spr_non_srg_obss_pd_max_offset") == 0) {
3585 conf->spr.non_srg_obss_pd_max_offset = atoi(pos);
3586 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_min_offset") == 0) {
3587 conf->spr.srg_obss_pd_min_offset = atoi(pos);
3588 } else if (os_strcmp(buf, "he_spr_srg_obss_pd_max_offset") == 0) {
3589 conf->spr.srg_obss_pd_max_offset = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003590 } else if (os_strcmp(buf, "he_spr_srg_bss_colors") == 0) {
3591 if (hostapd_parse_he_srg_bitmap(
3592 conf->spr.srg_bss_color_bitmap, pos)) {
3593 wpa_printf(MSG_ERROR,
3594 "Line %d: Invalid srg bss colors list '%s'",
3595 line, pos);
3596 return 1;
3597 }
3598 } else if (os_strcmp(buf, "he_spr_srg_partial_bssid") == 0) {
3599 if (hostapd_parse_he_srg_bitmap(
3600 conf->spr.srg_partial_bssid_bitmap, pos)) {
3601 wpa_printf(MSG_ERROR,
3602 "Line %d: Invalid srg partial bssid list '%s'",
3603 line, pos);
3604 return 1;
3605 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003606 } else if (os_strcmp(buf, "he_6ghz_reg_pwr_type") == 0) {
3607 conf->he_6ghz_reg_pwr_type = atoi(pos);
Hai Shalom81f62d82019-07-22 12:10:00 -07003608 } else if (os_strcmp(buf, "he_oper_chwidth") == 0) {
3609 conf->he_oper_chwidth = atoi(pos);
3610 } else if (os_strcmp(buf, "he_oper_centr_freq_seg0_idx") == 0) {
3611 conf->he_oper_centr_freq_seg0_idx = atoi(pos);
3612 } else if (os_strcmp(buf, "he_oper_centr_freq_seg1_idx") == 0) {
3613 conf->he_oper_centr_freq_seg1_idx = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08003614 } else if (os_strcmp(buf, "he_6ghz_max_mpdu") == 0) {
3615 conf->he_6ghz_max_mpdu = atoi(pos);
3616 } else if (os_strcmp(buf, "he_6ghz_max_ampdu_len_exp") == 0) {
3617 conf->he_6ghz_max_ampdu_len_exp = atoi(pos);
3618 } else if (os_strcmp(buf, "he_6ghz_rx_ant_pat") == 0) {
3619 conf->he_6ghz_rx_ant_pat = atoi(pos);
3620 } else if (os_strcmp(buf, "he_6ghz_tx_ant_pat") == 0) {
3621 conf->he_6ghz_tx_ant_pat = atoi(pos);
3622 } else if (os_strcmp(buf, "unsol_bcast_probe_resp_interval") == 0) {
3623 int val = atoi(pos);
3624
3625 if (val < 0 || val > 20) {
3626 wpa_printf(MSG_ERROR,
3627 "Line %d: invalid unsol_bcast_probe_resp_interval value",
3628 line);
3629 return 1;
3630 }
3631 bss->unsol_bcast_probe_resp_interval = val;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003632#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003633 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3634 bss->max_listen_interval = atoi(pos);
3635 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3636 bss->disable_pmksa_caching = atoi(pos);
3637 } else if (os_strcmp(buf, "okc") == 0) {
3638 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003639#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003640 } else if (os_strcmp(buf, "wps_state") == 0) {
3641 bss->wps_state = atoi(pos);
3642 if (bss->wps_state < 0 || bss->wps_state > 2) {
3643 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3644 line);
3645 return 1;
3646 }
3647 } else if (os_strcmp(buf, "wps_independent") == 0) {
3648 bss->wps_independent = atoi(pos);
3649 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3650 bss->ap_setup_locked = atoi(pos);
3651 } else if (os_strcmp(buf, "uuid") == 0) {
3652 if (uuid_str2bin(pos, bss->uuid)) {
3653 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3654 return 1;
3655 }
3656 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3657 os_free(bss->wps_pin_requests);
3658 bss->wps_pin_requests = os_strdup(pos);
3659 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003660 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003661 wpa_printf(MSG_ERROR, "Line %d: Too long "
3662 "device_name", line);
3663 return 1;
3664 }
3665 os_free(bss->device_name);
3666 bss->device_name = os_strdup(pos);
3667 } else if (os_strcmp(buf, "manufacturer") == 0) {
3668 if (os_strlen(pos) > 64) {
3669 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3670 line);
3671 return 1;
3672 }
3673 os_free(bss->manufacturer);
3674 bss->manufacturer = os_strdup(pos);
3675 } else if (os_strcmp(buf, "model_name") == 0) {
3676 if (os_strlen(pos) > 32) {
3677 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3678 line);
3679 return 1;
3680 }
3681 os_free(bss->model_name);
3682 bss->model_name = os_strdup(pos);
3683 } else if (os_strcmp(buf, "model_number") == 0) {
3684 if (os_strlen(pos) > 32) {
3685 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3686 line);
3687 return 1;
3688 }
3689 os_free(bss->model_number);
3690 bss->model_number = os_strdup(pos);
3691 } else if (os_strcmp(buf, "serial_number") == 0) {
3692 if (os_strlen(pos) > 32) {
3693 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3694 line);
3695 return 1;
3696 }
3697 os_free(bss->serial_number);
3698 bss->serial_number = os_strdup(pos);
3699 } else if (os_strcmp(buf, "device_type") == 0) {
3700 if (wps_dev_type_str2bin(pos, bss->device_type))
3701 return 1;
3702 } else if (os_strcmp(buf, "config_methods") == 0) {
3703 os_free(bss->config_methods);
3704 bss->config_methods = os_strdup(pos);
3705 } else if (os_strcmp(buf, "os_version") == 0) {
3706 if (hexstr2bin(pos, bss->os_version, 4)) {
3707 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3708 line);
3709 return 1;
3710 }
3711 } else if (os_strcmp(buf, "ap_pin") == 0) {
3712 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003713 if (*pos == '\0')
3714 bss->ap_pin = NULL;
3715 else
3716 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003717 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3718 bss->skip_cred_build = atoi(pos);
3719 } else if (os_strcmp(buf, "extra_cred") == 0) {
3720 os_free(bss->extra_cred);
3721 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3722 if (bss->extra_cred == NULL) {
3723 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3724 line, pos);
3725 return 1;
3726 }
3727 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3728 bss->wps_cred_processing = atoi(pos);
Hai Shalom021b0b52019-04-10 11:17:58 -07003729 } else if (os_strcmp(buf, "wps_cred_add_sae") == 0) {
3730 bss->wps_cred_add_sae = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003731 } else if (os_strcmp(buf, "ap_settings") == 0) {
3732 os_free(bss->ap_settings);
3733 bss->ap_settings =
3734 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3735 if (bss->ap_settings == NULL) {
3736 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3737 line, pos);
3738 return 1;
3739 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003740 } else if (os_strcmp(buf, "multi_ap_backhaul_ssid") == 0) {
3741 size_t slen;
3742 char *str = wpa_config_parse_string(pos, &slen);
3743
3744 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
3745 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
3746 line, pos);
3747 os_free(str);
3748 return 1;
3749 }
3750 os_memcpy(bss->multi_ap_backhaul_ssid.ssid, str, slen);
3751 bss->multi_ap_backhaul_ssid.ssid_len = slen;
3752 bss->multi_ap_backhaul_ssid.ssid_set = 1;
3753 os_free(str);
3754 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_passphrase") == 0) {
3755 int len = os_strlen(pos);
3756
3757 if (len < 8 || len > 63) {
3758 wpa_printf(MSG_ERROR,
3759 "Line %d: invalid WPA passphrase length %d (expected 8..63)",
3760 line, len);
3761 return 1;
3762 }
3763 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3764 bss->multi_ap_backhaul_ssid.wpa_passphrase = os_strdup(pos);
3765 if (bss->multi_ap_backhaul_ssid.wpa_passphrase) {
3766 hostapd_config_clear_wpa_psk(
3767 &bss->multi_ap_backhaul_ssid.wpa_psk);
3768 bss->multi_ap_backhaul_ssid.wpa_passphrase_set = 1;
3769 }
3770 } else if (os_strcmp(buf, "multi_ap_backhaul_wpa_psk") == 0) {
3771 hostapd_config_clear_wpa_psk(
3772 &bss->multi_ap_backhaul_ssid.wpa_psk);
3773 bss->multi_ap_backhaul_ssid.wpa_psk =
3774 os_zalloc(sizeof(struct hostapd_wpa_psk));
3775 if (!bss->multi_ap_backhaul_ssid.wpa_psk)
3776 return 1;
3777 if (hexstr2bin(pos, bss->multi_ap_backhaul_ssid.wpa_psk->psk,
3778 PMK_LEN) ||
3779 pos[PMK_LEN * 2] != '\0') {
3780 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
3781 line, pos);
3782 hostapd_config_clear_wpa_psk(
3783 &bss->multi_ap_backhaul_ssid.wpa_psk);
3784 return 1;
3785 }
3786 bss->multi_ap_backhaul_ssid.wpa_psk->group = 1;
3787 os_free(bss->multi_ap_backhaul_ssid.wpa_passphrase);
3788 bss->multi_ap_backhaul_ssid.wpa_passphrase = NULL;
3789 bss->multi_ap_backhaul_ssid.wpa_psk_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003790 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003791 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003792 bss->upnp_iface = os_strdup(pos);
3793 } else if (os_strcmp(buf, "friendly_name") == 0) {
3794 os_free(bss->friendly_name);
3795 bss->friendly_name = os_strdup(pos);
3796 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3797 os_free(bss->manufacturer_url);
3798 bss->manufacturer_url = os_strdup(pos);
3799 } else if (os_strcmp(buf, "model_description") == 0) {
3800 os_free(bss->model_description);
3801 bss->model_description = os_strdup(pos);
3802 } else if (os_strcmp(buf, "model_url") == 0) {
3803 os_free(bss->model_url);
3804 bss->model_url = os_strdup(pos);
3805 } else if (os_strcmp(buf, "upc") == 0) {
3806 os_free(bss->upc);
3807 bss->upc = os_strdup(pos);
3808 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3809 bss->pbc_in_m1 = atoi(pos);
3810 } else if (os_strcmp(buf, "server_id") == 0) {
3811 os_free(bss->server_id);
3812 bss->server_id = os_strdup(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07003813 } else if (os_strcmp(buf, "wps_application_ext") == 0) {
3814 wpabuf_free(bss->wps_application_ext);
3815 bss->wps_application_ext = wpabuf_parse_bin(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003816#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003817 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3818 bss->wps_nfc_dev_pw_id = atoi(pos);
3819 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3820 bss->wps_nfc_dev_pw_id > 0xffff) {
3821 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3822 line);
3823 return 1;
3824 }
3825 bss->wps_nfc_pw_from_config = 1;
3826 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3827 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003828 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003829 bss->wps_nfc_pw_from_config = 1;
3830 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3831 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003832 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003833 bss->wps_nfc_pw_from_config = 1;
3834 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3835 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003836 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003837 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003838#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003839#endif /* CONFIG_WPS */
3840#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003841 } else if (os_strcmp(buf, "manage_p2p") == 0) {
3842 if (atoi(pos))
3843 bss->p2p |= P2P_MANAGE;
3844 else
3845 bss->p2p &= ~P2P_MANAGE;
3846 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3847 if (atoi(pos))
3848 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3849 else
3850 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003851#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003852 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3853 bss->disassoc_low_ack = atoi(pos);
3854 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
3855 if (atoi(pos))
3856 bss->tdls |= TDLS_PROHIBIT;
3857 else
3858 bss->tdls &= ~TDLS_PROHIBIT;
3859 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
3860 if (atoi(pos))
3861 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3862 else
3863 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003865 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3866 extern int rsn_testing;
3867 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003868#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003869 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3870 bss->time_advertisement = atoi(pos);
3871 } else if (os_strcmp(buf, "time_zone") == 0) {
3872 size_t tz_len = os_strlen(pos);
3873 if (tz_len < 4 || tz_len > 255) {
3874 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3875 line);
3876 return 1;
3877 }
3878 os_free(bss->time_zone);
3879 bss->time_zone = os_strdup(pos);
3880 if (bss->time_zone == NULL)
3881 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003882#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003883 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3884 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003885 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3886 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003887 } else if (os_strcmp(buf, "bss_transition") == 0) {
3888 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003889#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003890#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003891 } else if (os_strcmp(buf, "interworking") == 0) {
3892 bss->interworking = atoi(pos);
3893 } else if (os_strcmp(buf, "access_network_type") == 0) {
3894 bss->access_network_type = atoi(pos);
3895 if (bss->access_network_type < 0 ||
3896 bss->access_network_type > 15) {
3897 wpa_printf(MSG_ERROR,
3898 "Line %d: invalid access_network_type",
3899 line);
3900 return 1;
3901 }
3902 } else if (os_strcmp(buf, "internet") == 0) {
3903 bss->internet = atoi(pos);
3904 } else if (os_strcmp(buf, "asra") == 0) {
3905 bss->asra = atoi(pos);
3906 } else if (os_strcmp(buf, "esr") == 0) {
3907 bss->esr = atoi(pos);
3908 } else if (os_strcmp(buf, "uesa") == 0) {
3909 bss->uesa = atoi(pos);
3910 } else if (os_strcmp(buf, "venue_group") == 0) {
3911 bss->venue_group = atoi(pos);
3912 bss->venue_info_set = 1;
3913 } else if (os_strcmp(buf, "venue_type") == 0) {
3914 bss->venue_type = atoi(pos);
3915 bss->venue_info_set = 1;
3916 } else if (os_strcmp(buf, "hessid") == 0) {
3917 if (hwaddr_aton(pos, bss->hessid)) {
3918 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3919 return 1;
3920 }
3921 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3922 if (parse_roaming_consortium(bss, pos, line) < 0)
3923 return 1;
3924 } else if (os_strcmp(buf, "venue_name") == 0) {
3925 if (parse_venue_name(bss, pos, line) < 0)
3926 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003927 } else if (os_strcmp(buf, "venue_url") == 0) {
3928 if (parse_venue_url(bss, pos, line) < 0)
3929 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003930 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3931 u8 auth_type;
3932 u16 redirect_url_len;
3933 if (hexstr2bin(pos, &auth_type, 1)) {
3934 wpa_printf(MSG_ERROR,
3935 "Line %d: Invalid network_auth_type '%s'",
3936 line, pos);
3937 return 1;
3938 }
3939 if (auth_type == 0 || auth_type == 2)
3940 redirect_url_len = os_strlen(pos + 2);
3941 else
3942 redirect_url_len = 0;
3943 os_free(bss->network_auth_type);
3944 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3945 if (bss->network_auth_type == NULL)
3946 return 1;
3947 *bss->network_auth_type = auth_type;
3948 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3949 if (redirect_url_len)
3950 os_memcpy(bss->network_auth_type + 3, pos + 2,
3951 redirect_url_len);
3952 bss->network_auth_type_len = 3 + redirect_url_len;
3953 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3954 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3955 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3956 line, pos);
3957 bss->ipaddr_type_configured = 0;
3958 return 1;
3959 }
3960 bss->ipaddr_type_configured = 1;
3961 } else if (os_strcmp(buf, "domain_name") == 0) {
3962 int j, num_domains, domain_len, domain_list_len = 0;
3963 char *tok_start, *tok_prev;
3964 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003965
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003966 domain_list_len = os_strlen(pos) + 1;
3967 domain_list = os_malloc(domain_list_len);
3968 if (domain_list == NULL)
3969 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003970
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003971 domain_ptr = domain_list;
3972 tok_prev = pos;
3973 num_domains = 1;
3974 while ((tok_prev = os_strchr(tok_prev, ','))) {
3975 num_domains++;
3976 tok_prev++;
3977 }
3978 tok_prev = pos;
3979 for (j = 0; j < num_domains; j++) {
3980 tok_start = os_strchr(tok_prev, ',');
3981 if (tok_start) {
3982 domain_len = tok_start - tok_prev;
3983 *domain_ptr = domain_len;
3984 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3985 domain_ptr += domain_len + 1;
3986 tok_prev = ++tok_start;
3987 } else {
3988 domain_len = os_strlen(tok_prev);
3989 *domain_ptr = domain_len;
3990 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3991 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003992 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003993 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003994
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003995 os_free(bss->domain_name);
3996 bss->domain_name = domain_list;
3997 bss->domain_name_len = domain_list_len;
3998 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3999 if (parse_3gpp_cell_net(bss, pos, line) < 0)
4000 return 1;
4001 } else if (os_strcmp(buf, "nai_realm") == 0) {
4002 if (parse_nai_realm(bss, pos, line) < 0)
4003 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004004 } else if (os_strcmp(buf, "anqp_elem") == 0) {
4005 if (parse_anqp_elem(bss, pos, line) < 0)
4006 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004007 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004008 int val = atoi(pos);
4009
4010 if (val <= 0) {
4011 wpa_printf(MSG_ERROR,
4012 "Line %d: Invalid gas_frag_limit '%s'",
4013 line, pos);
4014 return 1;
4015 }
4016 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004017 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
4018 bss->gas_comeback_delay = atoi(pos);
4019 } else if (os_strcmp(buf, "qos_map_set") == 0) {
4020 if (parse_qos_map_set(bss, pos, line) < 0)
4021 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004022#endif /* CONFIG_INTERWORKING */
4023#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004024 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
4025 os_free(bss->dump_msk_file);
4026 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004027#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004028#ifdef CONFIG_PROXYARP
4029 } else if (os_strcmp(buf, "proxy_arp") == 0) {
4030 bss->proxy_arp = atoi(pos);
4031#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004032#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004033 } else if (os_strcmp(buf, "hs20") == 0) {
4034 bss->hs20 = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004035 } else if (os_strcmp(buf, "hs20_release") == 0) {
4036 int val = atoi(pos);
4037
4038 if (val < 1 || val > (HS20_VERSION >> 4) + 1) {
4039 wpa_printf(MSG_ERROR,
4040 "Line %d: Unsupported hs20_release: %s",
4041 line, pos);
4042 return 1;
4043 }
4044 bss->hs20_release = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004045 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
4046 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004047 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
4048 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004049 } else if (os_strcmp(buf, "osen") == 0) {
4050 bss->osen = atoi(pos);
4051 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
4052 bss->anqp_domain_id = atoi(pos);
4053 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
4054 bss->hs20_deauth_req_timeout = atoi(pos);
4055 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
4056 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
4057 return 1;
4058 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
4059 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
4060 return 1;
4061 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
4062 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
4063 return 1;
4064 }
4065 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
4066 u8 *oper_class;
4067 size_t oper_class_len;
4068 oper_class_len = os_strlen(pos);
4069 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
4070 wpa_printf(MSG_ERROR,
4071 "Line %d: Invalid hs20_operating_class '%s'",
4072 line, pos);
4073 return 1;
4074 }
4075 oper_class_len /= 2;
4076 oper_class = os_malloc(oper_class_len);
4077 if (oper_class == NULL)
4078 return 1;
4079 if (hexstr2bin(pos, oper_class, oper_class_len)) {
4080 wpa_printf(MSG_ERROR,
4081 "Line %d: Invalid hs20_operating_class '%s'",
4082 line, pos);
4083 os_free(oper_class);
4084 return 1;
4085 }
4086 os_free(bss->hs20_operating_class);
4087 bss->hs20_operating_class = oper_class;
4088 bss->hs20_operating_class_len = oper_class_len;
4089 } else if (os_strcmp(buf, "hs20_icon") == 0) {
4090 if (hs20_parse_icon(bss, pos) < 0) {
4091 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
4092 line, pos);
4093 return 1;
4094 }
4095 } else if (os_strcmp(buf, "osu_ssid") == 0) {
4096 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
4097 return 1;
4098 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
4099 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
4100 return 1;
4101 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
4102 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
4103 return 1;
4104 } else if (os_strcmp(buf, "osu_nai") == 0) {
4105 if (hs20_parse_osu_nai(bss, pos, line) < 0)
4106 return 1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004107 } else if (os_strcmp(buf, "osu_nai2") == 0) {
4108 if (hs20_parse_osu_nai2(bss, pos, line) < 0)
4109 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004110 } else if (os_strcmp(buf, "osu_method_list") == 0) {
4111 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
4112 return 1;
4113 } else if (os_strcmp(buf, "osu_icon") == 0) {
4114 if (hs20_parse_osu_icon(bss, pos, line) < 0)
4115 return 1;
4116 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
4117 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
4118 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004119 } else if (os_strcmp(buf, "operator_icon") == 0) {
4120 if (hs20_parse_operator_icon(bss, pos, line) < 0)
4121 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004122 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
4123 os_free(bss->subscr_remediation_url);
4124 bss->subscr_remediation_url = os_strdup(pos);
4125 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
4126 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004127 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
4128 os_free(bss->t_c_filename);
4129 bss->t_c_filename = os_strdup(pos);
4130 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
4131 bss->t_c_timestamp = strtol(pos, NULL, 0);
4132 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
4133 os_free(bss->t_c_server_url);
4134 bss->t_c_server_url = os_strdup(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004135 } else if (os_strcmp(buf, "hs20_sim_provisioning_url") == 0) {
4136 os_free(bss->hs20_sim_provisioning_url);
4137 bss->hs20_sim_provisioning_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004138#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004139#ifdef CONFIG_MBO
4140 } else if (os_strcmp(buf, "mbo") == 0) {
4141 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004142 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
4143 bss->mbo_cell_data_conn_pref = atoi(pos);
4144 } else if (os_strcmp(buf, "oce") == 0) {
4145 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004146#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004147#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004148#define PARSE_TEST_PROBABILITY(_val) \
4149 } else if (os_strcmp(buf, #_val) == 0) { \
4150 char *end; \
4151 \
4152 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004153 if (*end || conf->_val < 0.0 || \
4154 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004155 wpa_printf(MSG_ERROR, \
4156 "Line %d: Invalid value '%s'", \
4157 line, pos); \
4158 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004159 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004160 PARSE_TEST_PROBABILITY(ignore_probe_probability)
4161 PARSE_TEST_PROBABILITY(ignore_auth_probability)
4162 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
4163 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
4164 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004165 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
4166 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004167 } else if (os_strcmp(buf, "bss_load_test") == 0) {
4168 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
4169 pos = os_strchr(pos, ':');
4170 if (pos == NULL) {
4171 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4172 line);
4173 return 1;
4174 }
4175 pos++;
4176 bss->bss_load_test[2] = atoi(pos);
4177 pos = os_strchr(pos, ':');
4178 if (pos == NULL) {
4179 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
4180 line);
4181 return 1;
4182 }
4183 pos++;
4184 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
4185 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004186 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004187 /*
4188 * DEPRECATED: This parameter will be removed in the future.
4189 * Use rrm_neighbor_report instead.
4190 */
4191 int val = atoi(pos);
4192
4193 if (val & BIT(0))
4194 bss->radio_measurements[0] |=
4195 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004196 } else if (os_strcmp(buf, "own_ie_override") == 0) {
4197 struct wpabuf *tmp;
4198 size_t len = os_strlen(pos) / 2;
4199
4200 tmp = wpabuf_alloc(len);
4201 if (!tmp)
4202 return 1;
4203
4204 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
4205 wpabuf_free(tmp);
4206 wpa_printf(MSG_ERROR,
4207 "Line %d: Invalid own_ie_override '%s'",
4208 line, pos);
4209 return 1;
4210 }
4211
4212 wpabuf_free(bss->own_ie_override);
4213 bss->own_ie_override = tmp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004214 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
4215 bss->sae_reflection_attack = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004216 } else if (os_strcmp(buf, "sae_commit_status") == 0) {
4217 bss->sae_commit_status = atoi(pos);
4218 } else if (os_strcmp(buf, "sae_pk_omit") == 0) {
4219 bss->sae_pk_omit = atoi(pos);
4220 } else if (os_strcmp(buf, "sae_pk_password_check_skip") == 0) {
4221 bss->sae_pk_password_check_skip = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004222 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
4223 wpabuf_free(bss->sae_commit_override);
4224 bss->sae_commit_override = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004225 } else if (os_strcmp(buf, "rsne_override_eapol") == 0) {
4226 wpabuf_free(bss->rsne_override_eapol);
4227 bss->rsne_override_eapol = wpabuf_parse_bin(pos);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004228 } else if (os_strcmp(buf, "rsnxe_override_eapol") == 0) {
4229 wpabuf_free(bss->rsnxe_override_eapol);
4230 bss->rsnxe_override_eapol = wpabuf_parse_bin(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004231 } else if (os_strcmp(buf, "rsne_override_ft") == 0) {
4232 wpabuf_free(bss->rsne_override_ft);
4233 bss->rsne_override_ft = wpabuf_parse_bin(pos);
4234 } else if (os_strcmp(buf, "rsnxe_override_ft") == 0) {
4235 wpabuf_free(bss->rsnxe_override_ft);
4236 bss->rsnxe_override_ft = wpabuf_parse_bin(pos);
4237 } else if (os_strcmp(buf, "gtk_rsc_override") == 0) {
4238 wpabuf_free(bss->gtk_rsc_override);
4239 bss->gtk_rsc_override = wpabuf_parse_bin(pos);
4240 } else if (os_strcmp(buf, "igtk_rsc_override") == 0) {
4241 wpabuf_free(bss->igtk_rsc_override);
4242 bss->igtk_rsc_override = wpabuf_parse_bin(pos);
4243 } else if (os_strcmp(buf, "no_beacon_rsnxe") == 0) {
4244 bss->no_beacon_rsnxe = atoi(pos);
4245 } else if (os_strcmp(buf, "skip_prune_assoc") == 0) {
4246 bss->skip_prune_assoc = atoi(pos);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004247 } else if (os_strcmp(buf, "ft_rsnxe_used") == 0) {
4248 bss->ft_rsnxe_used = atoi(pos);
Hai Shalom899fcc72020-10-19 14:38:18 -07004249 } else if (os_strcmp(buf, "oci_freq_override_eapol_m3") == 0) {
4250 bss->oci_freq_override_eapol_m3 = atoi(pos);
4251 } else if (os_strcmp(buf, "oci_freq_override_eapol_g1") == 0) {
4252 bss->oci_freq_override_eapol_g1 = atoi(pos);
4253 } else if (os_strcmp(buf, "oci_freq_override_saquery_req") == 0) {
4254 bss->oci_freq_override_saquery_req = atoi(pos);
4255 } else if (os_strcmp(buf, "oci_freq_override_saquery_resp") == 0) {
4256 bss->oci_freq_override_saquery_resp = atoi(pos);
4257 } else if (os_strcmp(buf, "oci_freq_override_ft_assoc") == 0) {
4258 bss->oci_freq_override_ft_assoc = atoi(pos);
4259 } else if (os_strcmp(buf, "oci_freq_override_fils_assoc") == 0) {
4260 bss->oci_freq_override_fils_assoc = atoi(pos);
4261 } else if (os_strcmp(buf, "oci_freq_override_wnm_sleep") == 0) {
4262 bss->oci_freq_override_wnm_sleep = atoi(pos);
Kai Shie75b0652020-11-24 20:31:29 -08004263 } else if (os_strcmp(buf, "skip_send_eapol") == 0) {
4264 conf->skip_send_eapol = atoi(pos);
4265 } else if (os_strcmp(buf, "enable_eapol_large_timeout") == 0) {
4266 conf->enable_eapol_large_timeout = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004267 } else if (os_strcmp(buf, "eap_skip_prot_success") == 0) {
4268 bss->eap_skip_prot_success = atoi(pos);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004269#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004270#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004271 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004272 if (parse_sae_password(bss, pos) < 0) {
4273 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
4274 line);
4275 return 1;
4276 }
4277#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004278 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004279 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004280 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004281 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
4282 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004283 return 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08004284 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0 ||
4285 os_strcmp(buf, "anti_clogging_threshold") == 0) {
4286 bss->anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004287 } else if (os_strcmp(buf, "sae_sync") == 0) {
4288 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004289 } else if (os_strcmp(buf, "sae_groups") == 0) {
4290 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
4291 wpa_printf(MSG_ERROR,
4292 "Line %d: Invalid sae_groups value '%s'",
4293 line, pos);
4294 return 1;
4295 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004296 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
4297 bss->sae_require_mfp = atoi(pos);
Hai Shalomc3565922019-10-28 11:58:20 -07004298 } else if (os_strcmp(buf, "sae_confirm_immediate") == 0) {
4299 bss->sae_confirm_immediate = atoi(pos);
4300 } else if (os_strcmp(buf, "sae_pwe") == 0) {
4301 bss->sae_pwe = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004302 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
4303 int val = atoi(pos);
4304 if (val < 0 || val > 255) {
4305 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
4306 line, val);
4307 return 1;
4308 }
4309 conf->local_pwr_constraint = val;
4310 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
4311 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07004312 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
4313 os_free(bss->wowlan_triggers);
4314 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004315#ifdef CONFIG_FST
4316 } else if (os_strcmp(buf, "fst_group_id") == 0) {
4317 size_t len = os_strlen(pos);
4318
4319 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
4320 wpa_printf(MSG_ERROR,
4321 "Line %d: Invalid fst_group_id value '%s'",
4322 line, pos);
4323 return 1;
4324 }
4325
4326 if (conf->fst_cfg.group_id[0]) {
4327 wpa_printf(MSG_ERROR,
4328 "Line %d: Duplicate fst_group value '%s'",
4329 line, pos);
4330 return 1;
4331 }
4332
4333 os_strlcpy(conf->fst_cfg.group_id, pos,
4334 sizeof(conf->fst_cfg.group_id));
4335 } else if (os_strcmp(buf, "fst_priority") == 0) {
4336 char *endp;
4337 long int val;
4338
4339 if (!*pos) {
4340 wpa_printf(MSG_ERROR,
4341 "Line %d: fst_priority value not supplied (expected 1..%u)",
4342 line, FST_MAX_PRIO_VALUE);
4343 return -1;
4344 }
4345
4346 val = strtol(pos, &endp, 0);
4347 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
4348 wpa_printf(MSG_ERROR,
4349 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
4350 line, val, pos, FST_MAX_PRIO_VALUE);
4351 return 1;
4352 }
4353 conf->fst_cfg.priority = (u8) val;
4354 } else if (os_strcmp(buf, "fst_llt") == 0) {
4355 char *endp;
4356 long int val;
4357
4358 if (!*pos) {
4359 wpa_printf(MSG_ERROR,
4360 "Line %d: fst_llt value not supplied (expected 1..%u)",
4361 line, FST_MAX_LLT_MS);
4362 return -1;
4363 }
4364 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07004365 if (*endp || val < 1 ||
4366 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004367 wpa_printf(MSG_ERROR,
4368 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
4369 line, val, pos, FST_MAX_LLT_MS);
4370 return 1;
4371 }
4372 conf->fst_cfg.llt = (u32) val;
4373#endif /* CONFIG_FST */
4374 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
4375 conf->track_sta_max_num = atoi(pos);
4376 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
4377 conf->track_sta_max_age = atoi(pos);
4378 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
4379 os_free(bss->no_probe_resp_if_seen_on);
4380 bss->no_probe_resp_if_seen_on = os_strdup(pos);
4381 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
4382 os_free(bss->no_auth_if_seen_on);
4383 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004384 } else if (os_strcmp(buf, "lci") == 0) {
4385 wpabuf_free(conf->lci);
4386 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004387 if (conf->lci && wpabuf_len(conf->lci) == 0) {
4388 wpabuf_free(conf->lci);
4389 conf->lci = NULL;
4390 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004391 } else if (os_strcmp(buf, "civic") == 0) {
4392 wpabuf_free(conf->civic);
4393 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004394 if (conf->civic && wpabuf_len(conf->civic) == 0) {
4395 wpabuf_free(conf->civic);
4396 conf->civic = NULL;
4397 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004398 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
4399 if (atoi(pos))
4400 bss->radio_measurements[0] |=
4401 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004402 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
4403 if (atoi(pos))
4404 bss->radio_measurements[0] |=
4405 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4406 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4407 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004408 } else if (os_strcmp(buf, "gas_address3") == 0) {
4409 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004410 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4411 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004412 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4413 bss->ftm_responder = atoi(pos);
4414 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4415 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004416#ifdef CONFIG_FILS
4417 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4418 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4419 wpa_printf(MSG_ERROR,
4420 "Line %d: Invalid fils_cache_id '%s'",
4421 line, pos);
4422 return 1;
4423 }
4424 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004425 } else if (os_strcmp(buf, "fils_realm") == 0) {
4426 if (parse_fils_realm(bss, pos) < 0)
4427 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004428 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4429 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004430 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4431 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4432 wpa_printf(MSG_ERROR,
4433 "Line %d: invalid IP address '%s'",
4434 line, pos);
4435 return 1;
4436 }
4437 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4438 bss->dhcp_rapid_commit_proxy = atoi(pos);
4439 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4440 bss->fils_hlp_wait_time = atoi(pos);
4441 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4442 bss->dhcp_server_port = atoi(pos);
4443 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4444 bss->dhcp_relay_port = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004445 } else if (os_strcmp(buf, "fils_discovery_min_interval") == 0) {
4446 bss->fils_discovery_min_int = atoi(pos);
4447 } else if (os_strcmp(buf, "fils_discovery_max_interval") == 0) {
4448 bss->fils_discovery_max_int = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004449#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004450 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4451 bss->multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004452 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4453 bss->broadcast_deauth = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004454 } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
4455 bss->notify_mgmt_frames = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004456#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07004457 } else if (os_strcmp(buf, "dpp_name") == 0) {
4458 os_free(bss->dpp_name);
4459 bss->dpp_name = os_strdup(pos);
4460 } else if (os_strcmp(buf, "dpp_mud_url") == 0) {
4461 os_free(bss->dpp_mud_url);
4462 bss->dpp_mud_url = os_strdup(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004463 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4464 os_free(bss->dpp_connector);
4465 bss->dpp_connector = os_strdup(pos);
4466 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4467 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4468 return 1;
4469 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4470 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4471 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4472 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4473 return 1;
Hai Shalom81f62d82019-07-22 12:10:00 -07004474#ifdef CONFIG_DPP2
4475 } else if (os_strcmp(buf, "dpp_controller") == 0) {
4476 if (hostapd_dpp_controller_parse(bss, pos))
4477 return 1;
Hai Shalomfdcde762020-04-02 11:19:20 -07004478 } else if (os_strcmp(buf, "dpp_configurator_connectivity") == 0) {
4479 bss->dpp_configurator_connectivity = atoi(pos);
4480 } else if (os_strcmp(buf, "dpp_pfs") == 0) {
4481 int val = atoi(pos);
4482
4483 if (val < 0 || val > 2) {
4484 wpa_printf(MSG_ERROR,
4485 "Line %d: Invalid dpp_pfs value '%s'",
4486 line, pos);
4487 return -1;
4488 }
4489 bss->dpp_pfs = val;
Hai Shalom81f62d82019-07-22 12:10:00 -07004490#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004491#endif /* CONFIG_DPP */
4492#ifdef CONFIG_OWE
4493 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4494 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4495 wpa_printf(MSG_ERROR,
4496 "Line %d: invalid owe_transition_bssid",
4497 line);
4498 return 1;
4499 }
4500 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4501 size_t slen;
4502 char *str = wpa_config_parse_string(pos, &slen);
4503
4504 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4505 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4506 line, pos);
4507 os_free(str);
4508 return 1;
4509 }
4510 os_memcpy(bss->owe_transition_ssid, str, slen);
4511 bss->owe_transition_ssid_len = slen;
4512 os_free(str);
4513 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4514 os_strlcpy(bss->owe_transition_ifname, pos,
4515 sizeof(bss->owe_transition_ifname));
4516 } else if (os_strcmp(buf, "owe_groups") == 0) {
4517 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4518 wpa_printf(MSG_ERROR,
4519 "Line %d: Invalid owe_groups value '%s'",
4520 line, pos);
4521 return 1;
4522 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004523 } else if (os_strcmp(buf, "owe_ptk_workaround") == 0) {
4524 bss->owe_ptk_workaround = atoi(pos);
4525#endif /* CONFIG_OWE */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004526 } else if (os_strcmp(buf, "coloc_intf_reporting") == 0) {
4527 bss->coloc_intf_reporting = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004528 } else if (os_strcmp(buf, "multi_ap") == 0) {
4529 int val = atoi(pos);
4530
4531 if (val < 0 || val > 3) {
4532 wpa_printf(MSG_ERROR, "Line %d: Invalid multi_ap '%s'",
4533 line, buf);
4534 return -1;
4535 }
4536
4537 bss->multi_ap = val;
4538 } else if (os_strcmp(buf, "rssi_reject_assoc_rssi") == 0) {
4539 conf->rssi_reject_assoc_rssi = atoi(pos);
4540 } else if (os_strcmp(buf, "rssi_reject_assoc_timeout") == 0) {
4541 conf->rssi_reject_assoc_timeout = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004542 } else if (os_strcmp(buf, "rssi_ignore_probe_request") == 0) {
4543 conf->rssi_ignore_probe_request = atoi(pos);
Hai Shalom74f70d42019-02-11 14:42:39 -08004544 } else if (os_strcmp(buf, "pbss") == 0) {
4545 bss->pbss = atoi(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -07004546 } else if (os_strcmp(buf, "transition_disable") == 0) {
4547 bss->transition_disable = strtol(pos, NULL, 16);
Hai Shalom81f62d82019-07-22 12:10:00 -07004548#ifdef CONFIG_AIRTIME_POLICY
4549 } else if (os_strcmp(buf, "airtime_mode") == 0) {
4550 int val = atoi(pos);
4551
4552 if (val < 0 || val > AIRTIME_MODE_MAX) {
4553 wpa_printf(MSG_ERROR, "Line %d: Unknown airtime_mode",
4554 line);
4555 return 1;
4556 }
4557 conf->airtime_mode = val;
4558 } else if (os_strcmp(buf, "airtime_update_interval") == 0) {
4559 conf->airtime_update_interval = atoi(pos);
4560 } else if (os_strcmp(buf, "airtime_bss_weight") == 0) {
4561 bss->airtime_weight = atoi(pos);
4562 } else if (os_strcmp(buf, "airtime_bss_limit") == 0) {
4563 int val = atoi(pos);
4564
4565 if (val < 0 || val > 1) {
4566 wpa_printf(MSG_ERROR,
4567 "Line %d: Invalid airtime_bss_limit (must be 0 or 1)",
4568 line);
4569 return 1;
4570 }
4571 bss->airtime_limit = val;
4572 } else if (os_strcmp(buf, "airtime_sta_weight") == 0) {
4573 if (add_airtime_weight(bss, pos) < 0) {
4574 wpa_printf(MSG_ERROR,
4575 "Line %d: Invalid airtime weight '%s'",
4576 line, pos);
4577 return 1;
4578 }
4579#endif /* CONFIG_AIRTIME_POLICY */
4580#ifdef CONFIG_MACSEC
4581 } else if (os_strcmp(buf, "macsec_policy") == 0) {
4582 int macsec_policy = atoi(pos);
4583
4584 if (macsec_policy < 0 || macsec_policy > 1) {
4585 wpa_printf(MSG_ERROR,
4586 "Line %d: invalid macsec_policy (%d): '%s'.",
4587 line, macsec_policy, pos);
4588 return 1;
4589 }
4590 bss->macsec_policy = macsec_policy;
4591 } else if (os_strcmp(buf, "macsec_integ_only") == 0) {
4592 int macsec_integ_only = atoi(pos);
4593
4594 if (macsec_integ_only < 0 || macsec_integ_only > 1) {
4595 wpa_printf(MSG_ERROR,
4596 "Line %d: invalid macsec_integ_only (%d): '%s'.",
4597 line, macsec_integ_only, pos);
4598 return 1;
4599 }
4600 bss->macsec_integ_only = macsec_integ_only;
4601 } else if (os_strcmp(buf, "macsec_replay_protect") == 0) {
4602 int macsec_replay_protect = atoi(pos);
4603
4604 if (macsec_replay_protect < 0 || macsec_replay_protect > 1) {
4605 wpa_printf(MSG_ERROR,
4606 "Line %d: invalid macsec_replay_protect (%d): '%s'.",
4607 line, macsec_replay_protect, pos);
4608 return 1;
4609 }
4610 bss->macsec_replay_protect = macsec_replay_protect;
4611 } else if (os_strcmp(buf, "macsec_replay_window") == 0) {
4612 bss->macsec_replay_window = atoi(pos);
4613 } else if (os_strcmp(buf, "macsec_port") == 0) {
4614 int macsec_port = atoi(pos);
4615
4616 if (macsec_port < 1 || macsec_port > 65534) {
4617 wpa_printf(MSG_ERROR,
4618 "Line %d: invalid macsec_port (%d): '%s'.",
4619 line, macsec_port, pos);
4620 return 1;
4621 }
4622 bss->macsec_port = macsec_port;
4623 } else if (os_strcmp(buf, "mka_priority") == 0) {
4624 int mka_priority = atoi(pos);
4625
4626 if (mka_priority < 0 || mka_priority > 255) {
4627 wpa_printf(MSG_ERROR,
4628 "Line %d: invalid mka_priority (%d): '%s'.",
4629 line, mka_priority, pos);
4630 return 1;
4631 }
4632 bss->mka_priority = mka_priority;
Sunil Ravia04bd252022-05-02 22:54:18 -07004633 } else if (os_strcmp(buf, "macsec_csindex") == 0) {
4634 int macsec_csindex = atoi(pos);
4635
4636 if (macsec_csindex < 0 || macsec_csindex > 1) {
4637 wpa_printf(MSG_ERROR,
4638 "Line %d: invalid macsec_csindex (%d): '%s'.",
4639 line, macsec_csindex, pos);
4640 return 1;
4641 }
4642 bss->macsec_csindex = macsec_csindex;
Hai Shalom81f62d82019-07-22 12:10:00 -07004643 } else if (os_strcmp(buf, "mka_cak") == 0) {
4644 size_t len = os_strlen(pos);
4645
4646 if (len > 2 * MACSEC_CAK_MAX_LEN ||
4647 (len != 2 * 16 && len != 2 * 32) ||
4648 hexstr2bin(pos, bss->mka_cak, len / 2)) {
4649 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.",
4650 line, pos);
4651 return 1;
4652 }
4653 bss->mka_cak_len = len / 2;
4654 bss->mka_psk_set |= MKA_PSK_SET_CAK;
4655 } else if (os_strcmp(buf, "mka_ckn") == 0) {
4656 size_t len = os_strlen(pos);
4657
4658 if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */
4659 len < 2 || /* too short */
4660 len % 2 != 0 /* not an integral number of bytes */) {
4661 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4662 line, pos);
4663 return 1;
4664 }
4665 bss->mka_ckn_len = len / 2;
4666 if (hexstr2bin(pos, bss->mka_ckn, bss->mka_ckn_len)) {
4667 wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.",
4668 line, pos);
4669 return -1;
4670 }
4671 bss->mka_psk_set |= MKA_PSK_SET_CKN;
4672#endif /* CONFIG_MACSEC */
Hai Shalom60840252021-02-19 19:02:11 -08004673 } else if (os_strcmp(buf, "disable_11n") == 0) {
4674 bss->disable_11n = !!atoi(pos);
4675 } else if (os_strcmp(buf, "disable_11ac") == 0) {
4676 bss->disable_11ac = !!atoi(pos);
4677 } else if (os_strcmp(buf, "disable_11ax") == 0) {
4678 bss->disable_11ax = !!atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004679 } else if (os_strcmp(buf, "disable_11be") == 0) {
4680 bss->disable_11be = !!atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004681#ifdef CONFIG_PASN
4682#ifdef CONFIG_TESTING_OPTIONS
4683 } else if (os_strcmp(buf, "force_kdk_derivation") == 0) {
4684 bss->force_kdk_derivation = atoi(pos);
Hai Shaloma20dcd72022-02-04 13:43:00 -08004685 } else if (os_strcmp(buf, "pasn_corrupt_mic") == 0) {
4686 bss->pasn_corrupt_mic = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004687#endif /* CONFIG_TESTING_OPTIONS */
4688 } else if (os_strcmp(buf, "pasn_groups") == 0) {
4689 if (hostapd_parse_intlist(&bss->pasn_groups, pos)) {
4690 wpa_printf(MSG_ERROR,
4691 "Line %d: Invalid pasn_groups value '%s'",
4692 line, pos);
4693 return 1;
4694 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08004695 } else if (os_strcmp(buf, "pasn_comeback_after") == 0) {
4696 bss->pasn_comeback_after = atoi(pos);
Hai Shalom60840252021-02-19 19:02:11 -08004697#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -08004698 } else if (os_strcmp(buf, "ext_capa_mask") == 0) {
4699 if (get_hex_config(bss->ext_capa_mask, EXT_CAPA_MAX_LEN,
4700 line, "ext_capa_mask", pos))
4701 return 1;
4702 } else if (os_strcmp(buf, "ext_capa") == 0) {
4703 if (get_hex_config(bss->ext_capa, EXT_CAPA_MAX_LEN,
4704 line, "ext_capa", pos))
4705 return 1;
4706 } else if (os_strcmp(buf, "rnr") == 0) {
4707 bss->rnr = atoi(pos);
Sunil Ravia04bd252022-05-02 22:54:18 -07004708#ifdef CONFIG_IEEE80211BE
4709 } else if (os_strcmp(buf, "ieee80211be") == 0) {
4710 conf->ieee80211be = atoi(pos);
4711 } else if (os_strcmp(buf, "eht_oper_chwidth") == 0) {
4712 conf->eht_oper_chwidth = atoi(pos);
4713 } else if (os_strcmp(buf, "eht_oper_centr_freq_seg0_idx") == 0) {
4714 conf->eht_oper_centr_freq_seg0_idx = atoi(pos);
4715 } else if (os_strcmp(buf, "eht_su_beamformer") == 0) {
4716 conf->eht_phy_capab.su_beamformer = atoi(pos);
4717 } else if (os_strcmp(buf, "eht_su_beamformee") == 0) {
4718 conf->eht_phy_capab.su_beamformee = atoi(pos);
4719 } else if (os_strcmp(buf, "eht_mu_beamformer") == 0) {
4720 conf->eht_phy_capab.mu_beamformer = atoi(pos);
4721#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004722 } else {
4723 wpa_printf(MSG_ERROR,
4724 "Line %d: unknown configuration item '%s'",
4725 line, buf);
4726 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004727 }
4728
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004729 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004730}
4731
4732
Dmitry Shmidt04949592012-07-19 12:16:46 -07004733/**
4734 * hostapd_config_read - Read and parse a configuration file
4735 * @fname: Configuration file name (including path, if needed)
4736 * Returns: Allocated configuration data structure
4737 */
4738struct hostapd_config * hostapd_config_read(const char *fname)
4739{
4740 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004741 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004742 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004743 int line = 0;
4744 int errors = 0;
4745 size_t i;
4746
4747 f = fopen(fname, "r");
4748 if (f == NULL) {
4749 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4750 "for reading.", fname);
4751 return NULL;
4752 }
4753
4754 conf = hostapd_config_defaults();
4755 if (conf == NULL) {
4756 fclose(f);
4757 return NULL;
4758 }
4759
4760 /* set default driver based on configuration */
4761 conf->driver = wpa_drivers[0];
4762 if (conf->driver == NULL) {
4763 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4764 hostapd_config_free(conf);
4765 fclose(f);
4766 return NULL;
4767 }
4768
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004769 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004770
4771 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004772 struct hostapd_bss_config *bss;
4773
Dmitry Shmidt04949592012-07-19 12:16:46 -07004774 bss = conf->last_bss;
4775 line++;
4776
4777 if (buf[0] == '#')
4778 continue;
4779 pos = buf;
4780 while (*pos != '\0') {
4781 if (*pos == '\n') {
4782 *pos = '\0';
4783 break;
4784 }
4785 pos++;
4786 }
4787 if (buf[0] == '\0')
4788 continue;
4789
4790 pos = os_strchr(buf, '=');
4791 if (pos == NULL) {
4792 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4793 line, buf);
4794 errors++;
4795 continue;
4796 }
4797 *pos = '\0';
4798 pos++;
4799 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4800 }
4801
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802 fclose(f);
4803
Dmitry Shmidt04949592012-07-19 12:16:46 -07004804 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004805 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004806
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004807 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004808 errors++;
4809
4810#ifndef WPA_IGNORE_CONFIG_ERRORS
4811 if (errors) {
4812 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4813 "'%s'", errors, fname);
4814 hostapd_config_free(conf);
4815 conf = NULL;
4816 }
4817#endif /* WPA_IGNORE_CONFIG_ERRORS */
4818
4819 return conf;
4820}
Dmitry Shmidt04949592012-07-19 12:16:46 -07004821
4822
4823int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004824 struct hostapd_bss_config *bss, const char *field,
4825 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004826{
4827 int errors;
4828 size_t i;
4829
4830 errors = hostapd_config_fill(conf, bss, field, value, 0);
4831 if (errors) {
4832 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4833 "to value '%s'", field, value);
4834 return -1;
4835 }
4836
4837 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004838 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004839
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004840 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004841 wpa_printf(MSG_ERROR, "Configuration check failed");
4842 return -1;
4843 }
4844
4845 return 0;
4846}