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