blob: bd66474392dc8a32141a589d01034a44badc7911 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration file parser
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003 * Copyright (c) 2003-2014, 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 Shmidt8d520ff2011-05-09 14:06:53 -070025#ifndef CONFIG_NO_VLAN
26static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
27 const char *fname)
28{
29 FILE *f;
30 char buf[128], *pos, *pos2;
31 int line = 0, vlan_id;
32 struct hostapd_vlan *vlan;
33
34 f = fopen(fname, "r");
35 if (!f) {
36 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
37 return -1;
38 }
39
40 while (fgets(buf, sizeof(buf), f)) {
41 line++;
42
43 if (buf[0] == '#')
44 continue;
45 pos = buf;
46 while (*pos != '\0') {
47 if (*pos == '\n') {
48 *pos = '\0';
49 break;
50 }
51 pos++;
52 }
53 if (buf[0] == '\0')
54 continue;
55
56 if (buf[0] == '*') {
57 vlan_id = VLAN_ID_WILDCARD;
58 pos = buf + 1;
59 } else {
60 vlan_id = strtol(buf, &pos, 10);
61 if (buf == pos || vlan_id < 1 ||
62 vlan_id > MAX_VLAN_ID) {
63 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
64 "line %d in '%s'", line, fname);
65 fclose(f);
66 return -1;
67 }
68 }
69
70 while (*pos == ' ' || *pos == '\t')
71 pos++;
72 pos2 = pos;
73 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
74 pos2++;
75 *pos2 = '\0';
76 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
77 wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
78 "in '%s'", line, fname);
79 fclose(f);
80 return -1;
81 }
82
Dmitry Shmidt4b060592013-04-29 16:42:49 -070083 vlan = os_zalloc(sizeof(*vlan));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084 if (vlan == NULL) {
85 wpa_printf(MSG_ERROR, "Out of memory while reading "
86 "VLAN interfaces from '%s'", fname);
87 fclose(f);
88 return -1;
89 }
90
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070091 vlan->vlan_id = vlan_id;
92 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -070093 vlan->next = bss->vlan;
94 bss->vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095 }
96
97 fclose(f);
98
99 return 0;
100}
101#endif /* CONFIG_NO_VLAN */
102
103
104static int hostapd_acl_comp(const void *a, const void *b)
105{
106 const struct mac_acl_entry *aa = a;
107 const struct mac_acl_entry *bb = b;
108 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
109}
110
111
112static int hostapd_config_read_maclist(const char *fname,
113 struct mac_acl_entry **acl, int *num)
114{
115 FILE *f;
116 char buf[128], *pos;
117 int line = 0;
118 u8 addr[ETH_ALEN];
119 struct mac_acl_entry *newacl;
120 int vlan_id;
121
122 if (!fname)
123 return 0;
124
125 f = fopen(fname, "r");
126 if (!f) {
127 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
128 return -1;
129 }
130
131 while (fgets(buf, sizeof(buf), f)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800132 int i, rem = 0;
133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134 line++;
135
136 if (buf[0] == '#')
137 continue;
138 pos = buf;
139 while (*pos != '\0') {
140 if (*pos == '\n') {
141 *pos = '\0';
142 break;
143 }
144 pos++;
145 }
146 if (buf[0] == '\0')
147 continue;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800148 pos = buf;
149 if (buf[0] == '-') {
150 rem = 1;
151 pos++;
152 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800154 if (hwaddr_aton(pos, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800156 "line %d in '%s'", pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157 fclose(f);
158 return -1;
159 }
160
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800161 if (rem) {
162 i = 0;
163 while (i < *num) {
164 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
165 0) {
166 os_remove_in_array(*acl, *num,
167 sizeof(**acl), i);
168 (*num)--;
169 } else
170 i++;
171 }
172 continue;
173 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174 vlan_id = 0;
175 pos = buf;
176 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
177 pos++;
178 while (*pos == ' ' || *pos == '\t')
179 pos++;
180 if (*pos != '\0')
181 vlan_id = atoi(pos);
182
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700183 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184 if (newacl == NULL) {
185 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
186 fclose(f);
187 return -1;
188 }
189
190 *acl = newacl;
191 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
192 (*acl)[*num].vlan_id = vlan_id;
193 (*num)++;
194 }
195
196 fclose(f);
197
198 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
199
200 return 0;
201}
202
203
204#ifdef EAP_SERVER
205static int hostapd_config_read_eap_user(const char *fname,
206 struct hostapd_bss_config *conf)
207{
208 FILE *f;
209 char buf[512], *pos, *start, *pos2;
210 int line = 0, ret = 0, num_methods;
211 struct hostapd_eap_user *user, *tail = NULL;
212
213 if (!fname)
214 return 0;
215
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800216 if (os_strncmp(fname, "sqlite:", 7) == 0) {
217 os_free(conf->eap_user_sqlite);
218 conf->eap_user_sqlite = os_strdup(fname + 7);
219 return 0;
220 }
221
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 f = fopen(fname, "r");
223 if (!f) {
224 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
225 return -1;
226 }
227
228 /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
229 while (fgets(buf, sizeof(buf), f)) {
230 line++;
231
232 if (buf[0] == '#')
233 continue;
234 pos = buf;
235 while (*pos != '\0') {
236 if (*pos == '\n') {
237 *pos = '\0';
238 break;
239 }
240 pos++;
241 }
242 if (buf[0] == '\0')
243 continue;
244
245 user = NULL;
246
247 if (buf[0] != '"' && buf[0] != '*') {
248 wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
249 "start) on line %d in '%s'", line, fname);
250 goto failed;
251 }
252
253 user = os_zalloc(sizeof(*user));
254 if (user == NULL) {
255 wpa_printf(MSG_ERROR, "EAP user allocation failed");
256 goto failed;
257 }
258 user->force_version = -1;
259
260 if (buf[0] == '*') {
261 pos = buf;
262 } else {
263 pos = buf + 1;
264 start = pos;
265 while (*pos != '"' && *pos != '\0')
266 pos++;
267 if (*pos == '\0') {
268 wpa_printf(MSG_ERROR, "Invalid EAP identity "
269 "(no \" in end) on line %d in '%s'",
270 line, fname);
271 goto failed;
272 }
273
274 user->identity = os_malloc(pos - start);
275 if (user->identity == NULL) {
276 wpa_printf(MSG_ERROR, "Failed to allocate "
277 "memory for EAP identity");
278 goto failed;
279 }
280 os_memcpy(user->identity, start, pos - start);
281 user->identity_len = pos - start;
282
283 if (pos[0] == '"' && pos[1] == '*') {
284 user->wildcard_prefix = 1;
285 pos++;
286 }
287 }
288 pos++;
289 while (*pos == ' ' || *pos == '\t')
290 pos++;
291
292 if (*pos == '\0') {
293 wpa_printf(MSG_ERROR, "No EAP method on line %d in "
294 "'%s'", line, fname);
295 goto failed;
296 }
297
298 start = pos;
299 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
300 pos++;
301 if (*pos == '\0') {
302 pos = NULL;
303 } else {
304 *pos = '\0';
305 pos++;
306 }
307 num_methods = 0;
308 while (*start) {
309 char *pos3 = os_strchr(start, ',');
310 if (pos3) {
311 *pos3++ = '\0';
312 }
313 user->methods[num_methods].method =
314 eap_server_get_type(
315 start,
316 &user->methods[num_methods].vendor);
317 if (user->methods[num_methods].vendor ==
318 EAP_VENDOR_IETF &&
319 user->methods[num_methods].method == EAP_TYPE_NONE)
320 {
321 if (os_strcmp(start, "TTLS-PAP") == 0) {
322 user->ttls_auth |= EAP_TTLS_AUTH_PAP;
323 goto skip_eap;
324 }
325 if (os_strcmp(start, "TTLS-CHAP") == 0) {
326 user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
327 goto skip_eap;
328 }
329 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
330 user->ttls_auth |=
331 EAP_TTLS_AUTH_MSCHAP;
332 goto skip_eap;
333 }
334 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
335 user->ttls_auth |=
336 EAP_TTLS_AUTH_MSCHAPV2;
337 goto skip_eap;
338 }
339 wpa_printf(MSG_ERROR, "Unsupported EAP type "
340 "'%s' on line %d in '%s'",
341 start, line, fname);
342 goto failed;
343 }
344
345 num_methods++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800346 if (num_methods >= EAP_MAX_METHODS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 break;
348 skip_eap:
349 if (pos3 == NULL)
350 break;
351 start = pos3;
352 }
353 if (num_methods == 0 && user->ttls_auth == 0) {
354 wpa_printf(MSG_ERROR, "No EAP types configured on "
355 "line %d in '%s'", line, fname);
356 goto failed;
357 }
358
359 if (pos == NULL)
360 goto done;
361
362 while (*pos == ' ' || *pos == '\t')
363 pos++;
364 if (*pos == '\0')
365 goto done;
366
367 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
368 user->force_version = 0;
369 goto done;
370 }
371
372 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
373 user->force_version = 1;
374 goto done;
375 }
376
377 if (os_strncmp(pos, "[2]", 3) == 0) {
378 user->phase2 = 1;
379 goto done;
380 }
381
382 if (*pos == '"') {
383 pos++;
384 start = pos;
385 while (*pos != '"' && *pos != '\0')
386 pos++;
387 if (*pos == '\0') {
388 wpa_printf(MSG_ERROR, "Invalid EAP password "
389 "(no \" in end) on line %d in '%s'",
390 line, fname);
391 goto failed;
392 }
393
394 user->password = os_malloc(pos - start);
395 if (user->password == NULL) {
396 wpa_printf(MSG_ERROR, "Failed to allocate "
397 "memory for EAP password");
398 goto failed;
399 }
400 os_memcpy(user->password, start, pos - start);
401 user->password_len = pos - start;
402
403 pos++;
404 } else if (os_strncmp(pos, "hash:", 5) == 0) {
405 pos += 5;
406 pos2 = pos;
407 while (*pos2 != '\0' && *pos2 != ' ' &&
408 *pos2 != '\t' && *pos2 != '#')
409 pos2++;
410 if (pos2 - pos != 32) {
411 wpa_printf(MSG_ERROR, "Invalid password hash "
412 "on line %d in '%s'", line, fname);
413 goto failed;
414 }
415 user->password = os_malloc(16);
416 if (user->password == NULL) {
417 wpa_printf(MSG_ERROR, "Failed to allocate "
418 "memory for EAP password hash");
419 goto failed;
420 }
421 if (hexstr2bin(pos, user->password, 16) < 0) {
422 wpa_printf(MSG_ERROR, "Invalid hash password "
423 "on line %d in '%s'", line, fname);
424 goto failed;
425 }
426 user->password_len = 16;
427 user->password_hash = 1;
428 pos = pos2;
429 } else {
430 pos2 = pos;
431 while (*pos2 != '\0' && *pos2 != ' ' &&
432 *pos2 != '\t' && *pos2 != '#')
433 pos2++;
434 if ((pos2 - pos) & 1) {
435 wpa_printf(MSG_ERROR, "Invalid hex password "
436 "on line %d in '%s'", line, fname);
437 goto failed;
438 }
439 user->password = os_malloc((pos2 - pos) / 2);
440 if (user->password == NULL) {
441 wpa_printf(MSG_ERROR, "Failed to allocate "
442 "memory for EAP password");
443 goto failed;
444 }
445 if (hexstr2bin(pos, user->password,
446 (pos2 - pos) / 2) < 0) {
447 wpa_printf(MSG_ERROR, "Invalid hex password "
448 "on line %d in '%s'", line, fname);
449 goto failed;
450 }
451 user->password_len = (pos2 - pos) / 2;
452 pos = pos2;
453 }
454
455 while (*pos == ' ' || *pos == '\t')
456 pos++;
457 if (os_strncmp(pos, "[2]", 3) == 0) {
458 user->phase2 = 1;
459 }
460
461 done:
462 if (tail == NULL) {
463 tail = conf->eap_user = user;
464 } else {
465 tail->next = user;
466 tail = user;
467 }
468 continue;
469
470 failed:
471 if (user) {
472 os_free(user->password);
473 os_free(user->identity);
474 os_free(user);
475 }
476 ret = -1;
477 break;
478 }
479
480 fclose(f);
481
482 return ret;
483}
484#endif /* EAP_SERVER */
485
486
487#ifndef CONFIG_NO_RADIUS
488static int
489hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
490 int *num_server, const char *val, int def_port,
491 struct hostapd_radius_server **curr_serv)
492{
493 struct hostapd_radius_server *nserv;
494 int ret;
495 static int server_index = 1;
496
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700497 nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 if (nserv == NULL)
499 return -1;
500
501 *server = nserv;
502 nserv = &nserv[*num_server];
503 (*num_server)++;
504 (*curr_serv) = nserv;
505
506 os_memset(nserv, 0, sizeof(*nserv));
507 nserv->port = def_port;
508 ret = hostapd_parse_ip_addr(val, &nserv->addr);
509 nserv->index = server_index++;
510
511 return ret;
512}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700513
514
515static struct hostapd_radius_attr *
516hostapd_parse_radius_attr(const char *value)
517{
518 const char *pos;
519 char syntax;
520 struct hostapd_radius_attr *attr;
521 size_t len;
522
523 attr = os_zalloc(sizeof(*attr));
524 if (attr == NULL)
525 return NULL;
526
527 attr->type = atoi(value);
528
529 pos = os_strchr(value, ':');
530 if (pos == NULL) {
531 attr->val = wpabuf_alloc(1);
532 if (attr->val == NULL) {
533 os_free(attr);
534 return NULL;
535 }
536 wpabuf_put_u8(attr->val, 0);
537 return attr;
538 }
539
540 pos++;
541 if (pos[0] == '\0' || pos[1] != ':') {
542 os_free(attr);
543 return NULL;
544 }
545 syntax = *pos++;
546 pos++;
547
548 switch (syntax) {
549 case 's':
550 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
551 break;
552 case 'x':
553 len = os_strlen(pos);
554 if (len & 1)
555 break;
556 len /= 2;
557 attr->val = wpabuf_alloc(len);
558 if (attr->val == NULL)
559 break;
560 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
561 wpabuf_free(attr->val);
562 os_free(attr);
563 return NULL;
564 }
565 break;
566 case 'd':
567 attr->val = wpabuf_alloc(4);
568 if (attr->val)
569 wpabuf_put_be32(attr->val, atoi(pos));
570 break;
571 default:
572 os_free(attr);
573 return NULL;
574 }
575
576 if (attr->val == NULL) {
577 os_free(attr);
578 return NULL;
579 }
580
581 return attr;
582}
583
584
585static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
586 const char *val)
587{
588 char *secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700589
590 secret = os_strchr(val, ' ');
591 if (secret == NULL)
592 return -1;
593
594 secret++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700595
596 if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
597 return -1;
598
599 os_free(bss->radius_das_shared_secret);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700600 bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700601 if (bss->radius_das_shared_secret == NULL)
602 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700603 bss->radius_das_shared_secret_len = os_strlen(secret);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700604
605 return 0;
606}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607#endif /* CONFIG_NO_RADIUS */
608
609
610static int hostapd_config_parse_key_mgmt(int line, const char *value)
611{
612 int val = 0, last;
613 char *start, *end, *buf;
614
615 buf = os_strdup(value);
616 if (buf == NULL)
617 return -1;
618 start = buf;
619
620 while (*start != '\0') {
621 while (*start == ' ' || *start == '\t')
622 start++;
623 if (*start == '\0')
624 break;
625 end = start;
626 while (*end != ' ' && *end != '\t' && *end != '\0')
627 end++;
628 last = *end == '\0';
629 *end = '\0';
630 if (os_strcmp(start, "WPA-PSK") == 0)
631 val |= WPA_KEY_MGMT_PSK;
632 else if (os_strcmp(start, "WPA-EAP") == 0)
633 val |= WPA_KEY_MGMT_IEEE8021X;
634#ifdef CONFIG_IEEE80211R
635 else if (os_strcmp(start, "FT-PSK") == 0)
636 val |= WPA_KEY_MGMT_FT_PSK;
637 else if (os_strcmp(start, "FT-EAP") == 0)
638 val |= WPA_KEY_MGMT_FT_IEEE8021X;
639#endif /* CONFIG_IEEE80211R */
640#ifdef CONFIG_IEEE80211W
641 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
642 val |= WPA_KEY_MGMT_PSK_SHA256;
643 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
644 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
645#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800646#ifdef CONFIG_SAE
647 else if (os_strcmp(start, "SAE") == 0)
648 val |= WPA_KEY_MGMT_SAE;
649 else if (os_strcmp(start, "FT-SAE") == 0)
650 val |= WPA_KEY_MGMT_FT_SAE;
651#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 else {
653 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
654 line, start);
655 os_free(buf);
656 return -1;
657 }
658
659 if (last)
660 break;
661 start = end + 1;
662 }
663
664 os_free(buf);
665 if (val == 0) {
666 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
667 "configured.", line);
668 return -1;
669 }
670
671 return val;
672}
673
674
675static int hostapd_config_parse_cipher(int line, const char *value)
676{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800677 int val = wpa_parse_cipher(value);
678 if (val < 0) {
679 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
680 line, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 if (val == 0) {
684 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
685 line);
686 return -1;
687 }
688 return val;
689}
690
691
692static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
693 char *val)
694{
695 size_t len = os_strlen(val);
696
697 if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
698 return -1;
699
700 if (val[0] == '"') {
701 if (len < 2 || val[len - 1] != '"')
702 return -1;
703 len -= 2;
704 wep->key[keyidx] = os_malloc(len);
705 if (wep->key[keyidx] == NULL)
706 return -1;
707 os_memcpy(wep->key[keyidx], val + 1, len);
708 wep->len[keyidx] = len;
709 } else {
710 if (len & 1)
711 return -1;
712 len /= 2;
713 wep->key[keyidx] = os_malloc(len);
714 if (wep->key[keyidx] == NULL)
715 return -1;
716 wep->len[keyidx] = len;
717 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
718 return -1;
719 }
720
721 wep->keys_set++;
722
723 return 0;
724}
725
726
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700727static int hostapd_parse_intlist(int **int_list, char *val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728{
729 int *list;
730 int count;
731 char *pos, *end;
732
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700733 os_free(*int_list);
734 *int_list = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735
736 pos = val;
737 count = 0;
738 while (*pos != '\0') {
739 if (*pos == ' ')
740 count++;
741 pos++;
742 }
743
744 list = os_malloc(sizeof(int) * (count + 2));
745 if (list == NULL)
746 return -1;
747 pos = val;
748 count = 0;
749 while (*pos != '\0') {
750 end = os_strchr(pos, ' ');
751 if (end)
752 *end = '\0';
753
754 list[count++] = atoi(pos);
755 if (!end)
756 break;
757 pos = end + 1;
758 }
759 list[count] = -1;
760
Dmitry Shmidtea69e842013-05-13 14:52:28 -0700761 *int_list = list;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 return 0;
763}
764
765
766static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
767{
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800768 struct hostapd_bss_config **all, *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769
770 if (*ifname == '\0')
771 return -1;
772
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800773 all = os_realloc_array(conf->bss, conf->num_bss + 1,
774 sizeof(struct hostapd_bss_config *));
775 if (all == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
777 "multi-BSS entry");
778 return -1;
779 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800780 conf->bss = all;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800782 bss = os_zalloc(sizeof(*bss));
783 if (bss == NULL)
784 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 bss->radius = os_zalloc(sizeof(*bss->radius));
786 if (bss->radius == NULL) {
787 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
788 "multi-BSS RADIUS data");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800789 os_free(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 return -1;
791 }
792
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800793 conf->bss[conf->num_bss++] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 conf->last_bss = bss;
795
796 hostapd_config_defaults_bss(bss);
797 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
798 os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
799
800 return 0;
801}
802
803
804/* convert floats with one decimal place to value*10 int, i.e.,
805 * "1.5" will return 15 */
806static int hostapd_config_read_int10(const char *value)
807{
808 int i, d;
809 char *pos;
810
811 i = atoi(value);
812 pos = os_strchr(value, '.');
813 d = 0;
814 if (pos) {
815 pos++;
816 if (*pos >= '0' && *pos <= '9')
817 d = *pos - '0';
818 }
819
820 return i * 10 + d;
821}
822
823
824static int valid_cw(int cw)
825{
826 return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
827 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
828}
829
830
831enum {
832 IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
833 IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
834 IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
835 IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
836};
837
838static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
839 char *val)
840{
841 int num;
842 char *pos;
843 struct hostapd_tx_queue_params *queue;
844
845 /* skip 'tx_queue_' prefix */
846 pos = name + 9;
847 if (os_strncmp(pos, "data", 4) == 0 &&
848 pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
849 num = pos[4] - '0';
850 pos += 6;
851 } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
852 os_strncmp(pos, "beacon_", 7) == 0) {
853 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
854 return 0;
855 } else {
856 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
857 return -1;
858 }
859
860 if (num >= NUM_TX_QUEUES) {
861 /* for backwards compatibility, do not trigger failure */
862 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
863 return 0;
864 }
865
866 queue = &conf->tx_queue[num];
867
868 if (os_strcmp(pos, "aifs") == 0) {
869 queue->aifs = atoi(val);
870 if (queue->aifs < 0 || queue->aifs > 255) {
871 wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
872 queue->aifs);
873 return -1;
874 }
875 } else if (os_strcmp(pos, "cwmin") == 0) {
876 queue->cwmin = atoi(val);
877 if (!valid_cw(queue->cwmin)) {
878 wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
879 queue->cwmin);
880 return -1;
881 }
882 } else if (os_strcmp(pos, "cwmax") == 0) {
883 queue->cwmax = atoi(val);
884 if (!valid_cw(queue->cwmax)) {
885 wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
886 queue->cwmax);
887 return -1;
888 }
889 } else if (os_strcmp(pos, "burst") == 0) {
890 queue->burst = hostapd_config_read_int10(val);
891 } else {
892 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
893 return -1;
894 }
895
896 return 0;
897}
898
899
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900#ifdef CONFIG_IEEE80211R
901static int add_r0kh(struct hostapd_bss_config *bss, char *value)
902{
903 struct ft_remote_r0kh *r0kh;
904 char *pos, *next;
905
906 r0kh = os_zalloc(sizeof(*r0kh));
907 if (r0kh == NULL)
908 return -1;
909
910 /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
911 pos = value;
912 next = os_strchr(pos, ' ');
913 if (next)
914 *next++ = '\0';
915 if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
916 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
917 os_free(r0kh);
918 return -1;
919 }
920
921 pos = next;
922 next = os_strchr(pos, ' ');
923 if (next)
924 *next++ = '\0';
925 if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
926 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
927 os_free(r0kh);
928 return -1;
929 }
930 r0kh->id_len = next - pos - 1;
931 os_memcpy(r0kh->id, pos, r0kh->id_len);
932
933 pos = next;
934 if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
935 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
936 os_free(r0kh);
937 return -1;
938 }
939
940 r0kh->next = bss->r0kh_list;
941 bss->r0kh_list = r0kh;
942
943 return 0;
944}
945
946
947static int add_r1kh(struct hostapd_bss_config *bss, char *value)
948{
949 struct ft_remote_r1kh *r1kh;
950 char *pos, *next;
951
952 r1kh = os_zalloc(sizeof(*r1kh));
953 if (r1kh == NULL)
954 return -1;
955
956 /* 02:01:02:03:04:05 02:01:02:03:04:05
957 * 000102030405060708090a0b0c0d0e0f */
958 pos = value;
959 next = os_strchr(pos, ' ');
960 if (next)
961 *next++ = '\0';
962 if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
963 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
964 os_free(r1kh);
965 return -1;
966 }
967
968 pos = next;
969 next = os_strchr(pos, ' ');
970 if (next)
971 *next++ = '\0';
972 if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
973 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
974 os_free(r1kh);
975 return -1;
976 }
977
978 pos = next;
979 if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
980 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
981 os_free(r1kh);
982 return -1;
983 }
984
985 r1kh->next = bss->r1kh_list;
986 bss->r1kh_list = r1kh;
987
988 return 0;
989}
990#endif /* CONFIG_IEEE80211R */
991
992
993#ifdef CONFIG_IEEE80211N
994static int hostapd_config_ht_capab(struct hostapd_config *conf,
995 const char *capab)
996{
997 if (os_strstr(capab, "[LDPC]"))
998 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
999 if (os_strstr(capab, "[HT40-]")) {
1000 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1001 conf->secondary_channel = -1;
1002 }
1003 if (os_strstr(capab, "[HT40+]")) {
1004 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1005 conf->secondary_channel = 1;
1006 }
1007 if (os_strstr(capab, "[SMPS-STATIC]")) {
1008 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1009 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
1010 }
1011 if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
1012 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
1013 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
1014 }
1015 if (os_strstr(capab, "[GF]"))
1016 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
1017 if (os_strstr(capab, "[SHORT-GI-20]"))
1018 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
1019 if (os_strstr(capab, "[SHORT-GI-40]"))
1020 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
1021 if (os_strstr(capab, "[TX-STBC]"))
1022 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
1023 if (os_strstr(capab, "[RX-STBC1]")) {
1024 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1025 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
1026 }
1027 if (os_strstr(capab, "[RX-STBC12]")) {
1028 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1029 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
1030 }
1031 if (os_strstr(capab, "[RX-STBC123]")) {
1032 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
1033 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
1034 }
1035 if (os_strstr(capab, "[DELAYED-BA]"))
1036 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
1037 if (os_strstr(capab, "[MAX-AMSDU-7935]"))
1038 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
1039 if (os_strstr(capab, "[DSSS_CCK-40]"))
1040 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
1041 if (os_strstr(capab, "[PSMP]"))
1042 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
1043 if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
1044 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
1045
1046 return 0;
1047}
1048#endif /* CONFIG_IEEE80211N */
1049
1050
Dmitry Shmidt04949592012-07-19 12:16:46 -07001051#ifdef CONFIG_IEEE80211AC
1052static int hostapd_config_vht_capab(struct hostapd_config *conf,
1053 const char *capab)
1054{
1055 if (os_strstr(capab, "[MAX-MPDU-7991]"))
1056 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
1057 if (os_strstr(capab, "[MAX-MPDU-11454]"))
1058 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
1059 if (os_strstr(capab, "[VHT160]"))
1060 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1061 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1062 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1063 if (os_strstr(capab, "[VHT160-80PLUS80]"))
1064 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1065 if (os_strstr(capab, "[RXLDPC]"))
1066 conf->vht_capab |= VHT_CAP_RXLDPC;
1067 if (os_strstr(capab, "[SHORT-GI-80]"))
1068 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
1069 if (os_strstr(capab, "[SHORT-GI-160]"))
1070 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
1071 if (os_strstr(capab, "[TX-STBC-2BY1]"))
1072 conf->vht_capab |= VHT_CAP_TXSTBC;
1073 if (os_strstr(capab, "[RX-STBC-1]"))
1074 conf->vht_capab |= VHT_CAP_RXSTBC_1;
1075 if (os_strstr(capab, "[RX-STBC-12]"))
1076 conf->vht_capab |= VHT_CAP_RXSTBC_2;
1077 if (os_strstr(capab, "[RX-STBC-123]"))
1078 conf->vht_capab |= VHT_CAP_RXSTBC_3;
1079 if (os_strstr(capab, "[RX-STBC-1234]"))
1080 conf->vht_capab |= VHT_CAP_RXSTBC_4;
1081 if (os_strstr(capab, "[SU-BEAMFORMER]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001082 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001083 if (os_strstr(capab, "[SU-BEAMFORMEE]"))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001084 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001085 if (os_strstr(capab, "[BF-ANTENNA-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001086 (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
1087 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001088 if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001089 (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
1090 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001091 if (os_strstr(capab, "[MU-BEAMFORMER]"))
1092 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
1093 if (os_strstr(capab, "[MU-BEAMFORMEE]"))
1094 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1095 if (os_strstr(capab, "[VHT-TXOP-PS]"))
1096 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
1097 if (os_strstr(capab, "[HTC-VHT]"))
1098 conf->vht_capab |= VHT_CAP_HTC_VHT;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001099 if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
1100 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
1101 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
1102 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
1103 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
1104 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
1105 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
1106 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
1107 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
1108 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
1109 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
1110 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
1111 else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
1112 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001113 if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
1114 (conf->vht_capab & VHT_CAP_HTC_VHT))
1115 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
1116 if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
1117 (conf->vht_capab & VHT_CAP_HTC_VHT))
1118 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
1119 if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
1120 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
1121 if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
1122 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
1123 return 0;
1124}
1125#endif /* CONFIG_IEEE80211AC */
1126
1127
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001128#ifdef CONFIG_INTERWORKING
1129static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
1130 int line)
1131{
1132 size_t len = os_strlen(pos);
1133 u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
1134
1135 struct hostapd_roaming_consortium *rc;
1136
1137 if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
1138 hexstr2bin(pos, oi, len / 2)) {
1139 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
1140 "'%s'", line, pos);
1141 return -1;
1142 }
1143 len /= 2;
1144
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001145 rc = os_realloc_array(bss->roaming_consortium,
1146 bss->roaming_consortium_count + 1,
1147 sizeof(struct hostapd_roaming_consortium));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001148 if (rc == NULL)
1149 return -1;
1150
1151 os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
1152 rc[bss->roaming_consortium_count].len = len;
1153
1154 bss->roaming_consortium = rc;
1155 bss->roaming_consortium_count++;
1156
1157 return 0;
1158}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001159
1160
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001161static int parse_lang_string(struct hostapd_lang_string **array,
1162 unsigned int *count, char *pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001163{
Dmitry Shmidt56052862013-10-04 10:23:25 -07001164 char *sep, *str = NULL;
1165 size_t clen, nlen, slen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001166 struct hostapd_lang_string *ls;
Dmitry Shmidt56052862013-10-04 10:23:25 -07001167 int ret = -1;
1168
1169 if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
1170 str = wpa_config_parse_string(pos, &slen);
1171 if (!str)
1172 return -1;
1173 pos = str;
1174 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001175
1176 sep = os_strchr(pos, ':');
1177 if (sep == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001178 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001179 *sep++ = '\0';
1180
1181 clen = os_strlen(pos);
Dmitry Shmidt56052862013-10-04 10:23:25 -07001182 if (clen < 2 || clen > sizeof(ls->lang))
1183 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001184 nlen = os_strlen(sep);
1185 if (nlen > 252)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001186 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001187
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001188 ls = os_realloc_array(*array, *count + 1,
1189 sizeof(struct hostapd_lang_string));
1190 if (ls == NULL)
Dmitry Shmidt56052862013-10-04 10:23:25 -07001191 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001192
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001193 *array = ls;
1194 ls = &(*array)[*count];
1195 (*count)++;
1196
1197 os_memset(ls->lang, 0, sizeof(ls->lang));
1198 os_memcpy(ls->lang, pos, clen);
1199 ls->name_len = nlen;
1200 os_memcpy(ls->name, sep, nlen);
1201
Dmitry Shmidt56052862013-10-04 10:23:25 -07001202 ret = 0;
1203fail:
1204 os_free(str);
1205 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001206}
1207
1208
1209static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
1210 int line)
1211{
1212 if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
1213 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
1214 line, pos);
1215 return -1;
1216 }
1217 return 0;
1218}
1219
1220
1221static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
1222 int line)
1223{
1224 size_t count;
1225 char *pos;
1226 u8 *info = NULL, *ipos;
1227
1228 /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
1229
1230 count = 1;
1231 for (pos = buf; *pos; pos++) {
1232 if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
1233 goto fail;
1234 if (*pos == ';')
1235 count++;
1236 }
1237 if (1 + count * 3 > 0x7f)
1238 goto fail;
1239
1240 info = os_zalloc(2 + 3 + count * 3);
1241 if (info == NULL)
1242 return -1;
1243
1244 ipos = info;
1245 *ipos++ = 0; /* GUD - Version 1 */
1246 *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
1247 *ipos++ = 0; /* PLMN List IEI */
1248 /* ext(b8) | Length of PLMN List value contents(b7..1) */
1249 *ipos++ = 1 + count * 3;
1250 *ipos++ = count; /* Number of PLMNs */
1251
1252 pos = buf;
1253 while (pos && *pos) {
1254 char *mcc, *mnc;
1255 size_t mnc_len;
1256
1257 mcc = pos;
1258 mnc = os_strchr(pos, ',');
1259 if (mnc == NULL)
1260 goto fail;
1261 *mnc++ = '\0';
1262 pos = os_strchr(mnc, ';');
1263 if (pos)
1264 *pos++ = '\0';
1265
1266 mnc_len = os_strlen(mnc);
1267 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
1268 goto fail;
1269
1270 /* BC coded MCC,MNC */
1271 /* MCC digit 2 | MCC digit 1 */
1272 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
1273 /* MNC digit 3 | MCC digit 3 */
1274 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
1275 (mcc[2] - '0');
1276 /* MNC digit 2 | MNC digit 1 */
1277 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
1278 }
1279
1280 os_free(bss->anqp_3gpp_cell_net);
1281 bss->anqp_3gpp_cell_net = info;
1282 bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
1283 wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
1284 bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001285
1286 return 0;
1287
1288fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001289 wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
1290 line, buf);
1291 os_free(info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001292 return -1;
1293}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001294
1295
1296static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
1297{
1298 struct hostapd_nai_realm_data *realm;
1299 size_t i, j, len;
1300 int *offsets;
1301 char *pos, *end, *rpos;
1302
1303 offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
1304 sizeof(int));
1305 if (offsets == NULL)
1306 return -1;
1307
1308 for (i = 0; i < bss->nai_realm_count; i++) {
1309 realm = &bss->nai_realm_data[i];
1310 for (j = 0; j < MAX_NAI_REALMS; j++) {
1311 offsets[i * MAX_NAI_REALMS + j] =
1312 realm->realm[j] ?
1313 realm->realm[j] - realm->realm_buf : -1;
1314 }
1315 }
1316
1317 realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
1318 sizeof(struct hostapd_nai_realm_data));
1319 if (realm == NULL) {
1320 os_free(offsets);
1321 return -1;
1322 }
1323 bss->nai_realm_data = realm;
1324
1325 /* patch the pointers after realloc */
1326 for (i = 0; i < bss->nai_realm_count; i++) {
1327 realm = &bss->nai_realm_data[i];
1328 for (j = 0; j < MAX_NAI_REALMS; j++) {
1329 int offs = offsets[i * MAX_NAI_REALMS + j];
1330 if (offs >= 0)
1331 realm->realm[j] = realm->realm_buf + offs;
1332 else
1333 realm->realm[j] = NULL;
1334 }
1335 }
1336 os_free(offsets);
1337
1338 realm = &bss->nai_realm_data[bss->nai_realm_count];
1339 os_memset(realm, 0, sizeof(*realm));
1340
1341 pos = buf;
1342 realm->encoding = atoi(pos);
1343 pos = os_strchr(pos, ',');
1344 if (pos == NULL)
1345 goto fail;
1346 pos++;
1347
1348 end = os_strchr(pos, ',');
1349 if (end) {
1350 len = end - pos;
1351 *end = '\0';
1352 } else {
1353 len = os_strlen(pos);
1354 }
1355
1356 if (len > MAX_NAI_REALMLEN) {
1357 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
1358 "characters)", (int) len, MAX_NAI_REALMLEN);
1359 goto fail;
1360 }
1361 os_memcpy(realm->realm_buf, pos, len);
1362
1363 if (end)
1364 pos = end + 1;
1365 else
1366 pos = NULL;
1367
1368 while (pos && *pos) {
1369 struct hostapd_nai_realm_eap *eap;
1370
1371 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
1372 wpa_printf(MSG_ERROR, "Too many EAP methods");
1373 goto fail;
1374 }
1375
1376 eap = &realm->eap_method[realm->eap_method_count];
1377 realm->eap_method_count++;
1378
1379 end = os_strchr(pos, ',');
1380 if (end == NULL)
1381 end = pos + os_strlen(pos);
1382
1383 eap->eap_method = atoi(pos);
1384 for (;;) {
1385 pos = os_strchr(pos, '[');
1386 if (pos == NULL || pos > end)
1387 break;
1388 pos++;
1389 if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
1390 wpa_printf(MSG_ERROR, "Too many auth params");
1391 goto fail;
1392 }
1393 eap->auth_id[eap->num_auths] = atoi(pos);
1394 pos = os_strchr(pos, ':');
1395 if (pos == NULL || pos > end)
1396 goto fail;
1397 pos++;
1398 eap->auth_val[eap->num_auths] = atoi(pos);
1399 pos = os_strchr(pos, ']');
1400 if (pos == NULL || pos > end)
1401 goto fail;
1402 pos++;
1403 eap->num_auths++;
1404 }
1405
1406 if (*end != ',')
1407 break;
1408
1409 pos = end + 1;
1410 }
1411
1412 /* Split realm list into null terminated realms */
1413 rpos = realm->realm_buf;
1414 i = 0;
1415 while (*rpos) {
1416 if (i >= MAX_NAI_REALMS) {
1417 wpa_printf(MSG_ERROR, "Too many realms");
1418 goto fail;
1419 }
1420 realm->realm[i++] = rpos;
1421 rpos = os_strchr(rpos, ';');
1422 if (rpos == NULL)
1423 break;
1424 *rpos++ = '\0';
1425 }
1426
1427 bss->nai_realm_count++;
1428
1429 return 0;
1430
1431fail:
1432 wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
1433 return -1;
1434}
1435
Dmitry Shmidt051af732013-10-22 13:52:46 -07001436
1437static int parse_qos_map_set(struct hostapd_bss_config *bss,
1438 char *buf, int line)
1439{
1440 u8 qos_map_set[16 + 2 * 21], count = 0;
1441 char *pos = buf;
1442 int val;
1443
1444 for (;;) {
1445 if (count == sizeof(qos_map_set)) {
1446 wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
1447 "parameters '%s'", line, buf);
1448 return -1;
1449 }
1450
1451 val = atoi(pos);
1452 if (val > 255 || val < 0) {
1453 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
1454 "'%s'", line, buf);
1455 return -1;
1456 }
1457
1458 qos_map_set[count++] = val;
1459 pos = os_strchr(pos, ',');
1460 if (!pos)
1461 break;
1462 pos++;
1463 }
1464
1465 if (count < 16 || count & 1) {
1466 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
1467 line, buf);
1468 return -1;
1469 }
1470
1471 os_memcpy(bss->qos_map_set, qos_map_set, count);
1472 bss->qos_map_set_len = count;
1473
1474 return 0;
1475}
1476
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001477#endif /* CONFIG_INTERWORKING */
1478
1479
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001480#ifdef CONFIG_HS20
1481static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
1482 int line)
1483{
1484 u8 *conn_cap;
1485 char *pos;
1486
1487 if (bss->hs20_connection_capability_len >= 0xfff0)
1488 return -1;
1489
1490 conn_cap = os_realloc(bss->hs20_connection_capability,
1491 bss->hs20_connection_capability_len + 4);
1492 if (conn_cap == NULL)
1493 return -1;
1494
1495 bss->hs20_connection_capability = conn_cap;
1496 conn_cap += bss->hs20_connection_capability_len;
1497 pos = buf;
1498 conn_cap[0] = atoi(pos);
1499 pos = os_strchr(pos, ':');
1500 if (pos == NULL)
1501 return -1;
1502 pos++;
1503 WPA_PUT_LE16(conn_cap + 1, atoi(pos));
1504 pos = os_strchr(pos, ':');
1505 if (pos == NULL)
1506 return -1;
1507 pos++;
1508 conn_cap[3] = atoi(pos);
1509 bss->hs20_connection_capability_len += 4;
1510
1511 return 0;
1512}
1513
1514
1515static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
1516 int line)
1517{
1518 u8 *wan_metrics;
1519 char *pos;
1520
1521 /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
1522
1523 wan_metrics = os_zalloc(13);
1524 if (wan_metrics == NULL)
1525 return -1;
1526
1527 pos = buf;
1528 /* WAN Info */
1529 if (hexstr2bin(pos, wan_metrics, 1) < 0)
1530 goto fail;
1531 pos += 2;
1532 if (*pos != ':')
1533 goto fail;
1534 pos++;
1535
1536 /* Downlink Speed */
1537 WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
1538 pos = os_strchr(pos, ':');
1539 if (pos == NULL)
1540 goto fail;
1541 pos++;
1542
1543 /* Uplink Speed */
1544 WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
1545 pos = os_strchr(pos, ':');
1546 if (pos == NULL)
1547 goto fail;
1548 pos++;
1549
1550 /* Downlink Load */
1551 wan_metrics[9] = atoi(pos);
1552 pos = os_strchr(pos, ':');
1553 if (pos == NULL)
1554 goto fail;
1555 pos++;
1556
1557 /* Uplink Load */
1558 wan_metrics[10] = atoi(pos);
1559 pos = os_strchr(pos, ':');
1560 if (pos == NULL)
1561 goto fail;
1562 pos++;
1563
1564 /* LMD */
1565 WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
1566
1567 os_free(bss->hs20_wan_metrics);
1568 bss->hs20_wan_metrics = wan_metrics;
1569
1570 return 0;
1571
1572fail:
1573 wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
1574 line, pos);
1575 os_free(wan_metrics);
1576 return -1;
1577}
1578
1579
1580static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
1581 char *pos, int line)
1582{
1583 if (parse_lang_string(&bss->hs20_oper_friendly_name,
1584 &bss->hs20_oper_friendly_name_count, pos)) {
1585 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1586 "hs20_oper_friendly_name '%s'", line, pos);
1587 return -1;
1588 }
1589 return 0;
1590}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001591
1592
1593static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
1594{
1595 struct hs20_icon *icon;
1596 char *end;
1597
1598 icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
1599 sizeof(struct hs20_icon));
1600 if (icon == NULL)
1601 return -1;
1602 bss->hs20_icons = icon;
1603 icon = &bss->hs20_icons[bss->hs20_icons_count];
1604 os_memset(icon, 0, sizeof(*icon));
1605
1606 icon->width = atoi(pos);
1607 pos = os_strchr(pos, ':');
1608 if (pos == NULL)
1609 return -1;
1610 pos++;
1611
1612 icon->height = atoi(pos);
1613 pos = os_strchr(pos, ':');
1614 if (pos == NULL)
1615 return -1;
1616 pos++;
1617
1618 end = os_strchr(pos, ':');
1619 if (end == NULL || end - pos > 3)
1620 return -1;
1621 os_memcpy(icon->language, pos, end - pos);
1622 pos = end + 1;
1623
1624 end = os_strchr(pos, ':');
1625 if (end == NULL || end - pos > 255)
1626 return -1;
1627 os_memcpy(icon->type, pos, end - pos);
1628 pos = end + 1;
1629
1630 end = os_strchr(pos, ':');
1631 if (end == NULL || end - pos > 255)
1632 return -1;
1633 os_memcpy(icon->name, pos, end - pos);
1634 pos = end + 1;
1635
1636 if (os_strlen(pos) > 255)
1637 return -1;
1638 os_memcpy(icon->file, pos, os_strlen(pos));
1639
1640 bss->hs20_icons_count++;
1641
1642 return 0;
1643}
1644
1645
1646static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
1647 char *pos, int line)
1648{
1649 size_t slen;
1650 char *str;
1651
1652 str = wpa_config_parse_string(pos, &slen);
1653 if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
1654 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
1655 return -1;
1656 }
1657
1658 os_memcpy(bss->osu_ssid, str, slen);
1659 bss->osu_ssid_len = slen;
1660 os_free(str);
1661
1662 return 0;
1663}
1664
1665
1666static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
1667 char *pos, int line)
1668{
1669 struct hs20_osu_provider *p;
1670
1671 p = os_realloc_array(bss->hs20_osu_providers,
1672 bss->hs20_osu_providers_count + 1, sizeof(*p));
1673 if (p == NULL)
1674 return -1;
1675
1676 bss->hs20_osu_providers = p;
1677 bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
1678 bss->hs20_osu_providers_count++;
1679 os_memset(bss->last_osu, 0, sizeof(*p));
1680 bss->last_osu->server_uri = os_strdup(pos);
1681
1682 return 0;
1683}
1684
1685
1686static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
1687 char *pos, int line)
1688{
1689 if (bss->last_osu == NULL) {
1690 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1691 return -1;
1692 }
1693
1694 if (parse_lang_string(&bss->last_osu->friendly_name,
1695 &bss->last_osu->friendly_name_count, pos)) {
1696 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
1697 line, pos);
1698 return -1;
1699 }
1700
1701 return 0;
1702}
1703
1704
1705static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
1706 char *pos, int line)
1707{
1708 if (bss->last_osu == NULL) {
1709 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1710 return -1;
1711 }
1712
1713 os_free(bss->last_osu->osu_nai);
1714 bss->last_osu->osu_nai = os_strdup(pos);
1715 if (bss->last_osu->osu_nai == NULL)
1716 return -1;
1717
1718 return 0;
1719}
1720
1721
1722static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
1723 int line)
1724{
1725 if (bss->last_osu == NULL) {
1726 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1727 return -1;
1728 }
1729
1730 if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
1731 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
1732 return -1;
1733 }
1734
1735 return 0;
1736}
1737
1738
1739static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
1740 int line)
1741{
1742 char **n;
1743 struct hs20_osu_provider *p = bss->last_osu;
1744
1745 if (p == NULL) {
1746 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1747 return -1;
1748 }
1749
1750 n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
1751 if (n == NULL)
1752 return -1;
1753 p->icons = n;
1754 p->icons[p->icons_count] = os_strdup(pos);
1755 if (p->icons[p->icons_count] == NULL)
1756 return -1;
1757 p->icons_count++;
1758
1759 return 0;
1760}
1761
1762
1763static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
1764 char *pos, int line)
1765{
1766 if (bss->last_osu == NULL) {
1767 wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
1768 return -1;
1769 }
1770
1771 if (parse_lang_string(&bss->last_osu->service_desc,
1772 &bss->last_osu->service_desc_count, pos)) {
1773 wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
1774 line, pos);
1775 return -1;
1776 }
1777
1778 return 0;
1779}
1780
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001781#endif /* CONFIG_HS20 */
1782
1783
Dmitry Shmidt04949592012-07-19 12:16:46 -07001784#ifdef CONFIG_WPS_NFC
1785static struct wpabuf * hostapd_parse_bin(const char *buf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001787 size_t len;
1788 struct wpabuf *ret;
1789
1790 len = os_strlen(buf);
1791 if (len & 0x01)
1792 return NULL;
1793 len /= 2;
1794
1795 ret = wpabuf_alloc(len);
1796 if (ret == NULL)
1797 return NULL;
1798
1799 if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
1800 wpabuf_free(ret);
1801 return NULL;
1802 }
1803
1804 return ret;
1805}
1806#endif /* CONFIG_WPS_NFC */
1807
1808
1809static int hostapd_config_fill(struct hostapd_config *conf,
1810 struct hostapd_bss_config *bss,
1811 char *buf, char *pos, int line)
1812{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001813 int errors = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001814
Dmitry Shmidt04949592012-07-19 12:16:46 -07001815 {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816 if (os_strcmp(buf, "interface") == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001817 os_strlcpy(conf->bss[0]->iface, pos,
1818 sizeof(conf->bss[0]->iface));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001819 } else if (os_strcmp(buf, "bridge") == 0) {
1820 os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001821 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
1822 os_strlcpy(bss->vlan_bridge, pos,
1823 sizeof(bss->vlan_bridge));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 } else if (os_strcmp(buf, "wds_bridge") == 0) {
1825 os_strlcpy(bss->wds_bridge, pos,
1826 sizeof(bss->wds_bridge));
1827 } else if (os_strcmp(buf, "driver") == 0) {
1828 int j;
1829 /* clear to get error below if setting is invalid */
1830 conf->driver = NULL;
1831 for (j = 0; wpa_drivers[j]; j++) {
1832 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
1833 {
1834 conf->driver = wpa_drivers[j];
1835 break;
1836 }
1837 }
1838 if (conf->driver == NULL) {
1839 wpa_printf(MSG_ERROR, "Line %d: invalid/"
1840 "unknown driver '%s'", line, pos);
1841 errors++;
1842 }
1843 } else if (os_strcmp(buf, "debug") == 0) {
1844 wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
1845 "configuration variable is not used "
1846 "anymore", line);
1847 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
1848 bss->logger_syslog_level = atoi(pos);
1849 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
1850 bss->logger_stdout_level = atoi(pos);
1851 } else if (os_strcmp(buf, "logger_syslog") == 0) {
1852 bss->logger_syslog = atoi(pos);
1853 } else if (os_strcmp(buf, "logger_stdout") == 0) {
1854 bss->logger_stdout = atoi(pos);
1855 } else if (os_strcmp(buf, "dump_file") == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001856 wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
1857 line);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 } else if (os_strcmp(buf, "ssid") == 0) {
1859 bss->ssid.ssid_len = os_strlen(pos);
1860 if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
1861 bss->ssid.ssid_len < 1) {
1862 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1863 "'%s'", line, pos);
1864 errors++;
1865 } else {
1866 os_memcpy(bss->ssid.ssid, pos,
1867 bss->ssid.ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 bss->ssid.ssid_set = 1;
1869 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001870 } else if (os_strcmp(buf, "ssid2") == 0) {
1871 size_t slen;
1872 char *str = wpa_config_parse_string(pos, &slen);
1873 if (str == NULL || slen < 1 ||
1874 slen > HOSTAPD_MAX_SSID_LEN) {
1875 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
1876 "'%s'", line, pos);
1877 errors++;
1878 } else {
1879 os_memcpy(bss->ssid.ssid, str, slen);
1880 bss->ssid.ssid_len = slen;
1881 bss->ssid.ssid_set = 1;
1882 }
1883 os_free(str);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001884 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
1885 bss->ssid.utf8_ssid = atoi(pos) > 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
1887 bss->macaddr_acl = atoi(pos);
1888 if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
1889 bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
1890 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1891 wpa_printf(MSG_ERROR, "Line %d: unknown "
1892 "macaddr_acl %d",
1893 line, bss->macaddr_acl);
1894 }
1895 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
1896 if (hostapd_config_read_maclist(pos, &bss->accept_mac,
1897 &bss->num_accept_mac))
1898 {
1899 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1900 "read accept_mac_file '%s'",
1901 line, pos);
1902 errors++;
1903 }
1904 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
1905 if (hostapd_config_read_maclist(pos, &bss->deny_mac,
1906 &bss->num_deny_mac)) {
1907 wpa_printf(MSG_ERROR, "Line %d: Failed to "
1908 "read deny_mac_file '%s'",
1909 line, pos);
1910 errors++;
1911 }
1912 } else if (os_strcmp(buf, "wds_sta") == 0) {
1913 bss->wds_sta = atoi(pos);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001914 } else if (os_strcmp(buf, "start_disabled") == 0) {
1915 bss->start_disabled = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001916 } else if (os_strcmp(buf, "ap_isolate") == 0) {
1917 bss->isolate = atoi(pos);
1918 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
1919 bss->ap_max_inactivity = atoi(pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001920 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
1921 bss->skip_inactivity_poll = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922 } else if (os_strcmp(buf, "country_code") == 0) {
1923 os_memcpy(conf->country, pos, 2);
1924 /* FIX: make this configurable */
1925 conf->country[2] = ' ';
1926 } else if (os_strcmp(buf, "ieee80211d") == 0) {
1927 conf->ieee80211d = atoi(pos);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07001928 } else if (os_strcmp(buf, "ieee80211h") == 0) {
1929 conf->ieee80211h = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930 } else if (os_strcmp(buf, "ieee8021x") == 0) {
1931 bss->ieee802_1x = atoi(pos);
1932 } else if (os_strcmp(buf, "eapol_version") == 0) {
1933 bss->eapol_version = atoi(pos);
1934 if (bss->eapol_version < 1 ||
1935 bss->eapol_version > 2) {
1936 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
1937 "version (%d): '%s'.",
1938 line, bss->eapol_version, pos);
1939 errors++;
1940 } else
1941 wpa_printf(MSG_DEBUG, "eapol_version=%d",
1942 bss->eapol_version);
1943#ifdef EAP_SERVER
1944 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
1945 bss->eap_server = atoi(pos);
1946 wpa_printf(MSG_ERROR, "Line %d: obsolete "
1947 "eap_authenticator used; this has been "
1948 "renamed to eap_server", line);
1949 } else if (os_strcmp(buf, "eap_server") == 0) {
1950 bss->eap_server = atoi(pos);
1951 } else if (os_strcmp(buf, "eap_user_file") == 0) {
1952 if (hostapd_config_read_eap_user(pos, bss))
1953 errors++;
1954 } else if (os_strcmp(buf, "ca_cert") == 0) {
1955 os_free(bss->ca_cert);
1956 bss->ca_cert = os_strdup(pos);
1957 } else if (os_strcmp(buf, "server_cert") == 0) {
1958 os_free(bss->server_cert);
1959 bss->server_cert = os_strdup(pos);
1960 } else if (os_strcmp(buf, "private_key") == 0) {
1961 os_free(bss->private_key);
1962 bss->private_key = os_strdup(pos);
1963 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
1964 os_free(bss->private_key_passwd);
1965 bss->private_key_passwd = os_strdup(pos);
1966 } else if (os_strcmp(buf, "check_crl") == 0) {
1967 bss->check_crl = atoi(pos);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001968 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
1969 os_free(bss->ocsp_stapling_response);
1970 bss->ocsp_stapling_response = os_strdup(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 } else if (os_strcmp(buf, "dh_file") == 0) {
1972 os_free(bss->dh_file);
1973 bss->dh_file = os_strdup(pos);
1974 } else if (os_strcmp(buf, "fragment_size") == 0) {
1975 bss->fragment_size = atoi(pos);
1976#ifdef EAP_SERVER_FAST
1977 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
1978 os_free(bss->pac_opaque_encr_key);
1979 bss->pac_opaque_encr_key = os_malloc(16);
1980 if (bss->pac_opaque_encr_key == NULL) {
1981 wpa_printf(MSG_ERROR, "Line %d: No memory for "
1982 "pac_opaque_encr_key", line);
1983 errors++;
1984 } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
1985 16)) {
1986 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1987 "pac_opaque_encr_key", line);
1988 errors++;
1989 }
1990 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
1991 size_t idlen = os_strlen(pos);
1992 if (idlen & 1) {
1993 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1994 "eap_fast_a_id", line);
1995 errors++;
1996 } else {
1997 os_free(bss->eap_fast_a_id);
1998 bss->eap_fast_a_id = os_malloc(idlen / 2);
1999 if (bss->eap_fast_a_id == NULL ||
2000 hexstr2bin(pos, bss->eap_fast_a_id,
2001 idlen / 2)) {
2002 wpa_printf(MSG_ERROR, "Line %d: "
2003 "Failed to parse "
2004 "eap_fast_a_id", line);
2005 errors++;
2006 } else
2007 bss->eap_fast_a_id_len = idlen / 2;
2008 }
2009 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
2010 os_free(bss->eap_fast_a_id_info);
2011 bss->eap_fast_a_id_info = os_strdup(pos);
2012 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
2013 bss->eap_fast_prov = atoi(pos);
2014 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
2015 bss->pac_key_lifetime = atoi(pos);
2016 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
2017 bss->pac_key_refresh_time = atoi(pos);
2018#endif /* EAP_SERVER_FAST */
2019#ifdef EAP_SERVER_SIM
2020 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
2021 os_free(bss->eap_sim_db);
2022 bss->eap_sim_db = os_strdup(pos);
2023 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
2024 bss->eap_sim_aka_result_ind = atoi(pos);
2025#endif /* EAP_SERVER_SIM */
2026#ifdef EAP_SERVER_TNC
2027 } else if (os_strcmp(buf, "tnc") == 0) {
2028 bss->tnc = atoi(pos);
2029#endif /* EAP_SERVER_TNC */
2030#ifdef EAP_SERVER_PWD
2031 } else if (os_strcmp(buf, "pwd_group") == 0) {
2032 bss->pwd_group = atoi(pos);
2033#endif /* EAP_SERVER_PWD */
2034#endif /* EAP_SERVER */
2035 } else if (os_strcmp(buf, "eap_message") == 0) {
2036 char *term;
2037 bss->eap_req_id_text = os_strdup(pos);
2038 if (bss->eap_req_id_text == NULL) {
2039 wpa_printf(MSG_ERROR, "Line %d: Failed to "
2040 "allocate memory for "
2041 "eap_req_id_text", line);
2042 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002043 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 }
2045 bss->eap_req_id_text_len =
2046 os_strlen(bss->eap_req_id_text);
2047 term = os_strstr(bss->eap_req_id_text, "\\0");
2048 if (term) {
2049 *term++ = '\0';
2050 os_memmove(term, term + 1,
2051 bss->eap_req_id_text_len -
2052 (term - bss->eap_req_id_text) - 1);
2053 bss->eap_req_id_text_len--;
2054 }
2055 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
2056 bss->default_wep_key_len = atoi(pos);
2057 if (bss->default_wep_key_len > 13) {
2058 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2059 "key len %lu (= %lu bits)", line,
2060 (unsigned long)
2061 bss->default_wep_key_len,
2062 (unsigned long)
2063 bss->default_wep_key_len * 8);
2064 errors++;
2065 }
2066 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
2067 bss->individual_wep_key_len = atoi(pos);
2068 if (bss->individual_wep_key_len < 0 ||
2069 bss->individual_wep_key_len > 13) {
2070 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2071 "key len %d (= %d bits)", line,
2072 bss->individual_wep_key_len,
2073 bss->individual_wep_key_len * 8);
2074 errors++;
2075 }
2076 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
2077 bss->wep_rekeying_period = atoi(pos);
2078 if (bss->wep_rekeying_period < 0) {
2079 wpa_printf(MSG_ERROR, "Line %d: invalid "
2080 "period %d",
2081 line, bss->wep_rekeying_period);
2082 errors++;
2083 }
2084 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
2085 bss->eap_reauth_period = atoi(pos);
2086 if (bss->eap_reauth_period < 0) {
2087 wpa_printf(MSG_ERROR, "Line %d: invalid "
2088 "period %d",
2089 line, bss->eap_reauth_period);
2090 errors++;
2091 }
2092 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
2093 bss->eapol_key_index_workaround = atoi(pos);
2094#ifdef CONFIG_IAPP
2095 } else if (os_strcmp(buf, "iapp_interface") == 0) {
2096 bss->ieee802_11f = 1;
2097 os_strlcpy(bss->iapp_iface, pos,
2098 sizeof(bss->iapp_iface));
2099#endif /* CONFIG_IAPP */
2100 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
2101 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
2102 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2103 "address '%s'", line, pos);
2104 errors++;
2105 }
2106 } else if (os_strcmp(buf, "nas_identifier") == 0) {
2107 bss->nas_identifier = os_strdup(pos);
2108#ifndef CONFIG_NO_RADIUS
2109 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
2110 if (hostapd_config_read_radius_addr(
2111 &bss->radius->auth_servers,
2112 &bss->radius->num_auth_servers, pos, 1812,
2113 &bss->radius->auth_server)) {
2114 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2115 "address '%s'", line, pos);
2116 errors++;
2117 }
2118 } else if (bss->radius->auth_server &&
2119 os_strcmp(buf, "auth_server_port") == 0) {
2120 bss->radius->auth_server->port = atoi(pos);
2121 } else if (bss->radius->auth_server &&
2122 os_strcmp(buf, "auth_server_shared_secret") == 0) {
2123 int len = os_strlen(pos);
2124 if (len == 0) {
2125 /* RFC 2865, Ch. 3 */
2126 wpa_printf(MSG_ERROR, "Line %d: empty shared "
2127 "secret is not allowed.", line);
2128 errors++;
2129 }
2130 bss->radius->auth_server->shared_secret =
2131 (u8 *) os_strdup(pos);
2132 bss->radius->auth_server->shared_secret_len = len;
2133 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
2134 if (hostapd_config_read_radius_addr(
2135 &bss->radius->acct_servers,
2136 &bss->radius->num_acct_servers, pos, 1813,
2137 &bss->radius->acct_server)) {
2138 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
2139 "address '%s'", line, pos);
2140 errors++;
2141 }
2142 } else if (bss->radius->acct_server &&
2143 os_strcmp(buf, "acct_server_port") == 0) {
2144 bss->radius->acct_server->port = atoi(pos);
2145 } else if (bss->radius->acct_server &&
2146 os_strcmp(buf, "acct_server_shared_secret") == 0) {
2147 int len = os_strlen(pos);
2148 if (len == 0) {
2149 /* RFC 2865, Ch. 3 */
2150 wpa_printf(MSG_ERROR, "Line %d: empty shared "
2151 "secret is not allowed.", line);
2152 errors++;
2153 }
2154 bss->radius->acct_server->shared_secret =
2155 (u8 *) os_strdup(pos);
2156 bss->radius->acct_server->shared_secret_len = len;
2157 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
2158 0) {
2159 bss->radius->retry_primary_interval = atoi(pos);
2160 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
2161 {
2162 bss->acct_interim_interval = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002163 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
2164 bss->radius_request_cui = atoi(pos);
2165 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
2166 struct hostapd_radius_attr *attr, *a;
2167 attr = hostapd_parse_radius_attr(pos);
2168 if (attr == NULL) {
2169 wpa_printf(MSG_ERROR, "Line %d: invalid "
2170 "radius_auth_req_attr", line);
2171 errors++;
2172 } else if (bss->radius_auth_req_attr == NULL) {
2173 bss->radius_auth_req_attr = attr;
2174 } else {
2175 a = bss->radius_auth_req_attr;
2176 while (a->next)
2177 a = a->next;
2178 a->next = attr;
2179 }
2180 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
2181 struct hostapd_radius_attr *attr, *a;
2182 attr = hostapd_parse_radius_attr(pos);
2183 if (attr == NULL) {
2184 wpa_printf(MSG_ERROR, "Line %d: invalid "
2185 "radius_acct_req_attr", line);
2186 errors++;
2187 } else if (bss->radius_acct_req_attr == NULL) {
2188 bss->radius_acct_req_attr = attr;
2189 } else {
2190 a = bss->radius_acct_req_attr;
2191 while (a->next)
2192 a = a->next;
2193 a->next = attr;
2194 }
2195 } else if (os_strcmp(buf, "radius_das_port") == 0) {
2196 bss->radius_das_port = atoi(pos);
2197 } else if (os_strcmp(buf, "radius_das_client") == 0) {
2198 if (hostapd_parse_das_client(bss, pos) < 0) {
2199 wpa_printf(MSG_ERROR, "Line %d: invalid "
2200 "DAS client", line);
2201 errors++;
2202 }
2203 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
2204 bss->radius_das_time_window = atoi(pos);
2205 } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
2206 == 0) {
2207 bss->radius_das_require_event_timestamp = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002208#endif /* CONFIG_NO_RADIUS */
2209 } else if (os_strcmp(buf, "auth_algs") == 0) {
2210 bss->auth_algs = atoi(pos);
2211 if (bss->auth_algs == 0) {
2212 wpa_printf(MSG_ERROR, "Line %d: no "
2213 "authentication algorithms allowed",
2214 line);
2215 errors++;
2216 }
2217 } else if (os_strcmp(buf, "max_num_sta") == 0) {
2218 bss->max_num_sta = atoi(pos);
2219 if (bss->max_num_sta < 0 ||
2220 bss->max_num_sta > MAX_STA_COUNT) {
2221 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2222 "max_num_sta=%d; allowed range "
2223 "0..%d", line, bss->max_num_sta,
2224 MAX_STA_COUNT);
2225 errors++;
2226 }
2227 } else if (os_strcmp(buf, "wpa") == 0) {
2228 bss->wpa = atoi(pos);
2229 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
2230 bss->wpa_group_rekey = atoi(pos);
2231 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
2232 bss->wpa_strict_rekey = atoi(pos);
2233 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
2234 bss->wpa_gmk_rekey = atoi(pos);
2235 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
2236 bss->wpa_ptk_rekey = atoi(pos);
2237 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
2238 int len = os_strlen(pos);
2239 if (len < 8 || len > 63) {
2240 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
2241 "passphrase length %d (expected "
2242 "8..63)", line, len);
2243 errors++;
2244 } else {
2245 os_free(bss->ssid.wpa_passphrase);
2246 bss->ssid.wpa_passphrase = os_strdup(pos);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002247 if (bss->ssid.wpa_passphrase) {
2248 os_free(bss->ssid.wpa_psk);
2249 bss->ssid.wpa_psk = NULL;
2250 bss->ssid.wpa_passphrase_set = 1;
2251 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002252 }
2253 } else if (os_strcmp(buf, "wpa_psk") == 0) {
2254 os_free(bss->ssid.wpa_psk);
2255 bss->ssid.wpa_psk =
2256 os_zalloc(sizeof(struct hostapd_wpa_psk));
2257 if (bss->ssid.wpa_psk == NULL)
2258 errors++;
2259 else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
2260 PMK_LEN) ||
2261 pos[PMK_LEN * 2] != '\0') {
2262 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
2263 "'%s'.", line, pos);
2264 errors++;
2265 } else {
2266 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002267 os_free(bss->ssid.wpa_passphrase);
2268 bss->ssid.wpa_passphrase = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002269 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 }
2271 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
2272 os_free(bss->ssid.wpa_psk_file);
2273 bss->ssid.wpa_psk_file = os_strdup(pos);
2274 if (!bss->ssid.wpa_psk_file) {
2275 wpa_printf(MSG_ERROR, "Line %d: allocation "
2276 "failed", line);
2277 errors++;
2278 }
2279 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
2280 bss->wpa_key_mgmt =
2281 hostapd_config_parse_key_mgmt(line, pos);
2282 if (bss->wpa_key_mgmt == -1)
2283 errors++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002284 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
2285 bss->wpa_psk_radius = atoi(pos);
2286 if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
2287 bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
2288 bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
2289 wpa_printf(MSG_ERROR, "Line %d: unknown "
2290 "wpa_psk_radius %d",
2291 line, bss->wpa_psk_radius);
2292 errors++;
2293 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
2295 bss->wpa_pairwise =
2296 hostapd_config_parse_cipher(line, pos);
2297 if (bss->wpa_pairwise == -1 ||
2298 bss->wpa_pairwise == 0)
2299 errors++;
2300 else if (bss->wpa_pairwise &
2301 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2302 WPA_CIPHER_WEP104)) {
2303 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2304 "pairwise cipher suite '%s'",
2305 bss->wpa_pairwise, pos);
2306 errors++;
2307 }
2308 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
2309 bss->rsn_pairwise =
2310 hostapd_config_parse_cipher(line, pos);
2311 if (bss->rsn_pairwise == -1 ||
2312 bss->rsn_pairwise == 0)
2313 errors++;
2314 else if (bss->rsn_pairwise &
2315 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
2316 WPA_CIPHER_WEP104)) {
2317 wpa_printf(MSG_ERROR, "Line %d: unsupported "
2318 "pairwise cipher suite '%s'",
2319 bss->rsn_pairwise, pos);
2320 errors++;
2321 }
2322#ifdef CONFIG_RSN_PREAUTH
2323 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
2324 bss->rsn_preauth = atoi(pos);
2325 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
2326 bss->rsn_preauth_interfaces = os_strdup(pos);
2327#endif /* CONFIG_RSN_PREAUTH */
2328#ifdef CONFIG_PEERKEY
2329 } else if (os_strcmp(buf, "peerkey") == 0) {
2330 bss->peerkey = atoi(pos);
2331#endif /* CONFIG_PEERKEY */
2332#ifdef CONFIG_IEEE80211R
2333 } else if (os_strcmp(buf, "mobility_domain") == 0) {
2334 if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
2335 hexstr2bin(pos, bss->mobility_domain,
2336 MOBILITY_DOMAIN_ID_LEN) != 0) {
2337 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2338 "mobility_domain '%s'", line, pos);
2339 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002340 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 }
2342 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
2343 if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
2344 hexstr2bin(pos, bss->r1_key_holder,
2345 FT_R1KH_ID_LEN) != 0) {
2346 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2347 "r1_key_holder '%s'", line, pos);
2348 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002349 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350 }
2351 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
2352 bss->r0_key_lifetime = atoi(pos);
2353 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
2354 bss->reassociation_deadline = atoi(pos);
2355 } else if (os_strcmp(buf, "r0kh") == 0) {
2356 if (add_r0kh(bss, pos) < 0) {
2357 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2358 "r0kh '%s'", line, pos);
2359 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002360 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002361 }
2362 } else if (os_strcmp(buf, "r1kh") == 0) {
2363 if (add_r1kh(bss, pos) < 0) {
2364 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
2365 "r1kh '%s'", line, pos);
2366 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002367 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368 }
2369 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
2370 bss->pmk_r1_push = atoi(pos);
2371 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
2372 bss->ft_over_ds = atoi(pos);
2373#endif /* CONFIG_IEEE80211R */
2374#ifndef CONFIG_NO_CTRL_IFACE
2375 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
2376 os_free(bss->ctrl_interface);
2377 bss->ctrl_interface = os_strdup(pos);
2378 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
2379#ifndef CONFIG_NATIVE_WINDOWS
2380 struct group *grp;
2381 char *endp;
2382 const char *group = pos;
2383
2384 grp = getgrnam(group);
2385 if (grp) {
2386 bss->ctrl_interface_gid = grp->gr_gid;
2387 bss->ctrl_interface_gid_set = 1;
2388 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
2389 " (from group name '%s')",
2390 bss->ctrl_interface_gid, group);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002391 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002392 }
2393
2394 /* Group name not found - try to parse this as gid */
2395 bss->ctrl_interface_gid = strtol(group, &endp, 10);
2396 if (*group == '\0' || *endp != '\0') {
2397 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
2398 "'%s'", line, group);
2399 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002400 return errors;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401 }
2402 bss->ctrl_interface_gid_set = 1;
2403 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
2404 bss->ctrl_interface_gid);
2405#endif /* CONFIG_NATIVE_WINDOWS */
2406#endif /* CONFIG_NO_CTRL_IFACE */
2407#ifdef RADIUS_SERVER
2408 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
2409 os_free(bss->radius_server_clients);
2410 bss->radius_server_clients = os_strdup(pos);
2411 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
2412 bss->radius_server_auth_port = atoi(pos);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002413 } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
2414 bss->radius_server_acct_port = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
2416 bss->radius_server_ipv6 = atoi(pos);
2417#endif /* RADIUS_SERVER */
2418 } else if (os_strcmp(buf, "test_socket") == 0) {
2419 os_free(bss->test_socket);
2420 bss->test_socket = os_strdup(pos);
2421 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
2422 bss->use_pae_group_addr = atoi(pos);
2423 } else if (os_strcmp(buf, "hw_mode") == 0) {
2424 if (os_strcmp(pos, "a") == 0)
2425 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
2426 else if (os_strcmp(pos, "b") == 0)
2427 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
2428 else if (os_strcmp(pos, "g") == 0)
2429 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002430 else if (os_strcmp(pos, "ad") == 0)
2431 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002432 else {
2433 wpa_printf(MSG_ERROR, "Line %d: unknown "
2434 "hw_mode '%s'", line, pos);
2435 errors++;
2436 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002437 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
2438 if (os_strcmp(pos, "a") == 0)
2439 bss->wps_rf_bands = WPS_RF_50GHZ;
2440 else if (os_strcmp(pos, "g") == 0 ||
2441 os_strcmp(pos, "b") == 0)
2442 bss->wps_rf_bands = WPS_RF_24GHZ;
2443 else if (os_strcmp(pos, "ag") == 0 ||
2444 os_strcmp(pos, "ga") == 0)
2445 bss->wps_rf_bands =
2446 WPS_RF_24GHZ | WPS_RF_50GHZ;
2447 else {
2448 wpa_printf(MSG_ERROR, "Line %d: unknown "
2449 "wps_rf_band '%s'", line, pos);
2450 errors++;
2451 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002452 } else if (os_strcmp(buf, "channel") == 0) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002453 if (os_strcmp(pos, "acs_survey") == 0) {
2454#ifndef CONFIG_ACS
2455 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
2456 line);
2457 errors++;
2458#endif /* CONFIG_ACS */
2459 conf->channel = 0;
2460 } else
2461 conf->channel = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002462 } else if (os_strcmp(buf, "beacon_int") == 0) {
2463 int val = atoi(pos);
2464 /* MIB defines range as 1..65535, but very small values
2465 * cause problems with the current implementation.
2466 * Since it is unlikely that this small numbers are
2467 * useful in real life scenarios, do not allow beacon
2468 * period to be set below 15 TU. */
2469 if (val < 15 || val > 65535) {
2470 wpa_printf(MSG_ERROR, "Line %d: invalid "
2471 "beacon_int %d (expected "
2472 "15..65535)", line, val);
2473 errors++;
2474 } else
2475 conf->beacon_int = val;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002476#ifdef CONFIG_ACS
2477 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
2478 int val = atoi(pos);
2479 if (val <= 0 || val > 100) {
2480 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
2481 line, val);
2482 errors++;
2483 } else
2484 conf->acs_num_scans = val;
2485#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002486 } else if (os_strcmp(buf, "dtim_period") == 0) {
2487 bss->dtim_period = atoi(pos);
2488 if (bss->dtim_period < 1 || bss->dtim_period > 255) {
2489 wpa_printf(MSG_ERROR, "Line %d: invalid "
2490 "dtim_period %d",
2491 line, bss->dtim_period);
2492 errors++;
2493 }
2494 } else if (os_strcmp(buf, "rts_threshold") == 0) {
2495 conf->rts_threshold = atoi(pos);
2496 if (conf->rts_threshold < 0 ||
2497 conf->rts_threshold > 2347) {
2498 wpa_printf(MSG_ERROR, "Line %d: invalid "
2499 "rts_threshold %d",
2500 line, conf->rts_threshold);
2501 errors++;
2502 }
2503 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
2504 conf->fragm_threshold = atoi(pos);
2505 if (conf->fragm_threshold < 256 ||
2506 conf->fragm_threshold > 2346) {
2507 wpa_printf(MSG_ERROR, "Line %d: invalid "
2508 "fragm_threshold %d",
2509 line, conf->fragm_threshold);
2510 errors++;
2511 }
2512 } else if (os_strcmp(buf, "send_probe_response") == 0) {
2513 int val = atoi(pos);
2514 if (val != 0 && val != 1) {
2515 wpa_printf(MSG_ERROR, "Line %d: invalid "
2516 "send_probe_response %d (expected "
2517 "0 or 1)", line, val);
2518 } else
2519 conf->send_probe_response = val;
2520 } else if (os_strcmp(buf, "supported_rates") == 0) {
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002521 if (hostapd_parse_intlist(&conf->supported_rates, pos))
2522 {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2524 "list", line);
2525 errors++;
2526 }
2527 } else if (os_strcmp(buf, "basic_rates") == 0) {
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002528 if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002529 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
2530 "list", line);
2531 errors++;
2532 }
2533 } else if (os_strcmp(buf, "preamble") == 0) {
2534 if (atoi(pos))
2535 conf->preamble = SHORT_PREAMBLE;
2536 else
2537 conf->preamble = LONG_PREAMBLE;
2538 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
2539 bss->ignore_broadcast_ssid = atoi(pos);
2540 } else if (os_strcmp(buf, "wep_default_key") == 0) {
2541 bss->ssid.wep.idx = atoi(pos);
2542 if (bss->ssid.wep.idx > 3) {
2543 wpa_printf(MSG_ERROR, "Invalid "
2544 "wep_default_key index %d",
2545 bss->ssid.wep.idx);
2546 errors++;
2547 }
2548 } else if (os_strcmp(buf, "wep_key0") == 0 ||
2549 os_strcmp(buf, "wep_key1") == 0 ||
2550 os_strcmp(buf, "wep_key2") == 0 ||
2551 os_strcmp(buf, "wep_key3") == 0) {
2552 if (hostapd_config_read_wep(&bss->ssid.wep,
2553 buf[7] - '0', pos)) {
2554 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
2555 "key '%s'", line, buf);
2556 errors++;
2557 }
2558#ifndef CONFIG_NO_VLAN
2559 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
2560 bss->ssid.dynamic_vlan = atoi(pos);
2561 } else if (os_strcmp(buf, "vlan_file") == 0) {
2562 if (hostapd_config_read_vlan_file(bss, pos)) {
2563 wpa_printf(MSG_ERROR, "Line %d: failed to "
2564 "read VLAN file '%s'", line, pos);
2565 errors++;
2566 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002567 } else if (os_strcmp(buf, "vlan_naming") == 0) {
2568 bss->ssid.vlan_naming = atoi(pos);
2569 if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
2570 bss->ssid.vlan_naming < 0) {
2571 wpa_printf(MSG_ERROR, "Line %d: invalid "
2572 "naming scheme %d", line,
2573 bss->ssid.vlan_naming);
2574 errors++;
2575 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576#ifdef CONFIG_FULL_DYNAMIC_VLAN
2577 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
2578 bss->ssid.vlan_tagged_interface = os_strdup(pos);
2579#endif /* CONFIG_FULL_DYNAMIC_VLAN */
2580#endif /* CONFIG_NO_VLAN */
2581 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
2582 conf->ap_table_max_size = atoi(pos);
2583 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
2584 conf->ap_table_expiration_time = atoi(pos);
2585 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
2586 if (hostapd_config_tx_queue(conf, buf, pos)) {
2587 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
2588 "queue item", line);
2589 errors++;
2590 }
2591 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
2592 os_strcmp(buf, "wmm_enabled") == 0) {
2593 bss->wmm_enabled = atoi(pos);
2594 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
2595 bss->wmm_uapsd = atoi(pos);
2596 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
2597 os_strncmp(buf, "wmm_ac_", 7) == 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002598 if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
2599 pos)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002600 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
2601 "ac item", line);
2602 errors++;
2603 }
2604 } else if (os_strcmp(buf, "bss") == 0) {
2605 if (hostapd_config_bss(conf, pos)) {
2606 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
2607 "item", line);
2608 errors++;
2609 }
2610 } else if (os_strcmp(buf, "bssid") == 0) {
2611 if (hwaddr_aton(pos, bss->bssid)) {
2612 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
2613 "item", line);
2614 errors++;
2615 }
2616#ifdef CONFIG_IEEE80211W
2617 } else if (os_strcmp(buf, "ieee80211w") == 0) {
2618 bss->ieee80211w = atoi(pos);
2619 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
2620 bss->assoc_sa_query_max_timeout = atoi(pos);
2621 if (bss->assoc_sa_query_max_timeout == 0) {
2622 wpa_printf(MSG_ERROR, "Line %d: invalid "
2623 "assoc_sa_query_max_timeout", line);
2624 errors++;
2625 }
2626 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
2627 {
2628 bss->assoc_sa_query_retry_timeout = atoi(pos);
2629 if (bss->assoc_sa_query_retry_timeout == 0) {
2630 wpa_printf(MSG_ERROR, "Line %d: invalid "
2631 "assoc_sa_query_retry_timeout",
2632 line);
2633 errors++;
2634 }
2635#endif /* CONFIG_IEEE80211W */
2636#ifdef CONFIG_IEEE80211N
2637 } else if (os_strcmp(buf, "ieee80211n") == 0) {
2638 conf->ieee80211n = atoi(pos);
2639 } else if (os_strcmp(buf, "ht_capab") == 0) {
2640 if (hostapd_config_ht_capab(conf, pos) < 0) {
2641 wpa_printf(MSG_ERROR, "Line %d: invalid "
2642 "ht_capab", line);
2643 errors++;
2644 }
2645 } else if (os_strcmp(buf, "require_ht") == 0) {
2646 conf->require_ht = atoi(pos);
Dmitry Shmidt54605472013-11-08 11:10:19 -08002647 } else if (os_strcmp(buf, "obss_interval") == 0) {
2648 conf->obss_interval = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002649#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002650#ifdef CONFIG_IEEE80211AC
2651 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
2652 conf->ieee80211ac = atoi(pos);
2653 } else if (os_strcmp(buf, "vht_capab") == 0) {
2654 if (hostapd_config_vht_capab(conf, pos) < 0) {
2655 wpa_printf(MSG_ERROR, "Line %d: invalid "
2656 "vht_capab", line);
2657 errors++;
2658 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002659 } else if (os_strcmp(buf, "require_vht") == 0) {
2660 conf->require_vht = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002661 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002662 conf->vht_oper_chwidth = atoi(pos);
2663 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
2664 {
2665 conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002666 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
2667 {
2668 conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002669#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
2671 bss->max_listen_interval = atoi(pos);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07002672 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
2673 bss->disable_pmksa_caching = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 } else if (os_strcmp(buf, "okc") == 0) {
2675 bss->okc = atoi(pos);
2676#ifdef CONFIG_WPS
2677 } else if (os_strcmp(buf, "wps_state") == 0) {
2678 bss->wps_state = atoi(pos);
2679 if (bss->wps_state < 0 || bss->wps_state > 2) {
2680 wpa_printf(MSG_ERROR, "Line %d: invalid "
2681 "wps_state", line);
2682 errors++;
2683 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002684 } else if (os_strcmp(buf, "wps_independent") == 0) {
2685 bss->wps_independent = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
2687 bss->ap_setup_locked = atoi(pos);
2688 } else if (os_strcmp(buf, "uuid") == 0) {
2689 if (uuid_str2bin(pos, bss->uuid)) {
2690 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
2691 line);
2692 errors++;
2693 }
2694 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
2695 os_free(bss->wps_pin_requests);
2696 bss->wps_pin_requests = os_strdup(pos);
2697 } else if (os_strcmp(buf, "device_name") == 0) {
2698 if (os_strlen(pos) > 32) {
2699 wpa_printf(MSG_ERROR, "Line %d: Too long "
2700 "device_name", line);
2701 errors++;
2702 }
2703 os_free(bss->device_name);
2704 bss->device_name = os_strdup(pos);
2705 } else if (os_strcmp(buf, "manufacturer") == 0) {
2706 if (os_strlen(pos) > 64) {
2707 wpa_printf(MSG_ERROR, "Line %d: Too long "
2708 "manufacturer", line);
2709 errors++;
2710 }
2711 os_free(bss->manufacturer);
2712 bss->manufacturer = os_strdup(pos);
2713 } else if (os_strcmp(buf, "model_name") == 0) {
2714 if (os_strlen(pos) > 32) {
2715 wpa_printf(MSG_ERROR, "Line %d: Too long "
2716 "model_name", line);
2717 errors++;
2718 }
2719 os_free(bss->model_name);
2720 bss->model_name = os_strdup(pos);
2721 } else if (os_strcmp(buf, "model_number") == 0) {
2722 if (os_strlen(pos) > 32) {
2723 wpa_printf(MSG_ERROR, "Line %d: Too long "
2724 "model_number", line);
2725 errors++;
2726 }
2727 os_free(bss->model_number);
2728 bss->model_number = os_strdup(pos);
2729 } else if (os_strcmp(buf, "serial_number") == 0) {
2730 if (os_strlen(pos) > 32) {
2731 wpa_printf(MSG_ERROR, "Line %d: Too long "
2732 "serial_number", line);
2733 errors++;
2734 }
2735 os_free(bss->serial_number);
2736 bss->serial_number = os_strdup(pos);
2737 } else if (os_strcmp(buf, "device_type") == 0) {
2738 if (wps_dev_type_str2bin(pos, bss->device_type))
2739 errors++;
2740 } else if (os_strcmp(buf, "config_methods") == 0) {
2741 os_free(bss->config_methods);
2742 bss->config_methods = os_strdup(pos);
2743 } else if (os_strcmp(buf, "os_version") == 0) {
2744 if (hexstr2bin(pos, bss->os_version, 4)) {
2745 wpa_printf(MSG_ERROR, "Line %d: invalid "
2746 "os_version", line);
2747 errors++;
2748 }
2749 } else if (os_strcmp(buf, "ap_pin") == 0) {
2750 os_free(bss->ap_pin);
2751 bss->ap_pin = os_strdup(pos);
2752 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
2753 bss->skip_cred_build = atoi(pos);
2754 } else if (os_strcmp(buf, "extra_cred") == 0) {
2755 os_free(bss->extra_cred);
2756 bss->extra_cred =
2757 (u8 *) os_readfile(pos, &bss->extra_cred_len);
2758 if (bss->extra_cred == NULL) {
2759 wpa_printf(MSG_ERROR, "Line %d: could not "
2760 "read Credentials from '%s'",
2761 line, pos);
2762 errors++;
2763 }
2764 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
2765 bss->wps_cred_processing = atoi(pos);
2766 } else if (os_strcmp(buf, "ap_settings") == 0) {
2767 os_free(bss->ap_settings);
2768 bss->ap_settings =
2769 (u8 *) os_readfile(pos, &bss->ap_settings_len);
2770 if (bss->ap_settings == NULL) {
2771 wpa_printf(MSG_ERROR, "Line %d: could not "
2772 "read AP Settings from '%s'",
2773 line, pos);
2774 errors++;
2775 }
2776 } else if (os_strcmp(buf, "upnp_iface") == 0) {
2777 bss->upnp_iface = os_strdup(pos);
2778 } else if (os_strcmp(buf, "friendly_name") == 0) {
2779 os_free(bss->friendly_name);
2780 bss->friendly_name = os_strdup(pos);
2781 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
2782 os_free(bss->manufacturer_url);
2783 bss->manufacturer_url = os_strdup(pos);
2784 } else if (os_strcmp(buf, "model_description") == 0) {
2785 os_free(bss->model_description);
2786 bss->model_description = os_strdup(pos);
2787 } else if (os_strcmp(buf, "model_url") == 0) {
2788 os_free(bss->model_url);
2789 bss->model_url = os_strdup(pos);
2790 } else if (os_strcmp(buf, "upc") == 0) {
2791 os_free(bss->upc);
2792 bss->upc = os_strdup(pos);
Jouni Malinen87fd2792011-05-16 18:35:42 +03002793 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
2794 bss->pbc_in_m1 = atoi(pos);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002795 } else if (os_strcmp(buf, "server_id") == 0) {
2796 os_free(bss->server_id);
2797 bss->server_id = os_strdup(pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002798#ifdef CONFIG_WPS_NFC
2799 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
2800 bss->wps_nfc_dev_pw_id = atoi(pos);
2801 if (bss->wps_nfc_dev_pw_id < 0x10 ||
2802 bss->wps_nfc_dev_pw_id > 0xffff) {
2803 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2804 "wps_nfc_dev_pw_id value", line);
2805 errors++;
2806 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002807 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002808 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
2809 wpabuf_free(bss->wps_nfc_dh_pubkey);
2810 bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002811 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002812 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
2813 wpabuf_free(bss->wps_nfc_dh_privkey);
2814 bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002815 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002816 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
2817 wpabuf_free(bss->wps_nfc_dev_pw);
2818 bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002819 bss->wps_nfc_pw_from_config = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002820#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002821#endif /* CONFIG_WPS */
2822#ifdef CONFIG_P2P_MANAGER
2823 } else if (os_strcmp(buf, "manage_p2p") == 0) {
2824 int manage = atoi(pos);
2825 if (manage)
2826 bss->p2p |= P2P_MANAGE;
2827 else
2828 bss->p2p &= ~P2P_MANAGE;
2829 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
2830 if (atoi(pos))
2831 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
2832 else
2833 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
2834#endif /* CONFIG_P2P_MANAGER */
2835 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
2836 bss->disassoc_low_ack = atoi(pos);
2837 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
2838 int val = atoi(pos);
2839 if (val)
2840 bss->tdls |= TDLS_PROHIBIT;
2841 else
2842 bss->tdls &= ~TDLS_PROHIBIT;
2843 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
2844 int val = atoi(pos);
2845 if (val)
2846 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
2847 else
2848 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
2849#ifdef CONFIG_RSN_TESTING
2850 } else if (os_strcmp(buf, "rsn_testing") == 0) {
2851 extern int rsn_testing;
2852 rsn_testing = atoi(pos);
2853#endif /* CONFIG_RSN_TESTING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002854 } else if (os_strcmp(buf, "time_advertisement") == 0) {
2855 bss->time_advertisement = atoi(pos);
2856 } else if (os_strcmp(buf, "time_zone") == 0) {
2857 size_t tz_len = os_strlen(pos);
2858 if (tz_len < 4 || tz_len > 255) {
2859 wpa_printf(MSG_DEBUG, "Line %d: invalid "
2860 "time_zone", line);
2861 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002862 return errors;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002863 }
2864 os_free(bss->time_zone);
2865 bss->time_zone = os_strdup(pos);
2866 if (bss->time_zone == NULL)
2867 errors++;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002868#ifdef CONFIG_WNM
2869 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
2870 bss->wnm_sleep_mode = atoi(pos);
2871 } else if (os_strcmp(buf, "bss_transition") == 0) {
2872 bss->bss_transition = atoi(pos);
2873#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002874#ifdef CONFIG_INTERWORKING
2875 } else if (os_strcmp(buf, "interworking") == 0) {
2876 bss->interworking = atoi(pos);
2877 } else if (os_strcmp(buf, "access_network_type") == 0) {
2878 bss->access_network_type = atoi(pos);
2879 if (bss->access_network_type < 0 ||
2880 bss->access_network_type > 15) {
2881 wpa_printf(MSG_ERROR, "Line %d: invalid "
2882 "access_network_type", line);
2883 errors++;
2884 }
2885 } else if (os_strcmp(buf, "internet") == 0) {
2886 bss->internet = atoi(pos);
2887 } else if (os_strcmp(buf, "asra") == 0) {
2888 bss->asra = atoi(pos);
2889 } else if (os_strcmp(buf, "esr") == 0) {
2890 bss->esr = atoi(pos);
2891 } else if (os_strcmp(buf, "uesa") == 0) {
2892 bss->uesa = atoi(pos);
2893 } else if (os_strcmp(buf, "venue_group") == 0) {
2894 bss->venue_group = atoi(pos);
2895 bss->venue_info_set = 1;
2896 } else if (os_strcmp(buf, "venue_type") == 0) {
2897 bss->venue_type = atoi(pos);
2898 bss->venue_info_set = 1;
2899 } else if (os_strcmp(buf, "hessid") == 0) {
2900 if (hwaddr_aton(pos, bss->hessid)) {
2901 wpa_printf(MSG_ERROR, "Line %d: invalid "
2902 "hessid", line);
2903 errors++;
2904 }
2905 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
2906 if (parse_roaming_consortium(bss, pos, line) < 0)
2907 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002908 } else if (os_strcmp(buf, "venue_name") == 0) {
2909 if (parse_venue_name(bss, pos, line) < 0)
2910 errors++;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002911 } else if (os_strcmp(buf, "network_auth_type") == 0) {
2912 u8 auth_type;
2913 u16 redirect_url_len;
2914 if (hexstr2bin(pos, &auth_type, 1)) {
2915 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2916 "network_auth_type '%s'",
2917 line, pos);
2918 errors++;
2919 return errors;
2920 }
2921 if (auth_type == 0 || auth_type == 2)
2922 redirect_url_len = os_strlen(pos + 2);
2923 else
2924 redirect_url_len = 0;
2925 os_free(bss->network_auth_type);
2926 bss->network_auth_type =
2927 os_malloc(redirect_url_len + 3 + 1);
2928 if (bss->network_auth_type == NULL) {
2929 errors++;
2930 return errors;
2931 }
2932 *bss->network_auth_type = auth_type;
2933 WPA_PUT_LE16(bss->network_auth_type + 1,
2934 redirect_url_len);
2935 if (redirect_url_len)
2936 os_memcpy(bss->network_auth_type + 3,
2937 pos + 2, redirect_url_len);
2938 bss->network_auth_type_len = 3 + redirect_url_len;
2939 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
2940 if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
2941 {
2942 wpa_printf(MSG_ERROR, "Line %d: Invalid "
2943 "ipaddr_type_availability '%s'",
2944 line, pos);
2945 bss->ipaddr_type_configured = 0;
2946 errors++;
2947 return errors;
2948 }
2949 bss->ipaddr_type_configured = 1;
2950 } else if (os_strcmp(buf, "domain_name") == 0) {
2951 int j, num_domains, domain_len, domain_list_len = 0;
2952 char *tok_start, *tok_prev;
2953 u8 *domain_list, *domain_ptr;
2954
2955 domain_list_len = os_strlen(pos) + 1;
2956 domain_list = os_malloc(domain_list_len);
2957 if (domain_list == NULL) {
2958 errors++;
2959 return errors;
2960 }
2961
2962 domain_ptr = domain_list;
2963 tok_prev = pos;
2964 num_domains = 1;
2965 while ((tok_prev = os_strchr(tok_prev, ','))) {
2966 num_domains++;
2967 tok_prev++;
2968 }
2969 tok_prev = pos;
2970 for (j = 0; j < num_domains; j++) {
2971 tok_start = os_strchr(tok_prev, ',');
2972 if (tok_start) {
2973 domain_len = tok_start - tok_prev;
2974 *domain_ptr = domain_len;
2975 os_memcpy(domain_ptr + 1, tok_prev,
2976 domain_len);
2977 domain_ptr += domain_len + 1;
2978 tok_prev = ++tok_start;
2979 } else {
2980 domain_len = os_strlen(tok_prev);
2981 *domain_ptr = domain_len;
2982 os_memcpy(domain_ptr + 1, tok_prev,
2983 domain_len);
2984 domain_ptr += domain_len + 1;
2985 }
2986 }
2987
2988 os_free(bss->domain_name);
2989 bss->domain_name = domain_list;
2990 bss->domain_name_len = domain_list_len;
2991 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
2992 if (parse_3gpp_cell_net(bss, pos, line) < 0)
2993 errors++;
2994 } else if (os_strcmp(buf, "nai_realm") == 0) {
2995 if (parse_nai_realm(bss, pos, line) < 0)
2996 errors++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002997 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
2998 bss->gas_frag_limit = atoi(pos);
2999 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
3000 bss->gas_comeback_delay = atoi(pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003001 } else if (os_strcmp(buf, "qos_map_set") == 0) {
3002 if (parse_qos_map_set(bss, pos, line) < 0)
3003 errors++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003004#endif /* CONFIG_INTERWORKING */
3005#ifdef CONFIG_RADIUS_TEST
3006 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
3007 os_free(bss->dump_msk_file);
3008 bss->dump_msk_file = os_strdup(pos);
3009#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003010#ifdef CONFIG_HS20
3011 } else if (os_strcmp(buf, "hs20") == 0) {
3012 bss->hs20 = atoi(pos);
3013 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
3014 bss->disable_dgaf = atoi(pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003015 } else if (os_strcmp(buf, "osen") == 0) {
3016 bss->osen = atoi(pos);
3017 } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
3018 bss->anqp_domain_id = atoi(pos);
3019 } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
3020 bss->hs20_deauth_req_timeout = atoi(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003021 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
3022 if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
3023 errors++;
3024 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
3025 if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
3026 errors++;
3027 return errors;
3028 }
3029 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
3030 if (hs20_parse_conn_capab(bss, pos, line) < 0) {
3031 errors++;
3032 return errors;
3033 }
3034 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
3035 u8 *oper_class;
3036 size_t oper_class_len;
3037 oper_class_len = os_strlen(pos);
3038 if (oper_class_len < 2 || (oper_class_len & 0x01)) {
3039 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3040 "hs20_operating_class '%s'",
3041 line, pos);
3042 errors++;
3043 return errors;
3044 }
3045 oper_class_len /= 2;
3046 oper_class = os_malloc(oper_class_len);
3047 if (oper_class == NULL) {
3048 errors++;
3049 return errors;
3050 }
3051 if (hexstr2bin(pos, oper_class, oper_class_len)) {
3052 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3053 "hs20_operating_class '%s'",
3054 line, pos);
3055 os_free(oper_class);
3056 errors++;
3057 return errors;
3058 }
3059 os_free(bss->hs20_operating_class);
3060 bss->hs20_operating_class = oper_class;
3061 bss->hs20_operating_class_len = oper_class_len;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003062 } else if (os_strcmp(buf, "hs20_icon") == 0) {
3063 if (hs20_parse_icon(bss, pos) < 0) {
3064 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3065 "hs20_icon '%s'", line, pos);
3066 errors++;
3067 return errors;
3068 }
3069 } else if (os_strcmp(buf, "osu_ssid") == 0) {
3070 if (hs20_parse_osu_ssid(bss, pos, line) < 0)
3071 errors++;
3072 } else if (os_strcmp(buf, "osu_server_uri") == 0) {
3073 if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
3074 errors++;
3075 } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
3076 if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
3077 errors++;
3078 } else if (os_strcmp(buf, "osu_nai") == 0) {
3079 if (hs20_parse_osu_nai(bss, pos, line) < 0)
3080 errors++;
3081 } else if (os_strcmp(buf, "osu_method_list") == 0) {
3082 if (hs20_parse_osu_method_list(bss, pos, line) < 0)
3083 errors++;
3084 } else if (os_strcmp(buf, "osu_icon") == 0) {
3085 if (hs20_parse_osu_icon(bss, pos, line) < 0)
3086 errors++;
3087 } else if (os_strcmp(buf, "osu_service_desc") == 0) {
3088 if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
3089 errors++;
3090 } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
3091 os_free(bss->subscr_remediation_url);
3092 bss->subscr_remediation_url = os_strdup(pos);
3093 } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
3094 bss->subscr_remediation_method = atoi(pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003095#endif /* CONFIG_HS20 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003096#ifdef CONFIG_TESTING_OPTIONS
3097#define PARSE_TEST_PROBABILITY(_val) \
3098 } else if (os_strcmp(buf, #_val) == 0) { \
3099 char *end; \
3100 \
3101 conf->_val = strtod(pos, &end); \
3102 if (*end || conf->_val < 0.0d || \
3103 conf->_val > 1.0d) { \
3104 wpa_printf(MSG_ERROR, \
3105 "Line %d: Invalid value '%s'", \
3106 line, pos); \
3107 errors++; \
3108 return errors; \
3109 }
3110 PARSE_TEST_PROBABILITY(ignore_probe_probability)
3111 PARSE_TEST_PROBABILITY(ignore_auth_probability)
3112 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
3113 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003114 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
Dmitry Shmidt051af732013-10-22 13:52:46 -07003115 } else if (os_strcmp(buf, "bss_load_test") == 0) {
3116 WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
3117 pos = os_strchr(pos, ':');
3118 if (pos == NULL) {
3119 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3120 "bss_load_test", line);
3121 return 1;
3122 }
3123 pos++;
3124 bss->bss_load_test[2] = atoi(pos);
3125 pos = os_strchr(pos, ':');
3126 if (pos == NULL) {
3127 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3128 "bss_load_test", line);
3129 return 1;
3130 }
3131 pos++;
3132 WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
3133 bss->bss_load_test_set = 1;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003134#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003135 } else if (os_strcmp(buf, "vendor_elements") == 0) {
3136 struct wpabuf *elems;
3137 size_t len = os_strlen(pos);
3138 if (len & 0x01) {
3139 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3140 "vendor_elements '%s'", line, pos);
3141 return 1;
3142 }
3143 len /= 2;
3144 if (len == 0) {
3145 wpabuf_free(bss->vendor_elements);
3146 bss->vendor_elements = NULL;
3147 return 0;
3148 }
3149
3150 elems = wpabuf_alloc(len);
3151 if (elems == NULL)
3152 return 1;
3153
3154 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
3155 wpabuf_free(elems);
3156 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3157 "vendor_elements '%s'", line, pos);
3158 return 1;
3159 }
3160
3161 wpabuf_free(bss->vendor_elements);
3162 bss->vendor_elements = elems;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003163 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
3164 bss->sae_anti_clogging_threshold = atoi(pos);
3165 } else if (os_strcmp(buf, "sae_groups") == 0) {
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003166 if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003167 wpa_printf(MSG_ERROR, "Line %d: Invalid "
3168 "sae_groups value '%s'", line, pos);
3169 return 1;
3170 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003171 } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
3172 int val = atoi(pos);
3173 if (val < 0 || val > 255) {
3174 wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
3175 line, val);
3176 return 1;
3177 }
3178 conf->local_pwr_constraint = val;
3179 } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
3180 conf->spectrum_mgmt_required = atoi(pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003181 } else {
3182 wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
3183 "item '%s'", line, buf);
3184 errors++;
3185 }
3186 }
3187
Dmitry Shmidt04949592012-07-19 12:16:46 -07003188 return errors;
3189}
3190
3191
Dmitry Shmidt04949592012-07-19 12:16:46 -07003192/**
3193 * hostapd_config_read - Read and parse a configuration file
3194 * @fname: Configuration file name (including path, if needed)
3195 * Returns: Allocated configuration data structure
3196 */
3197struct hostapd_config * hostapd_config_read(const char *fname)
3198{
3199 struct hostapd_config *conf;
3200 struct hostapd_bss_config *bss;
3201 FILE *f;
3202 char buf[512], *pos;
3203 int line = 0;
3204 int errors = 0;
3205 size_t i;
3206
3207 f = fopen(fname, "r");
3208 if (f == NULL) {
3209 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
3210 "for reading.", fname);
3211 return NULL;
3212 }
3213
3214 conf = hostapd_config_defaults();
3215 if (conf == NULL) {
3216 fclose(f);
3217 return NULL;
3218 }
3219
3220 /* set default driver based on configuration */
3221 conf->driver = wpa_drivers[0];
3222 if (conf->driver == NULL) {
3223 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
3224 hostapd_config_free(conf);
3225 fclose(f);
3226 return NULL;
3227 }
3228
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003229 bss = conf->last_bss = conf->bss[0];
Dmitry Shmidt04949592012-07-19 12:16:46 -07003230
3231 while (fgets(buf, sizeof(buf), f)) {
3232 bss = conf->last_bss;
3233 line++;
3234
3235 if (buf[0] == '#')
3236 continue;
3237 pos = buf;
3238 while (*pos != '\0') {
3239 if (*pos == '\n') {
3240 *pos = '\0';
3241 break;
3242 }
3243 pos++;
3244 }
3245 if (buf[0] == '\0')
3246 continue;
3247
3248 pos = os_strchr(buf, '=');
3249 if (pos == NULL) {
3250 wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
3251 line, buf);
3252 errors++;
3253 continue;
3254 }
3255 *pos = '\0';
3256 pos++;
3257 errors += hostapd_config_fill(conf, bss, buf, pos, line);
3258 }
3259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 fclose(f);
3261
Dmitry Shmidt04949592012-07-19 12:16:46 -07003262 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003263 hostapd_set_security_params(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003264
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003265 if (hostapd_config_check(conf, 1))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003266 errors++;
3267
3268#ifndef WPA_IGNORE_CONFIG_ERRORS
3269 if (errors) {
3270 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
3271 "'%s'", errors, fname);
3272 hostapd_config_free(conf);
3273 conf = NULL;
3274 }
3275#endif /* WPA_IGNORE_CONFIG_ERRORS */
3276
3277 return conf;
3278}
Dmitry Shmidt04949592012-07-19 12:16:46 -07003279
3280
3281int hostapd_set_iface(struct hostapd_config *conf,
3282 struct hostapd_bss_config *bss, char *field, char *value)
3283{
3284 int errors;
3285 size_t i;
3286
3287 errors = hostapd_config_fill(conf, bss, field, value, 0);
3288 if (errors) {
3289 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
3290 "to value '%s'", field, value);
3291 return -1;
3292 }
3293
3294 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003295 hostapd_set_security_params(conf->bss[i]);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003296
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003297 if (hostapd_config_check(conf, 0)) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003298 wpa_printf(MSG_ERROR, "Configuration check failed");
3299 return -1;
3300 }
3301
3302 return 0;
3303}