blob: 37308dbcc1272c970d21a7cb1921089d9bb209e2 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10#ifndef CONFIG_NATIVE_WINDOWS
11#include <grp.h>
12#endif /* CONFIG_NATIVE_WINDOWS */
13
14#include "utils/common.h"
15#include "utils/uuid.h"
16#include "common/ieee802_11_defs.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070017#include "crypto/sha256.h"
18#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "drivers/driver.h"
20#include "eap_server/eap.h"
21#include "radius/radius_client.h"
22#include "ap/wpa_auth.h"
23#include "ap/ap_config.h"
24#include "config_file.h"
25
26
Dmitry Shmidt818ea482014-03-10 13:15:21 -070027#ifndef CONFIG_NO_RADIUS
28#ifdef EAP_SERVER
29static struct hostapd_radius_attr *
30hostapd_parse_radius_attr(const char *value);
31#endif /* EAP_SERVER */
32#endif /* CONFIG_NO_RADIUS */
33
34
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#ifndef CONFIG_NO_VLAN
36static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
37 const char *fname)
38{
39 FILE *f;
40 char buf[128], *pos, *pos2;
41 int line = 0, vlan_id;
42 struct hostapd_vlan *vlan;
43
44 f = fopen(fname, "r");
45 if (!f) {
46 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
47 return -1;
48 }
49
50 while (fgets(buf, sizeof(buf), f)) {
51 line++;
52
53 if (buf[0] == '#')
54 continue;
55 pos = buf;
56 while (*pos != '\0') {
57 if (*pos == '\n') {
58 *pos = '\0';
59 break;
60 }
61 pos++;
62 }
63 if (buf[0] == '\0')
64 continue;
65
66 if (buf[0] == '*') {
67 vlan_id = VLAN_ID_WILDCARD;
68 pos = buf + 1;
69 } else {
70 vlan_id = strtol(buf, &pos, 10);
71 if (buf == pos || vlan_id < 1 ||
72 vlan_id > MAX_VLAN_ID) {
73 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
74 "line %d in '%s'", line, fname);
75 fclose(f);
76 return -1;
77 }
78 }
79
80 while (*pos == ' ' || *pos == '\t')
81 pos++;
82 pos2 = pos;
83 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
84 pos2++;
85 *pos2 = '\0';
86 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
87 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
88 "in '%s'", line, fname);
89 fclose(f);
90 return -1;
91 }
92
Dmitry Shmidt4b060592013-04-29 16:42:49 -070093 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 if (vlan == NULL) {
95 wpa_printf(MSG_ERROR, "Out of memory while reading "
96 "VLAN interfaces from '%s'", fname);
97 fclose(f);
98 return -1;
99 }
100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700101 vlan->vlan_id = vlan_id;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800102 vlan->vlan_desc.untagged = vlan_id;
103 vlan->vlan_desc.notempty = !!vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700105 vlan->next = bss->vlan;
106 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107 }
108
109 fclose(f);
110
111 return 0;
112}
113#endif /* CONFIG_NO_VLAN */
114
115
Roshan Pius3a1667e2018-07-03 15:17:14 -0700116int hostapd_acl_comp(const void *a, const void *b)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700117{
118 const struct mac_acl_entry *aa = a;
119 const struct mac_acl_entry *bb = b;
120 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
121}
122
123
Roshan Pius3a1667e2018-07-03 15:17:14 -0700124int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
125 int vlan_id, const u8 *addr)
126{
127 struct mac_acl_entry *newacl;
128
129 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
130 if (!newacl) {
131 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
132 return -1;
133 }
134
135 *acl = newacl;
136 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
137 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
138 (*acl)[*num].vlan_id.untagged = vlan_id;
139 (*acl)[*num].vlan_id.notempty = !!vlan_id;
140 (*num)++;
141
142 return 0;
143}
144
145
146void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
147 const u8 *addr)
148{
149 int i = 0;
150
151 while (i < *num) {
152 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
153 os_remove_in_array(*acl, *num, sizeof(**acl), i);
154 (*num)--;
155 } else {
156 i++;
157 }
158 }
159}
160
161
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162static int hostapd_config_read_maclist(const char *fname,
163 struct mac_acl_entry **acl, int *num)
164{
165 FILE *f;
166 char buf[128], *pos;
167 int line = 0;
168 u8 addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 int vlan_id;
170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 f = fopen(fname, "r");
172 if (!f) {
173 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
174 return -1;
175 }
176
177 while (fgets(buf, sizeof(buf), f)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700178 int rem = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800179
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 line++;
181
182 if (buf[0] == '#')
183 continue;
184 pos = buf;
185 while (*pos != '\0') {
186 if (*pos == '\n') {
187 *pos = '\0';
188 break;
189 }
190 pos++;
191 }
192 if (buf[0] == '\0')
193 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800194 pos = buf;
195 if (buf[0] == '-') {
196 rem = 1;
197 pos++;
198 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800200 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700201 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800202 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 fclose(f);
204 return -1;
205 }
206
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800207 if (rem) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700208 hostapd_remove_acl_mac(acl, num, addr);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800209 continue;
210 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211 vlan_id = 0;
212 pos = buf;
213 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
214 pos++;
215 while (*pos == ' ' || *pos == '\t')
216 pos++;
217 if (*pos != '\0')
218 vlan_id = atoi(pos);
219
Roshan Pius3a1667e2018-07-03 15:17:14 -0700220 if (hostapd_add_acl_maclist(acl, num, vlan_id, addr) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 fclose(f);
222 return -1;
223 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 }
225
226 fclose(f);
227
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800228 if (*acl)
229 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230
231 return 0;
232}
233
234
235#ifdef EAP_SERVER
Roshan Pius3a1667e2018-07-03 15:17:14 -0700236
237static int hostapd_config_eap_user_salted(struct hostapd_eap_user *user,
238 const char *hash, size_t len,
239 char **pos, int line,
240 const char *fname)
241{
242 char *pos2 = *pos;
243
244 while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != '#')
245 pos2++;
246
247 if (pos2 - *pos < (int) (2 * (len + 1))) { /* at least 1 byte of salt */
248 wpa_printf(MSG_ERROR,
249 "Invalid salted %s hash on line %d in '%s'",
250 hash, line, fname);
251 return -1;
252 }
253
254 user->password = os_malloc(len);
255 if (!user->password) {
256 wpa_printf(MSG_ERROR,
257 "Failed to allocate memory for salted %s hash",
258 hash);
259 return -1;
260 }
261
262 if (hexstr2bin(*pos, user->password, len) < 0) {
263 wpa_printf(MSG_ERROR,
264 "Invalid salted password on line %d in '%s'",
265 line, fname);
266 return -1;
267 }
268 user->password_len = len;
269 *pos += 2 * len;
270
271 user->salt_len = (pos2 - *pos) / 2;
272 user->salt = os_malloc(user->salt_len);
273 if (!user->salt) {
274 wpa_printf(MSG_ERROR,
275 "Failed to allocate memory for salted %s hash",
276 hash);
277 return -1;
278 }
279
280 if (hexstr2bin(*pos, user->salt, user->salt_len) < 0) {
281 wpa_printf(MSG_ERROR,
282 "Invalid salt for password on line %d in '%s'",
283 line, fname);
284 return -1;
285 }
286
287 *pos = pos2;
288 return 0;
289}
290
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292static int hostapd_config_read_eap_user(const char *fname,
293 struct hostapd_bss_config *conf)
294{
295 FILE *f;
296 char buf[512], *pos, *start, *pos2;
297 int line = 0, ret = 0, num_methods;
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800298 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800300 if (os_strncmp(fname, "sqlite:", 7) == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700301#ifdef CONFIG_SQLITE
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800302 os_free(conf->eap_user_sqlite);
303 conf->eap_user_sqlite = os_strdup(fname + 7);
304 return 0;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700305#else /* CONFIG_SQLITE */
306 wpa_printf(MSG_ERROR,
307 "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build.");
308 return -1;
309#endif /* CONFIG_SQLITE */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800310 }
311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 f = fopen(fname, "r");
313 if (!f) {
314 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
315 return -1;
316 }
317
318 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
319 while (fgets(buf, sizeof(buf), f)) {
320 line++;
321
322 if (buf[0] == '#')
323 continue;
324 pos = buf;
325 while (*pos != '\0') {
326 if (*pos == '\n') {
327 *pos = '\0';
328 break;
329 }
330 pos++;
331 }
332 if (buf[0] == '\0')
333 continue;
334
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700335#ifndef CONFIG_NO_RADIUS
336 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
337 struct hostapd_radius_attr *attr, *a;
338 attr = hostapd_parse_radius_attr(buf + 19);
339 if (attr == NULL) {
340 wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
341 buf + 19);
Dmitry Shmidt98660862014-03-11 17:26:21 -0700342 user = NULL; /* already in the BSS list */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700343 goto failed;
344 }
345 if (user->accept_attr == NULL) {
346 user->accept_attr = attr;
347 } else {
348 a = user->accept_attr;
349 while (a->next)
350 a = a->next;
351 a->next = attr;
352 }
353 continue;
354 }
355#endif /* CONFIG_NO_RADIUS */
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 user = NULL;
358
359 if (buf[0] != '"' && buf[0] != '*') {
360 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
361 "start) on line %d in '%s'", line, fname);
362 goto failed;
363 }
364
365 user = os_zalloc(sizeof(*user));
366 if (user == NULL) {
367 wpa_printf(MSG_ERROR, "EAP user allocation failed");
368 goto failed;
369 }
370 user->force_version = -1;
371
372 if (buf[0] == '*') {
373 pos = buf;
374 } else {
375 pos = buf + 1;
376 start = pos;
377 while (*pos != '"' && *pos != '\0')
378 pos++;
379 if (*pos == '\0') {
380 wpa_printf(MSG_ERROR, "Invalid EAP identity "
381 "(no \" in end) on line %d in '%s'",
382 line, fname);
383 goto failed;
384 }
385
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700386 user->identity = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 if (user->identity == NULL) {
388 wpa_printf(MSG_ERROR, "Failed to allocate "
389 "memory for EAP identity");
390 goto failed;
391 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 user->identity_len = pos - start;
393
394 if (pos[0] == '"' && pos[1] == '*') {
395 user->wildcard_prefix = 1;
396 pos++;
397 }
398 }
399 pos++;
400 while (*pos == ' ' || *pos == '\t')
401 pos++;
402
403 if (*pos == '\0') {
404 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
405 "'%s'", line, fname);
406 goto failed;
407 }
408
409 start = pos;
410 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
411 pos++;
412 if (*pos == '\0') {
413 pos = NULL;
414 } else {
415 *pos = '\0';
416 pos++;
417 }
418 num_methods = 0;
419 while (*start) {
420 char *pos3 = os_strchr(start, ',');
421 if (pos3) {
422 *pos3++ = '\0';
423 }
424 user->methods[num_methods].method =
425 eap_server_get_type(
426 start,
427 &user->methods[num_methods].vendor);
428 if (user->methods[num_methods].vendor ==
429 EAP_VENDOR_IETF &&
430 user->methods[num_methods].method == EAP_TYPE_NONE)
431 {
432 if (os_strcmp(start, "TTLS-PAP") == 0) {
433 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
434 goto skip_eap;
435 }
436 if (os_strcmp(start, "TTLS-CHAP") == 0) {
437 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
438 goto skip_eap;
439 }
440 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
441 user->ttls_auth |=
442 EAP_TTLS_AUTH_MSCHAP;
443 goto skip_eap;
444 }
445 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
446 user->ttls_auth |=
447 EAP_TTLS_AUTH_MSCHAPV2;
448 goto skip_eap;
449 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700450 if (os_strcmp(start, "MACACL") == 0) {
451 user->macacl = 1;
452 goto skip_eap;
453 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 wpa_printf(MSG_ERROR, "Unsupported EAP type "
455 "'%s' on line %d in '%s'",
456 start, line, fname);
457 goto failed;
458 }
459
460 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800461 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700462 break;
463 skip_eap:
464 if (pos3 == NULL)
465 break;
466 start = pos3;
467 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700468 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 wpa_printf(MSG_ERROR, "No EAP types configured on "
470 "line %d in '%s'", line, fname);
471 goto failed;
472 }
473
474 if (pos == NULL)
475 goto done;
476
477 while (*pos == ' ' || *pos == '\t')
478 pos++;
479 if (*pos == '\0')
480 goto done;
481
482 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
483 user->force_version = 0;
484 goto done;
485 }
486
487 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
488 user->force_version = 1;
489 goto done;
490 }
491
492 if (os_strncmp(pos, "[2]", 3) == 0) {
493 user->phase2 = 1;
494 goto done;
495 }
496
497 if (*pos == '"') {
498 pos++;
499 start = pos;
500 while (*pos != '"' && *pos != '\0')
501 pos++;
502 if (*pos == '\0') {
503 wpa_printf(MSG_ERROR, "Invalid EAP password "
504 "(no \" in end) on line %d in '%s'",
505 line, fname);
506 goto failed;
507 }
508
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700509 user->password = os_memdup(start, pos - start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510 if (user->password == NULL) {
511 wpa_printf(MSG_ERROR, "Failed to allocate "
512 "memory for EAP password");
513 goto failed;
514 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 user->password_len = pos - start;
516
517 pos++;
518 } else if (os_strncmp(pos, "hash:", 5) == 0) {
519 pos += 5;
520 pos2 = pos;
521 while (*pos2 != '\0' && *pos2 != ' ' &&
522 *pos2 != '\t' && *pos2 != '#')
523 pos2++;
524 if (pos2 - pos != 32) {
525 wpa_printf(MSG_ERROR, "Invalid password hash "
526 "on line %d in '%s'", line, fname);
527 goto failed;
528 }
529 user->password = os_malloc(16);
530 if (user->password == NULL) {
531 wpa_printf(MSG_ERROR, "Failed to allocate "
532 "memory for EAP password hash");
533 goto failed;
534 }
535 if (hexstr2bin(pos, user->password, 16) < 0) {
536 wpa_printf(MSG_ERROR, "Invalid hash password "
537 "on line %d in '%s'", line, fname);
538 goto failed;
539 }
540 user->password_len = 16;
541 user->password_hash = 1;
542 pos = pos2;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700543 } else if (os_strncmp(pos, "ssha1:", 6) == 0) {
544 pos += 6;
545 if (hostapd_config_eap_user_salted(user, "sha1", 20,
546 &pos,
547 line, fname) < 0)
548 goto failed;
549 } else if (os_strncmp(pos, "ssha256:", 8) == 0) {
550 pos += 8;
551 if (hostapd_config_eap_user_salted(user, "sha256", 32,
552 &pos,
553 line, fname) < 0)
554 goto failed;
555 } else if (os_strncmp(pos, "ssha512:", 8) == 0) {
556 pos += 8;
557 if (hostapd_config_eap_user_salted(user, "sha512", 64,
558 &pos,
559 line, fname) < 0)
560 goto failed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 } else {
562 pos2 = pos;
563 while (*pos2 != '\0' && *pos2 != ' ' &&
564 *pos2 != '\t' && *pos2 != '#')
565 pos2++;
566 if ((pos2 - pos) & 1) {
567 wpa_printf(MSG_ERROR, "Invalid hex password "
568 "on line %d in '%s'", line, fname);
569 goto failed;
570 }
571 user->password = os_malloc((pos2 - pos) / 2);
572 if (user->password == NULL) {
573 wpa_printf(MSG_ERROR, "Failed to allocate "
574 "memory for EAP password");
575 goto failed;
576 }
577 if (hexstr2bin(pos, user->password,
578 (pos2 - pos) / 2) < 0) {
579 wpa_printf(MSG_ERROR, "Invalid hex password "
580 "on line %d in '%s'", line, fname);
581 goto failed;
582 }
583 user->password_len = (pos2 - pos) / 2;
584 pos = pos2;
585 }
586
587 while (*pos == ' ' || *pos == '\t')
588 pos++;
589 if (os_strncmp(pos, "[2]", 3) == 0) {
590 user->phase2 = 1;
591 }
592
593 done:
594 if (tail == NULL) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800595 tail = new_user = user;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 } else {
597 tail->next = user;
598 tail = user;
599 }
600 continue;
601
602 failed:
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700603 if (user)
604 hostapd_config_free_eap_user(user);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 ret = -1;
606 break;
607 }
608
609 fclose(f);
610
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800611 if (ret == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800612 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800613 conf->eap_user = new_user;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800614 } else {
615 hostapd_config_free_eap_users(new_user);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800616 }
617
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618 return ret;
619}
Roshan Pius3a1667e2018-07-03 15:17:14 -0700620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621#endif /* EAP_SERVER */
622
623
624#ifndef CONFIG_NO_RADIUS
625static int
626hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
627 int *num_server, const char *val, int def_port,
628 struct hostapd_radius_server **curr_serv)
629{
630 struct hostapd_radius_server *nserv;
631 int ret;
632 static int server_index = 1;
633
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700634 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 if (nserv == NULL)
636 return -1;
637
638 *server = nserv;
639 nserv = &nserv[*num_server];
640 (*num_server)++;
641 (*curr_serv) = nserv;
642
643 os_memset(nserv, 0, sizeof(*nserv));
644 nserv->port = def_port;
645 ret = hostapd_parse_ip_addr(val, &nserv->addr);
646 nserv->index = server_index++;
647
648 return ret;
649}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700650
651
652static struct hostapd_radius_attr *
653hostapd_parse_radius_attr(const char *value)
654{
655 const char *pos;
656 char syntax;
657 struct hostapd_radius_attr *attr;
658 size_t len;
659
660 attr = os_zalloc(sizeof(*attr));
661 if (attr == NULL)
662 return NULL;
663
664 attr->type = atoi(value);
665
666 pos = os_strchr(value, ':');
667 if (pos == NULL) {
668 attr->val = wpabuf_alloc(1);
669 if (attr->val == NULL) {
670 os_free(attr);
671 return NULL;
672 }
673 wpabuf_put_u8(attr->val, 0);
674 return attr;
675 }
676
677 pos++;
678 if (pos[0] == '\0' || pos[1] != ':') {
679 os_free(attr);
680 return NULL;
681 }
682 syntax = *pos++;
683 pos++;
684
685 switch (syntax) {
686 case 's':
687 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
688 break;
689 case 'x':
690 len = os_strlen(pos);
691 if (len & 1)
692 break;
693 len /= 2;
694 attr->val = wpabuf_alloc(len);
695 if (attr->val == NULL)
696 break;
697 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
698 wpabuf_free(attr->val);
699 os_free(attr);
700 return NULL;
701 }
702 break;
703 case 'd':
704 attr->val = wpabuf_alloc(4);
705 if (attr->val)
706 wpabuf_put_be32(attr->val, atoi(pos));
707 break;
708 default:
709 os_free(attr);
710 return NULL;
711 }
712
713 if (attr->val == NULL) {
714 os_free(attr);
715 return NULL;
716 }
717
718 return attr;
719}
720
721
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700722static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700723{
724 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700725
726 secret = os_strchr(val, ' ');
727 if (secret == NULL)
728 return -1;
729
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700730 *secret++ = '\0';
Dmitry Shmidt04949592012-07-19 12:16:46 -0700731
732 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
733 return -1;
734
735 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700736 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700737 if (bss->radius_das_shared_secret == NULL)
738 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700739 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700740
741 return 0;
742}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743#endif /* CONFIG_NO_RADIUS */
744
745
746static int hostapd_config_parse_key_mgmt(int line, const char *value)
747{
748 int val = 0, last;
749 char *start, *end, *buf;
750
751 buf = os_strdup(value);
752 if (buf == NULL)
753 return -1;
754 start = buf;
755
756 while (*start != '\0') {
757 while (*start == ' ' || *start == '\t')
758 start++;
759 if (*start == '\0')
760 break;
761 end = start;
762 while (*end != ' ' && *end != '\t' && *end != '\0')
763 end++;
764 last = *end == '\0';
765 *end = '\0';
766 if (os_strcmp(start, "WPA-PSK") == 0)
767 val |= WPA_KEY_MGMT_PSK;
768 else if (os_strcmp(start, "WPA-EAP") == 0)
769 val |= WPA_KEY_MGMT_IEEE8021X;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800770#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 else if (os_strcmp(start, "FT-PSK") == 0)
772 val |= WPA_KEY_MGMT_FT_PSK;
773 else if (os_strcmp(start, "FT-EAP") == 0)
774 val |= WPA_KEY_MGMT_FT_IEEE8021X;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700775#ifdef CONFIG_SHA384
776 else if (os_strcmp(start, "FT-EAP-SHA384") == 0)
777 val |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
778#endif /* CONFIG_SHA384 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800779#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780#ifdef CONFIG_IEEE80211W
781 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
782 val |= WPA_KEY_MGMT_PSK_SHA256;
783 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
784 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
785#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800786#ifdef CONFIG_SAE
787 else if (os_strcmp(start, "SAE") == 0)
788 val |= WPA_KEY_MGMT_SAE;
789 else if (os_strcmp(start, "FT-SAE") == 0)
790 val |= WPA_KEY_MGMT_FT_SAE;
791#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800792#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800793 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
794 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800795#endif /* CONFIG_SUITEB */
796#ifdef CONFIG_SUITEB192
797 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
798 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
799#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800800#ifdef CONFIG_FILS
801 else if (os_strcmp(start, "FILS-SHA256") == 0)
802 val |= WPA_KEY_MGMT_FILS_SHA256;
803 else if (os_strcmp(start, "FILS-SHA384") == 0)
804 val |= WPA_KEY_MGMT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800805#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800806 else if (os_strcmp(start, "FT-FILS-SHA256") == 0)
807 val |= WPA_KEY_MGMT_FT_FILS_SHA256;
808 else if (os_strcmp(start, "FT-FILS-SHA384") == 0)
809 val |= WPA_KEY_MGMT_FT_FILS_SHA384;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800810#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800811#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700812#ifdef CONFIG_OWE
813 else if (os_strcmp(start, "OWE") == 0)
814 val |= WPA_KEY_MGMT_OWE;
815#endif /* CONFIG_OWE */
816#ifdef CONFIG_DPP
817 else if (os_strcmp(start, "DPP") == 0)
818 val |= WPA_KEY_MGMT_DPP;
819#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700820#ifdef CONFIG_HS20
821 else if (os_strcmp(start, "OSEN") == 0)
822 val |= WPA_KEY_MGMT_OSEN;
823#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 else {
825 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
826 line, start);
827 os_free(buf);
828 return -1;
829 }
830
831 if (last)
832 break;
833 start = end + 1;
834 }
835
836 os_free(buf);
837 if (val == 0) {
838 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
839 "configured.", line);
840 return -1;
841 }
842
843 return val;
844}
845
846
847static int hostapd_config_parse_cipher(int line, const char *value)
848{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800849 int val = wpa_parse_cipher(value);
850 if (val < 0) {
851 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
852 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 if (val == 0) {
856 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
857 line);
858 return -1;
859 }
860 return val;
861}
862
863
864static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
865 char *val)
866{
867 size_t len = os_strlen(val);
868
Dmitry Shmidt29333592017-01-09 12:27:11 -0800869 if (keyidx < 0 || keyidx > 3)
870 return -1;
871
872 if (len == 0) {
873 int i, set = 0;
874
875 bin_clear_free(wep->key[keyidx], wep->len[keyidx]);
876 wep->key[keyidx] = NULL;
877 wep->len[keyidx] = 0;
878 for (i = 0; i < NUM_WEP_KEYS; i++) {
879 if (wep->key[i])
880 set++;
881 }
882 if (!set)
883 wep->keys_set = 0;
884 return 0;
885 }
886
887 if (wep->key[keyidx] != NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888 return -1;
889
890 if (val[0] == '"') {
891 if (len < 2 || val[len - 1] != '"')
892 return -1;
893 len -= 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700894 wep->key[keyidx] = os_memdup(val + 1, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 if (wep->key[keyidx] == NULL)
896 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897 wep->len[keyidx] = len;
898 } else {
899 if (len & 1)
900 return -1;
901 len /= 2;
902 wep->key[keyidx] = os_malloc(len);
903 if (wep->key[keyidx] == NULL)
904 return -1;
905 wep->len[keyidx] = len;
906 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
907 return -1;
908 }
909
910 wep->keys_set++;
911
912 return 0;
913}
914
915
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700916static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
917{
918 char *pos;
919
920 /* for backwards compatibility, translate ' ' in conf str to ',' */
921 pos = val;
922 while (pos) {
923 pos = os_strchr(pos, ' ');
924 if (pos)
925 *pos++ = ',';
926 }
927 if (freq_range_list_parse(&conf->acs_ch_list, val))
928 return -1;
929
930 return 0;
931}
932
933
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700934static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935{
936 int *list;
937 int count;
938 char *pos, *end;
939
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700940 os_free(*int_list);
941 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700942
943 pos = val;
944 count = 0;
945 while (*pos != '\0') {
946 if (*pos == ' ')
947 count++;
948 pos++;
949 }
950
951 list = os_malloc(sizeof(int) * (count + 2));
952 if (list == NULL)
953 return -1;
954 pos = val;
955 count = 0;
956 while (*pos != '\0') {
957 end = os_strchr(pos, ' ');
958 if (end)
959 *end = '\0';
960
961 list[count++] = atoi(pos);
962 if (!end)
963 break;
964 pos = end + 1;
965 }
966 list[count] = -1;
967
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700968 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 return 0;
970}
971
972
973static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
974{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800975 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700976
977 if (*ifname == '\0')
978 return -1;
979
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800980 all = os_realloc_array(conf->bss, conf->num_bss + 1,
981 sizeof(struct hostapd_bss_config *));
982 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
984 "multi-BSS entry");
985 return -1;
986 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800987 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800989 bss = os_zalloc(sizeof(*bss));
990 if (bss == NULL)
991 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 bss->radius = os_zalloc(sizeof(*bss->radius));
993 if (bss->radius == NULL) {
994 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
995 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800996 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997 return -1;
998 }
999
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001000 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001 conf->last_bss = bss;
1002
1003 hostapd_config_defaults_bss(bss);
1004 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1005 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
1006
1007 return 0;
1008}
1009
1010
1011/* convert floats with one decimal place to value*10 int, i.e.,
1012 * "1.5" will return 15 */
1013static int hostapd_config_read_int10(const char *value)
1014{
1015 int i, d;
1016 char *pos;
1017
1018 i = atoi(value);
1019 pos = os_strchr(value, '.');
1020 d = 0;
1021 if (pos) {
1022 pos++;
1023 if (*pos >= '0' && *pos <= '9')
1024 d = *pos - '0';
1025 }
1026
1027 return i * 10 + d;
1028}
1029
1030
1031static int valid_cw(int cw)
1032{
1033 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
Dmitry Shmidt41712582015-06-29 11:02:15 -07001034 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023 ||
1035 cw == 2047 || cw == 4095 || cw == 8191 || cw == 16383 ||
1036 cw == 32767);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037}
1038
1039
1040enum {
1041 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
1042 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
1043 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
1044 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
1045};
1046
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001047static int hostapd_config_tx_queue(struct hostapd_config *conf,
1048 const char *name, const char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049{
1050 int num;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001051 const char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052 struct hostapd_tx_queue_params *queue;
1053
1054 /* skip 'tx_queue_' prefix */
1055 pos = name + 9;
1056 if (os_strncmp(pos, "data", 4) == 0 &&
1057 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
1058 num = pos[4] - '0';
1059 pos += 6;
1060 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
1061 os_strncmp(pos, "beacon_", 7) == 0) {
1062 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
1063 return 0;
1064 } else {
1065 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
1066 return -1;
1067 }
1068
1069 if (num >= NUM_TX_QUEUES) {
1070 /* for backwards compatibility, do not trigger failure */
1071 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
1072 return 0;
1073 }
1074
1075 queue = &conf->tx_queue[num];
1076
1077 if (os_strcmp(pos, "aifs") == 0) {
1078 queue->aifs = atoi(val);
1079 if (queue->aifs < 0 || queue->aifs > 255) {
1080 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
1081 queue->aifs);
1082 return -1;
1083 }
1084 } else if (os_strcmp(pos, "cwmin") == 0) {
1085 queue->cwmin = atoi(val);
1086 if (!valid_cw(queue->cwmin)) {
1087 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
1088 queue->cwmin);
1089 return -1;
1090 }
1091 } else if (os_strcmp(pos, "cwmax") == 0) {
1092 queue->cwmax = atoi(val);
1093 if (!valid_cw(queue->cwmax)) {
1094 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
1095 queue->cwmax);
1096 return -1;
1097 }
1098 } else if (os_strcmp(pos, "burst") == 0) {
1099 queue->burst = hostapd_config_read_int10(val);
1100 } else {
1101 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
1102 return -1;
1103 }
1104
1105 return 0;
1106}
1107
1108
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001109#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001110
1111static int rkh_derive_key(const char *pos, u8 *key, size_t key_len)
1112{
1113 u8 oldkey[16];
1114 int ret;
1115
1116 if (!hexstr2bin(pos, key, key_len))
1117 return 0;
1118
1119 /* Try to use old short key for backwards compatibility */
1120 if (hexstr2bin(pos, oldkey, sizeof(oldkey)))
1121 return -1;
1122
1123 ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0,
1124 key, key_len);
1125 os_memset(oldkey, 0, sizeof(oldkey));
1126 return ret;
1127}
1128
1129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130static int add_r0kh(struct hostapd_bss_config *bss, char *value)
1131{
1132 struct ft_remote_r0kh *r0kh;
1133 char *pos, *next;
1134
1135 r0kh = os_zalloc(sizeof(*r0kh));
1136 if (r0kh == NULL)
1137 return -1;
1138
1139 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
1140 pos = value;
1141 next = os_strchr(pos, ' ');
1142 if (next)
1143 *next++ = '\0';
1144 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
1145 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
1146 os_free(r0kh);
1147 return -1;
1148 }
1149
1150 pos = next;
1151 next = os_strchr(pos, ' ');
1152 if (next)
1153 *next++ = '\0';
1154 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
1155 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
1156 os_free(r0kh);
1157 return -1;
1158 }
1159 r0kh->id_len = next - pos - 1;
1160 os_memcpy(r0kh->id, pos, r0kh->id_len);
1161
1162 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001163 if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1165 os_free(r0kh);
1166 return -1;
1167 }
1168
1169 r0kh->next = bss->r0kh_list;
1170 bss->r0kh_list = r0kh;
1171
1172 return 0;
1173}
1174
1175
1176static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1177{
1178 struct ft_remote_r1kh *r1kh;
1179 char *pos, *next;
1180
1181 r1kh = os_zalloc(sizeof(*r1kh));
1182 if (r1kh == NULL)
1183 return -1;
1184
1185 /* 02:01:02:03:04:05 02:01:02:03:04:05
1186 * 000102030405060708090a0b0c0d0e0f */
1187 pos = value;
1188 next = os_strchr(pos, ' ');
1189 if (next)
1190 *next++ = '\0';
1191 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1192 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1193 os_free(r1kh);
1194 return -1;
1195 }
1196
1197 pos = next;
1198 next = os_strchr(pos, ' ');
1199 if (next)
1200 *next++ = '\0';
1201 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1202 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1203 os_free(r1kh);
1204 return -1;
1205 }
1206
1207 pos = next;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001208 if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001209 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1210 os_free(r1kh);
1211 return -1;
1212 }
1213
1214 r1kh->next = bss->r1kh_list;
1215 bss->r1kh_list = r1kh;
1216
1217 return 0;
1218}
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220
1221
1222#ifdef CONFIG_IEEE80211N
1223static int hostapd_config_ht_capab(struct hostapd_config *conf,
1224 const char *capab)
1225{
1226 if (os_strstr(capab, "[LDPC]"))
1227 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1228 if (os_strstr(capab, "[HT40-]")) {
1229 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1230 conf->secondary_channel = -1;
1231 }
1232 if (os_strstr(capab, "[HT40+]")) {
1233 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1234 conf->secondary_channel = 1;
1235 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001236 if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
1237 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1238 conf->ht40_plus_minus_allowed = 1;
1239 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 if (os_strstr(capab, "[SMPS-STATIC]")) {
1241 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1242 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1243 }
1244 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1245 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1246 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1247 }
1248 if (os_strstr(capab, "[GF]"))
1249 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1250 if (os_strstr(capab, "[SHORT-GI-20]"))
1251 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1252 if (os_strstr(capab, "[SHORT-GI-40]"))
1253 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1254 if (os_strstr(capab, "[TX-STBC]"))
1255 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1256 if (os_strstr(capab, "[RX-STBC1]")) {
1257 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1258 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1259 }
1260 if (os_strstr(capab, "[RX-STBC12]")) {
1261 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1262 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1263 }
1264 if (os_strstr(capab, "[RX-STBC123]")) {
1265 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1266 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1267 }
1268 if (os_strstr(capab, "[DELAYED-BA]"))
1269 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1270 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1271 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1272 if (os_strstr(capab, "[DSSS_CCK-40]"))
1273 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001274 if (os_strstr(capab, "[40-INTOLERANT]"))
1275 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1277 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1278
1279 return 0;
1280}
1281#endif /* CONFIG_IEEE80211N */
1282
1283
Dmitry Shmidt04949592012-07-19 12:16:46 -07001284#ifdef CONFIG_IEEE80211AC
1285static int hostapd_config_vht_capab(struct hostapd_config *conf,
1286 const char *capab)
1287{
1288 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1289 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1290 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1291 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1292 if (os_strstr(capab, "[VHT160]"))
1293 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1294 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1295 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001296 if (os_strstr(capab, "[RXLDPC]"))
1297 conf->vht_capab |= VHT_CAP_RXLDPC;
1298 if (os_strstr(capab, "[SHORT-GI-80]"))
1299 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1300 if (os_strstr(capab, "[SHORT-GI-160]"))
1301 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1302 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1303 conf->vht_capab |= VHT_CAP_TXSTBC;
1304 if (os_strstr(capab, "[RX-STBC-1]"))
1305 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1306 if (os_strstr(capab, "[RX-STBC-12]"))
1307 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1308 if (os_strstr(capab, "[RX-STBC-123]"))
1309 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1310 if (os_strstr(capab, "[RX-STBC-1234]"))
1311 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1312 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001313 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001314 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001315 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001316 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001317 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1318 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001319 if (os_strstr(capab, "[BF-ANTENNA-3]") &&
1320 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1321 conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
1322 if (os_strstr(capab, "[BF-ANTENNA-4]") &&
1323 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1324 conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001325 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001326 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1327 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001328 if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") &&
1329 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1330 conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
1331 if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") &&
1332 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1333 conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001334 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1335 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001336 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1337 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1338 if (os_strstr(capab, "[HTC-VHT]"))
1339 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001340 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1341 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1342 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1343 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1344 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1345 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1346 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1347 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1348 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1349 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1350 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1351 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1352 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1353 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001354 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1355 (conf->vht_capab & VHT_CAP_HTC_VHT))
1356 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1357 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1358 (conf->vht_capab & VHT_CAP_HTC_VHT))
1359 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1360 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1361 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1362 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1363 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1364 return 0;
1365}
1366#endif /* CONFIG_IEEE80211AC */
1367
1368
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001369#ifdef CONFIG_INTERWORKING
1370static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1371 int line)
1372{
1373 size_t len = os_strlen(pos);
1374 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1375
1376 struct hostapd_roaming_consortium *rc;
1377
1378 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1379 hexstr2bin(pos, oi, len / 2)) {
1380 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1381 "'%s'", line, pos);
1382 return -1;
1383 }
1384 len /= 2;
1385
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001386 rc = os_realloc_array(bss->roaming_consortium,
1387 bss->roaming_consortium_count + 1,
1388 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001389 if (rc == NULL)
1390 return -1;
1391
1392 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1393 rc[bss->roaming_consortium_count].len = len;
1394
1395 bss->roaming_consortium = rc;
1396 bss->roaming_consortium_count++;
1397
1398 return 0;
1399}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001400
1401
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001402static int parse_lang_string(struct hostapd_lang_string **array,
1403 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001404{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001405 char *sep, *str = NULL;
1406 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001407 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001408 int ret = -1;
1409
1410 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1411 str = wpa_config_parse_string(pos, &slen);
1412 if (!str)
1413 return -1;
1414 pos = str;
1415 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001416
1417 sep = os_strchr(pos, ':');
1418 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001419 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001420 *sep++ = '\0';
1421
1422 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001423 if (clen < 2 || clen > sizeof(ls->lang))
1424 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001425 nlen = os_strlen(sep);
1426 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001427 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001428
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001429 ls = os_realloc_array(*array, *count + 1,
1430 sizeof(struct hostapd_lang_string));
1431 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001432 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001433
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001434 *array = ls;
1435 ls = &(*array)[*count];
1436 (*count)++;
1437
1438 os_memset(ls->lang, 0, sizeof(ls->lang));
1439 os_memcpy(ls->lang, pos, clen);
1440 ls->name_len = nlen;
1441 os_memcpy(ls->name, sep, nlen);
1442
Dmitry Shmidt56052862013-10-04 10:23:25 -07001443 ret = 0;
1444fail:
1445 os_free(str);
1446 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001447}
1448
1449
1450static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1451 int line)
1452{
1453 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1454 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1455 line, pos);
1456 return -1;
1457 }
1458 return 0;
1459}
1460
1461
Roshan Pius3a1667e2018-07-03 15:17:14 -07001462static int parse_venue_url(struct hostapd_bss_config *bss, char *pos,
1463 int line)
1464{
1465 char *sep;
1466 size_t nlen;
1467 struct hostapd_venue_url *url;
1468 int ret = -1;
1469
1470 sep = os_strchr(pos, ':');
1471 if (!sep)
1472 goto fail;
1473 *sep++ = '\0';
1474
1475 nlen = os_strlen(sep);
1476 if (nlen > 254)
1477 goto fail;
1478
1479 url = os_realloc_array(bss->venue_url, bss->venue_url_count + 1,
1480 sizeof(struct hostapd_venue_url));
1481 if (!url)
1482 goto fail;
1483
1484 bss->venue_url = url;
1485 url = &bss->venue_url[bss->venue_url_count++];
1486
1487 url->venue_number = atoi(pos);
1488 url->url_len = nlen;
1489 os_memcpy(url->url, sep, nlen);
1490
1491 ret = 0;
1492fail:
1493 if (ret)
1494 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_url '%s'",
1495 line, pos);
1496 return ret;
1497}
1498
1499
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001500static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1501 int line)
1502{
1503 size_t count;
1504 char *pos;
1505 u8 *info = NULL, *ipos;
1506
1507 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1508
1509 count = 1;
1510 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001511 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001512 goto fail;
1513 if (*pos == ';')
1514 count++;
1515 }
1516 if (1 + count * 3 > 0x7f)
1517 goto fail;
1518
1519 info = os_zalloc(2 + 3 + count * 3);
1520 if (info == NULL)
1521 return -1;
1522
1523 ipos = info;
1524 *ipos++ = 0; /* GUD - Version 1 */
1525 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1526 *ipos++ = 0; /* PLMN List IEI */
1527 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1528 *ipos++ = 1 + count * 3;
1529 *ipos++ = count; /* Number of PLMNs */
1530
1531 pos = buf;
1532 while (pos && *pos) {
1533 char *mcc, *mnc;
1534 size_t mnc_len;
1535
1536 mcc = pos;
1537 mnc = os_strchr(pos, ',');
1538 if (mnc == NULL)
1539 goto fail;
1540 *mnc++ = '\0';
1541 pos = os_strchr(mnc, ';');
1542 if (pos)
1543 *pos++ = '\0';
1544
1545 mnc_len = os_strlen(mnc);
1546 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1547 goto fail;
1548
1549 /* BC coded MCC,MNC */
1550 /* MCC digit 2 | MCC digit 1 */
1551 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1552 /* MNC digit 3 | MCC digit 3 */
1553 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1554 (mcc[2] - '0');
1555 /* MNC digit 2 | MNC digit 1 */
1556 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1557 }
1558
1559 os_free(bss->anqp_3gpp_cell_net);
1560 bss->anqp_3gpp_cell_net = info;
1561 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1562 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1563 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001564
1565 return 0;
1566
1567fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001568 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1569 line, buf);
1570 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001571 return -1;
1572}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001573
1574
1575static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1576{
1577 struct hostapd_nai_realm_data *realm;
1578 size_t i, j, len;
1579 int *offsets;
1580 char *pos, *end, *rpos;
1581
1582 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1583 sizeof(int));
1584 if (offsets == NULL)
1585 return -1;
1586
1587 for (i = 0; i < bss->nai_realm_count; i++) {
1588 realm = &bss->nai_realm_data[i];
1589 for (j = 0; j < MAX_NAI_REALMS; j++) {
1590 offsets[i * MAX_NAI_REALMS + j] =
1591 realm->realm[j] ?
1592 realm->realm[j] - realm->realm_buf : -1;
1593 }
1594 }
1595
1596 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1597 sizeof(struct hostapd_nai_realm_data));
1598 if (realm == NULL) {
1599 os_free(offsets);
1600 return -1;
1601 }
1602 bss->nai_realm_data = realm;
1603
1604 /* patch the pointers after realloc */
1605 for (i = 0; i < bss->nai_realm_count; i++) {
1606 realm = &bss->nai_realm_data[i];
1607 for (j = 0; j < MAX_NAI_REALMS; j++) {
1608 int offs = offsets[i * MAX_NAI_REALMS + j];
1609 if (offs >= 0)
1610 realm->realm[j] = realm->realm_buf + offs;
1611 else
1612 realm->realm[j] = NULL;
1613 }
1614 }
1615 os_free(offsets);
1616
1617 realm = &bss->nai_realm_data[bss->nai_realm_count];
1618 os_memset(realm, 0, sizeof(*realm));
1619
1620 pos = buf;
1621 realm->encoding = atoi(pos);
1622 pos = os_strchr(pos, ',');
1623 if (pos == NULL)
1624 goto fail;
1625 pos++;
1626
1627 end = os_strchr(pos, ',');
1628 if (end) {
1629 len = end - pos;
1630 *end = '\0';
1631 } else {
1632 len = os_strlen(pos);
1633 }
1634
1635 if (len > MAX_NAI_REALMLEN) {
1636 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1637 "characters)", (int) len, MAX_NAI_REALMLEN);
1638 goto fail;
1639 }
1640 os_memcpy(realm->realm_buf, pos, len);
1641
1642 if (end)
1643 pos = end + 1;
1644 else
1645 pos = NULL;
1646
1647 while (pos && *pos) {
1648 struct hostapd_nai_realm_eap *eap;
1649
1650 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1651 wpa_printf(MSG_ERROR, "Too many EAP methods");
1652 goto fail;
1653 }
1654
1655 eap = &realm->eap_method[realm->eap_method_count];
1656 realm->eap_method_count++;
1657
1658 end = os_strchr(pos, ',');
1659 if (end == NULL)
1660 end = pos + os_strlen(pos);
1661
1662 eap->eap_method = atoi(pos);
1663 for (;;) {
1664 pos = os_strchr(pos, '[');
1665 if (pos == NULL || pos > end)
1666 break;
1667 pos++;
1668 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1669 wpa_printf(MSG_ERROR, "Too many auth params");
1670 goto fail;
1671 }
1672 eap->auth_id[eap->num_auths] = atoi(pos);
1673 pos = os_strchr(pos, ':');
1674 if (pos == NULL || pos > end)
1675 goto fail;
1676 pos++;
1677 eap->auth_val[eap->num_auths] = atoi(pos);
1678 pos = os_strchr(pos, ']');
1679 if (pos == NULL || pos > end)
1680 goto fail;
1681 pos++;
1682 eap->num_auths++;
1683 }
1684
1685 if (*end != ',')
1686 break;
1687
1688 pos = end + 1;
1689 }
1690
1691 /* Split realm list into null terminated realms */
1692 rpos = realm->realm_buf;
1693 i = 0;
1694 while (*rpos) {
1695 if (i >= MAX_NAI_REALMS) {
1696 wpa_printf(MSG_ERROR, "Too many realms");
1697 goto fail;
1698 }
1699 realm->realm[i++] = rpos;
1700 rpos = os_strchr(rpos, ';');
1701 if (rpos == NULL)
1702 break;
1703 *rpos++ = '\0';
1704 }
1705
1706 bss->nai_realm_count++;
1707
1708 return 0;
1709
1710fail:
1711 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1712 return -1;
1713}
1714
Dmitry Shmidt051af732013-10-22 13:52:46 -07001715
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001716static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line)
1717{
1718 char *delim;
1719 u16 infoid;
1720 size_t len;
1721 struct wpabuf *payload;
1722 struct anqp_element *elem;
1723
1724 delim = os_strchr(buf, ':');
1725 if (!delim)
1726 return -1;
1727 delim++;
1728 infoid = atoi(buf);
1729 len = os_strlen(delim);
1730 if (len & 1)
1731 return -1;
1732 len /= 2;
1733 payload = wpabuf_alloc(len);
1734 if (!payload)
1735 return -1;
1736 if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) {
1737 wpabuf_free(payload);
1738 return -1;
1739 }
1740
1741 dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) {
1742 if (elem->infoid == infoid) {
1743 /* Update existing entry */
1744 wpabuf_free(elem->payload);
1745 elem->payload = payload;
1746 return 0;
1747 }
1748 }
1749
1750 /* Add a new entry */
1751 elem = os_zalloc(sizeof(*elem));
1752 if (!elem) {
1753 wpabuf_free(payload);
1754 return -1;
1755 }
1756 elem->infoid = infoid;
1757 elem->payload = payload;
1758 dl_list_add(&bss->anqp_elem, &elem->list);
1759
1760 return 0;
1761}
1762
1763
Dmitry Shmidt051af732013-10-22 13:52:46 -07001764static int parse_qos_map_set(struct hostapd_bss_config *bss,
1765 char *buf, int line)
1766{
1767 u8 qos_map_set[16 + 2 * 21], count = 0;
1768 char *pos = buf;
1769 int val;
1770
1771 for (;;) {
1772 if (count == sizeof(qos_map_set)) {
1773 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1774 "parameters '%s'", line, buf);
1775 return -1;
1776 }
1777
1778 val = atoi(pos);
1779 if (val > 255 || val < 0) {
1780 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1781 "'%s'", line, buf);
1782 return -1;
1783 }
1784
1785 qos_map_set[count++] = val;
1786 pos = os_strchr(pos, ',');
1787 if (!pos)
1788 break;
1789 pos++;
1790 }
1791
1792 if (count < 16 || count & 1) {
1793 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1794 line, buf);
1795 return -1;
1796 }
1797
1798 os_memcpy(bss->qos_map_set, qos_map_set, count);
1799 bss->qos_map_set_len = count;
1800
1801 return 0;
1802}
1803
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001804#endif /* CONFIG_INTERWORKING */
1805
1806
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001807#ifdef CONFIG_HS20
1808static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1809 int line)
1810{
1811 u8 *conn_cap;
1812 char *pos;
1813
1814 if (bss->hs20_connection_capability_len >= 0xfff0)
1815 return -1;
1816
1817 conn_cap = os_realloc(bss->hs20_connection_capability,
1818 bss->hs20_connection_capability_len + 4);
1819 if (conn_cap == NULL)
1820 return -1;
1821
1822 bss->hs20_connection_capability = conn_cap;
1823 conn_cap += bss->hs20_connection_capability_len;
1824 pos = buf;
1825 conn_cap[0] = atoi(pos);
1826 pos = os_strchr(pos, ':');
1827 if (pos == NULL)
1828 return -1;
1829 pos++;
1830 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1831 pos = os_strchr(pos, ':');
1832 if (pos == NULL)
1833 return -1;
1834 pos++;
1835 conn_cap[3] = atoi(pos);
1836 bss->hs20_connection_capability_len += 4;
1837
1838 return 0;
1839}
1840
1841
1842static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1843 int line)
1844{
1845 u8 *wan_metrics;
1846 char *pos;
1847
1848 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1849
1850 wan_metrics = os_zalloc(13);
1851 if (wan_metrics == NULL)
1852 return -1;
1853
1854 pos = buf;
1855 /* WAN Info */
1856 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1857 goto fail;
1858 pos += 2;
1859 if (*pos != ':')
1860 goto fail;
1861 pos++;
1862
1863 /* Downlink Speed */
1864 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1865 pos = os_strchr(pos, ':');
1866 if (pos == NULL)
1867 goto fail;
1868 pos++;
1869
1870 /* Uplink Speed */
1871 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1872 pos = os_strchr(pos, ':');
1873 if (pos == NULL)
1874 goto fail;
1875 pos++;
1876
1877 /* Downlink Load */
1878 wan_metrics[9] = atoi(pos);
1879 pos = os_strchr(pos, ':');
1880 if (pos == NULL)
1881 goto fail;
1882 pos++;
1883
1884 /* Uplink Load */
1885 wan_metrics[10] = atoi(pos);
1886 pos = os_strchr(pos, ':');
1887 if (pos == NULL)
1888 goto fail;
1889 pos++;
1890
1891 /* LMD */
1892 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1893
1894 os_free(bss->hs20_wan_metrics);
1895 bss->hs20_wan_metrics = wan_metrics;
1896
1897 return 0;
1898
1899fail:
1900 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001901 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001902 os_free(wan_metrics);
1903 return -1;
1904}
1905
1906
1907static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1908 char *pos, int line)
1909{
1910 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1911 &bss->hs20_oper_friendly_name_count, pos)) {
1912 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1913 "hs20_oper_friendly_name '%s'", line, pos);
1914 return -1;
1915 }
1916 return 0;
1917}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001918
1919
1920static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1921{
1922 struct hs20_icon *icon;
1923 char *end;
1924
1925 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1926 sizeof(struct hs20_icon));
1927 if (icon == NULL)
1928 return -1;
1929 bss->hs20_icons = icon;
1930 icon = &bss->hs20_icons[bss->hs20_icons_count];
1931 os_memset(icon, 0, sizeof(*icon));
1932
1933 icon->width = atoi(pos);
1934 pos = os_strchr(pos, ':');
1935 if (pos == NULL)
1936 return -1;
1937 pos++;
1938
1939 icon->height = atoi(pos);
1940 pos = os_strchr(pos, ':');
1941 if (pos == NULL)
1942 return -1;
1943 pos++;
1944
1945 end = os_strchr(pos, ':');
1946 if (end == NULL || end - pos > 3)
1947 return -1;
1948 os_memcpy(icon->language, pos, end - pos);
1949 pos = end + 1;
1950
1951 end = os_strchr(pos, ':');
1952 if (end == NULL || end - pos > 255)
1953 return -1;
1954 os_memcpy(icon->type, pos, end - pos);
1955 pos = end + 1;
1956
1957 end = os_strchr(pos, ':');
1958 if (end == NULL || end - pos > 255)
1959 return -1;
1960 os_memcpy(icon->name, pos, end - pos);
1961 pos = end + 1;
1962
1963 if (os_strlen(pos) > 255)
1964 return -1;
1965 os_memcpy(icon->file, pos, os_strlen(pos));
1966
1967 bss->hs20_icons_count++;
1968
1969 return 0;
1970}
1971
1972
1973static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1974 char *pos, int line)
1975{
1976 size_t slen;
1977 char *str;
1978
1979 str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001980 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001981 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001982 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001983 return -1;
1984 }
1985
1986 os_memcpy(bss->osu_ssid, str, slen);
1987 bss->osu_ssid_len = slen;
1988 os_free(str);
1989
1990 return 0;
1991}
1992
1993
1994static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1995 char *pos, int line)
1996{
1997 struct hs20_osu_provider *p;
1998
1999 p = os_realloc_array(bss->hs20_osu_providers,
2000 bss->hs20_osu_providers_count + 1, sizeof(*p));
2001 if (p == NULL)
2002 return -1;
2003
2004 bss->hs20_osu_providers = p;
2005 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
2006 bss->hs20_osu_providers_count++;
2007 os_memset(bss->last_osu, 0, sizeof(*p));
2008 bss->last_osu->server_uri = os_strdup(pos);
2009
2010 return 0;
2011}
2012
2013
2014static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
2015 char *pos, int line)
2016{
2017 if (bss->last_osu == NULL) {
2018 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2019 return -1;
2020 }
2021
2022 if (parse_lang_string(&bss->last_osu->friendly_name,
2023 &bss->last_osu->friendly_name_count, pos)) {
2024 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
2025 line, pos);
2026 return -1;
2027 }
2028
2029 return 0;
2030}
2031
2032
2033static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
2034 char *pos, int line)
2035{
2036 if (bss->last_osu == NULL) {
2037 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2038 return -1;
2039 }
2040
2041 os_free(bss->last_osu->osu_nai);
2042 bss->last_osu->osu_nai = os_strdup(pos);
2043 if (bss->last_osu->osu_nai == NULL)
2044 return -1;
2045
2046 return 0;
2047}
2048
2049
2050static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
2051 int line)
2052{
2053 if (bss->last_osu == NULL) {
2054 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2055 return -1;
2056 }
2057
2058 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
2059 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
2060 return -1;
2061 }
2062
2063 return 0;
2064}
2065
2066
2067static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
2068 int line)
2069{
2070 char **n;
2071 struct hs20_osu_provider *p = bss->last_osu;
2072
2073 if (p == NULL) {
2074 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2075 return -1;
2076 }
2077
2078 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
2079 if (n == NULL)
2080 return -1;
2081 p->icons = n;
2082 p->icons[p->icons_count] = os_strdup(pos);
2083 if (p->icons[p->icons_count] == NULL)
2084 return -1;
2085 p->icons_count++;
2086
2087 return 0;
2088}
2089
2090
2091static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
2092 char *pos, int line)
2093{
2094 if (bss->last_osu == NULL) {
2095 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
2096 return -1;
2097 }
2098
2099 if (parse_lang_string(&bss->last_osu->service_desc,
2100 &bss->last_osu->service_desc_count, pos)) {
2101 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
2102 line, pos);
2103 return -1;
2104 }
2105
2106 return 0;
2107}
2108
Roshan Pius3a1667e2018-07-03 15:17:14 -07002109
2110static int hs20_parse_operator_icon(struct hostapd_bss_config *bss, char *pos,
2111 int line)
2112{
2113 char **n;
2114
2115 n = os_realloc_array(bss->hs20_operator_icon,
2116 bss->hs20_operator_icon_count + 1, sizeof(char *));
2117 if (!n)
2118 return -1;
2119 bss->hs20_operator_icon = n;
2120 bss->hs20_operator_icon[bss->hs20_operator_icon_count] = os_strdup(pos);
2121 if (!bss->hs20_operator_icon[bss->hs20_operator_icon_count])
2122 return -1;
2123 bss->hs20_operator_icon_count++;
2124
2125 return 0;
2126}
2127
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002128#endif /* CONFIG_HS20 */
2129
2130
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002131#ifdef CONFIG_ACS
2132static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
2133 char *pos)
2134{
2135 struct acs_bias *bias = NULL, *tmp;
2136 unsigned int num = 0;
2137 char *end;
2138
2139 while (*pos) {
2140 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
2141 if (!tmp)
2142 goto fail;
2143 bias = tmp;
2144
2145 bias[num].channel = atoi(pos);
2146 if (bias[num].channel <= 0)
2147 goto fail;
2148 pos = os_strchr(pos, ':');
2149 if (!pos)
2150 goto fail;
2151 pos++;
2152 bias[num].bias = strtod(pos, &end);
2153 if (end == pos || bias[num].bias < 0.0)
2154 goto fail;
2155 pos = end;
2156 if (*pos != ' ' && *pos != '\0')
2157 goto fail;
2158 num++;
2159 }
2160
2161 os_free(conf->acs_chan_bias);
2162 conf->acs_chan_bias = bias;
2163 conf->num_acs_chan_bias = num;
2164
2165 return 0;
2166fail:
2167 os_free(bias);
2168 return -1;
2169}
2170#endif /* CONFIG_ACS */
2171
2172
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002173static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
2174 const char *val)
2175{
2176 struct wpabuf *elems;
2177
2178 if (val[0] == '\0') {
2179 wpabuf_free(*buf);
2180 *buf = NULL;
2181 return 0;
2182 }
2183
2184 elems = wpabuf_parse_bin(val);
2185 if (!elems) {
2186 wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
2187 line, name, val);
2188 return -1;
2189 }
2190
2191 wpabuf_free(*buf);
2192 *buf = elems;
2193
2194 return 0;
2195}
2196
2197
Dmitry Shmidt29333592017-01-09 12:27:11 -08002198#ifdef CONFIG_FILS
2199static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val)
2200{
2201 struct fils_realm *realm;
2202 size_t len;
2203
2204 len = os_strlen(val);
2205 realm = os_zalloc(sizeof(*realm) + len + 1);
2206 if (!realm)
2207 return -1;
2208
2209 os_memcpy(realm->realm, val, len);
2210 if (fils_domain_name_hash(val, realm->hash) < 0) {
2211 os_free(realm);
2212 return -1;
2213 }
2214 dl_list_add_tail(&bss->fils_realms, &realm->list);
2215
2216 return 0;
2217}
2218#endif /* CONFIG_FILS */
2219
2220
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002221#ifdef EAP_SERVER
2222static unsigned int parse_tls_flags(const char *val)
2223{
2224 unsigned int flags = 0;
2225
Roshan Pius3a1667e2018-07-03 15:17:14 -07002226 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
2227 * This can be enabled by default once the implementation has been fully
2228 * completed and tested with other implementations. */
2229 flags |= TLS_CONN_DISABLE_TLSv1_3;
2230
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002231 if (os_strstr(val, "[ALLOW-SIGN-RSA-MD5]"))
2232 flags |= TLS_CONN_ALLOW_SIGN_RSA_MD5;
2233 if (os_strstr(val, "[DISABLE-TIME-CHECKS]"))
2234 flags |= TLS_CONN_DISABLE_TIME_CHECKS;
2235 if (os_strstr(val, "[DISABLE-TLSv1.0]"))
2236 flags |= TLS_CONN_DISABLE_TLSv1_0;
2237 if (os_strstr(val, "[DISABLE-TLSv1.1]"))
2238 flags |= TLS_CONN_DISABLE_TLSv1_1;
2239 if (os_strstr(val, "[DISABLE-TLSv1.2]"))
2240 flags |= TLS_CONN_DISABLE_TLSv1_2;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002241 if (os_strstr(val, "[DISABLE-TLSv1.3]"))
2242 flags |= TLS_CONN_DISABLE_TLSv1_3;
2243 if (os_strstr(val, "[ENABLE-TLSv1.3]"))
2244 flags &= ~TLS_CONN_DISABLE_TLSv1_3;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002245 if (os_strstr(val, "[SUITEB]"))
2246 flags |= TLS_CONN_SUITEB;
2247 if (os_strstr(val, "[SUITEB-NO-ECDH]"))
2248 flags |= TLS_CONN_SUITEB_NO_ECDH | TLS_CONN_SUITEB;
2249
2250 return flags;
2251}
2252#endif /* EAP_SERVER */
2253
2254
Roshan Pius3a1667e2018-07-03 15:17:14 -07002255#ifdef CONFIG_SAE
2256static int parse_sae_password(struct hostapd_bss_config *bss, const char *val)
2257{
2258 struct sae_password_entry *pw;
2259 const char *pos = val, *pos2, *end = NULL;
2260
2261 pw = os_zalloc(sizeof(*pw));
2262 if (!pw)
2263 return -1;
2264 os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */
2265
2266 pos2 = os_strstr(pos, "|mac=");
2267 if (pos2) {
2268 end = pos2;
2269 pos2 += 5;
2270 if (hwaddr_aton(pos2, pw->peer_addr) < 0)
2271 goto fail;
2272 pos = pos2 + ETH_ALEN * 3 - 1;
2273 }
2274
2275 pos2 = os_strstr(pos, "|id=");
2276 if (pos2) {
2277 if (!end)
2278 end = pos2;
2279 pos2 += 4;
2280 pw->identifier = os_strdup(pos2);
2281 if (!pw->identifier)
2282 goto fail;
2283 }
2284
2285 if (!end) {
2286 pw->password = os_strdup(val);
2287 if (!pw->password)
2288 goto fail;
2289 } else {
2290 pw->password = os_malloc(end - val + 1);
2291 if (!pw->password)
2292 goto fail;
2293 os_memcpy(pw->password, val, end - val);
2294 pw->password[end - val] = '\0';
2295 }
2296
2297 pw->next = bss->sae_passwords;
2298 bss->sae_passwords = pw;
2299
2300 return 0;
2301fail:
2302 str_clear_free(pw->password);
2303 os_free(pw->identifier);
2304 os_free(pw);
2305 return -1;
2306}
2307#endif /* CONFIG_SAE */
2308
2309
Dmitry Shmidt04949592012-07-19 12:16:46 -07002310static int hostapd_config_fill(struct hostapd_config *conf,
2311 struct hostapd_bss_config *bss,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002312 const char *buf, char *pos, int line)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002313{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002314 if (os_strcmp(buf, "interface") == 0) {
2315 os_strlcpy(conf->bss[0]->iface, pos,
2316 sizeof(conf->bss[0]->iface));
2317 } else if (os_strcmp(buf, "bridge") == 0) {
2318 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
2319 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
2320 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
2321 } else if (os_strcmp(buf, "wds_bridge") == 0) {
2322 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
2323 } else if (os_strcmp(buf, "driver") == 0) {
2324 int j;
Dmitry Shmidt29333592017-01-09 12:27:11 -08002325 const struct wpa_driver_ops *driver = NULL;
2326
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002327 for (j = 0; wpa_drivers[j]; j++) {
2328 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002329 driver = wpa_drivers[j];
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002330 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002332 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002333 if (!driver) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002334 wpa_printf(MSG_ERROR,
2335 "Line %d: invalid/unknown driver '%s'",
2336 line, pos);
2337 return 1;
2338 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002339 conf->driver = driver;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002340 } else if (os_strcmp(buf, "driver_params") == 0) {
2341 os_free(conf->driver_params);
2342 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002343 } else if (os_strcmp(buf, "debug") == 0) {
2344 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
2345 line);
2346 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
2347 bss->logger_syslog_level = atoi(pos);
2348 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
2349 bss->logger_stdout_level = atoi(pos);
2350 } else if (os_strcmp(buf, "logger_syslog") == 0) {
2351 bss->logger_syslog = atoi(pos);
2352 } else if (os_strcmp(buf, "logger_stdout") == 0) {
2353 bss->logger_stdout = atoi(pos);
2354 } else if (os_strcmp(buf, "dump_file") == 0) {
2355 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
2356 line);
2357 } else if (os_strcmp(buf, "ssid") == 0) {
2358 bss->ssid.ssid_len = os_strlen(pos);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002359 if (bss->ssid.ssid_len > SSID_MAX_LEN ||
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002360 bss->ssid.ssid_len < 1) {
2361 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2362 line, pos);
2363 return 1;
2364 }
2365 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
2366 bss->ssid.ssid_set = 1;
2367 } else if (os_strcmp(buf, "ssid2") == 0) {
2368 size_t slen;
2369 char *str = wpa_config_parse_string(pos, &slen);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002370 if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002371 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
2372 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002373 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002374 return 1;
2375 }
2376 os_memcpy(bss->ssid.ssid, str, slen);
2377 bss->ssid.ssid_len = slen;
2378 bss->ssid.ssid_set = 1;
2379 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) {
2418 os_memcpy(conf->country, pos, 2);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002419 } else if (os_strcmp(buf, "country3") == 0) {
2420 conf->country[2] = strtol(pos, NULL, 16);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002421 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2422 conf->ieee80211d = atoi(pos);
2423 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2424 conf->ieee80211h = atoi(pos);
2425 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2426 bss->ieee802_1x = atoi(pos);
2427 } else if (os_strcmp(buf, "eapol_version") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002428 int eapol_version = atoi(pos);
2429
2430 if (eapol_version < 1 || eapol_version > 2) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002431 wpa_printf(MSG_ERROR,
2432 "Line %d: invalid EAPOL version (%d): '%s'.",
Dmitry Shmidt29333592017-01-09 12:27:11 -08002433 line, eapol_version, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002434 return 1;
2435 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002436 bss->eapol_version = eapol_version;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002437 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002439 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2440 bss->eap_server = atoi(pos);
2441 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2442 } else if (os_strcmp(buf, "eap_server") == 0) {
2443 bss->eap_server = atoi(pos);
2444 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2445 if (hostapd_config_read_eap_user(pos, bss))
2446 return 1;
2447 } else if (os_strcmp(buf, "ca_cert") == 0) {
2448 os_free(bss->ca_cert);
2449 bss->ca_cert = os_strdup(pos);
2450 } else if (os_strcmp(buf, "server_cert") == 0) {
2451 os_free(bss->server_cert);
2452 bss->server_cert = os_strdup(pos);
2453 } else if (os_strcmp(buf, "private_key") == 0) {
2454 os_free(bss->private_key);
2455 bss->private_key = os_strdup(pos);
2456 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2457 os_free(bss->private_key_passwd);
2458 bss->private_key_passwd = os_strdup(pos);
2459 } else if (os_strcmp(buf, "check_crl") == 0) {
2460 bss->check_crl = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002461 } else if (os_strcmp(buf, "tls_session_lifetime") == 0) {
2462 bss->tls_session_lifetime = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002463 } else if (os_strcmp(buf, "tls_flags") == 0) {
2464 bss->tls_flags = parse_tls_flags(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002465 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2466 os_free(bss->ocsp_stapling_response);
2467 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002468 } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) {
2469 os_free(bss->ocsp_stapling_response_multi);
2470 bss->ocsp_stapling_response_multi = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002471 } else if (os_strcmp(buf, "dh_file") == 0) {
2472 os_free(bss->dh_file);
2473 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002474 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2475 os_free(bss->openssl_ciphers);
2476 bss->openssl_ciphers = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002477 } else if (os_strcmp(buf, "fragment_size") == 0) {
2478 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002479#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002480 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2481 os_free(bss->pac_opaque_encr_key);
2482 bss->pac_opaque_encr_key = os_malloc(16);
2483 if (bss->pac_opaque_encr_key == NULL) {
2484 wpa_printf(MSG_ERROR,
2485 "Line %d: No memory for pac_opaque_encr_key",
2486 line);
2487 return 1;
2488 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2489 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2490 line);
2491 return 1;
2492 }
2493 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2494 size_t idlen = os_strlen(pos);
2495 if (idlen & 1) {
2496 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2497 line);
2498 return 1;
2499 }
2500 os_free(bss->eap_fast_a_id);
2501 bss->eap_fast_a_id = os_malloc(idlen / 2);
2502 if (bss->eap_fast_a_id == NULL ||
2503 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2504 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2505 line);
2506 os_free(bss->eap_fast_a_id);
2507 bss->eap_fast_a_id = NULL;
2508 return 1;
2509 } else {
2510 bss->eap_fast_a_id_len = idlen / 2;
2511 }
2512 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2513 os_free(bss->eap_fast_a_id_info);
2514 bss->eap_fast_a_id_info = os_strdup(pos);
2515 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2516 bss->eap_fast_prov = atoi(pos);
2517 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2518 bss->pac_key_lifetime = atoi(pos);
2519 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2520 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521#endif /* EAP_SERVER_FAST */
2522#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002523 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2524 os_free(bss->eap_sim_db);
2525 bss->eap_sim_db = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002526 } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) {
2527 bss->eap_sim_db_timeout = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002528 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2529 bss->eap_sim_aka_result_ind = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002530#endif /* EAP_SERVER_SIM */
2531#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002532 } else if (os_strcmp(buf, "tnc") == 0) {
2533 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002534#endif /* EAP_SERVER_TNC */
2535#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002536 } else if (os_strcmp(buf, "pwd_group") == 0) {
2537 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002538#endif /* EAP_SERVER_PWD */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002539#ifdef CONFIG_ERP
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002540 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2541 bss->eap_server_erp = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002542#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002543#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002544 } else if (os_strcmp(buf, "eap_message") == 0) {
2545 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002546 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002547 bss->eap_req_id_text = os_strdup(pos);
2548 if (bss->eap_req_id_text == NULL) {
2549 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2550 line);
2551 return 1;
2552 }
2553 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2554 term = os_strstr(bss->eap_req_id_text, "\\0");
2555 if (term) {
2556 *term++ = '\0';
2557 os_memmove(term, term + 1,
2558 bss->eap_req_id_text_len -
2559 (term - bss->eap_req_id_text) - 1);
2560 bss->eap_req_id_text_len--;
2561 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002562 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2563 bss->erp_send_reauth_start = atoi(pos);
2564 } else if (os_strcmp(buf, "erp_domain") == 0) {
2565 os_free(bss->erp_domain);
2566 bss->erp_domain = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002567 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002568 int val = atoi(pos);
2569
2570 if (val < 0 || val > 13) {
2571 wpa_printf(MSG_ERROR,
2572 "Line %d: invalid WEP key len %d (= %d bits)",
2573 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002574 return 1;
2575 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002576 bss->default_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002577 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08002578 int val = atoi(pos);
2579
2580 if (val < 0 || val > 13) {
2581 wpa_printf(MSG_ERROR,
2582 "Line %d: invalid WEP key len %d (= %d bits)",
2583 line, val, val * 8);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002584 return 1;
2585 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08002586 bss->individual_wep_key_len = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002587 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2588 bss->wep_rekeying_period = atoi(pos);
2589 if (bss->wep_rekeying_period < 0) {
2590 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2591 line, bss->wep_rekeying_period);
2592 return 1;
2593 }
2594 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2595 bss->eap_reauth_period = atoi(pos);
2596 if (bss->eap_reauth_period < 0) {
2597 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2598 line, bss->eap_reauth_period);
2599 return 1;
2600 }
2601 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2602 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002604 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2605 bss->ieee802_11f = 1;
2606 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002608 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2609 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2610 wpa_printf(MSG_ERROR,
2611 "Line %d: invalid IP address '%s'",
2612 line, pos);
2613 return 1;
2614 }
2615 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002616 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002617 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002618#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002619 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2620 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2621 wpa_printf(MSG_ERROR,
2622 "Line %d: invalid IP address '%s'",
2623 line, pos);
2624 return 1;
2625 }
2626 bss->radius->force_client_addr = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002627 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2628 if (hostapd_config_read_radius_addr(
2629 &bss->radius->auth_servers,
2630 &bss->radius->num_auth_servers, pos, 1812,
2631 &bss->radius->auth_server)) {
2632 wpa_printf(MSG_ERROR,
2633 "Line %d: invalid IP address '%s'",
2634 line, pos);
2635 return 1;
2636 }
2637 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002638 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2639 if (hostapd_parse_ip_addr(pos,
2640 &bss->radius->auth_server->addr)) {
2641 wpa_printf(MSG_ERROR,
2642 "Line %d: invalid IP address '%s'",
2643 line, pos);
2644 return 1;
2645 }
2646 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002647 os_strcmp(buf, "auth_server_port") == 0) {
2648 bss->radius->auth_server->port = atoi(pos);
2649 } else if (bss->radius->auth_server &&
2650 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2651 int len = os_strlen(pos);
2652 if (len == 0) {
2653 /* RFC 2865, Ch. 3 */
2654 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2655 line);
2656 return 1;
2657 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002658 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002659 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2660 bss->radius->auth_server->shared_secret_len = len;
2661 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2662 if (hostapd_config_read_radius_addr(
2663 &bss->radius->acct_servers,
2664 &bss->radius->num_acct_servers, pos, 1813,
2665 &bss->radius->acct_server)) {
2666 wpa_printf(MSG_ERROR,
2667 "Line %d: invalid IP address '%s'",
2668 line, pos);
2669 return 1;
2670 }
2671 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002672 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2673 if (hostapd_parse_ip_addr(pos,
2674 &bss->radius->acct_server->addr)) {
2675 wpa_printf(MSG_ERROR,
2676 "Line %d: invalid IP address '%s'",
2677 line, pos);
2678 return 1;
2679 }
2680 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002681 os_strcmp(buf, "acct_server_port") == 0) {
2682 bss->radius->acct_server->port = atoi(pos);
2683 } else if (bss->radius->acct_server &&
2684 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2685 int len = os_strlen(pos);
2686 if (len == 0) {
2687 /* RFC 2865, Ch. 3 */
2688 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2689 line);
2690 return 1;
2691 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002692 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002693 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2694 bss->radius->acct_server->shared_secret_len = len;
2695 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2696 bss->radius->retry_primary_interval = atoi(pos);
2697 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2698 bss->acct_interim_interval = atoi(pos);
2699 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2700 bss->radius_request_cui = atoi(pos);
2701 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2702 struct hostapd_radius_attr *attr, *a;
2703 attr = hostapd_parse_radius_attr(pos);
2704 if (attr == NULL) {
2705 wpa_printf(MSG_ERROR,
2706 "Line %d: invalid radius_auth_req_attr",
2707 line);
2708 return 1;
2709 } else if (bss->radius_auth_req_attr == NULL) {
2710 bss->radius_auth_req_attr = attr;
2711 } else {
2712 a = bss->radius_auth_req_attr;
2713 while (a->next)
2714 a = a->next;
2715 a->next = attr;
2716 }
2717 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2718 struct hostapd_radius_attr *attr, *a;
2719 attr = hostapd_parse_radius_attr(pos);
2720 if (attr == NULL) {
2721 wpa_printf(MSG_ERROR,
2722 "Line %d: invalid radius_acct_req_attr",
2723 line);
2724 return 1;
2725 } else if (bss->radius_acct_req_attr == NULL) {
2726 bss->radius_acct_req_attr = attr;
2727 } else {
2728 a = bss->radius_acct_req_attr;
2729 while (a->next)
2730 a = a->next;
2731 a->next = attr;
2732 }
2733 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2734 bss->radius_das_port = atoi(pos);
2735 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2736 if (hostapd_parse_das_client(bss, pos) < 0) {
2737 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2738 line);
2739 return 1;
2740 }
2741 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2742 bss->radius_das_time_window = atoi(pos);
2743 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2744 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002745 } else if (os_strcmp(buf, "radius_das_require_message_authenticator") ==
2746 0) {
2747 bss->radius_das_require_message_authenticator = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002749 } else if (os_strcmp(buf, "auth_algs") == 0) {
2750 bss->auth_algs = atoi(pos);
2751 if (bss->auth_algs == 0) {
2752 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2753 line);
2754 return 1;
2755 }
2756 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2757 bss->max_num_sta = atoi(pos);
2758 if (bss->max_num_sta < 0 ||
2759 bss->max_num_sta > MAX_STA_COUNT) {
2760 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2761 line, bss->max_num_sta, MAX_STA_COUNT);
2762 return 1;
2763 }
2764 } else if (os_strcmp(buf, "wpa") == 0) {
2765 bss->wpa = atoi(pos);
2766 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2767 bss->wpa_group_rekey = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002768 bss->wpa_group_rekey_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002769 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2770 bss->wpa_strict_rekey = atoi(pos);
2771 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2772 bss->wpa_gmk_rekey = atoi(pos);
2773 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2774 bss->wpa_ptk_rekey = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002775 } else if (os_strcmp(buf, "wpa_group_update_count") == 0) {
2776 char *endp;
2777 unsigned long val = strtoul(pos, &endp, 0);
2778
2779 if (*endp || val < 1 || val > (u32) -1) {
2780 wpa_printf(MSG_ERROR,
2781 "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295",
2782 line, val);
2783 return 1;
2784 }
2785 bss->wpa_group_update_count = (u32) val;
2786 } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) {
2787 char *endp;
2788 unsigned long val = strtoul(pos, &endp, 0);
2789
2790 if (*endp || val < 1 || val > (u32) -1) {
2791 wpa_printf(MSG_ERROR,
2792 "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295",
2793 line, val);
2794 return 1;
2795 }
2796 bss->wpa_pairwise_update_count = (u32) val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002797 } else if (os_strcmp(buf, "wpa_disable_eapol_key_retries") == 0) {
2798 bss->wpa_disable_eapol_key_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002799 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2800 int len = os_strlen(pos);
2801 if (len < 8 || len > 63) {
2802 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2803 line, len);
2804 return 1;
2805 }
2806 os_free(bss->ssid.wpa_passphrase);
2807 bss->ssid.wpa_passphrase = os_strdup(pos);
2808 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002809 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002810 bss->ssid.wpa_passphrase_set = 1;
2811 }
2812 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002813 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002814 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2815 if (bss->ssid.wpa_psk == NULL)
2816 return 1;
2817 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2818 pos[PMK_LEN * 2] != '\0') {
2819 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2820 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002821 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002822 return 1;
2823 }
2824 bss->ssid.wpa_psk->group = 1;
2825 os_free(bss->ssid.wpa_passphrase);
2826 bss->ssid.wpa_passphrase = NULL;
2827 bss->ssid.wpa_psk_set = 1;
2828 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2829 os_free(bss->ssid.wpa_psk_file);
2830 bss->ssid.wpa_psk_file = os_strdup(pos);
2831 if (!bss->ssid.wpa_psk_file) {
2832 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2833 line);
2834 return 1;
2835 }
2836 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2837 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2838 if (bss->wpa_key_mgmt == -1)
2839 return 1;
2840 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2841 bss->wpa_psk_radius = atoi(pos);
2842 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2843 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2844 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2845 wpa_printf(MSG_ERROR,
2846 "Line %d: unknown wpa_psk_radius %d",
2847 line, bss->wpa_psk_radius);
2848 return 1;
2849 }
2850 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2851 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2852 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2853 return 1;
2854 if (bss->wpa_pairwise &
2855 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2856 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002857 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002858 return 1;
2859 }
2860 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2861 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2862 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2863 return 1;
2864 if (bss->rsn_pairwise &
2865 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2866 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002867 line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002868 return 1;
2869 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002870 } else if (os_strcmp(buf, "group_cipher") == 0) {
2871 bss->group_cipher = hostapd_config_parse_cipher(line, pos);
2872 if (bss->group_cipher == -1 || bss->group_cipher == 0)
2873 return 1;
2874 if (bss->group_cipher != WPA_CIPHER_TKIP &&
2875 bss->group_cipher != WPA_CIPHER_CCMP &&
2876 bss->group_cipher != WPA_CIPHER_GCMP &&
2877 bss->group_cipher != WPA_CIPHER_GCMP_256 &&
2878 bss->group_cipher != WPA_CIPHER_CCMP_256) {
2879 wpa_printf(MSG_ERROR,
2880 "Line %d: unsupported group cipher suite '%s'",
2881 line, pos);
2882 return 1;
2883 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002885 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2886 bss->rsn_preauth = atoi(pos);
2887 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002888 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002889 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002890#endif /* CONFIG_RSN_PREAUTH */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002891 } else if (os_strcmp(buf, "peerkey") == 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002892 wpa_printf(MSG_INFO,
2893 "Line %d: Obsolete peerkey parameter ignored", line);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002894#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002895 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2896 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2897 hexstr2bin(pos, bss->mobility_domain,
2898 MOBILITY_DOMAIN_ID_LEN) != 0) {
2899 wpa_printf(MSG_ERROR,
2900 "Line %d: Invalid mobility_domain '%s'",
2901 line, pos);
2902 return 1;
2903 }
2904 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2905 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2906 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2907 wpa_printf(MSG_ERROR,
2908 "Line %d: Invalid r1_key_holder '%s'",
2909 line, pos);
2910 return 1;
2911 }
2912 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002913 /* DEPRECATED: Use ft_r0_key_lifetime instead. */
2914 bss->r0_key_lifetime = atoi(pos) * 60;
2915 } else if (os_strcmp(buf, "ft_r0_key_lifetime") == 0) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002916 bss->r0_key_lifetime = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002917 } else if (os_strcmp(buf, "r1_max_key_lifetime") == 0) {
2918 bss->r1_max_key_lifetime = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002919 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2920 bss->reassociation_deadline = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002921 } else if (os_strcmp(buf, "rkh_pos_timeout") == 0) {
2922 bss->rkh_pos_timeout = atoi(pos);
2923 } else if (os_strcmp(buf, "rkh_neg_timeout") == 0) {
2924 bss->rkh_neg_timeout = atoi(pos);
2925 } else if (os_strcmp(buf, "rkh_pull_timeout") == 0) {
2926 bss->rkh_pull_timeout = atoi(pos);
2927 } else if (os_strcmp(buf, "rkh_pull_retries") == 0) {
2928 bss->rkh_pull_retries = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002929 } else if (os_strcmp(buf, "r0kh") == 0) {
2930 if (add_r0kh(bss, pos) < 0) {
2931 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2932 line, pos);
2933 return 1;
2934 }
2935 } else if (os_strcmp(buf, "r1kh") == 0) {
2936 if (add_r1kh(bss, pos) < 0) {
2937 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2938 line, pos);
2939 return 1;
2940 }
2941 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2942 bss->pmk_r1_push = atoi(pos);
2943 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2944 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002945 } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) {
2946 bss->ft_psk_generate_local = atoi(pos);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002947#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002948#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002949 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2950 os_free(bss->ctrl_interface);
2951 bss->ctrl_interface = os_strdup(pos);
2952 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002953#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002954 struct group *grp;
2955 char *endp;
2956 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002958 grp = getgrnam(group);
2959 if (grp) {
2960 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002961 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002962 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2963 bss->ctrl_interface_gid, group);
2964 return 0;
2965 }
2966
2967 /* Group name not found - try to parse this as gid */
2968 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2969 if (*group == '\0' || *endp != '\0') {
2970 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2971 line, group);
2972 return 1;
2973 }
2974 bss->ctrl_interface_gid_set = 1;
2975 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2976 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002977#endif /* CONFIG_NATIVE_WINDOWS */
2978#endif /* CONFIG_NO_CTRL_IFACE */
2979#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002980 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2981 os_free(bss->radius_server_clients);
2982 bss->radius_server_clients = os_strdup(pos);
2983 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2984 bss->radius_server_auth_port = atoi(pos);
2985 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2986 bss->radius_server_acct_port = atoi(pos);
2987 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2988 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002989#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002990 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2991 bss->use_pae_group_addr = atoi(pos);
2992 } else if (os_strcmp(buf, "hw_mode") == 0) {
2993 if (os_strcmp(pos, "a") == 0)
2994 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2995 else if (os_strcmp(pos, "b") == 0)
2996 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2997 else if (os_strcmp(pos, "g") == 0)
2998 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2999 else if (os_strcmp(pos, "ad") == 0)
3000 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003001 else if (os_strcmp(pos, "any") == 0)
3002 conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003003 else {
3004 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
3005 line, pos);
3006 return 1;
3007 }
3008 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003009 if (os_strcmp(pos, "ad") == 0)
3010 bss->wps_rf_bands = WPS_RF_60GHZ;
3011 else if (os_strcmp(pos, "a") == 0)
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003012 bss->wps_rf_bands = WPS_RF_50GHZ;
3013 else if (os_strcmp(pos, "g") == 0 ||
3014 os_strcmp(pos, "b") == 0)
3015 bss->wps_rf_bands = WPS_RF_24GHZ;
3016 else if (os_strcmp(pos, "ag") == 0 ||
3017 os_strcmp(pos, "ga") == 0)
3018 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
3019 else {
3020 wpa_printf(MSG_ERROR,
3021 "Line %d: unknown wps_rf_band '%s'",
3022 line, pos);
3023 return 1;
3024 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003025 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
3026 conf->acs_exclude_dfs = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003027 } else if (os_strcmp(buf, "channel") == 0) {
3028 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003029#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003030 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
3031 line);
3032 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003033#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003034 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003035 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003036#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003037 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003038 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003039 conf->acs = conf->channel == 0;
3040 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003041 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003042 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003043 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
3044 line);
3045 return 1;
3046 }
3047 } else if (os_strcmp(buf, "beacon_int") == 0) {
3048 int val = atoi(pos);
3049 /* MIB defines range as 1..65535, but very small values
3050 * cause problems with the current implementation.
3051 * Since it is unlikely that this small numbers are
3052 * useful in real life scenarios, do not allow beacon
3053 * period to be set below 15 TU. */
3054 if (val < 15 || val > 65535) {
3055 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
3056 line, val);
3057 return 1;
3058 }
3059 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003060#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003061 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
3062 int val = atoi(pos);
3063 if (val <= 0 || val > 100) {
3064 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
3065 line, val);
3066 return 1;
3067 }
3068 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003069 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
3070 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
3071 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
3072 line);
3073 return -1;
3074 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003075#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003076 } else if (os_strcmp(buf, "dtim_period") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003077 int val = atoi(pos);
3078
3079 if (val < 1 || val > 255) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003080 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
Dmitry Shmidt29333592017-01-09 12:27:11 -08003081 line, val);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003082 return 1;
3083 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08003084 bss->dtim_period = val;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003085 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003086 int val = atoi(pos);
3087
3088 if (val < 0 || val > 100) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003089 wpa_printf(MSG_ERROR,
3090 "Line %d: invalid bss_load_update_period %d",
Roshan Pius3a1667e2018-07-03 15:17:14 -07003091 line, val);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003092 return 1;
3093 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003094 bss->bss_load_update_period = val;
3095 } else if (os_strcmp(buf, "chan_util_avg_period") == 0) {
3096 int val = atoi(pos);
3097
3098 if (val < 0) {
3099 wpa_printf(MSG_ERROR,
3100 "Line %d: invalid chan_util_avg_period",
3101 line);
3102 return 1;
3103 }
3104 bss->chan_util_avg_period = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003105 } else if (os_strcmp(buf, "rts_threshold") == 0) {
3106 conf->rts_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003107 if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003108 wpa_printf(MSG_ERROR,
3109 "Line %d: invalid rts_threshold %d",
3110 line, conf->rts_threshold);
3111 return 1;
3112 }
3113 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
3114 conf->fragm_threshold = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003115 if (conf->fragm_threshold == -1) {
3116 /* allow a value of -1 */
3117 } else if (conf->fragm_threshold < 256 ||
3118 conf->fragm_threshold > 2346) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003119 wpa_printf(MSG_ERROR,
3120 "Line %d: invalid fragm_threshold %d",
3121 line, conf->fragm_threshold);
3122 return 1;
3123 }
3124 } else if (os_strcmp(buf, "send_probe_response") == 0) {
3125 int val = atoi(pos);
3126 if (val != 0 && val != 1) {
3127 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
3128 line, val);
3129 return 1;
3130 }
3131 conf->send_probe_response = val;
3132 } else if (os_strcmp(buf, "supported_rates") == 0) {
3133 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
3134 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3135 line);
3136 return 1;
3137 }
3138 } else if (os_strcmp(buf, "basic_rates") == 0) {
3139 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
3140 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
3141 line);
3142 return 1;
3143 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003144 } else if (os_strcmp(buf, "beacon_rate") == 0) {
3145 int val;
3146
3147 if (os_strncmp(pos, "ht:", 3) == 0) {
3148 val = atoi(pos + 3);
3149 if (val < 0 || val > 31) {
3150 wpa_printf(MSG_ERROR,
3151 "Line %d: invalid beacon_rate HT-MCS %d",
3152 line, val);
3153 return 1;
3154 }
3155 conf->rate_type = BEACON_RATE_HT;
3156 conf->beacon_rate = val;
3157 } else if (os_strncmp(pos, "vht:", 4) == 0) {
3158 val = atoi(pos + 4);
3159 if (val < 0 || val > 9) {
3160 wpa_printf(MSG_ERROR,
3161 "Line %d: invalid beacon_rate VHT-MCS %d",
3162 line, val);
3163 return 1;
3164 }
3165 conf->rate_type = BEACON_RATE_VHT;
3166 conf->beacon_rate = val;
3167 } else {
3168 val = atoi(pos);
3169 if (val < 10 || val > 10000) {
3170 wpa_printf(MSG_ERROR,
3171 "Line %d: invalid legacy beacon_rate %d",
3172 line, val);
3173 return 1;
3174 }
3175 conf->rate_type = BEACON_RATE_LEGACY;
3176 conf->beacon_rate = val;
3177 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003178 } else if (os_strcmp(buf, "preamble") == 0) {
3179 if (atoi(pos))
3180 conf->preamble = SHORT_PREAMBLE;
3181 else
3182 conf->preamble = LONG_PREAMBLE;
3183 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
3184 bss->ignore_broadcast_ssid = atoi(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003185 } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) {
3186 bss->no_probe_resp_if_max_sta = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003187 } else if (os_strcmp(buf, "wep_default_key") == 0) {
3188 bss->ssid.wep.idx = atoi(pos);
3189 if (bss->ssid.wep.idx > 3) {
3190 wpa_printf(MSG_ERROR,
3191 "Invalid wep_default_key index %d",
3192 bss->ssid.wep.idx);
3193 return 1;
3194 }
3195 } else if (os_strcmp(buf, "wep_key0") == 0 ||
3196 os_strcmp(buf, "wep_key1") == 0 ||
3197 os_strcmp(buf, "wep_key2") == 0 ||
3198 os_strcmp(buf, "wep_key3") == 0) {
3199 if (hostapd_config_read_wep(&bss->ssid.wep,
3200 buf[7] - '0', pos)) {
3201 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
3202 line, buf);
3203 return 1;
3204 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003205#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003206 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
3207 bss->ssid.dynamic_vlan = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003208 } else if (os_strcmp(buf, "per_sta_vif") == 0) {
3209 bss->ssid.per_sta_vif = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003210 } else if (os_strcmp(buf, "vlan_file") == 0) {
3211 if (hostapd_config_read_vlan_file(bss, pos)) {
3212 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
3213 line, pos);
3214 return 1;
3215 }
3216 } else if (os_strcmp(buf, "vlan_naming") == 0) {
3217 bss->ssid.vlan_naming = atoi(pos);
3218 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
3219 bss->ssid.vlan_naming < 0) {
3220 wpa_printf(MSG_ERROR,
3221 "Line %d: invalid naming scheme %d",
3222 line, bss->ssid.vlan_naming);
3223 return 1;
3224 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003225#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003226 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003227 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003228 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003229#endif /* CONFIG_FULL_DYNAMIC_VLAN */
3230#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003231 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
3232 conf->ap_table_max_size = atoi(pos);
3233 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
3234 conf->ap_table_expiration_time = atoi(pos);
3235 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
3236 if (hostapd_config_tx_queue(conf, buf, pos)) {
3237 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
3238 line);
3239 return 1;
3240 }
3241 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
3242 os_strcmp(buf, "wmm_enabled") == 0) {
3243 bss->wmm_enabled = atoi(pos);
3244 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
3245 bss->wmm_uapsd = atoi(pos);
3246 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
3247 os_strncmp(buf, "wmm_ac_", 7) == 0) {
3248 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
3249 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
3250 line);
3251 return 1;
3252 }
3253 } else if (os_strcmp(buf, "bss") == 0) {
3254 if (hostapd_config_bss(conf, pos)) {
3255 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
3256 line);
3257 return 1;
3258 }
3259 } else if (os_strcmp(buf, "bssid") == 0) {
3260 if (hwaddr_aton(pos, bss->bssid)) {
3261 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
3262 line);
3263 return 1;
3264 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003265 } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
3266 conf->use_driver_iface_addr = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003267#ifdef CONFIG_IEEE80211W
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003268 } else if (os_strcmp(buf, "ieee80211w") == 0) {
3269 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003270 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
3271 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
3272 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
3273 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
3274 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
3275 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
3276 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
3277 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
3278 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
3279 } else {
3280 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
3281 line, pos);
3282 return 1;
3283 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003284 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
3285 bss->assoc_sa_query_max_timeout = atoi(pos);
3286 if (bss->assoc_sa_query_max_timeout == 0) {
3287 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
3288 line);
3289 return 1;
3290 }
3291 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
3292 bss->assoc_sa_query_retry_timeout = atoi(pos);
3293 if (bss->assoc_sa_query_retry_timeout == 0) {
3294 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
3295 line);
3296 return 1;
3297 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298#endif /* CONFIG_IEEE80211W */
3299#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003300 } else if (os_strcmp(buf, "ieee80211n") == 0) {
3301 conf->ieee80211n = atoi(pos);
3302 } else if (os_strcmp(buf, "ht_capab") == 0) {
3303 if (hostapd_config_ht_capab(conf, pos) < 0) {
3304 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
3305 line);
3306 return 1;
3307 }
3308 } else if (os_strcmp(buf, "require_ht") == 0) {
3309 conf->require_ht = atoi(pos);
3310 } else if (os_strcmp(buf, "obss_interval") == 0) {
3311 conf->obss_interval = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003312#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003313#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003314 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
3315 conf->ieee80211ac = atoi(pos);
3316 } else if (os_strcmp(buf, "vht_capab") == 0) {
3317 if (hostapd_config_vht_capab(conf, pos) < 0) {
3318 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
3319 line);
3320 return 1;
3321 }
3322 } else if (os_strcmp(buf, "require_vht") == 0) {
3323 conf->require_vht = atoi(pos);
3324 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
3325 conf->vht_oper_chwidth = atoi(pos);
3326 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
3327 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
3328 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
3329 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003330 } else if (os_strcmp(buf, "vendor_vht") == 0) {
3331 bss->vendor_vht = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003332 } else if (os_strcmp(buf, "use_sta_nsts") == 0) {
3333 bss->use_sta_nsts = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003334#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003335#ifdef CONFIG_IEEE80211AX
3336 } else if (os_strcmp(buf, "ieee80211ax") == 0) {
3337 conf->ieee80211ax = atoi(pos);
3338 } else if (os_strcmp(buf, "he_su_beamformer") == 0) {
3339 conf->he_phy_capab.he_su_beamformer = atoi(pos);
3340 } else if (os_strcmp(buf, "he_su_beamformee") == 0) {
3341 conf->he_phy_capab.he_su_beamformee = atoi(pos);
3342 } else if (os_strcmp(buf, "he_mu_beamformer") == 0) {
3343 conf->he_phy_capab.he_mu_beamformer = atoi(pos);
3344 } else if (os_strcmp(buf, "he_bss_color") == 0) {
3345 conf->he_op.he_bss_color = atoi(pos);
3346 } else if (os_strcmp(buf, "he_default_pe_duration") == 0) {
3347 conf->he_op.he_default_pe_duration = atoi(pos);
3348 } else if (os_strcmp(buf, "he_twt_required") == 0) {
3349 conf->he_op.he_twt_required = atoi(pos);
3350 } else if (os_strcmp(buf, "he_rts_threshold") == 0) {
3351 conf->he_op.he_rts_threshold = atoi(pos);
3352#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003353 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
3354 bss->max_listen_interval = atoi(pos);
3355 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
3356 bss->disable_pmksa_caching = atoi(pos);
3357 } else if (os_strcmp(buf, "okc") == 0) {
3358 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003360 } else if (os_strcmp(buf, "wps_state") == 0) {
3361 bss->wps_state = atoi(pos);
3362 if (bss->wps_state < 0 || bss->wps_state > 2) {
3363 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
3364 line);
3365 return 1;
3366 }
3367 } else if (os_strcmp(buf, "wps_independent") == 0) {
3368 bss->wps_independent = atoi(pos);
3369 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
3370 bss->ap_setup_locked = atoi(pos);
3371 } else if (os_strcmp(buf, "uuid") == 0) {
3372 if (uuid_str2bin(pos, bss->uuid)) {
3373 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3374 return 1;
3375 }
3376 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
3377 os_free(bss->wps_pin_requests);
3378 bss->wps_pin_requests = os_strdup(pos);
3379 } else if (os_strcmp(buf, "device_name") == 0) {
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003380 if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003381 wpa_printf(MSG_ERROR, "Line %d: Too long "
3382 "device_name", line);
3383 return 1;
3384 }
3385 os_free(bss->device_name);
3386 bss->device_name = os_strdup(pos);
3387 } else if (os_strcmp(buf, "manufacturer") == 0) {
3388 if (os_strlen(pos) > 64) {
3389 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
3390 line);
3391 return 1;
3392 }
3393 os_free(bss->manufacturer);
3394 bss->manufacturer = os_strdup(pos);
3395 } else if (os_strcmp(buf, "model_name") == 0) {
3396 if (os_strlen(pos) > 32) {
3397 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
3398 line);
3399 return 1;
3400 }
3401 os_free(bss->model_name);
3402 bss->model_name = os_strdup(pos);
3403 } else if (os_strcmp(buf, "model_number") == 0) {
3404 if (os_strlen(pos) > 32) {
3405 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
3406 line);
3407 return 1;
3408 }
3409 os_free(bss->model_number);
3410 bss->model_number = os_strdup(pos);
3411 } else if (os_strcmp(buf, "serial_number") == 0) {
3412 if (os_strlen(pos) > 32) {
3413 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
3414 line);
3415 return 1;
3416 }
3417 os_free(bss->serial_number);
3418 bss->serial_number = os_strdup(pos);
3419 } else if (os_strcmp(buf, "device_type") == 0) {
3420 if (wps_dev_type_str2bin(pos, bss->device_type))
3421 return 1;
3422 } else if (os_strcmp(buf, "config_methods") == 0) {
3423 os_free(bss->config_methods);
3424 bss->config_methods = os_strdup(pos);
3425 } else if (os_strcmp(buf, "os_version") == 0) {
3426 if (hexstr2bin(pos, bss->os_version, 4)) {
3427 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
3428 line);
3429 return 1;
3430 }
3431 } else if (os_strcmp(buf, "ap_pin") == 0) {
3432 os_free(bss->ap_pin);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003433 if (*pos == '\0')
3434 bss->ap_pin = NULL;
3435 else
3436 bss->ap_pin = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003437 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
3438 bss->skip_cred_build = atoi(pos);
3439 } else if (os_strcmp(buf, "extra_cred") == 0) {
3440 os_free(bss->extra_cred);
3441 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
3442 if (bss->extra_cred == NULL) {
3443 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
3444 line, pos);
3445 return 1;
3446 }
3447 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
3448 bss->wps_cred_processing = atoi(pos);
3449 } else if (os_strcmp(buf, "ap_settings") == 0) {
3450 os_free(bss->ap_settings);
3451 bss->ap_settings =
3452 (u8 *) os_readfile(pos, &bss->ap_settings_len);
3453 if (bss->ap_settings == NULL) {
3454 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
3455 line, pos);
3456 return 1;
3457 }
3458 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07003459 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003460 bss->upnp_iface = os_strdup(pos);
3461 } else if (os_strcmp(buf, "friendly_name") == 0) {
3462 os_free(bss->friendly_name);
3463 bss->friendly_name = os_strdup(pos);
3464 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
3465 os_free(bss->manufacturer_url);
3466 bss->manufacturer_url = os_strdup(pos);
3467 } else if (os_strcmp(buf, "model_description") == 0) {
3468 os_free(bss->model_description);
3469 bss->model_description = os_strdup(pos);
3470 } else if (os_strcmp(buf, "model_url") == 0) {
3471 os_free(bss->model_url);
3472 bss->model_url = os_strdup(pos);
3473 } else if (os_strcmp(buf, "upc") == 0) {
3474 os_free(bss->upc);
3475 bss->upc = os_strdup(pos);
3476 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
3477 bss->pbc_in_m1 = atoi(pos);
3478 } else if (os_strcmp(buf, "server_id") == 0) {
3479 os_free(bss->server_id);
3480 bss->server_id = os_strdup(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003481#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003482 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
3483 bss->wps_nfc_dev_pw_id = atoi(pos);
3484 if (bss->wps_nfc_dev_pw_id < 0x10 ||
3485 bss->wps_nfc_dev_pw_id > 0xffff) {
3486 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
3487 line);
3488 return 1;
3489 }
3490 bss->wps_nfc_pw_from_config = 1;
3491 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
3492 wpabuf_free(bss->wps_nfc_dh_pubkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003493 bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003494 bss->wps_nfc_pw_from_config = 1;
3495 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
3496 wpabuf_free(bss->wps_nfc_dh_privkey);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003497 bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003498 bss->wps_nfc_pw_from_config = 1;
3499 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
3500 wpabuf_free(bss->wps_nfc_dev_pw);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003501 bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003502 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003503#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003504#endif /* CONFIG_WPS */
3505#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003506 } else if (os_strcmp(buf, "manage_p2p") == 0) {
3507 if (atoi(pos))
3508 bss->p2p |= P2P_MANAGE;
3509 else
3510 bss->p2p &= ~P2P_MANAGE;
3511 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
3512 if (atoi(pos))
3513 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
3514 else
3515 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003516#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003517 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
3518 bss->disassoc_low_ack = atoi(pos);
3519 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
3520 if (atoi(pos))
3521 bss->tdls |= TDLS_PROHIBIT;
3522 else
3523 bss->tdls &= ~TDLS_PROHIBIT;
3524 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
3525 if (atoi(pos))
3526 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
3527 else
3528 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003529#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003530 } else if (os_strcmp(buf, "rsn_testing") == 0) {
3531 extern int rsn_testing;
3532 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003533#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003534 } else if (os_strcmp(buf, "time_advertisement") == 0) {
3535 bss->time_advertisement = atoi(pos);
3536 } else if (os_strcmp(buf, "time_zone") == 0) {
3537 size_t tz_len = os_strlen(pos);
3538 if (tz_len < 4 || tz_len > 255) {
3539 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
3540 line);
3541 return 1;
3542 }
3543 os_free(bss->time_zone);
3544 bss->time_zone = os_strdup(pos);
3545 if (bss->time_zone == NULL)
3546 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003547#ifdef CONFIG_WNM_AP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003548 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3549 bss->wnm_sleep_mode = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003550 } else if (os_strcmp(buf, "wnm_sleep_mode_no_keys") == 0) {
3551 bss->wnm_sleep_mode_no_keys = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003552 } else if (os_strcmp(buf, "bss_transition") == 0) {
3553 bss->bss_transition = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003554#endif /* CONFIG_WNM_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003555#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003556 } else if (os_strcmp(buf, "interworking") == 0) {
3557 bss->interworking = atoi(pos);
3558 } else if (os_strcmp(buf, "access_network_type") == 0) {
3559 bss->access_network_type = atoi(pos);
3560 if (bss->access_network_type < 0 ||
3561 bss->access_network_type > 15) {
3562 wpa_printf(MSG_ERROR,
3563 "Line %d: invalid access_network_type",
3564 line);
3565 return 1;
3566 }
3567 } else if (os_strcmp(buf, "internet") == 0) {
3568 bss->internet = atoi(pos);
3569 } else if (os_strcmp(buf, "asra") == 0) {
3570 bss->asra = atoi(pos);
3571 } else if (os_strcmp(buf, "esr") == 0) {
3572 bss->esr = atoi(pos);
3573 } else if (os_strcmp(buf, "uesa") == 0) {
3574 bss->uesa = atoi(pos);
3575 } else if (os_strcmp(buf, "venue_group") == 0) {
3576 bss->venue_group = atoi(pos);
3577 bss->venue_info_set = 1;
3578 } else if (os_strcmp(buf, "venue_type") == 0) {
3579 bss->venue_type = atoi(pos);
3580 bss->venue_info_set = 1;
3581 } else if (os_strcmp(buf, "hessid") == 0) {
3582 if (hwaddr_aton(pos, bss->hessid)) {
3583 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3584 return 1;
3585 }
3586 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3587 if (parse_roaming_consortium(bss, pos, line) < 0)
3588 return 1;
3589 } else if (os_strcmp(buf, "venue_name") == 0) {
3590 if (parse_venue_name(bss, pos, line) < 0)
3591 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003592 } else if (os_strcmp(buf, "venue_url") == 0) {
3593 if (parse_venue_url(bss, pos, line) < 0)
3594 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003595 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3596 u8 auth_type;
3597 u16 redirect_url_len;
3598 if (hexstr2bin(pos, &auth_type, 1)) {
3599 wpa_printf(MSG_ERROR,
3600 "Line %d: Invalid network_auth_type '%s'",
3601 line, pos);
3602 return 1;
3603 }
3604 if (auth_type == 0 || auth_type == 2)
3605 redirect_url_len = os_strlen(pos + 2);
3606 else
3607 redirect_url_len = 0;
3608 os_free(bss->network_auth_type);
3609 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3610 if (bss->network_auth_type == NULL)
3611 return 1;
3612 *bss->network_auth_type = auth_type;
3613 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3614 if (redirect_url_len)
3615 os_memcpy(bss->network_auth_type + 3, pos + 2,
3616 redirect_url_len);
3617 bss->network_auth_type_len = 3 + redirect_url_len;
3618 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3619 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3620 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3621 line, pos);
3622 bss->ipaddr_type_configured = 0;
3623 return 1;
3624 }
3625 bss->ipaddr_type_configured = 1;
3626 } else if (os_strcmp(buf, "domain_name") == 0) {
3627 int j, num_domains, domain_len, domain_list_len = 0;
3628 char *tok_start, *tok_prev;
3629 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003630
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003631 domain_list_len = os_strlen(pos) + 1;
3632 domain_list = os_malloc(domain_list_len);
3633 if (domain_list == NULL)
3634 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003635
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003636 domain_ptr = domain_list;
3637 tok_prev = pos;
3638 num_domains = 1;
3639 while ((tok_prev = os_strchr(tok_prev, ','))) {
3640 num_domains++;
3641 tok_prev++;
3642 }
3643 tok_prev = pos;
3644 for (j = 0; j < num_domains; j++) {
3645 tok_start = os_strchr(tok_prev, ',');
3646 if (tok_start) {
3647 domain_len = tok_start - tok_prev;
3648 *domain_ptr = domain_len;
3649 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3650 domain_ptr += domain_len + 1;
3651 tok_prev = ++tok_start;
3652 } else {
3653 domain_len = os_strlen(tok_prev);
3654 *domain_ptr = domain_len;
3655 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3656 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003657 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003658 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003659
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003660 os_free(bss->domain_name);
3661 bss->domain_name = domain_list;
3662 bss->domain_name_len = domain_list_len;
3663 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3664 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3665 return 1;
3666 } else if (os_strcmp(buf, "nai_realm") == 0) {
3667 if (parse_nai_realm(bss, pos, line) < 0)
3668 return 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003669 } else if (os_strcmp(buf, "anqp_elem") == 0) {
3670 if (parse_anqp_elem(bss, pos, line) < 0)
3671 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003672 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003673 int val = atoi(pos);
3674
3675 if (val <= 0) {
3676 wpa_printf(MSG_ERROR,
3677 "Line %d: Invalid gas_frag_limit '%s'",
3678 line, pos);
3679 return 1;
3680 }
3681 bss->gas_frag_limit = val;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003682 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3683 bss->gas_comeback_delay = atoi(pos);
3684 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3685 if (parse_qos_map_set(bss, pos, line) < 0)
3686 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003687#endif /* CONFIG_INTERWORKING */
3688#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003689 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3690 os_free(bss->dump_msk_file);
3691 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003692#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08003693#ifdef CONFIG_PROXYARP
3694 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3695 bss->proxy_arp = atoi(pos);
3696#endif /* CONFIG_PROXYARP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003697#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003698 } else if (os_strcmp(buf, "hs20") == 0) {
3699 bss->hs20 = atoi(pos);
3700 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3701 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07003702 } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) {
3703 bss->na_mcast_to_ucast = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003704 } else if (os_strcmp(buf, "osen") == 0) {
3705 bss->osen = atoi(pos);
3706 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3707 bss->anqp_domain_id = atoi(pos);
3708 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3709 bss->hs20_deauth_req_timeout = atoi(pos);
3710 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3711 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3712 return 1;
3713 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3714 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3715 return 1;
3716 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3717 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3718 return 1;
3719 }
3720 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3721 u8 *oper_class;
3722 size_t oper_class_len;
3723 oper_class_len = os_strlen(pos);
3724 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3725 wpa_printf(MSG_ERROR,
3726 "Line %d: Invalid hs20_operating_class '%s'",
3727 line, pos);
3728 return 1;
3729 }
3730 oper_class_len /= 2;
3731 oper_class = os_malloc(oper_class_len);
3732 if (oper_class == NULL)
3733 return 1;
3734 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3735 wpa_printf(MSG_ERROR,
3736 "Line %d: Invalid hs20_operating_class '%s'",
3737 line, pos);
3738 os_free(oper_class);
3739 return 1;
3740 }
3741 os_free(bss->hs20_operating_class);
3742 bss->hs20_operating_class = oper_class;
3743 bss->hs20_operating_class_len = oper_class_len;
3744 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3745 if (hs20_parse_icon(bss, pos) < 0) {
3746 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3747 line, pos);
3748 return 1;
3749 }
3750 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3751 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
3752 return 1;
3753 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3754 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
3755 return 1;
3756 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3757 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
3758 return 1;
3759 } else if (os_strcmp(buf, "osu_nai") == 0) {
3760 if (hs20_parse_osu_nai(bss, pos, line) < 0)
3761 return 1;
3762 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3763 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
3764 return 1;
3765 } else if (os_strcmp(buf, "osu_icon") == 0) {
3766 if (hs20_parse_osu_icon(bss, pos, line) < 0)
3767 return 1;
3768 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3769 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
3770 return 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003771 } else if (os_strcmp(buf, "operator_icon") == 0) {
3772 if (hs20_parse_operator_icon(bss, pos, line) < 0)
3773 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003774 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3775 os_free(bss->subscr_remediation_url);
3776 bss->subscr_remediation_url = os_strdup(pos);
3777 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3778 bss->subscr_remediation_method = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003779 } else if (os_strcmp(buf, "hs20_t_c_filename") == 0) {
3780 os_free(bss->t_c_filename);
3781 bss->t_c_filename = os_strdup(pos);
3782 } else if (os_strcmp(buf, "hs20_t_c_timestamp") == 0) {
3783 bss->t_c_timestamp = strtol(pos, NULL, 0);
3784 } else if (os_strcmp(buf, "hs20_t_c_server_url") == 0) {
3785 os_free(bss->t_c_server_url);
3786 bss->t_c_server_url = os_strdup(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003787#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003788#ifdef CONFIG_MBO
3789 } else if (os_strcmp(buf, "mbo") == 0) {
3790 bss->mbo_enabled = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003791 } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) {
3792 bss->mbo_cell_data_conn_pref = atoi(pos);
3793 } else if (os_strcmp(buf, "oce") == 0) {
3794 bss->oce = atoi(pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003795#endif /* CONFIG_MBO */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003796#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003797#define PARSE_TEST_PROBABILITY(_val) \
3798 } else if (os_strcmp(buf, #_val) == 0) { \
3799 char *end; \
3800 \
3801 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003802 if (*end || conf->_val < 0.0 || \
3803 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003804 wpa_printf(MSG_ERROR, \
3805 "Line %d: Invalid value '%s'", \
3806 line, pos); \
3807 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003808 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003809 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3810 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3811 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3812 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3813 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003814 } else if (os_strcmp(buf, "ecsa_ie_only") == 0) {
3815 conf->ecsa_ie_only = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003816 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3817 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3818 pos = os_strchr(pos, ':');
3819 if (pos == NULL) {
3820 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3821 line);
3822 return 1;
3823 }
3824 pos++;
3825 bss->bss_load_test[2] = atoi(pos);
3826 pos = os_strchr(pos, ':');
3827 if (pos == NULL) {
3828 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3829 line);
3830 return 1;
3831 }
3832 pos++;
3833 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3834 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003835 } else if (os_strcmp(buf, "radio_measurements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003836 /*
3837 * DEPRECATED: This parameter will be removed in the future.
3838 * Use rrm_neighbor_report instead.
3839 */
3840 int val = atoi(pos);
3841
3842 if (val & BIT(0))
3843 bss->radio_measurements[0] |=
3844 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003845 } else if (os_strcmp(buf, "own_ie_override") == 0) {
3846 struct wpabuf *tmp;
3847 size_t len = os_strlen(pos) / 2;
3848
3849 tmp = wpabuf_alloc(len);
3850 if (!tmp)
3851 return 1;
3852
3853 if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
3854 wpabuf_free(tmp);
3855 wpa_printf(MSG_ERROR,
3856 "Line %d: Invalid own_ie_override '%s'",
3857 line, pos);
3858 return 1;
3859 }
3860
3861 wpabuf_free(bss->own_ie_override);
3862 bss->own_ie_override = tmp;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003863 } else if (os_strcmp(buf, "sae_reflection_attack") == 0) {
3864 bss->sae_reflection_attack = atoi(pos);
3865 } else if (os_strcmp(buf, "sae_commit_override") == 0) {
3866 wpabuf_free(bss->sae_commit_override);
3867 bss->sae_commit_override = wpabuf_parse_bin(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003868#ifdef CONFIG_SAE
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003869 } else if (os_strcmp(buf, "sae_password") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003870 if (parse_sae_password(bss, pos) < 0) {
3871 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_password",
3872 line);
3873 return 1;
3874 }
3875#endif /* CONFIG_SAE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003876#endif /* CONFIG_TESTING_OPTIONS */
3877 } else if (os_strcmp(buf, "vendor_elements") == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003878 if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003879 return 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003880 } else if (os_strcmp(buf, "assocresp_elements") == 0) {
3881 if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003882 return 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003883 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3884 bss->sae_anti_clogging_threshold = atoi(pos);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003885 } else if (os_strcmp(buf, "sae_sync") == 0) {
3886 bss->sae_sync = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003887 } else if (os_strcmp(buf, "sae_groups") == 0) {
3888 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3889 wpa_printf(MSG_ERROR,
3890 "Line %d: Invalid sae_groups value '%s'",
3891 line, pos);
3892 return 1;
3893 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003894 } else if (os_strcmp(buf, "sae_require_mfp") == 0) {
3895 bss->sae_require_mfp = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003896 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3897 int val = atoi(pos);
3898 if (val < 0 || val > 255) {
3899 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3900 line, val);
3901 return 1;
3902 }
3903 conf->local_pwr_constraint = val;
3904 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3905 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07003906 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3907 os_free(bss->wowlan_triggers);
3908 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003909#ifdef CONFIG_FST
3910 } else if (os_strcmp(buf, "fst_group_id") == 0) {
3911 size_t len = os_strlen(pos);
3912
3913 if (!len || len >= sizeof(conf->fst_cfg.group_id)) {
3914 wpa_printf(MSG_ERROR,
3915 "Line %d: Invalid fst_group_id value '%s'",
3916 line, pos);
3917 return 1;
3918 }
3919
3920 if (conf->fst_cfg.group_id[0]) {
3921 wpa_printf(MSG_ERROR,
3922 "Line %d: Duplicate fst_group value '%s'",
3923 line, pos);
3924 return 1;
3925 }
3926
3927 os_strlcpy(conf->fst_cfg.group_id, pos,
3928 sizeof(conf->fst_cfg.group_id));
3929 } else if (os_strcmp(buf, "fst_priority") == 0) {
3930 char *endp;
3931 long int val;
3932
3933 if (!*pos) {
3934 wpa_printf(MSG_ERROR,
3935 "Line %d: fst_priority value not supplied (expected 1..%u)",
3936 line, FST_MAX_PRIO_VALUE);
3937 return -1;
3938 }
3939
3940 val = strtol(pos, &endp, 0);
3941 if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) {
3942 wpa_printf(MSG_ERROR,
3943 "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)",
3944 line, val, pos, FST_MAX_PRIO_VALUE);
3945 return 1;
3946 }
3947 conf->fst_cfg.priority = (u8) val;
3948 } else if (os_strcmp(buf, "fst_llt") == 0) {
3949 char *endp;
3950 long int val;
3951
3952 if (!*pos) {
3953 wpa_printf(MSG_ERROR,
3954 "Line %d: fst_llt value not supplied (expected 1..%u)",
3955 line, FST_MAX_LLT_MS);
3956 return -1;
3957 }
3958 val = strtol(pos, &endp, 0);
Dmitry Shmidte4663042016-04-04 10:07:49 -07003959 if (*endp || val < 1 ||
3960 (unsigned long int) val > FST_MAX_LLT_MS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003961 wpa_printf(MSG_ERROR,
3962 "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)",
3963 line, val, pos, FST_MAX_LLT_MS);
3964 return 1;
3965 }
3966 conf->fst_cfg.llt = (u32) val;
3967#endif /* CONFIG_FST */
3968 } else if (os_strcmp(buf, "track_sta_max_num") == 0) {
3969 conf->track_sta_max_num = atoi(pos);
3970 } else if (os_strcmp(buf, "track_sta_max_age") == 0) {
3971 conf->track_sta_max_age = atoi(pos);
3972 } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) {
3973 os_free(bss->no_probe_resp_if_seen_on);
3974 bss->no_probe_resp_if_seen_on = os_strdup(pos);
3975 } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) {
3976 os_free(bss->no_auth_if_seen_on);
3977 bss->no_auth_if_seen_on = os_strdup(pos);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003978 } else if (os_strcmp(buf, "lci") == 0) {
3979 wpabuf_free(conf->lci);
3980 conf->lci = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003981 if (conf->lci && wpabuf_len(conf->lci) == 0) {
3982 wpabuf_free(conf->lci);
3983 conf->lci = NULL;
3984 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003985 } else if (os_strcmp(buf, "civic") == 0) {
3986 wpabuf_free(conf->civic);
3987 conf->civic = wpabuf_parse_bin(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003988 if (conf->civic && wpabuf_len(conf->civic) == 0) {
3989 wpabuf_free(conf->civic);
3990 conf->civic = NULL;
3991 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003992 } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) {
3993 if (atoi(pos))
3994 bss->radio_measurements[0] |=
3995 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -08003996 } else if (os_strcmp(buf, "rrm_beacon_report") == 0) {
3997 if (atoi(pos))
3998 bss->radio_measurements[0] |=
3999 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
4000 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
4001 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004002 } else if (os_strcmp(buf, "gas_address3") == 0) {
4003 bss->gas_address3 = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004004 } else if (os_strcmp(buf, "stationary_ap") == 0) {
4005 conf->stationary_ap = atoi(pos);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07004006 } else if (os_strcmp(buf, "ftm_responder") == 0) {
4007 bss->ftm_responder = atoi(pos);
4008 } else if (os_strcmp(buf, "ftm_initiator") == 0) {
4009 bss->ftm_initiator = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004010#ifdef CONFIG_FILS
4011 } else if (os_strcmp(buf, "fils_cache_id") == 0) {
4012 if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) {
4013 wpa_printf(MSG_ERROR,
4014 "Line %d: Invalid fils_cache_id '%s'",
4015 line, pos);
4016 return 1;
4017 }
4018 bss->fils_cache_id_set = 1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004019 } else if (os_strcmp(buf, "fils_realm") == 0) {
4020 if (parse_fils_realm(bss, pos) < 0)
4021 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004022 } else if (os_strcmp(buf, "fils_dh_group") == 0) {
4023 bss->fils_dh_group = atoi(pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004024 } else if (os_strcmp(buf, "dhcp_server") == 0) {
4025 if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) {
4026 wpa_printf(MSG_ERROR,
4027 "Line %d: invalid IP address '%s'",
4028 line, pos);
4029 return 1;
4030 }
4031 } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) {
4032 bss->dhcp_rapid_commit_proxy = atoi(pos);
4033 } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) {
4034 bss->fils_hlp_wait_time = atoi(pos);
4035 } else if (os_strcmp(buf, "dhcp_server_port") == 0) {
4036 bss->dhcp_server_port = atoi(pos);
4037 } else if (os_strcmp(buf, "dhcp_relay_port") == 0) {
4038 bss->dhcp_relay_port = atoi(pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004039#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004040 } else if (os_strcmp(buf, "multicast_to_unicast") == 0) {
4041 bss->multicast_to_unicast = atoi(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004042 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
4043 bss->broadcast_deauth = atoi(pos);
4044#ifdef CONFIG_DPP
4045 } else if (os_strcmp(buf, "dpp_connector") == 0) {
4046 os_free(bss->dpp_connector);
4047 bss->dpp_connector = os_strdup(pos);
4048 } else if (os_strcmp(buf, "dpp_netaccesskey") == 0) {
4049 if (parse_wpabuf_hex(line, buf, &bss->dpp_netaccesskey, pos))
4050 return 1;
4051 } else if (os_strcmp(buf, "dpp_netaccesskey_expiry") == 0) {
4052 bss->dpp_netaccesskey_expiry = strtol(pos, NULL, 0);
4053 } else if (os_strcmp(buf, "dpp_csign") == 0) {
4054 if (parse_wpabuf_hex(line, buf, &bss->dpp_csign, pos))
4055 return 1;
4056#endif /* CONFIG_DPP */
4057#ifdef CONFIG_OWE
4058 } else if (os_strcmp(buf, "owe_transition_bssid") == 0) {
4059 if (hwaddr_aton(pos, bss->owe_transition_bssid)) {
4060 wpa_printf(MSG_ERROR,
4061 "Line %d: invalid owe_transition_bssid",
4062 line);
4063 return 1;
4064 }
4065 } else if (os_strcmp(buf, "owe_transition_ssid") == 0) {
4066 size_t slen;
4067 char *str = wpa_config_parse_string(pos, &slen);
4068
4069 if (!str || slen < 1 || slen > SSID_MAX_LEN) {
4070 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
4071 line, pos);
4072 os_free(str);
4073 return 1;
4074 }
4075 os_memcpy(bss->owe_transition_ssid, str, slen);
4076 bss->owe_transition_ssid_len = slen;
4077 os_free(str);
4078 } else if (os_strcmp(buf, "owe_transition_ifname") == 0) {
4079 os_strlcpy(bss->owe_transition_ifname, pos,
4080 sizeof(bss->owe_transition_ifname));
4081 } else if (os_strcmp(buf, "owe_groups") == 0) {
4082 if (hostapd_parse_intlist(&bss->owe_groups, pos)) {
4083 wpa_printf(MSG_ERROR,
4084 "Line %d: Invalid owe_groups value '%s'",
4085 line, pos);
4086 return 1;
4087 }
4088#endif /* CONFIG_OWE */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004089 } else {
4090 wpa_printf(MSG_ERROR,
4091 "Line %d: unknown configuration item '%s'",
4092 line, buf);
4093 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004094 }
4095
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07004096 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004097}
4098
4099
Dmitry Shmidt04949592012-07-19 12:16:46 -07004100/**
4101 * hostapd_config_read - Read and parse a configuration file
4102 * @fname: Configuration file name (including path, if needed)
4103 * Returns: Allocated configuration data structure
4104 */
4105struct hostapd_config * hostapd_config_read(const char *fname)
4106{
4107 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004108 FILE *f;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004109 char buf[4096], *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004110 int line = 0;
4111 int errors = 0;
4112 size_t i;
4113
4114 f = fopen(fname, "r");
4115 if (f == NULL) {
4116 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
4117 "for reading.", fname);
4118 return NULL;
4119 }
4120
4121 conf = hostapd_config_defaults();
4122 if (conf == NULL) {
4123 fclose(f);
4124 return NULL;
4125 }
4126
4127 /* set default driver based on configuration */
4128 conf->driver = wpa_drivers[0];
4129 if (conf->driver == NULL) {
4130 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
4131 hostapd_config_free(conf);
4132 fclose(f);
4133 return NULL;
4134 }
4135
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004136 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07004137
4138 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004139 struct hostapd_bss_config *bss;
4140
Dmitry Shmidt04949592012-07-19 12:16:46 -07004141 bss = conf->last_bss;
4142 line++;
4143
4144 if (buf[0] == '#')
4145 continue;
4146 pos = buf;
4147 while (*pos != '\0') {
4148 if (*pos == '\n') {
4149 *pos = '\0';
4150 break;
4151 }
4152 pos++;
4153 }
4154 if (buf[0] == '\0')
4155 continue;
4156
4157 pos = os_strchr(buf, '=');
4158 if (pos == NULL) {
4159 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
4160 line, buf);
4161 errors++;
4162 continue;
4163 }
4164 *pos = '\0';
4165 pos++;
4166 errors += hostapd_config_fill(conf, bss, buf, pos, line);
4167 }
4168
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 fclose(f);
4170
Dmitry Shmidt04949592012-07-19 12:16:46 -07004171 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004172 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004173
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004174 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004175 errors++;
4176
4177#ifndef WPA_IGNORE_CONFIG_ERRORS
4178 if (errors) {
4179 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
4180 "'%s'", errors, fname);
4181 hostapd_config_free(conf);
4182 conf = NULL;
4183 }
4184#endif /* WPA_IGNORE_CONFIG_ERRORS */
4185
4186 return conf;
4187}
Dmitry Shmidt04949592012-07-19 12:16:46 -07004188
4189
4190int hostapd_set_iface(struct hostapd_config *conf,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004191 struct hostapd_bss_config *bss, const char *field,
4192 char *value)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004193{
4194 int errors;
4195 size_t i;
4196
4197 errors = hostapd_config_fill(conf, bss, field, value, 0);
4198 if (errors) {
4199 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
4200 "to value '%s'", field, value);
4201 return -1;
4202 }
4203
4204 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07004205 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004206
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004207 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004208 wpa_printf(MSG_ERROR, "Configuration check failed");
4209 return -1;
4210 }
4211
4212 return 0;
4213}