]>
Commit | Line | Data |
---|---|---|
41d719d6 JM |
1 | /* |
2 | * hostapd / Configuration file parser | |
5e3b5197 | 3 | * Copyright (c) 2003-2015, 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 | 16 | #include "common/ieee802_11_defs.h" |
245fc96e | 17 | #include "crypto/sha256.h" |
41d719d6 JM |
18 | #include "drivers/driver.h" |
19 | #include "eap_server/eap.h" | |
20 | #include "radius/radius_client.h" | |
6226e38d JM |
21 | #include "ap/wpa_auth.h" |
22 | #include "ap/ap_config.h" | |
1057d78e | 23 | #include "config_file.h" |
41d719d6 JM |
24 | |
25 | ||
d0ee16ed JM |
26 | #ifndef CONFIG_NO_RADIUS |
27 | #ifdef EAP_SERVER | |
28 | static struct hostapd_radius_attr * | |
29 | hostapd_parse_radius_attr(const char *value); | |
30 | #endif /* EAP_SERVER */ | |
31 | #endif /* CONFIG_NO_RADIUS */ | |
32 | ||
33 | ||
41d719d6 JM |
34 | #ifndef CONFIG_NO_VLAN |
35 | static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, | |
36 | const char *fname) | |
37 | { | |
38 | FILE *f; | |
39 | char buf[128], *pos, *pos2; | |
40 | int line = 0, vlan_id; | |
41 | struct hostapd_vlan *vlan; | |
42 | ||
43 | f = fopen(fname, "r"); | |
44 | if (!f) { | |
45 | wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname); | |
46 | return -1; | |
47 | } | |
48 | ||
49 | while (fgets(buf, sizeof(buf), f)) { | |
50 | line++; | |
51 | ||
52 | if (buf[0] == '#') | |
53 | continue; | |
54 | pos = buf; | |
55 | while (*pos != '\0') { | |
56 | if (*pos == '\n') { | |
57 | *pos = '\0'; | |
58 | break; | |
59 | } | |
60 | pos++; | |
61 | } | |
62 | if (buf[0] == '\0') | |
63 | continue; | |
64 | ||
65 | if (buf[0] == '*') { | |
66 | vlan_id = VLAN_ID_WILDCARD; | |
67 | pos = buf + 1; | |
68 | } else { | |
69 | vlan_id = strtol(buf, &pos, 10); | |
70 | if (buf == pos || vlan_id < 1 || | |
71 | vlan_id > MAX_VLAN_ID) { | |
72 | wpa_printf(MSG_ERROR, "Invalid VLAN ID at " | |
73 | "line %d in '%s'", line, fname); | |
74 | fclose(f); | |
75 | return -1; | |
76 | } | |
77 | } | |
78 | ||
79 | while (*pos == ' ' || *pos == '\t') | |
80 | pos++; | |
81 | pos2 = pos; | |
82 | while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0') | |
83 | pos2++; | |
84 | *pos2 = '\0'; | |
85 | if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) { | |
86 | wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d " | |
87 | "in '%s'", line, fname); | |
88 | fclose(f); | |
89 | return -1; | |
90 | } | |
91 | ||
8b44ad7e | 92 | vlan = os_zalloc(sizeof(*vlan)); |
41d719d6 JM |
93 | if (vlan == NULL) { |
94 | wpa_printf(MSG_ERROR, "Out of memory while reading " | |
95 | "VLAN interfaces from '%s'", fname); | |
96 | fclose(f); | |
97 | return -1; | |
98 | } | |
99 | ||
41d719d6 | 100 | vlan->vlan_id = vlan_id; |
1889af2e MB |
101 | vlan->vlan_desc.untagged = vlan_id; |
102 | vlan->vlan_desc.notempty = !!vlan_id; | |
41d719d6 | 103 | os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname)); |
c2db79f2 MB |
104 | vlan->next = bss->vlan; |
105 | bss->vlan = vlan; | |
41d719d6 JM |
106 | } |
107 | ||
108 | fclose(f); | |
109 | ||
110 | return 0; | |
111 | } | |
112 | #endif /* CONFIG_NO_VLAN */ | |
113 | ||
114 | ||
115 | static int hostapd_acl_comp(const void *a, const void *b) | |
116 | { | |
117 | const struct mac_acl_entry *aa = a; | |
118 | const struct mac_acl_entry *bb = b; | |
119 | return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); | |
120 | } | |
121 | ||
122 | ||
123 | static int hostapd_config_read_maclist(const char *fname, | |
124 | struct mac_acl_entry **acl, int *num) | |
125 | { | |
126 | FILE *f; | |
127 | char buf[128], *pos; | |
128 | int line = 0; | |
129 | u8 addr[ETH_ALEN]; | |
130 | struct mac_acl_entry *newacl; | |
131 | int vlan_id; | |
132 | ||
41d719d6 JM |
133 | f = fopen(fname, "r"); |
134 | if (!f) { | |
135 | wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); | |
136 | return -1; | |
137 | } | |
138 | ||
139 | while (fgets(buf, sizeof(buf), f)) { | |
1748f1da ET |
140 | int i, rem = 0; |
141 | ||
41d719d6 JM |
142 | line++; |
143 | ||
144 | if (buf[0] == '#') | |
145 | continue; | |
146 | pos = buf; | |
147 | while (*pos != '\0') { | |
148 | if (*pos == '\n') { | |
149 | *pos = '\0'; | |
150 | break; | |
151 | } | |
152 | pos++; | |
153 | } | |
154 | if (buf[0] == '\0') | |
155 | continue; | |
1748f1da ET |
156 | pos = buf; |
157 | if (buf[0] == '-') { | |
158 | rem = 1; | |
159 | pos++; | |
160 | } | |
41d719d6 | 161 | |
1748f1da | 162 | if (hwaddr_aton(pos, addr)) { |
41d719d6 | 163 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at " |
1748f1da | 164 | "line %d in '%s'", pos, line, fname); |
41d719d6 JM |
165 | fclose(f); |
166 | return -1; | |
167 | } | |
168 | ||
1748f1da ET |
169 | if (rem) { |
170 | i = 0; | |
171 | while (i < *num) { | |
172 | if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == | |
173 | 0) { | |
174 | os_remove_in_array(*acl, *num, | |
175 | sizeof(**acl), i); | |
176 | (*num)--; | |
177 | } else | |
178 | i++; | |
179 | } | |
180 | continue; | |
181 | } | |
41d719d6 JM |
182 | vlan_id = 0; |
183 | pos = buf; | |
184 | while (*pos != '\0' && *pos != ' ' && *pos != '\t') | |
185 | pos++; | |
186 | while (*pos == ' ' || *pos == '\t') | |
187 | pos++; | |
188 | if (*pos != '\0') | |
189 | vlan_id = atoi(pos); | |
190 | ||
067ffa26 | 191 | newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); |
41d719d6 JM |
192 | if (newacl == NULL) { |
193 | wpa_printf(MSG_ERROR, "MAC list reallocation failed"); | |
194 | fclose(f); | |
195 | return -1; | |
196 | } | |
197 | ||
198 | *acl = newacl; | |
199 | os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); | |
1889af2e MB |
200 | os_memset(&(*acl)[*num].vlan_id, 0, |
201 | sizeof((*acl)[*num].vlan_id)); | |
202 | (*acl)[*num].vlan_id.untagged = vlan_id; | |
203 | (*acl)[*num].vlan_id.notempty = !!vlan_id; | |
41d719d6 JM |
204 | (*num)++; |
205 | } | |
206 | ||
207 | fclose(f); | |
208 | ||
33111c91 JC |
209 | if (*acl) |
210 | qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); | |
41d719d6 JM |
211 | |
212 | return 0; | |
213 | } | |
214 | ||
215 | ||
216 | #ifdef EAP_SERVER | |
217 | static int hostapd_config_read_eap_user(const char *fname, | |
218 | struct hostapd_bss_config *conf) | |
219 | { | |
220 | FILE *f; | |
221 | char buf[512], *pos, *start, *pos2; | |
222 | int line = 0, ret = 0, num_methods; | |
4437f8fc | 223 | struct hostapd_eap_user *user = NULL, *tail = NULL, *new_user = NULL; |
41d719d6 | 224 | |
ee431d77 | 225 | if (os_strncmp(fname, "sqlite:", 7) == 0) { |
c469d622 | 226 | #ifdef CONFIG_SQLITE |
ee431d77 JM |
227 | os_free(conf->eap_user_sqlite); |
228 | conf->eap_user_sqlite = os_strdup(fname + 7); | |
229 | return 0; | |
c469d622 BG |
230 | #else /* CONFIG_SQLITE */ |
231 | wpa_printf(MSG_ERROR, | |
232 | "EAP user file in SQLite DB, but CONFIG_SQLITE was not enabled in the build."); | |
233 | return -1; | |
234 | #endif /* CONFIG_SQLITE */ | |
ee431d77 JM |
235 | } |
236 | ||
41d719d6 JM |
237 | f = fopen(fname, "r"); |
238 | if (!f) { | |
239 | wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname); | |
240 | return -1; | |
241 | } | |
242 | ||
243 | /* Lines: "user" METHOD,METHOD2 "password" (password optional) */ | |
244 | while (fgets(buf, sizeof(buf), f)) { | |
245 | line++; | |
246 | ||
247 | if (buf[0] == '#') | |
248 | continue; | |
249 | pos = buf; | |
250 | while (*pos != '\0') { | |
251 | if (*pos == '\n') { | |
252 | *pos = '\0'; | |
253 | break; | |
254 | } | |
255 | pos++; | |
256 | } | |
257 | if (buf[0] == '\0') | |
258 | continue; | |
259 | ||
d0ee16ed JM |
260 | #ifndef CONFIG_NO_RADIUS |
261 | if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) { | |
262 | struct hostapd_radius_attr *attr, *a; | |
263 | attr = hostapd_parse_radius_attr(buf + 19); | |
264 | if (attr == NULL) { | |
265 | wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s", | |
266 | buf + 19); | |
4fb363c6 | 267 | user = NULL; /* already in the BSS list */ |
d0ee16ed JM |
268 | goto failed; |
269 | } | |
270 | if (user->accept_attr == NULL) { | |
271 | user->accept_attr = attr; | |
272 | } else { | |
273 | a = user->accept_attr; | |
274 | while (a->next) | |
275 | a = a->next; | |
276 | a->next = attr; | |
277 | } | |
278 | continue; | |
279 | } | |
280 | #endif /* CONFIG_NO_RADIUS */ | |
281 | ||
41d719d6 JM |
282 | user = NULL; |
283 | ||
284 | if (buf[0] != '"' && buf[0] != '*') { | |
285 | wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in " | |
286 | "start) on line %d in '%s'", line, fname); | |
287 | goto failed; | |
288 | } | |
289 | ||
290 | user = os_zalloc(sizeof(*user)); | |
291 | if (user == NULL) { | |
292 | wpa_printf(MSG_ERROR, "EAP user allocation failed"); | |
293 | goto failed; | |
294 | } | |
295 | user->force_version = -1; | |
296 | ||
297 | if (buf[0] == '*') { | |
298 | pos = buf; | |
299 | } else { | |
300 | pos = buf + 1; | |
301 | start = pos; | |
302 | while (*pos != '"' && *pos != '\0') | |
303 | pos++; | |
304 | if (*pos == '\0') { | |
305 | wpa_printf(MSG_ERROR, "Invalid EAP identity " | |
306 | "(no \" in end) on line %d in '%s'", | |
307 | line, fname); | |
308 | goto failed; | |
309 | } | |
310 | ||
a1f11e34 | 311 | user->identity = os_memdup(start, pos - start); |
41d719d6 JM |
312 | if (user->identity == NULL) { |
313 | wpa_printf(MSG_ERROR, "Failed to allocate " | |
314 | "memory for EAP identity"); | |
315 | goto failed; | |
316 | } | |
41d719d6 JM |
317 | user->identity_len = pos - start; |
318 | ||
319 | if (pos[0] == '"' && pos[1] == '*') { | |
320 | user->wildcard_prefix = 1; | |
321 | pos++; | |
322 | } | |
323 | } | |
324 | pos++; | |
325 | while (*pos == ' ' || *pos == '\t') | |
326 | pos++; | |
327 | ||
328 | if (*pos == '\0') { | |
329 | wpa_printf(MSG_ERROR, "No EAP method on line %d in " | |
330 | "'%s'", line, fname); | |
331 | goto failed; | |
332 | } | |
333 | ||
334 | start = pos; | |
335 | while (*pos != ' ' && *pos != '\t' && *pos != '\0') | |
336 | pos++; | |
337 | if (*pos == '\0') { | |
338 | pos = NULL; | |
339 | } else { | |
340 | *pos = '\0'; | |
341 | pos++; | |
342 | } | |
343 | num_methods = 0; | |
344 | while (*start) { | |
345 | char *pos3 = os_strchr(start, ','); | |
346 | if (pos3) { | |
347 | *pos3++ = '\0'; | |
348 | } | |
349 | user->methods[num_methods].method = | |
350 | eap_server_get_type( | |
351 | start, | |
352 | &user->methods[num_methods].vendor); | |
353 | if (user->methods[num_methods].vendor == | |
354 | EAP_VENDOR_IETF && | |
355 | user->methods[num_methods].method == EAP_TYPE_NONE) | |
356 | { | |
357 | if (os_strcmp(start, "TTLS-PAP") == 0) { | |
358 | user->ttls_auth |= EAP_TTLS_AUTH_PAP; | |
359 | goto skip_eap; | |
360 | } | |
361 | if (os_strcmp(start, "TTLS-CHAP") == 0) { | |
362 | user->ttls_auth |= EAP_TTLS_AUTH_CHAP; | |
363 | goto skip_eap; | |
364 | } | |
365 | if (os_strcmp(start, "TTLS-MSCHAP") == 0) { | |
366 | user->ttls_auth |= | |
367 | EAP_TTLS_AUTH_MSCHAP; | |
368 | goto skip_eap; | |
369 | } | |
370 | if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) { | |
371 | user->ttls_auth |= | |
372 | EAP_TTLS_AUTH_MSCHAPV2; | |
373 | goto skip_eap; | |
374 | } | |
8943cc99 JM |
375 | if (os_strcmp(start, "MACACL") == 0) { |
376 | user->macacl = 1; | |
377 | goto skip_eap; | |
378 | } | |
41d719d6 JM |
379 | wpa_printf(MSG_ERROR, "Unsupported EAP type " |
380 | "'%s' on line %d in '%s'", | |
381 | start, line, fname); | |
382 | goto failed; | |
383 | } | |
384 | ||
385 | num_methods++; | |
e9447a94 | 386 | if (num_methods >= EAP_MAX_METHODS) |
41d719d6 JM |
387 | break; |
388 | skip_eap: | |
389 | if (pos3 == NULL) | |
390 | break; | |
391 | start = pos3; | |
392 | } | |
8943cc99 | 393 | if (num_methods == 0 && user->ttls_auth == 0 && !user->macacl) { |
41d719d6 JM |
394 | wpa_printf(MSG_ERROR, "No EAP types configured on " |
395 | "line %d in '%s'", line, fname); | |
396 | goto failed; | |
397 | } | |
398 | ||
399 | if (pos == NULL) | |
400 | goto done; | |
401 | ||
402 | while (*pos == ' ' || *pos == '\t') | |
403 | pos++; | |
404 | if (*pos == '\0') | |
405 | goto done; | |
406 | ||
407 | if (os_strncmp(pos, "[ver=0]", 7) == 0) { | |
408 | user->force_version = 0; | |
409 | goto done; | |
410 | } | |
411 | ||
412 | if (os_strncmp(pos, "[ver=1]", 7) == 0) { | |
413 | user->force_version = 1; | |
414 | goto done; | |
415 | } | |
416 | ||
417 | if (os_strncmp(pos, "[2]", 3) == 0) { | |
418 | user->phase2 = 1; | |
419 | goto done; | |
420 | } | |
421 | ||
422 | if (*pos == '"') { | |
423 | pos++; | |
424 | start = pos; | |
425 | while (*pos != '"' && *pos != '\0') | |
426 | pos++; | |
427 | if (*pos == '\0') { | |
428 | wpa_printf(MSG_ERROR, "Invalid EAP password " | |
429 | "(no \" in end) on line %d in '%s'", | |
430 | line, fname); | |
431 | goto failed; | |
432 | } | |
433 | ||
a1f11e34 | 434 | user->password = os_memdup(start, pos - start); |
41d719d6 JM |
435 | if (user->password == NULL) { |
436 | wpa_printf(MSG_ERROR, "Failed to allocate " | |
437 | "memory for EAP password"); | |
438 | goto failed; | |
439 | } | |
41d719d6 JM |
440 | user->password_len = pos - start; |
441 | ||
442 | pos++; | |
443 | } else if (os_strncmp(pos, "hash:", 5) == 0) { | |
444 | pos += 5; | |
445 | pos2 = pos; | |
446 | while (*pos2 != '\0' && *pos2 != ' ' && | |
447 | *pos2 != '\t' && *pos2 != '#') | |
448 | pos2++; | |
449 | if (pos2 - pos != 32) { | |
450 | wpa_printf(MSG_ERROR, "Invalid password hash " | |
451 | "on line %d in '%s'", line, fname); | |
452 | goto failed; | |
453 | } | |
454 | user->password = os_malloc(16); | |
455 | if (user->password == NULL) { | |
456 | wpa_printf(MSG_ERROR, "Failed to allocate " | |
457 | "memory for EAP password hash"); | |
458 | goto failed; | |
459 | } | |
460 | if (hexstr2bin(pos, user->password, 16) < 0) { | |
461 | wpa_printf(MSG_ERROR, "Invalid hash password " | |
462 | "on line %d in '%s'", line, fname); | |
463 | goto failed; | |
464 | } | |
465 | user->password_len = 16; | |
466 | user->password_hash = 1; | |
467 | pos = pos2; | |
468 | } else { | |
469 | pos2 = pos; | |
470 | while (*pos2 != '\0' && *pos2 != ' ' && | |
471 | *pos2 != '\t' && *pos2 != '#') | |
472 | pos2++; | |
473 | if ((pos2 - pos) & 1) { | |
474 | wpa_printf(MSG_ERROR, "Invalid hex password " | |
475 | "on line %d in '%s'", line, fname); | |
476 | goto failed; | |
477 | } | |
478 | user->password = os_malloc((pos2 - pos) / 2); | |
479 | if (user->password == NULL) { | |
480 | wpa_printf(MSG_ERROR, "Failed to allocate " | |
481 | "memory for EAP password"); | |
482 | goto failed; | |
483 | } | |
484 | if (hexstr2bin(pos, user->password, | |
485 | (pos2 - pos) / 2) < 0) { | |
486 | wpa_printf(MSG_ERROR, "Invalid hex password " | |
487 | "on line %d in '%s'", line, fname); | |
488 | goto failed; | |
489 | } | |
490 | user->password_len = (pos2 - pos) / 2; | |
491 | pos = pos2; | |
492 | } | |
493 | ||
494 | while (*pos == ' ' || *pos == '\t') | |
495 | pos++; | |
496 | if (os_strncmp(pos, "[2]", 3) == 0) { | |
497 | user->phase2 = 1; | |
498 | } | |
499 | ||
500 | done: | |
501 | if (tail == NULL) { | |
4437f8fc | 502 | tail = new_user = user; |
41d719d6 JM |
503 | } else { |
504 | tail->next = user; | |
505 | tail = user; | |
506 | } | |
507 | continue; | |
508 | ||
509 | failed: | |
d0ee16ed JM |
510 | if (user) |
511 | hostapd_config_free_eap_user(user); | |
41d719d6 JM |
512 | ret = -1; |
513 | break; | |
514 | } | |
515 | ||
516 | fclose(f); | |
517 | ||
4437f8fc | 518 | if (ret == 0) { |
78022c83 | 519 | hostapd_config_free_eap_users(conf->eap_user); |
4437f8fc | 520 | conf->eap_user = new_user; |
78022c83 JM |
521 | } else { |
522 | hostapd_config_free_eap_users(new_user); | |
4437f8fc JM |
523 | } |
524 | ||
41d719d6 JM |
525 | return ret; |
526 | } | |
527 | #endif /* EAP_SERVER */ | |
528 | ||
529 | ||
530 | #ifndef CONFIG_NO_RADIUS | |
531 | static int | |
532 | hostapd_config_read_radius_addr(struct hostapd_radius_server **server, | |
533 | int *num_server, const char *val, int def_port, | |
534 | struct hostapd_radius_server **curr_serv) | |
535 | { | |
536 | struct hostapd_radius_server *nserv; | |
537 | int ret; | |
538 | static int server_index = 1; | |
539 | ||
067ffa26 | 540 | nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv)); |
41d719d6 JM |
541 | if (nserv == NULL) |
542 | return -1; | |
543 | ||
544 | *server = nserv; | |
545 | nserv = &nserv[*num_server]; | |
546 | (*num_server)++; | |
547 | (*curr_serv) = nserv; | |
548 | ||
549 | os_memset(nserv, 0, sizeof(*nserv)); | |
550 | nserv->port = def_port; | |
551 | ret = hostapd_parse_ip_addr(val, &nserv->addr); | |
552 | nserv->index = server_index++; | |
553 | ||
554 | return ret; | |
555 | } | |
af35e7af JM |
556 | |
557 | ||
558 | static struct hostapd_radius_attr * | |
559 | hostapd_parse_radius_attr(const char *value) | |
560 | { | |
561 | const char *pos; | |
562 | char syntax; | |
563 | struct hostapd_radius_attr *attr; | |
564 | size_t len; | |
565 | ||
566 | attr = os_zalloc(sizeof(*attr)); | |
567 | if (attr == NULL) | |
568 | return NULL; | |
569 | ||
570 | attr->type = atoi(value); | |
571 | ||
572 | pos = os_strchr(value, ':'); | |
573 | if (pos == NULL) { | |
574 | attr->val = wpabuf_alloc(1); | |
575 | if (attr->val == NULL) { | |
576 | os_free(attr); | |
577 | return NULL; | |
578 | } | |
579 | wpabuf_put_u8(attr->val, 0); | |
580 | return attr; | |
581 | } | |
582 | ||
583 | pos++; | |
584 | if (pos[0] == '\0' || pos[1] != ':') { | |
585 | os_free(attr); | |
586 | return NULL; | |
587 | } | |
588 | syntax = *pos++; | |
589 | pos++; | |
590 | ||
591 | switch (syntax) { | |
592 | case 's': | |
593 | attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); | |
594 | break; | |
595 | case 'x': | |
596 | len = os_strlen(pos); | |
597 | if (len & 1) | |
598 | break; | |
599 | len /= 2; | |
600 | attr->val = wpabuf_alloc(len); | |
601 | if (attr->val == NULL) | |
602 | break; | |
603 | if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { | |
604 | wpabuf_free(attr->val); | |
605 | os_free(attr); | |
606 | return NULL; | |
607 | } | |
608 | break; | |
609 | case 'd': | |
610 | attr->val = wpabuf_alloc(4); | |
611 | if (attr->val) | |
612 | wpabuf_put_be32(attr->val, atoi(pos)); | |
613 | break; | |
614 | default: | |
615 | os_free(attr); | |
616 | return NULL; | |
617 | } | |
618 | ||
619 | if (attr->val == NULL) { | |
620 | os_free(attr); | |
621 | return NULL; | |
622 | } | |
623 | ||
624 | return attr; | |
625 | } | |
b031338c JM |
626 | |
627 | ||
79931efa | 628 | static int hostapd_parse_das_client(struct hostapd_bss_config *bss, char *val) |
b031338c JM |
629 | { |
630 | char *secret; | |
b031338c JM |
631 | |
632 | secret = os_strchr(val, ' '); | |
633 | if (secret == NULL) | |
634 | return -1; | |
635 | ||
79931efa | 636 | *secret++ = '\0'; |
b031338c JM |
637 | |
638 | if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr)) | |
639 | return -1; | |
640 | ||
641 | os_free(bss->radius_das_shared_secret); | |
6e459875 | 642 | bss->radius_das_shared_secret = (u8 *) os_strdup(secret); |
b031338c JM |
643 | if (bss->radius_das_shared_secret == NULL) |
644 | return -1; | |
6e459875 | 645 | bss->radius_das_shared_secret_len = os_strlen(secret); |
b031338c JM |
646 | |
647 | return 0; | |
648 | } | |
41d719d6 JM |
649 | #endif /* CONFIG_NO_RADIUS */ |
650 | ||
651 | ||
652 | static int hostapd_config_parse_key_mgmt(int line, const char *value) | |
653 | { | |
654 | int val = 0, last; | |
655 | char *start, *end, *buf; | |
656 | ||
657 | buf = os_strdup(value); | |
658 | if (buf == NULL) | |
659 | return -1; | |
660 | start = buf; | |
661 | ||
662 | while (*start != '\0') { | |
663 | while (*start == ' ' || *start == '\t') | |
664 | start++; | |
665 | if (*start == '\0') | |
666 | break; | |
667 | end = start; | |
668 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
669 | end++; | |
670 | last = *end == '\0'; | |
671 | *end = '\0'; | |
672 | if (os_strcmp(start, "WPA-PSK") == 0) | |
673 | val |= WPA_KEY_MGMT_PSK; | |
674 | else if (os_strcmp(start, "WPA-EAP") == 0) | |
675 | val |= WPA_KEY_MGMT_IEEE8021X; | |
d503eeea | 676 | #ifdef CONFIG_IEEE80211R_AP |
41d719d6 JM |
677 | else if (os_strcmp(start, "FT-PSK") == 0) |
678 | val |= WPA_KEY_MGMT_FT_PSK; | |
679 | else if (os_strcmp(start, "FT-EAP") == 0) | |
680 | val |= WPA_KEY_MGMT_FT_IEEE8021X; | |
d503eeea | 681 | #endif /* CONFIG_IEEE80211R_AP */ |
41d719d6 JM |
682 | #ifdef CONFIG_IEEE80211W |
683 | else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) | |
684 | val |= WPA_KEY_MGMT_PSK_SHA256; | |
685 | else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) | |
686 | val |= WPA_KEY_MGMT_IEEE8021X_SHA256; | |
687 | #endif /* CONFIG_IEEE80211W */ | |
c10347f2 JM |
688 | #ifdef CONFIG_SAE |
689 | else if (os_strcmp(start, "SAE") == 0) | |
690 | val |= WPA_KEY_MGMT_SAE; | |
691 | else if (os_strcmp(start, "FT-SAE") == 0) | |
692 | val |= WPA_KEY_MGMT_FT_SAE; | |
693 | #endif /* CONFIG_SAE */ | |
5e3b5197 | 694 | #ifdef CONFIG_SUITEB |
666497c8 JM |
695 | else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0) |
696 | val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B; | |
5e3b5197 JM |
697 | #endif /* CONFIG_SUITEB */ |
698 | #ifdef CONFIG_SUITEB192 | |
699 | else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0) | |
700 | val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; | |
701 | #endif /* CONFIG_SUITEB192 */ | |
903ecbe8 JM |
702 | #ifdef CONFIG_FILS |
703 | else if (os_strcmp(start, "FILS-SHA256") == 0) | |
704 | val |= WPA_KEY_MGMT_FILS_SHA256; | |
705 | else if (os_strcmp(start, "FILS-SHA384") == 0) | |
706 | val |= WPA_KEY_MGMT_FILS_SHA384; | |
d503eeea | 707 | #ifdef CONFIG_IEEE80211R_AP |
903ecbe8 JM |
708 | else if (os_strcmp(start, "FT-FILS-SHA256") == 0) |
709 | val |= WPA_KEY_MGMT_FT_FILS_SHA256; | |
710 | else if (os_strcmp(start, "FT-FILS-SHA384") == 0) | |
711 | val |= WPA_KEY_MGMT_FT_FILS_SHA384; | |
d503eeea | 712 | #endif /* CONFIG_IEEE80211R_AP */ |
903ecbe8 | 713 | #endif /* CONFIG_FILS */ |
a1ea1b45 JM |
714 | #ifdef CONFIG_OWE |
715 | else if (os_strcmp(start, "OWE") == 0) | |
716 | val |= WPA_KEY_MGMT_OWE; | |
717 | #endif /* CONFIG_OWE */ | |
41d719d6 JM |
718 | else { |
719 | wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", | |
720 | line, start); | |
721 | os_free(buf); | |
722 | return -1; | |
723 | } | |
724 | ||
725 | if (last) | |
726 | break; | |
727 | start = end + 1; | |
728 | } | |
729 | ||
730 | os_free(buf); | |
731 | if (val == 0) { | |
732 | wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values " | |
733 | "configured.", line); | |
734 | return -1; | |
735 | } | |
736 | ||
737 | return val; | |
738 | } | |
739 | ||
740 | ||
741 | static int hostapd_config_parse_cipher(int line, const char *value) | |
742 | { | |
a39c78be JM |
743 | int val = wpa_parse_cipher(value); |
744 | if (val < 0) { | |
745 | wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", | |
746 | line, value); | |
41d719d6 | 747 | return -1; |
41d719d6 | 748 | } |
41d719d6 JM |
749 | if (val == 0) { |
750 | wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", | |
751 | line); | |
752 | return -1; | |
753 | } | |
754 | return val; | |
755 | } | |
756 | ||
757 | ||
758 | static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx, | |
759 | char *val) | |
760 | { | |
761 | size_t len = os_strlen(val); | |
762 | ||
20b1a9e2 JM |
763 | if (keyidx < 0 || keyidx > 3) |
764 | return -1; | |
765 | ||
766 | if (len == 0) { | |
767 | int i, set = 0; | |
768 | ||
769 | bin_clear_free(wep->key[keyidx], wep->len[keyidx]); | |
770 | wep->key[keyidx] = NULL; | |
771 | wep->len[keyidx] = 0; | |
772 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
773 | if (wep->key[i]) | |
774 | set++; | |
775 | } | |
776 | if (!set) | |
777 | wep->keys_set = 0; | |
778 | return 0; | |
779 | } | |
780 | ||
781 | if (wep->key[keyidx] != NULL) | |
41d719d6 JM |
782 | return -1; |
783 | ||
784 | if (val[0] == '"') { | |
785 | if (len < 2 || val[len - 1] != '"') | |
786 | return -1; | |
787 | len -= 2; | |
a1f11e34 | 788 | wep->key[keyidx] = os_memdup(val + 1, len); |
41d719d6 JM |
789 | if (wep->key[keyidx] == NULL) |
790 | return -1; | |
41d719d6 JM |
791 | wep->len[keyidx] = len; |
792 | } else { | |
793 | if (len & 1) | |
794 | return -1; | |
795 | len /= 2; | |
796 | wep->key[keyidx] = os_malloc(len); | |
797 | if (wep->key[keyidx] == NULL) | |
798 | return -1; | |
799 | wep->len[keyidx] = len; | |
800 | if (hexstr2bin(val, wep->key[keyidx], len) < 0) | |
801 | return -1; | |
802 | } | |
803 | ||
804 | wep->keys_set++; | |
805 | ||
806 | return 0; | |
807 | } | |
808 | ||
809 | ||
857d9422 MM |
810 | static int hostapd_parse_chanlist(struct hostapd_config *conf, char *val) |
811 | { | |
812 | char *pos; | |
813 | ||
814 | /* for backwards compatibility, translate ' ' in conf str to ',' */ | |
815 | pos = val; | |
816 | while (pos) { | |
817 | pos = os_strchr(pos, ' '); | |
818 | if (pos) | |
819 | *pos++ = ','; | |
820 | } | |
821 | if (freq_range_list_parse(&conf->acs_ch_list, val)) | |
822 | return -1; | |
823 | ||
824 | return 0; | |
825 | } | |
826 | ||
827 | ||
732118ec | 828 | static int hostapd_parse_intlist(int **int_list, char *val) |
41d719d6 JM |
829 | { |
830 | int *list; | |
831 | int count; | |
832 | char *pos, *end; | |
833 | ||
732118ec SW |
834 | os_free(*int_list); |
835 | *int_list = NULL; | |
41d719d6 JM |
836 | |
837 | pos = val; | |
838 | count = 0; | |
839 | while (*pos != '\0') { | |
840 | if (*pos == ' ') | |
841 | count++; | |
842 | pos++; | |
843 | } | |
844 | ||
845 | list = os_malloc(sizeof(int) * (count + 2)); | |
846 | if (list == NULL) | |
847 | return -1; | |
848 | pos = val; | |
849 | count = 0; | |
850 | while (*pos != '\0') { | |
851 | end = os_strchr(pos, ' '); | |
852 | if (end) | |
853 | *end = '\0'; | |
854 | ||
855 | list[count++] = atoi(pos); | |
856 | if (!end) | |
857 | break; | |
858 | pos = end + 1; | |
859 | } | |
860 | list[count] = -1; | |
861 | ||
732118ec | 862 | *int_list = list; |
41d719d6 JM |
863 | return 0; |
864 | } | |
865 | ||
866 | ||
867 | static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname) | |
868 | { | |
ebd79f07 | 869 | struct hostapd_bss_config **all, *bss; |
41d719d6 JM |
870 | |
871 | if (*ifname == '\0') | |
872 | return -1; | |
873 | ||
ebd79f07 JM |
874 | all = os_realloc_array(conf->bss, conf->num_bss + 1, |
875 | sizeof(struct hostapd_bss_config *)); | |
876 | if (all == NULL) { | |
41d719d6 JM |
877 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
878 | "multi-BSS entry"); | |
879 | return -1; | |
880 | } | |
ebd79f07 | 881 | conf->bss = all; |
41d719d6 | 882 | |
2fe210ce JM |
883 | bss = os_zalloc(sizeof(*bss)); |
884 | if (bss == NULL) | |
885 | return -1; | |
41d719d6 JM |
886 | bss->radius = os_zalloc(sizeof(*bss->radius)); |
887 | if (bss->radius == NULL) { | |
888 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " | |
889 | "multi-BSS RADIUS data"); | |
2fe210ce | 890 | os_free(bss); |
41d719d6 JM |
891 | return -1; |
892 | } | |
893 | ||
2fe210ce | 894 | conf->bss[conf->num_bss++] = bss; |
41d719d6 JM |
895 | conf->last_bss = bss; |
896 | ||
897 | hostapd_config_defaults_bss(bss); | |
898 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); | |
899 | os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); | |
900 | ||
901 | return 0; | |
902 | } | |
903 | ||
904 | ||
905 | /* convert floats with one decimal place to value*10 int, i.e., | |
906 | * "1.5" will return 15 */ | |
907 | static int hostapd_config_read_int10(const char *value) | |
908 | { | |
909 | int i, d; | |
910 | char *pos; | |
911 | ||
912 | i = atoi(value); | |
913 | pos = os_strchr(value, '.'); | |
914 | d = 0; | |
915 | if (pos) { | |
916 | pos++; | |
917 | if (*pos >= '0' && *pos <= '9') | |
918 | d = *pos - '0'; | |
919 | } | |
920 | ||
921 | return i * 10 + d; | |
922 | } | |
923 | ||
924 | ||
925 | static int valid_cw(int cw) | |
926 | { | |
927 | return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || | |
6c731491 JM |
928 | cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023 || |
929 | cw == 2047 || cw == 4095 || cw == 8191 || cw == 16383 || | |
930 | cw == 32767); | |
41d719d6 JM |
931 | } |
932 | ||
933 | ||
934 | enum { | |
935 | IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ | |
936 | IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ | |
937 | IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ | |
7e3c1781 | 938 | IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */ |
41d719d6 JM |
939 | }; |
940 | ||
63e169e1 JM |
941 | static int hostapd_config_tx_queue(struct hostapd_config *conf, |
942 | const char *name, const char *val) | |
41d719d6 JM |
943 | { |
944 | int num; | |
63e169e1 | 945 | const char *pos; |
41d719d6 JM |
946 | struct hostapd_tx_queue_params *queue; |
947 | ||
948 | /* skip 'tx_queue_' prefix */ | |
949 | pos = name + 9; | |
950 | if (os_strncmp(pos, "data", 4) == 0 && | |
951 | pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') { | |
952 | num = pos[4] - '0'; | |
953 | pos += 6; | |
7e3c1781 JM |
954 | } else if (os_strncmp(pos, "after_beacon_", 13) == 0 || |
955 | os_strncmp(pos, "beacon_", 7) == 0) { | |
956 | wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); | |
957 | return 0; | |
41d719d6 JM |
958 | } else { |
959 | wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); | |
960 | return -1; | |
961 | } | |
962 | ||
7e3c1781 | 963 | if (num >= NUM_TX_QUEUES) { |
d2da2249 | 964 | /* for backwards compatibility, do not trigger failure */ |
7e3c1781 JM |
965 | wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); |
966 | return 0; | |
967 | } | |
968 | ||
41d719d6 JM |
969 | queue = &conf->tx_queue[num]; |
970 | ||
971 | if (os_strcmp(pos, "aifs") == 0) { | |
972 | queue->aifs = atoi(val); | |
973 | if (queue->aifs < 0 || queue->aifs > 255) { | |
974 | wpa_printf(MSG_ERROR, "Invalid AIFS value %d", | |
975 | queue->aifs); | |
976 | return -1; | |
977 | } | |
978 | } else if (os_strcmp(pos, "cwmin") == 0) { | |
979 | queue->cwmin = atoi(val); | |
980 | if (!valid_cw(queue->cwmin)) { | |
981 | wpa_printf(MSG_ERROR, "Invalid cwMin value %d", | |
982 | queue->cwmin); | |
983 | return -1; | |
984 | } | |
985 | } else if (os_strcmp(pos, "cwmax") == 0) { | |
986 | queue->cwmax = atoi(val); | |
987 | if (!valid_cw(queue->cwmax)) { | |
988 | wpa_printf(MSG_ERROR, "Invalid cwMax value %d", | |
989 | queue->cwmax); | |
990 | return -1; | |
991 | } | |
992 | } else if (os_strcmp(pos, "burst") == 0) { | |
993 | queue->burst = hostapd_config_read_int10(val); | |
994 | } else { | |
995 | wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); | |
996 | return -1; | |
997 | } | |
998 | ||
41d719d6 JM |
999 | return 0; |
1000 | } | |
1001 | ||
1002 | ||
d503eeea | 1003 | #ifdef CONFIG_IEEE80211R_AP |
245fc96e MB |
1004 | |
1005 | static int rkh_derive_key(const char *pos, u8 *key, size_t key_len) | |
1006 | { | |
1007 | u8 oldkey[16]; | |
1008 | int ret; | |
1009 | ||
1010 | if (!hexstr2bin(pos, key, key_len)) | |
1011 | return 0; | |
1012 | ||
1013 | /* Try to use old short key for backwards compatibility */ | |
1014 | if (hexstr2bin(pos, oldkey, sizeof(oldkey))) | |
1015 | return -1; | |
1016 | ||
1017 | ret = hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0, | |
1018 | key, key_len); | |
1019 | os_memset(oldkey, 0, sizeof(oldkey)); | |
1020 | return ret; | |
1021 | } | |
1022 | ||
1023 | ||
41d719d6 JM |
1024 | static int add_r0kh(struct hostapd_bss_config *bss, char *value) |
1025 | { | |
1026 | struct ft_remote_r0kh *r0kh; | |
1027 | char *pos, *next; | |
1028 | ||
1029 | r0kh = os_zalloc(sizeof(*r0kh)); | |
1030 | if (r0kh == NULL) | |
1031 | return -1; | |
1032 | ||
1033 | /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ | |
1034 | pos = value; | |
1035 | next = os_strchr(pos, ' '); | |
1036 | if (next) | |
1037 | *next++ = '\0'; | |
1038 | if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { | |
1039 | wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); | |
1040 | os_free(r0kh); | |
1041 | return -1; | |
1042 | } | |
1043 | ||
1044 | pos = next; | |
1045 | next = os_strchr(pos, ' '); | |
1046 | if (next) | |
1047 | *next++ = '\0'; | |
1048 | if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { | |
1049 | wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); | |
1050 | os_free(r0kh); | |
1051 | return -1; | |
1052 | } | |
1053 | r0kh->id_len = next - pos - 1; | |
1054 | os_memcpy(r0kh->id, pos, r0kh->id_len); | |
1055 | ||
1056 | pos = next; | |
245fc96e | 1057 | if (rkh_derive_key(pos, r0kh->key, sizeof(r0kh->key)) < 0) { |
41d719d6 JM |
1058 | wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); |
1059 | os_free(r0kh); | |
1060 | return -1; | |
1061 | } | |
1062 | ||
1063 | r0kh->next = bss->r0kh_list; | |
1064 | bss->r0kh_list = r0kh; | |
1065 | ||
1066 | return 0; | |
1067 | } | |
1068 | ||
1069 | ||
1070 | static int add_r1kh(struct hostapd_bss_config *bss, char *value) | |
1071 | { | |
1072 | struct ft_remote_r1kh *r1kh; | |
1073 | char *pos, *next; | |
1074 | ||
1075 | r1kh = os_zalloc(sizeof(*r1kh)); | |
1076 | if (r1kh == NULL) | |
1077 | return -1; | |
1078 | ||
1079 | /* 02:01:02:03:04:05 02:01:02:03:04:05 | |
1080 | * 000102030405060708090a0b0c0d0e0f */ | |
1081 | pos = value; | |
1082 | next = os_strchr(pos, ' '); | |
1083 | if (next) | |
1084 | *next++ = '\0'; | |
1085 | if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { | |
1086 | wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); | |
1087 | os_free(r1kh); | |
1088 | return -1; | |
1089 | } | |
1090 | ||
1091 | pos = next; | |
1092 | next = os_strchr(pos, ' '); | |
1093 | if (next) | |
1094 | *next++ = '\0'; | |
1095 | if (next == NULL || hwaddr_aton(pos, r1kh->id)) { | |
1096 | wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); | |
1097 | os_free(r1kh); | |
1098 | return -1; | |
1099 | } | |
1100 | ||
1101 | pos = next; | |
245fc96e | 1102 | if (rkh_derive_key(pos, r1kh->key, sizeof(r1kh->key)) < 0) { |
41d719d6 JM |
1103 | wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); |
1104 | os_free(r1kh); | |
1105 | return -1; | |
1106 | } | |
1107 | ||
1108 | r1kh->next = bss->r1kh_list; | |
1109 | bss->r1kh_list = r1kh; | |
1110 | ||
1111 | return 0; | |
1112 | } | |
d503eeea | 1113 | #endif /* CONFIG_IEEE80211R_AP */ |
41d719d6 JM |
1114 | |
1115 | ||
1116 | #ifdef CONFIG_IEEE80211N | |
1117 | static int hostapd_config_ht_capab(struct hostapd_config *conf, | |
1118 | const char *capab) | |
1119 | { | |
1120 | if (os_strstr(capab, "[LDPC]")) | |
1121 | conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; | |
1122 | if (os_strstr(capab, "[HT40-]")) { | |
1123 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; | |
1124 | conf->secondary_channel = -1; | |
1125 | } | |
1126 | if (os_strstr(capab, "[HT40+]")) { | |
1127 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; | |
1128 | conf->secondary_channel = 1; | |
1129 | } | |
ec27b04e PX |
1130 | if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) { |
1131 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; | |
1132 | conf->ht40_plus_minus_allowed = 1; | |
1133 | } | |
41d719d6 JM |
1134 | if (os_strstr(capab, "[SMPS-STATIC]")) { |
1135 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; | |
1136 | conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; | |
1137 | } | |
1138 | if (os_strstr(capab, "[SMPS-DYNAMIC]")) { | |
1139 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; | |
1140 | conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; | |
1141 | } | |
1142 | if (os_strstr(capab, "[GF]")) | |
1143 | conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; | |
1144 | if (os_strstr(capab, "[SHORT-GI-20]")) | |
1145 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; | |
1146 | if (os_strstr(capab, "[SHORT-GI-40]")) | |
1147 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; | |
1148 | if (os_strstr(capab, "[TX-STBC]")) | |
1149 | conf->ht_capab |= HT_CAP_INFO_TX_STBC; | |
1150 | if (os_strstr(capab, "[RX-STBC1]")) { | |
1151 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1152 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; | |
1153 | } | |
1154 | if (os_strstr(capab, "[RX-STBC12]")) { | |
1155 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1156 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; | |
1157 | } | |
1158 | if (os_strstr(capab, "[RX-STBC123]")) { | |
1159 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1160 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; | |
1161 | } | |
1162 | if (os_strstr(capab, "[DELAYED-BA]")) | |
1163 | conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; | |
1164 | if (os_strstr(capab, "[MAX-AMSDU-7935]")) | |
1165 | conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; | |
1166 | if (os_strstr(capab, "[DSSS_CCK-40]")) | |
1167 | conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; | |
b7a8d67f JM |
1168 | if (os_strstr(capab, "[40-INTOLERANT]")) |
1169 | conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT; | |
41d719d6 JM |
1170 | if (os_strstr(capab, "[LSIG-TXOP-PROT]")) |
1171 | conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; | |
1172 | ||
1173 | return 0; | |
1174 | } | |
1175 | #endif /* CONFIG_IEEE80211N */ | |
1176 | ||
1177 | ||
efe45d14 MP |
1178 | #ifdef CONFIG_IEEE80211AC |
1179 | static int hostapd_config_vht_capab(struct hostapd_config *conf, | |
1180 | const char *capab) | |
1181 | { | |
1182 | if (os_strstr(capab, "[MAX-MPDU-7991]")) | |
1183 | conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991; | |
1184 | if (os_strstr(capab, "[MAX-MPDU-11454]")) | |
1185 | conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454; | |
1186 | if (os_strstr(capab, "[VHT160]")) | |
1187 | conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; | |
1188 | if (os_strstr(capab, "[VHT160-80PLUS80]")) | |
1189 | conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; | |
efe45d14 MP |
1190 | if (os_strstr(capab, "[RXLDPC]")) |
1191 | conf->vht_capab |= VHT_CAP_RXLDPC; | |
1192 | if (os_strstr(capab, "[SHORT-GI-80]")) | |
1193 | conf->vht_capab |= VHT_CAP_SHORT_GI_80; | |
1194 | if (os_strstr(capab, "[SHORT-GI-160]")) | |
1195 | conf->vht_capab |= VHT_CAP_SHORT_GI_160; | |
1196 | if (os_strstr(capab, "[TX-STBC-2BY1]")) | |
1197 | conf->vht_capab |= VHT_CAP_TXSTBC; | |
1198 | if (os_strstr(capab, "[RX-STBC-1]")) | |
1199 | conf->vht_capab |= VHT_CAP_RXSTBC_1; | |
1200 | if (os_strstr(capab, "[RX-STBC-12]")) | |
1201 | conf->vht_capab |= VHT_CAP_RXSTBC_2; | |
1202 | if (os_strstr(capab, "[RX-STBC-123]")) | |
1203 | conf->vht_capab |= VHT_CAP_RXSTBC_3; | |
1204 | if (os_strstr(capab, "[RX-STBC-1234]")) | |
1205 | conf->vht_capab |= VHT_CAP_RXSTBC_4; | |
1206 | if (os_strstr(capab, "[SU-BEAMFORMER]")) | |
7066a8e7 | 1207 | conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE; |
efe45d14 | 1208 | if (os_strstr(capab, "[SU-BEAMFORMEE]")) |
7066a8e7 | 1209 | conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE; |
efe45d14 | 1210 | if (os_strstr(capab, "[BF-ANTENNA-2]") && |
b29b012c EP |
1211 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) |
1212 | conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET); | |
442ffc51 VN |
1213 | if (os_strstr(capab, "[BF-ANTENNA-3]") && |
1214 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) | |
1215 | conf->vht_capab |= (2 << VHT_CAP_BEAMFORMEE_STS_OFFSET); | |
1216 | if (os_strstr(capab, "[BF-ANTENNA-4]") && | |
1217 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) | |
1218 | conf->vht_capab |= (3 << VHT_CAP_BEAMFORMEE_STS_OFFSET); | |
efe45d14 | 1219 | if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") && |
b29b012c EP |
1220 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) |
1221 | conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); | |
442ffc51 VN |
1222 | if (os_strstr(capab, "[SOUNDING-DIMENSION-3]") && |
1223 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) | |
1224 | conf->vht_capab |= (2 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); | |
1225 | if (os_strstr(capab, "[SOUNDING-DIMENSION-4]") && | |
1226 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) | |
1227 | conf->vht_capab |= (3 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); | |
efe45d14 MP |
1228 | if (os_strstr(capab, "[MU-BEAMFORMER]")) |
1229 | conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE; | |
efe45d14 MP |
1230 | if (os_strstr(capab, "[VHT-TXOP-PS]")) |
1231 | conf->vht_capab |= VHT_CAP_VHT_TXOP_PS; | |
1232 | if (os_strstr(capab, "[HTC-VHT]")) | |
1233 | conf->vht_capab |= VHT_CAP_HTC_VHT; | |
905828fe BM |
1234 | if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]")) |
1235 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX; | |
1236 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]")) | |
1237 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6; | |
1238 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]")) | |
1239 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5; | |
1240 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]")) | |
1241 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4; | |
1242 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]")) | |
1243 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3; | |
1244 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]")) | |
1245 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2; | |
1246 | else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]")) | |
1247 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1; | |
efe45d14 MP |
1248 | if (os_strstr(capab, "[VHT-LINK-ADAPT2]") && |
1249 | (conf->vht_capab & VHT_CAP_HTC_VHT)) | |
1250 | conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB; | |
1251 | if (os_strstr(capab, "[VHT-LINK-ADAPT3]") && | |
1252 | (conf->vht_capab & VHT_CAP_HTC_VHT)) | |
1253 | conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; | |
1254 | if (os_strstr(capab, "[RX-ANTENNA-PATTERN]")) | |
1255 | conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN; | |
1256 | if (os_strstr(capab, "[TX-ANTENNA-PATTERN]")) | |
1257 | conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN; | |
1258 | return 0; | |
1259 | } | |
1260 | #endif /* CONFIG_IEEE80211AC */ | |
1261 | ||
1262 | ||
4b2a77ab JM |
1263 | #ifdef CONFIG_INTERWORKING |
1264 | static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos, | |
1265 | int line) | |
1266 | { | |
1267 | size_t len = os_strlen(pos); | |
1268 | u8 oi[MAX_ROAMING_CONSORTIUM_LEN]; | |
1269 | ||
1270 | struct hostapd_roaming_consortium *rc; | |
1271 | ||
1272 | if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN || | |
1273 | hexstr2bin(pos, oi, len / 2)) { | |
1274 | wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium " | |
1275 | "'%s'", line, pos); | |
1276 | return -1; | |
1277 | } | |
1278 | len /= 2; | |
1279 | ||
067ffa26 JM |
1280 | rc = os_realloc_array(bss->roaming_consortium, |
1281 | bss->roaming_consortium_count + 1, | |
1282 | sizeof(struct hostapd_roaming_consortium)); | |
4b2a77ab JM |
1283 | if (rc == NULL) |
1284 | return -1; | |
1285 | ||
1286 | os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len); | |
1287 | rc[bss->roaming_consortium_count].len = len; | |
1288 | ||
1289 | bss->roaming_consortium = rc; | |
1290 | bss->roaming_consortium_count++; | |
1291 | ||
1292 | return 0; | |
1293 | } | |
648cc711 JM |
1294 | |
1295 | ||
1792e58d JM |
1296 | static int parse_lang_string(struct hostapd_lang_string **array, |
1297 | unsigned int *count, char *pos) | |
648cc711 | 1298 | { |
f224cf05 KP |
1299 | char *sep, *str = NULL; |
1300 | size_t clen, nlen, slen; | |
1792e58d | 1301 | struct hostapd_lang_string *ls; |
f224cf05 KP |
1302 | int ret = -1; |
1303 | ||
1304 | if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) { | |
1305 | str = wpa_config_parse_string(pos, &slen); | |
1306 | if (!str) | |
1307 | return -1; | |
1308 | pos = str; | |
1309 | } | |
648cc711 JM |
1310 | |
1311 | sep = os_strchr(pos, ':'); | |
1312 | if (sep == NULL) | |
f224cf05 | 1313 | goto fail; |
648cc711 JM |
1314 | *sep++ = '\0'; |
1315 | ||
1316 | clen = os_strlen(pos); | |
04e533e2 | 1317 | if (clen < 2 || clen > sizeof(ls->lang)) |
f224cf05 | 1318 | goto fail; |
648cc711 JM |
1319 | nlen = os_strlen(sep); |
1320 | if (nlen > 252) | |
f224cf05 | 1321 | goto fail; |
648cc711 | 1322 | |
1792e58d JM |
1323 | ls = os_realloc_array(*array, *count + 1, |
1324 | sizeof(struct hostapd_lang_string)); | |
1325 | if (ls == NULL) | |
f224cf05 | 1326 | goto fail; |
648cc711 | 1327 | |
1792e58d JM |
1328 | *array = ls; |
1329 | ls = &(*array)[*count]; | |
1330 | (*count)++; | |
648cc711 | 1331 | |
1792e58d JM |
1332 | os_memset(ls->lang, 0, sizeof(ls->lang)); |
1333 | os_memcpy(ls->lang, pos, clen); | |
1334 | ls->name_len = nlen; | |
1335 | os_memcpy(ls->name, sep, nlen); | |
648cc711 | 1336 | |
f224cf05 KP |
1337 | ret = 0; |
1338 | fail: | |
1339 | os_free(str); | |
1340 | return ret; | |
1792e58d JM |
1341 | } |
1342 | ||
648cc711 | 1343 | |
1792e58d JM |
1344 | static int parse_venue_name(struct hostapd_bss_config *bss, char *pos, |
1345 | int line) | |
1346 | { | |
1347 | if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) { | |
1348 | wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'", | |
1349 | line, pos); | |
1350 | return -1; | |
1351 | } | |
1352 | return 0; | |
648cc711 | 1353 | } |
7515adb2 JK |
1354 | |
1355 | ||
1356 | static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf, | |
1357 | int line) | |
1358 | { | |
1359 | size_t count; | |
1360 | char *pos; | |
1361 | u8 *info = NULL, *ipos; | |
1362 | ||
1363 | /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */ | |
1364 | ||
1365 | count = 1; | |
1366 | for (pos = buf; *pos; pos++) { | |
4be20bf9 | 1367 | if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',') |
7515adb2 JK |
1368 | goto fail; |
1369 | if (*pos == ';') | |
1370 | count++; | |
1371 | } | |
1372 | if (1 + count * 3 > 0x7f) | |
1373 | goto fail; | |
1374 | ||
1375 | info = os_zalloc(2 + 3 + count * 3); | |
1376 | if (info == NULL) | |
1377 | return -1; | |
1378 | ||
1379 | ipos = info; | |
1380 | *ipos++ = 0; /* GUD - Version 1 */ | |
1381 | *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */ | |
1382 | *ipos++ = 0; /* PLMN List IEI */ | |
1383 | /* ext(b8) | Length of PLMN List value contents(b7..1) */ | |
1384 | *ipos++ = 1 + count * 3; | |
1385 | *ipos++ = count; /* Number of PLMNs */ | |
1386 | ||
1387 | pos = buf; | |
1388 | while (pos && *pos) { | |
1389 | char *mcc, *mnc; | |
1390 | size_t mnc_len; | |
1391 | ||
1392 | mcc = pos; | |
1393 | mnc = os_strchr(pos, ','); | |
1394 | if (mnc == NULL) | |
1395 | goto fail; | |
1396 | *mnc++ = '\0'; | |
1397 | pos = os_strchr(mnc, ';'); | |
1398 | if (pos) | |
1399 | *pos++ = '\0'; | |
1400 | ||
1401 | mnc_len = os_strlen(mnc); | |
1402 | if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3)) | |
1403 | goto fail; | |
1404 | ||
1405 | /* BC coded MCC,MNC */ | |
1406 | /* MCC digit 2 | MCC digit 1 */ | |
1407 | *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0'); | |
1408 | /* MNC digit 3 | MCC digit 3 */ | |
1409 | *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) | | |
1410 | (mcc[2] - '0'); | |
1411 | /* MNC digit 2 | MNC digit 1 */ | |
1412 | *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0'); | |
1413 | } | |
1414 | ||
1415 | os_free(bss->anqp_3gpp_cell_net); | |
1416 | bss->anqp_3gpp_cell_net = info; | |
1417 | bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count; | |
1418 | wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information", | |
1419 | bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len); | |
1420 | ||
1421 | return 0; | |
1422 | ||
1423 | fail: | |
1424 | wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s", | |
1425 | line, buf); | |
1426 | os_free(info); | |
1427 | return -1; | |
1428 | } | |
1429 | ||
8047b186 JK |
1430 | |
1431 | static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line) | |
1432 | { | |
1433 | struct hostapd_nai_realm_data *realm; | |
1434 | size_t i, j, len; | |
1435 | int *offsets; | |
1436 | char *pos, *end, *rpos; | |
1437 | ||
1438 | offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS, | |
1439 | sizeof(int)); | |
1440 | if (offsets == NULL) | |
1441 | return -1; | |
1442 | ||
1443 | for (i = 0; i < bss->nai_realm_count; i++) { | |
1444 | realm = &bss->nai_realm_data[i]; | |
1445 | for (j = 0; j < MAX_NAI_REALMS; j++) { | |
1446 | offsets[i * MAX_NAI_REALMS + j] = | |
1447 | realm->realm[j] ? | |
1448 | realm->realm[j] - realm->realm_buf : -1; | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1, | |
1453 | sizeof(struct hostapd_nai_realm_data)); | |
1454 | if (realm == NULL) { | |
1455 | os_free(offsets); | |
1456 | return -1; | |
1457 | } | |
1458 | bss->nai_realm_data = realm; | |
1459 | ||
1460 | /* patch the pointers after realloc */ | |
1461 | for (i = 0; i < bss->nai_realm_count; i++) { | |
1462 | realm = &bss->nai_realm_data[i]; | |
1463 | for (j = 0; j < MAX_NAI_REALMS; j++) { | |
1464 | int offs = offsets[i * MAX_NAI_REALMS + j]; | |
1465 | if (offs >= 0) | |
1466 | realm->realm[j] = realm->realm_buf + offs; | |
1467 | else | |
1468 | realm->realm[j] = NULL; | |
1469 | } | |
1470 | } | |
1471 | os_free(offsets); | |
1472 | ||
1473 | realm = &bss->nai_realm_data[bss->nai_realm_count]; | |
1474 | os_memset(realm, 0, sizeof(*realm)); | |
1475 | ||
1476 | pos = buf; | |
1477 | realm->encoding = atoi(pos); | |
1478 | pos = os_strchr(pos, ','); | |
1479 | if (pos == NULL) | |
1480 | goto fail; | |
1481 | pos++; | |
1482 | ||
1483 | end = os_strchr(pos, ','); | |
1484 | if (end) { | |
1485 | len = end - pos; | |
1486 | *end = '\0'; | |
1487 | } else { | |
1488 | len = os_strlen(pos); | |
1489 | } | |
1490 | ||
1491 | if (len > MAX_NAI_REALMLEN) { | |
1492 | wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d " | |
1493 | "characters)", (int) len, MAX_NAI_REALMLEN); | |
1494 | goto fail; | |
1495 | } | |
1496 | os_memcpy(realm->realm_buf, pos, len); | |
1497 | ||
1498 | if (end) | |
1499 | pos = end + 1; | |
1500 | else | |
1501 | pos = NULL; | |
1502 | ||
1503 | while (pos && *pos) { | |
1504 | struct hostapd_nai_realm_eap *eap; | |
1505 | ||
1506 | if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) { | |
1507 | wpa_printf(MSG_ERROR, "Too many EAP methods"); | |
1508 | goto fail; | |
1509 | } | |
1510 | ||
1511 | eap = &realm->eap_method[realm->eap_method_count]; | |
1512 | realm->eap_method_count++; | |
1513 | ||
1514 | end = os_strchr(pos, ','); | |
1515 | if (end == NULL) | |
1516 | end = pos + os_strlen(pos); | |
1517 | ||
1518 | eap->eap_method = atoi(pos); | |
1519 | for (;;) { | |
1520 | pos = os_strchr(pos, '['); | |
1521 | if (pos == NULL || pos > end) | |
1522 | break; | |
1523 | pos++; | |
1524 | if (eap->num_auths >= MAX_NAI_AUTH_TYPES) { | |
1525 | wpa_printf(MSG_ERROR, "Too many auth params"); | |
1526 | goto fail; | |
1527 | } | |
1528 | eap->auth_id[eap->num_auths] = atoi(pos); | |
1529 | pos = os_strchr(pos, ':'); | |
1530 | if (pos == NULL || pos > end) | |
1531 | goto fail; | |
1532 | pos++; | |
1533 | eap->auth_val[eap->num_auths] = atoi(pos); | |
1534 | pos = os_strchr(pos, ']'); | |
1535 | if (pos == NULL || pos > end) | |
1536 | goto fail; | |
1537 | pos++; | |
1538 | eap->num_auths++; | |
1539 | } | |
1540 | ||
1541 | if (*end != ',') | |
1542 | break; | |
1543 | ||
1544 | pos = end + 1; | |
1545 | } | |
1546 | ||
1547 | /* Split realm list into null terminated realms */ | |
1548 | rpos = realm->realm_buf; | |
1549 | i = 0; | |
1550 | while (*rpos) { | |
1551 | if (i >= MAX_NAI_REALMS) { | |
1552 | wpa_printf(MSG_ERROR, "Too many realms"); | |
1553 | goto fail; | |
1554 | } | |
1555 | realm->realm[i++] = rpos; | |
1556 | rpos = os_strchr(rpos, ';'); | |
1557 | if (rpos == NULL) | |
1558 | break; | |
1559 | *rpos++ = '\0'; | |
1560 | } | |
1561 | ||
1562 | bss->nai_realm_count++; | |
1563 | ||
1564 | return 0; | |
1565 | ||
1566 | fail: | |
1567 | wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf); | |
1568 | return -1; | |
1569 | } | |
1570 | ||
c551700f | 1571 | |
695dbbea JM |
1572 | static int parse_anqp_elem(struct hostapd_bss_config *bss, char *buf, int line) |
1573 | { | |
1574 | char *delim; | |
1575 | u16 infoid; | |
1576 | size_t len; | |
1577 | struct wpabuf *payload; | |
1578 | struct anqp_element *elem; | |
1579 | ||
1580 | delim = os_strchr(buf, ':'); | |
1581 | if (!delim) | |
1582 | return -1; | |
1583 | delim++; | |
1584 | infoid = atoi(buf); | |
1585 | len = os_strlen(delim); | |
1586 | if (len & 1) | |
1587 | return -1; | |
1588 | len /= 2; | |
1589 | payload = wpabuf_alloc(len); | |
1590 | if (!payload) | |
1591 | return -1; | |
1592 | if (hexstr2bin(delim, wpabuf_put(payload, len), len) < 0) { | |
1593 | wpabuf_free(payload); | |
1594 | return -1; | |
1595 | } | |
1596 | ||
1597 | dl_list_for_each(elem, &bss->anqp_elem, struct anqp_element, list) { | |
1598 | if (elem->infoid == infoid) { | |
1599 | /* Update existing entry */ | |
1600 | wpabuf_free(elem->payload); | |
1601 | elem->payload = payload; | |
1602 | return 0; | |
1603 | } | |
1604 | } | |
1605 | ||
1606 | /* Add a new entry */ | |
1607 | elem = os_zalloc(sizeof(*elem)); | |
1608 | if (!elem) { | |
1609 | wpabuf_free(payload); | |
1610 | return -1; | |
1611 | } | |
1612 | elem->infoid = infoid; | |
1613 | elem->payload = payload; | |
1614 | dl_list_add(&bss->anqp_elem, &elem->list); | |
1615 | ||
1616 | return 0; | |
1617 | } | |
1618 | ||
1619 | ||
c551700f KP |
1620 | static int parse_qos_map_set(struct hostapd_bss_config *bss, |
1621 | char *buf, int line) | |
1622 | { | |
1623 | u8 qos_map_set[16 + 2 * 21], count = 0; | |
1624 | char *pos = buf; | |
1625 | int val; | |
1626 | ||
1627 | for (;;) { | |
1628 | if (count == sizeof(qos_map_set)) { | |
1629 | wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set " | |
1630 | "parameters '%s'", line, buf); | |
1631 | return -1; | |
1632 | } | |
1633 | ||
1634 | val = atoi(pos); | |
1635 | if (val > 255 || val < 0) { | |
1636 | wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set " | |
1637 | "'%s'", line, buf); | |
1638 | return -1; | |
1639 | } | |
1640 | ||
1641 | qos_map_set[count++] = val; | |
1642 | pos = os_strchr(pos, ','); | |
1643 | if (!pos) | |
1644 | break; | |
1645 | pos++; | |
1646 | } | |
1647 | ||
1648 | if (count < 16 || count & 1) { | |
1649 | wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'", | |
1650 | line, buf); | |
1651 | return -1; | |
1652 | } | |
1653 | ||
1654 | os_memcpy(bss->qos_map_set, qos_map_set, count); | |
1655 | bss->qos_map_set_len = count; | |
1656 | ||
1657 | return 0; | |
1658 | } | |
1659 | ||
4b2a77ab JM |
1660 | #endif /* CONFIG_INTERWORKING */ |
1661 | ||
1662 | ||
5ccc54aa JK |
1663 | #ifdef CONFIG_HS20 |
1664 | static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf, | |
1665 | int line) | |
1666 | { | |
1667 | u8 *conn_cap; | |
1668 | char *pos; | |
1669 | ||
1670 | if (bss->hs20_connection_capability_len >= 0xfff0) | |
1671 | return -1; | |
1672 | ||
1673 | conn_cap = os_realloc(bss->hs20_connection_capability, | |
1674 | bss->hs20_connection_capability_len + 4); | |
1675 | if (conn_cap == NULL) | |
1676 | return -1; | |
1677 | ||
1678 | bss->hs20_connection_capability = conn_cap; | |
1679 | conn_cap += bss->hs20_connection_capability_len; | |
1680 | pos = buf; | |
1681 | conn_cap[0] = atoi(pos); | |
1682 | pos = os_strchr(pos, ':'); | |
1683 | if (pos == NULL) | |
1684 | return -1; | |
1685 | pos++; | |
1686 | WPA_PUT_LE16(conn_cap + 1, atoi(pos)); | |
1687 | pos = os_strchr(pos, ':'); | |
1688 | if (pos == NULL) | |
1689 | return -1; | |
1690 | pos++; | |
1691 | conn_cap[3] = atoi(pos); | |
1692 | bss->hs20_connection_capability_len += 4; | |
1693 | ||
1694 | return 0; | |
1695 | } | |
4065a309 JK |
1696 | |
1697 | ||
1698 | static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf, | |
1699 | int line) | |
1700 | { | |
1701 | u8 *wan_metrics; | |
1702 | char *pos; | |
1703 | ||
1704 | /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */ | |
1705 | ||
1706 | wan_metrics = os_zalloc(13); | |
1707 | if (wan_metrics == NULL) | |
1708 | return -1; | |
1709 | ||
1710 | pos = buf; | |
1711 | /* WAN Info */ | |
1712 | if (hexstr2bin(pos, wan_metrics, 1) < 0) | |
1713 | goto fail; | |
1714 | pos += 2; | |
1715 | if (*pos != ':') | |
1716 | goto fail; | |
1717 | pos++; | |
1718 | ||
1719 | /* Downlink Speed */ | |
1720 | WPA_PUT_LE32(wan_metrics + 1, atoi(pos)); | |
1721 | pos = os_strchr(pos, ':'); | |
1722 | if (pos == NULL) | |
1723 | goto fail; | |
1724 | pos++; | |
1725 | ||
1726 | /* Uplink Speed */ | |
1727 | WPA_PUT_LE32(wan_metrics + 5, atoi(pos)); | |
1728 | pos = os_strchr(pos, ':'); | |
1729 | if (pos == NULL) | |
1730 | goto fail; | |
1731 | pos++; | |
1732 | ||
1733 | /* Downlink Load */ | |
1734 | wan_metrics[9] = atoi(pos); | |
1735 | pos = os_strchr(pos, ':'); | |
1736 | if (pos == NULL) | |
1737 | goto fail; | |
1738 | pos++; | |
1739 | ||
1740 | /* Uplink Load */ | |
1741 | wan_metrics[10] = atoi(pos); | |
1742 | pos = os_strchr(pos, ':'); | |
1743 | if (pos == NULL) | |
1744 | goto fail; | |
1745 | pos++; | |
1746 | ||
1747 | /* LMD */ | |
1748 | WPA_PUT_LE16(wan_metrics + 11, atoi(pos)); | |
1749 | ||
1750 | os_free(bss->hs20_wan_metrics); | |
1751 | bss->hs20_wan_metrics = wan_metrics; | |
1752 | ||
1753 | return 0; | |
1754 | ||
1755 | fail: | |
1756 | wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'", | |
5cfc87b7 | 1757 | line, buf); |
4065a309 JK |
1758 | os_free(wan_metrics); |
1759 | return -1; | |
1760 | } | |
a9277e85 JK |
1761 | |
1762 | ||
1763 | static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss, | |
1764 | char *pos, int line) | |
1765 | { | |
1766 | if (parse_lang_string(&bss->hs20_oper_friendly_name, | |
1767 | &bss->hs20_oper_friendly_name_count, pos)) { | |
1768 | wpa_printf(MSG_ERROR, "Line %d: Invalid " | |
1769 | "hs20_oper_friendly_name '%s'", line, pos); | |
1770 | return -1; | |
1771 | } | |
1772 | return 0; | |
1773 | } | |
f7bd7a01 JM |
1774 | |
1775 | ||
1776 | static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos) | |
1777 | { | |
1778 | struct hs20_icon *icon; | |
1779 | char *end; | |
1780 | ||
1781 | icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1, | |
1782 | sizeof(struct hs20_icon)); | |
1783 | if (icon == NULL) | |
1784 | return -1; | |
1785 | bss->hs20_icons = icon; | |
1786 | icon = &bss->hs20_icons[bss->hs20_icons_count]; | |
1787 | os_memset(icon, 0, sizeof(*icon)); | |
1788 | ||
1789 | icon->width = atoi(pos); | |
1790 | pos = os_strchr(pos, ':'); | |
1791 | if (pos == NULL) | |
1792 | return -1; | |
1793 | pos++; | |
1794 | ||
1795 | icon->height = atoi(pos); | |
1796 | pos = os_strchr(pos, ':'); | |
1797 | if (pos == NULL) | |
1798 | return -1; | |
1799 | pos++; | |
1800 | ||
1801 | end = os_strchr(pos, ':'); | |
1802 | if (end == NULL || end - pos > 3) | |
1803 | return -1; | |
1804 | os_memcpy(icon->language, pos, end - pos); | |
1805 | pos = end + 1; | |
1806 | ||
1807 | end = os_strchr(pos, ':'); | |
1808 | if (end == NULL || end - pos > 255) | |
1809 | return -1; | |
1810 | os_memcpy(icon->type, pos, end - pos); | |
1811 | pos = end + 1; | |
1812 | ||
1813 | end = os_strchr(pos, ':'); | |
1814 | if (end == NULL || end - pos > 255) | |
1815 | return -1; | |
1816 | os_memcpy(icon->name, pos, end - pos); | |
1817 | pos = end + 1; | |
1818 | ||
1819 | if (os_strlen(pos) > 255) | |
1820 | return -1; | |
1821 | os_memcpy(icon->file, pos, os_strlen(pos)); | |
1822 | ||
1823 | bss->hs20_icons_count++; | |
1824 | ||
1825 | return 0; | |
1826 | } | |
1827 | ||
ae6d15c7 JM |
1828 | |
1829 | static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss, | |
1830 | char *pos, int line) | |
1831 | { | |
1832 | size_t slen; | |
1833 | char *str; | |
1834 | ||
1835 | str = wpa_config_parse_string(pos, &slen); | |
81847c22 | 1836 | if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) { |
ae6d15c7 | 1837 | wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos); |
b2e32cde | 1838 | os_free(str); |
ae6d15c7 JM |
1839 | return -1; |
1840 | } | |
1841 | ||
1842 | os_memcpy(bss->osu_ssid, str, slen); | |
1843 | bss->osu_ssid_len = slen; | |
1844 | os_free(str); | |
1845 | ||
1846 | return 0; | |
1847 | } | |
1848 | ||
1849 | ||
1850 | static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss, | |
1851 | char *pos, int line) | |
1852 | { | |
1853 | struct hs20_osu_provider *p; | |
1854 | ||
1855 | p = os_realloc_array(bss->hs20_osu_providers, | |
1856 | bss->hs20_osu_providers_count + 1, sizeof(*p)); | |
1857 | if (p == NULL) | |
1858 | return -1; | |
1859 | ||
1860 | bss->hs20_osu_providers = p; | |
1861 | bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count]; | |
1862 | bss->hs20_osu_providers_count++; | |
1863 | os_memset(bss->last_osu, 0, sizeof(*p)); | |
1864 | bss->last_osu->server_uri = os_strdup(pos); | |
1865 | ||
1866 | return 0; | |
1867 | } | |
1868 | ||
1869 | ||
1870 | static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss, | |
1871 | char *pos, int line) | |
1872 | { | |
1873 | if (bss->last_osu == NULL) { | |
1874 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); | |
1875 | return -1; | |
1876 | } | |
1877 | ||
1878 | if (parse_lang_string(&bss->last_osu->friendly_name, | |
1879 | &bss->last_osu->friendly_name_count, pos)) { | |
1880 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'", | |
1881 | line, pos); | |
1882 | return -1; | |
1883 | } | |
1884 | ||
1885 | return 0; | |
1886 | } | |
1887 | ||
1888 | ||
1889 | static int hs20_parse_osu_nai(struct hostapd_bss_config *bss, | |
1890 | char *pos, int line) | |
1891 | { | |
1892 | if (bss->last_osu == NULL) { | |
1893 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); | |
1894 | return -1; | |
1895 | } | |
1896 | ||
1897 | os_free(bss->last_osu->osu_nai); | |
1898 | bss->last_osu->osu_nai = os_strdup(pos); | |
1899 | if (bss->last_osu->osu_nai == NULL) | |
1900 | return -1; | |
1901 | ||
1902 | return 0; | |
1903 | } | |
1904 | ||
1905 | ||
1906 | static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos, | |
1907 | int line) | |
1908 | { | |
1909 | if (bss->last_osu == NULL) { | |
1910 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); | |
1911 | return -1; | |
1912 | } | |
1913 | ||
1914 | if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) { | |
1915 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line); | |
1916 | return -1; | |
1917 | } | |
1918 | ||
1919 | return 0; | |
1920 | } | |
1921 | ||
1922 | ||
1923 | static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos, | |
1924 | int line) | |
1925 | { | |
1926 | char **n; | |
1927 | struct hs20_osu_provider *p = bss->last_osu; | |
1928 | ||
1929 | if (p == NULL) { | |
1930 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); | |
1931 | return -1; | |
1932 | } | |
1933 | ||
1934 | n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *)); | |
1935 | if (n == NULL) | |
1936 | return -1; | |
1937 | p->icons = n; | |
1938 | p->icons[p->icons_count] = os_strdup(pos); | |
1939 | if (p->icons[p->icons_count] == NULL) | |
1940 | return -1; | |
1941 | p->icons_count++; | |
1942 | ||
1943 | return 0; | |
1944 | } | |
1945 | ||
1946 | ||
1947 | static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss, | |
1948 | char *pos, int line) | |
1949 | { | |
1950 | if (bss->last_osu == NULL) { | |
1951 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); | |
1952 | return -1; | |
1953 | } | |
1954 | ||
1955 | if (parse_lang_string(&bss->last_osu->service_desc, | |
1956 | &bss->last_osu->service_desc_count, pos)) { | |
1957 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'", | |
1958 | line, pos); | |
1959 | return -1; | |
1960 | } | |
1961 | ||
1962 | return 0; | |
1963 | } | |
1964 | ||
5ccc54aa JK |
1965 | #endif /* CONFIG_HS20 */ |
1966 | ||
1967 | ||
68fa00c3 JM |
1968 | #ifdef CONFIG_ACS |
1969 | static int hostapd_config_parse_acs_chan_bias(struct hostapd_config *conf, | |
1970 | char *pos) | |
1971 | { | |
1972 | struct acs_bias *bias = NULL, *tmp; | |
1973 | unsigned int num = 0; | |
1974 | char *end; | |
1975 | ||
1976 | while (*pos) { | |
1977 | tmp = os_realloc_array(bias, num + 1, sizeof(*bias)); | |
1978 | if (!tmp) | |
1979 | goto fail; | |
1980 | bias = tmp; | |
1981 | ||
1982 | bias[num].channel = atoi(pos); | |
1983 | if (bias[num].channel <= 0) | |
1984 | goto fail; | |
1985 | pos = os_strchr(pos, ':'); | |
1986 | if (!pos) | |
1987 | goto fail; | |
1988 | pos++; | |
1989 | bias[num].bias = strtod(pos, &end); | |
1990 | if (end == pos || bias[num].bias < 0.0) | |
1991 | goto fail; | |
1992 | pos = end; | |
1993 | if (*pos != ' ' && *pos != '\0') | |
1994 | goto fail; | |
1995 | num++; | |
1996 | } | |
1997 | ||
1998 | os_free(conf->acs_chan_bias); | |
1999 | conf->acs_chan_bias = bias; | |
2000 | conf->num_acs_chan_bias = num; | |
2001 | ||
2002 | return 0; | |
2003 | fail: | |
2004 | os_free(bias); | |
2005 | return -1; | |
2006 | } | |
2007 | #endif /* CONFIG_ACS */ | |
2008 | ||
2009 | ||
4ac33989 JM |
2010 | static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf, |
2011 | const char *val) | |
2012 | { | |
2013 | struct wpabuf *elems; | |
2014 | ||
2015 | if (val[0] == '\0') { | |
2016 | wpabuf_free(*buf); | |
2017 | *buf = NULL; | |
2018 | return 0; | |
2019 | } | |
2020 | ||
2021 | elems = wpabuf_parse_bin(val); | |
2022 | if (!elems) { | |
2023 | wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'", | |
2024 | line, name, val); | |
2025 | return -1; | |
2026 | } | |
2027 | ||
2028 | wpabuf_free(*buf); | |
2029 | *buf = elems; | |
2030 | ||
2031 | return 0; | |
2032 | } | |
2033 | ||
2034 | ||
26bf70e3 JM |
2035 | #ifdef CONFIG_FILS |
2036 | static int parse_fils_realm(struct hostapd_bss_config *bss, const char *val) | |
2037 | { | |
2038 | struct fils_realm *realm; | |
2039 | size_t len; | |
2040 | ||
2041 | len = os_strlen(val); | |
2042 | realm = os_zalloc(sizeof(*realm) + len + 1); | |
2043 | if (!realm) | |
2044 | return -1; | |
2045 | ||
2046 | os_memcpy(realm->realm, val, len); | |
2047 | if (fils_domain_name_hash(val, realm->hash) < 0) { | |
2048 | os_free(realm); | |
2049 | return -1; | |
2050 | } | |
2051 | dl_list_add_tail(&bss->fils_realms, &realm->list); | |
2052 | ||
2053 | return 0; | |
2054 | } | |
2055 | #endif /* CONFIG_FILS */ | |
2056 | ||
2057 | ||
ef45bc89 SP |
2058 | static int hostapd_config_fill(struct hostapd_config *conf, |
2059 | struct hostapd_bss_config *bss, | |
63e169e1 | 2060 | const char *buf, char *pos, int line) |
41d719d6 | 2061 | { |
599f40db JM |
2062 | if (os_strcmp(buf, "interface") == 0) { |
2063 | os_strlcpy(conf->bss[0]->iface, pos, | |
2064 | sizeof(conf->bss[0]->iface)); | |
2065 | } else if (os_strcmp(buf, "bridge") == 0) { | |
2066 | os_strlcpy(bss->bridge, pos, sizeof(bss->bridge)); | |
2067 | } else if (os_strcmp(buf, "vlan_bridge") == 0) { | |
2068 | os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge)); | |
2069 | } else if (os_strcmp(buf, "wds_bridge") == 0) { | |
2070 | os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge)); | |
2071 | } else if (os_strcmp(buf, "driver") == 0) { | |
2072 | int j; | |
8628555f JM |
2073 | const struct wpa_driver_ops *driver = NULL; |
2074 | ||
599f40db JM |
2075 | for (j = 0; wpa_drivers[j]; j++) { |
2076 | if (os_strcmp(pos, wpa_drivers[j]->name) == 0) { | |
8628555f | 2077 | driver = wpa_drivers[j]; |
599f40db | 2078 | break; |
41d719d6 | 2079 | } |
599f40db | 2080 | } |
8628555f | 2081 | if (!driver) { |
599f40db JM |
2082 | wpa_printf(MSG_ERROR, |
2083 | "Line %d: invalid/unknown driver '%s'", | |
2084 | line, pos); | |
a0b728b7 | 2085 | return 1; |
599f40db | 2086 | } |
8628555f | 2087 | conf->driver = driver; |
0ecff8d7 JM |
2088 | } else if (os_strcmp(buf, "driver_params") == 0) { |
2089 | os_free(conf->driver_params); | |
2090 | conf->driver_params = os_strdup(pos); | |
599f40db JM |
2091 | } else if (os_strcmp(buf, "debug") == 0) { |
2092 | wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore", | |
2093 | line); | |
2094 | } else if (os_strcmp(buf, "logger_syslog_level") == 0) { | |
2095 | bss->logger_syslog_level = atoi(pos); | |
2096 | } else if (os_strcmp(buf, "logger_stdout_level") == 0) { | |
2097 | bss->logger_stdout_level = atoi(pos); | |
2098 | } else if (os_strcmp(buf, "logger_syslog") == 0) { | |
2099 | bss->logger_syslog = atoi(pos); | |
2100 | } else if (os_strcmp(buf, "logger_stdout") == 0) { | |
2101 | bss->logger_stdout = atoi(pos); | |
2102 | } else if (os_strcmp(buf, "dump_file") == 0) { | |
2103 | wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore", | |
2104 | line); | |
2105 | } else if (os_strcmp(buf, "ssid") == 0) { | |
2106 | bss->ssid.ssid_len = os_strlen(pos); | |
81847c22 | 2107 | if (bss->ssid.ssid_len > SSID_MAX_LEN || |
599f40db JM |
2108 | bss->ssid.ssid_len < 1) { |
2109 | wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'", | |
2110 | line, pos); | |
a0b728b7 | 2111 | return 1; |
599f40db | 2112 | } |
b4c26ef9 JM |
2113 | os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len); |
2114 | bss->ssid.ssid_set = 1; | |
599f40db JM |
2115 | } else if (os_strcmp(buf, "ssid2") == 0) { |
2116 | size_t slen; | |
2117 | char *str = wpa_config_parse_string(pos, &slen); | |
81847c22 | 2118 | if (str == NULL || slen < 1 || slen > SSID_MAX_LEN) { |
599f40db JM |
2119 | wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'", |
2120 | line, pos); | |
b2e32cde | 2121 | os_free(str); |
a0b728b7 | 2122 | return 1; |
599f40db | 2123 | } |
b2e32cde JM |
2124 | os_memcpy(bss->ssid.ssid, str, slen); |
2125 | bss->ssid.ssid_len = slen; | |
2126 | bss->ssid.ssid_set = 1; | |
599f40db JM |
2127 | os_free(str); |
2128 | } else if (os_strcmp(buf, "utf8_ssid") == 0) { | |
2129 | bss->ssid.utf8_ssid = atoi(pos) > 0; | |
2130 | } else if (os_strcmp(buf, "macaddr_acl") == 0) { | |
9266d00b JM |
2131 | enum macaddr_acl acl = atoi(pos); |
2132 | ||
2133 | if (acl != ACCEPT_UNLESS_DENIED && | |
2134 | acl != DENY_UNLESS_ACCEPTED && | |
2135 | acl != USE_EXTERNAL_RADIUS_AUTH) { | |
599f40db | 2136 | wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d", |
9266d00b JM |
2137 | line, acl); |
2138 | return 1; | |
599f40db | 2139 | } |
9266d00b | 2140 | bss->macaddr_acl = acl; |
599f40db JM |
2141 | } else if (os_strcmp(buf, "accept_mac_file") == 0) { |
2142 | if (hostapd_config_read_maclist(pos, &bss->accept_mac, | |
2143 | &bss->num_accept_mac)) { | |
2144 | wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'", | |
2145 | line, pos); | |
a0b728b7 | 2146 | return 1; |
599f40db JM |
2147 | } |
2148 | } else if (os_strcmp(buf, "deny_mac_file") == 0) { | |
2149 | if (hostapd_config_read_maclist(pos, &bss->deny_mac, | |
2150 | &bss->num_deny_mac)) { | |
2151 | wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'", | |
2152 | line, pos); | |
a0b728b7 | 2153 | return 1; |
599f40db JM |
2154 | } |
2155 | } else if (os_strcmp(buf, "wds_sta") == 0) { | |
2156 | bss->wds_sta = atoi(pos); | |
2157 | } else if (os_strcmp(buf, "start_disabled") == 0) { | |
2158 | bss->start_disabled = atoi(pos); | |
2159 | } else if (os_strcmp(buf, "ap_isolate") == 0) { | |
2160 | bss->isolate = atoi(pos); | |
2161 | } else if (os_strcmp(buf, "ap_max_inactivity") == 0) { | |
2162 | bss->ap_max_inactivity = atoi(pos); | |
2163 | } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) { | |
2164 | bss->skip_inactivity_poll = atoi(pos); | |
2165 | } else if (os_strcmp(buf, "country_code") == 0) { | |
2166 | os_memcpy(conf->country, pos, 2); | |
ff936bc7 JM |
2167 | } else if (os_strcmp(buf, "country3") == 0) { |
2168 | conf->country[2] = strtol(pos, NULL, 16); | |
599f40db JM |
2169 | } else if (os_strcmp(buf, "ieee80211d") == 0) { |
2170 | conf->ieee80211d = atoi(pos); | |
2171 | } else if (os_strcmp(buf, "ieee80211h") == 0) { | |
2172 | conf->ieee80211h = atoi(pos); | |
2173 | } else if (os_strcmp(buf, "ieee8021x") == 0) { | |
2174 | bss->ieee802_1x = atoi(pos); | |
2175 | } else if (os_strcmp(buf, "eapol_version") == 0) { | |
e0ba7efe JM |
2176 | int eapol_version = atoi(pos); |
2177 | ||
2178 | if (eapol_version < 1 || eapol_version > 2) { | |
599f40db JM |
2179 | wpa_printf(MSG_ERROR, |
2180 | "Line %d: invalid EAPOL version (%d): '%s'.", | |
e0ba7efe | 2181 | line, eapol_version, pos); |
a0b728b7 | 2182 | return 1; |
b4c26ef9 | 2183 | } |
e0ba7efe | 2184 | bss->eapol_version = eapol_version; |
b4c26ef9 | 2185 | wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version); |
41d719d6 | 2186 | #ifdef EAP_SERVER |
599f40db JM |
2187 | } else if (os_strcmp(buf, "eap_authenticator") == 0) { |
2188 | bss->eap_server = atoi(pos); | |
2189 | wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line); | |
2190 | } else if (os_strcmp(buf, "eap_server") == 0) { | |
2191 | bss->eap_server = atoi(pos); | |
2192 | } else if (os_strcmp(buf, "eap_user_file") == 0) { | |
2193 | if (hostapd_config_read_eap_user(pos, bss)) | |
a0b728b7 | 2194 | return 1; |
599f40db JM |
2195 | } else if (os_strcmp(buf, "ca_cert") == 0) { |
2196 | os_free(bss->ca_cert); | |
2197 | bss->ca_cert = os_strdup(pos); | |
2198 | } else if (os_strcmp(buf, "server_cert") == 0) { | |
2199 | os_free(bss->server_cert); | |
2200 | bss->server_cert = os_strdup(pos); | |
2201 | } else if (os_strcmp(buf, "private_key") == 0) { | |
2202 | os_free(bss->private_key); | |
2203 | bss->private_key = os_strdup(pos); | |
2204 | } else if (os_strcmp(buf, "private_key_passwd") == 0) { | |
2205 | os_free(bss->private_key_passwd); | |
2206 | bss->private_key_passwd = os_strdup(pos); | |
2207 | } else if (os_strcmp(buf, "check_crl") == 0) { | |
2208 | bss->check_crl = atoi(pos); | |
681e199d JM |
2209 | } else if (os_strcmp(buf, "tls_session_lifetime") == 0) { |
2210 | bss->tls_session_lifetime = atoi(pos); | |
599f40db JM |
2211 | } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) { |
2212 | os_free(bss->ocsp_stapling_response); | |
2213 | bss->ocsp_stapling_response = os_strdup(pos); | |
5addb0df JM |
2214 | } else if (os_strcmp(buf, "ocsp_stapling_response_multi") == 0) { |
2215 | os_free(bss->ocsp_stapling_response_multi); | |
2216 | bss->ocsp_stapling_response_multi = os_strdup(pos); | |
599f40db JM |
2217 | } else if (os_strcmp(buf, "dh_file") == 0) { |
2218 | os_free(bss->dh_file); | |
2219 | bss->dh_file = os_strdup(pos); | |
f8995f8f JM |
2220 | } else if (os_strcmp(buf, "openssl_ciphers") == 0) { |
2221 | os_free(bss->openssl_ciphers); | |
2222 | bss->openssl_ciphers = os_strdup(pos); | |
599f40db JM |
2223 | } else if (os_strcmp(buf, "fragment_size") == 0) { |
2224 | bss->fragment_size = atoi(pos); | |
41d719d6 | 2225 | #ifdef EAP_SERVER_FAST |
599f40db JM |
2226 | } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) { |
2227 | os_free(bss->pac_opaque_encr_key); | |
2228 | bss->pac_opaque_encr_key = os_malloc(16); | |
2229 | if (bss->pac_opaque_encr_key == NULL) { | |
2230 | wpa_printf(MSG_ERROR, | |
2231 | "Line %d: No memory for pac_opaque_encr_key", | |
2232 | line); | |
a0b728b7 | 2233 | return 1; |
599f40db JM |
2234 | } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) { |
2235 | wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key", | |
2236 | line); | |
a0b728b7 | 2237 | return 1; |
599f40db JM |
2238 | } |
2239 | } else if (os_strcmp(buf, "eap_fast_a_id") == 0) { | |
2240 | size_t idlen = os_strlen(pos); | |
2241 | if (idlen & 1) { | |
2242 | wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id", | |
2243 | line); | |
a0b728b7 | 2244 | return 1; |
b4c26ef9 JM |
2245 | } |
2246 | os_free(bss->eap_fast_a_id); | |
2247 | bss->eap_fast_a_id = os_malloc(idlen / 2); | |
2248 | if (bss->eap_fast_a_id == NULL || | |
2249 | hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) { | |
2250 | wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id", | |
2251 | line); | |
599f40db | 2252 | os_free(bss->eap_fast_a_id); |
b4c26ef9 JM |
2253 | bss->eap_fast_a_id = NULL; |
2254 | return 1; | |
2255 | } else { | |
2256 | bss->eap_fast_a_id_len = idlen / 2; | |
599f40db JM |
2257 | } |
2258 | } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) { | |
2259 | os_free(bss->eap_fast_a_id_info); | |
2260 | bss->eap_fast_a_id_info = os_strdup(pos); | |
2261 | } else if (os_strcmp(buf, "eap_fast_prov") == 0) { | |
2262 | bss->eap_fast_prov = atoi(pos); | |
2263 | } else if (os_strcmp(buf, "pac_key_lifetime") == 0) { | |
2264 | bss->pac_key_lifetime = atoi(pos); | |
2265 | } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) { | |
2266 | bss->pac_key_refresh_time = atoi(pos); | |
41d719d6 JM |
2267 | #endif /* EAP_SERVER_FAST */ |
2268 | #ifdef EAP_SERVER_SIM | |
599f40db JM |
2269 | } else if (os_strcmp(buf, "eap_sim_db") == 0) { |
2270 | os_free(bss->eap_sim_db); | |
2271 | bss->eap_sim_db = os_strdup(pos); | |
7b0f5500 FL |
2272 | } else if (os_strcmp(buf, "eap_sim_db_timeout") == 0) { |
2273 | bss->eap_sim_db_timeout = atoi(pos); | |
599f40db JM |
2274 | } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) { |
2275 | bss->eap_sim_aka_result_ind = atoi(pos); | |
41d719d6 JM |
2276 | #endif /* EAP_SERVER_SIM */ |
2277 | #ifdef EAP_SERVER_TNC | |
599f40db JM |
2278 | } else if (os_strcmp(buf, "tnc") == 0) { |
2279 | bss->tnc = atoi(pos); | |
41d719d6 | 2280 | #endif /* EAP_SERVER_TNC */ |
df684d82 | 2281 | #ifdef EAP_SERVER_PWD |
599f40db JM |
2282 | } else if (os_strcmp(buf, "pwd_group") == 0) { |
2283 | bss->pwd_group = atoi(pos); | |
df684d82 | 2284 | #endif /* EAP_SERVER_PWD */ |
d3bddd8b JM |
2285 | } else if (os_strcmp(buf, "eap_server_erp") == 0) { |
2286 | bss->eap_server_erp = atoi(pos); | |
41d719d6 | 2287 | #endif /* EAP_SERVER */ |
599f40db JM |
2288 | } else if (os_strcmp(buf, "eap_message") == 0) { |
2289 | char *term; | |
5784b9a4 | 2290 | os_free(bss->eap_req_id_text); |
599f40db JM |
2291 | bss->eap_req_id_text = os_strdup(pos); |
2292 | if (bss->eap_req_id_text == NULL) { | |
2293 | wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text", | |
2294 | line); | |
a0b728b7 | 2295 | return 1; |
599f40db JM |
2296 | } |
2297 | bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text); | |
2298 | term = os_strstr(bss->eap_req_id_text, "\\0"); | |
2299 | if (term) { | |
2300 | *term++ = '\0'; | |
2301 | os_memmove(term, term + 1, | |
2302 | bss->eap_req_id_text_len - | |
2303 | (term - bss->eap_req_id_text) - 1); | |
2304 | bss->eap_req_id_text_len--; | |
2305 | } | |
2a5156a6 JM |
2306 | } else if (os_strcmp(buf, "erp_send_reauth_start") == 0) { |
2307 | bss->erp_send_reauth_start = atoi(pos); | |
2308 | } else if (os_strcmp(buf, "erp_domain") == 0) { | |
2309 | os_free(bss->erp_domain); | |
2310 | bss->erp_domain = os_strdup(pos); | |
599f40db | 2311 | } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) { |
f78402ac JM |
2312 | int val = atoi(pos); |
2313 | ||
2314 | if (val < 0 || val > 13) { | |
2315 | wpa_printf(MSG_ERROR, | |
2316 | "Line %d: invalid WEP key len %d (= %d bits)", | |
2317 | line, val, val * 8); | |
a0b728b7 | 2318 | return 1; |
599f40db | 2319 | } |
f78402ac | 2320 | bss->default_wep_key_len = val; |
599f40db | 2321 | } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) { |
a5861afc JM |
2322 | int val = atoi(pos); |
2323 | ||
2324 | if (val < 0 || val > 13) { | |
2325 | wpa_printf(MSG_ERROR, | |
2326 | "Line %d: invalid WEP key len %d (= %d bits)", | |
2327 | line, val, val * 8); | |
a0b728b7 | 2328 | return 1; |
599f40db | 2329 | } |
a5861afc | 2330 | bss->individual_wep_key_len = val; |
599f40db JM |
2331 | } else if (os_strcmp(buf, "wep_rekey_period") == 0) { |
2332 | bss->wep_rekeying_period = atoi(pos); | |
2333 | if (bss->wep_rekeying_period < 0) { | |
2334 | wpa_printf(MSG_ERROR, "Line %d: invalid period %d", | |
2335 | line, bss->wep_rekeying_period); | |
a0b728b7 | 2336 | return 1; |
599f40db JM |
2337 | } |
2338 | } else if (os_strcmp(buf, "eap_reauth_period") == 0) { | |
2339 | bss->eap_reauth_period = atoi(pos); | |
2340 | if (bss->eap_reauth_period < 0) { | |
2341 | wpa_printf(MSG_ERROR, "Line %d: invalid period %d", | |
2342 | line, bss->eap_reauth_period); | |
a0b728b7 | 2343 | return 1; |
599f40db JM |
2344 | } |
2345 | } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) { | |
2346 | bss->eapol_key_index_workaround = atoi(pos); | |
41d719d6 | 2347 | #ifdef CONFIG_IAPP |
599f40db JM |
2348 | } else if (os_strcmp(buf, "iapp_interface") == 0) { |
2349 | bss->ieee802_11f = 1; | |
2350 | os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface)); | |
41d719d6 | 2351 | #endif /* CONFIG_IAPP */ |
599f40db JM |
2352 | } else if (os_strcmp(buf, "own_ip_addr") == 0) { |
2353 | if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) { | |
2354 | wpa_printf(MSG_ERROR, | |
2355 | "Line %d: invalid IP address '%s'", | |
2356 | line, pos); | |
a0b728b7 | 2357 | return 1; |
599f40db JM |
2358 | } |
2359 | } else if (os_strcmp(buf, "nas_identifier") == 0) { | |
5784b9a4 | 2360 | os_free(bss->nas_identifier); |
599f40db | 2361 | bss->nas_identifier = os_strdup(pos); |
41d719d6 | 2362 | #ifndef CONFIG_NO_RADIUS |
9836cb53 JM |
2363 | } else if (os_strcmp(buf, "radius_client_addr") == 0) { |
2364 | if (hostapd_parse_ip_addr(pos, &bss->radius->client_addr)) { | |
2365 | wpa_printf(MSG_ERROR, | |
2366 | "Line %d: invalid IP address '%s'", | |
2367 | line, pos); | |
2368 | return 1; | |
2369 | } | |
2370 | bss->radius->force_client_addr = 1; | |
599f40db JM |
2371 | } else if (os_strcmp(buf, "auth_server_addr") == 0) { |
2372 | if (hostapd_config_read_radius_addr( | |
2373 | &bss->radius->auth_servers, | |
2374 | &bss->radius->num_auth_servers, pos, 1812, | |
2375 | &bss->radius->auth_server)) { | |
2376 | wpa_printf(MSG_ERROR, | |
2377 | "Line %d: invalid IP address '%s'", | |
2378 | line, pos); | |
a0b728b7 | 2379 | return 1; |
599f40db | 2380 | } |
bbee36e3 JM |
2381 | } else if (bss->radius->auth_server && |
2382 | os_strcmp(buf, "auth_server_addr_replace") == 0) { | |
2383 | if (hostapd_parse_ip_addr(pos, | |
2384 | &bss->radius->auth_server->addr)) { | |
2385 | wpa_printf(MSG_ERROR, | |
2386 | "Line %d: invalid IP address '%s'", | |
2387 | line, pos); | |
2388 | return 1; | |
2389 | } | |
599f40db JM |
2390 | } else if (bss->radius->auth_server && |
2391 | os_strcmp(buf, "auth_server_port") == 0) { | |
2392 | bss->radius->auth_server->port = atoi(pos); | |
2393 | } else if (bss->radius->auth_server && | |
2394 | os_strcmp(buf, "auth_server_shared_secret") == 0) { | |
2395 | int len = os_strlen(pos); | |
2396 | if (len == 0) { | |
2397 | /* RFC 2865, Ch. 3 */ | |
2398 | wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed", | |
2399 | line); | |
a0b728b7 | 2400 | return 1; |
599f40db | 2401 | } |
5784b9a4 | 2402 | os_free(bss->radius->auth_server->shared_secret); |
599f40db JM |
2403 | bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos); |
2404 | bss->radius->auth_server->shared_secret_len = len; | |
2405 | } else if (os_strcmp(buf, "acct_server_addr") == 0) { | |
2406 | if (hostapd_config_read_radius_addr( | |
2407 | &bss->radius->acct_servers, | |
2408 | &bss->radius->num_acct_servers, pos, 1813, | |
2409 | &bss->radius->acct_server)) { | |
2410 | wpa_printf(MSG_ERROR, | |
2411 | "Line %d: invalid IP address '%s'", | |
2412 | line, pos); | |
a0b728b7 | 2413 | return 1; |
bbee36e3 JM |
2414 | } |
2415 | } else if (bss->radius->acct_server && | |
2416 | os_strcmp(buf, "acct_server_addr_replace") == 0) { | |
2417 | if (hostapd_parse_ip_addr(pos, | |
2418 | &bss->radius->acct_server->addr)) { | |
2419 | wpa_printf(MSG_ERROR, | |
2420 | "Line %d: invalid IP address '%s'", | |
2421 | line, pos); | |
2422 | return 1; | |
599f40db JM |
2423 | } |
2424 | } else if (bss->radius->acct_server && | |
2425 | os_strcmp(buf, "acct_server_port") == 0) { | |
2426 | bss->radius->acct_server->port = atoi(pos); | |
2427 | } else if (bss->radius->acct_server && | |
2428 | os_strcmp(buf, "acct_server_shared_secret") == 0) { | |
2429 | int len = os_strlen(pos); | |
2430 | if (len == 0) { | |
2431 | /* RFC 2865, Ch. 3 */ | |
2432 | wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed", | |
2433 | line); | |
a0b728b7 | 2434 | return 1; |
599f40db | 2435 | } |
5784b9a4 | 2436 | os_free(bss->radius->acct_server->shared_secret); |
599f40db JM |
2437 | bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos); |
2438 | bss->radius->acct_server->shared_secret_len = len; | |
2439 | } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) { | |
2440 | bss->radius->retry_primary_interval = atoi(pos); | |
2441 | } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) { | |
2442 | bss->acct_interim_interval = atoi(pos); | |
2443 | } else if (os_strcmp(buf, "radius_request_cui") == 0) { | |
2444 | bss->radius_request_cui = atoi(pos); | |
2445 | } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) { | |
2446 | struct hostapd_radius_attr *attr, *a; | |
2447 | attr = hostapd_parse_radius_attr(pos); | |
2448 | if (attr == NULL) { | |
2449 | wpa_printf(MSG_ERROR, | |
2450 | "Line %d: invalid radius_auth_req_attr", | |
2451 | line); | |
a0b728b7 | 2452 | return 1; |
599f40db JM |
2453 | } else if (bss->radius_auth_req_attr == NULL) { |
2454 | bss->radius_auth_req_attr = attr; | |
2455 | } else { | |
2456 | a = bss->radius_auth_req_attr; | |
2457 | while (a->next) | |
2458 | a = a->next; | |
2459 | a->next = attr; | |
2460 | } | |
2461 | } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) { | |
2462 | struct hostapd_radius_attr *attr, *a; | |
2463 | attr = hostapd_parse_radius_attr(pos); | |
2464 | if (attr == NULL) { | |
2465 | wpa_printf(MSG_ERROR, | |
2466 | "Line %d: invalid radius_acct_req_attr", | |
2467 | line); | |
a0b728b7 | 2468 | return 1; |
599f40db JM |
2469 | } else if (bss->radius_acct_req_attr == NULL) { |
2470 | bss->radius_acct_req_attr = attr; | |
2471 | } else { | |
2472 | a = bss->radius_acct_req_attr; | |
2473 | while (a->next) | |
2474 | a = a->next; | |
2475 | a->next = attr; | |
2476 | } | |
2477 | } else if (os_strcmp(buf, "radius_das_port") == 0) { | |
2478 | bss->radius_das_port = atoi(pos); | |
2479 | } else if (os_strcmp(buf, "radius_das_client") == 0) { | |
2480 | if (hostapd_parse_das_client(bss, pos) < 0) { | |
2481 | wpa_printf(MSG_ERROR, "Line %d: invalid DAS client", | |
2482 | line); | |
a0b728b7 | 2483 | return 1; |
599f40db JM |
2484 | } |
2485 | } else if (os_strcmp(buf, "radius_das_time_window") == 0) { | |
2486 | bss->radius_das_time_window = atoi(pos); | |
2487 | } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) { | |
2488 | bss->radius_das_require_event_timestamp = atoi(pos); | |
42d30e9e NL |
2489 | } else if (os_strcmp(buf, "radius_das_require_message_authenticator") == |
2490 | 0) { | |
2491 | bss->radius_das_require_message_authenticator = atoi(pos); | |
41d719d6 | 2492 | #endif /* CONFIG_NO_RADIUS */ |
599f40db JM |
2493 | } else if (os_strcmp(buf, "auth_algs") == 0) { |
2494 | bss->auth_algs = atoi(pos); | |
2495 | if (bss->auth_algs == 0) { | |
2496 | wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed", | |
2497 | line); | |
a0b728b7 | 2498 | return 1; |
599f40db JM |
2499 | } |
2500 | } else if (os_strcmp(buf, "max_num_sta") == 0) { | |
2501 | bss->max_num_sta = atoi(pos); | |
2502 | if (bss->max_num_sta < 0 || | |
2503 | bss->max_num_sta > MAX_STA_COUNT) { | |
2504 | wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d", | |
2505 | line, bss->max_num_sta, MAX_STA_COUNT); | |
a0b728b7 | 2506 | return 1; |
599f40db JM |
2507 | } |
2508 | } else if (os_strcmp(buf, "wpa") == 0) { | |
2509 | bss->wpa = atoi(pos); | |
2510 | } else if (os_strcmp(buf, "wpa_group_rekey") == 0) { | |
2511 | bss->wpa_group_rekey = atoi(pos); | |
2512 | } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) { | |
2513 | bss->wpa_strict_rekey = atoi(pos); | |
2514 | } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) { | |
2515 | bss->wpa_gmk_rekey = atoi(pos); | |
2516 | } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) { | |
2517 | bss->wpa_ptk_rekey = atoi(pos); | |
41f140d3 GK |
2518 | } else if (os_strcmp(buf, "wpa_group_update_count") == 0) { |
2519 | char *endp; | |
2520 | unsigned long val = strtoul(pos, &endp, 0); | |
2521 | ||
2522 | if (*endp || val < 1 || val > (u32) -1) { | |
2523 | wpa_printf(MSG_ERROR, | |
2524 | "Line %d: Invalid wpa_group_update_count=%lu; allowed range 1..4294967295", | |
2525 | line, val); | |
2526 | return 1; | |
2527 | } | |
2528 | bss->wpa_group_update_count = (u32) val; | |
2529 | } else if (os_strcmp(buf, "wpa_pairwise_update_count") == 0) { | |
2530 | char *endp; | |
2531 | unsigned long val = strtoul(pos, &endp, 0); | |
2532 | ||
2533 | if (*endp || val < 1 || val > (u32) -1) { | |
2534 | wpa_printf(MSG_ERROR, | |
2535 | "Line %d: Invalid wpa_pairwise_update_count=%lu; allowed range 1..4294967295", | |
2536 | line, val); | |
2537 | return 1; | |
2538 | } | |
2539 | bss->wpa_pairwise_update_count = (u32) val; | |
599f40db JM |
2540 | } else if (os_strcmp(buf, "wpa_passphrase") == 0) { |
2541 | int len = os_strlen(pos); | |
2542 | if (len < 8 || len > 63) { | |
2543 | wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)", | |
2544 | line, len); | |
a0b728b7 | 2545 | return 1; |
b4c26ef9 JM |
2546 | } |
2547 | os_free(bss->ssid.wpa_passphrase); | |
2548 | bss->ssid.wpa_passphrase = os_strdup(pos); | |
2549 | if (bss->ssid.wpa_passphrase) { | |
891dfb33 | 2550 | hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk); |
b4c26ef9 | 2551 | bss->ssid.wpa_passphrase_set = 1; |
599f40db JM |
2552 | } |
2553 | } else if (os_strcmp(buf, "wpa_psk") == 0) { | |
891dfb33 | 2554 | hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk); |
599f40db JM |
2555 | bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); |
2556 | if (bss->ssid.wpa_psk == NULL) | |
a0b728b7 | 2557 | return 1; |
b4c26ef9 JM |
2558 | if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) || |
2559 | pos[PMK_LEN * 2] != '\0') { | |
599f40db JM |
2560 | wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.", |
2561 | line, pos); | |
891dfb33 | 2562 | hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk); |
a0b728b7 | 2563 | return 1; |
599f40db | 2564 | } |
b4c26ef9 JM |
2565 | bss->ssid.wpa_psk->group = 1; |
2566 | os_free(bss->ssid.wpa_passphrase); | |
2567 | bss->ssid.wpa_passphrase = NULL; | |
2568 | bss->ssid.wpa_psk_set = 1; | |
599f40db JM |
2569 | } else if (os_strcmp(buf, "wpa_psk_file") == 0) { |
2570 | os_free(bss->ssid.wpa_psk_file); | |
2571 | bss->ssid.wpa_psk_file = os_strdup(pos); | |
2572 | if (!bss->ssid.wpa_psk_file) { | |
2573 | wpa_printf(MSG_ERROR, "Line %d: allocation failed", | |
2574 | line); | |
a0b728b7 | 2575 | return 1; |
599f40db JM |
2576 | } |
2577 | } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) { | |
2578 | bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos); | |
2579 | if (bss->wpa_key_mgmt == -1) | |
a0b728b7 | 2580 | return 1; |
599f40db JM |
2581 | } else if (os_strcmp(buf, "wpa_psk_radius") == 0) { |
2582 | bss->wpa_psk_radius = atoi(pos); | |
2583 | if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED && | |
2584 | bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED && | |
2585 | bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) { | |
2586 | wpa_printf(MSG_ERROR, | |
2587 | "Line %d: unknown wpa_psk_radius %d", | |
2588 | line, bss->wpa_psk_radius); | |
a0b728b7 | 2589 | return 1; |
599f40db JM |
2590 | } |
2591 | } else if (os_strcmp(buf, "wpa_pairwise") == 0) { | |
2592 | bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos); | |
2593 | if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0) | |
a0b728b7 | 2594 | return 1; |
b4c26ef9 JM |
2595 | if (bss->wpa_pairwise & |
2596 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) { | |
599f40db JM |
2597 | wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'", |
2598 | bss->wpa_pairwise, pos); | |
a0b728b7 | 2599 | return 1; |
599f40db JM |
2600 | } |
2601 | } else if (os_strcmp(buf, "rsn_pairwise") == 0) { | |
2602 | bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos); | |
2603 | if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0) | |
a0b728b7 | 2604 | return 1; |
b4c26ef9 JM |
2605 | if (bss->rsn_pairwise & |
2606 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) { | |
599f40db JM |
2607 | wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'", |
2608 | bss->rsn_pairwise, pos); | |
a0b728b7 | 2609 | return 1; |
599f40db | 2610 | } |
41d719d6 | 2611 | #ifdef CONFIG_RSN_PREAUTH |
599f40db JM |
2612 | } else if (os_strcmp(buf, "rsn_preauth") == 0) { |
2613 | bss->rsn_preauth = atoi(pos); | |
2614 | } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) { | |
5784b9a4 | 2615 | os_free(bss->rsn_preauth_interfaces); |
599f40db | 2616 | bss->rsn_preauth_interfaces = os_strdup(pos); |
41d719d6 JM |
2617 | #endif /* CONFIG_RSN_PREAUTH */ |
2618 | #ifdef CONFIG_PEERKEY | |
599f40db JM |
2619 | } else if (os_strcmp(buf, "peerkey") == 0) { |
2620 | bss->peerkey = atoi(pos); | |
41d719d6 | 2621 | #endif /* CONFIG_PEERKEY */ |
d503eeea | 2622 | #ifdef CONFIG_IEEE80211R_AP |
599f40db JM |
2623 | } else if (os_strcmp(buf, "mobility_domain") == 0) { |
2624 | if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN || | |
2625 | hexstr2bin(pos, bss->mobility_domain, | |
2626 | MOBILITY_DOMAIN_ID_LEN) != 0) { | |
2627 | wpa_printf(MSG_ERROR, | |
2628 | "Line %d: Invalid mobility_domain '%s'", | |
2629 | line, pos); | |
a0b728b7 | 2630 | return 1; |
599f40db JM |
2631 | } |
2632 | } else if (os_strcmp(buf, "r1_key_holder") == 0) { | |
2633 | if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN || | |
2634 | hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) { | |
2635 | wpa_printf(MSG_ERROR, | |
2636 | "Line %d: Invalid r1_key_holder '%s'", | |
2637 | line, pos); | |
a0b728b7 | 2638 | return 1; |
599f40db JM |
2639 | } |
2640 | } else if (os_strcmp(buf, "r0_key_lifetime") == 0) { | |
2641 | bss->r0_key_lifetime = atoi(pos); | |
2642 | } else if (os_strcmp(buf, "reassociation_deadline") == 0) { | |
2643 | bss->reassociation_deadline = atoi(pos); | |
2644 | } else if (os_strcmp(buf, "r0kh") == 0) { | |
2645 | if (add_r0kh(bss, pos) < 0) { | |
2646 | wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'", | |
2647 | line, pos); | |
a0b728b7 | 2648 | return 1; |
599f40db JM |
2649 | } |
2650 | } else if (os_strcmp(buf, "r1kh") == 0) { | |
2651 | if (add_r1kh(bss, pos) < 0) { | |
2652 | wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'", | |
2653 | line, pos); | |
a0b728b7 | 2654 | return 1; |
599f40db JM |
2655 | } |
2656 | } else if (os_strcmp(buf, "pmk_r1_push") == 0) { | |
2657 | bss->pmk_r1_push = atoi(pos); | |
2658 | } else if (os_strcmp(buf, "ft_over_ds") == 0) { | |
2659 | bss->ft_over_ds = atoi(pos); | |
96590564 MB |
2660 | } else if (os_strcmp(buf, "ft_psk_generate_local") == 0) { |
2661 | bss->ft_psk_generate_local = atoi(pos); | |
d503eeea | 2662 | #endif /* CONFIG_IEEE80211R_AP */ |
41d719d6 | 2663 | #ifndef CONFIG_NO_CTRL_IFACE |
599f40db JM |
2664 | } else if (os_strcmp(buf, "ctrl_interface") == 0) { |
2665 | os_free(bss->ctrl_interface); | |
2666 | bss->ctrl_interface = os_strdup(pos); | |
2667 | } else if (os_strcmp(buf, "ctrl_interface_group") == 0) { | |
41d719d6 | 2668 | #ifndef CONFIG_NATIVE_WINDOWS |
599f40db JM |
2669 | struct group *grp; |
2670 | char *endp; | |
2671 | const char *group = pos; | |
41d719d6 | 2672 | |
599f40db JM |
2673 | grp = getgrnam(group); |
2674 | if (grp) { | |
2675 | bss->ctrl_interface_gid = grp->gr_gid; | |
41d719d6 | 2676 | bss->ctrl_interface_gid_set = 1; |
599f40db JM |
2677 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')", |
2678 | bss->ctrl_interface_gid, group); | |
2679 | return 0; | |
2680 | } | |
2681 | ||
2682 | /* Group name not found - try to parse this as gid */ | |
2683 | bss->ctrl_interface_gid = strtol(group, &endp, 10); | |
2684 | if (*group == '\0' || *endp != '\0') { | |
2685 | wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'", | |
2686 | line, group); | |
2687 | return 1; | |
2688 | } | |
2689 | bss->ctrl_interface_gid_set = 1; | |
2690 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d", | |
2691 | bss->ctrl_interface_gid); | |
41d719d6 JM |
2692 | #endif /* CONFIG_NATIVE_WINDOWS */ |
2693 | #endif /* CONFIG_NO_CTRL_IFACE */ | |
2694 | #ifdef RADIUS_SERVER | |
599f40db JM |
2695 | } else if (os_strcmp(buf, "radius_server_clients") == 0) { |
2696 | os_free(bss->radius_server_clients); | |
2697 | bss->radius_server_clients = os_strdup(pos); | |
2698 | } else if (os_strcmp(buf, "radius_server_auth_port") == 0) { | |
2699 | bss->radius_server_auth_port = atoi(pos); | |
2700 | } else if (os_strcmp(buf, "radius_server_acct_port") == 0) { | |
2701 | bss->radius_server_acct_port = atoi(pos); | |
2702 | } else if (os_strcmp(buf, "radius_server_ipv6") == 0) { | |
2703 | bss->radius_server_ipv6 = atoi(pos); | |
41d719d6 | 2704 | #endif /* RADIUS_SERVER */ |
599f40db JM |
2705 | } else if (os_strcmp(buf, "use_pae_group_addr") == 0) { |
2706 | bss->use_pae_group_addr = atoi(pos); | |
2707 | } else if (os_strcmp(buf, "hw_mode") == 0) { | |
2708 | if (os_strcmp(pos, "a") == 0) | |
2709 | conf->hw_mode = HOSTAPD_MODE_IEEE80211A; | |
2710 | else if (os_strcmp(pos, "b") == 0) | |
2711 | conf->hw_mode = HOSTAPD_MODE_IEEE80211B; | |
2712 | else if (os_strcmp(pos, "g") == 0) | |
2713 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
2714 | else if (os_strcmp(pos, "ad") == 0) | |
2715 | conf->hw_mode = HOSTAPD_MODE_IEEE80211AD; | |
3784c058 PX |
2716 | else if (os_strcmp(pos, "any") == 0) |
2717 | conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY; | |
599f40db JM |
2718 | else { |
2719 | wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'", | |
2720 | line, pos); | |
a0b728b7 | 2721 | return 1; |
599f40db JM |
2722 | } |
2723 | } else if (os_strcmp(buf, "wps_rf_bands") == 0) { | |
01a02593 HK |
2724 | if (os_strcmp(pos, "ad") == 0) |
2725 | bss->wps_rf_bands = WPS_RF_60GHZ; | |
2726 | else if (os_strcmp(pos, "a") == 0) | |
599f40db JM |
2727 | bss->wps_rf_bands = WPS_RF_50GHZ; |
2728 | else if (os_strcmp(pos, "g") == 0 || | |
2729 | os_strcmp(pos, "b") == 0) | |
2730 | bss->wps_rf_bands = WPS_RF_24GHZ; | |
2731 | else if (os_strcmp(pos, "ag") == 0 || | |
2732 | os_strcmp(pos, "ga") == 0) | |
2733 | bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; | |
2734 | else { | |
2735 | wpa_printf(MSG_ERROR, | |
2736 | "Line %d: unknown wps_rf_band '%s'", | |
2737 | line, pos); | |
a0b728b7 | 2738 | return 1; |
599f40db JM |
2739 | } |
2740 | } else if (os_strcmp(buf, "channel") == 0) { | |
2741 | if (os_strcmp(pos, "acs_survey") == 0) { | |
50f4f2a0 | 2742 | #ifndef CONFIG_ACS |
599f40db JM |
2743 | wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled", |
2744 | line); | |
a0b728b7 | 2745 | return 1; |
9670f877 | 2746 | #else /* CONFIG_ACS */ |
857d9422 | 2747 | conf->acs = 1; |
599f40db | 2748 | conf->channel = 0; |
9670f877 | 2749 | #endif /* CONFIG_ACS */ |
857d9422 | 2750 | } else { |
599f40db | 2751 | conf->channel = atoi(pos); |
857d9422 MM |
2752 | conf->acs = conf->channel == 0; |
2753 | } | |
599f40db | 2754 | } else if (os_strcmp(buf, "chanlist") == 0) { |
857d9422 | 2755 | if (hostapd_parse_chanlist(conf, pos)) { |
599f40db JM |
2756 | wpa_printf(MSG_ERROR, "Line %d: invalid channel list", |
2757 | line); | |
a0b728b7 | 2758 | return 1; |
599f40db JM |
2759 | } |
2760 | } else if (os_strcmp(buf, "beacon_int") == 0) { | |
2761 | int val = atoi(pos); | |
2762 | /* MIB defines range as 1..65535, but very small values | |
2763 | * cause problems with the current implementation. | |
2764 | * Since it is unlikely that this small numbers are | |
2765 | * useful in real life scenarios, do not allow beacon | |
2766 | * period to be set below 15 TU. */ | |
2767 | if (val < 15 || val > 65535) { | |
2768 | wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)", | |
2769 | line, val); | |
a0b728b7 | 2770 | return 1; |
b4c26ef9 JM |
2771 | } |
2772 | conf->beacon_int = val; | |
50f4f2a0 | 2773 | #ifdef CONFIG_ACS |
599f40db JM |
2774 | } else if (os_strcmp(buf, "acs_num_scans") == 0) { |
2775 | int val = atoi(pos); | |
2776 | if (val <= 0 || val > 100) { | |
2777 | wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)", | |
2778 | line, val); | |
a0b728b7 | 2779 | return 1; |
b4c26ef9 JM |
2780 | } |
2781 | conf->acs_num_scans = val; | |
68fa00c3 JM |
2782 | } else if (os_strcmp(buf, "acs_chan_bias") == 0) { |
2783 | if (hostapd_config_parse_acs_chan_bias(conf, pos)) { | |
2784 | wpa_printf(MSG_ERROR, "Line %d: invalid acs_chan_bias", | |
2785 | line); | |
2786 | return -1; | |
2787 | } | |
50f4f2a0 | 2788 | #endif /* CONFIG_ACS */ |
599f40db | 2789 | } else if (os_strcmp(buf, "dtim_period") == 0) { |
546680f8 JM |
2790 | int val = atoi(pos); |
2791 | ||
2792 | if (val < 1 || val > 255) { | |
599f40db | 2793 | wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d", |
546680f8 | 2794 | line, val); |
a0b728b7 | 2795 | return 1; |
599f40db | 2796 | } |
546680f8 | 2797 | bss->dtim_period = val; |
ec8f36af KP |
2798 | } else if (os_strcmp(buf, "bss_load_update_period") == 0) { |
2799 | bss->bss_load_update_period = atoi(pos); | |
2800 | if (bss->bss_load_update_period < 0 || | |
2801 | bss->bss_load_update_period > 100) { | |
2802 | wpa_printf(MSG_ERROR, | |
2803 | "Line %d: invalid bss_load_update_period %d", | |
2804 | line, bss->bss_load_update_period); | |
2805 | return 1; | |
2806 | } | |
599f40db JM |
2807 | } else if (os_strcmp(buf, "rts_threshold") == 0) { |
2808 | conf->rts_threshold = atoi(pos); | |
bc50bb0a | 2809 | if (conf->rts_threshold < -1 || conf->rts_threshold > 65535) { |
599f40db JM |
2810 | wpa_printf(MSG_ERROR, |
2811 | "Line %d: invalid rts_threshold %d", | |
2812 | line, conf->rts_threshold); | |
a0b728b7 | 2813 | return 1; |
599f40db JM |
2814 | } |
2815 | } else if (os_strcmp(buf, "fragm_threshold") == 0) { | |
2816 | conf->fragm_threshold = atoi(pos); | |
95be79f1 MM |
2817 | if (conf->fragm_threshold == -1) { |
2818 | /* allow a value of -1 */ | |
2819 | } else if (conf->fragm_threshold < 256 || | |
2820 | conf->fragm_threshold > 2346) { | |
599f40db JM |
2821 | wpa_printf(MSG_ERROR, |
2822 | "Line %d: invalid fragm_threshold %d", | |
2823 | line, conf->fragm_threshold); | |
a0b728b7 | 2824 | return 1; |
599f40db JM |
2825 | } |
2826 | } else if (os_strcmp(buf, "send_probe_response") == 0) { | |
2827 | int val = atoi(pos); | |
2828 | if (val != 0 && val != 1) { | |
2829 | wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)", | |
2830 | line, val); | |
b4c26ef9 JM |
2831 | return 1; |
2832 | } | |
2833 | conf->send_probe_response = val; | |
599f40db JM |
2834 | } else if (os_strcmp(buf, "supported_rates") == 0) { |
2835 | if (hostapd_parse_intlist(&conf->supported_rates, pos)) { | |
2836 | wpa_printf(MSG_ERROR, "Line %d: invalid rate list", | |
2837 | line); | |
a0b728b7 | 2838 | return 1; |
599f40db JM |
2839 | } |
2840 | } else if (os_strcmp(buf, "basic_rates") == 0) { | |
2841 | if (hostapd_parse_intlist(&conf->basic_rates, pos)) { | |
2842 | wpa_printf(MSG_ERROR, "Line %d: invalid rate list", | |
2843 | line); | |
a0b728b7 | 2844 | return 1; |
599f40db | 2845 | } |
29483a56 PK |
2846 | } else if (os_strcmp(buf, "beacon_rate") == 0) { |
2847 | int val; | |
2848 | ||
2849 | if (os_strncmp(pos, "ht:", 3) == 0) { | |
2850 | val = atoi(pos + 3); | |
2851 | if (val < 0 || val > 31) { | |
2852 | wpa_printf(MSG_ERROR, | |
2853 | "Line %d: invalid beacon_rate HT-MCS %d", | |
2854 | line, val); | |
2855 | return 1; | |
2856 | } | |
2857 | conf->rate_type = BEACON_RATE_HT; | |
2858 | conf->beacon_rate = val; | |
2859 | } else if (os_strncmp(pos, "vht:", 4) == 0) { | |
2860 | val = atoi(pos + 4); | |
2861 | if (val < 0 || val > 9) { | |
2862 | wpa_printf(MSG_ERROR, | |
2863 | "Line %d: invalid beacon_rate VHT-MCS %d", | |
2864 | line, val); | |
2865 | return 1; | |
2866 | } | |
2867 | conf->rate_type = BEACON_RATE_VHT; | |
2868 | conf->beacon_rate = val; | |
2869 | } else { | |
2870 | val = atoi(pos); | |
2871 | if (val < 10 || val > 10000) { | |
2872 | wpa_printf(MSG_ERROR, | |
2873 | "Line %d: invalid legacy beacon_rate %d", | |
2874 | line, val); | |
2875 | return 1; | |
2876 | } | |
2877 | conf->rate_type = BEACON_RATE_LEGACY; | |
2878 | conf->beacon_rate = val; | |
2879 | } | |
599f40db JM |
2880 | } else if (os_strcmp(buf, "preamble") == 0) { |
2881 | if (atoi(pos)) | |
2882 | conf->preamble = SHORT_PREAMBLE; | |
2883 | else | |
2884 | conf->preamble = LONG_PREAMBLE; | |
2885 | } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) { | |
2886 | bss->ignore_broadcast_ssid = atoi(pos); | |
9b7a1bd7 JM |
2887 | } else if (os_strcmp(buf, "no_probe_resp_if_max_sta") == 0) { |
2888 | bss->no_probe_resp_if_max_sta = atoi(pos); | |
599f40db JM |
2889 | } else if (os_strcmp(buf, "wep_default_key") == 0) { |
2890 | bss->ssid.wep.idx = atoi(pos); | |
2891 | if (bss->ssid.wep.idx > 3) { | |
2892 | wpa_printf(MSG_ERROR, | |
2893 | "Invalid wep_default_key index %d", | |
2894 | bss->ssid.wep.idx); | |
a0b728b7 | 2895 | return 1; |
599f40db JM |
2896 | } |
2897 | } else if (os_strcmp(buf, "wep_key0") == 0 || | |
2898 | os_strcmp(buf, "wep_key1") == 0 || | |
2899 | os_strcmp(buf, "wep_key2") == 0 || | |
2900 | os_strcmp(buf, "wep_key3") == 0) { | |
2901 | if (hostapd_config_read_wep(&bss->ssid.wep, | |
2902 | buf[7] - '0', pos)) { | |
2903 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'", | |
2904 | line, buf); | |
a0b728b7 | 2905 | return 1; |
599f40db | 2906 | } |
41d719d6 | 2907 | #ifndef CONFIG_NO_VLAN |
599f40db JM |
2908 | } else if (os_strcmp(buf, "dynamic_vlan") == 0) { |
2909 | bss->ssid.dynamic_vlan = atoi(pos); | |
8be640b7 MB |
2910 | } else if (os_strcmp(buf, "per_sta_vif") == 0) { |
2911 | bss->ssid.per_sta_vif = atoi(pos); | |
599f40db JM |
2912 | } else if (os_strcmp(buf, "vlan_file") == 0) { |
2913 | if (hostapd_config_read_vlan_file(bss, pos)) { | |
2914 | wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'", | |
2915 | line, pos); | |
a0b728b7 | 2916 | return 1; |
599f40db JM |
2917 | } |
2918 | } else if (os_strcmp(buf, "vlan_naming") == 0) { | |
2919 | bss->ssid.vlan_naming = atoi(pos); | |
2920 | if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END || | |
2921 | bss->ssid.vlan_naming < 0) { | |
2922 | wpa_printf(MSG_ERROR, | |
2923 | "Line %d: invalid naming scheme %d", | |
2924 | line, bss->ssid.vlan_naming); | |
a0b728b7 | 2925 | return 1; |
599f40db | 2926 | } |
41d719d6 | 2927 | #ifdef CONFIG_FULL_DYNAMIC_VLAN |
599f40db | 2928 | } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) { |
5784b9a4 | 2929 | os_free(bss->ssid.vlan_tagged_interface); |
599f40db | 2930 | bss->ssid.vlan_tagged_interface = os_strdup(pos); |
41d719d6 JM |
2931 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ |
2932 | #endif /* CONFIG_NO_VLAN */ | |
599f40db JM |
2933 | } else if (os_strcmp(buf, "ap_table_max_size") == 0) { |
2934 | conf->ap_table_max_size = atoi(pos); | |
2935 | } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) { | |
2936 | conf->ap_table_expiration_time = atoi(pos); | |
2937 | } else if (os_strncmp(buf, "tx_queue_", 9) == 0) { | |
2938 | if (hostapd_config_tx_queue(conf, buf, pos)) { | |
2939 | wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item", | |
2940 | line); | |
a0b728b7 | 2941 | return 1; |
599f40db JM |
2942 | } |
2943 | } else if (os_strcmp(buf, "wme_enabled") == 0 || | |
2944 | os_strcmp(buf, "wmm_enabled") == 0) { | |
2945 | bss->wmm_enabled = atoi(pos); | |
2946 | } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) { | |
2947 | bss->wmm_uapsd = atoi(pos); | |
2948 | } else if (os_strncmp(buf, "wme_ac_", 7) == 0 || | |
2949 | os_strncmp(buf, "wmm_ac_", 7) == 0) { | |
2950 | if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) { | |
2951 | wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item", | |
2952 | line); | |
a0b728b7 | 2953 | return 1; |
599f40db JM |
2954 | } |
2955 | } else if (os_strcmp(buf, "bss") == 0) { | |
2956 | if (hostapd_config_bss(conf, pos)) { | |
2957 | wpa_printf(MSG_ERROR, "Line %d: invalid bss item", | |
2958 | line); | |
a0b728b7 | 2959 | return 1; |
599f40db JM |
2960 | } |
2961 | } else if (os_strcmp(buf, "bssid") == 0) { | |
2962 | if (hwaddr_aton(pos, bss->bssid)) { | |
2963 | wpa_printf(MSG_ERROR, "Line %d: invalid bssid item", | |
2964 | line); | |
a0b728b7 | 2965 | return 1; |
599f40db | 2966 | } |
6448e064 EP |
2967 | } else if (os_strcmp(buf, "use_driver_iface_addr") == 0) { |
2968 | conf->use_driver_iface_addr = atoi(pos); | |
41d719d6 | 2969 | #ifdef CONFIG_IEEE80211W |
599f40db JM |
2970 | } else if (os_strcmp(buf, "ieee80211w") == 0) { |
2971 | bss->ieee80211w = atoi(pos); | |
8dd9f9cd JM |
2972 | } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) { |
2973 | if (os_strcmp(pos, "AES-128-CMAC") == 0) { | |
2974 | bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC; | |
2975 | } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) { | |
2976 | bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128; | |
2977 | } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) { | |
2978 | bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256; | |
2979 | } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) { | |
2980 | bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256; | |
2981 | } else { | |
2982 | wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s", | |
2983 | line, pos); | |
2984 | return 1; | |
2985 | } | |
599f40db JM |
2986 | } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) { |
2987 | bss->assoc_sa_query_max_timeout = atoi(pos); | |
2988 | if (bss->assoc_sa_query_max_timeout == 0) { | |
2989 | wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout", | |
2990 | line); | |
a0b728b7 | 2991 | return 1; |
599f40db JM |
2992 | } |
2993 | } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) { | |
2994 | bss->assoc_sa_query_retry_timeout = atoi(pos); | |
2995 | if (bss->assoc_sa_query_retry_timeout == 0) { | |
2996 | wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout", | |
2997 | line); | |
a0b728b7 | 2998 | return 1; |
599f40db | 2999 | } |
41d719d6 JM |
3000 | #endif /* CONFIG_IEEE80211W */ |
3001 | #ifdef CONFIG_IEEE80211N | |
599f40db JM |
3002 | } else if (os_strcmp(buf, "ieee80211n") == 0) { |
3003 | conf->ieee80211n = atoi(pos); | |
3004 | } else if (os_strcmp(buf, "ht_capab") == 0) { | |
3005 | if (hostapd_config_ht_capab(conf, pos) < 0) { | |
3006 | wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab", | |
3007 | line); | |
a0b728b7 | 3008 | return 1; |
599f40db JM |
3009 | } |
3010 | } else if (os_strcmp(buf, "require_ht") == 0) { | |
3011 | conf->require_ht = atoi(pos); | |
3012 | } else if (os_strcmp(buf, "obss_interval") == 0) { | |
3013 | conf->obss_interval = atoi(pos); | |
41d719d6 | 3014 | #endif /* CONFIG_IEEE80211N */ |
efe45d14 | 3015 | #ifdef CONFIG_IEEE80211AC |
599f40db JM |
3016 | } else if (os_strcmp(buf, "ieee80211ac") == 0) { |
3017 | conf->ieee80211ac = atoi(pos); | |
3018 | } else if (os_strcmp(buf, "vht_capab") == 0) { | |
3019 | if (hostapd_config_vht_capab(conf, pos) < 0) { | |
3020 | wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab", | |
3021 | line); | |
a0b728b7 | 3022 | return 1; |
599f40db JM |
3023 | } |
3024 | } else if (os_strcmp(buf, "require_vht") == 0) { | |
3025 | conf->require_vht = atoi(pos); | |
3026 | } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) { | |
3027 | conf->vht_oper_chwidth = atoi(pos); | |
3028 | } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) { | |
3029 | conf->vht_oper_centr_freq_seg0_idx = atoi(pos); | |
3030 | } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) { | |
3031 | conf->vht_oper_centr_freq_seg1_idx = atoi(pos); | |
e7d0e97b YL |
3032 | } else if (os_strcmp(buf, "vendor_vht") == 0) { |
3033 | bss->vendor_vht = atoi(pos); | |
fc72a48a T |
3034 | } else if (os_strcmp(buf, "use_sta_nsts") == 0) { |
3035 | bss->use_sta_nsts = atoi(pos); | |
efe45d14 | 3036 | #endif /* CONFIG_IEEE80211AC */ |
94380cb4 PX |
3037 | #ifdef CONFIG_IEEE80211AX |
3038 | } else if (os_strcmp(buf, "ieee80211ax") == 0) { | |
3039 | conf->ieee80211ax = atoi(pos); | |
3040 | } else if (os_strcmp(buf, "he_su_beamformer") == 0) { | |
3041 | conf->he_phy_capab.he_su_beamformer = atoi(pos); | |
3042 | } else if (os_strcmp(buf, "he_su_beamformee") == 0) { | |
3043 | conf->he_phy_capab.he_su_beamformee = atoi(pos); | |
3044 | } else if (os_strcmp(buf, "he_mu_beamformer") == 0) { | |
3045 | conf->he_phy_capab.he_mu_beamformer = atoi(pos); | |
3046 | } else if (os_strcmp(buf, "he_bss_color") == 0) { | |
3047 | conf->he_op.he_bss_color = atoi(pos); | |
3048 | } else if (os_strcmp(buf, "he_default_pe_duration") == 0) { | |
3049 | conf->he_op.he_default_pe_duration = atoi(pos); | |
3050 | } else if (os_strcmp(buf, "he_twt_required") == 0) { | |
3051 | conf->he_op.he_twt_required = atoi(pos); | |
3052 | } else if (os_strcmp(buf, "he_rts_threshold") == 0) { | |
3053 | conf->he_op.he_rts_threshold = atoi(pos); | |
3054 | #endif /* CONFIG_IEEE80211AX */ | |
599f40db JM |
3055 | } else if (os_strcmp(buf, "max_listen_interval") == 0) { |
3056 | bss->max_listen_interval = atoi(pos); | |
3057 | } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) { | |
3058 | bss->disable_pmksa_caching = atoi(pos); | |
3059 | } else if (os_strcmp(buf, "okc") == 0) { | |
3060 | bss->okc = atoi(pos); | |
41d719d6 | 3061 | #ifdef CONFIG_WPS |
599f40db JM |
3062 | } else if (os_strcmp(buf, "wps_state") == 0) { |
3063 | bss->wps_state = atoi(pos); | |
3064 | if (bss->wps_state < 0 || bss->wps_state > 2) { | |
3065 | wpa_printf(MSG_ERROR, "Line %d: invalid wps_state", | |
3066 | line); | |
a0b728b7 | 3067 | return 1; |
599f40db JM |
3068 | } |
3069 | } else if (os_strcmp(buf, "wps_independent") == 0) { | |
3070 | bss->wps_independent = atoi(pos); | |
3071 | } else if (os_strcmp(buf, "ap_setup_locked") == 0) { | |
3072 | bss->ap_setup_locked = atoi(pos); | |
3073 | } else if (os_strcmp(buf, "uuid") == 0) { | |
3074 | if (uuid_str2bin(pos, bss->uuid)) { | |
3075 | wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line); | |
a0b728b7 | 3076 | return 1; |
599f40db JM |
3077 | } |
3078 | } else if (os_strcmp(buf, "wps_pin_requests") == 0) { | |
3079 | os_free(bss->wps_pin_requests); | |
3080 | bss->wps_pin_requests = os_strdup(pos); | |
3081 | } else if (os_strcmp(buf, "device_name") == 0) { | |
cc6f2438 | 3082 | if (os_strlen(pos) > WPS_DEV_NAME_MAX_LEN) { |
599f40db JM |
3083 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
3084 | "device_name", line); | |
a0b728b7 | 3085 | return 1; |
599f40db JM |
3086 | } |
3087 | os_free(bss->device_name); | |
3088 | bss->device_name = os_strdup(pos); | |
3089 | } else if (os_strcmp(buf, "manufacturer") == 0) { | |
3090 | if (os_strlen(pos) > 64) { | |
3091 | wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer", | |
3092 | line); | |
a0b728b7 | 3093 | return 1; |
599f40db JM |
3094 | } |
3095 | os_free(bss->manufacturer); | |
3096 | bss->manufacturer = os_strdup(pos); | |
3097 | } else if (os_strcmp(buf, "model_name") == 0) { | |
3098 | if (os_strlen(pos) > 32) { | |
3099 | wpa_printf(MSG_ERROR, "Line %d: Too long model_name", | |
3100 | line); | |
a0b728b7 | 3101 | return 1; |
599f40db JM |
3102 | } |
3103 | os_free(bss->model_name); | |
3104 | bss->model_name = os_strdup(pos); | |
3105 | } else if (os_strcmp(buf, "model_number") == 0) { | |
3106 | if (os_strlen(pos) > 32) { | |
3107 | wpa_printf(MSG_ERROR, "Line %d: Too long model_number", | |
3108 | line); | |
a0b728b7 | 3109 | return 1; |
599f40db JM |
3110 | } |
3111 | os_free(bss->model_number); | |
3112 | bss->model_number = os_strdup(pos); | |
3113 | } else if (os_strcmp(buf, "serial_number") == 0) { | |
3114 | if (os_strlen(pos) > 32) { | |
3115 | wpa_printf(MSG_ERROR, "Line %d: Too long serial_number", | |
3116 | line); | |
a0b728b7 | 3117 | return 1; |
599f40db JM |
3118 | } |
3119 | os_free(bss->serial_number); | |
3120 | bss->serial_number = os_strdup(pos); | |
3121 | } else if (os_strcmp(buf, "device_type") == 0) { | |
3122 | if (wps_dev_type_str2bin(pos, bss->device_type)) | |
a0b728b7 | 3123 | return 1; |
599f40db JM |
3124 | } else if (os_strcmp(buf, "config_methods") == 0) { |
3125 | os_free(bss->config_methods); | |
3126 | bss->config_methods = os_strdup(pos); | |
3127 | } else if (os_strcmp(buf, "os_version") == 0) { | |
3128 | if (hexstr2bin(pos, bss->os_version, 4)) { | |
3129 | wpa_printf(MSG_ERROR, "Line %d: invalid os_version", | |
3130 | line); | |
a0b728b7 | 3131 | return 1; |
599f40db JM |
3132 | } |
3133 | } else if (os_strcmp(buf, "ap_pin") == 0) { | |
3134 | os_free(bss->ap_pin); | |
3135 | bss->ap_pin = os_strdup(pos); | |
3136 | } else if (os_strcmp(buf, "skip_cred_build") == 0) { | |
3137 | bss->skip_cred_build = atoi(pos); | |
3138 | } else if (os_strcmp(buf, "extra_cred") == 0) { | |
3139 | os_free(bss->extra_cred); | |
3140 | bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len); | |
3141 | if (bss->extra_cred == NULL) { | |
3142 | wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'", | |
3143 | line, pos); | |
a0b728b7 | 3144 | return 1; |
599f40db JM |
3145 | } |
3146 | } else if (os_strcmp(buf, "wps_cred_processing") == 0) { | |
3147 | bss->wps_cred_processing = atoi(pos); | |
3148 | } else if (os_strcmp(buf, "ap_settings") == 0) { | |
3149 | os_free(bss->ap_settings); | |
3150 | bss->ap_settings = | |
3151 | (u8 *) os_readfile(pos, &bss->ap_settings_len); | |
3152 | if (bss->ap_settings == NULL) { | |
3153 | wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'", | |
3154 | line, pos); | |
a0b728b7 | 3155 | return 1; |
599f40db JM |
3156 | } |
3157 | } else if (os_strcmp(buf, "upnp_iface") == 0) { | |
5784b9a4 | 3158 | os_free(bss->upnp_iface); |
599f40db JM |
3159 | bss->upnp_iface = os_strdup(pos); |
3160 | } else if (os_strcmp(buf, "friendly_name") == 0) { | |
3161 | os_free(bss->friendly_name); | |
3162 | bss->friendly_name = os_strdup(pos); | |
3163 | } else if (os_strcmp(buf, "manufacturer_url") == 0) { | |
3164 | os_free(bss->manufacturer_url); | |
3165 | bss->manufacturer_url = os_strdup(pos); | |
3166 | } else if (os_strcmp(buf, "model_description") == 0) { | |
3167 | os_free(bss->model_description); | |
3168 | bss->model_description = os_strdup(pos); | |
3169 | } else if (os_strcmp(buf, "model_url") == 0) { | |
3170 | os_free(bss->model_url); | |
3171 | bss->model_url = os_strdup(pos); | |
3172 | } else if (os_strcmp(buf, "upc") == 0) { | |
3173 | os_free(bss->upc); | |
3174 | bss->upc = os_strdup(pos); | |
3175 | } else if (os_strcmp(buf, "pbc_in_m1") == 0) { | |
3176 | bss->pbc_in_m1 = atoi(pos); | |
3177 | } else if (os_strcmp(buf, "server_id") == 0) { | |
3178 | os_free(bss->server_id); | |
3179 | bss->server_id = os_strdup(pos); | |
ffdaa05a | 3180 | #ifdef CONFIG_WPS_NFC |
599f40db JM |
3181 | } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) { |
3182 | bss->wps_nfc_dev_pw_id = atoi(pos); | |
3183 | if (bss->wps_nfc_dev_pw_id < 0x10 || | |
3184 | bss->wps_nfc_dev_pw_id > 0xffff) { | |
3185 | wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value", | |
3186 | line); | |
a0b728b7 | 3187 | return 1; |
599f40db JM |
3188 | } |
3189 | bss->wps_nfc_pw_from_config = 1; | |
3190 | } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) { | |
3191 | wpabuf_free(bss->wps_nfc_dh_pubkey); | |
9d955f75 | 3192 | bss->wps_nfc_dh_pubkey = wpabuf_parse_bin(pos); |
599f40db JM |
3193 | bss->wps_nfc_pw_from_config = 1; |
3194 | } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) { | |
3195 | wpabuf_free(bss->wps_nfc_dh_privkey); | |
9d955f75 | 3196 | bss->wps_nfc_dh_privkey = wpabuf_parse_bin(pos); |
599f40db JM |
3197 | bss->wps_nfc_pw_from_config = 1; |
3198 | } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) { | |
3199 | wpabuf_free(bss->wps_nfc_dev_pw); | |
9d955f75 | 3200 | bss->wps_nfc_dev_pw = wpabuf_parse_bin(pos); |
599f40db | 3201 | bss->wps_nfc_pw_from_config = 1; |
ffdaa05a | 3202 | #endif /* CONFIG_WPS_NFC */ |
41d719d6 | 3203 | #endif /* CONFIG_WPS */ |
962473c1 | 3204 | #ifdef CONFIG_P2P_MANAGER |
599f40db | 3205 | } else if (os_strcmp(buf, "manage_p2p") == 0) { |
b4c26ef9 | 3206 | if (atoi(pos)) |
599f40db JM |
3207 | bss->p2p |= P2P_MANAGE; |
3208 | else | |
3209 | bss->p2p &= ~P2P_MANAGE; | |
3210 | } else if (os_strcmp(buf, "allow_cross_connection") == 0) { | |
3211 | if (atoi(pos)) | |
3212 | bss->p2p |= P2P_ALLOW_CROSS_CONNECTION; | |
3213 | else | |
3214 | bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION; | |
962473c1 | 3215 | #endif /* CONFIG_P2P_MANAGER */ |
599f40db JM |
3216 | } else if (os_strcmp(buf, "disassoc_low_ack") == 0) { |
3217 | bss->disassoc_low_ack = atoi(pos); | |
3218 | } else if (os_strcmp(buf, "tdls_prohibit") == 0) { | |
b4c26ef9 | 3219 | if (atoi(pos)) |
599f40db JM |
3220 | bss->tdls |= TDLS_PROHIBIT; |
3221 | else | |
3222 | bss->tdls &= ~TDLS_PROHIBIT; | |
3223 | } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) { | |
b4c26ef9 | 3224 | if (atoi(pos)) |
599f40db JM |
3225 | bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH; |
3226 | else | |
3227 | bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH; | |
cd9fc786 | 3228 | #ifdef CONFIG_RSN_TESTING |
599f40db JM |
3229 | } else if (os_strcmp(buf, "rsn_testing") == 0) { |
3230 | extern int rsn_testing; | |
3231 | rsn_testing = atoi(pos); | |
cd9fc786 | 3232 | #endif /* CONFIG_RSN_TESTING */ |
599f40db JM |
3233 | } else if (os_strcmp(buf, "time_advertisement") == 0) { |
3234 | bss->time_advertisement = atoi(pos); | |
3235 | } else if (os_strcmp(buf, "time_zone") == 0) { | |
3236 | size_t tz_len = os_strlen(pos); | |
3237 | if (tz_len < 4 || tz_len > 255) { | |
3238 | wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone", | |
3239 | line); | |
a0b728b7 | 3240 | return 1; |
599f40db JM |
3241 | } |
3242 | os_free(bss->time_zone); | |
3243 | bss->time_zone = os_strdup(pos); | |
3244 | if (bss->time_zone == NULL) | |
a0b728b7 | 3245 | return 1; |
2049a875 | 3246 | #ifdef CONFIG_WNM |
599f40db JM |
3247 | } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) { |
3248 | bss->wnm_sleep_mode = atoi(pos); | |
3249 | } else if (os_strcmp(buf, "bss_transition") == 0) { | |
3250 | bss->bss_transition = atoi(pos); | |
2049a875 | 3251 | #endif /* CONFIG_WNM */ |
b83e3e93 | 3252 | #ifdef CONFIG_INTERWORKING |
599f40db JM |
3253 | } else if (os_strcmp(buf, "interworking") == 0) { |
3254 | bss->interworking = atoi(pos); | |
3255 | } else if (os_strcmp(buf, "access_network_type") == 0) { | |
3256 | bss->access_network_type = atoi(pos); | |
3257 | if (bss->access_network_type < 0 || | |
3258 | bss->access_network_type > 15) { | |
3259 | wpa_printf(MSG_ERROR, | |
3260 | "Line %d: invalid access_network_type", | |
3261 | line); | |
a0b728b7 | 3262 | return 1; |
599f40db JM |
3263 | } |
3264 | } else if (os_strcmp(buf, "internet") == 0) { | |
3265 | bss->internet = atoi(pos); | |
3266 | } else if (os_strcmp(buf, "asra") == 0) { | |
3267 | bss->asra = atoi(pos); | |
3268 | } else if (os_strcmp(buf, "esr") == 0) { | |
3269 | bss->esr = atoi(pos); | |
3270 | } else if (os_strcmp(buf, "uesa") == 0) { | |
3271 | bss->uesa = atoi(pos); | |
3272 | } else if (os_strcmp(buf, "venue_group") == 0) { | |
3273 | bss->venue_group = atoi(pos); | |
3274 | bss->venue_info_set = 1; | |
3275 | } else if (os_strcmp(buf, "venue_type") == 0) { | |
3276 | bss->venue_type = atoi(pos); | |
3277 | bss->venue_info_set = 1; | |
3278 | } else if (os_strcmp(buf, "hessid") == 0) { | |
3279 | if (hwaddr_aton(pos, bss->hessid)) { | |
3280 | wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line); | |
a0b728b7 | 3281 | return 1; |
599f40db JM |
3282 | } |
3283 | } else if (os_strcmp(buf, "roaming_consortium") == 0) { | |
3284 | if (parse_roaming_consortium(bss, pos, line) < 0) | |
a0b728b7 | 3285 | return 1; |
599f40db JM |
3286 | } else if (os_strcmp(buf, "venue_name") == 0) { |
3287 | if (parse_venue_name(bss, pos, line) < 0) | |
a0b728b7 | 3288 | return 1; |
599f40db JM |
3289 | } else if (os_strcmp(buf, "network_auth_type") == 0) { |
3290 | u8 auth_type; | |
3291 | u16 redirect_url_len; | |
3292 | if (hexstr2bin(pos, &auth_type, 1)) { | |
3293 | wpa_printf(MSG_ERROR, | |
3294 | "Line %d: Invalid network_auth_type '%s'", | |
3295 | line, pos); | |
a0b728b7 | 3296 | return 1; |
599f40db JM |
3297 | } |
3298 | if (auth_type == 0 || auth_type == 2) | |
3299 | redirect_url_len = os_strlen(pos + 2); | |
3300 | else | |
3301 | redirect_url_len = 0; | |
3302 | os_free(bss->network_auth_type); | |
3303 | bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1); | |
a0b728b7 JM |
3304 | if (bss->network_auth_type == NULL) |
3305 | return 1; | |
599f40db JM |
3306 | *bss->network_auth_type = auth_type; |
3307 | WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len); | |
3308 | if (redirect_url_len) | |
3309 | os_memcpy(bss->network_auth_type + 3, pos + 2, | |
3310 | redirect_url_len); | |
3311 | bss->network_auth_type_len = 3 + redirect_url_len; | |
3312 | } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) { | |
3313 | if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) { | |
3314 | wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'", | |
3315 | line, pos); | |
3316 | bss->ipaddr_type_configured = 0; | |
a0b728b7 | 3317 | return 1; |
599f40db JM |
3318 | } |
3319 | bss->ipaddr_type_configured = 1; | |
b4c26ef9 | 3320 | } else if (os_strcmp(buf, "domain_name") == 0) { |
599f40db JM |
3321 | int j, num_domains, domain_len, domain_list_len = 0; |
3322 | char *tok_start, *tok_prev; | |
3323 | u8 *domain_list, *domain_ptr; | |
26fac8b6 | 3324 | |
599f40db JM |
3325 | domain_list_len = os_strlen(pos) + 1; |
3326 | domain_list = os_malloc(domain_list_len); | |
a0b728b7 JM |
3327 | if (domain_list == NULL) |
3328 | return 1; | |
26fac8b6 | 3329 | |
599f40db JM |
3330 | domain_ptr = domain_list; |
3331 | tok_prev = pos; | |
3332 | num_domains = 1; | |
3333 | while ((tok_prev = os_strchr(tok_prev, ','))) { | |
3334 | num_domains++; | |
3335 | tok_prev++; | |
3336 | } | |
3337 | tok_prev = pos; | |
3338 | for (j = 0; j < num_domains; j++) { | |
3339 | tok_start = os_strchr(tok_prev, ','); | |
3340 | if (tok_start) { | |
3341 | domain_len = tok_start - tok_prev; | |
3342 | *domain_ptr = domain_len; | |
3343 | os_memcpy(domain_ptr + 1, tok_prev, domain_len); | |
3344 | domain_ptr += domain_len + 1; | |
3345 | tok_prev = ++tok_start; | |
3346 | } else { | |
3347 | domain_len = os_strlen(tok_prev); | |
3348 | *domain_ptr = domain_len; | |
3349 | os_memcpy(domain_ptr + 1, tok_prev, domain_len); | |
3350 | domain_ptr += domain_len + 1; | |
26fac8b6 | 3351 | } |
599f40db | 3352 | } |
26fac8b6 | 3353 | |
599f40db JM |
3354 | os_free(bss->domain_name); |
3355 | bss->domain_name = domain_list; | |
3356 | bss->domain_name_len = domain_list_len; | |
3357 | } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) { | |
3358 | if (parse_3gpp_cell_net(bss, pos, line) < 0) | |
a0b728b7 | 3359 | return 1; |
599f40db JM |
3360 | } else if (os_strcmp(buf, "nai_realm") == 0) { |
3361 | if (parse_nai_realm(bss, pos, line) < 0) | |
a0b728b7 | 3362 | return 1; |
695dbbea JM |
3363 | } else if (os_strcmp(buf, "anqp_elem") == 0) { |
3364 | if (parse_anqp_elem(bss, pos, line) < 0) | |
3365 | return 1; | |
599f40db | 3366 | } else if (os_strcmp(buf, "gas_frag_limit") == 0) { |
2977f519 JM |
3367 | int val = atoi(pos); |
3368 | ||
3369 | if (val <= 0) { | |
3370 | wpa_printf(MSG_ERROR, | |
3371 | "Line %d: Invalid gas_frag_limit '%s'", | |
3372 | line, pos); | |
3373 | return 1; | |
3374 | } | |
3375 | bss->gas_frag_limit = val; | |
599f40db JM |
3376 | } else if (os_strcmp(buf, "gas_comeback_delay") == 0) { |
3377 | bss->gas_comeback_delay = atoi(pos); | |
3378 | } else if (os_strcmp(buf, "qos_map_set") == 0) { | |
3379 | if (parse_qos_map_set(bss, pos, line) < 0) | |
a0b728b7 | 3380 | return 1; |
b83e3e93 | 3381 | #endif /* CONFIG_INTERWORKING */ |
505a3694 | 3382 | #ifdef CONFIG_RADIUS_TEST |
599f40db JM |
3383 | } else if (os_strcmp(buf, "dump_msk_file") == 0) { |
3384 | os_free(bss->dump_msk_file); | |
3385 | bss->dump_msk_file = os_strdup(pos); | |
505a3694 | 3386 | #endif /* CONFIG_RADIUS_TEST */ |
7b991b47 MW |
3387 | #ifdef CONFIG_PROXYARP |
3388 | } else if (os_strcmp(buf, "proxy_arp") == 0) { | |
3389 | bss->proxy_arp = atoi(pos); | |
3390 | #endif /* CONFIG_PROXYARP */ | |
159c89ab | 3391 | #ifdef CONFIG_HS20 |
599f40db JM |
3392 | } else if (os_strcmp(buf, "hs20") == 0) { |
3393 | bss->hs20 = atoi(pos); | |
3394 | } else if (os_strcmp(buf, "disable_dgaf") == 0) { | |
3395 | bss->disable_dgaf = atoi(pos); | |
4a7ce984 JM |
3396 | } else if (os_strcmp(buf, "na_mcast_to_ucast") == 0) { |
3397 | bss->na_mcast_to_ucast = atoi(pos); | |
599f40db JM |
3398 | } else if (os_strcmp(buf, "osen") == 0) { |
3399 | bss->osen = atoi(pos); | |
3400 | } else if (os_strcmp(buf, "anqp_domain_id") == 0) { | |
3401 | bss->anqp_domain_id = atoi(pos); | |
3402 | } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) { | |
3403 | bss->hs20_deauth_req_timeout = atoi(pos); | |
3404 | } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) { | |
3405 | if (hs20_parse_oper_friendly_name(bss, pos, line) < 0) | |
a0b728b7 | 3406 | return 1; |
599f40db | 3407 | } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) { |
a0b728b7 JM |
3408 | if (hs20_parse_wan_metrics(bss, pos, line) < 0) |
3409 | return 1; | |
599f40db JM |
3410 | } else if (os_strcmp(buf, "hs20_conn_capab") == 0) { |
3411 | if (hs20_parse_conn_capab(bss, pos, line) < 0) { | |
a0b728b7 | 3412 | return 1; |
599f40db JM |
3413 | } |
3414 | } else if (os_strcmp(buf, "hs20_operating_class") == 0) { | |
3415 | u8 *oper_class; | |
3416 | size_t oper_class_len; | |
3417 | oper_class_len = os_strlen(pos); | |
3418 | if (oper_class_len < 2 || (oper_class_len & 0x01)) { | |
3419 | wpa_printf(MSG_ERROR, | |
3420 | "Line %d: Invalid hs20_operating_class '%s'", | |
3421 | line, pos); | |
a0b728b7 | 3422 | return 1; |
599f40db JM |
3423 | } |
3424 | oper_class_len /= 2; | |
3425 | oper_class = os_malloc(oper_class_len); | |
a0b728b7 JM |
3426 | if (oper_class == NULL) |
3427 | return 1; | |
599f40db JM |
3428 | if (hexstr2bin(pos, oper_class, oper_class_len)) { |
3429 | wpa_printf(MSG_ERROR, | |
3430 | "Line %d: Invalid hs20_operating_class '%s'", | |
3431 | line, pos); | |
3432 | os_free(oper_class); | |
a0b728b7 | 3433 | return 1; |
599f40db JM |
3434 | } |
3435 | os_free(bss->hs20_operating_class); | |
3436 | bss->hs20_operating_class = oper_class; | |
3437 | bss->hs20_operating_class_len = oper_class_len; | |
3438 | } else if (os_strcmp(buf, "hs20_icon") == 0) { | |
3439 | if (hs20_parse_icon(bss, pos) < 0) { | |
3440 | wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'", | |
3441 | line, pos); | |
a0b728b7 | 3442 | return 1; |
599f40db JM |
3443 | } |
3444 | } else if (os_strcmp(buf, "osu_ssid") == 0) { | |
3445 | if (hs20_parse_osu_ssid(bss, pos, line) < 0) | |
a0b728b7 | 3446 | return 1; |
599f40db JM |
3447 | } else if (os_strcmp(buf, "osu_server_uri") == 0) { |
3448 | if (hs20_parse_osu_server_uri(bss, pos, line) < 0) | |
a0b728b7 | 3449 | return 1; |
599f40db JM |
3450 | } else if (os_strcmp(buf, "osu_friendly_name") == 0) { |
3451 | if (hs20_parse_osu_friendly_name(bss, pos, line) < 0) | |
a0b728b7 | 3452 | return 1; |
599f40db JM |
3453 | } else if (os_strcmp(buf, "osu_nai") == 0) { |
3454 | if (hs20_parse_osu_nai(bss, pos, line) < 0) | |
a0b728b7 | 3455 | return 1; |
599f40db JM |
3456 | } else if (os_strcmp(buf, "osu_method_list") == 0) { |
3457 | if (hs20_parse_osu_method_list(bss, pos, line) < 0) | |
a0b728b7 | 3458 | return 1; |
599f40db JM |
3459 | } else if (os_strcmp(buf, "osu_icon") == 0) { |
3460 | if (hs20_parse_osu_icon(bss, pos, line) < 0) | |
a0b728b7 | 3461 | return 1; |
599f40db JM |
3462 | } else if (os_strcmp(buf, "osu_service_desc") == 0) { |
3463 | if (hs20_parse_osu_service_desc(bss, pos, line) < 0) | |
a0b728b7 | 3464 | return 1; |
599f40db JM |
3465 | } else if (os_strcmp(buf, "subscr_remediation_url") == 0) { |
3466 | os_free(bss->subscr_remediation_url); | |
3467 | bss->subscr_remediation_url = os_strdup(pos); | |
3468 | } else if (os_strcmp(buf, "subscr_remediation_method") == 0) { | |
3469 | bss->subscr_remediation_method = atoi(pos); | |
159c89ab | 3470 | #endif /* CONFIG_HS20 */ |
fb9a1c3e AS |
3471 | #ifdef CONFIG_MBO |
3472 | } else if (os_strcmp(buf, "mbo") == 0) { | |
3473 | bss->mbo_enabled = atoi(pos); | |
941caed9 JM |
3474 | } else if (os_strcmp(buf, "mbo_cell_data_conn_pref") == 0) { |
3475 | bss->mbo_cell_data_conn_pref = atoi(pos); | |
fb9a1c3e | 3476 | #endif /* CONFIG_MBO */ |
c2aff6b1 | 3477 | #ifdef CONFIG_TESTING_OPTIONS |
599f40db JM |
3478 | #define PARSE_TEST_PROBABILITY(_val) \ |
3479 | } else if (os_strcmp(buf, #_val) == 0) { \ | |
3480 | char *end; \ | |
3481 | \ | |
3482 | conf->_val = strtod(pos, &end); \ | |
06df2aa6 JM |
3483 | if (*end || conf->_val < 0.0 || \ |
3484 | conf->_val > 1.0) { \ | |
599f40db JM |
3485 | wpa_printf(MSG_ERROR, \ |
3486 | "Line %d: Invalid value '%s'", \ | |
3487 | line, pos); \ | |
a0b728b7 | 3488 | return 1; \ |
599f40db JM |
3489 | } |
3490 | PARSE_TEST_PROBABILITY(ignore_probe_probability) | |
3491 | PARSE_TEST_PROBABILITY(ignore_auth_probability) | |
3492 | PARSE_TEST_PROBABILITY(ignore_assoc_probability) | |
3493 | PARSE_TEST_PROBABILITY(ignore_reassoc_probability) | |
3494 | PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability) | |
2b6e1216 JB |
3495 | } else if (os_strcmp(buf, "ecsa_ie_only") == 0) { |
3496 | conf->ecsa_ie_only = atoi(pos); | |
599f40db JM |
3497 | } else if (os_strcmp(buf, "bss_load_test") == 0) { |
3498 | WPA_PUT_LE16(bss->bss_load_test, atoi(pos)); | |
3499 | pos = os_strchr(pos, ':'); | |
3500 | if (pos == NULL) { | |
3501 | wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test", | |
3502 | line); | |
3503 | return 1; | |
3504 | } | |
3505 | pos++; | |
3506 | bss->bss_load_test[2] = atoi(pos); | |
3507 | pos = os_strchr(pos, ':'); | |
3508 | if (pos == NULL) { | |
3509 | wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test", | |
3510 | line); | |
3511 | return 1; | |
3512 | } | |
3513 | pos++; | |
3514 | WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos)); | |
3515 | bss->bss_load_test_set = 1; | |
0629eeb4 | 3516 | } else if (os_strcmp(buf, "radio_measurements") == 0) { |
01018212 DS |
3517 | /* |
3518 | * DEPRECATED: This parameter will be removed in the future. | |
3519 | * Use rrm_neighbor_report instead. | |
3520 | */ | |
3521 | int val = atoi(pos); | |
3522 | ||
3523 | if (val & BIT(0)) | |
3524 | bss->radio_measurements[0] |= | |
3525 | WLAN_RRM_CAPS_NEIGHBOR_REPORT; | |
bc02843e JM |
3526 | } else if (os_strcmp(buf, "own_ie_override") == 0) { |
3527 | struct wpabuf *tmp; | |
3528 | size_t len = os_strlen(pos) / 2; | |
3529 | ||
3530 | tmp = wpabuf_alloc(len); | |
3531 | if (!tmp) | |
3532 | return 1; | |
3533 | ||
3534 | if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) { | |
3535 | wpabuf_free(tmp); | |
3536 | wpa_printf(MSG_ERROR, | |
3537 | "Line %d: Invalid own_ie_override '%s'", | |
3538 | line, pos); | |
3539 | return 1; | |
3540 | } | |
3541 | ||
3542 | wpabuf_free(bss->own_ie_override); | |
3543 | bss->own_ie_override = tmp; | |
c2aff6b1 | 3544 | #endif /* CONFIG_TESTING_OPTIONS */ |
599f40db | 3545 | } else if (os_strcmp(buf, "vendor_elements") == 0) { |
4ac33989 | 3546 | if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos)) |
599f40db | 3547 | return 1; |
a9112270 | 3548 | } else if (os_strcmp(buf, "assocresp_elements") == 0) { |
4ac33989 | 3549 | if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos)) |
a9112270 | 3550 | return 1; |
599f40db JM |
3551 | } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) { |
3552 | bss->sae_anti_clogging_threshold = atoi(pos); | |
3553 | } else if (os_strcmp(buf, "sae_groups") == 0) { | |
3554 | if (hostapd_parse_intlist(&bss->sae_groups, pos)) { | |
3555 | wpa_printf(MSG_ERROR, | |
3556 | "Line %d: Invalid sae_groups value '%s'", | |
3557 | line, pos); | |
3558 | return 1; | |
41d719d6 | 3559 | } |
599f40db JM |
3560 | } else if (os_strcmp(buf, "local_pwr_constraint") == 0) { |
3561 | int val = atoi(pos); | |
3562 | if (val < 0 || val > 255) { | |
3563 | wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)", | |
3564 | line, val); | |
3565 | return 1; | |
3566 | } | |
3567 | conf->local_pwr_constraint = val; | |
3568 | } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) { | |
3569 | conf->spectrum_mgmt_required = atoi(pos); | |
88cb27c7 DS |
3570 | } else if (os_strcmp(buf, "wowlan_triggers") == 0) { |
3571 | os_free(bss->wowlan_triggers); | |
3572 | bss->wowlan_triggers = os_strdup(pos); | |
104bef45 AN |
3573 | #ifdef CONFIG_FST |
3574 | } else if (os_strcmp(buf, "fst_group_id") == 0) { | |
3575 | size_t len = os_strlen(pos); | |
3576 | ||
3577 | if (!len || len >= sizeof(conf->fst_cfg.group_id)) { | |
3578 | wpa_printf(MSG_ERROR, | |
3579 | "Line %d: Invalid fst_group_id value '%s'", | |
3580 | line, pos); | |
3581 | return 1; | |
3582 | } | |
3583 | ||
3584 | if (conf->fst_cfg.group_id[0]) { | |
3585 | wpa_printf(MSG_ERROR, | |
3586 | "Line %d: Duplicate fst_group value '%s'", | |
3587 | line, pos); | |
3588 | return 1; | |
3589 | } | |
3590 | ||
3591 | os_strlcpy(conf->fst_cfg.group_id, pos, | |
3592 | sizeof(conf->fst_cfg.group_id)); | |
3593 | } else if (os_strcmp(buf, "fst_priority") == 0) { | |
3594 | char *endp; | |
3595 | long int val; | |
3596 | ||
3597 | if (!*pos) { | |
3598 | wpa_printf(MSG_ERROR, | |
3599 | "Line %d: fst_priority value not supplied (expected 1..%u)", | |
3600 | line, FST_MAX_PRIO_VALUE); | |
3601 | return -1; | |
3602 | } | |
3603 | ||
3604 | val = strtol(pos, &endp, 0); | |
3605 | if (*endp || val < 1 || val > FST_MAX_PRIO_VALUE) { | |
3606 | wpa_printf(MSG_ERROR, | |
3607 | "Line %d: Invalid fst_priority %ld (%s) (expected 1..%u)", | |
3608 | line, val, pos, FST_MAX_PRIO_VALUE); | |
3609 | return 1; | |
3610 | } | |
3611 | conf->fst_cfg.priority = (u8) val; | |
3612 | } else if (os_strcmp(buf, "fst_llt") == 0) { | |
3613 | char *endp; | |
3614 | long int val; | |
3615 | ||
3616 | if (!*pos) { | |
3617 | wpa_printf(MSG_ERROR, | |
3618 | "Line %d: fst_llt value not supplied (expected 1..%u)", | |
3619 | line, FST_MAX_LLT_MS); | |
3620 | return -1; | |
3621 | } | |
3622 | val = strtol(pos, &endp, 0); | |
24bce46e JM |
3623 | if (*endp || val < 1 || |
3624 | (unsigned long int) val > FST_MAX_LLT_MS) { | |
104bef45 AN |
3625 | wpa_printf(MSG_ERROR, |
3626 | "Line %d: Invalid fst_llt %ld (%s) (expected 1..%u)", | |
3627 | line, val, pos, FST_MAX_LLT_MS); | |
3628 | return 1; | |
3629 | } | |
3630 | conf->fst_cfg.llt = (u32) val; | |
3631 | #endif /* CONFIG_FST */ | |
a65a9b8d JM |
3632 | } else if (os_strcmp(buf, "track_sta_max_num") == 0) { |
3633 | conf->track_sta_max_num = atoi(pos); | |
3634 | } else if (os_strcmp(buf, "track_sta_max_age") == 0) { | |
3635 | conf->track_sta_max_age = atoi(pos); | |
964f64e2 JM |
3636 | } else if (os_strcmp(buf, "no_probe_resp_if_seen_on") == 0) { |
3637 | os_free(bss->no_probe_resp_if_seen_on); | |
3638 | bss->no_probe_resp_if_seen_on = os_strdup(pos); | |
0e2412d0 JM |
3639 | } else if (os_strcmp(buf, "no_auth_if_seen_on") == 0) { |
3640 | os_free(bss->no_auth_if_seen_on); | |
3641 | bss->no_auth_if_seen_on = os_strdup(pos); | |
74e982d8 DS |
3642 | } else if (os_strcmp(buf, "lci") == 0) { |
3643 | wpabuf_free(conf->lci); | |
9d955f75 | 3644 | conf->lci = wpabuf_parse_bin(pos); |
5cb59370 IP |
3645 | if (conf->lci && wpabuf_len(conf->lci) == 0) { |
3646 | wpabuf_free(conf->lci); | |
3647 | conf->lci = NULL; | |
3648 | } | |
74e982d8 DS |
3649 | } else if (os_strcmp(buf, "civic") == 0) { |
3650 | wpabuf_free(conf->civic); | |
9d955f75 | 3651 | conf->civic = wpabuf_parse_bin(pos); |
5cb59370 IP |
3652 | if (conf->civic && wpabuf_len(conf->civic) == 0) { |
3653 | wpabuf_free(conf->civic); | |
3654 | conf->civic = NULL; | |
3655 | } | |
01018212 DS |
3656 | } else if (os_strcmp(buf, "rrm_neighbor_report") == 0) { |
3657 | if (atoi(pos)) | |
3658 | bss->radio_measurements[0] |= | |
3659 | WLAN_RRM_CAPS_NEIGHBOR_REPORT; | |
73a27a63 JM |
3660 | } else if (os_strcmp(buf, "rrm_beacon_report") == 0) { |
3661 | if (atoi(pos)) | |
3662 | bss->radio_measurements[0] |= | |
3663 | WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE | | |
3664 | WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE | | |
3665 | WLAN_RRM_CAPS_BEACON_REPORT_TABLE; | |
83594725 JM |
3666 | } else if (os_strcmp(buf, "gas_address3") == 0) { |
3667 | bss->gas_address3 = atoi(pos); | |
451a27b1 DS |
3668 | } else if (os_strcmp(buf, "stationary_ap") == 0) { |
3669 | conf->stationary_ap = atoi(pos); | |
faecb392 LD |
3670 | } else if (os_strcmp(buf, "ftm_responder") == 0) { |
3671 | bss->ftm_responder = atoi(pos); | |
3672 | } else if (os_strcmp(buf, "ftm_initiator") == 0) { | |
3673 | bss->ftm_initiator = atoi(pos); | |
903ecbe8 JM |
3674 | #ifdef CONFIG_FILS |
3675 | } else if (os_strcmp(buf, "fils_cache_id") == 0) { | |
3676 | if (hexstr2bin(pos, bss->fils_cache_id, FILS_CACHE_ID_LEN)) { | |
3677 | wpa_printf(MSG_ERROR, | |
3678 | "Line %d: Invalid fils_cache_id '%s'", | |
3679 | line, pos); | |
3680 | return 1; | |
3681 | } | |
3682 | bss->fils_cache_id_set = 1; | |
26bf70e3 JM |
3683 | } else if (os_strcmp(buf, "fils_realm") == 0) { |
3684 | if (parse_fils_realm(bss, pos) < 0) | |
3685 | return 1; | |
1764559e JM |
3686 | } else if (os_strcmp(buf, "fils_dh_group") == 0) { |
3687 | bss->fils_dh_group = atoi(pos); | |
91d91abf JM |
3688 | } else if (os_strcmp(buf, "dhcp_server") == 0) { |
3689 | if (hostapd_parse_ip_addr(pos, &bss->dhcp_server)) { | |
3690 | wpa_printf(MSG_ERROR, | |
3691 | "Line %d: invalid IP address '%s'", | |
3692 | line, pos); | |
3693 | return 1; | |
3694 | } | |
3695 | } else if (os_strcmp(buf, "dhcp_rapid_commit_proxy") == 0) { | |
3696 | bss->dhcp_rapid_commit_proxy = atoi(pos); | |
3697 | } else if (os_strcmp(buf, "fils_hlp_wait_time") == 0) { | |
3698 | bss->fils_hlp_wait_time = atoi(pos); | |
3699 | } else if (os_strcmp(buf, "dhcp_server_port") == 0) { | |
3700 | bss->dhcp_server_port = atoi(pos); | |
3701 | } else if (os_strcmp(buf, "dhcp_relay_port") == 0) { | |
3702 | bss->dhcp_relay_port = atoi(pos); | |
903ecbe8 | 3703 | #endif /* CONFIG_FILS */ |
34f7c699 MB |
3704 | } else if (os_strcmp(buf, "multicast_to_unicast") == 0) { |
3705 | bss->multicast_to_unicast = atoi(pos); | |
57a2aaca JM |
3706 | } else if (os_strcmp(buf, "broadcast_deauth") == 0) { |
3707 | bss->broadcast_deauth = atoi(pos); | |
599f40db JM |
3708 | } else { |
3709 | wpa_printf(MSG_ERROR, | |
3710 | "Line %d: unknown configuration item '%s'", | |
3711 | line, buf); | |
a0b728b7 | 3712 | return 1; |
41d719d6 JM |
3713 | } |
3714 | ||
a0b728b7 | 3715 | return 0; |
ef45bc89 SP |
3716 | } |
3717 | ||
3718 | ||
3719 | /** | |
3720 | * hostapd_config_read - Read and parse a configuration file | |
3721 | * @fname: Configuration file name (including path, if needed) | |
3722 | * Returns: Allocated configuration data structure | |
3723 | */ | |
3724 | struct hostapd_config * hostapd_config_read(const char *fname) | |
3725 | { | |
3726 | struct hostapd_config *conf; | |
ef45bc89 | 3727 | FILE *f; |
ef50e410 | 3728 | char buf[4096], *pos; |
ef45bc89 SP |
3729 | int line = 0; |
3730 | int errors = 0; | |
ef45bc89 SP |
3731 | size_t i; |
3732 | ||
3733 | f = fopen(fname, "r"); | |
3734 | if (f == NULL) { | |
3735 | wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " | |
3736 | "for reading.", fname); | |
3737 | return NULL; | |
3738 | } | |
3739 | ||
3740 | conf = hostapd_config_defaults(); | |
3741 | if (conf == NULL) { | |
3742 | fclose(f); | |
3743 | return NULL; | |
3744 | } | |
3745 | ||
3746 | /* set default driver based on configuration */ | |
3747 | conf->driver = wpa_drivers[0]; | |
3748 | if (conf->driver == NULL) { | |
3749 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); | |
3750 | hostapd_config_free(conf); | |
3751 | fclose(f); | |
3752 | return NULL; | |
3753 | } | |
3754 | ||
df756b37 | 3755 | conf->last_bss = conf->bss[0]; |
ef45bc89 SP |
3756 | |
3757 | while (fgets(buf, sizeof(buf), f)) { | |
df756b37 JM |
3758 | struct hostapd_bss_config *bss; |
3759 | ||
ef45bc89 SP |
3760 | bss = conf->last_bss; |
3761 | line++; | |
3762 | ||
3763 | if (buf[0] == '#') | |
3764 | continue; | |
3765 | pos = buf; | |
3766 | while (*pos != '\0') { | |
3767 | if (*pos == '\n') { | |
3768 | *pos = '\0'; | |
3769 | break; | |
3770 | } | |
3771 | pos++; | |
3772 | } | |
3773 | if (buf[0] == '\0') | |
3774 | continue; | |
3775 | ||
3776 | pos = os_strchr(buf, '='); | |
3777 | if (pos == NULL) { | |
3778 | wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'", | |
3779 | line, buf); | |
3780 | errors++; | |
3781 | continue; | |
3782 | } | |
3783 | *pos = '\0'; | |
3784 | pos++; | |
3785 | errors += hostapd_config_fill(conf, bss, buf, pos, line); | |
3786 | } | |
3787 | ||
41d719d6 JM |
3788 | fclose(f); |
3789 | ||
a7f5b74d | 3790 | for (i = 0; i < conf->num_bss; i++) |
5d67bf15 | 3791 | hostapd_set_security_params(conf->bss[i], 1); |
41d719d6 | 3792 | |
08081ad8 | 3793 | if (hostapd_config_check(conf, 1)) |
41d719d6 JM |
3794 | errors++; |
3795 | ||
ae6e1bee | 3796 | #ifndef WPA_IGNORE_CONFIG_ERRORS |
41d719d6 JM |
3797 | if (errors) { |
3798 | wpa_printf(MSG_ERROR, "%d errors found in configuration file " | |
3799 | "'%s'", errors, fname); | |
3800 | hostapd_config_free(conf); | |
3801 | conf = NULL; | |
3802 | } | |
ae6e1bee | 3803 | #endif /* WPA_IGNORE_CONFIG_ERRORS */ |
41d719d6 JM |
3804 | |
3805 | return conf; | |
3806 | } | |
31b79e11 SP |
3807 | |
3808 | ||
3809 | int hostapd_set_iface(struct hostapd_config *conf, | |
63e169e1 JM |
3810 | struct hostapd_bss_config *bss, const char *field, |
3811 | char *value) | |
31b79e11 | 3812 | { |
4929898d | 3813 | int errors; |
31b79e11 SP |
3814 | size_t i; |
3815 | ||
3816 | errors = hostapd_config_fill(conf, bss, field, value, 0); | |
3817 | if (errors) { | |
3818 | wpa_printf(MSG_INFO, "Failed to set configuration field '%s' " | |
3819 | "to value '%s'", field, value); | |
3820 | return -1; | |
3821 | } | |
3822 | ||
3823 | for (i = 0; i < conf->num_bss; i++) | |
5d67bf15 | 3824 | hostapd_set_security_params(conf->bss[i], 0); |
31b79e11 | 3825 | |
08081ad8 | 3826 | if (hostapd_config_check(conf, 0)) { |
31b79e11 | 3827 | wpa_printf(MSG_ERROR, "Configuration check failed"); |
17706d1c | 3828 | return -1; |
31b79e11 SP |
3829 | } |
3830 | ||
3831 | return 0; | |
3832 | } |