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