blob: cae9fd30d008a824afd2f735bc4101400b7112b7 [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 Shmidt216983b2015-02-06 10:50:36 -0800219 struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = 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) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800497 tail = new_user = user;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 } 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
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800513 if (ret == 0) {
514 user = conf->eap_user;
515 while (user) {
516 struct hostapd_eap_user *prev;
517
518 prev = user;
519 user = user->next;
520 hostapd_config_free_eap_user(prev);
521 }
522 conf->eap_user = new_user;
523 }
524
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 return ret;
526}
527#endif /* EAP_SERVER */
528
529
530#ifndef CONFIG_NO_RADIUS
531static int
532hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
533 int *num_server, const char *val, int def_port,
534 struct hostapd_radius_server **curr_serv)
535{
536 struct hostapd_radius_server *nserv;
537 int ret;
538 static int server_index = 1;
539
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700540 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 if (nserv == NULL)
542 return -1;
543
544 *server = nserv;
545 nserv = &nserv[*num_server];
546 (*num_server)++;
547 (*curr_serv) = nserv;
548
549 os_memset(nserv, 0, sizeof(*nserv));
550 nserv->port = def_port;
551 ret = hostapd_parse_ip_addr(val, &nserv->addr);
552 nserv->index = server_index++;
553
554 return ret;
555}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700556
557
558static struct hostapd_radius_attr *
559hostapd_parse_radius_attr(const char *value)
560{
561 const char *pos;
562 char syntax;
563 struct hostapd_radius_attr *attr;
564 size_t len;
565
566 attr = os_zalloc(sizeof(*attr));
567 if (attr == NULL)
568 return NULL;
569
570 attr->type = atoi(value);
571
572 pos = os_strchr(value, ':');
573 if (pos == NULL) {
574 attr->val = wpabuf_alloc(1);
575 if (attr->val == NULL) {
576 os_free(attr);
577 return NULL;
578 }
579 wpabuf_put_u8(attr->val, 0);
580 return attr;
581 }
582
583 pos++;
584 if (pos[0] == '\0' || pos[1] != ':') {
585 os_free(attr);
586 return NULL;
587 }
588 syntax = *pos++;
589 pos++;
590
591 switch (syntax) {
592 case 's':
593 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
594 break;
595 case 'x':
596 len = os_strlen(pos);
597 if (len & 1)
598 break;
599 len /= 2;
600 attr->val = wpabuf_alloc(len);
601 if (attr->val == NULL)
602 break;
603 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
604 wpabuf_free(attr->val);
605 os_free(attr);
606 return NULL;
607 }
608 break;
609 case 'd':
610 attr->val = wpabuf_alloc(4);
611 if (attr->val)
612 wpabuf_put_be32(attr->val, atoi(pos));
613 break;
614 default:
615 os_free(attr);
616 return NULL;
617 }
618
619 if (attr->val == NULL) {
620 os_free(attr);
621 return NULL;
622 }
623
624 return attr;
625}
626
627
628static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
629 const char *val)
630{
631 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700632
633 secret = os_strchr(val, ' ');
634 if (secret == NULL)
635 return -1;
636
637 secret++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700638
639 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
640 return -1;
641
642 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700643 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700644 if (bss->radius_das_shared_secret == NULL)
645 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700646 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700647
648 return 0;
649}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650#endif /* CONFIG_NO_RADIUS */
651
652
653static int hostapd_config_parse_key_mgmt(int line, const char *value)
654{
655 int val = 0, last;
656 char *start, *end, *buf;
657
658 buf = os_strdup(value);
659 if (buf == NULL)
660 return -1;
661 start = buf;
662
663 while (*start != '\0') {
664 while (*start == ' ' || *start == '\t')
665 start++;
666 if (*start == '\0')
667 break;
668 end = start;
669 while (*end != ' ' && *end != '\t' && *end != '\0')
670 end++;
671 last = *end == '\0';
672 *end = '\0';
673 if (os_strcmp(start, "WPA-PSK") == 0)
674 val |= WPA_KEY_MGMT_PSK;
675 else if (os_strcmp(start, "WPA-EAP") == 0)
676 val |= WPA_KEY_MGMT_IEEE8021X;
677#ifdef CONFIG_IEEE80211R
678 else if (os_strcmp(start, "FT-PSK") == 0)
679 val |= WPA_KEY_MGMT_FT_PSK;
680 else if (os_strcmp(start, "FT-EAP") == 0)
681 val |= WPA_KEY_MGMT_FT_IEEE8021X;
682#endif /* CONFIG_IEEE80211R */
683#ifdef CONFIG_IEEE80211W
684 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
685 val |= WPA_KEY_MGMT_PSK_SHA256;
686 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
687 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
688#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800689#ifdef CONFIG_SAE
690 else if (os_strcmp(start, "SAE") == 0)
691 val |= WPA_KEY_MGMT_SAE;
692 else if (os_strcmp(start, "FT-SAE") == 0)
693 val |= WPA_KEY_MGMT_FT_SAE;
694#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800695#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800696 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
697 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800698#endif /* CONFIG_SUITEB */
699#ifdef CONFIG_SUITEB192
700 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
701 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
702#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 else {
704 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
705 line, start);
706 os_free(buf);
707 return -1;
708 }
709
710 if (last)
711 break;
712 start = end + 1;
713 }
714
715 os_free(buf);
716 if (val == 0) {
717 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
718 "configured.", line);
719 return -1;
720 }
721
722 return val;
723}
724
725
726static int hostapd_config_parse_cipher(int line, const char *value)
727{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800728 int val = wpa_parse_cipher(value);
729 if (val < 0) {
730 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
731 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 if (val == 0) {
735 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
736 line);
737 return -1;
738 }
739 return val;
740}
741
742
743static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
744 char *val)
745{
746 size_t len = os_strlen(val);
747
748 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
749 return -1;
750
751 if (val[0] == '"') {
752 if (len < 2 || val[len - 1] != '"')
753 return -1;
754 len -= 2;
755 wep->key[keyidx] = os_malloc(len);
756 if (wep->key[keyidx] == NULL)
757 return -1;
758 os_memcpy(wep->key[keyidx], val + 1, len);
759 wep->len[keyidx] = len;
760 } else {
761 if (len & 1)
762 return -1;
763 len /= 2;
764 wep->key[keyidx] = os_malloc(len);
765 if (wep->key[keyidx] == NULL)
766 return -1;
767 wep->len[keyidx] = len;
768 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
769 return -1;
770 }
771
772 wep->keys_set++;
773
774 return 0;
775}
776
777
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700778static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val)
779{
780 char *pos;
781
782 /* for backwards compatibility, translate ' ' in conf str to ',' */
783 pos = val;
784 while (pos) {
785 pos = os_strchr(pos, ' ');
786 if (pos)
787 *pos++ = ',';
788 }
789 if (freq_range_list_parse(&conf->acs_ch_list, val))
790 return -1;
791
792 return 0;
793}
794
795
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700796static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797{
798 int *list;
799 int count;
800 char *pos, *end;
801
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700802 os_free(*int_list);
803 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804
805 pos = val;
806 count = 0;
807 while (*pos != '\0') {
808 if (*pos == ' ')
809 count++;
810 pos++;
811 }
812
813 list = os_malloc(sizeof(int) * (count + 2));
814 if (list == NULL)
815 return -1;
816 pos = val;
817 count = 0;
818 while (*pos != '\0') {
819 end = os_strchr(pos, ' ');
820 if (end)
821 *end = '\0';
822
823 list[count++] = atoi(pos);
824 if (!end)
825 break;
826 pos = end + 1;
827 }
828 list[count] = -1;
829
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700830 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831 return 0;
832}
833
834
835static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
836{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800837 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838
839 if (*ifname == '\0')
840 return -1;
841
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800842 all = os_realloc_array(conf->bss, conf->num_bss + 1,
843 sizeof(struct hostapd_bss_config *));
844 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
846 "multi-BSS entry");
847 return -1;
848 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800849 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800851 bss = os_zalloc(sizeof(*bss));
852 if (bss == NULL)
853 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 bss->radius = os_zalloc(sizeof(*bss->radius));
855 if (bss->radius == NULL) {
856 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
857 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800858 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 return -1;
860 }
861
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800862 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 conf->last_bss = bss;
864
865 hostapd_config_defaults_bss(bss);
866 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
867 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
868
869 return 0;
870}
871
872
873/* convert floats with one decimal place to value*10 int, i.e.,
874 * "1.5" will return 15 */
875static int hostapd_config_read_int10(const char *value)
876{
877 int i, d;
878 char *pos;
879
880 i = atoi(value);
881 pos = os_strchr(value, '.');
882 d = 0;
883 if (pos) {
884 pos++;
885 if (*pos >= '0' && *pos <= '9')
886 d = *pos - '0';
887 }
888
889 return i * 10 + d;
890}
891
892
893static int valid_cw(int cw)
894{
895 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
896 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
897}
898
899
900enum {
901 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
902 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
903 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
904 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
905};
906
907static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
908 char *val)
909{
910 int num;
911 char *pos;
912 struct hostapd_tx_queue_params *queue;
913
914 /* skip 'tx_queue_' prefix */
915 pos = name + 9;
916 if (os_strncmp(pos, "data", 4) == 0 &&
917 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
918 num = pos[4] - '0';
919 pos += 6;
920 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
921 os_strncmp(pos, "beacon_", 7) == 0) {
922 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
923 return 0;
924 } else {
925 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
926 return -1;
927 }
928
929 if (num >= NUM_TX_QUEUES) {
930 /* for backwards compatibility, do not trigger failure */
931 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
932 return 0;
933 }
934
935 queue = &conf->tx_queue[num];
936
937 if (os_strcmp(pos, "aifs") == 0) {
938 queue->aifs = atoi(val);
939 if (queue->aifs < 0 || queue->aifs > 255) {
940 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
941 queue->aifs);
942 return -1;
943 }
944 } else if (os_strcmp(pos, "cwmin") == 0) {
945 queue->cwmin = atoi(val);
946 if (!valid_cw(queue->cwmin)) {
947 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
948 queue->cwmin);
949 return -1;
950 }
951 } else if (os_strcmp(pos, "cwmax") == 0) {
952 queue->cwmax = atoi(val);
953 if (!valid_cw(queue->cwmax)) {
954 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
955 queue->cwmax);
956 return -1;
957 }
958 } else if (os_strcmp(pos, "burst") == 0) {
959 queue->burst = hostapd_config_read_int10(val);
960 } else {
961 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
962 return -1;
963 }
964
965 return 0;
966}
967
968
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969#ifdef CONFIG_IEEE80211R
970static int add_r0kh(struct hostapd_bss_config *bss, char *value)
971{
972 struct ft_remote_r0kh *r0kh;
973 char *pos, *next;
974
975 r0kh = os_zalloc(sizeof(*r0kh));
976 if (r0kh == NULL)
977 return -1;
978
979 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
980 pos = value;
981 next = os_strchr(pos, ' ');
982 if (next)
983 *next++ = '\0';
984 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
985 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
986 os_free(r0kh);
987 return -1;
988 }
989
990 pos = next;
991 next = os_strchr(pos, ' ');
992 if (next)
993 *next++ = '\0';
994 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
995 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
996 os_free(r0kh);
997 return -1;
998 }
999 r0kh->id_len = next - pos - 1;
1000 os_memcpy(r0kh->id, pos, r0kh->id_len);
1001
1002 pos = next;
1003 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
1004 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
1005 os_free(r0kh);
1006 return -1;
1007 }
1008
1009 r0kh->next = bss->r0kh_list;
1010 bss->r0kh_list = r0kh;
1011
1012 return 0;
1013}
1014
1015
1016static int add_r1kh(struct hostapd_bss_config *bss, char *value)
1017{
1018 struct ft_remote_r1kh *r1kh;
1019 char *pos, *next;
1020
1021 r1kh = os_zalloc(sizeof(*r1kh));
1022 if (r1kh == NULL)
1023 return -1;
1024
1025 /* 02:01:02:03:04:05 02:01:02:03:04:05
1026 * 000102030405060708090a0b0c0d0e0f */
1027 pos = value;
1028 next = os_strchr(pos, ' ');
1029 if (next)
1030 *next++ = '\0';
1031 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
1032 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
1033 os_free(r1kh);
1034 return -1;
1035 }
1036
1037 pos = next;
1038 next = os_strchr(pos, ' ');
1039 if (next)
1040 *next++ = '\0';
1041 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
1042 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
1043 os_free(r1kh);
1044 return -1;
1045 }
1046
1047 pos = next;
1048 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
1049 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
1050 os_free(r1kh);
1051 return -1;
1052 }
1053
1054 r1kh->next = bss->r1kh_list;
1055 bss->r1kh_list = r1kh;
1056
1057 return 0;
1058}
1059#endif /* CONFIG_IEEE80211R */
1060
1061
1062#ifdef CONFIG_IEEE80211N
1063static int hostapd_config_ht_capab(struct hostapd_config *conf,
1064 const char *capab)
1065{
1066 if (os_strstr(capab, "[LDPC]"))
1067 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
1068 if (os_strstr(capab, "[HT40-]")) {
1069 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1070 conf->secondary_channel = -1;
1071 }
1072 if (os_strstr(capab, "[HT40+]")) {
1073 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1074 conf->secondary_channel = 1;
1075 }
1076 if (os_strstr(capab, "[SMPS-STATIC]")) {
1077 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1078 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1079 }
1080 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1081 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1082 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1083 }
1084 if (os_strstr(capab, "[GF]"))
1085 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1086 if (os_strstr(capab, "[SHORT-GI-20]"))
1087 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1088 if (os_strstr(capab, "[SHORT-GI-40]"))
1089 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1090 if (os_strstr(capab, "[TX-STBC]"))
1091 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1092 if (os_strstr(capab, "[RX-STBC1]")) {
1093 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1094 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1095 }
1096 if (os_strstr(capab, "[RX-STBC12]")) {
1097 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1098 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1099 }
1100 if (os_strstr(capab, "[RX-STBC123]")) {
1101 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1102 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1103 }
1104 if (os_strstr(capab, "[DELAYED-BA]"))
1105 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1106 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1107 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1108 if (os_strstr(capab, "[DSSS_CCK-40]"))
1109 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07001110 if (os_strstr(capab, "[40-INTOLERANT]"))
1111 conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1113 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1114
1115 return 0;
1116}
1117#endif /* CONFIG_IEEE80211N */
1118
1119
Dmitry Shmidt04949592012-07-19 12:16:46 -07001120#ifdef CONFIG_IEEE80211AC
1121static int hostapd_config_vht_capab(struct hostapd_config *conf,
1122 const char *capab)
1123{
1124 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1125 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1126 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1127 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1128 if (os_strstr(capab, "[VHT160]"))
1129 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1130 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1131 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001132 if (os_strstr(capab, "[RXLDPC]"))
1133 conf->vht_capab |= VHT_CAP_RXLDPC;
1134 if (os_strstr(capab, "[SHORT-GI-80]"))
1135 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1136 if (os_strstr(capab, "[SHORT-GI-160]"))
1137 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1138 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1139 conf->vht_capab |= VHT_CAP_TXSTBC;
1140 if (os_strstr(capab, "[RX-STBC-1]"))
1141 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1142 if (os_strstr(capab, "[RX-STBC-12]"))
1143 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1144 if (os_strstr(capab, "[RX-STBC-123]"))
1145 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1146 if (os_strstr(capab, "[RX-STBC-1234]"))
1147 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1148 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001149 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001150 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001151 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001152 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001153 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1154 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001155 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001156 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1157 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001158 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1159 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1160 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1161 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1162 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1163 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1164 if (os_strstr(capab, "[HTC-VHT]"))
1165 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001166 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1167 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1168 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1169 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1170 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1171 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1172 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1173 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1174 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1175 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1176 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1177 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1178 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1179 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001180 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1181 (conf->vht_capab & VHT_CAP_HTC_VHT))
1182 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1183 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1184 (conf->vht_capab & VHT_CAP_HTC_VHT))
1185 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1186 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1187 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1188 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1189 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1190 return 0;
1191}
1192#endif /* CONFIG_IEEE80211AC */
1193
1194
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195#ifdef CONFIG_INTERWORKING
1196static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1197 int line)
1198{
1199 size_t len = os_strlen(pos);
1200 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1201
1202 struct hostapd_roaming_consortium *rc;
1203
1204 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1205 hexstr2bin(pos, oi, len / 2)) {
1206 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1207 "'%s'", line, pos);
1208 return -1;
1209 }
1210 len /= 2;
1211
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001212 rc = os_realloc_array(bss->roaming_consortium,
1213 bss->roaming_consortium_count + 1,
1214 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001215 if (rc == NULL)
1216 return -1;
1217
1218 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1219 rc[bss->roaming_consortium_count].len = len;
1220
1221 bss->roaming_consortium = rc;
1222 bss->roaming_consortium_count++;
1223
1224 return 0;
1225}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001226
1227
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001228static int parse_lang_string(struct hostapd_lang_string **array,
1229 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001230{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001231 char *sep, *str = NULL;
1232 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001233 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001234 int ret = -1;
1235
1236 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1237 str = wpa_config_parse_string(pos, &slen);
1238 if (!str)
1239 return -1;
1240 pos = str;
1241 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001242
1243 sep = os_strchr(pos, ':');
1244 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001245 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001246 *sep++ = '\0';
1247
1248 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001249 if (clen < 2 || clen > sizeof(ls->lang))
1250 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001251 nlen = os_strlen(sep);
1252 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001253 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001254
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001255 ls = os_realloc_array(*array, *count + 1,
1256 sizeof(struct hostapd_lang_string));
1257 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001258 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001259
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001260 *array = ls;
1261 ls = &(*array)[*count];
1262 (*count)++;
1263
1264 os_memset(ls->lang, 0, sizeof(ls->lang));
1265 os_memcpy(ls->lang, pos, clen);
1266 ls->name_len = nlen;
1267 os_memcpy(ls->name, sep, nlen);
1268
Dmitry Shmidt56052862013-10-04 10:23:25 -07001269 ret = 0;
1270fail:
1271 os_free(str);
1272 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001273}
1274
1275
1276static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1277 int line)
1278{
1279 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1280 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1281 line, pos);
1282 return -1;
1283 }
1284 return 0;
1285}
1286
1287
1288static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1289 int line)
1290{
1291 size_t count;
1292 char *pos;
1293 u8 *info = NULL, *ipos;
1294
1295 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1296
1297 count = 1;
1298 for (pos = buf; *pos; pos++) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001299 if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300 goto fail;
1301 if (*pos == ';')
1302 count++;
1303 }
1304 if (1 + count * 3 > 0x7f)
1305 goto fail;
1306
1307 info = os_zalloc(2 + 3 + count * 3);
1308 if (info == NULL)
1309 return -1;
1310
1311 ipos = info;
1312 *ipos++ = 0; /* GUD - Version 1 */
1313 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1314 *ipos++ = 0; /* PLMN List IEI */
1315 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1316 *ipos++ = 1 + count * 3;
1317 *ipos++ = count; /* Number of PLMNs */
1318
1319 pos = buf;
1320 while (pos && *pos) {
1321 char *mcc, *mnc;
1322 size_t mnc_len;
1323
1324 mcc = pos;
1325 mnc = os_strchr(pos, ',');
1326 if (mnc == NULL)
1327 goto fail;
1328 *mnc++ = '\0';
1329 pos = os_strchr(mnc, ';');
1330 if (pos)
1331 *pos++ = '\0';
1332
1333 mnc_len = os_strlen(mnc);
1334 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1335 goto fail;
1336
1337 /* BC coded MCC,MNC */
1338 /* MCC digit 2 | MCC digit 1 */
1339 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1340 /* MNC digit 3 | MCC digit 3 */
1341 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1342 (mcc[2] - '0');
1343 /* MNC digit 2 | MNC digit 1 */
1344 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1345 }
1346
1347 os_free(bss->anqp_3gpp_cell_net);
1348 bss->anqp_3gpp_cell_net = info;
1349 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1350 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1351 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001352
1353 return 0;
1354
1355fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001356 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1357 line, buf);
1358 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001359 return -1;
1360}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001361
1362
1363static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1364{
1365 struct hostapd_nai_realm_data *realm;
1366 size_t i, j, len;
1367 int *offsets;
1368 char *pos, *end, *rpos;
1369
1370 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1371 sizeof(int));
1372 if (offsets == NULL)
1373 return -1;
1374
1375 for (i = 0; i < bss->nai_realm_count; i++) {
1376 realm = &bss->nai_realm_data[i];
1377 for (j = 0; j < MAX_NAI_REALMS; j++) {
1378 offsets[i * MAX_NAI_REALMS + j] =
1379 realm->realm[j] ?
1380 realm->realm[j] - realm->realm_buf : -1;
1381 }
1382 }
1383
1384 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1385 sizeof(struct hostapd_nai_realm_data));
1386 if (realm == NULL) {
1387 os_free(offsets);
1388 return -1;
1389 }
1390 bss->nai_realm_data = realm;
1391
1392 /* patch the pointers after realloc */
1393 for (i = 0; i < bss->nai_realm_count; i++) {
1394 realm = &bss->nai_realm_data[i];
1395 for (j = 0; j < MAX_NAI_REALMS; j++) {
1396 int offs = offsets[i * MAX_NAI_REALMS + j];
1397 if (offs >= 0)
1398 realm->realm[j] = realm->realm_buf + offs;
1399 else
1400 realm->realm[j] = NULL;
1401 }
1402 }
1403 os_free(offsets);
1404
1405 realm = &bss->nai_realm_data[bss->nai_realm_count];
1406 os_memset(realm, 0, sizeof(*realm));
1407
1408 pos = buf;
1409 realm->encoding = atoi(pos);
1410 pos = os_strchr(pos, ',');
1411 if (pos == NULL)
1412 goto fail;
1413 pos++;
1414
1415 end = os_strchr(pos, ',');
1416 if (end) {
1417 len = end - pos;
1418 *end = '\0';
1419 } else {
1420 len = os_strlen(pos);
1421 }
1422
1423 if (len > MAX_NAI_REALMLEN) {
1424 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1425 "characters)", (int) len, MAX_NAI_REALMLEN);
1426 goto fail;
1427 }
1428 os_memcpy(realm->realm_buf, pos, len);
1429
1430 if (end)
1431 pos = end + 1;
1432 else
1433 pos = NULL;
1434
1435 while (pos && *pos) {
1436 struct hostapd_nai_realm_eap *eap;
1437
1438 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1439 wpa_printf(MSG_ERROR, "Too many EAP methods");
1440 goto fail;
1441 }
1442
1443 eap = &realm->eap_method[realm->eap_method_count];
1444 realm->eap_method_count++;
1445
1446 end = os_strchr(pos, ',');
1447 if (end == NULL)
1448 end = pos + os_strlen(pos);
1449
1450 eap->eap_method = atoi(pos);
1451 for (;;) {
1452 pos = os_strchr(pos, '[');
1453 if (pos == NULL || pos > end)
1454 break;
1455 pos++;
1456 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1457 wpa_printf(MSG_ERROR, "Too many auth params");
1458 goto fail;
1459 }
1460 eap->auth_id[eap->num_auths] = atoi(pos);
1461 pos = os_strchr(pos, ':');
1462 if (pos == NULL || pos > end)
1463 goto fail;
1464 pos++;
1465 eap->auth_val[eap->num_auths] = atoi(pos);
1466 pos = os_strchr(pos, ']');
1467 if (pos == NULL || pos > end)
1468 goto fail;
1469 pos++;
1470 eap->num_auths++;
1471 }
1472
1473 if (*end != ',')
1474 break;
1475
1476 pos = end + 1;
1477 }
1478
1479 /* Split realm list into null terminated realms */
1480 rpos = realm->realm_buf;
1481 i = 0;
1482 while (*rpos) {
1483 if (i >= MAX_NAI_REALMS) {
1484 wpa_printf(MSG_ERROR, "Too many realms");
1485 goto fail;
1486 }
1487 realm->realm[i++] = rpos;
1488 rpos = os_strchr(rpos, ';');
1489 if (rpos == NULL)
1490 break;
1491 *rpos++ = '\0';
1492 }
1493
1494 bss->nai_realm_count++;
1495
1496 return 0;
1497
1498fail:
1499 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1500 return -1;
1501}
1502
Dmitry Shmidt051af732013-10-22 13:52:46 -07001503
1504static int parse_qos_map_set(struct hostapd_bss_config *bss,
1505 char *buf, int line)
1506{
1507 u8 qos_map_set[16 + 2 * 21], count = 0;
1508 char *pos = buf;
1509 int val;
1510
1511 for (;;) {
1512 if (count == sizeof(qos_map_set)) {
1513 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1514 "parameters '%s'", line, buf);
1515 return -1;
1516 }
1517
1518 val = atoi(pos);
1519 if (val > 255 || val < 0) {
1520 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1521 "'%s'", line, buf);
1522 return -1;
1523 }
1524
1525 qos_map_set[count++] = val;
1526 pos = os_strchr(pos, ',');
1527 if (!pos)
1528 break;
1529 pos++;
1530 }
1531
1532 if (count < 16 || count & 1) {
1533 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1534 line, buf);
1535 return -1;
1536 }
1537
1538 os_memcpy(bss->qos_map_set, qos_map_set, count);
1539 bss->qos_map_set_len = count;
1540
1541 return 0;
1542}
1543
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001544#endif /* CONFIG_INTERWORKING */
1545
1546
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001547#ifdef CONFIG_HS20
1548static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1549 int line)
1550{
1551 u8 *conn_cap;
1552 char *pos;
1553
1554 if (bss->hs20_connection_capability_len >= 0xfff0)
1555 return -1;
1556
1557 conn_cap = os_realloc(bss->hs20_connection_capability,
1558 bss->hs20_connection_capability_len + 4);
1559 if (conn_cap == NULL)
1560 return -1;
1561
1562 bss->hs20_connection_capability = conn_cap;
1563 conn_cap += bss->hs20_connection_capability_len;
1564 pos = buf;
1565 conn_cap[0] = atoi(pos);
1566 pos = os_strchr(pos, ':');
1567 if (pos == NULL)
1568 return -1;
1569 pos++;
1570 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1571 pos = os_strchr(pos, ':');
1572 if (pos == NULL)
1573 return -1;
1574 pos++;
1575 conn_cap[3] = atoi(pos);
1576 bss->hs20_connection_capability_len += 4;
1577
1578 return 0;
1579}
1580
1581
1582static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1583 int line)
1584{
1585 u8 *wan_metrics;
1586 char *pos;
1587
1588 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1589
1590 wan_metrics = os_zalloc(13);
1591 if (wan_metrics == NULL)
1592 return -1;
1593
1594 pos = buf;
1595 /* WAN Info */
1596 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1597 goto fail;
1598 pos += 2;
1599 if (*pos != ':')
1600 goto fail;
1601 pos++;
1602
1603 /* Downlink Speed */
1604 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1605 pos = os_strchr(pos, ':');
1606 if (pos == NULL)
1607 goto fail;
1608 pos++;
1609
1610 /* Uplink Speed */
1611 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1612 pos = os_strchr(pos, ':');
1613 if (pos == NULL)
1614 goto fail;
1615 pos++;
1616
1617 /* Downlink Load */
1618 wan_metrics[9] = atoi(pos);
1619 pos = os_strchr(pos, ':');
1620 if (pos == NULL)
1621 goto fail;
1622 pos++;
1623
1624 /* Uplink Load */
1625 wan_metrics[10] = atoi(pos);
1626 pos = os_strchr(pos, ':');
1627 if (pos == NULL)
1628 goto fail;
1629 pos++;
1630
1631 /* LMD */
1632 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1633
1634 os_free(bss->hs20_wan_metrics);
1635 bss->hs20_wan_metrics = wan_metrics;
1636
1637 return 0;
1638
1639fail:
1640 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001641 line, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001642 os_free(wan_metrics);
1643 return -1;
1644}
1645
1646
1647static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1648 char *pos, int line)
1649{
1650 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1651 &bss->hs20_oper_friendly_name_count, pos)) {
1652 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1653 "hs20_oper_friendly_name '%s'", line, pos);
1654 return -1;
1655 }
1656 return 0;
1657}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001658
1659
1660static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1661{
1662 struct hs20_icon *icon;
1663 char *end;
1664
1665 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1666 sizeof(struct hs20_icon));
1667 if (icon == NULL)
1668 return -1;
1669 bss->hs20_icons = icon;
1670 icon = &bss->hs20_icons[bss->hs20_icons_count];
1671 os_memset(icon, 0, sizeof(*icon));
1672
1673 icon->width = atoi(pos);
1674 pos = os_strchr(pos, ':');
1675 if (pos == NULL)
1676 return -1;
1677 pos++;
1678
1679 icon->height = atoi(pos);
1680 pos = os_strchr(pos, ':');
1681 if (pos == NULL)
1682 return -1;
1683 pos++;
1684
1685 end = os_strchr(pos, ':');
1686 if (end == NULL || end - pos > 3)
1687 return -1;
1688 os_memcpy(icon->language, pos, end - pos);
1689 pos = end + 1;
1690
1691 end = os_strchr(pos, ':');
1692 if (end == NULL || end - pos > 255)
1693 return -1;
1694 os_memcpy(icon->type, pos, end - pos);
1695 pos = end + 1;
1696
1697 end = os_strchr(pos, ':');
1698 if (end == NULL || end - pos > 255)
1699 return -1;
1700 os_memcpy(icon->name, pos, end - pos);
1701 pos = end + 1;
1702
1703 if (os_strlen(pos) > 255)
1704 return -1;
1705 os_memcpy(icon->file, pos, os_strlen(pos));
1706
1707 bss->hs20_icons_count++;
1708
1709 return 0;
1710}
1711
1712
1713static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1714 char *pos, int line)
1715{
1716 size_t slen;
1717 char *str;
1718
1719 str = wpa_config_parse_string(pos, &slen);
1720 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1721 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001722 os_free(str);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001723 return -1;
1724 }
1725
1726 os_memcpy(bss->osu_ssid, str, slen);
1727 bss->osu_ssid_len = slen;
1728 os_free(str);
1729
1730 return 0;
1731}
1732
1733
1734static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1735 char *pos, int line)
1736{
1737 struct hs20_osu_provider *p;
1738
1739 p = os_realloc_array(bss->hs20_osu_providers,
1740 bss->hs20_osu_providers_count + 1, sizeof(*p));
1741 if (p == NULL)
1742 return -1;
1743
1744 bss->hs20_osu_providers = p;
1745 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1746 bss->hs20_osu_providers_count++;
1747 os_memset(bss->last_osu, 0, sizeof(*p));
1748 bss->last_osu->server_uri = os_strdup(pos);
1749
1750 return 0;
1751}
1752
1753
1754static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1755 char *pos, int line)
1756{
1757 if (bss->last_osu == NULL) {
1758 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1759 return -1;
1760 }
1761
1762 if (parse_lang_string(&bss->last_osu->friendly_name,
1763 &bss->last_osu->friendly_name_count, pos)) {
1764 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1765 line, pos);
1766 return -1;
1767 }
1768
1769 return 0;
1770}
1771
1772
1773static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1774 char *pos, int line)
1775{
1776 if (bss->last_osu == NULL) {
1777 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1778 return -1;
1779 }
1780
1781 os_free(bss->last_osu->osu_nai);
1782 bss->last_osu->osu_nai = os_strdup(pos);
1783 if (bss->last_osu->osu_nai == NULL)
1784 return -1;
1785
1786 return 0;
1787}
1788
1789
1790static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1791 int line)
1792{
1793 if (bss->last_osu == NULL) {
1794 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1795 return -1;
1796 }
1797
1798 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1799 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1800 return -1;
1801 }
1802
1803 return 0;
1804}
1805
1806
1807static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1808 int line)
1809{
1810 char **n;
1811 struct hs20_osu_provider *p = bss->last_osu;
1812
1813 if (p == NULL) {
1814 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1815 return -1;
1816 }
1817
1818 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1819 if (n == NULL)
1820 return -1;
1821 p->icons = n;
1822 p->icons[p->icons_count] = os_strdup(pos);
1823 if (p->icons[p->icons_count] == NULL)
1824 return -1;
1825 p->icons_count++;
1826
1827 return 0;
1828}
1829
1830
1831static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1832 char *pos, int line)
1833{
1834 if (bss->last_osu == NULL) {
1835 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1836 return -1;
1837 }
1838
1839 if (parse_lang_string(&bss->last_osu->service_desc,
1840 &bss->last_osu->service_desc_count, pos)) {
1841 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1842 line, pos);
1843 return -1;
1844 }
1845
1846 return 0;
1847}
1848
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001849#endif /* CONFIG_HS20 */
1850
1851
Dmitry Shmidt04949592012-07-19 12:16:46 -07001852#ifdef CONFIG_WPS_NFC
1853static struct wpabuf * hostapd_parse_bin(const char *buf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001855 size_t len;
1856 struct wpabuf *ret;
1857
1858 len = os_strlen(buf);
1859 if (len & 0x01)
1860 return NULL;
1861 len /= 2;
1862
1863 ret = wpabuf_alloc(len);
1864 if (ret == NULL)
1865 return NULL;
1866
1867 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1868 wpabuf_free(ret);
1869 return NULL;
1870 }
1871
1872 return ret;
1873}
1874#endif /* CONFIG_WPS_NFC */
1875
1876
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001877#ifdef CONFIG_ACS
1878static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf,
1879 char *pos)
1880{
1881 struct acs_bias *bias = NULL, *tmp;
1882 unsigned int num = 0;
1883 char *end;
1884
1885 while (*pos) {
1886 tmp = os_realloc_array(bias, num + 1, sizeof(*bias));
1887 if (!tmp)
1888 goto fail;
1889 bias = tmp;
1890
1891 bias[num].channel = atoi(pos);
1892 if (bias[num].channel <= 0)
1893 goto fail;
1894 pos = os_strchr(pos, ':');
1895 if (!pos)
1896 goto fail;
1897 pos++;
1898 bias[num].bias = strtod(pos, &end);
1899 if (end == pos || bias[num].bias < 0.0)
1900 goto fail;
1901 pos = end;
1902 if (*pos != ' ' && *pos != '\0')
1903 goto fail;
1904 num++;
1905 }
1906
1907 os_free(conf->acs_chan_bias);
1908 conf->acs_chan_bias = bias;
1909 conf->num_acs_chan_bias = num;
1910
1911 return 0;
1912fail:
1913 os_free(bias);
1914 return -1;
1915}
1916#endif /* CONFIG_ACS */
1917
1918
Dmitry Shmidt04949592012-07-19 12:16:46 -07001919static int hostapd_config_fill(struct hostapd_config *conf,
1920 struct hostapd_bss_config *bss,
1921 char *buf, char *pos, int line)
1922{
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001923 if (os_strcmp(buf, "interface") == 0) {
1924 os_strlcpy(conf->bss[0]->iface, pos,
1925 sizeof(conf->bss[0]->iface));
1926 } else if (os_strcmp(buf, "bridge") == 0) {
1927 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
1928 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1929 os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
1930 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1931 os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
1932 } else if (os_strcmp(buf, "driver") == 0) {
1933 int j;
1934 /* clear to get error below if setting is invalid */
1935 conf->driver = NULL;
1936 for (j = 0; wpa_drivers[j]; j++) {
1937 if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
1938 conf->driver = wpa_drivers[j];
1939 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001940 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001941 }
1942 if (conf->driver == NULL) {
1943 wpa_printf(MSG_ERROR,
1944 "Line %d: invalid/unknown driver '%s'",
1945 line, pos);
1946 return 1;
1947 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001948 } else if (os_strcmp(buf, "driver_params") == 0) {
1949 os_free(conf->driver_params);
1950 conf->driver_params = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001951 } else if (os_strcmp(buf, "debug") == 0) {
1952 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
1953 line);
1954 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1955 bss->logger_syslog_level = atoi(pos);
1956 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1957 bss->logger_stdout_level = atoi(pos);
1958 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1959 bss->logger_syslog = atoi(pos);
1960 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1961 bss->logger_stdout = atoi(pos);
1962 } else if (os_strcmp(buf, "dump_file") == 0) {
1963 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
1964 line);
1965 } else if (os_strcmp(buf, "ssid") == 0) {
1966 bss->ssid.ssid_len = os_strlen(pos);
1967 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1968 bss->ssid.ssid_len < 1) {
1969 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1970 line, pos);
1971 return 1;
1972 }
1973 os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
1974 bss->ssid.ssid_set = 1;
1975 } else if (os_strcmp(buf, "ssid2") == 0) {
1976 size_t slen;
1977 char *str = wpa_config_parse_string(pos, &slen);
1978 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1979 wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
1980 line, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001981 os_free(str);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07001982 return 1;
1983 }
1984 os_memcpy(bss->ssid.ssid, str, slen);
1985 bss->ssid.ssid_len = slen;
1986 bss->ssid.ssid_set = 1;
1987 os_free(str);
1988 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1989 bss->ssid.utf8_ssid = atoi(pos) > 0;
1990 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1991 bss->macaddr_acl = atoi(pos);
1992 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1993 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1994 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1995 wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
1996 line, bss->macaddr_acl);
1997 }
1998 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1999 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
2000 &bss->num_accept_mac)) {
2001 wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
2002 line, pos);
2003 return 1;
2004 }
2005 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
2006 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
2007 &bss->num_deny_mac)) {
2008 wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
2009 line, pos);
2010 return 1;
2011 }
2012 } else if (os_strcmp(buf, "wds_sta") == 0) {
2013 bss->wds_sta = atoi(pos);
2014 } else if (os_strcmp(buf, "start_disabled") == 0) {
2015 bss->start_disabled = atoi(pos);
2016 } else if (os_strcmp(buf, "ap_isolate") == 0) {
2017 bss->isolate = atoi(pos);
2018 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
2019 bss->ap_max_inactivity = atoi(pos);
2020 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
2021 bss->skip_inactivity_poll = atoi(pos);
2022 } else if (os_strcmp(buf, "country_code") == 0) {
2023 os_memcpy(conf->country, pos, 2);
2024 /* FIX: make this configurable */
2025 conf->country[2] = ' ';
2026 } else if (os_strcmp(buf, "ieee80211d") == 0) {
2027 conf->ieee80211d = atoi(pos);
2028 } else if (os_strcmp(buf, "ieee80211h") == 0) {
2029 conf->ieee80211h = atoi(pos);
2030 } else if (os_strcmp(buf, "ieee8021x") == 0) {
2031 bss->ieee802_1x = atoi(pos);
2032 } else if (os_strcmp(buf, "eapol_version") == 0) {
2033 bss->eapol_version = atoi(pos);
2034 if (bss->eapol_version < 1 || bss->eapol_version > 2) {
2035 wpa_printf(MSG_ERROR,
2036 "Line %d: invalid EAPOL version (%d): '%s'.",
2037 line, bss->eapol_version, pos);
2038 return 1;
2039 }
2040 wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041#ifdef EAP_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002042 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
2043 bss->eap_server = atoi(pos);
2044 wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
2045 } else if (os_strcmp(buf, "eap_server") == 0) {
2046 bss->eap_server = atoi(pos);
2047 } else if (os_strcmp(buf, "eap_user_file") == 0) {
2048 if (hostapd_config_read_eap_user(pos, bss))
2049 return 1;
2050 } else if (os_strcmp(buf, "ca_cert") == 0) {
2051 os_free(bss->ca_cert);
2052 bss->ca_cert = os_strdup(pos);
2053 } else if (os_strcmp(buf, "server_cert") == 0) {
2054 os_free(bss->server_cert);
2055 bss->server_cert = os_strdup(pos);
2056 } else if (os_strcmp(buf, "private_key") == 0) {
2057 os_free(bss->private_key);
2058 bss->private_key = os_strdup(pos);
2059 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
2060 os_free(bss->private_key_passwd);
2061 bss->private_key_passwd = os_strdup(pos);
2062 } else if (os_strcmp(buf, "check_crl") == 0) {
2063 bss->check_crl = atoi(pos);
2064 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
2065 os_free(bss->ocsp_stapling_response);
2066 bss->ocsp_stapling_response = os_strdup(pos);
2067 } else if (os_strcmp(buf, "dh_file") == 0) {
2068 os_free(bss->dh_file);
2069 bss->dh_file = os_strdup(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002070 } else if (os_strcmp(buf, "openssl_ciphers") == 0) {
2071 os_free(bss->openssl_ciphers);
2072 bss->openssl_ciphers = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002073 } else if (os_strcmp(buf, "fragment_size") == 0) {
2074 bss->fragment_size = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075#ifdef EAP_SERVER_FAST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002076 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
2077 os_free(bss->pac_opaque_encr_key);
2078 bss->pac_opaque_encr_key = os_malloc(16);
2079 if (bss->pac_opaque_encr_key == NULL) {
2080 wpa_printf(MSG_ERROR,
2081 "Line %d: No memory for pac_opaque_encr_key",
2082 line);
2083 return 1;
2084 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
2085 wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
2086 line);
2087 return 1;
2088 }
2089 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
2090 size_t idlen = os_strlen(pos);
2091 if (idlen & 1) {
2092 wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
2093 line);
2094 return 1;
2095 }
2096 os_free(bss->eap_fast_a_id);
2097 bss->eap_fast_a_id = os_malloc(idlen / 2);
2098 if (bss->eap_fast_a_id == NULL ||
2099 hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
2100 wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
2101 line);
2102 os_free(bss->eap_fast_a_id);
2103 bss->eap_fast_a_id = NULL;
2104 return 1;
2105 } else {
2106 bss->eap_fast_a_id_len = idlen / 2;
2107 }
2108 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2109 os_free(bss->eap_fast_a_id_info);
2110 bss->eap_fast_a_id_info = os_strdup(pos);
2111 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2112 bss->eap_fast_prov = atoi(pos);
2113 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2114 bss->pac_key_lifetime = atoi(pos);
2115 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2116 bss->pac_key_refresh_time = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002117#endif /* EAP_SERVER_FAST */
2118#ifdef EAP_SERVER_SIM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002119 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2120 os_free(bss->eap_sim_db);
2121 bss->eap_sim_db = os_strdup(pos);
2122 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2123 bss->eap_sim_aka_result_ind = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124#endif /* EAP_SERVER_SIM */
2125#ifdef EAP_SERVER_TNC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002126 } else if (os_strcmp(buf, "tnc") == 0) {
2127 bss->tnc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128#endif /* EAP_SERVER_TNC */
2129#ifdef EAP_SERVER_PWD
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002130 } else if (os_strcmp(buf, "pwd_group") == 0) {
2131 bss->pwd_group = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132#endif /* EAP_SERVER_PWD */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002133 } else if (os_strcmp(buf, "eap_server_erp") == 0) {
2134 bss->eap_server_erp = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135#endif /* EAP_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002136 } else if (os_strcmp(buf, "eap_message") == 0) {
2137 char *term;
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002138 os_free(bss->eap_req_id_text);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002139 bss->eap_req_id_text = os_strdup(pos);
2140 if (bss->eap_req_id_text == NULL) {
2141 wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
2142 line);
2143 return 1;
2144 }
2145 bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
2146 term = os_strstr(bss->eap_req_id_text, "\\0");
2147 if (term) {
2148 *term++ = '\0';
2149 os_memmove(term, term + 1,
2150 bss->eap_req_id_text_len -
2151 (term - bss->eap_req_id_text) - 1);
2152 bss->eap_req_id_text_len--;
2153 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002154 } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) {
2155 bss->erp_send_reauth_start = atoi(pos);
2156 } else if (os_strcmp(buf, "erp_domain") == 0) {
2157 os_free(bss->erp_domain);
2158 bss->erp_domain = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002159 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
2160 bss->default_wep_key_len = atoi(pos);
2161 if (bss->default_wep_key_len > 13) {
2162 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
2163 line,
2164 (unsigned long) bss->default_wep_key_len,
2165 (unsigned long)
2166 bss->default_wep_key_len * 8);
2167 return 1;
2168 }
2169 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
2170 bss->individual_wep_key_len = atoi(pos);
2171 if (bss->individual_wep_key_len < 0 ||
2172 bss->individual_wep_key_len > 13) {
2173 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
2174 line, bss->individual_wep_key_len,
2175 bss->individual_wep_key_len * 8);
2176 return 1;
2177 }
2178 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2179 bss->wep_rekeying_period = atoi(pos);
2180 if (bss->wep_rekeying_period < 0) {
2181 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2182 line, bss->wep_rekeying_period);
2183 return 1;
2184 }
2185 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2186 bss->eap_reauth_period = atoi(pos);
2187 if (bss->eap_reauth_period < 0) {
2188 wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
2189 line, bss->eap_reauth_period);
2190 return 1;
2191 }
2192 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2193 bss->eapol_key_index_workaround = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194#ifdef CONFIG_IAPP
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002195 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2196 bss->ieee802_11f = 1;
2197 os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002198#endif /* CONFIG_IAPP */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002199 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2200 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2201 wpa_printf(MSG_ERROR,
2202 "Line %d: invalid IP address '%s'",
2203 line, pos);
2204 return 1;
2205 }
2206 } else if (os_strcmp(buf, "nas_identifier") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002207 os_free(bss->nas_identifier);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002208 bss->nas_identifier = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002210 } else if (os_strcmp(buf, "radius_client_addr") == 0) {
2211 if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) {
2212 wpa_printf(MSG_ERROR,
2213 "Line %d: invalid IP address '%s'",
2214 line, pos);
2215 return 1;
2216 }
2217 bss->radius->force_client_addr = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002218 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2219 if (hostapd_config_read_radius_addr(
2220 &bss->radius->auth_servers,
2221 &bss->radius->num_auth_servers, pos, 1812,
2222 &bss->radius->auth_server)) {
2223 wpa_printf(MSG_ERROR,
2224 "Line %d: invalid IP address '%s'",
2225 line, pos);
2226 return 1;
2227 }
2228 } else if (bss->radius->auth_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002229 os_strcmp(buf, "auth_server_addr_replace") == 0) {
2230 if (hostapd_parse_ip_addr(pos,
2231 &bss->radius->auth_server->addr)) {
2232 wpa_printf(MSG_ERROR,
2233 "Line %d: invalid IP address '%s'",
2234 line, pos);
2235 return 1;
2236 }
2237 } else if (bss->radius->auth_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002238 os_strcmp(buf, "auth_server_port") == 0) {
2239 bss->radius->auth_server->port = atoi(pos);
2240 } else if (bss->radius->auth_server &&
2241 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2242 int len = os_strlen(pos);
2243 if (len == 0) {
2244 /* RFC 2865, Ch. 3 */
2245 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2246 line);
2247 return 1;
2248 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002249 os_free(bss->radius->auth_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002250 bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
2251 bss->radius->auth_server->shared_secret_len = len;
2252 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2253 if (hostapd_config_read_radius_addr(
2254 &bss->radius->acct_servers,
2255 &bss->radius->num_acct_servers, pos, 1813,
2256 &bss->radius->acct_server)) {
2257 wpa_printf(MSG_ERROR,
2258 "Line %d: invalid IP address '%s'",
2259 line, pos);
2260 return 1;
2261 }
2262 } else if (bss->radius->acct_server &&
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002263 os_strcmp(buf, "acct_server_addr_replace") == 0) {
2264 if (hostapd_parse_ip_addr(pos,
2265 &bss->radius->acct_server->addr)) {
2266 wpa_printf(MSG_ERROR,
2267 "Line %d: invalid IP address '%s'",
2268 line, pos);
2269 return 1;
2270 }
2271 } else if (bss->radius->acct_server &&
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002272 os_strcmp(buf, "acct_server_port") == 0) {
2273 bss->radius->acct_server->port = atoi(pos);
2274 } else if (bss->radius->acct_server &&
2275 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2276 int len = os_strlen(pos);
2277 if (len == 0) {
2278 /* RFC 2865, Ch. 3 */
2279 wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
2280 line);
2281 return 1;
2282 }
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002283 os_free(bss->radius->acct_server->shared_secret);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002284 bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
2285 bss->radius->acct_server->shared_secret_len = len;
2286 } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
2287 bss->radius->retry_primary_interval = atoi(pos);
2288 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
2289 bss->acct_interim_interval = atoi(pos);
2290 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2291 bss->radius_request_cui = atoi(pos);
2292 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2293 struct hostapd_radius_attr *attr, *a;
2294 attr = hostapd_parse_radius_attr(pos);
2295 if (attr == NULL) {
2296 wpa_printf(MSG_ERROR,
2297 "Line %d: invalid radius_auth_req_attr",
2298 line);
2299 return 1;
2300 } else if (bss->radius_auth_req_attr == NULL) {
2301 bss->radius_auth_req_attr = attr;
2302 } else {
2303 a = bss->radius_auth_req_attr;
2304 while (a->next)
2305 a = a->next;
2306 a->next = attr;
2307 }
2308 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2309 struct hostapd_radius_attr *attr, *a;
2310 attr = hostapd_parse_radius_attr(pos);
2311 if (attr == NULL) {
2312 wpa_printf(MSG_ERROR,
2313 "Line %d: invalid radius_acct_req_attr",
2314 line);
2315 return 1;
2316 } else if (bss->radius_acct_req_attr == NULL) {
2317 bss->radius_acct_req_attr = attr;
2318 } else {
2319 a = bss->radius_acct_req_attr;
2320 while (a->next)
2321 a = a->next;
2322 a->next = attr;
2323 }
2324 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2325 bss->radius_das_port = atoi(pos);
2326 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2327 if (hostapd_parse_das_client(bss, pos) < 0) {
2328 wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
2329 line);
2330 return 1;
2331 }
2332 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2333 bss->radius_das_time_window = atoi(pos);
2334 } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
2335 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002337 } else if (os_strcmp(buf, "auth_algs") == 0) {
2338 bss->auth_algs = atoi(pos);
2339 if (bss->auth_algs == 0) {
2340 wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
2341 line);
2342 return 1;
2343 }
2344 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2345 bss->max_num_sta = atoi(pos);
2346 if (bss->max_num_sta < 0 ||
2347 bss->max_num_sta > MAX_STA_COUNT) {
2348 wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
2349 line, bss->max_num_sta, MAX_STA_COUNT);
2350 return 1;
2351 }
2352 } else if (os_strcmp(buf, "wpa") == 0) {
2353 bss->wpa = atoi(pos);
2354 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2355 bss->wpa_group_rekey = atoi(pos);
2356 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2357 bss->wpa_strict_rekey = atoi(pos);
2358 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2359 bss->wpa_gmk_rekey = atoi(pos);
2360 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2361 bss->wpa_ptk_rekey = atoi(pos);
2362 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2363 int len = os_strlen(pos);
2364 if (len < 8 || len > 63) {
2365 wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
2366 line, len);
2367 return 1;
2368 }
2369 os_free(bss->ssid.wpa_passphrase);
2370 bss->ssid.wpa_passphrase = os_strdup(pos);
2371 if (bss->ssid.wpa_passphrase) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002372 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002373 bss->ssid.wpa_passphrase_set = 1;
2374 }
2375 } else if (os_strcmp(buf, "wpa_psk") == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002376 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002377 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2378 if (bss->ssid.wpa_psk == NULL)
2379 return 1;
2380 if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
2381 pos[PMK_LEN * 2] != '\0') {
2382 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
2383 line, pos);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002384 hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002385 return 1;
2386 }
2387 bss->ssid.wpa_psk->group = 1;
2388 os_free(bss->ssid.wpa_passphrase);
2389 bss->ssid.wpa_passphrase = NULL;
2390 bss->ssid.wpa_psk_set = 1;
2391 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2392 os_free(bss->ssid.wpa_psk_file);
2393 bss->ssid.wpa_psk_file = os_strdup(pos);
2394 if (!bss->ssid.wpa_psk_file) {
2395 wpa_printf(MSG_ERROR, "Line %d: allocation failed",
2396 line);
2397 return 1;
2398 }
2399 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2400 bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
2401 if (bss->wpa_key_mgmt == -1)
2402 return 1;
2403 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2404 bss->wpa_psk_radius = atoi(pos);
2405 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2406 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2407 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2408 wpa_printf(MSG_ERROR,
2409 "Line %d: unknown wpa_psk_radius %d",
2410 line, bss->wpa_psk_radius);
2411 return 1;
2412 }
2413 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2414 bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
2415 if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
2416 return 1;
2417 if (bss->wpa_pairwise &
2418 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2419 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2420 bss->wpa_pairwise, pos);
2421 return 1;
2422 }
2423 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2424 bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
2425 if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
2426 return 1;
2427 if (bss->rsn_pairwise &
2428 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
2429 wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
2430 bss->rsn_pairwise, pos);
2431 return 1;
2432 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002433#ifdef CONFIG_RSN_PREAUTH
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002434 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2435 bss->rsn_preauth = atoi(pos);
2436 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002437 os_free(bss->rsn_preauth_interfaces);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002438 bss->rsn_preauth_interfaces = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002439#endif /* CONFIG_RSN_PREAUTH */
2440#ifdef CONFIG_PEERKEY
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002441 } else if (os_strcmp(buf, "peerkey") == 0) {
2442 bss->peerkey = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002443#endif /* CONFIG_PEERKEY */
2444#ifdef CONFIG_IEEE80211R
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002445 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2446 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2447 hexstr2bin(pos, bss->mobility_domain,
2448 MOBILITY_DOMAIN_ID_LEN) != 0) {
2449 wpa_printf(MSG_ERROR,
2450 "Line %d: Invalid mobility_domain '%s'",
2451 line, pos);
2452 return 1;
2453 }
2454 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2455 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2456 hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
2457 wpa_printf(MSG_ERROR,
2458 "Line %d: Invalid r1_key_holder '%s'",
2459 line, pos);
2460 return 1;
2461 }
2462 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2463 bss->r0_key_lifetime = atoi(pos);
2464 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2465 bss->reassociation_deadline = atoi(pos);
2466 } else if (os_strcmp(buf, "r0kh") == 0) {
2467 if (add_r0kh(bss, pos) < 0) {
2468 wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
2469 line, pos);
2470 return 1;
2471 }
2472 } else if (os_strcmp(buf, "r1kh") == 0) {
2473 if (add_r1kh(bss, pos) < 0) {
2474 wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
2475 line, pos);
2476 return 1;
2477 }
2478 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2479 bss->pmk_r1_push = atoi(pos);
2480 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2481 bss->ft_over_ds = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002482#endif /* CONFIG_IEEE80211R */
2483#ifndef CONFIG_NO_CTRL_IFACE
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002484 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2485 os_free(bss->ctrl_interface);
2486 bss->ctrl_interface = os_strdup(pos);
2487 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002488#ifndef CONFIG_NATIVE_WINDOWS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002489 struct group *grp;
2490 char *endp;
2491 const char *group = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002492
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002493 grp = getgrnam(group);
2494 if (grp) {
2495 bss->ctrl_interface_gid = grp->gr_gid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 bss->ctrl_interface_gid_set = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002497 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
2498 bss->ctrl_interface_gid, group);
2499 return 0;
2500 }
2501
2502 /* Group name not found - try to parse this as gid */
2503 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2504 if (*group == '\0' || *endp != '\0') {
2505 wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
2506 line, group);
2507 return 1;
2508 }
2509 bss->ctrl_interface_gid_set = 1;
2510 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2511 bss->ctrl_interface_gid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002512#endif /* CONFIG_NATIVE_WINDOWS */
2513#endif /* CONFIG_NO_CTRL_IFACE */
2514#ifdef RADIUS_SERVER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002515 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2516 os_free(bss->radius_server_clients);
2517 bss->radius_server_clients = os_strdup(pos);
2518 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2519 bss->radius_server_auth_port = atoi(pos);
2520 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2521 bss->radius_server_acct_port = atoi(pos);
2522 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2523 bss->radius_server_ipv6 = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002524#endif /* RADIUS_SERVER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002525 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2526 bss->use_pae_group_addr = atoi(pos);
2527 } else if (os_strcmp(buf, "hw_mode") == 0) {
2528 if (os_strcmp(pos, "a") == 0)
2529 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2530 else if (os_strcmp(pos, "b") == 0)
2531 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2532 else if (os_strcmp(pos, "g") == 0)
2533 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
2534 else if (os_strcmp(pos, "ad") == 0)
2535 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
2536 else {
2537 wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
2538 line, pos);
2539 return 1;
2540 }
2541 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2542 if (os_strcmp(pos, "a") == 0)
2543 bss->wps_rf_bands = WPS_RF_50GHZ;
2544 else if (os_strcmp(pos, "g") == 0 ||
2545 os_strcmp(pos, "b") == 0)
2546 bss->wps_rf_bands = WPS_RF_24GHZ;
2547 else if (os_strcmp(pos, "ag") == 0 ||
2548 os_strcmp(pos, "ga") == 0)
2549 bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
2550 else {
2551 wpa_printf(MSG_ERROR,
2552 "Line %d: unknown wps_rf_band '%s'",
2553 line, pos);
2554 return 1;
2555 }
2556 } else if (os_strcmp(buf, "channel") == 0) {
2557 if (os_strcmp(pos, "acs_survey") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002558#ifndef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002559 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
2560 line);
2561 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002562#else /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002563 conf->acs = 1;
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002564 conf->channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002565#endif /* CONFIG_ACS */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002566 } else {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002567 conf->channel = atoi(pos);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002568 conf->acs = conf->channel == 0;
2569 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002570 } else if (os_strcmp(buf, "chanlist") == 0) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002571 if (hostapd_parse_chanlist(conf, pos)) {
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002572 wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
2573 line);
2574 return 1;
2575 }
2576 } else if (os_strcmp(buf, "beacon_int") == 0) {
2577 int val = atoi(pos);
2578 /* MIB defines range as 1..65535, but very small values
2579 * cause problems with the current implementation.
2580 * Since it is unlikely that this small numbers are
2581 * useful in real life scenarios, do not allow beacon
2582 * period to be set below 15 TU. */
2583 if (val < 15 || val > 65535) {
2584 wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
2585 line, val);
2586 return 1;
2587 }
2588 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002589#ifdef CONFIG_ACS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002590 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
2591 int val = atoi(pos);
2592 if (val <= 0 || val > 100) {
2593 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
2594 line, val);
2595 return 1;
2596 }
2597 conf->acs_num_scans = val;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002598 } else if (os_strcmp(buf, "acs_chan_bias") == 0) {
2599 if (hostapd_config_parse_acs_chan_bias(conf, pos)) {
2600 wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias",
2601 line);
2602 return -1;
2603 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002604#endif /* CONFIG_ACS */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002605 } else if (os_strcmp(buf, "dtim_period") == 0) {
2606 bss->dtim_period = atoi(pos);
2607 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2608 wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
2609 line, bss->dtim_period);
2610 return 1;
2611 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002612 } else if (os_strcmp(buf, "bss_load_update_period") == 0) {
2613 bss->bss_load_update_period = atoi(pos);
2614 if (bss->bss_load_update_period < 0 ||
2615 bss->bss_load_update_period > 100) {
2616 wpa_printf(MSG_ERROR,
2617 "Line %d: invalid bss_load_update_period %d",
2618 line, bss->bss_load_update_period);
2619 return 1;
2620 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002621 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2622 conf->rts_threshold = atoi(pos);
2623 if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
2624 wpa_printf(MSG_ERROR,
2625 "Line %d: invalid rts_threshold %d",
2626 line, conf->rts_threshold);
2627 return 1;
2628 }
2629 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2630 conf->fragm_threshold = atoi(pos);
2631 if (conf->fragm_threshold < 256 ||
2632 conf->fragm_threshold > 2346) {
2633 wpa_printf(MSG_ERROR,
2634 "Line %d: invalid fragm_threshold %d",
2635 line, conf->fragm_threshold);
2636 return 1;
2637 }
2638 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2639 int val = atoi(pos);
2640 if (val != 0 && val != 1) {
2641 wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
2642 line, val);
2643 return 1;
2644 }
2645 conf->send_probe_response = val;
2646 } else if (os_strcmp(buf, "supported_rates") == 0) {
2647 if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
2648 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2649 line);
2650 return 1;
2651 }
2652 } else if (os_strcmp(buf, "basic_rates") == 0) {
2653 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
2654 wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
2655 line);
2656 return 1;
2657 }
2658 } else if (os_strcmp(buf, "preamble") == 0) {
2659 if (atoi(pos))
2660 conf->preamble = SHORT_PREAMBLE;
2661 else
2662 conf->preamble = LONG_PREAMBLE;
2663 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2664 bss->ignore_broadcast_ssid = atoi(pos);
2665 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2666 bss->ssid.wep.idx = atoi(pos);
2667 if (bss->ssid.wep.idx > 3) {
2668 wpa_printf(MSG_ERROR,
2669 "Invalid wep_default_key index %d",
2670 bss->ssid.wep.idx);
2671 return 1;
2672 }
2673 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2674 os_strcmp(buf, "wep_key1") == 0 ||
2675 os_strcmp(buf, "wep_key2") == 0 ||
2676 os_strcmp(buf, "wep_key3") == 0) {
2677 if (hostapd_config_read_wep(&bss->ssid.wep,
2678 buf[7] - '0', pos)) {
2679 wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
2680 line, buf);
2681 return 1;
2682 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683#ifndef CONFIG_NO_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002684 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2685 bss->ssid.dynamic_vlan = atoi(pos);
2686 } else if (os_strcmp(buf, "vlan_file") == 0) {
2687 if (hostapd_config_read_vlan_file(bss, pos)) {
2688 wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
2689 line, pos);
2690 return 1;
2691 }
2692 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2693 bss->ssid.vlan_naming = atoi(pos);
2694 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2695 bss->ssid.vlan_naming < 0) {
2696 wpa_printf(MSG_ERROR,
2697 "Line %d: invalid naming scheme %d",
2698 line, bss->ssid.vlan_naming);
2699 return 1;
2700 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002701#ifdef CONFIG_FULL_DYNAMIC_VLAN
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002702 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002703 os_free(bss->ssid.vlan_tagged_interface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002704 bss->ssid.vlan_tagged_interface = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002705#endif /* CONFIG_FULL_DYNAMIC_VLAN */
2706#endif /* CONFIG_NO_VLAN */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002707 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2708 conf->ap_table_max_size = atoi(pos);
2709 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2710 conf->ap_table_expiration_time = atoi(pos);
2711 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2712 if (hostapd_config_tx_queue(conf, buf, pos)) {
2713 wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
2714 line);
2715 return 1;
2716 }
2717 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2718 os_strcmp(buf, "wmm_enabled") == 0) {
2719 bss->wmm_enabled = atoi(pos);
2720 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2721 bss->wmm_uapsd = atoi(pos);
2722 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2723 os_strncmp(buf, "wmm_ac_", 7) == 0) {
2724 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
2725 wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
2726 line);
2727 return 1;
2728 }
2729 } else if (os_strcmp(buf, "bss") == 0) {
2730 if (hostapd_config_bss(conf, pos)) {
2731 wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
2732 line);
2733 return 1;
2734 }
2735 } else if (os_strcmp(buf, "bssid") == 0) {
2736 if (hwaddr_aton(pos, bss->bssid)) {
2737 wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
2738 line);
2739 return 1;
2740 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002741#ifdef CONFIG_IEEE80211W
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002742 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2743 bss->ieee80211w = atoi(pos);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002744 } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
2745 if (os_strcmp(pos, "AES-128-CMAC") == 0) {
2746 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
2747 } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
2748 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
2749 } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
2750 bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
2751 } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
2752 bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
2753 } else {
2754 wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
2755 line, pos);
2756 return 1;
2757 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002758 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2759 bss->assoc_sa_query_max_timeout = atoi(pos);
2760 if (bss->assoc_sa_query_max_timeout == 0) {
2761 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
2762 line);
2763 return 1;
2764 }
2765 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
2766 bss->assoc_sa_query_retry_timeout = atoi(pos);
2767 if (bss->assoc_sa_query_retry_timeout == 0) {
2768 wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
2769 line);
2770 return 1;
2771 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772#endif /* CONFIG_IEEE80211W */
2773#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002774 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2775 conf->ieee80211n = atoi(pos);
2776 } else if (os_strcmp(buf, "ht_capab") == 0) {
2777 if (hostapd_config_ht_capab(conf, pos) < 0) {
2778 wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
2779 line);
2780 return 1;
2781 }
2782 } else if (os_strcmp(buf, "require_ht") == 0) {
2783 conf->require_ht = atoi(pos);
2784 } else if (os_strcmp(buf, "obss_interval") == 0) {
2785 conf->obss_interval = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002787#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002788 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2789 conf->ieee80211ac = atoi(pos);
2790 } else if (os_strcmp(buf, "vht_capab") == 0) {
2791 if (hostapd_config_vht_capab(conf, pos) < 0) {
2792 wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
2793 line);
2794 return 1;
2795 }
2796 } else if (os_strcmp(buf, "require_vht") == 0) {
2797 conf->require_vht = atoi(pos);
2798 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
2799 conf->vht_oper_chwidth = atoi(pos);
2800 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
2801 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
2802 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
2803 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002804 } else if (os_strcmp(buf, "vendor_vht") == 0) {
2805 bss->vendor_vht = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002806#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002807 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2808 bss->max_listen_interval = atoi(pos);
2809 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2810 bss->disable_pmksa_caching = atoi(pos);
2811 } else if (os_strcmp(buf, "okc") == 0) {
2812 bss->okc = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813#ifdef CONFIG_WPS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002814 } else if (os_strcmp(buf, "wps_state") == 0) {
2815 bss->wps_state = atoi(pos);
2816 if (bss->wps_state < 0 || bss->wps_state > 2) {
2817 wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
2818 line);
2819 return 1;
2820 }
2821 } else if (os_strcmp(buf, "wps_independent") == 0) {
2822 bss->wps_independent = atoi(pos);
2823 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2824 bss->ap_setup_locked = atoi(pos);
2825 } else if (os_strcmp(buf, "uuid") == 0) {
2826 if (uuid_str2bin(pos, bss->uuid)) {
2827 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2828 return 1;
2829 }
2830 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2831 os_free(bss->wps_pin_requests);
2832 bss->wps_pin_requests = os_strdup(pos);
2833 } else if (os_strcmp(buf, "device_name") == 0) {
2834 if (os_strlen(pos) > 32) {
2835 wpa_printf(MSG_ERROR, "Line %d: Too long "
2836 "device_name", line);
2837 return 1;
2838 }
2839 os_free(bss->device_name);
2840 bss->device_name = os_strdup(pos);
2841 } else if (os_strcmp(buf, "manufacturer") == 0) {
2842 if (os_strlen(pos) > 64) {
2843 wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
2844 line);
2845 return 1;
2846 }
2847 os_free(bss->manufacturer);
2848 bss->manufacturer = os_strdup(pos);
2849 } else if (os_strcmp(buf, "model_name") == 0) {
2850 if (os_strlen(pos) > 32) {
2851 wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
2852 line);
2853 return 1;
2854 }
2855 os_free(bss->model_name);
2856 bss->model_name = os_strdup(pos);
2857 } else if (os_strcmp(buf, "model_number") == 0) {
2858 if (os_strlen(pos) > 32) {
2859 wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
2860 line);
2861 return 1;
2862 }
2863 os_free(bss->model_number);
2864 bss->model_number = os_strdup(pos);
2865 } else if (os_strcmp(buf, "serial_number") == 0) {
2866 if (os_strlen(pos) > 32) {
2867 wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
2868 line);
2869 return 1;
2870 }
2871 os_free(bss->serial_number);
2872 bss->serial_number = os_strdup(pos);
2873 } else if (os_strcmp(buf, "device_type") == 0) {
2874 if (wps_dev_type_str2bin(pos, bss->device_type))
2875 return 1;
2876 } else if (os_strcmp(buf, "config_methods") == 0) {
2877 os_free(bss->config_methods);
2878 bss->config_methods = os_strdup(pos);
2879 } else if (os_strcmp(buf, "os_version") == 0) {
2880 if (hexstr2bin(pos, bss->os_version, 4)) {
2881 wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
2882 line);
2883 return 1;
2884 }
2885 } else if (os_strcmp(buf, "ap_pin") == 0) {
2886 os_free(bss->ap_pin);
2887 bss->ap_pin = os_strdup(pos);
2888 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2889 bss->skip_cred_build = atoi(pos);
2890 } else if (os_strcmp(buf, "extra_cred") == 0) {
2891 os_free(bss->extra_cred);
2892 bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
2893 if (bss->extra_cred == NULL) {
2894 wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
2895 line, pos);
2896 return 1;
2897 }
2898 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2899 bss->wps_cred_processing = atoi(pos);
2900 } else if (os_strcmp(buf, "ap_settings") == 0) {
2901 os_free(bss->ap_settings);
2902 bss->ap_settings =
2903 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2904 if (bss->ap_settings == NULL) {
2905 wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
2906 line, pos);
2907 return 1;
2908 }
2909 } else if (os_strcmp(buf, "upnp_iface") == 0) {
Dmitry Shmidt21de2142014-04-08 10:50:52 -07002910 os_free(bss->upnp_iface);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002911 bss->upnp_iface = os_strdup(pos);
2912 } else if (os_strcmp(buf, "friendly_name") == 0) {
2913 os_free(bss->friendly_name);
2914 bss->friendly_name = os_strdup(pos);
2915 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2916 os_free(bss->manufacturer_url);
2917 bss->manufacturer_url = os_strdup(pos);
2918 } else if (os_strcmp(buf, "model_description") == 0) {
2919 os_free(bss->model_description);
2920 bss->model_description = os_strdup(pos);
2921 } else if (os_strcmp(buf, "model_url") == 0) {
2922 os_free(bss->model_url);
2923 bss->model_url = os_strdup(pos);
2924 } else if (os_strcmp(buf, "upc") == 0) {
2925 os_free(bss->upc);
2926 bss->upc = os_strdup(pos);
2927 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2928 bss->pbc_in_m1 = atoi(pos);
2929 } else if (os_strcmp(buf, "server_id") == 0) {
2930 os_free(bss->server_id);
2931 bss->server_id = os_strdup(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002932#ifdef CONFIG_WPS_NFC
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002933 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2934 bss->wps_nfc_dev_pw_id = atoi(pos);
2935 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2936 bss->wps_nfc_dev_pw_id > 0xffff) {
2937 wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
2938 line);
2939 return 1;
2940 }
2941 bss->wps_nfc_pw_from_config = 1;
2942 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2943 wpabuf_free(bss->wps_nfc_dh_pubkey);
2944 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
2945 bss->wps_nfc_pw_from_config = 1;
2946 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2947 wpabuf_free(bss->wps_nfc_dh_privkey);
2948 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
2949 bss->wps_nfc_pw_from_config = 1;
2950 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2951 wpabuf_free(bss->wps_nfc_dev_pw);
2952 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
2953 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002954#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002955#endif /* CONFIG_WPS */
2956#ifdef CONFIG_P2P_MANAGER
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002957 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2958 if (atoi(pos))
2959 bss->p2p |= P2P_MANAGE;
2960 else
2961 bss->p2p &= ~P2P_MANAGE;
2962 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2963 if (atoi(pos))
2964 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2965 else
2966 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002967#endif /* CONFIG_P2P_MANAGER */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002968 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2969 bss->disassoc_low_ack = atoi(pos);
2970 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2971 if (atoi(pos))
2972 bss->tdls |= TDLS_PROHIBIT;
2973 else
2974 bss->tdls &= ~TDLS_PROHIBIT;
2975 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2976 if (atoi(pos))
2977 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2978 else
2979 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980#ifdef CONFIG_RSN_TESTING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002981 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2982 extern int rsn_testing;
2983 rsn_testing = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002985 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2986 bss->time_advertisement = atoi(pos);
2987 } else if (os_strcmp(buf, "time_zone") == 0) {
2988 size_t tz_len = os_strlen(pos);
2989 if (tz_len < 4 || tz_len > 255) {
2990 wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
2991 line);
2992 return 1;
2993 }
2994 os_free(bss->time_zone);
2995 bss->time_zone = os_strdup(pos);
2996 if (bss->time_zone == NULL)
2997 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002998#ifdef CONFIG_WNM
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07002999 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
3000 bss->wnm_sleep_mode = atoi(pos);
3001 } else if (os_strcmp(buf, "bss_transition") == 0) {
3002 bss->bss_transition = atoi(pos);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003003#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003004#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003005 } else if (os_strcmp(buf, "interworking") == 0) {
3006 bss->interworking = atoi(pos);
3007 } else if (os_strcmp(buf, "access_network_type") == 0) {
3008 bss->access_network_type = atoi(pos);
3009 if (bss->access_network_type < 0 ||
3010 bss->access_network_type > 15) {
3011 wpa_printf(MSG_ERROR,
3012 "Line %d: invalid access_network_type",
3013 line);
3014 return 1;
3015 }
3016 } else if (os_strcmp(buf, "internet") == 0) {
3017 bss->internet = atoi(pos);
3018 } else if (os_strcmp(buf, "asra") == 0) {
3019 bss->asra = atoi(pos);
3020 } else if (os_strcmp(buf, "esr") == 0) {
3021 bss->esr = atoi(pos);
3022 } else if (os_strcmp(buf, "uesa") == 0) {
3023 bss->uesa = atoi(pos);
3024 } else if (os_strcmp(buf, "venue_group") == 0) {
3025 bss->venue_group = atoi(pos);
3026 bss->venue_info_set = 1;
3027 } else if (os_strcmp(buf, "venue_type") == 0) {
3028 bss->venue_type = atoi(pos);
3029 bss->venue_info_set = 1;
3030 } else if (os_strcmp(buf, "hessid") == 0) {
3031 if (hwaddr_aton(pos, bss->hessid)) {
3032 wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
3033 return 1;
3034 }
3035 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
3036 if (parse_roaming_consortium(bss, pos, line) < 0)
3037 return 1;
3038 } else if (os_strcmp(buf, "venue_name") == 0) {
3039 if (parse_venue_name(bss, pos, line) < 0)
3040 return 1;
3041 } else if (os_strcmp(buf, "network_auth_type") == 0) {
3042 u8 auth_type;
3043 u16 redirect_url_len;
3044 if (hexstr2bin(pos, &auth_type, 1)) {
3045 wpa_printf(MSG_ERROR,
3046 "Line %d: Invalid network_auth_type '%s'",
3047 line, pos);
3048 return 1;
3049 }
3050 if (auth_type == 0 || auth_type == 2)
3051 redirect_url_len = os_strlen(pos + 2);
3052 else
3053 redirect_url_len = 0;
3054 os_free(bss->network_auth_type);
3055 bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
3056 if (bss->network_auth_type == NULL)
3057 return 1;
3058 *bss->network_auth_type = auth_type;
3059 WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
3060 if (redirect_url_len)
3061 os_memcpy(bss->network_auth_type + 3, pos + 2,
3062 redirect_url_len);
3063 bss->network_auth_type_len = 3 + redirect_url_len;
3064 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
3065 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
3066 wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
3067 line, pos);
3068 bss->ipaddr_type_configured = 0;
3069 return 1;
3070 }
3071 bss->ipaddr_type_configured = 1;
3072 } else if (os_strcmp(buf, "domain_name") == 0) {
3073 int j, num_domains, domain_len, domain_list_len = 0;
3074 char *tok_start, *tok_prev;
3075 u8 *domain_list, *domain_ptr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003076
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003077 domain_list_len = os_strlen(pos) + 1;
3078 domain_list = os_malloc(domain_list_len);
3079 if (domain_list == NULL)
3080 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003081
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003082 domain_ptr = domain_list;
3083 tok_prev = pos;
3084 num_domains = 1;
3085 while ((tok_prev = os_strchr(tok_prev, ','))) {
3086 num_domains++;
3087 tok_prev++;
3088 }
3089 tok_prev = pos;
3090 for (j = 0; j < num_domains; j++) {
3091 tok_start = os_strchr(tok_prev, ',');
3092 if (tok_start) {
3093 domain_len = tok_start - tok_prev;
3094 *domain_ptr = domain_len;
3095 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3096 domain_ptr += domain_len + 1;
3097 tok_prev = ++tok_start;
3098 } else {
3099 domain_len = os_strlen(tok_prev);
3100 *domain_ptr = domain_len;
3101 os_memcpy(domain_ptr + 1, tok_prev, domain_len);
3102 domain_ptr += domain_len + 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003103 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003104 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003105
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003106 os_free(bss->domain_name);
3107 bss->domain_name = domain_list;
3108 bss->domain_name_len = domain_list_len;
3109 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
3110 if (parse_3gpp_cell_net(bss, pos, line) < 0)
3111 return 1;
3112 } else if (os_strcmp(buf, "nai_realm") == 0) {
3113 if (parse_nai_realm(bss, pos, line) < 0)
3114 return 1;
3115 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
3116 bss->gas_frag_limit = atoi(pos);
3117 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3118 bss->gas_comeback_delay = atoi(pos);
3119 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3120 if (parse_qos_map_set(bss, pos, line) < 0)
3121 return 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003122#endif /* CONFIG_INTERWORKING */
3123#ifdef CONFIG_RADIUS_TEST
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003124 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3125 os_free(bss->dump_msk_file);
3126 bss->dump_msk_file = os_strdup(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003127#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003128#ifdef CONFIG_HS20
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003129 } else if (os_strcmp(buf, "hs20") == 0) {
3130 bss->hs20 = atoi(pos);
3131 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3132 bss->disable_dgaf = atoi(pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003133 } else if (os_strcmp(buf, "proxy_arp") == 0) {
3134 bss->proxy_arp = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003135 } else if (os_strcmp(buf, "osen") == 0) {
3136 bss->osen = atoi(pos);
3137 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3138 bss->anqp_domain_id = atoi(pos);
3139 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3140 bss->hs20_deauth_req_timeout = atoi(pos);
3141 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3142 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3143 return 1;
3144 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3145 if (hs20_parse_wan_metrics(bss, pos, line) < 0)
3146 return 1;
3147 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3148 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3149 return 1;
3150 }
3151 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3152 u8 *oper_class;
3153 size_t oper_class_len;
3154 oper_class_len = os_strlen(pos);
3155 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3156 wpa_printf(MSG_ERROR,
3157 "Line %d: Invalid hs20_operating_class '%s'",
3158 line, pos);
3159 return 1;
3160 }
3161 oper_class_len /= 2;
3162 oper_class = os_malloc(oper_class_len);
3163 if (oper_class == NULL)
3164 return 1;
3165 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3166 wpa_printf(MSG_ERROR,
3167 "Line %d: Invalid hs20_operating_class '%s'",
3168 line, pos);
3169 os_free(oper_class);
3170 return 1;
3171 }
3172 os_free(bss->hs20_operating_class);
3173 bss->hs20_operating_class = oper_class;
3174 bss->hs20_operating_class_len = oper_class_len;
3175 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3176 if (hs20_parse_icon(bss, pos) < 0) {
3177 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
3178 line, pos);
3179 return 1;
3180 }
3181 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3182 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
3183 return 1;
3184 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3185 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
3186 return 1;
3187 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3188 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
3189 return 1;
3190 } else if (os_strcmp(buf, "osu_nai") == 0) {
3191 if (hs20_parse_osu_nai(bss, pos, line) < 0)
3192 return 1;
3193 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3194 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
3195 return 1;
3196 } else if (os_strcmp(buf, "osu_icon") == 0) {
3197 if (hs20_parse_osu_icon(bss, pos, line) < 0)
3198 return 1;
3199 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3200 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
3201 return 1;
3202 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3203 os_free(bss->subscr_remediation_url);
3204 bss->subscr_remediation_url = os_strdup(pos);
3205 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3206 bss->subscr_remediation_method = atoi(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003207#endif /* CONFIG_HS20 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003208#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003209#define PARSE_TEST_PROBABILITY(_val) \
3210 } else if (os_strcmp(buf, #_val) == 0) { \
3211 char *end; \
3212 \
3213 conf->_val = strtod(pos, &end); \
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003214 if (*end || conf->_val < 0.0 || \
3215 conf->_val > 1.0) { \
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003216 wpa_printf(MSG_ERROR, \
3217 "Line %d: Invalid value '%s'", \
3218 line, pos); \
3219 return 1; \
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003220 }
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003221 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3222 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3223 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3224 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
3225 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
3226 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3227 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3228 pos = os_strchr(pos, ':');
3229 if (pos == NULL) {
3230 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3231 line);
3232 return 1;
3233 }
3234 pos++;
3235 bss->bss_load_test[2] = atoi(pos);
3236 pos = os_strchr(pos, ':');
3237 if (pos == NULL) {
3238 wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
3239 line);
3240 return 1;
3241 }
3242 pos++;
3243 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3244 bss->bss_load_test_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003245 } else if (os_strcmp(buf, "radio_measurements") == 0) {
3246 bss->radio_measurements = atoi(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003247#endif /* CONFIG_TESTING_OPTIONS */
3248 } else if (os_strcmp(buf, "vendor_elements") == 0) {
3249 struct wpabuf *elems;
3250 size_t len = os_strlen(pos);
3251 if (len & 0x01) {
3252 wpa_printf(MSG_ERROR,
3253 "Line %d: Invalid vendor_elements '%s'",
3254 line, pos);
3255 return 1;
3256 }
3257 len /= 2;
3258 if (len == 0) {
3259 wpabuf_free(bss->vendor_elements);
3260 bss->vendor_elements = NULL;
3261 return 0;
3262 }
3263
3264 elems = wpabuf_alloc(len);
3265 if (elems == NULL)
3266 return 1;
3267
3268 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
3269 wpabuf_free(elems);
3270 wpa_printf(MSG_ERROR,
3271 "Line %d: Invalid vendor_elements '%s'",
3272 line, pos);
3273 return 1;
3274 }
3275
3276 wpabuf_free(bss->vendor_elements);
3277 bss->vendor_elements = elems;
3278 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3279 bss->sae_anti_clogging_threshold = atoi(pos);
3280 } else if (os_strcmp(buf, "sae_groups") == 0) {
3281 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
3282 wpa_printf(MSG_ERROR,
3283 "Line %d: Invalid sae_groups value '%s'",
3284 line, pos);
3285 return 1;
3286 }
3287 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3288 int val = atoi(pos);
3289 if (val < 0 || val > 255) {
3290 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3291 line, val);
3292 return 1;
3293 }
3294 conf->local_pwr_constraint = val;
3295 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3296 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt0207e232014-09-03 14:58:37 -07003297 } else if (os_strcmp(buf, "wowlan_triggers") == 0) {
3298 os_free(bss->wowlan_triggers);
3299 bss->wowlan_triggers = os_strdup(pos);
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003300 } else {
3301 wpa_printf(MSG_ERROR,
3302 "Line %d: unknown configuration item '%s'",
3303 line, buf);
3304 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003305 }
3306
Dmitry Shmidtd5dc24e2014-03-12 14:22:04 -07003307 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003308}
3309
3310
Dmitry Shmidt04949592012-07-19 12:16:46 -07003311/**
3312 * hostapd_config_read - Read and parse a configuration file
3313 * @fname: Configuration file name (including path, if needed)
3314 * Returns: Allocated configuration data structure
3315 */
3316struct hostapd_config * hostapd_config_read(const char *fname)
3317{
3318 struct hostapd_config *conf;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003319 FILE *f;
3320 char buf[512], *pos;
3321 int line = 0;
3322 int errors = 0;
3323 size_t i;
3324
3325 f = fopen(fname, "r");
3326 if (f == NULL) {
3327 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3328 "for reading.", fname);
3329 return NULL;
3330 }
3331
3332 conf = hostapd_config_defaults();
3333 if (conf == NULL) {
3334 fclose(f);
3335 return NULL;
3336 }
3337
3338 /* set default driver based on configuration */
3339 conf->driver = wpa_drivers[0];
3340 if (conf->driver == NULL) {
3341 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3342 hostapd_config_free(conf);
3343 fclose(f);
3344 return NULL;
3345 }
3346
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003347 conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07003348
3349 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003350 struct hostapd_bss_config *bss;
3351
Dmitry Shmidt04949592012-07-19 12:16:46 -07003352 bss = conf->last_bss;
3353 line++;
3354
3355 if (buf[0] == '#')
3356 continue;
3357 pos = buf;
3358 while (*pos != '\0') {
3359 if (*pos == '\n') {
3360 *pos = '\0';
3361 break;
3362 }
3363 pos++;
3364 }
3365 if (buf[0] == '\0')
3366 continue;
3367
3368 pos = os_strchr(buf, '=');
3369 if (pos == NULL) {
3370 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3371 line, buf);
3372 errors++;
3373 continue;
3374 }
3375 *pos = '\0';
3376 pos++;
3377 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3378 }
3379
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003380 fclose(f);
3381
Dmitry Shmidt04949592012-07-19 12:16:46 -07003382 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07003383 hostapd_set_security_params(conf->bss[i], 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003384
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003385 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003386 errors++;
3387
3388#ifndef WPA_IGNORE_CONFIG_ERRORS
3389 if (errors) {
3390 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3391 "'%s'", errors, fname);
3392 hostapd_config_free(conf);
3393 conf = NULL;
3394 }
3395#endif /* WPA_IGNORE_CONFIG_ERRORS */
3396
3397 return conf;
3398}
Dmitry Shmidt04949592012-07-19 12:16:46 -07003399
3400
3401int hostapd_set_iface(struct hostapd_config *conf,
3402 struct hostapd_bss_config *bss, char *field, char *value)
3403{
3404 int errors;
3405 size_t i;
3406
3407 errors = hostapd_config_fill(conf, bss, field, value, 0);
3408 if (errors) {
3409 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3410 "to value '%s'", field, value);
3411 return -1;
3412 }
3413
3414 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07003415 hostapd_set_security_params(conf->bss[i], 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003416
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003417 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003418 wpa_printf(MSG_ERROR, "Configuration check failed");
3419 return -1;
3420 }
3421
3422 return 0;
3423}