blob: 7cbb46b46853df45668847e5aa3b56938bebebb7 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, 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"
17#include "drivers/driver.h"
18#include "eap_server/eap.h"
19#include "radius/radius_client.h"
20#include "ap/wpa_auth.h"
21#include "ap/ap_config.h"
22#include "config_file.h"
23
24
Dmitry Shmidt818ea482014-03-10 13:15:21 -070025#ifndef CONFIG_NO_RADIUS
26#ifdef EAP_SERVER
27static struct hostapd_radius_attr *
28hostapd_parse_radius_attr(const char *value);
29#endif /* EAP_SERVER */
30#endif /* CONFIG_NO_RADIUS */
31
32
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#ifndef CONFIG_NO_VLAN
34static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
35 const char *fname)
36{
37 FILE *f;
38 char buf[128], *pos, *pos2;
39 int line = 0, vlan_id;
40 struct hostapd_vlan *vlan;
41
42 f = fopen(fname, "r");
43 if (!f) {
44 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
45 return -1;
46 }
47
48 while (fgets(buf, sizeof(buf), f)) {
49 line++;
50
51 if (buf[0] == '#')
52 continue;
53 pos = buf;
54 while (*pos != '\0') {
55 if (*pos == '\n') {
56 *pos = '\0';
57 break;
58 }
59 pos++;
60 }
61 if (buf[0] == '\0')
62 continue;
63
64 if (buf[0] == '*') {
65 vlan_id = VLAN_ID_WILDCARD;
66 pos = buf + 1;
67 } else {
68 vlan_id = strtol(buf, &pos, 10);
69 if (buf == pos || vlan_id < 1 ||
70 vlan_id > MAX_VLAN_ID) {
71 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
72 "line %d in '%s'", line, fname);
73 fclose(f);
74 return -1;
75 }
76 }
77
78 while (*pos == ' ' || *pos == '\t')
79 pos++;
80 pos2 = pos;
81 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
82 pos2++;
83 *pos2 = '\0';
84 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
85 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
86 "in '%s'", line, fname);
87 fclose(f);
88 return -1;
89 }
90
Dmitry Shmidt4b060592013-04-29 16:42:49 -070091 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092 if (vlan == NULL) {
93 wpa_printf(MSG_ERROR, "Out of memory while reading "
94 "VLAN interfaces from '%s'", fname);
95 fclose(f);
96 return -1;
97 }
98
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099 vlan->vlan_id = vlan_id;
100 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700101 vlan->next = bss->vlan;
102 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 }
104
105 fclose(f);
106
107 return 0;
108}
109#endif /* CONFIG_NO_VLAN */
110
111
112static int hostapd_acl_comp(const void *a, const void *b)
113{
114 const struct mac_acl_entry *aa = a;
115 const struct mac_acl_entry *bb = b;
116 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
117}
118
119
120static int hostapd_config_read_maclist(const char *fname,
121 struct mac_acl_entry **acl, int *num)
122{
123 FILE *f;
124 char buf[128], *pos;
125 int line = 0;
126 u8 addr[ETH_ALEN];
127 struct mac_acl_entry *newacl;
128 int vlan_id;
129
130 if (!fname)
131 return 0;
132
133 f = fopen(fname, "r");
134 if (!f) {
135 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
136 return -1;
137 }
138
139 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800140 int i, rem = 0;
141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142 line++;
143
144 if (buf[0] == '#')
145 continue;
146 pos = buf;
147 while (*pos != '\0') {
148 if (*pos == '\n') {
149 *pos = '\0';
150 break;
151 }
152 pos++;
153 }
154 if (buf[0] == '\0')
155 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800156 pos = buf;
157 if (buf[0] == '-') {
158 rem = 1;
159 pos++;
160 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800162 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700163 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800164 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700165 fclose(f);
166 return -1;
167 }
168
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800169 if (rem) {
170 i = 0;
171 while (i < *num) {
172 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
173 0) {
174 os_remove_in_array(*acl, *num,
175 sizeof(**acl), i);
176 (*num)--;
177 } else
178 i++;
179 }
180 continue;
181 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182 vlan_id = 0;
183 pos = buf;
184 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
185 pos++;
186 while (*pos == ' ' || *pos == '\t')
187 pos++;
188 if (*pos != '\0')
189 vlan_id = atoi(pos);
190
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 if (newacl == NULL) {
193 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
194 fclose(f);
195 return -1;
196 }
197
198 *acl = newacl;
199 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
200 (*acl)[*num].vlan_id = vlan_id;
201 (*num)++;
202 }
203
204 fclose(f);
205
206 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
207
208 return 0;
209}
210
211
212#ifdef EAP_SERVER
213static int hostapd_config_read_eap_user(const char *fname,
214 struct hostapd_bss_config *conf)
215{
216 FILE *f;
217 char buf[512], *pos, *start, *pos2;
218 int line = 0, ret = 0, num_methods;
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700219 struct hostapd_eap_user *user = NULL, *tail = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220
221 if (!fname)
222 return 0;
223
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800224 if (os_strncmp(fname, "sqlite:", 7) == 0) {
225 os_free(conf->eap_user_sqlite);
226 conf->eap_user_sqlite = os_strdup(fname + 7);
227 return 0;
228 }
229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 f = fopen(fname, "r");
231 if (!f) {
232 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
233 return -1;
234 }
235
236 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
237 while (fgets(buf, sizeof(buf), f)) {
238 line++;
239
240 if (buf[0] == '#')
241 continue;
242 pos = buf;
243 while (*pos != '\0') {
244 if (*pos == '\n') {
245 *pos = '\0';
246 break;
247 }
248 pos++;
249 }
250 if (buf[0] == '\0')
251 continue;
252
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700253#ifndef CONFIG_NO_RADIUS
254 if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
255 struct hostapd_radius_attr *attr, *a;
256 attr = hostapd_parse_radius_attr(buf + 19);
257 if (attr == NULL) {
258 wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
259 buf + 19);
Dmitry Shmidt98660862014-03-11 17:26:21 -0700260 user = NULL; /* already in the BSS list */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700261 goto failed;
262 }
263 if (user->accept_attr == NULL) {
264 user->accept_attr = attr;
265 } else {
266 a = user->accept_attr;
267 while (a->next)
268 a = a->next;
269 a->next = attr;
270 }
271 continue;
272 }
273#endif /* CONFIG_NO_RADIUS */
274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275 user = NULL;
276
277 if (buf[0] != '"' && buf[0] != '*') {
278 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
279 "start) on line %d in '%s'", line, fname);
280 goto failed;
281 }
282
283 user = os_zalloc(sizeof(*user));
284 if (user == NULL) {
285 wpa_printf(MSG_ERROR, "EAP user allocation failed");
286 goto failed;
287 }
288 user->force_version = -1;
289
290 if (buf[0] == '*') {
291 pos = buf;
292 } else {
293 pos = buf + 1;
294 start = pos;
295 while (*pos != '"' && *pos != '\0')
296 pos++;
297 if (*pos == '\0') {
298 wpa_printf(MSG_ERROR, "Invalid EAP identity "
299 "(no \" in end) on line %d in '%s'",
300 line, fname);
301 goto failed;
302 }
303
304 user->identity = os_malloc(pos - start);
305 if (user->identity == NULL) {
306 wpa_printf(MSG_ERROR, "Failed to allocate "
307 "memory for EAP identity");
308 goto failed;
309 }
310 os_memcpy(user->identity, start, pos - start);
311 user->identity_len = pos - start;
312
313 if (pos[0] == '"' && pos[1] == '*') {
314 user->wildcard_prefix = 1;
315 pos++;
316 }
317 }
318 pos++;
319 while (*pos == ' ' || *pos == '\t')
320 pos++;
321
322 if (*pos == '\0') {
323 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
324 "'%s'", line, fname);
325 goto failed;
326 }
327
328 start = pos;
329 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
330 pos++;
331 if (*pos == '\0') {
332 pos = NULL;
333 } else {
334 *pos = '\0';
335 pos++;
336 }
337 num_methods = 0;
338 while (*start) {
339 char *pos3 = os_strchr(start, ',');
340 if (pos3) {
341 *pos3++ = '\0';
342 }
343 user->methods[num_methods].method =
344 eap_server_get_type(
345 start,
346 &user->methods[num_methods].vendor);
347 if (user->methods[num_methods].vendor ==
348 EAP_VENDOR_IETF &&
349 user->methods[num_methods].method == EAP_TYPE_NONE)
350 {
351 if (os_strcmp(start, "TTLS-PAP") == 0) {
352 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
353 goto skip_eap;
354 }
355 if (os_strcmp(start, "TTLS-CHAP") == 0) {
356 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
357 goto skip_eap;
358 }
359 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
360 user->ttls_auth |=
361 EAP_TTLS_AUTH_MSCHAP;
362 goto skip_eap;
363 }
364 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
365 user->ttls_auth |=
366 EAP_TTLS_AUTH_MSCHAPV2;
367 goto skip_eap;
368 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700369 if (os_strcmp(start, "MACACL") == 0) {
370 user->macacl = 1;
371 goto skip_eap;
372 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 wpa_printf(MSG_ERROR, "Unsupported EAP type "
374 "'%s' on line %d in '%s'",
375 start, line, fname);
376 goto failed;
377 }
378
379 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800380 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 break;
382 skip_eap:
383 if (pos3 == NULL)
384 break;
385 start = pos3;
386 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700387 if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 wpa_printf(MSG_ERROR, "No EAP types configured on "
389 "line %d in '%s'", line, fname);
390 goto failed;
391 }
392
393 if (pos == NULL)
394 goto done;
395
396 while (*pos == ' ' || *pos == '\t')
397 pos++;
398 if (*pos == '\0')
399 goto done;
400
401 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
402 user->force_version = 0;
403 goto done;
404 }
405
406 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
407 user->force_version = 1;
408 goto done;
409 }
410
411 if (os_strncmp(pos, "[2]", 3) == 0) {
412 user->phase2 = 1;
413 goto done;
414 }
415
416 if (*pos == '"') {
417 pos++;
418 start = pos;
419 while (*pos != '"' && *pos != '\0')
420 pos++;
421 if (*pos == '\0') {
422 wpa_printf(MSG_ERROR, "Invalid EAP password "
423 "(no \" in end) on line %d in '%s'",
424 line, fname);
425 goto failed;
426 }
427
428 user->password = os_malloc(pos - start);
429 if (user->password == NULL) {
430 wpa_printf(MSG_ERROR, "Failed to allocate "
431 "memory for EAP password");
432 goto failed;
433 }
434 os_memcpy(user->password, start, pos - start);
435 user->password_len = pos - start;
436
437 pos++;
438 } else if (os_strncmp(pos, "hash:", 5) == 0) {
439 pos += 5;
440 pos2 = pos;
441 while (*pos2 != '\0' && *pos2 != ' ' &&
442 *pos2 != '\t' && *pos2 != '#')
443 pos2++;
444 if (pos2 - pos != 32) {
445 wpa_printf(MSG_ERROR, "Invalid password hash "
446 "on line %d in '%s'", line, fname);
447 goto failed;
448 }
449 user->password = os_malloc(16);
450 if (user->password == NULL) {
451 wpa_printf(MSG_ERROR, "Failed to allocate "
452 "memory for EAP password hash");
453 goto failed;
454 }
455 if (hexstr2bin(pos, user->password, 16) < 0) {
456 wpa_printf(MSG_ERROR, "Invalid hash password "
457 "on line %d in '%s'", line, fname);
458 goto failed;
459 }
460 user->password_len = 16;
461 user->password_hash = 1;
462 pos = pos2;
463 } else {
464 pos2 = pos;
465 while (*pos2 != '\0' && *pos2 != ' ' &&
466 *pos2 != '\t' && *pos2 != '#')
467 pos2++;
468 if ((pos2 - pos) & 1) {
469 wpa_printf(MSG_ERROR, "Invalid hex password "
470 "on line %d in '%s'", line, fname);
471 goto failed;
472 }
473 user->password = os_malloc((pos2 - pos) / 2);
474 if (user->password == NULL) {
475 wpa_printf(MSG_ERROR, "Failed to allocate "
476 "memory for EAP password");
477 goto failed;
478 }
479 if (hexstr2bin(pos, user->password,
480 (pos2 - pos) / 2) < 0) {
481 wpa_printf(MSG_ERROR, "Invalid hex password "
482 "on line %d in '%s'", line, fname);
483 goto failed;
484 }
485 user->password_len = (pos2 - pos) / 2;
486 pos = pos2;
487 }
488
489 while (*pos == ' ' || *pos == '\t')
490 pos++;
491 if (os_strncmp(pos, "[2]", 3) == 0) {
492 user->phase2 = 1;
493 }
494
495 done:
496 if (tail == NULL) {
497 tail = conf->eap_user = user;
498 } else {
499 tail->next = user;
500 tail = user;
501 }
502 continue;
503
504 failed:
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700505 if (user)
506 hostapd_config_free_eap_user(user);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 ret = -1;
508 break;
509 }
510
511 fclose(f);
512
513 return ret;
514}
515#endif /* EAP_SERVER */
516
517
518#ifndef CONFIG_NO_RADIUS
519static int
520hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
521 int *num_server, const char *val, int def_port,
522 struct hostapd_radius_server **curr_serv)
523{
524 struct hostapd_radius_server *nserv;
525 int ret;
526 static int server_index = 1;
527
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700528 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 if (nserv == NULL)
530 return -1;
531
532 *server = nserv;
533 nserv = &nserv[*num_server];
534 (*num_server)++;
535 (*curr_serv) = nserv;
536
537 os_memset(nserv, 0, sizeof(*nserv));
538 nserv->port = def_port;
539 ret = hostapd_parse_ip_addr(val, &nserv->addr);
540 nserv->index = server_index++;
541
542 return ret;
543}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700544
545
546static struct hostapd_radius_attr *
547hostapd_parse_radius_attr(const char *value)
548{
549 const char *pos;
550 char syntax;
551 struct hostapd_radius_attr *attr;
552 size_t len;
553
554 attr = os_zalloc(sizeof(*attr));
555 if (attr == NULL)
556 return NULL;
557
558 attr->type = atoi(value);
559
560 pos = os_strchr(value, ':');
561 if (pos == NULL) {
562 attr->val = wpabuf_alloc(1);
563 if (attr->val == NULL) {
564 os_free(attr);
565 return NULL;
566 }
567 wpabuf_put_u8(attr->val, 0);
568 return attr;
569 }
570
571 pos++;
572 if (pos[0] == '\0' || pos[1] != ':') {
573 os_free(attr);
574 return NULL;
575 }
576 syntax = *pos++;
577 pos++;
578
579 switch (syntax) {
580 case 's':
581 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
582 break;
583 case 'x':
584 len = os_strlen(pos);
585 if (len & 1)
586 break;
587 len /= 2;
588 attr->val = wpabuf_alloc(len);
589 if (attr->val == NULL)
590 break;
591 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
592 wpabuf_free(attr->val);
593 os_free(attr);
594 return NULL;
595 }
596 break;
597 case 'd':
598 attr->val = wpabuf_alloc(4);
599 if (attr->val)
600 wpabuf_put_be32(attr->val, atoi(pos));
601 break;
602 default:
603 os_free(attr);
604 return NULL;
605 }
606
607 if (attr->val == NULL) {
608 os_free(attr);
609 return NULL;
610 }
611
612 return attr;
613}
614
615
616static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
617 const char *val)
618{
619 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700620
621 secret = os_strchr(val, ' ');
622 if (secret == NULL)
623 return -1;
624
625 secret++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700626
627 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
628 return -1;
629
630 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700631 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700632 if (bss->radius_das_shared_secret == NULL)
633 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700634 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700635
636 return 0;
637}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638#endif /* CONFIG_NO_RADIUS */
639
640
641static int hostapd_config_parse_key_mgmt(int line, const char *value)
642{
643 int val = 0, last;
644 char *start, *end, *buf;
645
646 buf = os_strdup(value);
647 if (buf == NULL)
648 return -1;
649 start = buf;
650
651 while (*start != '\0') {
652 while (*start == ' ' || *start == '\t')
653 start++;
654 if (*start == '\0')
655 break;
656 end = start;
657 while (*end != ' ' && *end != '\t' && *end != '\0')
658 end++;
659 last = *end == '\0';
660 *end = '\0';
661 if (os_strcmp(start, "WPA-PSK") == 0)
662 val |= WPA_KEY_MGMT_PSK;
663 else if (os_strcmp(start, "WPA-EAP") == 0)
664 val |= WPA_KEY_MGMT_IEEE8021X;
665#ifdef CONFIG_IEEE80211R
666 else if (os_strcmp(start, "FT-PSK") == 0)
667 val |= WPA_KEY_MGMT_FT_PSK;
668 else if (os_strcmp(start, "FT-EAP") == 0)
669 val |= WPA_KEY_MGMT_FT_IEEE8021X;
670#endif /* CONFIG_IEEE80211R */
671#ifdef CONFIG_IEEE80211W
672 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
673 val |= WPA_KEY_MGMT_PSK_SHA256;
674 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
675 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
676#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800677#ifdef CONFIG_SAE
678 else if (os_strcmp(start, "SAE") == 0)
679 val |= WPA_KEY_MGMT_SAE;
680 else if (os_strcmp(start, "FT-SAE") == 0)
681 val |= WPA_KEY_MGMT_FT_SAE;
682#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800683#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800684 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
685 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800686#endif /* CONFIG_SUITEB */
687#ifdef CONFIG_SUITEB192
688 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
689 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
690#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 else {
692 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
693 line, start);
694 os_free(buf);
695 return -1;
696 }
697
698 if (last)
699 break;
700 start = end + 1;
701 }
702
703 os_free(buf);
704 if (val == 0) {
705 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
706 "configured.", line);
707 return -1;
708 }
709
710 return val;
711}
712
713
714static int hostapd_config_parse_cipher(int line, const char *value)
715{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800716 int val = wpa_parse_cipher(value);
717 if (val < 0) {
718 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
719 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 if (val == 0) {
723 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
724 line);
725 return -1;
726 }
727 return val;
728}
729
730
731static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
732 char *val)
733{
734 size_t len = os_strlen(val);
735
736 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
737 return -1;
738
739 if (val[0] == '"') {
740 if (len < 2 || val[len - 1] != '"')
741 return -1;
742 len -= 2;
743 wep->key[keyidx] = os_malloc(len);
744 if (wep->key[keyidx] == NULL)
745 return -1;
746 os_memcpy(wep->key[keyidx], val + 1, len);
747 wep->len[keyidx] = len;
748 } else {
749 if (len & 1)
750 return -1;
751 len /= 2;
752 wep->key[keyidx] = os_malloc(len);
753 if (wep->key[keyidx] == NULL)
754 return -1;
755 wep->len[keyidx] = len;
756 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
757 return -1;
758 }
759
760 wep->keys_set++;
761
762 return 0;
763}
764
765
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700766static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767{
768 int *list;
769 int count;
770 char *pos, *end;
771
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700772 os_free(*int_list);
773 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774
775 pos = val;
776 count = 0;
777 while (*pos != '\0') {
778 if (*pos == ' ')
779 count++;
780 pos++;
781 }
782
783 list = os_malloc(sizeof(int) * (count + 2));
784 if (list == NULL)
785 return -1;
786 pos = val;
787 count = 0;
788 while (*pos != '\0') {
789 end = os_strchr(pos, ' ');
790 if (end)
791 *end = '\0';
792
793 list[count++] = atoi(pos);
794 if (!end)
795 break;
796 pos = end + 1;
797 }
798 list[count] = -1;
799
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700800 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 return 0;
802}
803
804
805static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
806{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800807 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808
809 if (*ifname == '\0')
810 return -1;
811
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800812 all = os_realloc_array(conf->bss, conf->num_bss + 1,
813 sizeof(struct hostapd_bss_config *));
814 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
816 "multi-BSS entry");
817 return -1;
818 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800819 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800821 bss = os_zalloc(sizeof(*bss));
822 if (bss == NULL)
823 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 bss->radius = os_zalloc(sizeof(*bss->radius));
825 if (bss->radius == NULL) {
826 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
827 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800828 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 return -1;
830 }
831
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800832 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 conf->last_bss = bss;
834
835 hostapd_config_defaults_bss(bss);
836 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
837 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
838
839 return 0;
840}
841
842
843/* convert floats with one decimal place to value*10 int, i.e.,
844 * "1.5" will return 15 */
845static int hostapd_config_read_int10(const char *value)
846{
847 int i, d;
848 char *pos;
849
850 i = atoi(value);
851 pos = os_strchr(value, '.');
852 d = 0;
853 if (pos) {
854 pos++;
855 if (*pos >= '0' && *pos <= '9')
856 d = *pos - '0';
857 }
858
859 return i * 10 + d;
860}
861
862
863static int valid_cw(int cw)
864{
865 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
866 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
867}
868
869
870enum {
871 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
872 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
873 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
874 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
875};
876
877static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
878 char *val)
879{
880 int num;
881 char *pos;
882 struct hostapd_tx_queue_params *queue;
883
884 /* skip 'tx_queue_' prefix */
885 pos = name + 9;
886 if (os_strncmp(pos, "data", 4) == 0 &&
887 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
888 num = pos[4] - '0';
889 pos += 6;
890 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
891 os_strncmp(pos, "beacon_", 7) == 0) {
892 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
893 return 0;
894 } else {
895 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
896 return -1;
897 }
898
899 if (num >= NUM_TX_QUEUES) {
900 /* for backwards compatibility, do not trigger failure */
901 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
902 return 0;
903 }
904
905 queue = &conf->tx_queue[num];
906
907 if (os_strcmp(pos, "aifs") == 0) {
908 queue->aifs = atoi(val);
909 if (queue->aifs < 0 || queue->aifs > 255) {
910 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
911 queue->aifs);
912 return -1;
913 }
914 } else if (os_strcmp(pos, "cwmin") == 0) {
915 queue->cwmin = atoi(val);
916 if (!valid_cw(queue->cwmin)) {
917 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
918 queue->cwmin);
919 return -1;
920 }
921 } else if (os_strcmp(pos, "cwmax") == 0) {
922 queue->cwmax = atoi(val);
923 if (!valid_cw(queue->cwmax)) {
924 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
925 queue->cwmax);
926 return -1;
927 }
928 } else if (os_strcmp(pos, "burst") == 0) {
929 queue->burst = hostapd_config_read_int10(val);
930 } else {
931 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
932 return -1;
933 }
934
935 return 0;
936}
937
938
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939#ifdef CONFIG_IEEE80211R
940static int add_r0kh(struct hostapd_bss_config *bss, char *value)
941{
942 struct ft_remote_r0kh *r0kh;
943 char *pos, *next;
944
945 r0kh = os_zalloc(sizeof(*r0kh));
946 if (r0kh == NULL)
947 return -1;
948
949 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
950 pos = value;
951 next = os_strchr(pos, ' ');
952 if (next)
953 *next++ = '\0';
954 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
955 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
956 os_free(r0kh);
957 return -1;
958 }
959
960 pos = next;
961 next = os_strchr(pos, ' ');
962 if (next)
963 *next++ = '\0';
964 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
965 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
966 os_free(r0kh);
967 return -1;
968 }
969 r0kh->id_len = next - pos - 1;
970 os_memcpy(r0kh->id, pos, r0kh->id_len);
971
972 pos = next;
973 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
974 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
975 os_free(r0kh);
976 return -1;
977 }
978
979 r0kh->next = bss->r0kh_list;
980 bss->r0kh_list = r0kh;
981
982 return 0;
983}
984
985
986static int add_r1kh(struct hostapd_bss_config *bss, char *value)
987{
988 struct ft_remote_r1kh *r1kh;
989 char *pos, *next;
990
991 r1kh = os_zalloc(sizeof(*r1kh));
992 if (r1kh == NULL)
993 return -1;
994
995 /* 02:01:02:03:04:05 02:01:02:03:04:05
996 * 000102030405060708090a0b0c0d0e0f */
997 pos = value;
998 next = os_strchr(pos, ' ');
999 if (next)
1000 *next++ = '\0';
1001 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1002 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1003 os_free(r1kh);
1004 return -1;
1005 }
1006
1007 pos = next;
1008 next = os_strchr(pos, ' ');
1009 if (next)
1010 *next++ = '\0';
1011 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1012 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1013 os_free(r1kh);
1014 return -1;
1015 }
1016
1017 pos = next;
1018 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1019 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1020 os_free(r1kh);
1021 return -1;
1022 }
1023
1024 r1kh->next = bss->r1kh_list;
1025 bss->r1kh_list = r1kh;
1026
1027 return 0;
1028}
1029#endif /* CONFIG_IEEE80211R */
1030
1031
1032#ifdef CONFIG_IEEE80211N
1033static int hostapd_config_ht_capab(struct hostapd_config *conf,
1034 const char *capab)
1035{
1036 if (os_strstr(capab, "[LDPC]"))
1037 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1038 if (os_strstr(capab, "[HT40-]")) {
1039 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1040 conf->secondary_channel = -1;
1041 }
1042 if (os_strstr(capab, "[HT40+]")) {
1043 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1044 conf->secondary_channel = 1;
1045 }
1046 if (os_strstr(capab, "[SMPS-STATIC]")) {
1047 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1048 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1049 }
1050 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1051 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1052 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1053 }
1054 if (os_strstr(capab, "[GF]"))
1055 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1056 if (os_strstr(capab, "[SHORT-GI-20]"))
1057 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1058 if (os_strstr(capab, "[SHORT-GI-40]"))
1059 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1060 if (os_strstr(capab, "[TX-STBC]"))
1061 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1062 if (os_strstr(capab, "[RX-STBC1]")) {
1063 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1064 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1065 }
1066 if (os_strstr(capab, "[RX-STBC12]")) {
1067 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1068 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1069 }
1070 if (os_strstr(capab, "[RX-STBC123]")) {
1071 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1072 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1073 }
1074 if (os_strstr(capab, "[DELAYED-BA]"))
1075 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1076 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1077 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1078 if (os_strstr(capab, "[DSSS_CCK-40]"))
1079 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001080 if (os_strstr(capab, "[40-INTOLERANT]"))
1081 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1083 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1084
1085 return 0;
1086}
1087#endif /* CONFIG_IEEE80211N */
1088
1089
Dmitry Shmidt04949592012-07-19 12:16:46 -07001090#ifdef CONFIG_IEEE80211AC
1091static int hostapd_config_vht_capab(struct hostapd_config *conf,
1092 const char *capab)
1093{
1094 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1095 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1096 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1097 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1098 if (os_strstr(capab, "[VHT160]"))
1099 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1100 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1101 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001102 if (os_strstr(capab, "[RXLDPC]"))
1103 conf->vht_capab |= VHT_CAP_RXLDPC;
1104 if (os_strstr(capab, "[SHORT-GI-80]"))
1105 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1106 if (os_strstr(capab, "[SHORT-GI-160]"))
1107 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1108 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1109 conf->vht_capab |= VHT_CAP_TXSTBC;
1110 if (os_strstr(capab, "[RX-STBC-1]"))
1111 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1112 if (os_strstr(capab, "[RX-STBC-12]"))
1113 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1114 if (os_strstr(capab, "[RX-STBC-123]"))
1115 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1116 if (os_strstr(capab, "[RX-STBC-1234]"))
1117 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1118 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001119 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001120 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001121 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001122 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001123 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1124 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001125 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001126 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1127 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001128 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1129 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1130 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1131 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1132 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1133 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1134 if (os_strstr(capab, "[HTC-VHT]"))
1135 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001136 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1137 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1138 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1139 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1140 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1141 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1142 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1143 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1144 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1145 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1146 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1147 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1148 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1149 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001150 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1151 (conf->vht_capab & VHT_CAP_HTC_VHT))
1152 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1153 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1154 (conf->vht_capab & VHT_CAP_HTC_VHT))
1155 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1156 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1157 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1158 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1159 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1160 return 0;
1161}
1162#endif /* CONFIG_IEEE80211AC */
1163
1164
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001165#ifdef CONFIG_INTERWORKING
1166static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1167 int line)
1168{
1169 size_t len = os_strlen(pos);
1170 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1171
1172 struct hostapd_roaming_consortium *rc;
1173
1174 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1175 hexstr2bin(pos, oi, len / 2)) {
1176 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1177 "'%s'", line, pos);
1178 return -1;
1179 }
1180 len /= 2;
1181
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001182 rc = os_realloc_array(bss->roaming_consortium,
1183 bss->roaming_consortium_count + 1,
1184 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001185 if (rc == NULL)
1186 return -1;
1187
1188 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1189 rc[bss->roaming_consortium_count].len = len;
1190
1191 bss->roaming_consortium = rc;
1192 bss->roaming_consortium_count++;
1193
1194 return 0;
1195}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001196
1197
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001198static int parse_lang_string(struct hostapd_lang_string **array,
1199 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001200{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001201 char *sep, *str = NULL;
1202 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001203 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001204 int ret = -1;
1205
1206 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1207 str = wpa_config_parse_string(pos, &slen);
1208 if (!str)
1209 return -1;
1210 pos = str;
1211 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001212
1213 sep = os_strchr(pos, ':');
1214 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001215 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001216 *sep++ = '\0';
1217
1218 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001219 if (clen < 2 || clen > sizeof(ls->lang))
1220 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001221 nlen = os_strlen(sep);
1222 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001223 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001224
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001225 ls = os_realloc_array(*array, *count + 1,
1226 sizeof(struct hostapd_lang_string));
1227 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001228 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001229
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001230 *array = ls;
1231 ls = &(*array)[*count];
1232 (*count)++;
1233
1234 os_memset(ls->lang, 0, sizeof(ls->lang));
1235 os_memcpy(ls->lang, pos, clen);
1236 ls->name_len = nlen;
1237 os_memcpy(ls->name, sep, nlen);
1238
Dmitry Shmidt56052862013-10-04 10:23:25 -07001239 ret = 0;
1240fail:
1241 os_free(str);
1242 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001243}
1244
1245
1246static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1247 int line)
1248{
1249 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1250 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1251 line, pos);
1252 return -1;
1253 }
1254 return 0;
1255}
1256
1257
1258static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1259 int line)
1260{
1261 size_t count;
1262 char *pos;
1263 u8 *info = NULL, *ipos;
1264
1265 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1266
1267 count = 1;
1268 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001269 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001270 goto fail;
1271 if (*pos == ';')
1272 count++;
1273 }
1274 if (1 + count * 3 > 0x7f)
1275 goto fail;
1276
1277 info = os_zalloc(2 + 3 + count * 3);
1278 if (info == NULL)
1279 return -1;
1280
1281 ipos = info;
1282 *ipos++ = 0; /* GUD - Version 1 */
1283 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1284 *ipos++ = 0; /* PLMN List IEI */
1285 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1286 *ipos++ = 1 + count * 3;
1287 *ipos++ = count; /* Number of PLMNs */
1288
1289 pos = buf;
1290 while (pos && *pos) {
1291 char *mcc, *mnc;
1292 size_t mnc_len;
1293
1294 mcc = pos;
1295 mnc = os_strchr(pos, ',');
1296 if (mnc == NULL)
1297 goto fail;
1298 *mnc++ = '\0';
1299 pos = os_strchr(mnc, ';');
1300 if (pos)
1301 *pos++ = '\0';
1302
1303 mnc_len = os_strlen(mnc);
1304 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1305 goto fail;
1306
1307 /* BC coded MCC,MNC */
1308 /* MCC digit 2 | MCC digit 1 */
1309 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1310 /* MNC digit 3 | MCC digit 3 */
1311 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1312 (mcc[2] - '0');
1313 /* MNC digit 2 | MNC digit 1 */
1314 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1315 }
1316
1317 os_free(bss->anqp_3gpp_cell_net);
1318 bss->anqp_3gpp_cell_net = info;
1319 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1320 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1321 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001322
1323 return 0;
1324
1325fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001326 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1327 line, buf);
1328 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001329 return -1;
1330}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001331
1332
1333static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1334{
1335 struct hostapd_nai_realm_data *realm;
1336 size_t i, j, len;
1337 int *offsets;
1338 char *pos, *end, *rpos;
1339
1340 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1341 sizeof(int));
1342 if (offsets == NULL)
1343 return -1;
1344
1345 for (i = 0; i < bss->nai_realm_count; i++) {
1346 realm = &bss->nai_realm_data[i];
1347 for (j = 0; j < MAX_NAI_REALMS; j++) {
1348 offsets[i * MAX_NAI_REALMS + j] =
1349 realm->realm[j] ?
1350 realm->realm[j] - realm->realm_buf : -1;
1351 }
1352 }
1353
1354 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1355 sizeof(struct hostapd_nai_realm_data));
1356 if (realm == NULL) {
1357 os_free(offsets);
1358 return -1;
1359 }
1360 bss->nai_realm_data = realm;
1361
1362 /* patch the pointers after realloc */
1363 for (i = 0; i < bss->nai_realm_count; i++) {
1364 realm = &bss->nai_realm_data[i];
1365 for (j = 0; j < MAX_NAI_REALMS; j++) {
1366 int offs = offsets[i * MAX_NAI_REALMS + j];
1367 if (offs >= 0)
1368 realm->realm[j] = realm->realm_buf + offs;
1369 else
1370 realm->realm[j] = NULL;
1371 }
1372 }
1373 os_free(offsets);
1374
1375 realm = &bss->nai_realm_data[bss->nai_realm_count];
1376 os_memset(realm, 0, sizeof(*realm));
1377
1378 pos = buf;
1379 realm->encoding = atoi(pos);
1380 pos = os_strchr(pos, ',');
1381 if (pos == NULL)
1382 goto fail;
1383 pos++;
1384
1385 end = os_strchr(pos, ',');
1386 if (end) {
1387 len = end - pos;
1388 *end = '\0';
1389 } else {
1390 len = os_strlen(pos);
1391 }
1392
1393 if (len > MAX_NAI_REALMLEN) {
1394 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1395 "characters)", (int) len, MAX_NAI_REALMLEN);
1396 goto fail;
1397 }
1398 os_memcpy(realm->realm_buf, pos, len);
1399
1400 if (end)
1401 pos = end + 1;
1402 else
1403 pos = NULL;
1404
1405 while (pos && *pos) {
1406 struct hostapd_nai_realm_eap *eap;
1407
1408 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1409 wpa_printf(MSG_ERROR, "Too many EAP methods");
1410 goto fail;
1411 }
1412
1413 eap = &realm->eap_method[realm->eap_method_count];
1414 realm->eap_method_count++;
1415
1416 end = os_strchr(pos, ',');
1417 if (end == NULL)
1418 end = pos + os_strlen(pos);
1419
1420 eap->eap_method = atoi(pos);
1421 for (;;) {
1422 pos = os_strchr(pos, '[');
1423 if (pos == NULL || pos > end)
1424 break;
1425 pos++;
1426 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1427 wpa_printf(MSG_ERROR, "Too many auth params");
1428 goto fail;
1429 }
1430 eap->auth_id[eap->num_auths] = atoi(pos);
1431 pos = os_strchr(pos, ':');
1432 if (pos == NULL || pos > end)
1433 goto fail;
1434 pos++;
1435 eap->auth_val[eap->num_auths] = atoi(pos);
1436 pos = os_strchr(pos, ']');
1437 if (pos == NULL || pos > end)
1438 goto fail;
1439 pos++;
1440 eap->num_auths++;
1441 }
1442
1443 if (*end != ',')
1444 break;
1445
1446 pos = end + 1;
1447 }
1448
1449 /* Split realm list into null terminated realms */
1450 rpos = realm->realm_buf;
1451 i = 0;
1452 while (*rpos) {
1453 if (i >= MAX_NAI_REALMS) {
1454 wpa_printf(MSG_ERROR, "Too many realms");
1455 goto fail;
1456 }
1457 realm->realm[i++] = rpos;
1458 rpos = os_strchr(rpos, ';');
1459 if (rpos == NULL)
1460 break;
1461 *rpos++ = '\0';
1462 }
1463
1464 bss->nai_realm_count++;
1465
1466 return 0;
1467
1468fail:
1469 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1470 return -1;
1471}
1472
Dmitry Shmidt051af732013-10-22 13:52:46 -07001473
1474static int parse_qos_map_set(struct hostapd_bss_config *bss,
1475 char *buf, int line)
1476{
1477 u8 qos_map_set[16 + 2 * 21], count = 0;
1478 char *pos = buf;
1479 int val;
1480
1481 for (;;) {
1482 if (count == sizeof(qos_map_set)) {
1483 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1484 "parameters '%s'", line, buf);
1485 return -1;
1486 }
1487
1488 val = atoi(pos);
1489 if (val > 255 || val < 0) {
1490 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1491 "'%s'", line, buf);
1492 return -1;
1493 }
1494
1495 qos_map_set[count++] = val;
1496 pos = os_strchr(pos, ',');
1497 if (!pos)
1498 break;
1499 pos++;
1500 }
1501
1502 if (count < 16 || count & 1) {
1503 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1504 line, buf);
1505 return -1;
1506 }
1507
1508 os_memcpy(bss->qos_map_set, qos_map_set, count);
1509 bss->qos_map_set_len = count;
1510
1511 return 0;
1512}
1513
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001514#endif /* CONFIG_INTERWORKING */
1515
1516
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001517#ifdef CONFIG_HS20
1518static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1519 int line)
1520{
1521 u8 *conn_cap;
1522 char *pos;
1523
1524 if (bss->hs20_connection_capability_len >= 0xfff0)
1525 return -1;
1526
1527 conn_cap = os_realloc(bss->hs20_connection_capability,
1528 bss->hs20_connection_capability_len + 4);
1529 if (conn_cap == NULL)
1530 return -1;
1531
1532 bss->hs20_connection_capability = conn_cap;
1533 conn_cap += bss->hs20_connection_capability_len;
1534 pos = buf;
1535 conn_cap[0] = atoi(pos);
1536 pos = os_strchr(pos, ':');
1537 if (pos == NULL)
1538 return -1;
1539 pos++;
1540 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1541 pos = os_strchr(pos, ':');
1542 if (pos == NULL)
1543 return -1;
1544 pos++;
1545 conn_cap[3] = atoi(pos);
1546 bss->hs20_connection_capability_len += 4;
1547
1548 return 0;
1549}
1550
1551
1552static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1553 int line)
1554{
1555 u8 *wan_metrics;
1556 char *pos;
1557
1558 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1559
1560 wan_metrics = os_zalloc(13);
1561 if (wan_metrics == NULL)
1562 return -1;
1563
1564 pos = buf;
1565 /* WAN Info */
1566 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1567 goto fail;
1568 pos += 2;
1569 if (*pos != ':')
1570 goto fail;
1571 pos++;
1572
1573 /* Downlink Speed */
1574 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1575 pos = os_strchr(pos, ':');
1576 if (pos == NULL)
1577 goto fail;
1578 pos++;
1579
1580 /* Uplink Speed */
1581 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1582 pos = os_strchr(pos, ':');
1583 if (pos == NULL)
1584 goto fail;
1585 pos++;
1586
1587 /* Downlink Load */
1588 wan_metrics[9] = atoi(pos);
1589 pos = os_strchr(pos, ':');
1590 if (pos == NULL)
1591 goto fail;
1592 pos++;
1593
1594 /* Uplink Load */
1595 wan_metrics[10] = atoi(pos);
1596 pos = os_strchr(pos, ':');
1597 if (pos == NULL)
1598 goto fail;
1599 pos++;
1600
1601 /* LMD */
1602 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1603
1604 os_free(bss->hs20_wan_metrics);
1605 bss->hs20_wan_metrics = wan_metrics;
1606
1607 return 0;
1608
1609fail:
1610 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001611 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001612 os_free(wan_metrics);
1613 return -1;
1614}
1615
1616
1617static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1618 char *pos, int line)
1619{
1620 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1621 &bss->hs20_oper_friendly_name_count, pos)) {
1622 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1623 "hs20_oper_friendly_name '%s'", line, pos);
1624 return -1;
1625 }
1626 return 0;
1627}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001628
1629
1630static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1631{
1632 struct hs20_icon *icon;
1633 char *end;
1634
1635 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1636 sizeof(struct hs20_icon));
1637 if (icon == NULL)
1638 return -1;
1639 bss->hs20_icons = icon;
1640 icon = &bss->hs20_icons[bss->hs20_icons_count];
1641 os_memset(icon, 0, sizeof(*icon));
1642
1643 icon->width = atoi(pos);
1644 pos = os_strchr(pos, ':');
1645 if (pos == NULL)
1646 return -1;
1647 pos++;
1648
1649 icon->height = atoi(pos);
1650 pos = os_strchr(pos, ':');
1651 if (pos == NULL)
1652 return -1;
1653 pos++;
1654
1655 end = os_strchr(pos, ':');
1656 if (end == NULL || end - pos > 3)
1657 return -1;
1658 os_memcpy(icon->language, pos, end - pos);
1659 pos = end + 1;
1660
1661 end = os_strchr(pos, ':');
1662 if (end == NULL || end - pos > 255)
1663 return -1;
1664 os_memcpy(icon->type, pos, end - pos);
1665 pos = end + 1;
1666
1667 end = os_strchr(pos, ':');
1668 if (end == NULL || end - pos > 255)
1669 return -1;
1670 os_memcpy(icon->name, pos, end - pos);
1671 pos = end + 1;
1672
1673 if (os_strlen(pos) > 255)
1674 return -1;
1675 os_memcpy(icon->file, pos, os_strlen(pos));
1676
1677 bss->hs20_icons_count++;
1678
1679 return 0;
1680}
1681
1682
1683static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1684 char *pos, int line)
1685{
1686 size_t slen;
1687 char *str;
1688
1689 str = wpa_config_parse_string(pos, &slen);
1690 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1691 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001692 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001693 return -1;
1694 }
1695
1696 os_memcpy(bss->osu_ssid, str, slen);
1697 bss->osu_ssid_len = slen;
1698 os_free(str);
1699
1700 return 0;
1701}
1702
1703
1704static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1705 char *pos, int line)
1706{
1707 struct hs20_osu_provider *p;
1708
1709 p = os_realloc_array(bss->hs20_osu_providers,
1710 bss->hs20_osu_providers_count + 1, sizeof(*p));
1711 if (p == NULL)
1712 return -1;
1713
1714 bss->hs20_osu_providers = p;
1715 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1716 bss->hs20_osu_providers_count++;
1717 os_memset(bss->last_osu, 0, sizeof(*p));
1718 bss->last_osu->server_uri = os_strdup(pos);
1719
1720 return 0;
1721}
1722
1723
1724static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1725 char *pos, int line)
1726{
1727 if (bss->last_osu == NULL) {
1728 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1729 return -1;
1730 }
1731
1732 if (parse_lang_string(&bss->last_osu->friendly_name,
1733 &bss->last_osu->friendly_name_count, pos)) {
1734 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1735 line, pos);
1736 return -1;
1737 }
1738
1739 return 0;
1740}
1741
1742
1743static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1744 char *pos, int line)
1745{
1746 if (bss->last_osu == NULL) {
1747 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1748 return -1;
1749 }
1750
1751 os_free(bss->last_osu->osu_nai);
1752 bss->last_osu->osu_nai = os_strdup(pos);
1753 if (bss->last_osu->osu_nai == NULL)
1754 return -1;
1755
1756 return 0;
1757}
1758
1759
1760static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1761 int line)
1762{
1763 if (bss->last_osu == NULL) {
1764 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1765 return -1;
1766 }
1767
1768 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1769 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1770 return -1;
1771 }
1772
1773 return 0;
1774}
1775
1776
1777static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1778 int line)
1779{
1780 char **n;
1781 struct hs20_osu_provider *p = bss->last_osu;
1782
1783 if (p == NULL) {
1784 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1785 return -1;
1786 }
1787
1788 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1789 if (n == NULL)
1790 return -1;
1791 p->icons = n;
1792 p->icons[p->icons_count] = os_strdup(pos);
1793 if (p->icons[p->icons_count] == NULL)
1794 return -1;
1795 p->icons_count++;
1796
1797 return 0;
1798}
1799
1800
1801static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1802 char *pos, int line)
1803{
1804 if (bss->last_osu == NULL) {
1805 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1806 return -1;
1807 }
1808
1809 if (parse_lang_string(&bss->last_osu->service_desc,
1810 &bss->last_osu->service_desc_count, pos)) {
1811 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1812 line, pos);
1813 return -1;
1814 }
1815
1816 return 0;
1817}
1818
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001819#endif /* CONFIG_HS20 */
1820
1821
Dmitry Shmidt04949592012-07-19 12:16:46 -07001822#ifdef CONFIG_WPS_NFC
1823static struct wpabuf * hostapd_parse_bin(const char *buf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001825 size_t len;
1826 struct wpabuf *ret;
1827
1828 len = os_strlen(buf);
1829 if (len & 0x01)
1830 return NULL;
1831 len /= 2;
1832
1833 ret = wpabuf_alloc(len);
1834 if (ret == NULL)
1835 return NULL;
1836
1837 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1838 wpabuf_free(ret);
1839 return NULL;
1840 }
1841
1842 return ret;
1843}
1844#endif /* CONFIG_WPS_NFC */
1845
1846
1847static int hostapd_config_fill(struct hostapd_config *conf,
1848 struct hostapd_bss_config *bss,
1849 char *buf, char *pos, int line)
1850{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001851 if (os_strcmp(buf, "interface") == 0) {
1852 os_strlcpy(conf->bss[0]->iface, pos,
1853 sizeof(conf->bss[0]->iface));
1854 } else if (os_strcmp(buf, "bridge") == 0) {
1855 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1856 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1857 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
1858 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1859 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
1860 } else if (os_strcmp(buf, "driver") == 0) {
1861 int j;
1862 /* clear to get error below if setting is invalid */
1863 conf->driver = NULL;
1864 for (j = 0; wpa_drivers[j]; j++) {
1865 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
1866 conf->driver = wpa_drivers[j];
1867 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001869 }
1870 if (conf->driver == NULL) {
1871 wpa_printf(MSG_ERROR,
1872 "Line %d: invalid/unknown driver '%s'",
1873 line, pos);
1874 return 1;
1875 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001876 } else if (os_strcmp(buf, "driver_params") == 0) {
1877 os_free(conf->driver_params);
1878 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001879 } else if (os_strcmp(buf, "debug") == 0) {
1880 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
1881 line);
1882 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1883 bss->logger_syslog_level = atoi(pos);
1884 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1885 bss->logger_stdout_level = atoi(pos);
1886 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1887 bss->logger_syslog = atoi(pos);
1888 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1889 bss->logger_stdout = atoi(pos);
1890 } else if (os_strcmp(buf, "dump_file") == 0) {
1891 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
1892 line);
1893 } else if (os_strcmp(buf, "ssid") == 0) {
1894 bss->ssid.ssid_len = os_strlen(pos);
1895 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1896 bss->ssid.ssid_len < 1) {
1897 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1898 line, pos);
1899 return 1;
1900 }
1901 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
1902 bss->ssid.ssid_set = 1;
1903 } else if (os_strcmp(buf, "ssid2") == 0) {
1904 size_t slen;
1905 char *str = wpa_config_parse_string(pos, &slen);
1906 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1907 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1908 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001909 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001910 return 1;
1911 }
1912 os_memcpy(bss->ssid.ssid, str, slen);
1913 bss->ssid.ssid_len = slen;
1914 bss->ssid.ssid_set = 1;
1915 os_free(str);
1916 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1917 bss->ssid.utf8_ssid = atoi(pos) > 0;
1918 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1919 bss->macaddr_acl = atoi(pos);
1920 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1921 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1922 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1923 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
1924 line, bss->macaddr_acl);
1925 }
1926 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1927 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1928 &bss->num_accept_mac)) {
1929 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
1930 line, pos);
1931 return 1;
1932 }
1933 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1934 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1935 &bss->num_deny_mac)) {
1936 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
1937 line, pos);
1938 return 1;
1939 }
1940 } else if (os_strcmp(buf, "wds_sta") == 0) {
1941 bss->wds_sta = atoi(pos);
1942 } else if (os_strcmp(buf, "start_disabled") == 0) {
1943 bss->start_disabled = atoi(pos);
1944 } else if (os_strcmp(buf, "ap_isolate") == 0) {
1945 bss->isolate = atoi(pos);
1946 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1947 bss->ap_max_inactivity = atoi(pos);
1948 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
1949 bss->skip_inactivity_poll = atoi(pos);
1950 } else if (os_strcmp(buf, "country_code") == 0) {
1951 os_memcpy(conf->country, pos, 2);
1952 /* FIX: make this configurable */
1953 conf->country[2] = ' ';
1954 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1955 conf->ieee80211d = atoi(pos);
1956 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1957 conf->ieee80211h = atoi(pos);
1958 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1959 bss->ieee802_1x = atoi(pos);
1960 } else if (os_strcmp(buf, "eapol_version") == 0) {
1961 bss->eapol_version = atoi(pos);
1962 if (bss->eapol_version < 1 || bss->eapol_version > 2) {
1963 wpa_printf(MSG_ERROR,
1964 "Line %d: invalid EAPOL version (%d): '%s'.",
1965 line, bss->eapol_version, pos);
1966 return 1;
1967 }
1968 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001969#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001970 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1971 bss->eap_server = atoi(pos);
1972 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
1973 } else if (os_strcmp(buf, "eap_server") == 0) {
1974 bss->eap_server = atoi(pos);
1975 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1976 if (hostapd_config_read_eap_user(pos, bss))
1977 return 1;
1978 } else if (os_strcmp(buf, "ca_cert") == 0) {
1979 os_free(bss->ca_cert);
1980 bss->ca_cert = os_strdup(pos);
1981 } else if (os_strcmp(buf, "server_cert") == 0) {
1982 os_free(bss->server_cert);
1983 bss->server_cert = os_strdup(pos);
1984 } else if (os_strcmp(buf, "private_key") == 0) {
1985 os_free(bss->private_key);
1986 bss->private_key = os_strdup(pos);
1987 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1988 os_free(bss->private_key_passwd);
1989 bss->private_key_passwd = os_strdup(pos);
1990 } else if (os_strcmp(buf, "check_crl") == 0) {
1991 bss->check_crl = atoi(pos);
1992 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
1993 os_free(bss->ocsp_stapling_response);
1994 bss->ocsp_stapling_response = os_strdup(pos);
1995 } else if (os_strcmp(buf, "dh_file") == 0) {
1996 os_free(bss->dh_file);
1997 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001998 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
1999 os_free(bss->openssl_ciphers);
2000 bss->openssl_ciphers = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002001 } else if (os_strcmp(buf, "fragment_size") == 0) {
2002 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002004 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2005 os_free(bss->pac_opaque_encr_key);
2006 bss->pac_opaque_encr_key = os_malloc(16);
2007 if (bss->pac_opaque_encr_key == NULL) {
2008 wpa_printf(MSG_ERROR,
2009 "Line %d: No memory for pac_opaque_encr_key",
2010 line);
2011 return 1;
2012 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2013 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2014 line);
2015 return 1;
2016 }
2017 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2018 size_t idlen = os_strlen(pos);
2019 if (idlen & 1) {
2020 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2021 line);
2022 return 1;
2023 }
2024 os_free(bss->eap_fast_a_id);
2025 bss->eap_fast_a_id = os_malloc(idlen / 2);
2026 if (bss->eap_fast_a_id == NULL ||
2027 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2028 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2029 line);
2030 os_free(bss->eap_fast_a_id);
2031 bss->eap_fast_a_id = NULL;
2032 return 1;
2033 } else {
2034 bss->eap_fast_a_id_len = idlen / 2;
2035 }
2036 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2037 os_free(bss->eap_fast_a_id_info);
2038 bss->eap_fast_a_id_info = os_strdup(pos);
2039 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2040 bss->eap_fast_prov = atoi(pos);
2041 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2042 bss->pac_key_lifetime = atoi(pos);
2043 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2044 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045#endif /* EAP_SERVER_FAST */
2046#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002047 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2048 os_free(bss->eap_sim_db);
2049 bss->eap_sim_db = os_strdup(pos);
2050 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2051 bss->eap_sim_aka_result_ind = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002052#endif /* EAP_SERVER_SIM */
2053#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002054 } else if (os_strcmp(buf, "tnc") == 0) {
2055 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002056#endif /* EAP_SERVER_TNC */
2057#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002058 } else if (os_strcmp(buf, "pwd_group") == 0) {
2059 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002060#endif /* EAP_SERVER_PWD */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002061 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2062 bss->eap_server_erp = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002063#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002064 } else if (os_strcmp(buf, "eap_message") == 0) {
2065 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002066 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002067 bss->eap_req_id_text = os_strdup(pos);
2068 if (bss->eap_req_id_text == NULL) {
2069 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2070 line);
2071 return 1;
2072 }
2073 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2074 term = os_strstr(bss->eap_req_id_text, "\\0");
2075 if (term) {
2076 *term++ = '\0';
2077 os_memmove(term, term + 1,
2078 bss->eap_req_id_text_len -
2079 (term - bss->eap_req_id_text) - 1);
2080 bss->eap_req_id_text_len--;
2081 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002082 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2083 bss->erp_send_reauth_start = atoi(pos);
2084 } else if (os_strcmp(buf, "erp_domain") == 0) {
2085 os_free(bss->erp_domain);
2086 bss->erp_domain = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002087 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
2088 bss->default_wep_key_len = atoi(pos);
2089 if (bss->default_wep_key_len > 13) {
2090 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
2091 line,
2092 (unsigned long) bss->default_wep_key_len,
2093 (unsigned long)
2094 bss->default_wep_key_len * 8);
2095 return 1;
2096 }
2097 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
2098 bss->individual_wep_key_len = atoi(pos);
2099 if (bss->individual_wep_key_len < 0 ||
2100 bss->individual_wep_key_len > 13) {
2101 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
2102 line, bss->individual_wep_key_len,
2103 bss->individual_wep_key_len * 8);
2104 return 1;
2105 }
2106 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2107 bss->wep_rekeying_period = atoi(pos);
2108 if (bss->wep_rekeying_period < 0) {
2109 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2110 line, bss->wep_rekeying_period);
2111 return 1;
2112 }
2113 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2114 bss->eap_reauth_period = atoi(pos);
2115 if (bss->eap_reauth_period < 0) {
2116 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2117 line, bss->eap_reauth_period);
2118 return 1;
2119 }
2120 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2121 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002123 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2124 bss->ieee802_11f = 1;
2125 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002127 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2128 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2129 wpa_printf(MSG_ERROR,
2130 "Line %d: invalid IP address '%s'",
2131 line, pos);
2132 return 1;
2133 }
2134 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002135 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002136 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137#ifndef CONFIG_NO_RADIUS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002138 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2139 if (hostapd_config_read_radius_addr(
2140 &bss->radius->auth_servers,
2141 &bss->radius->num_auth_servers, pos, 1812,
2142 &bss->radius->auth_server)) {
2143 wpa_printf(MSG_ERROR,
2144 "Line %d: invalid IP address '%s'",
2145 line, pos);
2146 return 1;
2147 }
2148 } else if (bss->radius->auth_server &&
2149 os_strcmp(buf, "auth_server_port") == 0) {
2150 bss->radius->auth_server->port = atoi(pos);
2151 } else if (bss->radius->auth_server &&
2152 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2153 int len = os_strlen(pos);
2154 if (len == 0) {
2155 /* RFC 2865, Ch. 3 */
2156 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2157 line);
2158 return 1;
2159 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002160 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002161 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2162 bss->radius->auth_server->shared_secret_len = len;
2163 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2164 if (hostapd_config_read_radius_addr(
2165 &bss->radius->acct_servers,
2166 &bss->radius->num_acct_servers, pos, 1813,
2167 &bss->radius->acct_server)) {
2168 wpa_printf(MSG_ERROR,
2169 "Line %d: invalid IP address '%s'",
2170 line, pos);
2171 return 1;
2172 }
2173 } else if (bss->radius->acct_server &&
2174 os_strcmp(buf, "acct_server_port") == 0) {
2175 bss->radius->acct_server->port = atoi(pos);
2176 } else if (bss->radius->acct_server &&
2177 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2178 int len = os_strlen(pos);
2179 if (len == 0) {
2180 /* RFC 2865, Ch. 3 */
2181 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2182 line);
2183 return 1;
2184 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002185 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002186 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2187 bss->radius->acct_server->shared_secret_len = len;
2188 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2189 bss->radius->retry_primary_interval = atoi(pos);
2190 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2191 bss->acct_interim_interval = atoi(pos);
2192 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2193 bss->radius_request_cui = atoi(pos);
2194 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2195 struct hostapd_radius_attr *attr, *a;
2196 attr = hostapd_parse_radius_attr(pos);
2197 if (attr == NULL) {
2198 wpa_printf(MSG_ERROR,
2199 "Line %d: invalid radius_auth_req_attr",
2200 line);
2201 return 1;
2202 } else if (bss->radius_auth_req_attr == NULL) {
2203 bss->radius_auth_req_attr = attr;
2204 } else {
2205 a = bss->radius_auth_req_attr;
2206 while (a->next)
2207 a = a->next;
2208 a->next = attr;
2209 }
2210 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2211 struct hostapd_radius_attr *attr, *a;
2212 attr = hostapd_parse_radius_attr(pos);
2213 if (attr == NULL) {
2214 wpa_printf(MSG_ERROR,
2215 "Line %d: invalid radius_acct_req_attr",
2216 line);
2217 return 1;
2218 } else if (bss->radius_acct_req_attr == NULL) {
2219 bss->radius_acct_req_attr = attr;
2220 } else {
2221 a = bss->radius_acct_req_attr;
2222 while (a->next)
2223 a = a->next;
2224 a->next = attr;
2225 }
2226 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2227 bss->radius_das_port = atoi(pos);
2228 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2229 if (hostapd_parse_das_client(bss, pos) < 0) {
2230 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2231 line);
2232 return 1;
2233 }
2234 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2235 bss->radius_das_time_window = atoi(pos);
2236 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2237 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002238#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002239 } else if (os_strcmp(buf, "auth_algs") == 0) {
2240 bss->auth_algs = atoi(pos);
2241 if (bss->auth_algs == 0) {
2242 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2243 line);
2244 return 1;
2245 }
2246 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2247 bss->max_num_sta = atoi(pos);
2248 if (bss->max_num_sta < 0 ||
2249 bss->max_num_sta > MAX_STA_COUNT) {
2250 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2251 line, bss->max_num_sta, MAX_STA_COUNT);
2252 return 1;
2253 }
2254 } else if (os_strcmp(buf, "wpa") == 0) {
2255 bss->wpa = atoi(pos);
2256 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2257 bss->wpa_group_rekey = atoi(pos);
2258 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2259 bss->wpa_strict_rekey = atoi(pos);
2260 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2261 bss->wpa_gmk_rekey = atoi(pos);
2262 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2263 bss->wpa_ptk_rekey = atoi(pos);
2264 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2265 int len = os_strlen(pos);
2266 if (len < 8 || len > 63) {
2267 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2268 line, len);
2269 return 1;
2270 }
2271 os_free(bss->ssid.wpa_passphrase);
2272 bss->ssid.wpa_passphrase = os_strdup(pos);
2273 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 os_free(bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002275 bss->ssid.wpa_psk = NULL;
2276 bss->ssid.wpa_passphrase_set = 1;
2277 }
2278 } else if (os_strcmp(buf, "wpa_psk") == 0) {
2279 os_free(bss->ssid.wpa_psk);
2280 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2281 if (bss->ssid.wpa_psk == NULL)
2282 return 1;
2283 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2284 pos[PMK_LEN * 2] != '\0') {
2285 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2286 line, pos);
2287 os_free(bss->ssid.wpa_psk);
2288 bss->ssid.wpa_psk = NULL;
2289 return 1;
2290 }
2291 bss->ssid.wpa_psk->group = 1;
2292 os_free(bss->ssid.wpa_passphrase);
2293 bss->ssid.wpa_passphrase = NULL;
2294 bss->ssid.wpa_psk_set = 1;
2295 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2296 os_free(bss->ssid.wpa_psk_file);
2297 bss->ssid.wpa_psk_file = os_strdup(pos);
2298 if (!bss->ssid.wpa_psk_file) {
2299 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2300 line);
2301 return 1;
2302 }
2303 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2304 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2305 if (bss->wpa_key_mgmt == -1)
2306 return 1;
2307 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2308 bss->wpa_psk_radius = atoi(pos);
2309 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2310 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2311 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2312 wpa_printf(MSG_ERROR,
2313 "Line %d: unknown wpa_psk_radius %d",
2314 line, bss->wpa_psk_radius);
2315 return 1;
2316 }
2317 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2318 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2319 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2320 return 1;
2321 if (bss->wpa_pairwise &
2322 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2323 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2324 bss->wpa_pairwise, pos);
2325 return 1;
2326 }
2327 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2328 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2329 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2330 return 1;
2331 if (bss->rsn_pairwise &
2332 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2333 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2334 bss->rsn_pairwise, pos);
2335 return 1;
2336 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002337#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002338 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2339 bss->rsn_preauth = atoi(pos);
2340 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002341 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002342 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002343#endif /* CONFIG_RSN_PREAUTH */
2344#ifdef CONFIG_PEERKEY
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002345 } else if (os_strcmp(buf, "peerkey") == 0) {
2346 bss->peerkey = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347#endif /* CONFIG_PEERKEY */
2348#ifdef CONFIG_IEEE80211R
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002349 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2350 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2351 hexstr2bin(pos, bss->mobility_domain,
2352 MOBILITY_DOMAIN_ID_LEN) != 0) {
2353 wpa_printf(MSG_ERROR,
2354 "Line %d: Invalid mobility_domain '%s'",
2355 line, pos);
2356 return 1;
2357 }
2358 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2359 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2360 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2361 wpa_printf(MSG_ERROR,
2362 "Line %d: Invalid r1_key_holder '%s'",
2363 line, pos);
2364 return 1;
2365 }
2366 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2367 bss->r0_key_lifetime = atoi(pos);
2368 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2369 bss->reassociation_deadline = atoi(pos);
2370 } else if (os_strcmp(buf, "r0kh") == 0) {
2371 if (add_r0kh(bss, pos) < 0) {
2372 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2373 line, pos);
2374 return 1;
2375 }
2376 } else if (os_strcmp(buf, "r1kh") == 0) {
2377 if (add_r1kh(bss, pos) < 0) {
2378 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2379 line, pos);
2380 return 1;
2381 }
2382 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2383 bss->pmk_r1_push = atoi(pos);
2384 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2385 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386#endif /* CONFIG_IEEE80211R */
2387#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002388 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2389 os_free(bss->ctrl_interface);
2390 bss->ctrl_interface = os_strdup(pos);
2391 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002392#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002393 struct group *grp;
2394 char *endp;
2395 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002397 grp = getgrnam(group);
2398 if (grp) {
2399 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002400 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002401 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2402 bss->ctrl_interface_gid, group);
2403 return 0;
2404 }
2405
2406 /* Group name not found - try to parse this as gid */
2407 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2408 if (*group == '\0' || *endp != '\0') {
2409 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2410 line, group);
2411 return 1;
2412 }
2413 bss->ctrl_interface_gid_set = 1;
2414 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2415 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416#endif /* CONFIG_NATIVE_WINDOWS */
2417#endif /* CONFIG_NO_CTRL_IFACE */
2418#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002419 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2420 os_free(bss->radius_server_clients);
2421 bss->radius_server_clients = os_strdup(pos);
2422 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2423 bss->radius_server_auth_port = atoi(pos);
2424 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2425 bss->radius_server_acct_port = atoi(pos);
2426 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2427 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002428#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002429 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2430 bss->use_pae_group_addr = atoi(pos);
2431 } else if (os_strcmp(buf, "hw_mode") == 0) {
2432 if (os_strcmp(pos, "a") == 0)
2433 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2434 else if (os_strcmp(pos, "b") == 0)
2435 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2436 else if (os_strcmp(pos, "g") == 0)
2437 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2438 else if (os_strcmp(pos, "ad") == 0)
2439 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
2440 else {
2441 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
2442 line, pos);
2443 return 1;
2444 }
2445 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2446 if (os_strcmp(pos, "a") == 0)
2447 bss->wps_rf_bands = WPS_RF_50GHZ;
2448 else if (os_strcmp(pos, "g") == 0 ||
2449 os_strcmp(pos, "b") == 0)
2450 bss->wps_rf_bands = WPS_RF_24GHZ;
2451 else if (os_strcmp(pos, "ag") == 0 ||
2452 os_strcmp(pos, "ga") == 0)
2453 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
2454 else {
2455 wpa_printf(MSG_ERROR,
2456 "Line %d: unknown wps_rf_band '%s'",
2457 line, pos);
2458 return 1;
2459 }
2460 } else if (os_strcmp(buf, "channel") == 0) {
2461 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002462#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002463 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
2464 line);
2465 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002466#else /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002467 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002468#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002469 } else
2470 conf->channel = atoi(pos);
2471 } else if (os_strcmp(buf, "chanlist") == 0) {
2472 if (hostapd_parse_intlist(&conf->chanlist, pos)) {
2473 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
2474 line);
2475 return 1;
2476 }
2477 } else if (os_strcmp(buf, "beacon_int") == 0) {
2478 int val = atoi(pos);
2479 /* MIB defines range as 1..65535, but very small values
2480 * cause problems with the current implementation.
2481 * Since it is unlikely that this small numbers are
2482 * useful in real life scenarios, do not allow beacon
2483 * period to be set below 15 TU. */
2484 if (val < 15 || val > 65535) {
2485 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
2486 line, val);
2487 return 1;
2488 }
2489 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002490#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002491 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
2492 int val = atoi(pos);
2493 if (val <= 0 || val > 100) {
2494 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
2495 line, val);
2496 return 1;
2497 }
2498 conf->acs_num_scans = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002499#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002500 } else if (os_strcmp(buf, "dtim_period") == 0) {
2501 bss->dtim_period = atoi(pos);
2502 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2503 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
2504 line, bss->dtim_period);
2505 return 1;
2506 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002507 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
2508 bss->bss_load_update_period = atoi(pos);
2509 if (bss->bss_load_update_period < 0 ||
2510 bss->bss_load_update_period > 100) {
2511 wpa_printf(MSG_ERROR,
2512 "Line %d: invalid bss_load_update_period %d",
2513 line, bss->bss_load_update_period);
2514 return 1;
2515 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002516 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2517 conf->rts_threshold = atoi(pos);
2518 if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
2519 wpa_printf(MSG_ERROR,
2520 "Line %d: invalid rts_threshold %d",
2521 line, conf->rts_threshold);
2522 return 1;
2523 }
2524 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2525 conf->fragm_threshold = atoi(pos);
2526 if (conf->fragm_threshold < 256 ||
2527 conf->fragm_threshold > 2346) {
2528 wpa_printf(MSG_ERROR,
2529 "Line %d: invalid fragm_threshold %d",
2530 line, conf->fragm_threshold);
2531 return 1;
2532 }
2533 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2534 int val = atoi(pos);
2535 if (val != 0 && val != 1) {
2536 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
2537 line, val);
2538 return 1;
2539 }
2540 conf->send_probe_response = val;
2541 } else if (os_strcmp(buf, "supported_rates") == 0) {
2542 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
2543 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2544 line);
2545 return 1;
2546 }
2547 } else if (os_strcmp(buf, "basic_rates") == 0) {
2548 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
2549 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2550 line);
2551 return 1;
2552 }
2553 } else if (os_strcmp(buf, "preamble") == 0) {
2554 if (atoi(pos))
2555 conf->preamble = SHORT_PREAMBLE;
2556 else
2557 conf->preamble = LONG_PREAMBLE;
2558 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2559 bss->ignore_broadcast_ssid = atoi(pos);
2560 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2561 bss->ssid.wep.idx = atoi(pos);
2562 if (bss->ssid.wep.idx > 3) {
2563 wpa_printf(MSG_ERROR,
2564 "Invalid wep_default_key index %d",
2565 bss->ssid.wep.idx);
2566 return 1;
2567 }
2568 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2569 os_strcmp(buf, "wep_key1") == 0 ||
2570 os_strcmp(buf, "wep_key2") == 0 ||
2571 os_strcmp(buf, "wep_key3") == 0) {
2572 if (hostapd_config_read_wep(&bss->ssid.wep,
2573 buf[7] - '0', pos)) {
2574 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
2575 line, buf);
2576 return 1;
2577 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002579 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2580 bss->ssid.dynamic_vlan = atoi(pos);
2581 } else if (os_strcmp(buf, "vlan_file") == 0) {
2582 if (hostapd_config_read_vlan_file(bss, pos)) {
2583 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
2584 line, pos);
2585 return 1;
2586 }
2587 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2588 bss->ssid.vlan_naming = atoi(pos);
2589 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2590 bss->ssid.vlan_naming < 0) {
2591 wpa_printf(MSG_ERROR,
2592 "Line %d: invalid naming scheme %d",
2593 line, bss->ssid.vlan_naming);
2594 return 1;
2595 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002596#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002597 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002598 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002599 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002600#endif /* CONFIG_FULL_DYNAMIC_VLAN */
2601#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002602 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2603 conf->ap_table_max_size = atoi(pos);
2604 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2605 conf->ap_table_expiration_time = atoi(pos);
2606 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2607 if (hostapd_config_tx_queue(conf, buf, pos)) {
2608 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
2609 line);
2610 return 1;
2611 }
2612 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2613 os_strcmp(buf, "wmm_enabled") == 0) {
2614 bss->wmm_enabled = atoi(pos);
2615 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2616 bss->wmm_uapsd = atoi(pos);
2617 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2618 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2619 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
2620 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
2621 line);
2622 return 1;
2623 }
2624 } else if (os_strcmp(buf, "bss") == 0) {
2625 if (hostapd_config_bss(conf, pos)) {
2626 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
2627 line);
2628 return 1;
2629 }
2630 } else if (os_strcmp(buf, "bssid") == 0) {
2631 if (hwaddr_aton(pos, bss->bssid)) {
2632 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
2633 line);
2634 return 1;
2635 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636#ifdef CONFIG_IEEE80211W
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002637 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2638 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002639 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
2640 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
2641 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
2642 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
2643 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
2644 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
2645 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
2646 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
2647 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
2648 } else {
2649 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
2650 line, pos);
2651 return 1;
2652 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002653 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2654 bss->assoc_sa_query_max_timeout = atoi(pos);
2655 if (bss->assoc_sa_query_max_timeout == 0) {
2656 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
2657 line);
2658 return 1;
2659 }
2660 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
2661 bss->assoc_sa_query_retry_timeout = atoi(pos);
2662 if (bss->assoc_sa_query_retry_timeout == 0) {
2663 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
2664 line);
2665 return 1;
2666 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002667#endif /* CONFIG_IEEE80211W */
2668#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002669 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2670 conf->ieee80211n = atoi(pos);
2671 } else if (os_strcmp(buf, "ht_capab") == 0) {
2672 if (hostapd_config_ht_capab(conf, pos) < 0) {
2673 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
2674 line);
2675 return 1;
2676 }
2677 } else if (os_strcmp(buf, "require_ht") == 0) {
2678 conf->require_ht = atoi(pos);
2679 } else if (os_strcmp(buf, "obss_interval") == 0) {
2680 conf->obss_interval = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002681#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002682#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002683 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2684 conf->ieee80211ac = atoi(pos);
2685 } else if (os_strcmp(buf, "vht_capab") == 0) {
2686 if (hostapd_config_vht_capab(conf, pos) < 0) {
2687 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
2688 line);
2689 return 1;
2690 }
2691 } else if (os_strcmp(buf, "require_vht") == 0) {
2692 conf->require_vht = atoi(pos);
2693 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2694 conf->vht_oper_chwidth = atoi(pos);
2695 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
2696 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2697 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
2698 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002699 } else if (os_strcmp(buf, "vendor_vht") == 0) {
2700 bss->vendor_vht = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002701#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002702 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2703 bss->max_listen_interval = atoi(pos);
2704 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2705 bss->disable_pmksa_caching = atoi(pos);
2706 } else if (os_strcmp(buf, "okc") == 0) {
2707 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002709 } else if (os_strcmp(buf, "wps_state") == 0) {
2710 bss->wps_state = atoi(pos);
2711 if (bss->wps_state < 0 || bss->wps_state > 2) {
2712 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
2713 line);
2714 return 1;
2715 }
2716 } else if (os_strcmp(buf, "wps_independent") == 0) {
2717 bss->wps_independent = atoi(pos);
2718 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2719 bss->ap_setup_locked = atoi(pos);
2720 } else if (os_strcmp(buf, "uuid") == 0) {
2721 if (uuid_str2bin(pos, bss->uuid)) {
2722 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2723 return 1;
2724 }
2725 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2726 os_free(bss->wps_pin_requests);
2727 bss->wps_pin_requests = os_strdup(pos);
2728 } else if (os_strcmp(buf, "device_name") == 0) {
2729 if (os_strlen(pos) > 32) {
2730 wpa_printf(MSG_ERROR, "Line %d: Too long "
2731 "device_name", line);
2732 return 1;
2733 }
2734 os_free(bss->device_name);
2735 bss->device_name = os_strdup(pos);
2736 } else if (os_strcmp(buf, "manufacturer") == 0) {
2737 if (os_strlen(pos) > 64) {
2738 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
2739 line);
2740 return 1;
2741 }
2742 os_free(bss->manufacturer);
2743 bss->manufacturer = os_strdup(pos);
2744 } else if (os_strcmp(buf, "model_name") == 0) {
2745 if (os_strlen(pos) > 32) {
2746 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
2747 line);
2748 return 1;
2749 }
2750 os_free(bss->model_name);
2751 bss->model_name = os_strdup(pos);
2752 } else if (os_strcmp(buf, "model_number") == 0) {
2753 if (os_strlen(pos) > 32) {
2754 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
2755 line);
2756 return 1;
2757 }
2758 os_free(bss->model_number);
2759 bss->model_number = os_strdup(pos);
2760 } else if (os_strcmp(buf, "serial_number") == 0) {
2761 if (os_strlen(pos) > 32) {
2762 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
2763 line);
2764 return 1;
2765 }
2766 os_free(bss->serial_number);
2767 bss->serial_number = os_strdup(pos);
2768 } else if (os_strcmp(buf, "device_type") == 0) {
2769 if (wps_dev_type_str2bin(pos, bss->device_type))
2770 return 1;
2771 } else if (os_strcmp(buf, "config_methods") == 0) {
2772 os_free(bss->config_methods);
2773 bss->config_methods = os_strdup(pos);
2774 } else if (os_strcmp(buf, "os_version") == 0) {
2775 if (hexstr2bin(pos, bss->os_version, 4)) {
2776 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
2777 line);
2778 return 1;
2779 }
2780 } else if (os_strcmp(buf, "ap_pin") == 0) {
2781 os_free(bss->ap_pin);
2782 bss->ap_pin = os_strdup(pos);
2783 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2784 bss->skip_cred_build = atoi(pos);
2785 } else if (os_strcmp(buf, "extra_cred") == 0) {
2786 os_free(bss->extra_cred);
2787 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
2788 if (bss->extra_cred == NULL) {
2789 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
2790 line, pos);
2791 return 1;
2792 }
2793 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2794 bss->wps_cred_processing = atoi(pos);
2795 } else if (os_strcmp(buf, "ap_settings") == 0) {
2796 os_free(bss->ap_settings);
2797 bss->ap_settings =
2798 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2799 if (bss->ap_settings == NULL) {
2800 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
2801 line, pos);
2802 return 1;
2803 }
2804 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002805 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002806 bss->upnp_iface = os_strdup(pos);
2807 } else if (os_strcmp(buf, "friendly_name") == 0) {
2808 os_free(bss->friendly_name);
2809 bss->friendly_name = os_strdup(pos);
2810 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2811 os_free(bss->manufacturer_url);
2812 bss->manufacturer_url = os_strdup(pos);
2813 } else if (os_strcmp(buf, "model_description") == 0) {
2814 os_free(bss->model_description);
2815 bss->model_description = os_strdup(pos);
2816 } else if (os_strcmp(buf, "model_url") == 0) {
2817 os_free(bss->model_url);
2818 bss->model_url = os_strdup(pos);
2819 } else if (os_strcmp(buf, "upc") == 0) {
2820 os_free(bss->upc);
2821 bss->upc = os_strdup(pos);
2822 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2823 bss->pbc_in_m1 = atoi(pos);
2824 } else if (os_strcmp(buf, "server_id") == 0) {
2825 os_free(bss->server_id);
2826 bss->server_id = os_strdup(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002827#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002828 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2829 bss->wps_nfc_dev_pw_id = atoi(pos);
2830 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2831 bss->wps_nfc_dev_pw_id > 0xffff) {
2832 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
2833 line);
2834 return 1;
2835 }
2836 bss->wps_nfc_pw_from_config = 1;
2837 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2838 wpabuf_free(bss->wps_nfc_dh_pubkey);
2839 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2840 bss->wps_nfc_pw_from_config = 1;
2841 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2842 wpabuf_free(bss->wps_nfc_dh_privkey);
2843 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2844 bss->wps_nfc_pw_from_config = 1;
2845 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2846 wpabuf_free(bss->wps_nfc_dev_pw);
2847 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2848 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002849#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850#endif /* CONFIG_WPS */
2851#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002852 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2853 if (atoi(pos))
2854 bss->p2p |= P2P_MANAGE;
2855 else
2856 bss->p2p &= ~P2P_MANAGE;
2857 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2858 if (atoi(pos))
2859 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2860 else
2861 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002863 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2864 bss->disassoc_low_ack = atoi(pos);
2865 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2866 if (atoi(pos))
2867 bss->tdls |= TDLS_PROHIBIT;
2868 else
2869 bss->tdls &= ~TDLS_PROHIBIT;
2870 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2871 if (atoi(pos))
2872 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2873 else
2874 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002876 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2877 extern int rsn_testing;
2878 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002879#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002880 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2881 bss->time_advertisement = atoi(pos);
2882 } else if (os_strcmp(buf, "time_zone") == 0) {
2883 size_t tz_len = os_strlen(pos);
2884 if (tz_len < 4 || tz_len > 255) {
2885 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
2886 line);
2887 return 1;
2888 }
2889 os_free(bss->time_zone);
2890 bss->time_zone = os_strdup(pos);
2891 if (bss->time_zone == NULL)
2892 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002893#ifdef CONFIG_WNM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002894 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
2895 bss->wnm_sleep_mode = atoi(pos);
2896 } else if (os_strcmp(buf, "bss_transition") == 0) {
2897 bss->bss_transition = atoi(pos);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002898#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002899#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002900 } else if (os_strcmp(buf, "interworking") == 0) {
2901 bss->interworking = atoi(pos);
2902 } else if (os_strcmp(buf, "access_network_type") == 0) {
2903 bss->access_network_type = atoi(pos);
2904 if (bss->access_network_type < 0 ||
2905 bss->access_network_type > 15) {
2906 wpa_printf(MSG_ERROR,
2907 "Line %d: invalid access_network_type",
2908 line);
2909 return 1;
2910 }
2911 } else if (os_strcmp(buf, "internet") == 0) {
2912 bss->internet = atoi(pos);
2913 } else if (os_strcmp(buf, "asra") == 0) {
2914 bss->asra = atoi(pos);
2915 } else if (os_strcmp(buf, "esr") == 0) {
2916 bss->esr = atoi(pos);
2917 } else if (os_strcmp(buf, "uesa") == 0) {
2918 bss->uesa = atoi(pos);
2919 } else if (os_strcmp(buf, "venue_group") == 0) {
2920 bss->venue_group = atoi(pos);
2921 bss->venue_info_set = 1;
2922 } else if (os_strcmp(buf, "venue_type") == 0) {
2923 bss->venue_type = atoi(pos);
2924 bss->venue_info_set = 1;
2925 } else if (os_strcmp(buf, "hessid") == 0) {
2926 if (hwaddr_aton(pos, bss->hessid)) {
2927 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
2928 return 1;
2929 }
2930 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
2931 if (parse_roaming_consortium(bss, pos, line) < 0)
2932 return 1;
2933 } else if (os_strcmp(buf, "venue_name") == 0) {
2934 if (parse_venue_name(bss, pos, line) < 0)
2935 return 1;
2936 } else if (os_strcmp(buf, "network_auth_type") == 0) {
2937 u8 auth_type;
2938 u16 redirect_url_len;
2939 if (hexstr2bin(pos, &auth_type, 1)) {
2940 wpa_printf(MSG_ERROR,
2941 "Line %d: Invalid network_auth_type '%s'",
2942 line, pos);
2943 return 1;
2944 }
2945 if (auth_type == 0 || auth_type == 2)
2946 redirect_url_len = os_strlen(pos + 2);
2947 else
2948 redirect_url_len = 0;
2949 os_free(bss->network_auth_type);
2950 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
2951 if (bss->network_auth_type == NULL)
2952 return 1;
2953 *bss->network_auth_type = auth_type;
2954 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
2955 if (redirect_url_len)
2956 os_memcpy(bss->network_auth_type + 3, pos + 2,
2957 redirect_url_len);
2958 bss->network_auth_type_len = 3 + redirect_url_len;
2959 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
2960 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
2961 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
2962 line, pos);
2963 bss->ipaddr_type_configured = 0;
2964 return 1;
2965 }
2966 bss->ipaddr_type_configured = 1;
2967 } else if (os_strcmp(buf, "domain_name") == 0) {
2968 int j, num_domains, domain_len, domain_list_len = 0;
2969 char *tok_start, *tok_prev;
2970 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002971
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002972 domain_list_len = os_strlen(pos) + 1;
2973 domain_list = os_malloc(domain_list_len);
2974 if (domain_list == NULL)
2975 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002976
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002977 domain_ptr = domain_list;
2978 tok_prev = pos;
2979 num_domains = 1;
2980 while ((tok_prev = os_strchr(tok_prev, ','))) {
2981 num_domains++;
2982 tok_prev++;
2983 }
2984 tok_prev = pos;
2985 for (j = 0; j < num_domains; j++) {
2986 tok_start = os_strchr(tok_prev, ',');
2987 if (tok_start) {
2988 domain_len = tok_start - tok_prev;
2989 *domain_ptr = domain_len;
2990 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
2991 domain_ptr += domain_len + 1;
2992 tok_prev = ++tok_start;
2993 } else {
2994 domain_len = os_strlen(tok_prev);
2995 *domain_ptr = domain_len;
2996 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
2997 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002998 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002999 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003000
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003001 os_free(bss->domain_name);
3002 bss->domain_name = domain_list;
3003 bss->domain_name_len = domain_list_len;
3004 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3005 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3006 return 1;
3007 } else if (os_strcmp(buf, "nai_realm") == 0) {
3008 if (parse_nai_realm(bss, pos, line) < 0)
3009 return 1;
3010 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
3011 bss->gas_frag_limit = atoi(pos);
3012 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3013 bss->gas_comeback_delay = atoi(pos);
3014 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3015 if (parse_qos_map_set(bss, pos, line) < 0)
3016 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003017#endif /* CONFIG_INTERWORKING */
3018#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003019 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3020 os_free(bss->dump_msk_file);
3021 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003022#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003023#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003024 } else if (os_strcmp(buf, "hs20") == 0) {
3025 bss->hs20 = atoi(pos);
3026 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3027 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003028 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3029 bss->proxy_arp = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003030 } else if (os_strcmp(buf, "osen") == 0) {
3031 bss->osen = atoi(pos);
3032 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3033 bss->anqp_domain_id = atoi(pos);
3034 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3035 bss->hs20_deauth_req_timeout = atoi(pos);
3036 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3037 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3038 return 1;
3039 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3040 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3041 return 1;
3042 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3043 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3044 return 1;
3045 }
3046 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3047 u8 *oper_class;
3048 size_t oper_class_len;
3049 oper_class_len = os_strlen(pos);
3050 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3051 wpa_printf(MSG_ERROR,
3052 "Line %d: Invalid hs20_operating_class '%s'",
3053 line, pos);
3054 return 1;
3055 }
3056 oper_class_len /= 2;
3057 oper_class = os_malloc(oper_class_len);
3058 if (oper_class == NULL)
3059 return 1;
3060 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3061 wpa_printf(MSG_ERROR,
3062 "Line %d: Invalid hs20_operating_class '%s'",
3063 line, pos);
3064 os_free(oper_class);
3065 return 1;
3066 }
3067 os_free(bss->hs20_operating_class);
3068 bss->hs20_operating_class = oper_class;
3069 bss->hs20_operating_class_len = oper_class_len;
3070 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3071 if (hs20_parse_icon(bss, pos) < 0) {
3072 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3073 line, pos);
3074 return 1;
3075 }
3076 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3077 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
3078 return 1;
3079 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3080 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
3081 return 1;
3082 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3083 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
3084 return 1;
3085 } else if (os_strcmp(buf, "osu_nai") == 0) {
3086 if (hs20_parse_osu_nai(bss, pos, line) < 0)
3087 return 1;
3088 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3089 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
3090 return 1;
3091 } else if (os_strcmp(buf, "osu_icon") == 0) {
3092 if (hs20_parse_osu_icon(bss, pos, line) < 0)
3093 return 1;
3094 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3095 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
3096 return 1;
3097 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3098 os_free(bss->subscr_remediation_url);
3099 bss->subscr_remediation_url = os_strdup(pos);
3100 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3101 bss->subscr_remediation_method = atoi(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003102#endif /* CONFIG_HS20 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003103#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003104#define PARSE_TEST_PROBABILITY(_val) \
3105 } else if (os_strcmp(buf, #_val) == 0) { \
3106 char *end; \
3107 \
3108 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003109 if (*end || conf->_val < 0.0 || \
3110 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003111 wpa_printf(MSG_ERROR, \
3112 "Line %d: Invalid value '%s'", \
3113 line, pos); \
3114 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003115 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003116 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3117 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3118 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3119 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3120 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
3121 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3122 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3123 pos = os_strchr(pos, ':');
3124 if (pos == NULL) {
3125 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3126 line);
3127 return 1;
3128 }
3129 pos++;
3130 bss->bss_load_test[2] = atoi(pos);
3131 pos = os_strchr(pos, ':');
3132 if (pos == NULL) {
3133 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3134 line);
3135 return 1;
3136 }
3137 pos++;
3138 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3139 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003140 } else if (os_strcmp(buf, "radio_measurements") == 0) {
3141 bss->radio_measurements = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003142#endif /* CONFIG_TESTING_OPTIONS */
3143 } else if (os_strcmp(buf, "vendor_elements") == 0) {
3144 struct wpabuf *elems;
3145 size_t len = os_strlen(pos);
3146 if (len & 0x01) {
3147 wpa_printf(MSG_ERROR,
3148 "Line %d: Invalid vendor_elements '%s'",
3149 line, pos);
3150 return 1;
3151 }
3152 len /= 2;
3153 if (len == 0) {
3154 wpabuf_free(bss->vendor_elements);
3155 bss->vendor_elements = NULL;
3156 return 0;
3157 }
3158
3159 elems = wpabuf_alloc(len);
3160 if (elems == NULL)
3161 return 1;
3162
3163 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
3164 wpabuf_free(elems);
3165 wpa_printf(MSG_ERROR,
3166 "Line %d: Invalid vendor_elements '%s'",
3167 line, pos);
3168 return 1;
3169 }
3170
3171 wpabuf_free(bss->vendor_elements);
3172 bss->vendor_elements = elems;
3173 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3174 bss->sae_anti_clogging_threshold = atoi(pos);
3175 } else if (os_strcmp(buf, "sae_groups") == 0) {
3176 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3177 wpa_printf(MSG_ERROR,
3178 "Line %d: Invalid sae_groups value '%s'",
3179 line, pos);
3180 return 1;
3181 }
3182 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3183 int val = atoi(pos);
3184 if (val < 0 || val > 255) {
3185 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3186 line, val);
3187 return 1;
3188 }
3189 conf->local_pwr_constraint = val;
3190 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3191 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07003192 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3193 os_free(bss->wowlan_triggers);
3194 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003195 } else {
3196 wpa_printf(MSG_ERROR,
3197 "Line %d: unknown configuration item '%s'",
3198 line, buf);
3199 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003200 }
3201
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003202 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003203}
3204
3205
Dmitry Shmidt04949592012-07-19 12:16:46 -07003206/**
3207 * hostapd_config_read - Read and parse a configuration file
3208 * @fname: Configuration file name (including path, if needed)
3209 * Returns: Allocated configuration data structure
3210 */
3211struct hostapd_config * hostapd_config_read(const char *fname)
3212{
3213 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003214 FILE *f;
3215 char buf[512], *pos;
3216 int line = 0;
3217 int errors = 0;
3218 size_t i;
3219
3220 f = fopen(fname, "r");
3221 if (f == NULL) {
3222 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3223 "for reading.", fname);
3224 return NULL;
3225 }
3226
3227 conf = hostapd_config_defaults();
3228 if (conf == NULL) {
3229 fclose(f);
3230 return NULL;
3231 }
3232
3233 /* set default driver based on configuration */
3234 conf->driver = wpa_drivers[0];
3235 if (conf->driver == NULL) {
3236 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3237 hostapd_config_free(conf);
3238 fclose(f);
3239 return NULL;
3240 }
3241
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003242 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07003243
3244 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003245 struct hostapd_bss_config *bss;
3246
Dmitry Shmidt04949592012-07-19 12:16:46 -07003247 bss = conf->last_bss;
3248 line++;
3249
3250 if (buf[0] == '#')
3251 continue;
3252 pos = buf;
3253 while (*pos != '\0') {
3254 if (*pos == '\n') {
3255 *pos = '\0';
3256 break;
3257 }
3258 pos++;
3259 }
3260 if (buf[0] == '\0')
3261 continue;
3262
3263 pos = os_strchr(buf, '=');
3264 if (pos == NULL) {
3265 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3266 line, buf);
3267 errors++;
3268 continue;
3269 }
3270 *pos = '\0';
3271 pos++;
3272 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3273 }
3274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003275 fclose(f);
3276
Dmitry Shmidt04949592012-07-19 12:16:46 -07003277 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07003278 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003279
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003280 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003281 errors++;
3282
3283#ifndef WPA_IGNORE_CONFIG_ERRORS
3284 if (errors) {
3285 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3286 "'%s'", errors, fname);
3287 hostapd_config_free(conf);
3288 conf = NULL;
3289 }
3290#endif /* WPA_IGNORE_CONFIG_ERRORS */
3291
3292 return conf;
3293}
Dmitry Shmidt04949592012-07-19 12:16:46 -07003294
3295
3296int hostapd_set_iface(struct hostapd_config *conf,
3297 struct hostapd_bss_config *bss, char *field, char *value)
3298{
3299 int errors;
3300 size_t i;
3301
3302 errors = hostapd_config_fill(conf, bss, field, value, 0);
3303 if (errors) {
3304 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3305 "to value '%s'", field, value);
3306 return -1;
3307 }
3308
3309 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07003310 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003311
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003312 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003313 wpa_printf(MSG_ERROR, "Configuration check failed");
3314 return -1;
3315 }
3316
3317 return 0;
3318}