]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant / Configuration parser and common functions | |
b99c4cad | 3 | * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
121adf9c | 12 | #include "utils/uuid.h" |
25ef8529 | 13 | #include "utils/ip_addr.h" |
65dfa872 | 14 | #include "common/ieee802_1x_defs.h" |
05a2fb0d | 15 | #include "common/sae.h" |
03da66bd | 16 | #include "crypto/sha1.h" |
3acb5005 | 17 | #include "rsn_supp/wpa.h" |
6fc6879b | 18 | #include "eap_peer/eap.h" |
21d996f7 | 19 | #include "p2p/p2p.h" |
76ca15b7 | 20 | #include "fst/fst.h" |
6fc6879b JM |
21 | #include "config.h" |
22 | ||
23 | ||
24 | #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE) | |
25 | #define NO_CONFIG_WRITE | |
26 | #endif | |
27 | ||
28 | /* | |
29 | * Structure for network configuration parsing. This data is used to implement | |
30 | * a generic parser for each network block variable. The table of configuration | |
31 | * variables is defined below in this file (ssid_fields[]). | |
32 | */ | |
33 | struct parse_data { | |
34 | /* Configuration variable name */ | |
35 | char *name; | |
36 | ||
5cd317d3 BKB |
37 | /* Parser function for this variable. The parser functions return 0 or 1 |
38 | * to indicate success. Value 0 indicates that the parameter value may | |
39 | * have changed while value 1 means that the value did not change. | |
40 | * Error cases (failure to parse the string) are indicated by returning | |
41 | * -1. */ | |
6fc6879b JM |
42 | int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid, |
43 | int line, const char *value); | |
44 | ||
45 | #ifndef NO_CONFIG_WRITE | |
46 | /* Writer function (i.e., to get the variable in text format from | |
47 | * internal presentation). */ | |
48 | char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid); | |
49 | #endif /* NO_CONFIG_WRITE */ | |
50 | ||
51 | /* Variable specific parameters for the parser. */ | |
52 | void *param1, *param2, *param3, *param4; | |
53 | ||
54 | /* 0 = this variable can be included in debug output and ctrl_iface | |
55 | * 1 = this variable contains key/private data and it must not be | |
56 | * included in debug output unless explicitly requested. In | |
57 | * addition, this variable will not be readable through the | |
58 | * ctrl_iface. | |
59 | */ | |
60 | int key_data; | |
61 | }; | |
62 | ||
63 | ||
6fc6879b JM |
64 | static int wpa_config_parse_str(const struct parse_data *data, |
65 | struct wpa_ssid *ssid, | |
66 | int line, const char *value) | |
67 | { | |
5cd317d3 | 68 | size_t res_len, *dst_len, prev_len; |
6fc6879b JM |
69 | char **dst, *tmp; |
70 | ||
b56c0546 JM |
71 | if (os_strcmp(value, "NULL") == 0) { |
72 | wpa_printf(MSG_DEBUG, "Unset configuration string '%s'", | |
73 | data->name); | |
74 | tmp = NULL; | |
75 | res_len = 0; | |
76 | goto set; | |
77 | } | |
78 | ||
6fc6879b JM |
79 | tmp = wpa_config_parse_string(value, &res_len); |
80 | if (tmp == NULL) { | |
81 | wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.", | |
82 | line, data->name, | |
83 | data->key_data ? "[KEY DATA REMOVED]" : value); | |
84 | return -1; | |
85 | } | |
86 | ||
87 | if (data->key_data) { | |
88 | wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name, | |
89 | (u8 *) tmp, res_len); | |
90 | } else { | |
91 | wpa_hexdump_ascii(MSG_MSGDUMP, data->name, | |
92 | (u8 *) tmp, res_len); | |
93 | } | |
94 | ||
95 | if (data->param3 && res_len < (size_t) data->param3) { | |
96 | wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu " | |
97 | "min_len=%ld)", line, data->name, | |
98 | (unsigned long) res_len, (long) data->param3); | |
99 | os_free(tmp); | |
100 | return -1; | |
101 | } | |
102 | ||
103 | if (data->param4 && res_len > (size_t) data->param4) { | |
104 | wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu " | |
105 | "max_len=%ld)", line, data->name, | |
106 | (unsigned long) res_len, (long) data->param4); | |
107 | os_free(tmp); | |
108 | return -1; | |
109 | } | |
110 | ||
b56c0546 | 111 | set: |
6fc6879b JM |
112 | dst = (char **) (((u8 *) ssid) + (long) data->param1); |
113 | dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2); | |
5cd317d3 BKB |
114 | |
115 | if (data->param2) | |
116 | prev_len = *dst_len; | |
117 | else if (*dst) | |
118 | prev_len = os_strlen(*dst); | |
119 | else | |
120 | prev_len = 0; | |
121 | if ((*dst == NULL && tmp == NULL) || | |
122 | (*dst && tmp && prev_len == res_len && | |
123 | os_memcmp(*dst, tmp, res_len) == 0)) { | |
124 | /* No change to the previously configured value */ | |
125 | os_free(tmp); | |
126 | return 1; | |
127 | } | |
128 | ||
6fc6879b JM |
129 | os_free(*dst); |
130 | *dst = tmp; | |
131 | if (data->param2) | |
132 | *dst_len = res_len; | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | ||
138 | #ifndef NO_CONFIG_WRITE | |
6fc6879b JM |
139 | static char * wpa_config_write_string_ascii(const u8 *value, size_t len) |
140 | { | |
141 | char *buf; | |
142 | ||
143 | buf = os_malloc(len + 3); | |
144 | if (buf == NULL) | |
145 | return NULL; | |
146 | buf[0] = '"'; | |
147 | os_memcpy(buf + 1, value, len); | |
148 | buf[len + 1] = '"'; | |
149 | buf[len + 2] = '\0'; | |
150 | ||
151 | return buf; | |
152 | } | |
153 | ||
154 | ||
155 | static char * wpa_config_write_string_hex(const u8 *value, size_t len) | |
156 | { | |
157 | char *buf; | |
158 | ||
159 | buf = os_zalloc(2 * len + 1); | |
160 | if (buf == NULL) | |
161 | return NULL; | |
162 | wpa_snprintf_hex(buf, 2 * len + 1, value, len); | |
163 | ||
164 | return buf; | |
165 | } | |
166 | ||
167 | ||
168 | static char * wpa_config_write_string(const u8 *value, size_t len) | |
169 | { | |
170 | if (value == NULL) | |
171 | return NULL; | |
172 | ||
173 | if (is_hex(value, len)) | |
174 | return wpa_config_write_string_hex(value, len); | |
175 | else | |
176 | return wpa_config_write_string_ascii(value, len); | |
177 | } | |
178 | ||
179 | ||
180 | static char * wpa_config_write_str(const struct parse_data *data, | |
181 | struct wpa_ssid *ssid) | |
182 | { | |
183 | size_t len; | |
184 | char **src; | |
185 | ||
186 | src = (char **) (((u8 *) ssid) + (long) data->param1); | |
187 | if (*src == NULL) | |
188 | return NULL; | |
189 | ||
190 | if (data->param2) | |
191 | len = *((size_t *) (((u8 *) ssid) + (long) data->param2)); | |
192 | else | |
193 | len = os_strlen(*src); | |
194 | ||
195 | return wpa_config_write_string((const u8 *) *src, len); | |
196 | } | |
197 | #endif /* NO_CONFIG_WRITE */ | |
198 | ||
199 | ||
200 | static int wpa_config_parse_int(const struct parse_data *data, | |
201 | struct wpa_ssid *ssid, | |
202 | int line, const char *value) | |
203 | { | |
eae3a584 JB |
204 | int val, *dst; |
205 | char *end; | |
6fc6879b JM |
206 | |
207 | dst = (int *) (((u8 *) ssid) + (long) data->param1); | |
eae3a584 JB |
208 | val = strtol(value, &end, 0); |
209 | if (*end) { | |
210 | wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"", | |
211 | line, value); | |
212 | return -1; | |
213 | } | |
5cd317d3 BKB |
214 | |
215 | if (*dst == val) | |
216 | return 1; | |
eae3a584 | 217 | *dst = val; |
6fc6879b JM |
218 | wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst); |
219 | ||
220 | if (data->param3 && *dst < (long) data->param3) { | |
221 | wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d " | |
222 | "min_value=%ld)", line, data->name, *dst, | |
223 | (long) data->param3); | |
224 | *dst = (long) data->param3; | |
225 | return -1; | |
226 | } | |
227 | ||
228 | if (data->param4 && *dst > (long) data->param4) { | |
229 | wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d " | |
230 | "max_value=%ld)", line, data->name, *dst, | |
231 | (long) data->param4); | |
232 | *dst = (long) data->param4; | |
233 | return -1; | |
234 | } | |
235 | ||
236 | return 0; | |
237 | } | |
238 | ||
239 | ||
240 | #ifndef NO_CONFIG_WRITE | |
241 | static char * wpa_config_write_int(const struct parse_data *data, | |
242 | struct wpa_ssid *ssid) | |
243 | { | |
244 | int *src, res; | |
245 | char *value; | |
246 | ||
247 | src = (int *) (((u8 *) ssid) + (long) data->param1); | |
248 | ||
249 | value = os_malloc(20); | |
250 | if (value == NULL) | |
251 | return NULL; | |
252 | res = os_snprintf(value, 20, "%d", *src); | |
d85e1fc8 | 253 | if (os_snprintf_error(20, res)) { |
6fc6879b JM |
254 | os_free(value); |
255 | return NULL; | |
256 | } | |
257 | value[20 - 1] = '\0'; | |
258 | return value; | |
259 | } | |
260 | #endif /* NO_CONFIG_WRITE */ | |
261 | ||
262 | ||
b3d6a0a8 ST |
263 | static int wpa_config_parse_addr_list(const struct parse_data *data, |
264 | int line, const char *value, | |
265 | u8 **list, size_t *num, char *name, | |
79cd993a | 266 | u8 abort_on_error, u8 masked) |
b3d6a0a8 ST |
267 | { |
268 | const char *pos; | |
79cd993a | 269 | u8 *buf, *n, addr[2 * ETH_ALEN]; |
b3d6a0a8 ST |
270 | size_t count; |
271 | ||
272 | buf = NULL; | |
273 | count = 0; | |
274 | ||
275 | pos = value; | |
276 | while (pos && *pos) { | |
277 | while (*pos == ' ') | |
278 | pos++; | |
279 | ||
79cd993a | 280 | if (hwaddr_masked_aton(pos, addr, &addr[ETH_ALEN], masked)) { |
b3d6a0a8 ST |
281 | if (abort_on_error || count == 0) { |
282 | wpa_printf(MSG_ERROR, | |
283 | "Line %d: Invalid %s address '%s'", | |
284 | line, name, value); | |
285 | os_free(buf); | |
286 | return -1; | |
287 | } | |
288 | /* continue anyway since this could have been from a | |
289 | * truncated configuration file line */ | |
290 | wpa_printf(MSG_INFO, | |
291 | "Line %d: Ignore likely truncated %s address '%s'", | |
292 | line, name, pos); | |
293 | } else { | |
79cd993a | 294 | n = os_realloc_array(buf, count + 1, 2 * ETH_ALEN); |
b3d6a0a8 ST |
295 | if (n == NULL) { |
296 | os_free(buf); | |
297 | return -1; | |
298 | } | |
299 | buf = n; | |
79cd993a ST |
300 | os_memmove(buf + 2 * ETH_ALEN, buf, |
301 | count * 2 * ETH_ALEN); | |
302 | os_memcpy(buf, addr, 2 * ETH_ALEN); | |
b3d6a0a8 | 303 | count++; |
79cd993a ST |
304 | wpa_printf(MSG_MSGDUMP, |
305 | "%s: addr=" MACSTR " mask=" MACSTR, | |
306 | name, MAC2STR(addr), | |
307 | MAC2STR(&addr[ETH_ALEN])); | |
b3d6a0a8 ST |
308 | } |
309 | ||
310 | pos = os_strchr(pos, ' '); | |
311 | } | |
312 | ||
313 | os_free(*list); | |
314 | *list = buf; | |
315 | *num = count; | |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
320 | ||
321 | #ifndef NO_CONFIG_WRITE | |
322 | static char * wpa_config_write_addr_list(const struct parse_data *data, | |
323 | const u8 *list, size_t num, char *name) | |
324 | { | |
325 | char *value, *end, *pos; | |
326 | int res; | |
327 | size_t i; | |
328 | ||
329 | if (list == NULL || num == 0) | |
330 | return NULL; | |
331 | ||
79cd993a | 332 | value = os_malloc(2 * 20 * num); |
b3d6a0a8 ST |
333 | if (value == NULL) |
334 | return NULL; | |
335 | pos = value; | |
79cd993a | 336 | end = value + 2 * 20 * num; |
b3d6a0a8 ST |
337 | |
338 | for (i = num; i > 0; i--) { | |
79cd993a ST |
339 | const u8 *a = list + (i - 1) * 2 * ETH_ALEN; |
340 | const u8 *m = a + ETH_ALEN; | |
341 | ||
342 | if (i < num) | |
343 | *pos++ = ' '; | |
344 | res = hwaddr_mask_txt(pos, end - pos, a, m); | |
345 | if (res < 0) { | |
b3d6a0a8 ST |
346 | os_free(value); |
347 | return NULL; | |
348 | } | |
349 | pos += res; | |
350 | } | |
351 | ||
b3d6a0a8 ST |
352 | return value; |
353 | } | |
354 | #endif /* NO_CONFIG_WRITE */ | |
355 | ||
6fc6879b JM |
356 | static int wpa_config_parse_bssid(const struct parse_data *data, |
357 | struct wpa_ssid *ssid, int line, | |
358 | const char *value) | |
359 | { | |
c0a321c5 WJL |
360 | if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 || |
361 | os_strcmp(value, "any") == 0) { | |
362 | ssid->bssid_set = 0; | |
363 | wpa_printf(MSG_MSGDUMP, "BSSID any"); | |
364 | return 0; | |
365 | } | |
6fc6879b JM |
366 | if (hwaddr_aton(value, ssid->bssid)) { |
367 | wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.", | |
368 | line, value); | |
369 | return -1; | |
370 | } | |
371 | ssid->bssid_set = 1; | |
372 | wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN); | |
373 | return 0; | |
374 | } | |
375 | ||
376 | ||
377 | #ifndef NO_CONFIG_WRITE | |
378 | static char * wpa_config_write_bssid(const struct parse_data *data, | |
379 | struct wpa_ssid *ssid) | |
380 | { | |
381 | char *value; | |
382 | int res; | |
383 | ||
384 | if (!ssid->bssid_set) | |
385 | return NULL; | |
386 | ||
387 | value = os_malloc(20); | |
388 | if (value == NULL) | |
389 | return NULL; | |
390 | res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid)); | |
d85e1fc8 | 391 | if (os_snprintf_error(20, res)) { |
6fc6879b JM |
392 | os_free(value); |
393 | return NULL; | |
394 | } | |
395 | value[20 - 1] = '\0'; | |
396 | return value; | |
397 | } | |
398 | #endif /* NO_CONFIG_WRITE */ | |
399 | ||
400 | ||
43a356b2 PK |
401 | static int wpa_config_parse_bssid_hint(const struct parse_data *data, |
402 | struct wpa_ssid *ssid, int line, | |
403 | const char *value) | |
404 | { | |
405 | if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 || | |
406 | os_strcmp(value, "any") == 0) { | |
407 | ssid->bssid_hint_set = 0; | |
408 | wpa_printf(MSG_MSGDUMP, "BSSID hint any"); | |
409 | return 0; | |
410 | } | |
411 | if (hwaddr_aton(value, ssid->bssid_hint)) { | |
412 | wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID hint '%s'.", | |
413 | line, value); | |
414 | return -1; | |
415 | } | |
416 | ssid->bssid_hint_set = 1; | |
417 | wpa_hexdump(MSG_MSGDUMP, "BSSID hint", ssid->bssid_hint, ETH_ALEN); | |
418 | return 0; | |
419 | } | |
420 | ||
421 | ||
422 | #ifndef NO_CONFIG_WRITE | |
423 | static char * wpa_config_write_bssid_hint(const struct parse_data *data, | |
424 | struct wpa_ssid *ssid) | |
425 | { | |
426 | char *value; | |
427 | int res; | |
428 | ||
429 | if (!ssid->bssid_hint_set) | |
430 | return NULL; | |
431 | ||
432 | value = os_malloc(20); | |
433 | if (!value) | |
434 | return NULL; | |
435 | res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid_hint)); | |
436 | if (os_snprintf_error(20, res)) { | |
437 | os_free(value); | |
438 | return NULL; | |
439 | } | |
440 | return value; | |
441 | } | |
442 | #endif /* NO_CONFIG_WRITE */ | |
443 | ||
444 | ||
b83e4554 ST |
445 | static int wpa_config_parse_bssid_blacklist(const struct parse_data *data, |
446 | struct wpa_ssid *ssid, int line, | |
447 | const char *value) | |
448 | { | |
449 | return wpa_config_parse_addr_list(data, line, value, | |
450 | &ssid->bssid_blacklist, | |
451 | &ssid->num_bssid_blacklist, | |
79cd993a | 452 | "bssid_blacklist", 1, 1); |
b83e4554 ST |
453 | } |
454 | ||
455 | ||
456 | #ifndef NO_CONFIG_WRITE | |
457 | static char * wpa_config_write_bssid_blacklist(const struct parse_data *data, | |
458 | struct wpa_ssid *ssid) | |
459 | { | |
460 | return wpa_config_write_addr_list(data, ssid->bssid_blacklist, | |
461 | ssid->num_bssid_blacklist, | |
462 | "bssid_blacklist"); | |
463 | } | |
464 | #endif /* NO_CONFIG_WRITE */ | |
465 | ||
466 | ||
467 | static int wpa_config_parse_bssid_whitelist(const struct parse_data *data, | |
468 | struct wpa_ssid *ssid, int line, | |
469 | const char *value) | |
470 | { | |
471 | return wpa_config_parse_addr_list(data, line, value, | |
472 | &ssid->bssid_whitelist, | |
473 | &ssid->num_bssid_whitelist, | |
79cd993a | 474 | "bssid_whitelist", 1, 1); |
b83e4554 ST |
475 | } |
476 | ||
477 | ||
478 | #ifndef NO_CONFIG_WRITE | |
479 | static char * wpa_config_write_bssid_whitelist(const struct parse_data *data, | |
480 | struct wpa_ssid *ssid) | |
481 | { | |
482 | return wpa_config_write_addr_list(data, ssid->bssid_whitelist, | |
483 | ssid->num_bssid_whitelist, | |
484 | "bssid_whitelist"); | |
485 | } | |
486 | #endif /* NO_CONFIG_WRITE */ | |
487 | ||
488 | ||
6fc6879b JM |
489 | static int wpa_config_parse_psk(const struct parse_data *data, |
490 | struct wpa_ssid *ssid, int line, | |
491 | const char *value) | |
492 | { | |
9173b16f JM |
493 | #ifdef CONFIG_EXT_PASSWORD |
494 | if (os_strncmp(value, "ext:", 4) == 0) { | |
19c48da0 | 495 | str_clear_free(ssid->passphrase); |
9173b16f JM |
496 | ssid->passphrase = NULL; |
497 | ssid->psk_set = 0; | |
498 | os_free(ssid->ext_psk); | |
499 | ssid->ext_psk = os_strdup(value + 4); | |
500 | if (ssid->ext_psk == NULL) | |
501 | return -1; | |
502 | wpa_printf(MSG_DEBUG, "PSK: External password '%s'", | |
503 | ssid->ext_psk); | |
504 | return 0; | |
505 | } | |
506 | #endif /* CONFIG_EXT_PASSWORD */ | |
507 | ||
6fc6879b JM |
508 | if (*value == '"') { |
509 | #ifndef CONFIG_NO_PBKDF2 | |
510 | const char *pos; | |
511 | size_t len; | |
512 | ||
513 | value++; | |
514 | pos = os_strrchr(value, '"'); | |
515 | if (pos) | |
516 | len = pos - value; | |
517 | else | |
518 | len = os_strlen(value); | |
519 | if (len < 8 || len > 63) { | |
520 | wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase " | |
521 | "length %lu (expected: 8..63) '%s'.", | |
522 | line, (unsigned long) len, value); | |
523 | return -1; | |
524 | } | |
525 | wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)", | |
526 | (u8 *) value, len); | |
73e4abb2 JM |
527 | if (has_ctrl_char((u8 *) value, len)) { |
528 | wpa_printf(MSG_ERROR, | |
529 | "Line %d: Invalid passphrase character", | |
530 | line); | |
531 | return -1; | |
532 | } | |
6fc6879b | 533 | if (ssid->passphrase && os_strlen(ssid->passphrase) == len && |
5cd317d3 BKB |
534 | os_memcmp(ssid->passphrase, value, len) == 0) { |
535 | /* No change to the previously configured value */ | |
536 | return 1; | |
537 | } | |
6fc6879b | 538 | ssid->psk_set = 0; |
19c48da0 | 539 | str_clear_free(ssid->passphrase); |
5e24dc8a | 540 | ssid->passphrase = dup_binstr(value, len); |
6fc6879b JM |
541 | if (ssid->passphrase == NULL) |
542 | return -1; | |
6fc6879b JM |
543 | return 0; |
544 | #else /* CONFIG_NO_PBKDF2 */ | |
545 | wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not " | |
546 | "supported.", line); | |
547 | return -1; | |
548 | #endif /* CONFIG_NO_PBKDF2 */ | |
549 | } | |
550 | ||
551 | if (hexstr2bin(value, ssid->psk, PMK_LEN) || | |
552 | value[PMK_LEN * 2] != '\0') { | |
553 | wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.", | |
554 | line, value); | |
555 | return -1; | |
556 | } | |
557 | ||
19c48da0 | 558 | str_clear_free(ssid->passphrase); |
6fc6879b JM |
559 | ssid->passphrase = NULL; |
560 | ||
561 | ssid->psk_set = 1; | |
562 | wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN); | |
563 | return 0; | |
564 | } | |
565 | ||
566 | ||
567 | #ifndef NO_CONFIG_WRITE | |
568 | static char * wpa_config_write_psk(const struct parse_data *data, | |
569 | struct wpa_ssid *ssid) | |
570 | { | |
9173b16f JM |
571 | #ifdef CONFIG_EXT_PASSWORD |
572 | if (ssid->ext_psk) { | |
573 | size_t len = 4 + os_strlen(ssid->ext_psk) + 1; | |
574 | char *buf = os_malloc(len); | |
1d399771 JM |
575 | int res; |
576 | ||
9173b16f JM |
577 | if (buf == NULL) |
578 | return NULL; | |
1d399771 JM |
579 | res = os_snprintf(buf, len, "ext:%s", ssid->ext_psk); |
580 | if (os_snprintf_error(len, res)) { | |
581 | os_free(buf); | |
582 | buf = NULL; | |
583 | } | |
9173b16f JM |
584 | return buf; |
585 | } | |
586 | #endif /* CONFIG_EXT_PASSWORD */ | |
587 | ||
6fc6879b JM |
588 | if (ssid->passphrase) |
589 | return wpa_config_write_string_ascii( | |
590 | (const u8 *) ssid->passphrase, | |
591 | os_strlen(ssid->passphrase)); | |
592 | ||
593 | if (ssid->psk_set) | |
594 | return wpa_config_write_string_hex(ssid->psk, PMK_LEN); | |
595 | ||
596 | return NULL; | |
597 | } | |
598 | #endif /* NO_CONFIG_WRITE */ | |
599 | ||
600 | ||
601 | static int wpa_config_parse_proto(const struct parse_data *data, | |
602 | struct wpa_ssid *ssid, int line, | |
603 | const char *value) | |
604 | { | |
605 | int val = 0, last, errors = 0; | |
606 | char *start, *end, *buf; | |
607 | ||
608 | buf = os_strdup(value); | |
609 | if (buf == NULL) | |
610 | return -1; | |
611 | start = buf; | |
612 | ||
613 | while (*start != '\0') { | |
614 | while (*start == ' ' || *start == '\t') | |
615 | start++; | |
616 | if (*start == '\0') | |
617 | break; | |
618 | end = start; | |
619 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
620 | end++; | |
621 | last = *end == '\0'; | |
622 | *end = '\0'; | |
623 | if (os_strcmp(start, "WPA") == 0) | |
624 | val |= WPA_PROTO_WPA; | |
625 | else if (os_strcmp(start, "RSN") == 0 || | |
626 | os_strcmp(start, "WPA2") == 0) | |
627 | val |= WPA_PROTO_RSN; | |
df0f01d9 JM |
628 | else if (os_strcmp(start, "OSEN") == 0) |
629 | val |= WPA_PROTO_OSEN; | |
6fc6879b JM |
630 | else { |
631 | wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'", | |
632 | line, start); | |
633 | errors++; | |
634 | } | |
635 | ||
636 | if (last) | |
637 | break; | |
638 | start = end + 1; | |
639 | } | |
640 | os_free(buf); | |
641 | ||
642 | if (val == 0) { | |
643 | wpa_printf(MSG_ERROR, | |
644 | "Line %d: no proto values configured.", line); | |
645 | errors++; | |
646 | } | |
647 | ||
5cd317d3 BKB |
648 | if (!errors && ssid->proto == val) |
649 | return 1; | |
6fc6879b JM |
650 | wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val); |
651 | ssid->proto = val; | |
652 | return errors ? -1 : 0; | |
653 | } | |
654 | ||
655 | ||
656 | #ifndef NO_CONFIG_WRITE | |
657 | static char * wpa_config_write_proto(const struct parse_data *data, | |
658 | struct wpa_ssid *ssid) | |
659 | { | |
290ea6a7 | 660 | int ret; |
6fc6879b JM |
661 | char *buf, *pos, *end; |
662 | ||
3141b82c | 663 | pos = buf = os_zalloc(20); |
6fc6879b JM |
664 | if (buf == NULL) |
665 | return NULL; | |
3141b82c | 666 | end = buf + 20; |
6fc6879b JM |
667 | |
668 | if (ssid->proto & WPA_PROTO_WPA) { | |
290ea6a7 JM |
669 | ret = os_snprintf(pos, end - pos, "%sWPA", |
670 | pos == buf ? "" : " "); | |
d85e1fc8 | 671 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
672 | return buf; |
673 | pos += ret; | |
6fc6879b JM |
674 | } |
675 | ||
676 | if (ssid->proto & WPA_PROTO_RSN) { | |
290ea6a7 JM |
677 | ret = os_snprintf(pos, end - pos, "%sRSN", |
678 | pos == buf ? "" : " "); | |
d85e1fc8 | 679 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
680 | return buf; |
681 | pos += ret; | |
6fc6879b JM |
682 | } |
683 | ||
3141b82c | 684 | if (ssid->proto & WPA_PROTO_OSEN) { |
290ea6a7 JM |
685 | ret = os_snprintf(pos, end - pos, "%sOSEN", |
686 | pos == buf ? "" : " "); | |
d85e1fc8 | 687 | if (os_snprintf_error(end - pos, ret)) |
3141b82c JM |
688 | return buf; |
689 | pos += ret; | |
3141b82c JM |
690 | } |
691 | ||
a1e46f32 JM |
692 | if (pos == buf) { |
693 | os_free(buf); | |
694 | buf = NULL; | |
695 | } | |
696 | ||
6fc6879b JM |
697 | return buf; |
698 | } | |
699 | #endif /* NO_CONFIG_WRITE */ | |
700 | ||
701 | ||
702 | static int wpa_config_parse_key_mgmt(const struct parse_data *data, | |
703 | struct wpa_ssid *ssid, int line, | |
704 | const char *value) | |
705 | { | |
706 | int val = 0, last, errors = 0; | |
707 | char *start, *end, *buf; | |
708 | ||
709 | buf = os_strdup(value); | |
710 | if (buf == NULL) | |
711 | return -1; | |
712 | start = buf; | |
713 | ||
714 | while (*start != '\0') { | |
715 | while (*start == ' ' || *start == '\t') | |
716 | start++; | |
717 | if (*start == '\0') | |
718 | break; | |
719 | end = start; | |
720 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
721 | end++; | |
722 | last = *end == '\0'; | |
723 | *end = '\0'; | |
724 | if (os_strcmp(start, "WPA-PSK") == 0) | |
725 | val |= WPA_KEY_MGMT_PSK; | |
726 | else if (os_strcmp(start, "WPA-EAP") == 0) | |
727 | val |= WPA_KEY_MGMT_IEEE8021X; | |
728 | else if (os_strcmp(start, "IEEE8021X") == 0) | |
729 | val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA; | |
730 | else if (os_strcmp(start, "NONE") == 0) | |
731 | val |= WPA_KEY_MGMT_NONE; | |
732 | else if (os_strcmp(start, "WPA-NONE") == 0) | |
733 | val |= WPA_KEY_MGMT_WPA_NONE; | |
734 | #ifdef CONFIG_IEEE80211R | |
735 | else if (os_strcmp(start, "FT-PSK") == 0) | |
736 | val |= WPA_KEY_MGMT_FT_PSK; | |
737 | else if (os_strcmp(start, "FT-EAP") == 0) | |
738 | val |= WPA_KEY_MGMT_FT_IEEE8021X; | |
d8e8c992 JM |
739 | #ifdef CONFIG_SHA384 |
740 | else if (os_strcmp(start, "FT-EAP-SHA384") == 0) | |
741 | val |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384; | |
742 | #endif /* CONFIG_SHA384 */ | |
6fc6879b | 743 | #endif /* CONFIG_IEEE80211R */ |
56586197 JM |
744 | else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) |
745 | val |= WPA_KEY_MGMT_PSK_SHA256; | |
746 | else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) | |
747 | val |= WPA_KEY_MGMT_IEEE8021X_SHA256; | |
ad08c363 JM |
748 | #ifdef CONFIG_WPS |
749 | else if (os_strcmp(start, "WPS") == 0) | |
750 | val |= WPA_KEY_MGMT_WPS; | |
751 | #endif /* CONFIG_WPS */ | |
c10347f2 JM |
752 | #ifdef CONFIG_SAE |
753 | else if (os_strcmp(start, "SAE") == 0) | |
754 | val |= WPA_KEY_MGMT_SAE; | |
755 | else if (os_strcmp(start, "FT-SAE") == 0) | |
756 | val |= WPA_KEY_MGMT_FT_SAE; | |
757 | #endif /* CONFIG_SAE */ | |
df0f01d9 JM |
758 | #ifdef CONFIG_HS20 |
759 | else if (os_strcmp(start, "OSEN") == 0) | |
760 | val |= WPA_KEY_MGMT_OSEN; | |
761 | #endif /* CONFIG_HS20 */ | |
5e3b5197 | 762 | #ifdef CONFIG_SUITEB |
666497c8 JM |
763 | else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0) |
764 | val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B; | |
5e3b5197 JM |
765 | #endif /* CONFIG_SUITEB */ |
766 | #ifdef CONFIG_SUITEB192 | |
767 | else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0) | |
768 | val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; | |
769 | #endif /* CONFIG_SUITEB192 */ | |
9b7a2b83 JM |
770 | #ifdef CONFIG_FILS |
771 | else if (os_strcmp(start, "FILS-SHA256") == 0) | |
772 | val |= WPA_KEY_MGMT_FILS_SHA256; | |
773 | else if (os_strcmp(start, "FILS-SHA384") == 0) | |
774 | val |= WPA_KEY_MGMT_FILS_SHA384; | |
775 | #ifdef CONFIG_IEEE80211R | |
776 | else if (os_strcmp(start, "FT-FILS-SHA256") == 0) | |
777 | val |= WPA_KEY_MGMT_FT_FILS_SHA256; | |
778 | else if (os_strcmp(start, "FT-FILS-SHA384") == 0) | |
779 | val |= WPA_KEY_MGMT_FT_FILS_SHA384; | |
780 | #endif /* CONFIG_IEEE80211R */ | |
781 | #endif /* CONFIG_FILS */ | |
a1ea1b45 JM |
782 | #ifdef CONFIG_OWE |
783 | else if (os_strcmp(start, "OWE") == 0) | |
784 | val |= WPA_KEY_MGMT_OWE; | |
785 | #endif /* CONFIG_OWE */ | |
567da5bb JM |
786 | #ifdef CONFIG_DPP |
787 | else if (os_strcmp(start, "DPP") == 0) | |
788 | val |= WPA_KEY_MGMT_DPP; | |
789 | #endif /* CONFIG_DPP */ | |
6fc6879b JM |
790 | else { |
791 | wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", | |
792 | line, start); | |
793 | errors++; | |
794 | } | |
795 | ||
796 | if (last) | |
797 | break; | |
798 | start = end + 1; | |
799 | } | |
800 | os_free(buf); | |
801 | ||
802 | if (val == 0) { | |
803 | wpa_printf(MSG_ERROR, | |
804 | "Line %d: no key_mgmt values configured.", line); | |
805 | errors++; | |
806 | } | |
807 | ||
5cd317d3 BKB |
808 | if (!errors && ssid->key_mgmt == val) |
809 | return 1; | |
6fc6879b JM |
810 | wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val); |
811 | ssid->key_mgmt = val; | |
812 | return errors ? -1 : 0; | |
813 | } | |
814 | ||
815 | ||
816 | #ifndef NO_CONFIG_WRITE | |
817 | static char * wpa_config_write_key_mgmt(const struct parse_data *data, | |
818 | struct wpa_ssid *ssid) | |
819 | { | |
820 | char *buf, *pos, *end; | |
821 | int ret; | |
822 | ||
50793929 | 823 | pos = buf = os_zalloc(100); |
6fc6879b JM |
824 | if (buf == NULL) |
825 | return NULL; | |
50793929 | 826 | end = buf + 100; |
6fc6879b JM |
827 | |
828 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) { | |
829 | ret = os_snprintf(pos, end - pos, "%sWPA-PSK", | |
830 | pos == buf ? "" : " "); | |
d85e1fc8 | 831 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
832 | end[-1] = '\0'; |
833 | return buf; | |
834 | } | |
835 | pos += ret; | |
836 | } | |
837 | ||
838 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) { | |
839 | ret = os_snprintf(pos, end - pos, "%sWPA-EAP", | |
840 | pos == buf ? "" : " "); | |
d85e1fc8 | 841 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
842 | end[-1] = '\0'; |
843 | return buf; | |
844 | } | |
845 | pos += ret; | |
846 | } | |
847 | ||
848 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
849 | ret = os_snprintf(pos, end - pos, "%sIEEE8021X", | |
850 | pos == buf ? "" : " "); | |
d85e1fc8 | 851 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
852 | end[-1] = '\0'; |
853 | return buf; | |
854 | } | |
855 | pos += ret; | |
856 | } | |
857 | ||
858 | if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) { | |
859 | ret = os_snprintf(pos, end - pos, "%sNONE", | |
860 | pos == buf ? "" : " "); | |
d85e1fc8 | 861 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
862 | end[-1] = '\0'; |
863 | return buf; | |
864 | } | |
865 | pos += ret; | |
866 | } | |
867 | ||
868 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) { | |
869 | ret = os_snprintf(pos, end - pos, "%sWPA-NONE", | |
870 | pos == buf ? "" : " "); | |
d85e1fc8 | 871 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
872 | end[-1] = '\0'; |
873 | return buf; | |
874 | } | |
875 | pos += ret; | |
876 | } | |
877 | ||
878 | #ifdef CONFIG_IEEE80211R | |
50793929 PF |
879 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) { |
880 | ret = os_snprintf(pos, end - pos, "%sFT-PSK", | |
881 | pos == buf ? "" : " "); | |
d85e1fc8 | 882 | if (os_snprintf_error(end - pos, ret)) { |
50793929 PF |
883 | end[-1] = '\0'; |
884 | return buf; | |
885 | } | |
886 | pos += ret; | |
887 | } | |
6fc6879b | 888 | |
50793929 PF |
889 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { |
890 | ret = os_snprintf(pos, end - pos, "%sFT-EAP", | |
891 | pos == buf ? "" : " "); | |
d85e1fc8 | 892 | if (os_snprintf_error(end - pos, ret)) { |
50793929 PF |
893 | end[-1] = '\0'; |
894 | return buf; | |
895 | } | |
896 | pos += ret; | |
897 | } | |
d8e8c992 JM |
898 | |
899 | #ifdef CONFIG_SHA384 | |
900 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) { | |
901 | ret = os_snprintf(pos, end - pos, "%sFT-EAP-SHA384", | |
902 | pos == buf ? "" : " "); | |
903 | if (os_snprintf_error(end - pos, ret)) { | |
904 | end[-1] = '\0'; | |
905 | return buf; | |
906 | } | |
907 | pos += ret; | |
908 | } | |
909 | #endif /* CONFIG_SHA384 */ | |
6fc6879b JM |
910 | #endif /* CONFIG_IEEE80211R */ |
911 | ||
50793929 PF |
912 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { |
913 | ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256", | |
914 | pos == buf ? "" : " "); | |
d85e1fc8 | 915 | if (os_snprintf_error(end - pos, ret)) { |
50793929 PF |
916 | end[-1] = '\0'; |
917 | return buf; | |
918 | } | |
919 | pos += ret; | |
920 | } | |
56586197 | 921 | |
50793929 PF |
922 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
923 | ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256", | |
924 | pos == buf ? "" : " "); | |
d85e1fc8 | 925 | if (os_snprintf_error(end - pos, ret)) { |
50793929 PF |
926 | end[-1] = '\0'; |
927 | return buf; | |
928 | } | |
929 | pos += ret; | |
930 | } | |
56586197 | 931 | |
728fae16 | 932 | #ifdef CONFIG_WPS |
50793929 PF |
933 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
934 | ret = os_snprintf(pos, end - pos, "%sWPS", | |
935 | pos == buf ? "" : " "); | |
d85e1fc8 | 936 | if (os_snprintf_error(end - pos, ret)) { |
50793929 PF |
937 | end[-1] = '\0'; |
938 | return buf; | |
939 | } | |
940 | pos += ret; | |
941 | } | |
728fae16 JM |
942 | #endif /* CONFIG_WPS */ |
943 | ||
d3fd563f TP |
944 | #ifdef CONFIG_SAE |
945 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) { | |
946 | ret = os_snprintf(pos, end - pos, "%sSAE", | |
947 | pos == buf ? "" : " "); | |
d85e1fc8 | 948 | if (os_snprintf_error(end - pos, ret)) { |
d3fd563f TP |
949 | end[-1] = '\0'; |
950 | return buf; | |
951 | } | |
952 | pos += ret; | |
953 | } | |
954 | ||
955 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) { | |
956 | ret = os_snprintf(pos, end - pos, "%sFT-SAE", | |
957 | pos == buf ? "" : " "); | |
d85e1fc8 | 958 | if (os_snprintf_error(end - pos, ret)) { |
d3fd563f TP |
959 | end[-1] = '\0'; |
960 | return buf; | |
961 | } | |
962 | pos += ret; | |
963 | } | |
964 | #endif /* CONFIG_SAE */ | |
965 | ||
2d6ee86f JM |
966 | #ifdef CONFIG_HS20 |
967 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) { | |
968 | ret = os_snprintf(pos, end - pos, "%sOSEN", | |
969 | pos == buf ? "" : " "); | |
d85e1fc8 | 970 | if (os_snprintf_error(end - pos, ret)) { |
2d6ee86f JM |
971 | end[-1] = '\0'; |
972 | return buf; | |
973 | } | |
974 | pos += ret; | |
975 | } | |
976 | #endif /* CONFIG_HS20 */ | |
977 | ||
5e3b5197 | 978 | #ifdef CONFIG_SUITEB |
666497c8 JM |
979 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
980 | ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B", | |
981 | pos == buf ? "" : " "); | |
d85e1fc8 | 982 | if (os_snprintf_error(end - pos, ret)) { |
666497c8 JM |
983 | end[-1] = '\0'; |
984 | return buf; | |
985 | } | |
986 | pos += ret; | |
987 | } | |
5e3b5197 JM |
988 | #endif /* CONFIG_SUITEB */ |
989 | ||
990 | #ifdef CONFIG_SUITEB192 | |
991 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
992 | ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B-192", | |
993 | pos == buf ? "" : " "); | |
994 | if (os_snprintf_error(end - pos, ret)) { | |
995 | end[-1] = '\0'; | |
996 | return buf; | |
997 | } | |
998 | pos += ret; | |
999 | } | |
1000 | #endif /* CONFIG_SUITEB192 */ | |
666497c8 | 1001 | |
199eb3a4 | 1002 | #ifdef CONFIG_FILS |
1003 | if (ssid->key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { | |
1004 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA256", | |
1005 | pos == buf ? "" : " "); | |
1006 | if (os_snprintf_error(end - pos, ret)) { | |
1007 | end[-1] = '\0'; | |
1008 | return buf; | |
1009 | } | |
1010 | pos += ret; | |
1011 | } | |
1012 | if (ssid->key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { | |
1013 | ret = os_snprintf(pos, end - pos, "%sFILS-SHA384", | |
1014 | pos == buf ? "" : " "); | |
1015 | if (os_snprintf_error(end - pos, ret)) { | |
1016 | end[-1] = '\0'; | |
1017 | return buf; | |
1018 | } | |
1019 | pos += ret; | |
1020 | } | |
1021 | #ifdef CONFIG_IEEE80211R | |
1022 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { | |
1023 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256", | |
1024 | pos == buf ? "" : " "); | |
1025 | if (os_snprintf_error(end - pos, ret)) { | |
1026 | end[-1] = '\0'; | |
1027 | return buf; | |
1028 | } | |
1029 | pos += ret; | |
1030 | } | |
1031 | if (ssid->key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { | |
1032 | ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384", | |
1033 | pos == buf ? "" : " "); | |
1034 | if (os_snprintf_error(end - pos, ret)) { | |
1035 | end[-1] = '\0'; | |
1036 | return buf; | |
1037 | } | |
1038 | pos += ret; | |
1039 | } | |
1040 | #endif /* CONFIG_IEEE80211R */ | |
1041 | #endif /* CONFIG_FILS */ | |
1042 | ||
ad6a9247 DRC |
1043 | #ifdef CONFIG_DPP |
1044 | if (ssid->key_mgmt & WPA_KEY_MGMT_DPP) { | |
1045 | ret = os_snprintf(pos, end - pos, "%sDPP", | |
1046 | pos == buf ? "" : " "); | |
1047 | if (os_snprintf_error(end - pos, ret)) { | |
1048 | end[-1] = '\0'; | |
1049 | return buf; | |
1050 | } | |
1051 | pos += ret; | |
1052 | } | |
1053 | #endif /* CONFIG_DPP */ | |
1054 | ||
06c00e6d JM |
1055 | #ifdef CONFIG_OWE |
1056 | if (ssid->key_mgmt & WPA_KEY_MGMT_OWE) { | |
1057 | ret = os_snprintf(pos, end - pos, "%sOWE", | |
1058 | pos == buf ? "" : " "); | |
1059 | if (os_snprintf_error(end - pos, ret)) { | |
1060 | end[-1] = '\0'; | |
1061 | return buf; | |
1062 | } | |
1063 | pos += ret; | |
1064 | } | |
1065 | #endif /* CONFIG_OWE */ | |
1066 | ||
a1e46f32 JM |
1067 | if (pos == buf) { |
1068 | os_free(buf); | |
1069 | buf = NULL; | |
1070 | } | |
1071 | ||
6fc6879b JM |
1072 | return buf; |
1073 | } | |
1074 | #endif /* NO_CONFIG_WRITE */ | |
1075 | ||
1076 | ||
1077 | static int wpa_config_parse_cipher(int line, const char *value) | |
1078 | { | |
9e68742e JM |
1079 | #ifdef CONFIG_NO_WPA |
1080 | return -1; | |
1081 | #else /* CONFIG_NO_WPA */ | |
a39c78be JM |
1082 | int val = wpa_parse_cipher(value); |
1083 | if (val < 0) { | |
1084 | wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", | |
1085 | line, value); | |
6fc6879b | 1086 | return -1; |
6fc6879b | 1087 | } |
6fc6879b JM |
1088 | if (val == 0) { |
1089 | wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", | |
1090 | line); | |
1091 | return -1; | |
1092 | } | |
1093 | return val; | |
9e68742e | 1094 | #endif /* CONFIG_NO_WPA */ |
6fc6879b JM |
1095 | } |
1096 | ||
1097 | ||
1098 | #ifndef NO_CONFIG_WRITE | |
1099 | static char * wpa_config_write_cipher(int cipher) | |
1100 | { | |
9e68742e JM |
1101 | #ifdef CONFIG_NO_WPA |
1102 | return NULL; | |
1103 | #else /* CONFIG_NO_WPA */ | |
0282a8c4 | 1104 | char *buf = os_zalloc(50); |
6fc6879b JM |
1105 | if (buf == NULL) |
1106 | return NULL; | |
6fc6879b | 1107 | |
0282a8c4 JM |
1108 | if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) { |
1109 | os_free(buf); | |
1110 | return NULL; | |
6fc6879b JM |
1111 | } |
1112 | ||
1113 | return buf; | |
9e68742e | 1114 | #endif /* CONFIG_NO_WPA */ |
6fc6879b JM |
1115 | } |
1116 | #endif /* NO_CONFIG_WRITE */ | |
1117 | ||
1118 | ||
1119 | static int wpa_config_parse_pairwise(const struct parse_data *data, | |
1120 | struct wpa_ssid *ssid, int line, | |
1121 | const char *value) | |
1122 | { | |
1123 | int val; | |
1124 | val = wpa_config_parse_cipher(line, value); | |
1125 | if (val == -1) | |
1126 | return -1; | |
03145326 | 1127 | if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) { |
6fc6879b JM |
1128 | wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher " |
1129 | "(0x%x).", line, val); | |
1130 | return -1; | |
1131 | } | |
1132 | ||
5cd317d3 BKB |
1133 | if (ssid->pairwise_cipher == val) |
1134 | return 1; | |
6fc6879b JM |
1135 | wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val); |
1136 | ssid->pairwise_cipher = val; | |
1137 | return 0; | |
1138 | } | |
1139 | ||
1140 | ||
1141 | #ifndef NO_CONFIG_WRITE | |
1142 | static char * wpa_config_write_pairwise(const struct parse_data *data, | |
1143 | struct wpa_ssid *ssid) | |
1144 | { | |
1145 | return wpa_config_write_cipher(ssid->pairwise_cipher); | |
1146 | } | |
1147 | #endif /* NO_CONFIG_WRITE */ | |
1148 | ||
1149 | ||
1150 | static int wpa_config_parse_group(const struct parse_data *data, | |
1151 | struct wpa_ssid *ssid, int line, | |
1152 | const char *value) | |
1153 | { | |
1154 | int val; | |
1155 | val = wpa_config_parse_cipher(line, value); | |
1156 | if (val == -1) | |
1157 | return -1; | |
ce8963fc JM |
1158 | |
1159 | /* | |
1160 | * Backwards compatibility - filter out WEP ciphers that were previously | |
1161 | * allowed. | |
1162 | */ | |
1163 | val &= ~(WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40); | |
1164 | ||
03145326 | 1165 | if (val & ~WPA_ALLOWED_GROUP_CIPHERS) { |
6fc6879b JM |
1166 | wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher " |
1167 | "(0x%x).", line, val); | |
1168 | return -1; | |
1169 | } | |
1170 | ||
5cd317d3 BKB |
1171 | if (ssid->group_cipher == val) |
1172 | return 1; | |
6fc6879b JM |
1173 | wpa_printf(MSG_MSGDUMP, "group: 0x%x", val); |
1174 | ssid->group_cipher = val; | |
1175 | return 0; | |
1176 | } | |
1177 | ||
1178 | ||
1179 | #ifndef NO_CONFIG_WRITE | |
1180 | static char * wpa_config_write_group(const struct parse_data *data, | |
1181 | struct wpa_ssid *ssid) | |
1182 | { | |
1183 | return wpa_config_write_cipher(ssid->group_cipher); | |
1184 | } | |
1185 | #endif /* NO_CONFIG_WRITE */ | |
1186 | ||
1187 | ||
61a56c14 JM |
1188 | static int wpa_config_parse_group_mgmt(const struct parse_data *data, |
1189 | struct wpa_ssid *ssid, int line, | |
1190 | const char *value) | |
1191 | { | |
1192 | int val; | |
1193 | ||
1194 | val = wpa_config_parse_cipher(line, value); | |
1195 | if (val == -1) | |
1196 | return -1; | |
1197 | ||
1198 | if (val & ~WPA_ALLOWED_GROUP_MGMT_CIPHERS) { | |
1199 | wpa_printf(MSG_ERROR, | |
1200 | "Line %d: not allowed group management cipher (0x%x).", | |
1201 | line, val); | |
1202 | return -1; | |
1203 | } | |
1204 | ||
1205 | if (ssid->group_mgmt_cipher == val) | |
1206 | return 1; | |
1207 | wpa_printf(MSG_MSGDUMP, "group_mgmt: 0x%x", val); | |
1208 | ssid->group_mgmt_cipher = val; | |
1209 | return 0; | |
1210 | } | |
1211 | ||
1212 | ||
1213 | #ifndef NO_CONFIG_WRITE | |
1214 | static char * wpa_config_write_group_mgmt(const struct parse_data *data, | |
1215 | struct wpa_ssid *ssid) | |
1216 | { | |
1217 | return wpa_config_write_cipher(ssid->group_mgmt_cipher); | |
1218 | } | |
1219 | #endif /* NO_CONFIG_WRITE */ | |
1220 | ||
1221 | ||
6fc6879b JM |
1222 | static int wpa_config_parse_auth_alg(const struct parse_data *data, |
1223 | struct wpa_ssid *ssid, int line, | |
1224 | const char *value) | |
1225 | { | |
1226 | int val = 0, last, errors = 0; | |
1227 | char *start, *end, *buf; | |
1228 | ||
1229 | buf = os_strdup(value); | |
1230 | if (buf == NULL) | |
1231 | return -1; | |
1232 | start = buf; | |
1233 | ||
1234 | while (*start != '\0') { | |
1235 | while (*start == ' ' || *start == '\t') | |
1236 | start++; | |
1237 | if (*start == '\0') | |
1238 | break; | |
1239 | end = start; | |
1240 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
1241 | end++; | |
1242 | last = *end == '\0'; | |
1243 | *end = '\0'; | |
1244 | if (os_strcmp(start, "OPEN") == 0) | |
1245 | val |= WPA_AUTH_ALG_OPEN; | |
1246 | else if (os_strcmp(start, "SHARED") == 0) | |
1247 | val |= WPA_AUTH_ALG_SHARED; | |
1248 | else if (os_strcmp(start, "LEAP") == 0) | |
1249 | val |= WPA_AUTH_ALG_LEAP; | |
1250 | else { | |
1251 | wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'", | |
1252 | line, start); | |
1253 | errors++; | |
1254 | } | |
1255 | ||
1256 | if (last) | |
1257 | break; | |
1258 | start = end + 1; | |
1259 | } | |
1260 | os_free(buf); | |
1261 | ||
1262 | if (val == 0) { | |
1263 | wpa_printf(MSG_ERROR, | |
1264 | "Line %d: no auth_alg values configured.", line); | |
1265 | errors++; | |
1266 | } | |
1267 | ||
5cd317d3 BKB |
1268 | if (!errors && ssid->auth_alg == val) |
1269 | return 1; | |
6fc6879b JM |
1270 | wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val); |
1271 | ssid->auth_alg = val; | |
1272 | return errors ? -1 : 0; | |
1273 | } | |
1274 | ||
1275 | ||
1276 | #ifndef NO_CONFIG_WRITE | |
1277 | static char * wpa_config_write_auth_alg(const struct parse_data *data, | |
1278 | struct wpa_ssid *ssid) | |
1279 | { | |
1280 | char *buf, *pos, *end; | |
1281 | int ret; | |
1282 | ||
1283 | pos = buf = os_zalloc(30); | |
1284 | if (buf == NULL) | |
1285 | return NULL; | |
1286 | end = buf + 30; | |
1287 | ||
1288 | if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) { | |
1289 | ret = os_snprintf(pos, end - pos, "%sOPEN", | |
1290 | pos == buf ? "" : " "); | |
d85e1fc8 | 1291 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
1292 | end[-1] = '\0'; |
1293 | return buf; | |
1294 | } | |
1295 | pos += ret; | |
1296 | } | |
1297 | ||
1298 | if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) { | |
1299 | ret = os_snprintf(pos, end - pos, "%sSHARED", | |
1300 | pos == buf ? "" : " "); | |
d85e1fc8 | 1301 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
1302 | end[-1] = '\0'; |
1303 | return buf; | |
1304 | } | |
1305 | pos += ret; | |
1306 | } | |
1307 | ||
1308 | if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) { | |
1309 | ret = os_snprintf(pos, end - pos, "%sLEAP", | |
1310 | pos == buf ? "" : " "); | |
d85e1fc8 | 1311 | if (os_snprintf_error(end - pos, ret)) { |
6fc6879b JM |
1312 | end[-1] = '\0'; |
1313 | return buf; | |
1314 | } | |
1315 | pos += ret; | |
1316 | } | |
1317 | ||
a1e46f32 JM |
1318 | if (pos == buf) { |
1319 | os_free(buf); | |
1320 | buf = NULL; | |
1321 | } | |
1322 | ||
6fc6879b JM |
1323 | return buf; |
1324 | } | |
1325 | #endif /* NO_CONFIG_WRITE */ | |
1326 | ||
1327 | ||
625f202a | 1328 | static int * wpa_config_parse_int_array(const char *value) |
d3a98225 JM |
1329 | { |
1330 | int *freqs; | |
1331 | size_t used, len; | |
1332 | const char *pos; | |
1333 | ||
1334 | used = 0; | |
1335 | len = 10; | |
f9884c09 | 1336 | freqs = os_calloc(len + 1, sizeof(int)); |
d3a98225 | 1337 | if (freqs == NULL) |
b766a9a2 | 1338 | return NULL; |
d3a98225 JM |
1339 | |
1340 | pos = value; | |
1341 | while (pos) { | |
1342 | while (*pos == ' ') | |
1343 | pos++; | |
1344 | if (used == len) { | |
1345 | int *n; | |
1346 | size_t i; | |
067ffa26 | 1347 | n = os_realloc_array(freqs, len * 2 + 1, sizeof(int)); |
d3a98225 JM |
1348 | if (n == NULL) { |
1349 | os_free(freqs); | |
b766a9a2 | 1350 | return NULL; |
d3a98225 JM |
1351 | } |
1352 | for (i = len; i <= len * 2; i++) | |
1353 | n[i] = 0; | |
1354 | freqs = n; | |
1355 | len *= 2; | |
1356 | } | |
1357 | ||
1358 | freqs[used] = atoi(pos); | |
1359 | if (freqs[used] == 0) | |
1360 | break; | |
1361 | used++; | |
1362 | pos = os_strchr(pos + 1, ' '); | |
1363 | } | |
1364 | ||
b766a9a2 JM |
1365 | return freqs; |
1366 | } | |
1367 | ||
1368 | ||
1369 | static int wpa_config_parse_scan_freq(const struct parse_data *data, | |
1370 | struct wpa_ssid *ssid, int line, | |
1371 | const char *value) | |
1372 | { | |
1373 | int *freqs; | |
1374 | ||
625f202a | 1375 | freqs = wpa_config_parse_int_array(value); |
b766a9a2 JM |
1376 | if (freqs == NULL) |
1377 | return -1; | |
6668efda JM |
1378 | if (freqs[0] == 0) { |
1379 | os_free(freqs); | |
1380 | freqs = NULL; | |
1381 | } | |
d3a98225 JM |
1382 | os_free(ssid->scan_freq); |
1383 | ssid->scan_freq = freqs; | |
1384 | ||
1385 | return 0; | |
1386 | } | |
1387 | ||
1388 | ||
b766a9a2 JM |
1389 | static int wpa_config_parse_freq_list(const struct parse_data *data, |
1390 | struct wpa_ssid *ssid, int line, | |
1391 | const char *value) | |
1392 | { | |
1393 | int *freqs; | |
1394 | ||
625f202a | 1395 | freqs = wpa_config_parse_int_array(value); |
b766a9a2 JM |
1396 | if (freqs == NULL) |
1397 | return -1; | |
6668efda JM |
1398 | if (freqs[0] == 0) { |
1399 | os_free(freqs); | |
1400 | freqs = NULL; | |
1401 | } | |
b766a9a2 JM |
1402 | os_free(ssid->freq_list); |
1403 | ssid->freq_list = freqs; | |
1404 | ||
1405 | return 0; | |
1406 | } | |
1407 | ||
1408 | ||
d3a98225 | 1409 | #ifndef NO_CONFIG_WRITE |
b766a9a2 JM |
1410 | static char * wpa_config_write_freqs(const struct parse_data *data, |
1411 | const int *freqs) | |
d3a98225 JM |
1412 | { |
1413 | char *buf, *pos, *end; | |
1414 | int i, ret; | |
1415 | size_t count; | |
1416 | ||
b766a9a2 | 1417 | if (freqs == NULL) |
d3a98225 JM |
1418 | return NULL; |
1419 | ||
1420 | count = 0; | |
b766a9a2 | 1421 | for (i = 0; freqs[i]; i++) |
d3a98225 JM |
1422 | count++; |
1423 | ||
1424 | pos = buf = os_zalloc(10 * count + 1); | |
1425 | if (buf == NULL) | |
1426 | return NULL; | |
1427 | end = buf + 10 * count + 1; | |
1428 | ||
b766a9a2 | 1429 | for (i = 0; freqs[i]; i++) { |
d3a98225 | 1430 | ret = os_snprintf(pos, end - pos, "%s%u", |
b766a9a2 | 1431 | i == 0 ? "" : " ", freqs[i]); |
d85e1fc8 | 1432 | if (os_snprintf_error(end - pos, ret)) { |
d3a98225 JM |
1433 | end[-1] = '\0'; |
1434 | return buf; | |
1435 | } | |
1436 | pos += ret; | |
1437 | } | |
1438 | ||
1439 | return buf; | |
1440 | } | |
b766a9a2 JM |
1441 | |
1442 | ||
1443 | static char * wpa_config_write_scan_freq(const struct parse_data *data, | |
1444 | struct wpa_ssid *ssid) | |
1445 | { | |
1446 | return wpa_config_write_freqs(data, ssid->scan_freq); | |
1447 | } | |
1448 | ||
1449 | ||
1450 | static char * wpa_config_write_freq_list(const struct parse_data *data, | |
1451 | struct wpa_ssid *ssid) | |
1452 | { | |
1453 | return wpa_config_write_freqs(data, ssid->freq_list); | |
1454 | } | |
d3a98225 JM |
1455 | #endif /* NO_CONFIG_WRITE */ |
1456 | ||
1457 | ||
6fc6879b JM |
1458 | #ifdef IEEE8021X_EAPOL |
1459 | static int wpa_config_parse_eap(const struct parse_data *data, | |
1460 | struct wpa_ssid *ssid, int line, | |
1461 | const char *value) | |
1462 | { | |
1463 | int last, errors = 0; | |
1464 | char *start, *end, *buf; | |
1465 | struct eap_method_type *methods = NULL, *tmp; | |
1466 | size_t num_methods = 0; | |
1467 | ||
1468 | buf = os_strdup(value); | |
1469 | if (buf == NULL) | |
1470 | return -1; | |
1471 | start = buf; | |
1472 | ||
1473 | while (*start != '\0') { | |
1474 | while (*start == ' ' || *start == '\t') | |
1475 | start++; | |
1476 | if (*start == '\0') | |
1477 | break; | |
1478 | end = start; | |
1479 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
1480 | end++; | |
1481 | last = *end == '\0'; | |
1482 | *end = '\0'; | |
1483 | tmp = methods; | |
067ffa26 JM |
1484 | methods = os_realloc_array(methods, num_methods + 1, |
1485 | sizeof(*methods)); | |
6fc6879b JM |
1486 | if (methods == NULL) { |
1487 | os_free(tmp); | |
1488 | os_free(buf); | |
1489 | return -1; | |
1490 | } | |
1491 | methods[num_methods].method = eap_peer_get_type( | |
1492 | start, &methods[num_methods].vendor); | |
1493 | if (methods[num_methods].vendor == EAP_VENDOR_IETF && | |
1494 | methods[num_methods].method == EAP_TYPE_NONE) { | |
1495 | wpa_printf(MSG_ERROR, "Line %d: unknown EAP method " | |
1496 | "'%s'", line, start); | |
1497 | wpa_printf(MSG_ERROR, "You may need to add support for" | |
1498 | " this EAP method during wpa_supplicant\n" | |
1499 | "build time configuration.\n" | |
1500 | "See README for more information."); | |
1501 | errors++; | |
1502 | } else if (methods[num_methods].vendor == EAP_VENDOR_IETF && | |
1503 | methods[num_methods].method == EAP_TYPE_LEAP) | |
1504 | ssid->leap++; | |
1505 | else | |
1506 | ssid->non_leap++; | |
1507 | num_methods++; | |
1508 | if (last) | |
1509 | break; | |
1510 | start = end + 1; | |
1511 | } | |
1512 | os_free(buf); | |
1513 | ||
1514 | tmp = methods; | |
067ffa26 | 1515 | methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods)); |
6fc6879b JM |
1516 | if (methods == NULL) { |
1517 | os_free(tmp); | |
1518 | return -1; | |
1519 | } | |
1520 | methods[num_methods].vendor = EAP_VENDOR_IETF; | |
1521 | methods[num_methods].method = EAP_TYPE_NONE; | |
1522 | num_methods++; | |
1523 | ||
5cd317d3 BKB |
1524 | if (!errors && ssid->eap.eap_methods) { |
1525 | struct eap_method_type *prev_m; | |
1526 | size_t i, j, prev_methods, match = 0; | |
1527 | ||
1528 | prev_m = ssid->eap.eap_methods; | |
1529 | for (i = 0; prev_m[i].vendor != EAP_VENDOR_IETF || | |
1530 | prev_m[i].method != EAP_TYPE_NONE; i++) { | |
1531 | /* Count the methods */ | |
1532 | } | |
1533 | prev_methods = i + 1; | |
1534 | ||
1535 | for (i = 0; prev_methods == num_methods && i < prev_methods; | |
1536 | i++) { | |
1537 | for (j = 0; j < num_methods; j++) { | |
1538 | if (prev_m[i].vendor == methods[j].vendor && | |
1539 | prev_m[i].method == methods[j].method) { | |
1540 | match++; | |
1541 | break; | |
1542 | } | |
1543 | } | |
1544 | } | |
1545 | if (match == num_methods) { | |
1546 | os_free(methods); | |
1547 | return 1; | |
1548 | } | |
1549 | } | |
6fc6879b JM |
1550 | wpa_hexdump(MSG_MSGDUMP, "eap methods", |
1551 | (u8 *) methods, num_methods * sizeof(*methods)); | |
bb8b1bb0 | 1552 | os_free(ssid->eap.eap_methods); |
6fc6879b JM |
1553 | ssid->eap.eap_methods = methods; |
1554 | return errors ? -1 : 0; | |
1555 | } | |
1556 | ||
1557 | ||
954f03aa | 1558 | #ifndef NO_CONFIG_WRITE |
6fc6879b JM |
1559 | static char * wpa_config_write_eap(const struct parse_data *data, |
1560 | struct wpa_ssid *ssid) | |
1561 | { | |
1562 | int i, ret; | |
1563 | char *buf, *pos, *end; | |
1564 | const struct eap_method_type *eap_methods = ssid->eap.eap_methods; | |
1565 | const char *name; | |
1566 | ||
1567 | if (eap_methods == NULL) | |
1568 | return NULL; | |
1569 | ||
1570 | pos = buf = os_zalloc(100); | |
1571 | if (buf == NULL) | |
1572 | return NULL; | |
1573 | end = buf + 100; | |
1574 | ||
1575 | for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF || | |
1576 | eap_methods[i].method != EAP_TYPE_NONE; i++) { | |
1577 | name = eap_get_name(eap_methods[i].vendor, | |
1578 | eap_methods[i].method); | |
1579 | if (name) { | |
1580 | ret = os_snprintf(pos, end - pos, "%s%s", | |
1581 | pos == buf ? "" : " ", name); | |
d85e1fc8 | 1582 | if (os_snprintf_error(end - pos, ret)) |
6fc6879b JM |
1583 | break; |
1584 | pos += ret; | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | end[-1] = '\0'; | |
1589 | ||
1590 | return buf; | |
1591 | } | |
954f03aa | 1592 | #endif /* NO_CONFIG_WRITE */ |
6fc6879b JM |
1593 | |
1594 | ||
1595 | static int wpa_config_parse_password(const struct parse_data *data, | |
1596 | struct wpa_ssid *ssid, int line, | |
1597 | const char *value) | |
1598 | { | |
1599 | u8 *hash; | |
1600 | ||
b56c0546 | 1601 | if (os_strcmp(value, "NULL") == 0) { |
5cd317d3 BKB |
1602 | if (!ssid->eap.password) |
1603 | return 1; /* Already unset */ | |
b56c0546 | 1604 | wpa_printf(MSG_DEBUG, "Unset configuration string 'password'"); |
19c48da0 | 1605 | bin_clear_free(ssid->eap.password, ssid->eap.password_len); |
b56c0546 JM |
1606 | ssid->eap.password = NULL; |
1607 | ssid->eap.password_len = 0; | |
1608 | return 0; | |
1609 | } | |
1610 | ||
0ebb23e3 JM |
1611 | #ifdef CONFIG_EXT_PASSWORD |
1612 | if (os_strncmp(value, "ext:", 4) == 0) { | |
1613 | char *name = os_strdup(value + 4); | |
c724a0a1 | 1614 | if (!name) |
0ebb23e3 | 1615 | return -1; |
19c48da0 | 1616 | bin_clear_free(ssid->eap.password, ssid->eap.password_len); |
0ebb23e3 JM |
1617 | ssid->eap.password = (u8 *) name; |
1618 | ssid->eap.password_len = os_strlen(name); | |
1619 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH; | |
1620 | ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD; | |
1621 | return 0; | |
1622 | } | |
1623 | #endif /* CONFIG_EXT_PASSWORD */ | |
1624 | ||
6fc6879b JM |
1625 | if (os_strncmp(value, "hash:", 5) != 0) { |
1626 | char *tmp; | |
1627 | size_t res_len; | |
1628 | ||
1629 | tmp = wpa_config_parse_string(value, &res_len); | |
c724a0a1 JM |
1630 | if (!tmp) { |
1631 | wpa_printf(MSG_ERROR, | |
1632 | "Line %d: failed to parse password.", line); | |
6fc6879b JM |
1633 | return -1; |
1634 | } | |
556f5a2a HS |
1635 | wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name, |
1636 | (u8 *) tmp, res_len); | |
6fc6879b | 1637 | |
19c48da0 | 1638 | bin_clear_free(ssid->eap.password, ssid->eap.password_len); |
6fc6879b JM |
1639 | ssid->eap.password = (u8 *) tmp; |
1640 | ssid->eap.password_len = res_len; | |
1641 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH; | |
0ebb23e3 | 1642 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD; |
6fc6879b JM |
1643 | |
1644 | return 0; | |
1645 | } | |
1646 | ||
1647 | ||
1648 | /* NtPasswordHash: hash:<32 hex digits> */ | |
1649 | if (os_strlen(value + 5) != 2 * 16) { | |
c724a0a1 JM |
1650 | wpa_printf(MSG_ERROR, |
1651 | "Line %d: Invalid password hash length (expected 32 hex digits)", | |
1652 | line); | |
6fc6879b JM |
1653 | return -1; |
1654 | } | |
1655 | ||
1656 | hash = os_malloc(16); | |
c724a0a1 | 1657 | if (!hash) |
6fc6879b JM |
1658 | return -1; |
1659 | ||
1660 | if (hexstr2bin(value + 5, hash, 16)) { | |
1661 | os_free(hash); | |
1662 | wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line); | |
1663 | return -1; | |
1664 | } | |
1665 | ||
1666 | wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16); | |
1667 | ||
5cd317d3 BKB |
1668 | if (ssid->eap.password && ssid->eap.password_len == 16 && |
1669 | os_memcmp(ssid->eap.password, hash, 16) == 0 && | |
1670 | (ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) { | |
1671 | bin_clear_free(hash, 16); | |
1672 | return 1; | |
1673 | } | |
19c48da0 | 1674 | bin_clear_free(ssid->eap.password, ssid->eap.password_len); |
6fc6879b JM |
1675 | ssid->eap.password = hash; |
1676 | ssid->eap.password_len = 16; | |
1677 | ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH; | |
0ebb23e3 | 1678 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD; |
6fc6879b JM |
1679 | |
1680 | return 0; | |
1681 | } | |
1682 | ||
1683 | ||
c724a0a1 JM |
1684 | static int wpa_config_parse_machine_password(const struct parse_data *data, |
1685 | struct wpa_ssid *ssid, int line, | |
1686 | const char *value) | |
1687 | { | |
1688 | u8 *hash; | |
1689 | ||
1690 | if (os_strcmp(value, "NULL") == 0) { | |
1691 | if (!ssid->eap.machine_password) | |
1692 | return 1; /* Already unset */ | |
1693 | wpa_printf(MSG_DEBUG, | |
1694 | "Unset configuration string 'machine_password'"); | |
1695 | bin_clear_free(ssid->eap.machine_password, | |
1696 | ssid->eap.machine_password_len); | |
1697 | ssid->eap.machine_password = NULL; | |
1698 | ssid->eap.machine_password_len = 0; | |
1699 | return 0; | |
1700 | } | |
1701 | ||
1702 | #ifdef CONFIG_EXT_PASSWORD | |
1703 | if (os_strncmp(value, "ext:", 4) == 0) { | |
1704 | char *name = os_strdup(value + 4); | |
1705 | ||
1706 | if (!name) | |
1707 | return -1; | |
1708 | bin_clear_free(ssid->eap.machine_password, | |
1709 | ssid->eap.machine_password_len); | |
1710 | ssid->eap.machine_password = (u8 *) name; | |
1711 | ssid->eap.machine_password_len = os_strlen(name); | |
1712 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH; | |
1713 | ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD; | |
1714 | return 0; | |
1715 | } | |
1716 | #endif /* CONFIG_EXT_PASSWORD */ | |
1717 | ||
1718 | if (os_strncmp(value, "hash:", 5) != 0) { | |
1719 | char *tmp; | |
1720 | size_t res_len; | |
1721 | ||
1722 | tmp = wpa_config_parse_string(value, &res_len); | |
1723 | if (!tmp) { | |
1724 | wpa_printf(MSG_ERROR, | |
1725 | "Line %d: failed to parse machine_password.", | |
1726 | line); | |
1727 | return -1; | |
1728 | } | |
1729 | wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name, | |
1730 | (u8 *) tmp, res_len); | |
1731 | ||
1732 | bin_clear_free(ssid->eap.machine_password, | |
1733 | ssid->eap.machine_password_len); | |
1734 | ssid->eap.machine_password = (u8 *) tmp; | |
1735 | ssid->eap.machine_password_len = res_len; | |
1736 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH; | |
1737 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD; | |
1738 | ||
1739 | return 0; | |
1740 | } | |
1741 | ||
1742 | ||
1743 | /* NtPasswordHash: hash:<32 hex digits> */ | |
1744 | if (os_strlen(value + 5) != 2 * 16) { | |
1745 | wpa_printf(MSG_ERROR, | |
1746 | "Line %d: Invalid machine_password hash length (expected 32 hex digits)", | |
1747 | line); | |
1748 | return -1; | |
1749 | } | |
1750 | ||
1751 | hash = os_malloc(16); | |
1752 | if (!hash) | |
1753 | return -1; | |
1754 | ||
1755 | if (hexstr2bin(value + 5, hash, 16)) { | |
1756 | os_free(hash); | |
1757 | wpa_printf(MSG_ERROR, "Line %d: Invalid machine_password hash", | |
1758 | line); | |
1759 | return -1; | |
1760 | } | |
1761 | ||
1762 | wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16); | |
1763 | ||
1764 | if (ssid->eap.machine_password && | |
1765 | ssid->eap.machine_password_len == 16 && | |
1766 | os_memcmp(ssid->eap.machine_password, hash, 16) == 0 && | |
1767 | (ssid->eap.flags & EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH)) { | |
1768 | bin_clear_free(hash, 16); | |
1769 | return 1; | |
1770 | } | |
1771 | bin_clear_free(ssid->eap.machine_password, | |
1772 | ssid->eap.machine_password_len); | |
1773 | ssid->eap.machine_password = hash; | |
1774 | ssid->eap.machine_password_len = 16; | |
1775 | ssid->eap.flags |= EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH; | |
1776 | ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD; | |
1777 | ||
1778 | return 0; | |
1779 | } | |
1780 | ||
1781 | ||
954f03aa | 1782 | #ifndef NO_CONFIG_WRITE |
c724a0a1 | 1783 | |
6fc6879b JM |
1784 | static char * wpa_config_write_password(const struct parse_data *data, |
1785 | struct wpa_ssid *ssid) | |
1786 | { | |
1787 | char *buf; | |
1788 | ||
c724a0a1 | 1789 | if (!ssid->eap.password) |
6fc6879b JM |
1790 | return NULL; |
1791 | ||
0ebb23e3 JM |
1792 | #ifdef CONFIG_EXT_PASSWORD |
1793 | if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) { | |
1794 | buf = os_zalloc(4 + ssid->eap.password_len + 1); | |
c724a0a1 | 1795 | if (!buf) |
0ebb23e3 JM |
1796 | return NULL; |
1797 | os_memcpy(buf, "ext:", 4); | |
1798 | os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len); | |
1799 | return buf; | |
1800 | } | |
1801 | #endif /* CONFIG_EXT_PASSWORD */ | |
1802 | ||
6fc6879b JM |
1803 | if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) { |
1804 | return wpa_config_write_string( | |
1805 | ssid->eap.password, ssid->eap.password_len); | |
1806 | } | |
1807 | ||
1808 | buf = os_malloc(5 + 32 + 1); | |
c724a0a1 | 1809 | if (!buf) |
6fc6879b JM |
1810 | return NULL; |
1811 | ||
1812 | os_memcpy(buf, "hash:", 5); | |
1813 | wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16); | |
1814 | ||
1815 | return buf; | |
1816 | } | |
c724a0a1 JM |
1817 | |
1818 | ||
1819 | static char * wpa_config_write_machine_password(const struct parse_data *data, | |
1820 | struct wpa_ssid *ssid) | |
1821 | { | |
1822 | char *buf; | |
1823 | ||
1824 | if (!ssid->eap.machine_password) | |
1825 | return NULL; | |
1826 | ||
1827 | #ifdef CONFIG_EXT_PASSWORD | |
1828 | if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD) { | |
1829 | buf = os_zalloc(4 + ssid->eap.machine_password_len + 1); | |
1830 | if (!buf) | |
1831 | return NULL; | |
1832 | os_memcpy(buf, "ext:", 4); | |
1833 | os_memcpy(buf + 4, ssid->eap.machine_password, | |
1834 | ssid->eap.machine_password_len); | |
1835 | return buf; | |
1836 | } | |
1837 | #endif /* CONFIG_EXT_PASSWORD */ | |
1838 | ||
1839 | if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH)) { | |
1840 | return wpa_config_write_string( | |
1841 | ssid->eap.machine_password, | |
1842 | ssid->eap.machine_password_len); | |
1843 | } | |
1844 | ||
1845 | buf = os_malloc(5 + 32 + 1); | |
1846 | if (!buf) | |
1847 | return NULL; | |
1848 | ||
1849 | os_memcpy(buf, "hash:", 5); | |
1850 | wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.machine_password, 16); | |
1851 | ||
1852 | return buf; | |
1853 | } | |
1854 | ||
954f03aa | 1855 | #endif /* NO_CONFIG_WRITE */ |
6fc6879b JM |
1856 | #endif /* IEEE8021X_EAPOL */ |
1857 | ||
1858 | ||
200c7693 JM |
1859 | #ifdef CONFIG_WEP |
1860 | ||
6fc6879b JM |
1861 | static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line, |
1862 | const char *value, int idx) | |
1863 | { | |
1864 | char *buf, title[20]; | |
1865 | int res; | |
1866 | ||
1867 | buf = wpa_config_parse_string(value, len); | |
1868 | if (buf == NULL) { | |
1869 | wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.", | |
1870 | line, idx, value); | |
1871 | return -1; | |
1872 | } | |
1873 | if (*len > MAX_WEP_KEY_LEN) { | |
1874 | wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.", | |
1875 | line, idx, value); | |
1876 | os_free(buf); | |
1877 | return -1; | |
1878 | } | |
fea7c3a0 JM |
1879 | if (*len && *len != 5 && *len != 13 && *len != 16) { |
1880 | wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - " | |
1881 | "this network block will be ignored", | |
1882 | line, (unsigned int) *len); | |
1883 | } | |
6fc6879b | 1884 | os_memcpy(key, buf, *len); |
19c48da0 | 1885 | str_clear_free(buf); |
6fc6879b | 1886 | res = os_snprintf(title, sizeof(title), "wep_key%d", idx); |
a80ba67a | 1887 | if (!os_snprintf_error(sizeof(title), res)) |
6fc6879b JM |
1888 | wpa_hexdump_key(MSG_MSGDUMP, title, key, *len); |
1889 | return 0; | |
1890 | } | |
1891 | ||
1892 | ||
1893 | static int wpa_config_parse_wep_key0(const struct parse_data *data, | |
1894 | struct wpa_ssid *ssid, int line, | |
1895 | const char *value) | |
1896 | { | |
1897 | return wpa_config_parse_wep_key(ssid->wep_key[0], | |
1898 | &ssid->wep_key_len[0], line, | |
1899 | value, 0); | |
1900 | } | |
1901 | ||
1902 | ||
1903 | static int wpa_config_parse_wep_key1(const struct parse_data *data, | |
1904 | struct wpa_ssid *ssid, int line, | |
1905 | const char *value) | |
1906 | { | |
1907 | return wpa_config_parse_wep_key(ssid->wep_key[1], | |
1908 | &ssid->wep_key_len[1], line, | |
1909 | value, 1); | |
1910 | } | |
1911 | ||
1912 | ||
1913 | static int wpa_config_parse_wep_key2(const struct parse_data *data, | |
1914 | struct wpa_ssid *ssid, int line, | |
1915 | const char *value) | |
1916 | { | |
1917 | return wpa_config_parse_wep_key(ssid->wep_key[2], | |
1918 | &ssid->wep_key_len[2], line, | |
1919 | value, 2); | |
1920 | } | |
1921 | ||
1922 | ||
1923 | static int wpa_config_parse_wep_key3(const struct parse_data *data, | |
1924 | struct wpa_ssid *ssid, int line, | |
1925 | const char *value) | |
1926 | { | |
1927 | return wpa_config_parse_wep_key(ssid->wep_key[3], | |
1928 | &ssid->wep_key_len[3], line, | |
1929 | value, 3); | |
1930 | } | |
1931 | ||
1932 | ||
1933 | #ifndef NO_CONFIG_WRITE | |
1934 | static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx) | |
1935 | { | |
1936 | if (ssid->wep_key_len[idx] == 0) | |
1937 | return NULL; | |
1938 | return wpa_config_write_string(ssid->wep_key[idx], | |
1939 | ssid->wep_key_len[idx]); | |
1940 | } | |
1941 | ||
1942 | ||
1943 | static char * wpa_config_write_wep_key0(const struct parse_data *data, | |
1944 | struct wpa_ssid *ssid) | |
1945 | { | |
1946 | return wpa_config_write_wep_key(ssid, 0); | |
1947 | } | |
1948 | ||
1949 | ||
1950 | static char * wpa_config_write_wep_key1(const struct parse_data *data, | |
1951 | struct wpa_ssid *ssid) | |
1952 | { | |
1953 | return wpa_config_write_wep_key(ssid, 1); | |
1954 | } | |
1955 | ||
1956 | ||
1957 | static char * wpa_config_write_wep_key2(const struct parse_data *data, | |
1958 | struct wpa_ssid *ssid) | |
1959 | { | |
1960 | return wpa_config_write_wep_key(ssid, 2); | |
1961 | } | |
1962 | ||
1963 | ||
1964 | static char * wpa_config_write_wep_key3(const struct parse_data *data, | |
1965 | struct wpa_ssid *ssid) | |
1966 | { | |
1967 | return wpa_config_write_wep_key(ssid, 3); | |
1968 | } | |
1969 | #endif /* NO_CONFIG_WRITE */ | |
1970 | ||
200c7693 JM |
1971 | #endif /* CONFIG_WEP */ |
1972 | ||
6fc6879b | 1973 | |
fbdcfd57 JM |
1974 | #ifdef CONFIG_P2P |
1975 | ||
9ec87666 JM |
1976 | static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data, |
1977 | struct wpa_ssid *ssid, int line, | |
1978 | const char *value) | |
1979 | { | |
1980 | if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 || | |
1981 | os_strcmp(value, "any") == 0) { | |
1982 | os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN); | |
1983 | wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any"); | |
1984 | return 0; | |
1985 | } | |
1986 | if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) { | |
1987 | wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.", | |
1988 | line, value); | |
1989 | return -1; | |
1990 | } | |
1991 | ssid->bssid_set = 1; | |
1992 | wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR, | |
1993 | MAC2STR(ssid->go_p2p_dev_addr)); | |
1994 | return 0; | |
1995 | } | |
1996 | ||
1997 | ||
1998 | #ifndef NO_CONFIG_WRITE | |
1999 | static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data, | |
2000 | struct wpa_ssid *ssid) | |
2001 | { | |
2002 | char *value; | |
2003 | int res; | |
2004 | ||
2005 | if (is_zero_ether_addr(ssid->go_p2p_dev_addr)) | |
2006 | return NULL; | |
2007 | ||
2008 | value = os_malloc(20); | |
2009 | if (value == NULL) | |
2010 | return NULL; | |
2011 | res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr)); | |
d85e1fc8 | 2012 | if (os_snprintf_error(20, res)) { |
9ec87666 JM |
2013 | os_free(value); |
2014 | return NULL; | |
2015 | } | |
2016 | value[20 - 1] = '\0'; | |
2017 | return value; | |
2018 | } | |
2019 | #endif /* NO_CONFIG_WRITE */ | |
2020 | ||
2021 | ||
fbdcfd57 JM |
2022 | static int wpa_config_parse_p2p_client_list(const struct parse_data *data, |
2023 | struct wpa_ssid *ssid, int line, | |
2024 | const char *value) | |
2025 | { | |
b3d6a0a8 ST |
2026 | return wpa_config_parse_addr_list(data, line, value, |
2027 | &ssid->p2p_client_list, | |
2028 | &ssid->num_p2p_clients, | |
79cd993a | 2029 | "p2p_client_list", 0, 0); |
fbdcfd57 JM |
2030 | } |
2031 | ||
2032 | ||
2033 | #ifndef NO_CONFIG_WRITE | |
2034 | static char * wpa_config_write_p2p_client_list(const struct parse_data *data, | |
2035 | struct wpa_ssid *ssid) | |
2036 | { | |
b3d6a0a8 ST |
2037 | return wpa_config_write_addr_list(data, ssid->p2p_client_list, |
2038 | ssid->num_p2p_clients, | |
2039 | "p2p_client_list"); | |
fbdcfd57 JM |
2040 | } |
2041 | #endif /* NO_CONFIG_WRITE */ | |
2042 | ||
01a57fe4 JM |
2043 | |
2044 | static int wpa_config_parse_psk_list(const struct parse_data *data, | |
2045 | struct wpa_ssid *ssid, int line, | |
2046 | const char *value) | |
2047 | { | |
2048 | struct psk_list_entry *p; | |
2049 | const char *pos; | |
2050 | ||
2051 | p = os_zalloc(sizeof(*p)); | |
2052 | if (p == NULL) | |
2053 | return -1; | |
2054 | ||
2055 | pos = value; | |
2056 | if (os_strncmp(pos, "P2P-", 4) == 0) { | |
2057 | p->p2p = 1; | |
2058 | pos += 4; | |
2059 | } | |
2060 | ||
2061 | if (hwaddr_aton(pos, p->addr)) { | |
2062 | wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'", | |
2063 | line, pos); | |
2064 | os_free(p); | |
2065 | return -1; | |
2066 | } | |
2067 | pos += 17; | |
2068 | if (*pos != '-') { | |
2069 | wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'", | |
2070 | line, pos); | |
2071 | os_free(p); | |
2072 | return -1; | |
2073 | } | |
2074 | pos++; | |
2075 | ||
2076 | if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') { | |
2077 | wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'", | |
2078 | line, pos); | |
2079 | os_free(p); | |
2080 | return -1; | |
2081 | } | |
2082 | ||
2083 | dl_list_add(&ssid->psk_list, &p->list); | |
2084 | ||
2085 | return 0; | |
2086 | } | |
2087 | ||
2088 | ||
2089 | #ifndef NO_CONFIG_WRITE | |
2090 | static char * wpa_config_write_psk_list(const struct parse_data *data, | |
2091 | struct wpa_ssid *ssid) | |
2092 | { | |
2093 | return NULL; | |
2094 | } | |
2095 | #endif /* NO_CONFIG_WRITE */ | |
2096 | ||
fbdcfd57 JM |
2097 | #endif /* CONFIG_P2P */ |
2098 | ||
5cfb672d JM |
2099 | |
2100 | #ifdef CONFIG_MESH | |
2101 | ||
2b2bb5a8 MH |
2102 | static int wpa_config_parse_mesh_basic_rates(const struct parse_data *data, |
2103 | struct wpa_ssid *ssid, int line, | |
2104 | const char *value) | |
2105 | { | |
2106 | int *rates = wpa_config_parse_int_array(value); | |
2107 | ||
2108 | if (rates == NULL) { | |
2109 | wpa_printf(MSG_ERROR, "Line %d: Invalid mesh_basic_rates '%s'", | |
2110 | line, value); | |
2111 | return -1; | |
2112 | } | |
2113 | if (rates[0] == 0) { | |
2114 | os_free(rates); | |
2115 | rates = NULL; | |
2116 | } | |
2117 | ||
2118 | os_free(ssid->mesh_basic_rates); | |
2119 | ssid->mesh_basic_rates = rates; | |
2120 | ||
2121 | return 0; | |
2122 | } | |
2123 | ||
2124 | ||
5cfb672d | 2125 | #ifndef NO_CONFIG_WRITE |
2b2bb5a8 | 2126 | |
2b2bb5a8 MH |
2127 | static char * wpa_config_write_mesh_basic_rates(const struct parse_data *data, |
2128 | struct wpa_ssid *ssid) | |
2129 | { | |
2130 | return wpa_config_write_freqs(data, ssid->mesh_basic_rates); | |
2131 | } | |
2132 | ||
5cfb672d JM |
2133 | #endif /* NO_CONFIG_WRITE */ |
2134 | ||
2135 | #endif /* CONFIG_MESH */ | |
2136 | ||
2137 | ||
ad51731a SD |
2138 | #ifdef CONFIG_MACSEC |
2139 | ||
2140 | static int wpa_config_parse_mka_cak(const struct parse_data *data, | |
2141 | struct wpa_ssid *ssid, int line, | |
2142 | const char *value) | |
2143 | { | |
871439b5 JM |
2144 | size_t len; |
2145 | ||
2146 | len = os_strlen(value); | |
2147 | if (len > 2 * MACSEC_CAK_MAX_LEN || | |
2148 | (len != 2 * 16 && len != 2 * 32) || | |
2149 | hexstr2bin(value, ssid->mka_cak, len / 2)) { | |
ad51731a SD |
2150 | wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CAK '%s'.", |
2151 | line, value); | |
2152 | return -1; | |
2153 | } | |
871439b5 | 2154 | ssid->mka_cak_len = len / 2; |
ad51731a SD |
2155 | ssid->mka_psk_set |= MKA_PSK_SET_CAK; |
2156 | ||
871439b5 JM |
2157 | wpa_hexdump_key(MSG_MSGDUMP, "MKA-CAK", ssid->mka_cak, |
2158 | ssid->mka_cak_len); | |
ad51731a SD |
2159 | return 0; |
2160 | } | |
2161 | ||
2162 | ||
2163 | static int wpa_config_parse_mka_ckn(const struct parse_data *data, | |
2164 | struct wpa_ssid *ssid, int line, | |
2165 | const char *value) | |
2166 | { | |
b678ed1e | 2167 | size_t len; |
2168 | ||
2169 | len = os_strlen(value); | |
2170 | if (len > 2 * MACSEC_CKN_MAX_LEN || /* too long */ | |
2171 | len < 2 || /* too short */ | |
2172 | len % 2 != 0 /* not an integral number of bytes */) { | |
2173 | wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.", | |
2174 | line, value); | |
2175 | return -1; | |
2176 | } | |
2177 | ssid->mka_ckn_len = len / 2; | |
2178 | if (hexstr2bin(value, ssid->mka_ckn, ssid->mka_ckn_len)) { | |
ad51731a SD |
2179 | wpa_printf(MSG_ERROR, "Line %d: Invalid MKA-CKN '%s'.", |
2180 | line, value); | |
2181 | return -1; | |
2182 | } | |
2183 | ||
2184 | ssid->mka_psk_set |= MKA_PSK_SET_CKN; | |
2185 | ||
b678ed1e | 2186 | wpa_hexdump_key(MSG_MSGDUMP, "MKA-CKN", ssid->mka_ckn, |
2187 | ssid->mka_ckn_len); | |
ad51731a SD |
2188 | return 0; |
2189 | } | |
2190 | ||
2191 | ||
2192 | #ifndef NO_CONFIG_WRITE | |
2193 | ||
2194 | static char * wpa_config_write_mka_cak(const struct parse_data *data, | |
2195 | struct wpa_ssid *ssid) | |
2196 | { | |
2197 | if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK)) | |
2198 | return NULL; | |
2199 | ||
871439b5 | 2200 | return wpa_config_write_string_hex(ssid->mka_cak, ssid->mka_cak_len); |
ad51731a SD |
2201 | } |
2202 | ||
2203 | ||
2204 | static char * wpa_config_write_mka_ckn(const struct parse_data *data, | |
2205 | struct wpa_ssid *ssid) | |
2206 | { | |
2207 | if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN)) | |
2208 | return NULL; | |
b678ed1e | 2209 | return wpa_config_write_string_hex(ssid->mka_ckn, ssid->mka_ckn_len); |
ad51731a SD |
2210 | } |
2211 | ||
2212 | #endif /* NO_CONFIG_WRITE */ | |
2213 | ||
2214 | #endif /* CONFIG_MACSEC */ | |
2215 | ||
2216 | ||
ce6829c2 MV |
2217 | #ifdef CONFIG_OCV |
2218 | ||
2219 | static int wpa_config_parse_ocv(const struct parse_data *data, | |
2220 | struct wpa_ssid *ssid, int line, | |
2221 | const char *value) | |
2222 | { | |
2223 | char *end; | |
2224 | ||
2225 | ssid->ocv = strtol(value, &end, 0); | |
2226 | if (*end || ssid->ocv < 0 || ssid->ocv > 1) { | |
2227 | wpa_printf(MSG_ERROR, "Line %d: Invalid ocv value '%s'.", | |
2228 | line, value); | |
2229 | return -1; | |
2230 | } | |
2231 | if (ssid->ocv && ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION) | |
2232 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL; | |
2233 | return 0; | |
2234 | } | |
2235 | ||
2236 | ||
2237 | #ifndef NO_CONFIG_WRITE | |
2238 | static char * wpa_config_write_ocv(const struct parse_data *data, | |
2239 | struct wpa_ssid *ssid) | |
2240 | { | |
2241 | char *value = os_malloc(20); | |
2242 | ||
2243 | if (!value) | |
2244 | return NULL; | |
2245 | os_snprintf(value, 20, "%d", ssid->ocv); | |
2246 | value[20 - 1] = '\0'; | |
2247 | return value; | |
2248 | } | |
2249 | #endif /* NO_CONFIG_WRITE */ | |
2250 | ||
2251 | #endif /* CONFIG_OCV */ | |
2252 | ||
2253 | ||
a0bf1b68 JM |
2254 | static int wpa_config_parse_peerkey(const struct parse_data *data, |
2255 | struct wpa_ssid *ssid, int line, | |
2256 | const char *value) | |
2257 | { | |
2258 | wpa_printf(MSG_INFO, "NOTE: Obsolete peerkey parameter ignored"); | |
2259 | return 0; | |
2260 | } | |
2261 | ||
2262 | ||
2263 | #ifndef NO_CONFIG_WRITE | |
2264 | static char * wpa_config_write_peerkey(const struct parse_data *data, | |
2265 | struct wpa_ssid *ssid) | |
2266 | { | |
2267 | return NULL; | |
2268 | } | |
2269 | #endif /* NO_CONFIG_WRITE */ | |
2270 | ||
2271 | ||
6fc6879b JM |
2272 | /* Helper macros for network block parser */ |
2273 | ||
2274 | #ifdef OFFSET | |
2275 | #undef OFFSET | |
2276 | #endif /* OFFSET */ | |
2277 | /* OFFSET: Get offset of a variable within the wpa_ssid structure */ | |
2278 | #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v) | |
2279 | ||
2280 | /* STR: Define a string variable for an ASCII string; f = field name */ | |
2281 | #ifdef NO_CONFIG_WRITE | |
2282 | #define _STR(f) #f, wpa_config_parse_str, OFFSET(f) | |
b99c4cad | 2283 | #define _STRe(f, m) #f, wpa_config_parse_str, OFFSET(eap.m) |
6fc6879b JM |
2284 | #else /* NO_CONFIG_WRITE */ |
2285 | #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f) | |
b99c4cad JM |
2286 | #define _STRe(f, m) #f, wpa_config_parse_str, wpa_config_write_str, \ |
2287 | OFFSET(eap.m) | |
6fc6879b JM |
2288 | #endif /* NO_CONFIG_WRITE */ |
2289 | #define STR(f) _STR(f), NULL, NULL, NULL, 0 | |
b99c4cad | 2290 | #define STRe(f, m) _STRe(f, m), NULL, NULL, NULL, 0 |
6fc6879b | 2291 | #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1 |
b99c4cad | 2292 | #define STR_KEYe(f, m) _STRe(f, m), NULL, NULL, NULL, 1 |
6fc6879b JM |
2293 | |
2294 | /* STR_LEN: Define a string variable with a separate variable for storing the | |
2295 | * data length. Unlike STR(), this can be used to store arbitrary binary data | |
2296 | * (i.e., even nul termination character). */ | |
2297 | #define _STR_LEN(f) _STR(f), OFFSET(f ## _len) | |
b99c4cad | 2298 | #define _STR_LENe(f, m) _STRe(f, m), OFFSET(eap.m ## _len) |
6fc6879b | 2299 | #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0 |
b99c4cad | 2300 | #define STR_LENe(f, m) _STR_LENe(f, m), NULL, NULL, 0 |
6fc6879b JM |
2301 | #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1 |
2302 | ||
2303 | /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length | |
2304 | * explicitly specified. */ | |
2305 | #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max) | |
2306 | #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0 | |
2307 | #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1 | |
2308 | ||
2309 | #ifdef NO_CONFIG_WRITE | |
2310 | #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0 | |
b99c4cad | 2311 | #define _INTe(f, m) #f, wpa_config_parse_int, OFFSET(eap.m), (void *) 0 |
6fc6879b JM |
2312 | #else /* NO_CONFIG_WRITE */ |
2313 | #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \ | |
2314 | OFFSET(f), (void *) 0 | |
b99c4cad JM |
2315 | #define _INTe(f, m) #f, wpa_config_parse_int, wpa_config_write_int, \ |
2316 | OFFSET(eap.m), (void *) 0 | |
6fc6879b JM |
2317 | #endif /* NO_CONFIG_WRITE */ |
2318 | ||
2319 | /* INT: Define an integer variable */ | |
2320 | #define INT(f) _INT(f), NULL, NULL, 0 | |
b99c4cad | 2321 | #define INTe(f, m) _INTe(f, m), NULL, NULL, 0 |
6fc6879b JM |
2322 | |
2323 | /* INT_RANGE: Define an integer variable with allowed value range */ | |
2324 | #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0 | |
2325 | ||
2326 | /* FUNC: Define a configuration variable that uses a custom function for | |
2327 | * parsing and writing the value. */ | |
2328 | #ifdef NO_CONFIG_WRITE | |
2329 | #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL | |
2330 | #else /* NO_CONFIG_WRITE */ | |
2331 | #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \ | |
2332 | NULL, NULL, NULL, NULL | |
2333 | #endif /* NO_CONFIG_WRITE */ | |
2334 | #define FUNC(f) _FUNC(f), 0 | |
2335 | #define FUNC_KEY(f) _FUNC(f), 1 | |
2336 | ||
2337 | /* | |
2338 | * Table of network configuration variables. This table is used to parse each | |
2339 | * network configuration variable, e.g., each line in wpa_supplicant.conf file | |
2340 | * that is inside a network block. | |
2341 | * | |
2342 | * This table is generated using the helper macros defined above and with | |
2343 | * generous help from the C pre-processor. The field name is stored as a string | |
2344 | * into .name and for STR and INT types, the offset of the target buffer within | |
2345 | * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar | |
2346 | * offset to the field containing the length of the configuration variable. | |
2347 | * .param3 and .param4 can be used to mark the allowed range (length for STR | |
2348 | * and value for INT). | |
2349 | * | |
2350 | * For each configuration line in wpa_supplicant.conf, the parser goes through | |
2351 | * this table and select the entry that matches with the field name. The parser | |
2352 | * function (.parser) is then called to parse the actual value of the field. | |
2353 | * | |
2354 | * This kind of mechanism makes it easy to add new configuration parameters, | |
2355 | * since only one line needs to be added into this table and into the | |
2356 | * struct wpa_ssid definition if the new variable is either a string or | |
2357 | * integer. More complex types will need to use their own parser and writer | |
2358 | * functions. | |
2359 | */ | |
2360 | static const struct parse_data ssid_fields[] = { | |
eaa8eefe | 2361 | { STR_RANGE(ssid, 0, SSID_MAX_LEN) }, |
6fc6879b JM |
2362 | { INT_RANGE(scan_ssid, 0, 1) }, |
2363 | { FUNC(bssid) }, | |
43a356b2 | 2364 | { FUNC(bssid_hint) }, |
b83e4554 ST |
2365 | { FUNC(bssid_blacklist) }, |
2366 | { FUNC(bssid_whitelist) }, | |
6fc6879b | 2367 | { FUNC_KEY(psk) }, |
a52410c2 | 2368 | { INT(mem_only_psk) }, |
a34ca59e | 2369 | { STR_KEY(sae_password) }, |
9be19d0b | 2370 | { STR(sae_password_id) }, |
6fc6879b JM |
2371 | { FUNC(proto) }, |
2372 | { FUNC(key_mgmt) }, | |
1f6c0ab8 | 2373 | { INT(bg_scan_period) }, |
6fc6879b JM |
2374 | { FUNC(pairwise) }, |
2375 | { FUNC(group) }, | |
61a56c14 | 2376 | { FUNC(group_mgmt) }, |
6fc6879b | 2377 | { FUNC(auth_alg) }, |
d3a98225 | 2378 | { FUNC(scan_freq) }, |
b766a9a2 | 2379 | { FUNC(freq_list) }, |
b07ff9cb | 2380 | { INT_RANGE(ht, 0, 1) }, |
2124a615 JB |
2381 | { INT_RANGE(vht, 0, 1) }, |
2382 | { INT_RANGE(ht40, -1, 1) }, | |
464dcfd0 JC |
2383 | { INT_RANGE(max_oper_chwidth, CHANWIDTH_USE_HT, |
2384 | CHANWIDTH_80P80MHZ) }, | |
2124a615 JB |
2385 | { INT(vht_center_freq1) }, |
2386 | { INT(vht_center_freq2) }, | |
6fc6879b JM |
2387 | #ifdef IEEE8021X_EAPOL |
2388 | { FUNC(eap) }, | |
b99c4cad JM |
2389 | { STR_LENe(identity, identity) }, |
2390 | { STR_LENe(anonymous_identity, anonymous_identity) }, | |
2391 | { STR_LENe(imsi_identity, imsi_identity) }, | |
2392 | { STR_LENe(machine_identity, machine_identity) }, | |
556f5a2a | 2393 | { FUNC_KEY(password) }, |
c724a0a1 | 2394 | { FUNC_KEY(machine_password) }, |
b99c4cad JM |
2395 | { STRe(ca_cert, cert.ca_cert) }, |
2396 | { STRe(ca_path, cert.ca_path) }, | |
2397 | { STRe(client_cert, cert.client_cert) }, | |
2398 | { STRe(private_key, cert.private_key) }, | |
2399 | { STR_KEYe(private_key_passwd, cert.private_key_passwd) }, | |
2400 | { STRe(dh_file, cert.dh_file) }, | |
2401 | { STRe(subject_match, cert.subject_match) }, | |
2402 | { STRe(check_cert_subject, cert.check_cert_subject) }, | |
2403 | { STRe(altsubject_match, cert.altsubject_match) }, | |
2404 | { STRe(domain_suffix_match, cert.domain_suffix_match) }, | |
2405 | { STRe(domain_match, cert.domain_match) }, | |
2406 | { STRe(ca_cert2, phase2_cert.ca_cert) }, | |
2407 | { STRe(ca_path2, phase2_cert.ca_path) }, | |
2408 | { STRe(client_cert2, phase2_cert.client_cert) }, | |
2409 | { STRe(private_key2, phase2_cert.private_key) }, | |
2410 | { STR_KEYe(private_key2_passwd, phase2_cert.private_key_passwd) }, | |
2411 | { STRe(dh_file2, phase2_cert.dh_file) }, | |
2412 | { STRe(subject_match2, phase2_cert.subject_match) }, | |
2413 | { STRe(check_cert_subject2, phase2_cert.check_cert_subject) }, | |
2414 | { STRe(altsubject_match2, phase2_cert.altsubject_match) }, | |
2415 | { STRe(domain_suffix_match2, phase2_cert.domain_suffix_match) }, | |
2416 | { STRe(domain_match2, phase2_cert.domain_match) }, | |
2417 | { STRe(phase1, phase1) }, | |
2418 | { STRe(phase2, phase2) }, | |
68161824 | 2419 | { STRe(machine_phase2, machine_phase2) }, |
b99c4cad JM |
2420 | { STRe(pcsc, pcsc) }, |
2421 | { STR_KEYe(pin, cert.pin) }, | |
2422 | { STRe(engine_id, cert.engine_id) }, | |
2423 | { STRe(key_id, cert.key_id) }, | |
2424 | { STRe(cert_id, cert.cert_id) }, | |
2425 | { STRe(ca_cert_id, cert.ca_cert_id) }, | |
2426 | { STR_KEYe(pin2, phase2_cert.pin) }, | |
2427 | { STRe(engine_id2, phase2_cert.engine_id) }, | |
2428 | { STRe(key_id2, phase2_cert.key_id) }, | |
2429 | { STRe(cert_id2, phase2_cert.cert_id) }, | |
2430 | { STRe(ca_cert_id2, phase2_cert.ca_cert_id) }, | |
2431 | { INTe(engine, cert.engine) }, | |
2432 | { INTe(engine2, phase2_cert.engine) }, | |
68161824 JM |
2433 | { STRe(machine_ca_cert, machine_cert.ca_cert) }, |
2434 | { STRe(machine_ca_path, machine_cert.ca_path) }, | |
2435 | { STRe(machine_client_cert, machine_cert.client_cert) }, | |
2436 | { STRe(machine_private_key, machine_cert.private_key) }, | |
2437 | { STR_KEYe(machine_private_key_passwd, | |
2438 | machine_cert.private_key_passwd) }, | |
2439 | { STRe(machine_dh_file, machine_cert.dh_file) }, | |
2440 | { STRe(machine_subject_match, machine_cert.subject_match) }, | |
2441 | { STRe(machine_check_cert_subject, machine_cert.check_cert_subject) }, | |
2442 | { STRe(machine_altsubject_match, machine_cert.altsubject_match) }, | |
2443 | { STRe(machine_domain_suffix_match, | |
2444 | machine_cert.domain_suffix_match) }, | |
2445 | { STRe(machine_domain_match, machine_cert.domain_match) }, | |
2446 | { STR_KEYe(machine_pin, machine_cert.pin) }, | |
2447 | { STRe(machine_engine_id, machine_cert.engine_id) }, | |
2448 | { STRe(machine_key_id, machine_cert.key_id) }, | |
2449 | { STRe(machine_cert_id, machine_cert.cert_id) }, | |
2450 | { STRe(machine_ca_cert_id, machine_cert.ca_cert_id) }, | |
2451 | { INTe(machine_engine, machine_cert.engine) }, | |
2452 | { INTe(machine_ocsp, machine_cert.ocsp) }, | |
6fc6879b | 2453 | { INT(eapol_flags) }, |
b99c4cad JM |
2454 | { INTe(sim_num, sim_num) }, |
2455 | { STRe(openssl_ciphers, openssl_ciphers) }, | |
2456 | { INTe(erp, erp) }, | |
6fc6879b | 2457 | #endif /* IEEE8021X_EAPOL */ |
200c7693 | 2458 | #ifdef CONFIG_WEP |
6fc6879b JM |
2459 | { FUNC_KEY(wep_key0) }, |
2460 | { FUNC_KEY(wep_key1) }, | |
2461 | { FUNC_KEY(wep_key2) }, | |
2462 | { FUNC_KEY(wep_key3) }, | |
2463 | { INT(wep_tx_keyidx) }, | |
200c7693 | 2464 | #endif /* CONFIG_WEP */ |
6fc6879b JM |
2465 | { INT(priority) }, |
2466 | #ifdef IEEE8021X_EAPOL | |
2467 | { INT(eap_workaround) }, | |
b99c4cad JM |
2468 | { STRe(pac_file, pac_file) }, |
2469 | { INTe(fragment_size, fragment_size) }, | |
043de65f JM |
2470 | { INTe(ocsp, cert.ocsp) }, |
2471 | { INTe(ocsp2, phase2_cert.ocsp) }, | |
6fc6879b | 2472 | #endif /* IEEE8021X_EAPOL */ |
476e6bb6 TP |
2473 | #ifdef CONFIG_MESH |
2474 | { INT_RANGE(mode, 0, 5) }, | |
07cb45cc | 2475 | { INT_RANGE(no_auto_peer, 0, 1) }, |
31a856a1 | 2476 | { INT_RANGE(mesh_rssi_threshold, -255, 1) }, |
476e6bb6 | 2477 | #else /* CONFIG_MESH */ |
2c5d725c | 2478 | { INT_RANGE(mode, 0, 4) }, |
476e6bb6 | 2479 | #endif /* CONFIG_MESH */ |
6fc6879b | 2480 | { INT_RANGE(proactive_key_caching, 0, 1) }, |
4dac0245 | 2481 | { INT_RANGE(disabled, 0, 2) }, |
6fc6879b | 2482 | { STR(id_str) }, |
6fc6879b | 2483 | { INT_RANGE(ieee80211w, 0, 2) }, |
ce6829c2 MV |
2484 | #ifdef CONFIG_OCV |
2485 | { FUNC(ocv) }, | |
2486 | #endif /* CONFIG_OCV */ | |
a0bf1b68 | 2487 | { FUNC(peerkey) /* obsolete - removed */ }, |
6fc6879b | 2488 | { INT_RANGE(mixed_cell, 0, 1) }, |
dc6c3be4 | 2489 | { INT_RANGE(frequency, 0, 70200) }, |
4d9e6fba | 2490 | { INT_RANGE(fixed_freq, 0, 1) }, |
e8ff22f4 AAL |
2491 | { INT_RANGE(enable_edmg, 0, 1) }, |
2492 | { INT_RANGE(edmg_channel, 9, 13) }, | |
d9909717 TB |
2493 | #ifdef CONFIG_ACS |
2494 | { INT_RANGE(acs, 0, 1) }, | |
2495 | #endif /* CONFIG_ACS */ | |
5cfb672d | 2496 | #ifdef CONFIG_MESH |
2b2bb5a8 | 2497 | { FUNC(mesh_basic_rates) }, |
e6096799 MH |
2498 | { INT(dot11MeshMaxRetries) }, |
2499 | { INT(dot11MeshRetryTimeout) }, | |
2500 | { INT(dot11MeshConfirmTimeout) }, | |
2501 | { INT(dot11MeshHoldingTimeout) }, | |
5cfb672d | 2502 | #endif /* CONFIG_MESH */ |
60b94c98 | 2503 | { INT(wpa_ptk_rekey) }, |
1f90a49d | 2504 | { INT_RANGE(wpa_deny_ptk0_rekey, 0, 2) }, |
6c33ca9f | 2505 | { INT(group_rekey) }, |
60b94c98 | 2506 | { STR(bgscan) }, |
e62f4ed0 | 2507 | { INT_RANGE(ignore_broadcast_ssid, 0, 2) }, |
fbdcfd57 | 2508 | #ifdef CONFIG_P2P |
9ec87666 | 2509 | { FUNC(go_p2p_dev_addr) }, |
fbdcfd57 | 2510 | { FUNC(p2p_client_list) }, |
01a57fe4 | 2511 | { FUNC(psk_list) }, |
fbdcfd57 | 2512 | #endif /* CONFIG_P2P */ |
80e8a5ee BG |
2513 | #ifdef CONFIG_HT_OVERRIDES |
2514 | { INT_RANGE(disable_ht, 0, 1) }, | |
2515 | { INT_RANGE(disable_ht40, -1, 1) }, | |
a90497f8 | 2516 | { INT_RANGE(disable_sgi, 0, 1) }, |
39a5800f | 2517 | { INT_RANGE(disable_ldpc, 0, 1) }, |
d41cc8cc | 2518 | { INT_RANGE(ht40_intolerant, 0, 1) }, |
cdeea70f SM |
2519 | { INT_RANGE(tx_stbc, -1, 1) }, |
2520 | { INT_RANGE(rx_stbc, -1, 3) }, | |
80e8a5ee BG |
2521 | { INT_RANGE(disable_max_amsdu, -1, 1) }, |
2522 | { INT_RANGE(ampdu_factor, -1, 3) }, | |
2523 | { INT_RANGE(ampdu_density, -1, 7) }, | |
2524 | { STR(ht_mcs) }, | |
2525 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
2526 | #ifdef CONFIG_VHT_OVERRIDES |
2527 | { INT_RANGE(disable_vht, 0, 1) }, | |
2528 | { INT(vht_capa) }, | |
2529 | { INT(vht_capa_mask) }, | |
2530 | { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) }, | |
2531 | { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) }, | |
2532 | { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) }, | |
2533 | { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) }, | |
2534 | { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) }, | |
2535 | { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) }, | |
2536 | { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) }, | |
2537 | { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) }, | |
2538 | { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) }, | |
2539 | { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) }, | |
2540 | { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) }, | |
2541 | { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) }, | |
2542 | { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) }, | |
2543 | { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) }, | |
2544 | { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) }, | |
2545 | { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) }, | |
2546 | #endif /* CONFIG_VHT_OVERRIDES */ | |
07f53b8c | 2547 | { INT(ap_max_inactivity) }, |
fdfb1c8b | 2548 | { INT(dtim_period) }, |
18206e02 | 2549 | { INT(beacon_int) }, |
dd10abcc HW |
2550 | #ifdef CONFIG_MACSEC |
2551 | { INT_RANGE(macsec_policy, 0, 1) }, | |
7b4d546e | 2552 | { INT_RANGE(macsec_integ_only, 0, 1) }, |
e49b78c0 AK |
2553 | { INT_RANGE(macsec_replay_protect, 0, 1) }, |
2554 | { INT(macsec_replay_window) }, | |
e0d9fd34 | 2555 | { INT_RANGE(macsec_port, 1, 65534) }, |
65dfa872 | 2556 | { INT_RANGE(mka_priority, 0, 255) }, |
ad51731a SD |
2557 | { FUNC_KEY(mka_cak) }, |
2558 | { FUNC_KEY(mka_ckn) }, | |
dd10abcc | 2559 | #endif /* CONFIG_MACSEC */ |
e376290c DS |
2560 | #ifdef CONFIG_HS20 |
2561 | { INT(update_identifier) }, | |
6311547e | 2562 | { STR_RANGE(roaming_consortium_selection, 0, MAX_ROAMING_CONS_OI_LEN) }, |
e376290c | 2563 | #endif /* CONFIG_HS20 */ |
a313d17d | 2564 | { INT_RANGE(mac_addr, 0, 2) }, |
90f14962 | 2565 | { INT_RANGE(pbss, 0, 2) }, |
b6317b41 | 2566 | { INT_RANGE(wps_disabled, 0, 1) }, |
76e20f4f | 2567 | { INT_RANGE(fils_dh_group, 0, 65535) }, |
b979caae JM |
2568 | #ifdef CONFIG_DPP |
2569 | { STR(dpp_connector) }, | |
2570 | { STR_LEN(dpp_netaccesskey) }, | |
2571 | { INT(dpp_netaccesskey_expiry) }, | |
2572 | { STR_LEN(dpp_csign) }, | |
b979caae | 2573 | #endif /* CONFIG_DPP */ |
ec9f4837 | 2574 | { INT_RANGE(owe_group, 0, 65535) }, |
c1790a5f | 2575 | { INT_RANGE(owe_only, 0, 1) }, |
8b138d28 | 2576 | { INT_RANGE(owe_ptk_workaround, 0, 1) }, |
5abc7823 | 2577 | { INT_RANGE(multi_ap_backhaul_sta, 0, 1) }, |
9083ef13 | 2578 | { INT_RANGE(ft_eap_pmksa_caching, 0, 1) }, |
ecbf59e6 | 2579 | { INT_RANGE(beacon_prot, 0, 1) }, |
6fc6879b JM |
2580 | }; |
2581 | ||
2582 | #undef OFFSET | |
2583 | #undef _STR | |
2584 | #undef STR | |
2585 | #undef STR_KEY | |
2586 | #undef _STR_LEN | |
2587 | #undef STR_LEN | |
2588 | #undef STR_LEN_KEY | |
2589 | #undef _STR_RANGE | |
2590 | #undef STR_RANGE | |
2591 | #undef STR_RANGE_KEY | |
2592 | #undef _INT | |
2593 | #undef INT | |
2594 | #undef INT_RANGE | |
2595 | #undef _FUNC | |
2596 | #undef FUNC | |
2597 | #undef FUNC_KEY | |
e7ecab4a | 2598 | #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields) |
6fc6879b JM |
2599 | |
2600 | ||
2601 | /** | |
2602 | * wpa_config_add_prio_network - Add a network to priority lists | |
2603 | * @config: Configuration data from wpa_config_read() | |
2604 | * @ssid: Pointer to the network configuration to be added to the list | |
2605 | * Returns: 0 on success, -1 on failure | |
2606 | * | |
2607 | * This function is used to add a network block to the priority list of | |
2608 | * networks. This must be called for each network when reading in the full | |
2609 | * configuration. In addition, this can be used indirectly when updating | |
2610 | * priorities by calling wpa_config_update_prio_list(). | |
2611 | */ | |
2612 | int wpa_config_add_prio_network(struct wpa_config *config, | |
2613 | struct wpa_ssid *ssid) | |
2614 | { | |
d2d16e31 | 2615 | size_t prio; |
6fc6879b JM |
2616 | struct wpa_ssid *prev, **nlist; |
2617 | ||
2618 | /* | |
2619 | * Add to an existing priority list if one is available for the | |
2620 | * configured priority level for this network. | |
2621 | */ | |
2622 | for (prio = 0; prio < config->num_prio; prio++) { | |
2623 | prev = config->pssid[prio]; | |
2624 | if (prev->priority == ssid->priority) { | |
2625 | while (prev->pnext) | |
2626 | prev = prev->pnext; | |
2627 | prev->pnext = ssid; | |
2628 | return 0; | |
2629 | } | |
2630 | } | |
2631 | ||
2632 | /* First network for this priority - add a new priority list */ | |
067ffa26 JM |
2633 | nlist = os_realloc_array(config->pssid, config->num_prio + 1, |
2634 | sizeof(struct wpa_ssid *)); | |
6fc6879b JM |
2635 | if (nlist == NULL) |
2636 | return -1; | |
2637 | ||
2638 | for (prio = 0; prio < config->num_prio; prio++) { | |
2c60ca73 JM |
2639 | if (nlist[prio]->priority < ssid->priority) { |
2640 | os_memmove(&nlist[prio + 1], &nlist[prio], | |
2641 | (config->num_prio - prio) * | |
2642 | sizeof(struct wpa_ssid *)); | |
6fc6879b | 2643 | break; |
2c60ca73 | 2644 | } |
6fc6879b JM |
2645 | } |
2646 | ||
6fc6879b JM |
2647 | nlist[prio] = ssid; |
2648 | config->num_prio++; | |
2649 | config->pssid = nlist; | |
2650 | ||
2651 | return 0; | |
2652 | } | |
2653 | ||
2654 | ||
2655 | /** | |
2656 | * wpa_config_update_prio_list - Update network priority list | |
2657 | * @config: Configuration data from wpa_config_read() | |
2658 | * Returns: 0 on success, -1 on failure | |
2659 | * | |
2660 | * This function is called to update the priority list of networks in the | |
2661 | * configuration when a network is being added or removed. This is also called | |
2662 | * if a priority for a network is changed. | |
2663 | */ | |
aa53509f | 2664 | int wpa_config_update_prio_list(struct wpa_config *config) |
6fc6879b JM |
2665 | { |
2666 | struct wpa_ssid *ssid; | |
2667 | int ret = 0; | |
2668 | ||
2669 | os_free(config->pssid); | |
2670 | config->pssid = NULL; | |
2671 | config->num_prio = 0; | |
2672 | ||
2673 | ssid = config->ssid; | |
2674 | while (ssid) { | |
2675 | ssid->pnext = NULL; | |
2676 | if (wpa_config_add_prio_network(config, ssid) < 0) | |
2677 | ret = -1; | |
2678 | ssid = ssid->next; | |
2679 | } | |
2680 | ||
2681 | return ret; | |
2682 | } | |
2683 | ||
2684 | ||
2685 | #ifdef IEEE8021X_EAPOL | |
b99c4cad JM |
2686 | |
2687 | static void eap_peer_config_free_cert(struct eap_peer_cert_config *cert) | |
2688 | { | |
2689 | os_free(cert->ca_cert); | |
2690 | os_free(cert->ca_path); | |
2691 | os_free(cert->client_cert); | |
2692 | os_free(cert->private_key); | |
2693 | str_clear_free(cert->private_key_passwd); | |
2694 | os_free(cert->dh_file); | |
2695 | os_free(cert->subject_match); | |
2696 | os_free(cert->check_cert_subject); | |
2697 | os_free(cert->altsubject_match); | |
2698 | os_free(cert->domain_suffix_match); | |
2699 | os_free(cert->domain_match); | |
2700 | str_clear_free(cert->pin); | |
2701 | os_free(cert->engine_id); | |
2702 | os_free(cert->key_id); | |
2703 | os_free(cert->cert_id); | |
2704 | os_free(cert->ca_cert_id); | |
2705 | } | |
2706 | ||
2707 | ||
6fc6879b JM |
2708 | static void eap_peer_config_free(struct eap_peer_config *eap) |
2709 | { | |
2710 | os_free(eap->eap_methods); | |
19c48da0 | 2711 | bin_clear_free(eap->identity, eap->identity_len); |
6fc6879b | 2712 | os_free(eap->anonymous_identity); |
9e834fc6 | 2713 | os_free(eap->imsi_identity); |
c724a0a1 | 2714 | os_free(eap->machine_identity); |
19c48da0 | 2715 | bin_clear_free(eap->password, eap->password_len); |
c724a0a1 | 2716 | bin_clear_free(eap->machine_password, eap->machine_password_len); |
b99c4cad JM |
2717 | eap_peer_config_free_cert(&eap->cert); |
2718 | eap_peer_config_free_cert(&eap->phase2_cert); | |
68161824 | 2719 | eap_peer_config_free_cert(&eap->machine_cert); |
6fc6879b JM |
2720 | os_free(eap->phase1); |
2721 | os_free(eap->phase2); | |
68161824 | 2722 | os_free(eap->machine_phase2); |
6fc6879b | 2723 | os_free(eap->pcsc); |
6fc6879b JM |
2724 | os_free(eap->otp); |
2725 | os_free(eap->pending_req_otp); | |
2726 | os_free(eap->pac_file); | |
19c48da0 JM |
2727 | bin_clear_free(eap->new_password, eap->new_password_len); |
2728 | str_clear_free(eap->external_sim_resp); | |
07e2de31 | 2729 | os_free(eap->openssl_ciphers); |
6fc6879b | 2730 | } |
b99c4cad | 2731 | |
6fc6879b JM |
2732 | #endif /* IEEE8021X_EAPOL */ |
2733 | ||
2734 | ||
2735 | /** | |
2736 | * wpa_config_free_ssid - Free network/ssid configuration data | |
2737 | * @ssid: Configuration data for the network | |
2738 | * | |
2739 | * This function frees all resources allocated for the network configuration | |
2740 | * data. | |
2741 | */ | |
2742 | void wpa_config_free_ssid(struct wpa_ssid *ssid) | |
2743 | { | |
01a57fe4 JM |
2744 | struct psk_list_entry *psk; |
2745 | ||
6fc6879b | 2746 | os_free(ssid->ssid); |
19c48da0 | 2747 | str_clear_free(ssid->passphrase); |
9173b16f | 2748 | os_free(ssid->ext_psk); |
a34ca59e | 2749 | str_clear_free(ssid->sae_password); |
9be19d0b | 2750 | os_free(ssid->sae_password_id); |
6fc6879b JM |
2751 | #ifdef IEEE8021X_EAPOL |
2752 | eap_peer_config_free(&ssid->eap); | |
2753 | #endif /* IEEE8021X_EAPOL */ | |
2754 | os_free(ssid->id_str); | |
d3a98225 | 2755 | os_free(ssid->scan_freq); |
b766a9a2 | 2756 | os_free(ssid->freq_list); |
60b94c98 | 2757 | os_free(ssid->bgscan); |
fbdcfd57 | 2758 | os_free(ssid->p2p_client_list); |
79cd993a ST |
2759 | os_free(ssid->bssid_blacklist); |
2760 | os_free(ssid->bssid_whitelist); | |
80e8a5ee BG |
2761 | #ifdef CONFIG_HT_OVERRIDES |
2762 | os_free(ssid->ht_mcs); | |
2763 | #endif /* CONFIG_HT_OVERRIDES */ | |
2b2bb5a8 MH |
2764 | #ifdef CONFIG_MESH |
2765 | os_free(ssid->mesh_basic_rates); | |
2766 | #endif /* CONFIG_MESH */ | |
6311547e JM |
2767 | #ifdef CONFIG_HS20 |
2768 | os_free(ssid->roaming_consortium_selection); | |
2769 | #endif /* CONFIG_HS20 */ | |
b979caae JM |
2770 | os_free(ssid->dpp_connector); |
2771 | bin_clear_free(ssid->dpp_netaccesskey, ssid->dpp_netaccesskey_len); | |
2772 | os_free(ssid->dpp_csign); | |
01a57fe4 JM |
2773 | while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry, |
2774 | list))) { | |
2775 | dl_list_del(&psk->list); | |
6df19739 | 2776 | bin_clear_free(psk, sizeof(*psk)); |
01a57fe4 | 2777 | } |
05a2fb0d JM |
2778 | #ifdef CONFIG_SAE |
2779 | sae_deinit_pt(ssid->pt); | |
2780 | #endif /* CONFIG_SAE */ | |
6df19739 | 2781 | bin_clear_free(ssid, sizeof(*ssid)); |
6fc6879b JM |
2782 | } |
2783 | ||
2784 | ||
1bb7b8e8 JM |
2785 | void wpa_config_free_cred(struct wpa_cred *cred) |
2786 | { | |
463c8ffb JM |
2787 | size_t i; |
2788 | ||
1bb7b8e8 | 2789 | os_free(cred->realm); |
19c48da0 JM |
2790 | str_clear_free(cred->username); |
2791 | str_clear_free(cred->password); | |
1bb7b8e8 | 2792 | os_free(cred->ca_cert); |
11e4f46a JM |
2793 | os_free(cred->client_cert); |
2794 | os_free(cred->private_key); | |
19c48da0 | 2795 | str_clear_free(cred->private_key_passwd); |
1bb7b8e8 | 2796 | os_free(cred->imsi); |
19c48da0 | 2797 | str_clear_free(cred->milenage); |
463c8ffb JM |
2798 | for (i = 0; i < cred->num_domain; i++) |
2799 | os_free(cred->domain[i]); | |
1bb7b8e8 | 2800 | os_free(cred->domain); |
ac1bc549 | 2801 | os_free(cred->domain_suffix_match); |
8ca93c59 JM |
2802 | os_free(cred->eap_method); |
2803 | os_free(cred->phase1); | |
2804 | os_free(cred->phase2); | |
dbea8ac7 | 2805 | os_free(cred->excluded_ssid); |
bc00053c | 2806 | os_free(cred->roaming_partner); |
aa26ba68 | 2807 | os_free(cred->provisioning_sp); |
33fb8c52 JM |
2808 | for (i = 0; i < cred->num_req_conn_capab; i++) |
2809 | os_free(cred->req_conn_capab_port[i]); | |
2810 | os_free(cred->req_conn_capab_port); | |
2811 | os_free(cred->req_conn_capab_proto); | |
1bb7b8e8 JM |
2812 | os_free(cred); |
2813 | } | |
2814 | ||
2815 | ||
d9bb2821 JM |
2816 | void wpa_config_flush_blobs(struct wpa_config *config) |
2817 | { | |
2818 | #ifndef CONFIG_NO_CONFIG_BLOBS | |
2819 | struct wpa_config_blob *blob, *prev; | |
2820 | ||
2821 | blob = config->blobs; | |
2822 | config->blobs = NULL; | |
2823 | while (blob) { | |
2824 | prev = blob; | |
2825 | blob = blob->next; | |
2826 | wpa_config_free_blob(prev); | |
2827 | } | |
2828 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
2829 | } | |
2830 | ||
2831 | ||
6fc6879b JM |
2832 | /** |
2833 | * wpa_config_free - Free configuration data | |
2834 | * @config: Configuration data from wpa_config_read() | |
2835 | * | |
2836 | * This function frees all resources allocated for the configuration data by | |
2837 | * wpa_config_read(). | |
2838 | */ | |
2839 | void wpa_config_free(struct wpa_config *config) | |
2840 | { | |
6fc6879b | 2841 | struct wpa_ssid *ssid, *prev = NULL; |
1bb7b8e8 | 2842 | struct wpa_cred *cred, *cprev; |
54e06b4f | 2843 | int i; |
e3768e7c | 2844 | |
6fc6879b JM |
2845 | ssid = config->ssid; |
2846 | while (ssid) { | |
2847 | prev = ssid; | |
2848 | ssid = ssid->next; | |
2849 | wpa_config_free_ssid(prev); | |
2850 | } | |
2851 | ||
1bb7b8e8 JM |
2852 | cred = config->cred; |
2853 | while (cred) { | |
2854 | cprev = cred; | |
2855 | cred = cred->next; | |
2856 | wpa_config_free_cred(cprev); | |
2857 | } | |
2858 | ||
d9bb2821 | 2859 | wpa_config_flush_blobs(config); |
6fc6879b | 2860 | |
71dd3b78 | 2861 | wpabuf_free(config->wps_vendor_ext_m1); |
54e06b4f JM |
2862 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) |
2863 | wpabuf_free(config->wps_vendor_ext[i]); | |
6fc6879b JM |
2864 | os_free(config->ctrl_interface); |
2865 | os_free(config->ctrl_interface_group); | |
6fc6879b JM |
2866 | os_free(config->opensc_engine_path); |
2867 | os_free(config->pkcs11_engine_path); | |
2868 | os_free(config->pkcs11_module_path); | |
07e2de31 | 2869 | os_free(config->openssl_ciphers); |
f64adcd7 | 2870 | os_free(config->pcsc_reader); |
19c48da0 | 2871 | str_clear_free(config->pcsc_pin); |
6fc6879b | 2872 | os_free(config->driver_param); |
3c0b7aa4 JM |
2873 | os_free(config->device_name); |
2874 | os_free(config->manufacturer); | |
2875 | os_free(config->model_name); | |
2876 | os_free(config->model_number); | |
2877 | os_free(config->serial_number); | |
c0e4dd9e | 2878 | os_free(config->config_methods); |
e3768e7c | 2879 | os_free(config->p2p_ssid_postfix); |
6fc6879b | 2880 | os_free(config->pssid); |
21d996f7 | 2881 | os_free(config->p2p_pref_chan); |
556b30da | 2882 | os_free(config->p2p_no_go_freq.range); |
b0786fba | 2883 | os_free(config->autoscan); |
f5ffc348 | 2884 | os_free(config->freq_list); |
3f2c8ba6 JM |
2885 | wpabuf_free(config->wps_nfc_dh_pubkey); |
2886 | wpabuf_free(config->wps_nfc_dh_privkey); | |
2887 | wpabuf_free(config->wps_nfc_dev_pw); | |
306ae225 | 2888 | os_free(config->ext_password_backend); |
625f202a | 2889 | os_free(config->sae_groups); |
18a2eaab | 2890 | wpabuf_free(config->ap_vendor_elements); |
b572df86 | 2891 | os_free(config->osu_dir); |
dd09e424 | 2892 | os_free(config->bgscan); |
e4fa8b12 | 2893 | os_free(config->wowlan_triggers); |
76ca15b7 | 2894 | os_free(config->fst_group_id); |
32c02261 | 2895 | os_free(config->sched_scan_plans); |
facf2c72 DS |
2896 | #ifdef CONFIG_MBO |
2897 | os_free(config->non_pref_chan); | |
2898 | #endif /* CONFIG_MBO */ | |
5a5639b0 JM |
2899 | os_free(config->dpp_name); |
2900 | os_free(config->dpp_mud_url); | |
32c02261 | 2901 | |
6fc6879b JM |
2902 | os_free(config); |
2903 | } | |
2904 | ||
2905 | ||
7c49fdd0 SL |
2906 | /** |
2907 | * wpa_config_foreach_network - Iterate over each configured network | |
2908 | * @config: Configuration data from wpa_config_read() | |
2909 | * @func: Callback function to process each network | |
2910 | * @arg: Opaque argument to pass to callback function | |
2911 | * | |
2912 | * Iterate over the set of configured networks calling the specified | |
2913 | * function for each item. We guard against callbacks removing the | |
2914 | * supplied network. | |
2915 | */ | |
2916 | void wpa_config_foreach_network(struct wpa_config *config, | |
2917 | void (*func)(void *, struct wpa_ssid *), | |
2918 | void *arg) | |
2919 | { | |
2920 | struct wpa_ssid *ssid, *next; | |
2921 | ||
2922 | ssid = config->ssid; | |
2923 | while (ssid) { | |
2924 | next = ssid->next; | |
2925 | func(arg, ssid); | |
2926 | ssid = next; | |
2927 | } | |
2928 | } | |
2929 | ||
2930 | ||
6fc6879b JM |
2931 | /** |
2932 | * wpa_config_get_network - Get configured network based on id | |
2933 | * @config: Configuration data from wpa_config_read() | |
2934 | * @id: Unique network id to search for | |
2935 | * Returns: Network configuration or %NULL if not found | |
2936 | */ | |
2937 | struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id) | |
2938 | { | |
2939 | struct wpa_ssid *ssid; | |
2940 | ||
2941 | ssid = config->ssid; | |
2942 | while (ssid) { | |
2943 | if (id == ssid->id) | |
2944 | break; | |
2945 | ssid = ssid->next; | |
2946 | } | |
2947 | ||
2948 | return ssid; | |
2949 | } | |
2950 | ||
2951 | ||
2952 | /** | |
2953 | * wpa_config_add_network - Add a new network with empty configuration | |
2954 | * @config: Configuration data from wpa_config_read() | |
2955 | * Returns: The new network configuration or %NULL if operation failed | |
2956 | */ | |
2957 | struct wpa_ssid * wpa_config_add_network(struct wpa_config *config) | |
2958 | { | |
2959 | int id; | |
2960 | struct wpa_ssid *ssid, *last = NULL; | |
2961 | ||
2962 | id = -1; | |
2963 | ssid = config->ssid; | |
2964 | while (ssid) { | |
2965 | if (ssid->id > id) | |
2966 | id = ssid->id; | |
2967 | last = ssid; | |
2968 | ssid = ssid->next; | |
2969 | } | |
2970 | id++; | |
2971 | ||
2972 | ssid = os_zalloc(sizeof(*ssid)); | |
2973 | if (ssid == NULL) | |
2974 | return NULL; | |
2975 | ssid->id = id; | |
01a57fe4 | 2976 | dl_list_init(&ssid->psk_list); |
6fc6879b JM |
2977 | if (last) |
2978 | last->next = ssid; | |
2979 | else | |
2980 | config->ssid = ssid; | |
2981 | ||
2982 | wpa_config_update_prio_list(config); | |
2983 | ||
2984 | return ssid; | |
2985 | } | |
2986 | ||
2987 | ||
2988 | /** | |
2989 | * wpa_config_remove_network - Remove a configured network based on id | |
2990 | * @config: Configuration data from wpa_config_read() | |
2991 | * @id: Unique network id to search for | |
2992 | * Returns: 0 on success, or -1 if the network was not found | |
2993 | */ | |
2994 | int wpa_config_remove_network(struct wpa_config *config, int id) | |
2995 | { | |
2996 | struct wpa_ssid *ssid, *prev = NULL; | |
2997 | ||
2998 | ssid = config->ssid; | |
2999 | while (ssid) { | |
3000 | if (id == ssid->id) | |
3001 | break; | |
3002 | prev = ssid; | |
3003 | ssid = ssid->next; | |
3004 | } | |
3005 | ||
3006 | if (ssid == NULL) | |
3007 | return -1; | |
3008 | ||
3009 | if (prev) | |
3010 | prev->next = ssid->next; | |
3011 | else | |
3012 | config->ssid = ssid->next; | |
3013 | ||
3014 | wpa_config_update_prio_list(config); | |
3015 | wpa_config_free_ssid(ssid); | |
3016 | return 0; | |
3017 | } | |
3018 | ||
3019 | ||
3020 | /** | |
3021 | * wpa_config_set_network_defaults - Set network default values | |
3022 | * @ssid: Pointer to network configuration data | |
3023 | */ | |
3024 | void wpa_config_set_network_defaults(struct wpa_ssid *ssid) | |
3025 | { | |
3026 | ssid->proto = DEFAULT_PROTO; | |
3027 | ssid->pairwise_cipher = DEFAULT_PAIRWISE; | |
3028 | ssid->group_cipher = DEFAULT_GROUP; | |
3029 | ssid->key_mgmt = DEFAULT_KEY_MGMT; | |
1f90a49d | 3030 | ssid->wpa_deny_ptk0_rekey = PTK0_REKEY_ALLOW_ALWAYS; |
1f6c0ab8 | 3031 | ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD; |
b07ff9cb | 3032 | ssid->ht = 1; |
6fc6879b JM |
3033 | #ifdef IEEE8021X_EAPOL |
3034 | ssid->eapol_flags = DEFAULT_EAPOL_FLAGS; | |
3035 | ssid->eap_workaround = DEFAULT_EAP_WORKAROUND; | |
3036 | ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE; | |
13f6a07e | 3037 | ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM; |
6fc6879b | 3038 | #endif /* IEEE8021X_EAPOL */ |
5cfb672d | 3039 | #ifdef CONFIG_MESH |
e6096799 MH |
3040 | ssid->dot11MeshMaxRetries = DEFAULT_MESH_MAX_RETRIES; |
3041 | ssid->dot11MeshRetryTimeout = DEFAULT_MESH_RETRY_TIMEOUT; | |
3042 | ssid->dot11MeshConfirmTimeout = DEFAULT_MESH_CONFIRM_TIMEOUT; | |
3043 | ssid->dot11MeshHoldingTimeout = DEFAULT_MESH_HOLDING_TIMEOUT; | |
31a856a1 | 3044 | ssid->mesh_rssi_threshold = DEFAULT_MESH_RSSI_THRESHOLD; |
5cfb672d | 3045 | #endif /* CONFIG_MESH */ |
80e8a5ee BG |
3046 | #ifdef CONFIG_HT_OVERRIDES |
3047 | ssid->disable_ht = DEFAULT_DISABLE_HT; | |
3048 | ssid->disable_ht40 = DEFAULT_DISABLE_HT40; | |
a90497f8 | 3049 | ssid->disable_sgi = DEFAULT_DISABLE_SGI; |
39a5800f | 3050 | ssid->disable_ldpc = DEFAULT_DISABLE_LDPC; |
cdeea70f SM |
3051 | ssid->tx_stbc = DEFAULT_TX_STBC; |
3052 | ssid->rx_stbc = DEFAULT_RX_STBC; | |
80e8a5ee BG |
3053 | ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU; |
3054 | ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR; | |
3055 | ssid->ampdu_density = DEFAULT_AMPDU_DENSITY; | |
3056 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
3057 | #ifdef CONFIG_VHT_OVERRIDES |
3058 | ssid->vht_rx_mcs_nss_1 = -1; | |
3059 | ssid->vht_rx_mcs_nss_2 = -1; | |
3060 | ssid->vht_rx_mcs_nss_3 = -1; | |
3061 | ssid->vht_rx_mcs_nss_4 = -1; | |
3062 | ssid->vht_rx_mcs_nss_5 = -1; | |
3063 | ssid->vht_rx_mcs_nss_6 = -1; | |
3064 | ssid->vht_rx_mcs_nss_7 = -1; | |
3065 | ssid->vht_rx_mcs_nss_8 = -1; | |
3066 | ssid->vht_tx_mcs_nss_1 = -1; | |
3067 | ssid->vht_tx_mcs_nss_2 = -1; | |
3068 | ssid->vht_tx_mcs_nss_3 = -1; | |
3069 | ssid->vht_tx_mcs_nss_4 = -1; | |
3070 | ssid->vht_tx_mcs_nss_5 = -1; | |
3071 | ssid->vht_tx_mcs_nss_6 = -1; | |
3072 | ssid->vht_tx_mcs_nss_7 = -1; | |
3073 | ssid->vht_tx_mcs_nss_8 = -1; | |
3074 | #endif /* CONFIG_VHT_OVERRIDES */ | |
6e202021 | 3075 | ssid->proactive_key_caching = -1; |
62d49803 | 3076 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT; |
65dfa872 BA |
3077 | #ifdef CONFIG_MACSEC |
3078 | ssid->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER; | |
3079 | #endif /* CONFIG_MACSEC */ | |
c267753b | 3080 | ssid->mac_addr = -1; |
806db174 | 3081 | ssid->max_oper_chwidth = DEFAULT_MAX_OPER_CHWIDTH; |
6fc6879b JM |
3082 | } |
3083 | ||
3084 | ||
3085 | /** | |
3086 | * wpa_config_set - Set a variable in network configuration | |
3087 | * @ssid: Pointer to network configuration data | |
3088 | * @var: Variable name, e.g., "ssid" | |
3089 | * @value: Variable value | |
3090 | * @line: Line number in configuration file or 0 if not used | |
5cd317d3 BKB |
3091 | * Returns: 0 on success with possible change in the value, 1 on success with |
3092 | * no change to previously configured value, or -1 on failure | |
6fc6879b JM |
3093 | * |
3094 | * This function can be used to set network configuration variables based on | |
3095 | * both the configuration file and management interface input. The value | |
3096 | * parameter must be in the same format as the text-based configuration file is | |
3097 | * using. For example, strings are using double quotation marks. | |
3098 | */ | |
3099 | int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value, | |
3100 | int line) | |
3101 | { | |
3102 | size_t i; | |
3103 | int ret = 0; | |
3104 | ||
3105 | if (ssid == NULL || var == NULL || value == NULL) | |
3106 | return -1; | |
3107 | ||
3108 | for (i = 0; i < NUM_SSID_FIELDS; i++) { | |
3109 | const struct parse_data *field = &ssid_fields[i]; | |
3110 | if (os_strcmp(var, field->name) != 0) | |
3111 | continue; | |
3112 | ||
5cd317d3 BKB |
3113 | ret = field->parser(field, ssid, line, value); |
3114 | if (ret < 0) { | |
6fc6879b JM |
3115 | if (line) { |
3116 | wpa_printf(MSG_ERROR, "Line %d: failed to " | |
3117 | "parse %s '%s'.", line, var, value); | |
3118 | } | |
3119 | ret = -1; | |
3120 | } | |
05a2fb0d JM |
3121 | #ifdef CONFIG_SAE |
3122 | if (os_strcmp(var, "ssid") == 0 || | |
3123 | os_strcmp(var, "psk") == 0 || | |
3124 | os_strcmp(var, "sae_password") == 0 || | |
3125 | os_strcmp(var, "sae_password_id") == 0) { | |
3126 | sae_deinit_pt(ssid->pt); | |
3127 | ssid->pt = NULL; | |
3128 | } | |
3129 | #endif /* CONFIG_SAE */ | |
6fc6879b JM |
3130 | break; |
3131 | } | |
3132 | if (i == NUM_SSID_FIELDS) { | |
3133 | if (line) { | |
3134 | wpa_printf(MSG_ERROR, "Line %d: unknown network field " | |
3135 | "'%s'.", line, var); | |
3136 | } | |
3137 | ret = -1; | |
3138 | } | |
3139 | ||
3140 | return ret; | |
3141 | } | |
3142 | ||
3143 | ||
67e1b984 JM |
3144 | int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var, |
3145 | const char *value) | |
3146 | { | |
3147 | size_t len; | |
3148 | char *buf; | |
3149 | int ret; | |
3150 | ||
3151 | len = os_strlen(value); | |
3152 | buf = os_malloc(len + 3); | |
3153 | if (buf == NULL) | |
3154 | return -1; | |
3155 | buf[0] = '"'; | |
3156 | os_memcpy(buf + 1, value, len); | |
3157 | buf[len + 1] = '"'; | |
3158 | buf[len + 2] = '\0'; | |
3159 | ret = wpa_config_set(ssid, var, buf, 0); | |
3160 | os_free(buf); | |
3161 | return ret; | |
3162 | } | |
3163 | ||
3164 | ||
3d3d3056 WS |
3165 | /** |
3166 | * wpa_config_get_all - Get all options from network configuration | |
3167 | * @ssid: Pointer to network configuration data | |
3168 | * @get_keys: Determines if keys/passwords will be included in returned list | |
d1c8ac88 | 3169 | * (if they may be exported) |
3d3d3056 WS |
3170 | * Returns: %NULL terminated list of all set keys and their values in the form |
3171 | * of [key1, val1, key2, val2, ... , NULL] | |
3172 | * | |
3173 | * This function can be used to get list of all configured network properties. | |
3174 | * The caller is responsible for freeing the returned list and all its | |
3175 | * elements. | |
3176 | */ | |
3177 | char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys) | |
3178 | { | |
954f03aa JM |
3179 | #ifdef NO_CONFIG_WRITE |
3180 | return NULL; | |
3181 | #else /* NO_CONFIG_WRITE */ | |
3d3d3056 WS |
3182 | const struct parse_data *field; |
3183 | char *key, *value; | |
3184 | size_t i; | |
3185 | char **props; | |
3186 | int fields_num; | |
3187 | ||
d1c8ac88 JB |
3188 | get_keys = get_keys && ssid->export_keys; |
3189 | ||
f9884c09 | 3190 | props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *)); |
3d3d3056 WS |
3191 | if (!props) |
3192 | return NULL; | |
3193 | ||
3194 | fields_num = 0; | |
3195 | for (i = 0; i < NUM_SSID_FIELDS; i++) { | |
3196 | field = &ssid_fields[i]; | |
3197 | if (field->key_data && !get_keys) | |
3198 | continue; | |
3199 | value = field->writer(field, ssid); | |
04746865 | 3200 | if (value == NULL) |
3d3d3056 | 3201 | continue; |
04746865 JM |
3202 | if (os_strlen(value) == 0) { |
3203 | os_free(value); | |
3204 | continue; | |
3205 | } | |
3d3d3056 WS |
3206 | |
3207 | key = os_strdup(field->name); | |
04746865 JM |
3208 | if (key == NULL) { |
3209 | os_free(value); | |
3d3d3056 | 3210 | goto err; |
04746865 | 3211 | } |
3d3d3056 WS |
3212 | |
3213 | props[fields_num * 2] = key; | |
3214 | props[fields_num * 2 + 1] = value; | |
3215 | ||
3216 | fields_num++; | |
3217 | } | |
3218 | ||
3219 | return props; | |
3220 | ||
3221 | err: | |
8329ad4d JM |
3222 | for (i = 0; props[i]; i++) |
3223 | os_free(props[i]); | |
3d3d3056 WS |
3224 | os_free(props); |
3225 | return NULL; | |
954f03aa | 3226 | #endif /* NO_CONFIG_WRITE */ |
3d3d3056 WS |
3227 | } |
3228 | ||
3229 | ||
6fc6879b JM |
3230 | #ifndef NO_CONFIG_WRITE |
3231 | /** | |
3232 | * wpa_config_get - Get a variable in network configuration | |
3233 | * @ssid: Pointer to network configuration data | |
3234 | * @var: Variable name, e.g., "ssid" | |
3235 | * Returns: Value of the variable or %NULL on failure | |
3236 | * | |
3237 | * This function can be used to get network configuration variables. The | |
3238 | * returned value is a copy of the configuration variable in text format, i.e,. | |
3239 | * the same format that the text-based configuration file and wpa_config_set() | |
3240 | * are using for the value. The caller is responsible for freeing the returned | |
3241 | * value. | |
3242 | */ | |
3243 | char * wpa_config_get(struct wpa_ssid *ssid, const char *var) | |
3244 | { | |
3245 | size_t i; | |
3246 | ||
3247 | if (ssid == NULL || var == NULL) | |
3248 | return NULL; | |
3249 | ||
3250 | for (i = 0; i < NUM_SSID_FIELDS; i++) { | |
3251 | const struct parse_data *field = &ssid_fields[i]; | |
0fe5a234 PS |
3252 | if (os_strcmp(var, field->name) == 0) { |
3253 | char *ret = field->writer(field, ssid); | |
3254 | ||
3255 | if (ret && has_newline(ret)) { | |
3256 | wpa_printf(MSG_ERROR, | |
3257 | "Found newline in value for %s; not returning it", | |
3258 | var); | |
3259 | os_free(ret); | |
3260 | ret = NULL; | |
3261 | } | |
3262 | ||
3263 | return ret; | |
3264 | } | |
6fc6879b JM |
3265 | } |
3266 | ||
3267 | return NULL; | |
3268 | } | |
3269 | ||
3270 | ||
3271 | /** | |
3272 | * wpa_config_get_no_key - Get a variable in network configuration (no keys) | |
3273 | * @ssid: Pointer to network configuration data | |
3274 | * @var: Variable name, e.g., "ssid" | |
3275 | * Returns: Value of the variable or %NULL on failure | |
3276 | * | |
3277 | * This function can be used to get network configuration variable like | |
3278 | * wpa_config_get(). The only difference is that this functions does not expose | |
3279 | * key/password material from the configuration. In case a key/password field | |
3280 | * is requested, the returned value is an empty string or %NULL if the variable | |
3281 | * is not set or "*" if the variable is set (regardless of its value). The | |
3282 | * returned value is a copy of the configuration variable in text format, i.e,. | |
3283 | * the same format that the text-based configuration file and wpa_config_set() | |
3284 | * are using for the value. The caller is responsible for freeing the returned | |
3285 | * value. | |
3286 | */ | |
3287 | char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var) | |
3288 | { | |
3289 | size_t i; | |
3290 | ||
3291 | if (ssid == NULL || var == NULL) | |
3292 | return NULL; | |
3293 | ||
3294 | for (i = 0; i < NUM_SSID_FIELDS; i++) { | |
3295 | const struct parse_data *field = &ssid_fields[i]; | |
3296 | if (os_strcmp(var, field->name) == 0) { | |
3297 | char *res = field->writer(field, ssid); | |
3298 | if (field->key_data) { | |
3299 | if (res && res[0]) { | |
3300 | wpa_printf(MSG_DEBUG, "Do not allow " | |
3301 | "key_data field to be " | |
3302 | "exposed"); | |
19c48da0 | 3303 | str_clear_free(res); |
6fc6879b JM |
3304 | return os_strdup("*"); |
3305 | } | |
3306 | ||
3307 | os_free(res); | |
3308 | return NULL; | |
3309 | } | |
3310 | return res; | |
3311 | } | |
3312 | } | |
3313 | ||
3314 | return NULL; | |
3315 | } | |
3316 | #endif /* NO_CONFIG_WRITE */ | |
3317 | ||
3318 | ||
3319 | /** | |
3320 | * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID | |
3321 | * @ssid: Pointer to network configuration data | |
3322 | * | |
3323 | * This function must be called to update WPA PSK when either SSID or the | |
3324 | * passphrase has changed for the network configuration. | |
3325 | */ | |
3326 | void wpa_config_update_psk(struct wpa_ssid *ssid) | |
3327 | { | |
3328 | #ifndef CONFIG_NO_PBKDF2 | |
986de33d | 3329 | pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096, |
6fc6879b JM |
3330 | ssid->psk, PMK_LEN); |
3331 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", | |
3332 | ssid->psk, PMK_LEN); | |
3333 | ssid->psk_set = 1; | |
3334 | #endif /* CONFIG_NO_PBKDF2 */ | |
3335 | } | |
3336 | ||
3337 | ||
33fb8c52 JM |
3338 | static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred, |
3339 | const char *value) | |
3340 | { | |
3341 | u8 *proto; | |
3342 | int **port; | |
3343 | int *ports, *nports; | |
3344 | const char *pos; | |
3345 | unsigned int num_ports; | |
3346 | ||
3347 | proto = os_realloc_array(cred->req_conn_capab_proto, | |
3348 | cred->num_req_conn_capab + 1, sizeof(u8)); | |
3349 | if (proto == NULL) | |
3350 | return -1; | |
3351 | cred->req_conn_capab_proto = proto; | |
3352 | ||
3353 | port = os_realloc_array(cred->req_conn_capab_port, | |
3354 | cred->num_req_conn_capab + 1, sizeof(int *)); | |
3355 | if (port == NULL) | |
3356 | return -1; | |
3357 | cred->req_conn_capab_port = port; | |
3358 | ||
3359 | proto[cred->num_req_conn_capab] = atoi(value); | |
3360 | ||
3361 | pos = os_strchr(value, ':'); | |
3362 | if (pos == NULL) { | |
3363 | port[cred->num_req_conn_capab] = NULL; | |
3364 | cred->num_req_conn_capab++; | |
3365 | return 0; | |
3366 | } | |
3367 | pos++; | |
3368 | ||
3369 | ports = NULL; | |
3370 | num_ports = 0; | |
3371 | ||
3372 | while (*pos) { | |
3373 | nports = os_realloc_array(ports, num_ports + 1, sizeof(int)); | |
3374 | if (nports == NULL) { | |
3375 | os_free(ports); | |
3376 | return -1; | |
3377 | } | |
3378 | ports = nports; | |
3379 | ports[num_ports++] = atoi(pos); | |
3380 | ||
3381 | pos = os_strchr(pos, ','); | |
3382 | if (pos == NULL) | |
3383 | break; | |
3384 | pos++; | |
3385 | } | |
3386 | ||
3387 | nports = os_realloc_array(ports, num_ports + 1, sizeof(int)); | |
3388 | if (nports == NULL) { | |
3389 | os_free(ports); | |
3390 | return -1; | |
3391 | } | |
3392 | ports = nports; | |
3393 | ports[num_ports] = -1; | |
3394 | ||
3395 | port[cred->num_req_conn_capab] = ports; | |
3396 | cred->num_req_conn_capab++; | |
3397 | return 0; | |
3398 | } | |
3399 | ||
3400 | ||
909a948b JM |
3401 | static int wpa_config_set_cred_roaming_consortiums(struct wpa_cred *cred, |
3402 | const char *value) | |
3403 | { | |
3404 | u8 roaming_consortiums[MAX_ROAMING_CONS][MAX_ROAMING_CONS_OI_LEN]; | |
3405 | size_t roaming_consortiums_len[MAX_ROAMING_CONS]; | |
3406 | unsigned int num_roaming_consortiums = 0; | |
3407 | const char *pos, *end; | |
3408 | size_t len; | |
3409 | ||
3410 | os_memset(roaming_consortiums, 0, sizeof(roaming_consortiums)); | |
3411 | os_memset(roaming_consortiums_len, 0, sizeof(roaming_consortiums_len)); | |
3412 | ||
3413 | for (pos = value;;) { | |
3414 | end = os_strchr(pos, ','); | |
3415 | len = end ? (size_t) (end - pos) : os_strlen(pos); | |
3416 | if (!end && len == 0) | |
3417 | break; | |
3418 | if (len == 0 || (len & 1) != 0 || | |
3419 | len / 2 > MAX_ROAMING_CONS_OI_LEN || | |
3420 | hexstr2bin(pos, | |
3421 | roaming_consortiums[num_roaming_consortiums], | |
3422 | len / 2) < 0) { | |
3423 | wpa_printf(MSG_INFO, | |
3424 | "Invalid roaming_consortiums entry: %s", | |
3425 | pos); | |
3426 | return -1; | |
3427 | } | |
3428 | roaming_consortiums_len[num_roaming_consortiums] = len / 2; | |
3429 | num_roaming_consortiums++; | |
ac0ac1dd AO |
3430 | |
3431 | if (!end) | |
3432 | break; | |
3433 | ||
3434 | if (num_roaming_consortiums >= MAX_ROAMING_CONS) { | |
909a948b JM |
3435 | wpa_printf(MSG_INFO, |
3436 | "Too many roaming_consortiums OIs"); | |
3437 | return -1; | |
3438 | } | |
3439 | ||
909a948b JM |
3440 | pos = end + 1; |
3441 | } | |
3442 | ||
3443 | os_memcpy(cred->roaming_consortiums, roaming_consortiums, | |
3444 | sizeof(roaming_consortiums)); | |
3445 | os_memcpy(cred->roaming_consortiums_len, roaming_consortiums_len, | |
3446 | sizeof(roaming_consortiums_len)); | |
3447 | cred->num_roaming_consortiums = num_roaming_consortiums; | |
3448 | ||
3449 | return 0; | |
3450 | } | |
3451 | ||
3452 | ||
1bb7b8e8 JM |
3453 | int wpa_config_set_cred(struct wpa_cred *cred, const char *var, |
3454 | const char *value, int line) | |
3455 | { | |
3456 | char *val; | |
3457 | size_t len; | |
909a948b | 3458 | int res; |
1bb7b8e8 | 3459 | |
03ed3324 JM |
3460 | if (os_strcmp(var, "temporary") == 0) { |
3461 | cred->temporary = atoi(value); | |
3462 | return 0; | |
3463 | } | |
3464 | ||
1a712d2f JM |
3465 | if (os_strcmp(var, "priority") == 0) { |
3466 | cred->priority = atoi(value); | |
3467 | return 0; | |
3468 | } | |
3469 | ||
74794891 JM |
3470 | if (os_strcmp(var, "sp_priority") == 0) { |
3471 | int prio = atoi(value); | |
3472 | if (prio < 0 || prio > 255) | |
3473 | return -1; | |
3474 | cred->sp_priority = prio; | |
3475 | return 0; | |
3476 | } | |
3477 | ||
d7b01abd JM |
3478 | if (os_strcmp(var, "pcsc") == 0) { |
3479 | cred->pcsc = atoi(value); | |
3480 | return 0; | |
3481 | } | |
3482 | ||
8ca93c59 JM |
3483 | if (os_strcmp(var, "eap") == 0) { |
3484 | struct eap_method_type method; | |
3485 | method.method = eap_peer_get_type(value, &method.vendor); | |
3486 | if (method.vendor == EAP_VENDOR_IETF && | |
3487 | method.method == EAP_TYPE_NONE) { | |
3488 | wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' " | |
3489 | "for a credential", line, value); | |
3490 | return -1; | |
3491 | } | |
3492 | os_free(cred->eap_method); | |
3493 | cred->eap_method = os_malloc(sizeof(*cred->eap_method)); | |
3494 | if (cred->eap_method == NULL) | |
3495 | return -1; | |
3496 | os_memcpy(cred->eap_method, &method, sizeof(method)); | |
3497 | return 0; | |
3498 | } | |
3499 | ||
02af9c90 JM |
3500 | if (os_strcmp(var, "password") == 0 && |
3501 | os_strncmp(value, "ext:", 4) == 0) { | |
b166cd84 JM |
3502 | if (has_newline(value)) |
3503 | return -1; | |
19c48da0 | 3504 | str_clear_free(cred->password); |
02af9c90 JM |
3505 | cred->password = os_strdup(value); |
3506 | cred->ext_password = 1; | |
3507 | return 0; | |
3508 | } | |
3509 | ||
f9cd147d JM |
3510 | if (os_strcmp(var, "update_identifier") == 0) { |
3511 | cred->update_identifier = atoi(value); | |
3512 | return 0; | |
3513 | } | |
3514 | ||
4cad9df1 JM |
3515 | if (os_strcmp(var, "min_dl_bandwidth_home") == 0) { |
3516 | cred->min_dl_bandwidth_home = atoi(value); | |
3517 | return 0; | |
3518 | } | |
3519 | ||
3520 | if (os_strcmp(var, "min_ul_bandwidth_home") == 0) { | |
3521 | cred->min_ul_bandwidth_home = atoi(value); | |
3522 | return 0; | |
3523 | } | |
3524 | ||
3525 | if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) { | |
3526 | cred->min_dl_bandwidth_roaming = atoi(value); | |
3527 | return 0; | |
3528 | } | |
3529 | ||
3530 | if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) { | |
3531 | cred->min_ul_bandwidth_roaming = atoi(value); | |
3532 | return 0; | |
3533 | } | |
3534 | ||
a45b2dc5 JM |
3535 | if (os_strcmp(var, "max_bss_load") == 0) { |
3536 | cred->max_bss_load = atoi(value); | |
3537 | return 0; | |
3538 | } | |
3539 | ||
33fb8c52 JM |
3540 | if (os_strcmp(var, "req_conn_capab") == 0) |
3541 | return wpa_config_set_cred_req_conn_capab(cred, value); | |
3542 | ||
cf6d08a6 JM |
3543 | if (os_strcmp(var, "ocsp") == 0) { |
3544 | cred->ocsp = atoi(value); | |
3545 | return 0; | |
3546 | } | |
3547 | ||
13f6a07e NJ |
3548 | if (os_strcmp(var, "sim_num") == 0) { |
3549 | cred->sim_num = atoi(value); | |
3550 | return 0; | |
3551 | } | |
3552 | ||
1bb7b8e8 | 3553 | val = wpa_config_parse_string(value, &len); |
b166cd84 JM |
3554 | if (val == NULL || |
3555 | (os_strcmp(var, "excluded_ssid") != 0 && | |
3556 | os_strcmp(var, "roaming_consortium") != 0 && | |
3557 | os_strcmp(var, "required_roaming_consortium") != 0 && | |
3558 | has_newline(val))) { | |
7d86e537 JM |
3559 | wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string " |
3560 | "value '%s'.", line, var, value); | |
b166cd84 | 3561 | os_free(val); |
1bb7b8e8 | 3562 | return -1; |
7d86e537 | 3563 | } |
1bb7b8e8 JM |
3564 | |
3565 | if (os_strcmp(var, "realm") == 0) { | |
3566 | os_free(cred->realm); | |
3567 | cred->realm = val; | |
3568 | return 0; | |
3569 | } | |
3570 | ||
3571 | if (os_strcmp(var, "username") == 0) { | |
19c48da0 | 3572 | str_clear_free(cred->username); |
1bb7b8e8 JM |
3573 | cred->username = val; |
3574 | return 0; | |
3575 | } | |
3576 | ||
3577 | if (os_strcmp(var, "password") == 0) { | |
19c48da0 | 3578 | str_clear_free(cred->password); |
1bb7b8e8 | 3579 | cred->password = val; |
02af9c90 | 3580 | cred->ext_password = 0; |
1bb7b8e8 JM |
3581 | return 0; |
3582 | } | |
3583 | ||
3584 | if (os_strcmp(var, "ca_cert") == 0) { | |
3585 | os_free(cred->ca_cert); | |
3586 | cred->ca_cert = val; | |
3587 | return 0; | |
3588 | } | |
3589 | ||
11e4f46a JM |
3590 | if (os_strcmp(var, "client_cert") == 0) { |
3591 | os_free(cred->client_cert); | |
3592 | cred->client_cert = val; | |
3593 | return 0; | |
3594 | } | |
3595 | ||
3596 | if (os_strcmp(var, "private_key") == 0) { | |
3597 | os_free(cred->private_key); | |
3598 | cred->private_key = val; | |
3599 | return 0; | |
3600 | } | |
3601 | ||
3602 | if (os_strcmp(var, "private_key_passwd") == 0) { | |
19c48da0 | 3603 | str_clear_free(cred->private_key_passwd); |
11e4f46a JM |
3604 | cred->private_key_passwd = val; |
3605 | return 0; | |
3606 | } | |
3607 | ||
1bb7b8e8 JM |
3608 | if (os_strcmp(var, "imsi") == 0) { |
3609 | os_free(cred->imsi); | |
3610 | cred->imsi = val; | |
3611 | return 0; | |
3612 | } | |
3613 | ||
3614 | if (os_strcmp(var, "milenage") == 0) { | |
19c48da0 | 3615 | str_clear_free(cred->milenage); |
1bb7b8e8 JM |
3616 | cred->milenage = val; |
3617 | return 0; | |
3618 | } | |
3619 | ||
ac1bc549 JM |
3620 | if (os_strcmp(var, "domain_suffix_match") == 0) { |
3621 | os_free(cred->domain_suffix_match); | |
3622 | cred->domain_suffix_match = val; | |
3623 | return 0; | |
3624 | } | |
3625 | ||
1bb7b8e8 | 3626 | if (os_strcmp(var, "domain") == 0) { |
463c8ffb JM |
3627 | char **new_domain; |
3628 | new_domain = os_realloc_array(cred->domain, | |
3629 | cred->num_domain + 1, | |
3630 | sizeof(char *)); | |
3631 | if (new_domain == NULL) { | |
3632 | os_free(val); | |
3633 | return -1; | |
3634 | } | |
3635 | new_domain[cred->num_domain++] = val; | |
3636 | cred->domain = new_domain; | |
1bb7b8e8 JM |
3637 | return 0; |
3638 | } | |
3639 | ||
8ca93c59 JM |
3640 | if (os_strcmp(var, "phase1") == 0) { |
3641 | os_free(cred->phase1); | |
3642 | cred->phase1 = val; | |
3643 | return 0; | |
3644 | } | |
3645 | ||
3646 | if (os_strcmp(var, "phase2") == 0) { | |
3647 | os_free(cred->phase2); | |
3648 | cred->phase2 = val; | |
3649 | return 0; | |
3650 | } | |
3651 | ||
955567bc JM |
3652 | if (os_strcmp(var, "roaming_consortium") == 0) { |
3653 | if (len < 3 || len > sizeof(cred->roaming_consortium)) { | |
3654 | wpa_printf(MSG_ERROR, "Line %d: invalid " | |
3655 | "roaming_consortium length %d (3..15 " | |
3656 | "expected)", line, (int) len); | |
3657 | os_free(val); | |
3658 | return -1; | |
3659 | } | |
3660 | os_memcpy(cred->roaming_consortium, val, len); | |
3661 | cred->roaming_consortium_len = len; | |
3662 | os_free(val); | |
3663 | return 0; | |
3664 | } | |
3665 | ||
f47c1452 JM |
3666 | if (os_strcmp(var, "required_roaming_consortium") == 0) { |
3667 | if (len < 3 || len > sizeof(cred->required_roaming_consortium)) | |
3668 | { | |
3669 | wpa_printf(MSG_ERROR, "Line %d: invalid " | |
3670 | "required_roaming_consortium length %d " | |
3671 | "(3..15 expected)", line, (int) len); | |
3672 | os_free(val); | |
3673 | return -1; | |
3674 | } | |
3675 | os_memcpy(cred->required_roaming_consortium, val, len); | |
3676 | cred->required_roaming_consortium_len = len; | |
3677 | os_free(val); | |
3678 | return 0; | |
3679 | } | |
3680 | ||
909a948b JM |
3681 | if (os_strcmp(var, "roaming_consortiums") == 0) { |
3682 | res = wpa_config_set_cred_roaming_consortiums(cred, val); | |
3683 | if (res < 0) | |
3684 | wpa_printf(MSG_ERROR, | |
3685 | "Line %d: invalid roaming_consortiums", | |
3686 | line); | |
3687 | os_free(val); | |
3688 | return res; | |
3689 | } | |
3690 | ||
dbea8ac7 JM |
3691 | if (os_strcmp(var, "excluded_ssid") == 0) { |
3692 | struct excluded_ssid *e; | |
3693 | ||
eaa8eefe | 3694 | if (len > SSID_MAX_LEN) { |
dbea8ac7 JM |
3695 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
3696 | "excluded_ssid length %d", line, (int) len); | |
3697 | os_free(val); | |
3698 | return -1; | |
3699 | } | |
3700 | ||
3701 | e = os_realloc_array(cred->excluded_ssid, | |
3702 | cred->num_excluded_ssid + 1, | |
3703 | sizeof(struct excluded_ssid)); | |
3704 | if (e == NULL) { | |
3705 | os_free(val); | |
3706 | return -1; | |
3707 | } | |
3708 | cred->excluded_ssid = e; | |
3709 | ||
3710 | e = &cred->excluded_ssid[cred->num_excluded_ssid++]; | |
3711 | os_memcpy(e->ssid, val, len); | |
3712 | e->ssid_len = len; | |
3713 | ||
3714 | os_free(val); | |
3715 | ||
3716 | return 0; | |
3717 | } | |
3718 | ||
bc00053c JM |
3719 | if (os_strcmp(var, "roaming_partner") == 0) { |
3720 | struct roaming_partner *p; | |
3721 | char *pos; | |
3722 | ||
3723 | p = os_realloc_array(cred->roaming_partner, | |
3724 | cred->num_roaming_partner + 1, | |
3725 | sizeof(struct roaming_partner)); | |
3726 | if (p == NULL) { | |
3727 | os_free(val); | |
3728 | return -1; | |
3729 | } | |
3730 | cred->roaming_partner = p; | |
3731 | ||
3732 | p = &cred->roaming_partner[cred->num_roaming_partner]; | |
3733 | ||
3734 | pos = os_strchr(val, ','); | |
3735 | if (pos == NULL) { | |
3736 | os_free(val); | |
3737 | return -1; | |
3738 | } | |
3739 | *pos++ = '\0'; | |
3740 | if (pos - val - 1 >= (int) sizeof(p->fqdn)) { | |
3741 | os_free(val); | |
3742 | return -1; | |
3743 | } | |
3744 | os_memcpy(p->fqdn, val, pos - val); | |
3745 | ||
3746 | p->exact_match = atoi(pos); | |
3747 | ||
3748 | pos = os_strchr(pos, ','); | |
3749 | if (pos == NULL) { | |
3750 | os_free(val); | |
3751 | return -1; | |
3752 | } | |
3753 | *pos++ = '\0'; | |
3754 | ||
3755 | p->priority = atoi(pos); | |
3756 | ||
3757 | pos = os_strchr(pos, ','); | |
3758 | if (pos == NULL) { | |
3759 | os_free(val); | |
3760 | return -1; | |
3761 | } | |
3762 | *pos++ = '\0'; | |
3763 | ||
3764 | if (os_strlen(pos) >= sizeof(p->country)) { | |
3765 | os_free(val); | |
3766 | return -1; | |
3767 | } | |
3768 | os_memcpy(p->country, pos, os_strlen(pos) + 1); | |
3769 | ||
3770 | cred->num_roaming_partner++; | |
3771 | os_free(val); | |
3772 | ||
3773 | return 0; | |
3774 | } | |
3775 | ||
aa26ba68 JM |
3776 | if (os_strcmp(var, "provisioning_sp") == 0) { |
3777 | os_free(cred->provisioning_sp); | |
3778 | cred->provisioning_sp = val; | |
3779 | return 0; | |
3780 | } | |
3781 | ||
1bb7b8e8 JM |
3782 | if (line) { |
3783 | wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.", | |
3784 | line, var); | |
3785 | } | |
3786 | ||
f4b2d69b JM |
3787 | os_free(val); |
3788 | ||
1bb7b8e8 JM |
3789 | return -1; |
3790 | } | |
3791 | ||
3792 | ||
8f03ac90 | 3793 | static char * alloc_int_str(int val) |
c880ab87 | 3794 | { |
1d399771 | 3795 | const unsigned int bufsize = 20; |
c880ab87 | 3796 | char *buf; |
1d399771 | 3797 | int res; |
c880ab87 | 3798 | |
1d399771 | 3799 | buf = os_malloc(bufsize); |
c880ab87 JM |
3800 | if (buf == NULL) |
3801 | return NULL; | |
1d399771 JM |
3802 | res = os_snprintf(buf, bufsize, "%d", val); |
3803 | if (os_snprintf_error(bufsize, res)) { | |
3804 | os_free(buf); | |
3805 | buf = NULL; | |
3806 | } | |
c880ab87 JM |
3807 | return buf; |
3808 | } | |
3809 | ||
3810 | ||
8f03ac90 | 3811 | static char * alloc_strdup(const char *str) |
c880ab87 JM |
3812 | { |
3813 | if (str == NULL) | |
3814 | return NULL; | |
3815 | return os_strdup(str); | |
3816 | } | |
3817 | ||
3818 | ||
3819 | char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var) | |
3820 | { | |
3821 | if (os_strcmp(var, "temporary") == 0) | |
3822 | return alloc_int_str(cred->temporary); | |
3823 | ||
3824 | if (os_strcmp(var, "priority") == 0) | |
3825 | return alloc_int_str(cred->priority); | |
3826 | ||
3827 | if (os_strcmp(var, "sp_priority") == 0) | |
3828 | return alloc_int_str(cred->sp_priority); | |
3829 | ||
3830 | if (os_strcmp(var, "pcsc") == 0) | |
3831 | return alloc_int_str(cred->pcsc); | |
3832 | ||
3833 | if (os_strcmp(var, "eap") == 0) { | |
3834 | if (!cred->eap_method) | |
3835 | return NULL; | |
3836 | return alloc_strdup(eap_get_name(cred->eap_method[0].vendor, | |
3837 | cred->eap_method[0].method)); | |
3838 | } | |
3839 | ||
3840 | if (os_strcmp(var, "update_identifier") == 0) | |
3841 | return alloc_int_str(cred->update_identifier); | |
3842 | ||
3843 | if (os_strcmp(var, "min_dl_bandwidth_home") == 0) | |
3844 | return alloc_int_str(cred->min_dl_bandwidth_home); | |
3845 | ||
3846 | if (os_strcmp(var, "min_ul_bandwidth_home") == 0) | |
3847 | return alloc_int_str(cred->min_ul_bandwidth_home); | |
3848 | ||
3849 | if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) | |
3850 | return alloc_int_str(cred->min_dl_bandwidth_roaming); | |
3851 | ||
3852 | if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) | |
3853 | return alloc_int_str(cred->min_ul_bandwidth_roaming); | |
3854 | ||
3855 | if (os_strcmp(var, "max_bss_load") == 0) | |
3856 | return alloc_int_str(cred->max_bss_load); | |
3857 | ||
3858 | if (os_strcmp(var, "req_conn_capab") == 0) { | |
3859 | unsigned int i; | |
3860 | char *buf, *end, *pos; | |
3861 | int ret; | |
3862 | ||
3863 | if (!cred->num_req_conn_capab) | |
3864 | return NULL; | |
3865 | ||
3866 | buf = os_malloc(4000); | |
3867 | if (buf == NULL) | |
3868 | return NULL; | |
3869 | pos = buf; | |
3870 | end = pos + 4000; | |
3871 | for (i = 0; i < cred->num_req_conn_capab; i++) { | |
3872 | int *ports; | |
3873 | ||
3874 | ret = os_snprintf(pos, end - pos, "%s%u", | |
3875 | i > 0 ? "\n" : "", | |
3876 | cred->req_conn_capab_proto[i]); | |
d85e1fc8 | 3877 | if (os_snprintf_error(end - pos, ret)) |
c880ab87 JM |
3878 | return buf; |
3879 | pos += ret; | |
3880 | ||
3881 | ports = cred->req_conn_capab_port[i]; | |
3882 | if (ports) { | |
3883 | int j; | |
3884 | for (j = 0; ports[j] != -1; j++) { | |
3885 | ret = os_snprintf(pos, end - pos, | |
3886 | "%s%d", | |
3887 | j > 0 ? "," : ":", | |
3888 | ports[j]); | |
d85e1fc8 | 3889 | if (os_snprintf_error(end - pos, ret)) |
c880ab87 JM |
3890 | return buf; |
3891 | pos += ret; | |
3892 | } | |
3893 | } | |
3894 | } | |
3895 | ||
3896 | return buf; | |
3897 | } | |
3898 | ||
3899 | if (os_strcmp(var, "ocsp") == 0) | |
3900 | return alloc_int_str(cred->ocsp); | |
3901 | ||
3902 | if (os_strcmp(var, "realm") == 0) | |
3903 | return alloc_strdup(cred->realm); | |
3904 | ||
3905 | if (os_strcmp(var, "username") == 0) | |
3906 | return alloc_strdup(cred->username); | |
3907 | ||
3908 | if (os_strcmp(var, "password") == 0) { | |
3909 | if (!cred->password) | |
3910 | return NULL; | |
3911 | return alloc_strdup("*"); | |
3912 | } | |
3913 | ||
3914 | if (os_strcmp(var, "ca_cert") == 0) | |
3915 | return alloc_strdup(cred->ca_cert); | |
3916 | ||
3917 | if (os_strcmp(var, "client_cert") == 0) | |
3918 | return alloc_strdup(cred->client_cert); | |
3919 | ||
3920 | if (os_strcmp(var, "private_key") == 0) | |
3921 | return alloc_strdup(cred->private_key); | |
3922 | ||
3923 | if (os_strcmp(var, "private_key_passwd") == 0) { | |
3924 | if (!cred->private_key_passwd) | |
3925 | return NULL; | |
3926 | return alloc_strdup("*"); | |
3927 | } | |
3928 | ||
3929 | if (os_strcmp(var, "imsi") == 0) | |
3930 | return alloc_strdup(cred->imsi); | |
3931 | ||
3932 | if (os_strcmp(var, "milenage") == 0) { | |
3933 | if (!(cred->milenage)) | |
3934 | return NULL; | |
3935 | return alloc_strdup("*"); | |
3936 | } | |
3937 | ||
3938 | if (os_strcmp(var, "domain_suffix_match") == 0) | |
3939 | return alloc_strdup(cred->domain_suffix_match); | |
3940 | ||
3941 | if (os_strcmp(var, "domain") == 0) { | |
3942 | unsigned int i; | |
3943 | char *buf, *end, *pos; | |
3944 | int ret; | |
3945 | ||
3946 | if (!cred->num_domain) | |
3947 | return NULL; | |
3948 | ||
3949 | buf = os_malloc(4000); | |
3950 | if (buf == NULL) | |
3951 | return NULL; | |
3952 | pos = buf; | |
3953 | end = pos + 4000; | |
3954 | ||
3955 | for (i = 0; i < cred->num_domain; i++) { | |
3956 | ret = os_snprintf(pos, end - pos, "%s%s", | |
3957 | i > 0 ? "\n" : "", cred->domain[i]); | |
d85e1fc8 | 3958 | if (os_snprintf_error(end - pos, ret)) |
c880ab87 JM |
3959 | return buf; |
3960 | pos += ret; | |
3961 | } | |
3962 | ||
3963 | return buf; | |
3964 | } | |
3965 | ||
3966 | if (os_strcmp(var, "phase1") == 0) | |
3967 | return alloc_strdup(cred->phase1); | |
3968 | ||
3969 | if (os_strcmp(var, "phase2") == 0) | |
3970 | return alloc_strdup(cred->phase2); | |
3971 | ||
3972 | if (os_strcmp(var, "roaming_consortium") == 0) { | |
3973 | size_t buflen; | |
3974 | char *buf; | |
3975 | ||
3976 | if (!cred->roaming_consortium_len) | |
3977 | return NULL; | |
3978 | buflen = cred->roaming_consortium_len * 2 + 1; | |
3979 | buf = os_malloc(buflen); | |
3980 | if (buf == NULL) | |
3981 | return NULL; | |
3982 | wpa_snprintf_hex(buf, buflen, cred->roaming_consortium, | |
3983 | cred->roaming_consortium_len); | |
3984 | return buf; | |
3985 | } | |
3986 | ||
3987 | if (os_strcmp(var, "required_roaming_consortium") == 0) { | |
3988 | size_t buflen; | |
3989 | char *buf; | |
3990 | ||
3991 | if (!cred->required_roaming_consortium_len) | |
3992 | return NULL; | |
3993 | buflen = cred->required_roaming_consortium_len * 2 + 1; | |
3994 | buf = os_malloc(buflen); | |
3995 | if (buf == NULL) | |
3996 | return NULL; | |
3997 | wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium, | |
3998 | cred->required_roaming_consortium_len); | |
3999 | return buf; | |
4000 | } | |
4001 | ||
909a948b JM |
4002 | if (os_strcmp(var, "roaming_consortiums") == 0) { |
4003 | size_t buflen; | |
4004 | char *buf, *pos; | |
4005 | size_t i; | |
4006 | ||
4007 | if (!cred->num_roaming_consortiums) | |
4008 | return NULL; | |
4009 | buflen = cred->num_roaming_consortiums * | |
4010 | MAX_ROAMING_CONS_OI_LEN * 2 + 1; | |
4011 | buf = os_malloc(buflen); | |
4012 | if (!buf) | |
4013 | return NULL; | |
4014 | pos = buf; | |
4015 | for (i = 0; i < cred->num_roaming_consortiums; i++) { | |
4016 | if (i > 0) | |
4017 | *pos++ = ','; | |
4018 | pos += wpa_snprintf_hex( | |
4019 | pos, buf + buflen - pos, | |
4020 | cred->roaming_consortiums[i], | |
4021 | cred->roaming_consortiums_len[i]); | |
4022 | } | |
4023 | *pos = '\0'; | |
4024 | return buf; | |
4025 | } | |
4026 | ||
c880ab87 JM |
4027 | if (os_strcmp(var, "excluded_ssid") == 0) { |
4028 | unsigned int i; | |
4029 | char *buf, *end, *pos; | |
4030 | ||
4031 | if (!cred->num_excluded_ssid) | |
4032 | return NULL; | |
4033 | ||
4034 | buf = os_malloc(4000); | |
4035 | if (buf == NULL) | |
4036 | return NULL; | |
4037 | pos = buf; | |
4038 | end = pos + 4000; | |
4039 | ||
4040 | for (i = 0; i < cred->num_excluded_ssid; i++) { | |
4041 | struct excluded_ssid *e; | |
4042 | int ret; | |
4043 | ||
4044 | e = &cred->excluded_ssid[i]; | |
4045 | ret = os_snprintf(pos, end - pos, "%s%s", | |
4046 | i > 0 ? "\n" : "", | |
4047 | wpa_ssid_txt(e->ssid, e->ssid_len)); | |
d85e1fc8 | 4048 | if (os_snprintf_error(end - pos, ret)) |
c880ab87 JM |
4049 | return buf; |
4050 | pos += ret; | |
4051 | } | |
4052 | ||
4053 | return buf; | |
4054 | } | |
4055 | ||
4056 | if (os_strcmp(var, "roaming_partner") == 0) { | |
4057 | unsigned int i; | |
4058 | char *buf, *end, *pos; | |
4059 | ||
4060 | if (!cred->num_roaming_partner) | |
4061 | return NULL; | |
4062 | ||
4063 | buf = os_malloc(4000); | |
4064 | if (buf == NULL) | |
4065 | return NULL; | |
4066 | pos = buf; | |
4067 | end = pos + 4000; | |
4068 | ||
4069 | for (i = 0; i < cred->num_roaming_partner; i++) { | |
4070 | struct roaming_partner *p; | |
4071 | int ret; | |
4072 | ||
4073 | p = &cred->roaming_partner[i]; | |
4074 | ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s", | |
4075 | i > 0 ? "\n" : "", | |
4076 | p->fqdn, p->exact_match, p->priority, | |
4077 | p->country); | |
d85e1fc8 | 4078 | if (os_snprintf_error(end - pos, ret)) |
c880ab87 JM |
4079 | return buf; |
4080 | pos += ret; | |
4081 | } | |
4082 | ||
4083 | return buf; | |
4084 | } | |
4085 | ||
4086 | if (os_strcmp(var, "provisioning_sp") == 0) | |
4087 | return alloc_strdup(cred->provisioning_sp); | |
4088 | ||
4089 | return NULL; | |
4090 | } | |
4091 | ||
4092 | ||
d94c9ee6 JM |
4093 | struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id) |
4094 | { | |
4095 | struct wpa_cred *cred; | |
4096 | ||
4097 | cred = config->cred; | |
4098 | while (cred) { | |
4099 | if (id == cred->id) | |
4100 | break; | |
4101 | cred = cred->next; | |
4102 | } | |
4103 | ||
4104 | return cred; | |
4105 | } | |
4106 | ||
4107 | ||
4108 | struct wpa_cred * wpa_config_add_cred(struct wpa_config *config) | |
4109 | { | |
4110 | int id; | |
4111 | struct wpa_cred *cred, *last = NULL; | |
4112 | ||
4113 | id = -1; | |
4114 | cred = config->cred; | |
4115 | while (cred) { | |
4116 | if (cred->id > id) | |
4117 | id = cred->id; | |
4118 | last = cred; | |
4119 | cred = cred->next; | |
4120 | } | |
4121 | id++; | |
4122 | ||
4123 | cred = os_zalloc(sizeof(*cred)); | |
4124 | if (cred == NULL) | |
4125 | return NULL; | |
4126 | cred->id = id; | |
13f6a07e | 4127 | cred->sim_num = DEFAULT_USER_SELECTED_SIM; |
d94c9ee6 JM |
4128 | if (last) |
4129 | last->next = cred; | |
4130 | else | |
4131 | config->cred = cred; | |
4132 | ||
4133 | return cred; | |
4134 | } | |
4135 | ||
4136 | ||
4137 | int wpa_config_remove_cred(struct wpa_config *config, int id) | |
4138 | { | |
4139 | struct wpa_cred *cred, *prev = NULL; | |
4140 | ||
4141 | cred = config->cred; | |
4142 | while (cred) { | |
4143 | if (id == cred->id) | |
4144 | break; | |
4145 | prev = cred; | |
4146 | cred = cred->next; | |
4147 | } | |
4148 | ||
4149 | if (cred == NULL) | |
4150 | return -1; | |
4151 | ||
4152 | if (prev) | |
4153 | prev->next = cred->next; | |
4154 | else | |
4155 | config->cred = cred->next; | |
4156 | ||
4157 | wpa_config_free_cred(cred); | |
4158 | return 0; | |
4159 | } | |
4160 | ||
4161 | ||
6fc6879b JM |
4162 | #ifndef CONFIG_NO_CONFIG_BLOBS |
4163 | /** | |
4164 | * wpa_config_get_blob - Get a named configuration blob | |
4165 | * @config: Configuration data from wpa_config_read() | |
4166 | * @name: Name of the blob | |
4167 | * Returns: Pointer to blob data or %NULL if not found | |
4168 | */ | |
4169 | const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config, | |
4170 | const char *name) | |
4171 | { | |
4172 | struct wpa_config_blob *blob = config->blobs; | |
4173 | ||
4174 | while (blob) { | |
4175 | if (os_strcmp(blob->name, name) == 0) | |
4176 | return blob; | |
4177 | blob = blob->next; | |
4178 | } | |
4179 | return NULL; | |
4180 | } | |
4181 | ||
4182 | ||
4183 | /** | |
4184 | * wpa_config_set_blob - Set or add a named configuration blob | |
4185 | * @config: Configuration data from wpa_config_read() | |
4186 | * @blob: New value for the blob | |
4187 | * | |
4188 | * Adds a new configuration blob or replaces the current value of an existing | |
4189 | * blob. | |
4190 | */ | |
4191 | void wpa_config_set_blob(struct wpa_config *config, | |
4192 | struct wpa_config_blob *blob) | |
4193 | { | |
4194 | wpa_config_remove_blob(config, blob->name); | |
4195 | blob->next = config->blobs; | |
4196 | config->blobs = blob; | |
4197 | } | |
4198 | ||
4199 | ||
4200 | /** | |
4201 | * wpa_config_free_blob - Free blob data | |
4202 | * @blob: Pointer to blob to be freed | |
4203 | */ | |
4204 | void wpa_config_free_blob(struct wpa_config_blob *blob) | |
4205 | { | |
4206 | if (blob) { | |
4207 | os_free(blob->name); | |
19c48da0 | 4208 | bin_clear_free(blob->data, blob->len); |
6fc6879b JM |
4209 | os_free(blob); |
4210 | } | |
4211 | } | |
4212 | ||
4213 | ||
4214 | /** | |
4215 | * wpa_config_remove_blob - Remove a named configuration blob | |
4216 | * @config: Configuration data from wpa_config_read() | |
4217 | * @name: Name of the blob to remove | |
4218 | * Returns: 0 if blob was removed or -1 if blob was not found | |
4219 | */ | |
4220 | int wpa_config_remove_blob(struct wpa_config *config, const char *name) | |
4221 | { | |
4222 | struct wpa_config_blob *pos = config->blobs, *prev = NULL; | |
4223 | ||
4224 | while (pos) { | |
4225 | if (os_strcmp(pos->name, name) == 0) { | |
4226 | if (prev) | |
4227 | prev->next = pos->next; | |
4228 | else | |
4229 | config->blobs = pos->next; | |
4230 | wpa_config_free_blob(pos); | |
4231 | return 0; | |
4232 | } | |
4233 | prev = pos; | |
4234 | pos = pos->next; | |
4235 | } | |
4236 | ||
4237 | return -1; | |
4238 | } | |
4239 | #endif /* CONFIG_NO_CONFIG_BLOBS */ | |
4240 | ||
4241 | ||
4242 | /** | |
4243 | * wpa_config_alloc_empty - Allocate an empty configuration | |
4244 | * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain | |
4245 | * socket | |
4246 | * @driver_param: Driver parameters | |
4247 | * Returns: Pointer to allocated configuration data or %NULL on failure | |
4248 | */ | |
4249 | struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface, | |
4250 | const char *driver_param) | |
4251 | { | |
4252 | struct wpa_config *config; | |
c26effe1 YD |
4253 | const int aCWmin = 4, aCWmax = 10; |
4254 | const struct hostapd_wmm_ac_params ac_bk = | |
4255 | { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */ | |
4256 | const struct hostapd_wmm_ac_params ac_be = | |
4257 | { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */ | |
4258 | const struct hostapd_wmm_ac_params ac_vi = /* video traffic */ | |
623ecdd5 | 4259 | { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 }; |
c26effe1 | 4260 | const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */ |
623ecdd5 | 4261 | { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 }; |
6fc6879b JM |
4262 | |
4263 | config = os_zalloc(sizeof(*config)); | |
4264 | if (config == NULL) | |
4265 | return NULL; | |
4266 | config->eapol_version = DEFAULT_EAPOL_VERSION; | |
4267 | config->ap_scan = DEFAULT_AP_SCAN; | |
e45e8989 | 4268 | config->user_mpm = DEFAULT_USER_MPM; |
4b409368 | 4269 | config->max_peer_links = DEFAULT_MAX_PEER_LINKS; |
5a2a6de6 | 4270 | config->mesh_max_inactivity = DEFAULT_MESH_MAX_INACTIVITY; |
ecd40fef MH |
4271 | config->dot11RSNASAERetransPeriod = |
4272 | DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD; | |
6fc6879b | 4273 | config->fast_reauth = DEFAULT_FAST_REAUTH; |
e3768e7c | 4274 | config->p2p_go_intent = DEFAULT_P2P_GO_INTENT; |
0f66abd2 | 4275 | config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS; |
1a471ff0 | 4276 | config->p2p_go_freq_change_policy = DEFAULT_P2P_GO_FREQ_MOVE; |
462a7439 | 4277 | config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY; |
e3bd6e9d | 4278 | config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN; |
0b8bcaa5 | 4279 | config->p2p_go_ctwindow = DEFAULT_P2P_GO_CTWINDOW; |
c9c38b09 | 4280 | config->bss_max_count = DEFAULT_BSS_MAX_COUNT; |
78633c37 SL |
4281 | config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE; |
4282 | config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT; | |
dae608d5 | 4283 | config->max_num_sta = DEFAULT_MAX_NUM_STA; |
19e20c14 | 4284 | config->ap_isolate = DEFAULT_AP_ISOLATE; |
11540c0b | 4285 | config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE; |
6124e858 | 4286 | config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ; |
c26effe1 YD |
4287 | config->wmm_ac_params[0] = ac_be; |
4288 | config->wmm_ac_params[1] = ac_bk; | |
4289 | config->wmm_ac_params[2] = ac_vi; | |
4290 | config->wmm_ac_params[3] = ac_vo; | |
d3b20469 | 4291 | config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY; |
c267753b | 4292 | config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME; |
b41f2684 | 4293 | config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD; |
483dd6a5 | 4294 | config->cert_in_cb = DEFAULT_CERT_IN_CB; |
73ed03f3 | 4295 | config->wpa_rsc_relaxation = DEFAULT_WPA_RSC_RELAXATION; |
b17b7a8e | 4296 | config->extended_key_id = DEFAULT_EXTENDED_KEY_ID; |
6fc6879b | 4297 | |
c5d193d7 DS |
4298 | #ifdef CONFIG_MBO |
4299 | config->mbo_cell_capa = DEFAULT_MBO_CELL_CAPA; | |
af8bc24d KV |
4300 | config->disassoc_imminent_rssi_threshold = |
4301 | DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD; | |
332aadb8 | 4302 | config->oce = DEFAULT_OCE_SUPPORT; |
c5d193d7 DS |
4303 | #endif /* CONFIG_MBO */ |
4304 | ||
6fc6879b JM |
4305 | if (ctrl_interface) |
4306 | config->ctrl_interface = os_strdup(ctrl_interface); | |
4307 | if (driver_param) | |
4308 | config->driver_param = os_strdup(driver_param); | |
1d9d21f3 | 4309 | config->gas_rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME; |
6fc6879b JM |
4310 | |
4311 | return config; | |
4312 | } | |
4313 | ||
4314 | ||
4315 | #ifndef CONFIG_NO_STDOUT_DEBUG | |
4316 | /** | |
4317 | * wpa_config_debug_dump_networks - Debug dump of configured networks | |
4318 | * @config: Configuration data from wpa_config_read() | |
4319 | */ | |
4320 | void wpa_config_debug_dump_networks(struct wpa_config *config) | |
4321 | { | |
d2d16e31 | 4322 | size_t prio; |
6fc6879b JM |
4323 | struct wpa_ssid *ssid; |
4324 | ||
4325 | for (prio = 0; prio < config->num_prio; prio++) { | |
4326 | ssid = config->pssid[prio]; | |
4327 | wpa_printf(MSG_DEBUG, "Priority group %d", | |
4328 | ssid->priority); | |
4329 | while (ssid) { | |
4330 | wpa_printf(MSG_DEBUG, " id=%d ssid='%s'", | |
4331 | ssid->id, | |
4332 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
4333 | ssid = ssid->pnext; | |
4334 | } | |
4335 | } | |
4336 | } | |
4337 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
121adf9c JM |
4338 | |
4339 | ||
4340 | struct global_parse_data { | |
4341 | char *name; | |
4342 | int (*parser)(const struct global_parse_data *data, | |
4343 | struct wpa_config *config, int line, const char *value); | |
10263dc2 OO |
4344 | int (*get)(const char *name, struct wpa_config *config, long offset, |
4345 | char *buf, size_t buflen, int pretty_print); | |
121adf9c | 4346 | void *param1, *param2, *param3; |
1d47214a | 4347 | unsigned int changed_flag; |
121adf9c JM |
4348 | }; |
4349 | ||
4350 | ||
4351 | static int wpa_global_config_parse_int(const struct global_parse_data *data, | |
4352 | struct wpa_config *config, int line, | |
4353 | const char *pos) | |
4354 | { | |
eae3a584 JB |
4355 | int val, *dst; |
4356 | char *end; | |
4357 | ||
121adf9c | 4358 | dst = (int *) (((u8 *) config) + (long) data->param1); |
eae3a584 JB |
4359 | val = strtol(pos, &end, 0); |
4360 | if (*end) { | |
4361 | wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"", | |
4362 | line, pos); | |
4363 | return -1; | |
4364 | } | |
4365 | *dst = val; | |
4366 | ||
121adf9c JM |
4367 | wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst); |
4368 | ||
4369 | if (data->param2 && *dst < (long) data->param2) { | |
4370 | wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d " | |
4371 | "min_value=%ld)", line, data->name, *dst, | |
4372 | (long) data->param2); | |
4373 | *dst = (long) data->param2; | |
4374 | return -1; | |
4375 | } | |
4376 | ||
4377 | if (data->param3 && *dst > (long) data->param3) { | |
4378 | wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d " | |
4379 | "max_value=%ld)", line, data->name, *dst, | |
4380 | (long) data->param3); | |
4381 | *dst = (long) data->param3; | |
4382 | return -1; | |
4383 | } | |
4384 | ||
4385 | return 0; | |
4386 | } | |
4387 | ||
4388 | ||
4389 | static int wpa_global_config_parse_str(const struct global_parse_data *data, | |
4390 | struct wpa_config *config, int line, | |
4391 | const char *pos) | |
4392 | { | |
4393 | size_t len; | |
4394 | char **dst, *tmp; | |
4395 | ||
4396 | len = os_strlen(pos); | |
4397 | if (data->param2 && len < (size_t) data->param2) { | |
4398 | wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu " | |
4399 | "min_len=%ld)", line, data->name, | |
4400 | (unsigned long) len, (long) data->param2); | |
4401 | return -1; | |
4402 | } | |
4403 | ||
4404 | if (data->param3 && len > (size_t) data->param3) { | |
4405 | wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu " | |
4406 | "max_len=%ld)", line, data->name, | |
4407 | (unsigned long) len, (long) data->param3); | |
4408 | return -1; | |
4409 | } | |
4410 | ||
2a3f5650 JM |
4411 | if (has_newline(pos)) { |
4412 | wpa_printf(MSG_ERROR, "Line %d: invalid %s value with newline", | |
4413 | line, data->name); | |
4414 | return -1; | |
4415 | } | |
4416 | ||
121adf9c JM |
4417 | tmp = os_strdup(pos); |
4418 | if (tmp == NULL) | |
4419 | return -1; | |
4420 | ||
4421 | dst = (char **) (((u8 *) config) + (long) data->param1); | |
4422 | os_free(*dst); | |
4423 | *dst = tmp; | |
4424 | wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst); | |
4425 | ||
4426 | return 0; | |
4427 | } | |
4428 | ||
4429 | ||
31392709 HD |
4430 | static int wpa_config_process_bgscan(const struct global_parse_data *data, |
4431 | struct wpa_config *config, int line, | |
4432 | const char *pos) | |
4433 | { | |
4434 | size_t len; | |
4435 | char *tmp; | |
04c366cb | 4436 | int res; |
31392709 HD |
4437 | |
4438 | tmp = wpa_config_parse_string(pos, &len); | |
4439 | if (tmp == NULL) { | |
4440 | wpa_printf(MSG_ERROR, "Line %d: failed to parse %s", | |
4441 | line, data->name); | |
4442 | return -1; | |
4443 | } | |
4444 | ||
04c366cb EL |
4445 | res = wpa_global_config_parse_str(data, config, line, tmp); |
4446 | os_free(tmp); | |
4447 | return res; | |
31392709 HD |
4448 | } |
4449 | ||
4450 | ||
3f2c8ba6 JM |
4451 | static int wpa_global_config_parse_bin(const struct global_parse_data *data, |
4452 | struct wpa_config *config, int line, | |
4453 | const char *pos) | |
4454 | { | |
3f2c8ba6 JM |
4455 | struct wpabuf **dst, *tmp; |
4456 | ||
9d955f75 DS |
4457 | tmp = wpabuf_parse_bin(pos); |
4458 | if (!tmp) | |
3f2c8ba6 | 4459 | return -1; |
3f2c8ba6 JM |
4460 | |
4461 | dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1); | |
4462 | wpabuf_free(*dst); | |
4463 | *dst = tmp; | |
4464 | wpa_printf(MSG_DEBUG, "%s", data->name); | |
4465 | ||
4466 | return 0; | |
4467 | } | |
4468 | ||
4469 | ||
f5ffc348 BG |
4470 | static int wpa_config_process_freq_list(const struct global_parse_data *data, |
4471 | struct wpa_config *config, int line, | |
4472 | const char *value) | |
4473 | { | |
4474 | int *freqs; | |
4475 | ||
4476 | freqs = wpa_config_parse_int_array(value); | |
4477 | if (freqs == NULL) | |
4478 | return -1; | |
6668efda JM |
4479 | if (freqs[0] == 0) { |
4480 | os_free(freqs); | |
4481 | freqs = NULL; | |
4482 | } | |
f5ffc348 BG |
4483 | os_free(config->freq_list); |
4484 | config->freq_list = freqs; | |
4485 | return 0; | |
4486 | } | |
4487 | ||
4488 | ||
25ef8529 JM |
4489 | #ifdef CONFIG_P2P |
4490 | static int wpa_global_config_parse_ipv4(const struct global_parse_data *data, | |
4491 | struct wpa_config *config, int line, | |
4492 | const char *pos) | |
4493 | { | |
4494 | u32 *dst; | |
4495 | struct hostapd_ip_addr addr; | |
4496 | ||
4497 | if (hostapd_parse_ip_addr(pos, &addr) < 0) | |
4498 | return -1; | |
4499 | if (addr.af != AF_INET) | |
4500 | return -1; | |
4501 | ||
4502 | dst = (u32 *) (((u8 *) config) + (long) data->param1); | |
4503 | os_memcpy(dst, &addr.u.v4.s_addr, 4); | |
4504 | wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name, | |
4505 | WPA_GET_BE32((u8 *) dst)); | |
4506 | ||
4507 | return 0; | |
4508 | } | |
4509 | #endif /* CONFIG_P2P */ | |
4510 | ||
4511 | ||
121adf9c JM |
4512 | static int wpa_config_process_country(const struct global_parse_data *data, |
4513 | struct wpa_config *config, int line, | |
4514 | const char *pos) | |
4515 | { | |
4516 | if (!pos[0] || !pos[1]) { | |
4517 | wpa_printf(MSG_DEBUG, "Invalid country set"); | |
4518 | return -1; | |
4519 | } | |
4520 | config->country[0] = pos[0]; | |
4521 | config->country[1] = pos[1]; | |
4522 | wpa_printf(MSG_DEBUG, "country='%c%c'", | |
4523 | config->country[0], config->country[1]); | |
4524 | return 0; | |
4525 | } | |
4526 | ||
4527 | ||
4528 | static int wpa_config_process_load_dynamic_eap( | |
4529 | const struct global_parse_data *data, struct wpa_config *config, | |
4530 | int line, const char *so) | |
4531 | { | |
4532 | int ret; | |
4533 | wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so); | |
4534 | ret = eap_peer_method_load(so); | |
4535 | if (ret == -2) { | |
4536 | wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not " | |
4537 | "reloading."); | |
4538 | } else if (ret) { | |
4539 | wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP " | |
4540 | "method '%s'.", line, so); | |
4541 | return -1; | |
4542 | } | |
4543 | ||
4544 | return 0; | |
4545 | } | |
4546 | ||
4547 | ||
4548 | #ifdef CONFIG_WPS | |
4549 | ||
4550 | static int wpa_config_process_uuid(const struct global_parse_data *data, | |
4551 | struct wpa_config *config, int line, | |
4552 | const char *pos) | |
4553 | { | |
4554 | char buf[40]; | |
4555 | if (uuid_str2bin(pos, config->uuid)) { | |
4556 | wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line); | |
4557 | return -1; | |
4558 | } | |
4559 | uuid_bin2str(config->uuid, buf, sizeof(buf)); | |
4560 | wpa_printf(MSG_DEBUG, "uuid=%s", buf); | |
4561 | return 0; | |
4562 | } | |
4563 | ||
4564 | ||
2f646b6e JB |
4565 | static int wpa_config_process_device_type( |
4566 | const struct global_parse_data *data, | |
4567 | struct wpa_config *config, int line, const char *pos) | |
4568 | { | |
4569 | return wps_dev_type_str2bin(pos, config->device_type); | |
4570 | } | |
4571 | ||
4572 | ||
121adf9c JM |
4573 | static int wpa_config_process_os_version(const struct global_parse_data *data, |
4574 | struct wpa_config *config, int line, | |
4575 | const char *pos) | |
4576 | { | |
4577 | if (hexstr2bin(pos, config->os_version, 4)) { | |
4578 | wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line); | |
4579 | return -1; | |
4580 | } | |
4581 | wpa_printf(MSG_DEBUG, "os_version=%08x", | |
4582 | WPA_GET_BE32(config->os_version)); | |
4583 | return 0; | |
4584 | } | |
4585 | ||
71dd3b78 AS |
4586 | |
4587 | static int wpa_config_process_wps_vendor_ext_m1( | |
4588 | const struct global_parse_data *data, | |
4589 | struct wpa_config *config, int line, const char *pos) | |
4590 | { | |
4591 | struct wpabuf *tmp; | |
4592 | int len = os_strlen(pos) / 2; | |
4593 | u8 *p; | |
4594 | ||
4595 | if (!len) { | |
4596 | wpa_printf(MSG_ERROR, "Line %d: " | |
4597 | "invalid wps_vendor_ext_m1", line); | |
4598 | return -1; | |
4599 | } | |
4600 | ||
4601 | tmp = wpabuf_alloc(len); | |
4602 | if (tmp) { | |
4603 | p = wpabuf_put(tmp, len); | |
4604 | ||
4605 | if (hexstr2bin(pos, p, len)) { | |
4606 | wpa_printf(MSG_ERROR, "Line %d: " | |
4607 | "invalid wps_vendor_ext_m1", line); | |
4608 | wpabuf_free(tmp); | |
4609 | return -1; | |
4610 | } | |
4611 | ||
4612 | wpabuf_free(config->wps_vendor_ext_m1); | |
4613 | config->wps_vendor_ext_m1 = tmp; | |
4614 | } else { | |
4615 | wpa_printf(MSG_ERROR, "Can not allocate " | |
4616 | "memory for wps_vendor_ext_m1"); | |
4617 | return -1; | |
4618 | } | |
4619 | ||
4620 | return 0; | |
4621 | } | |
4622 | ||
121adf9c JM |
4623 | #endif /* CONFIG_WPS */ |
4624 | ||
e3768e7c JM |
4625 | #ifdef CONFIG_P2P |
4626 | static int wpa_config_process_sec_device_type( | |
4627 | const struct global_parse_data *data, | |
4628 | struct wpa_config *config, int line, const char *pos) | |
4629 | { | |
4630 | int idx; | |
4631 | ||
2f646b6e | 4632 | if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) { |
e3768e7c JM |
4633 | wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type " |
4634 | "items", line); | |
4635 | return -1; | |
4636 | } | |
4637 | ||
2f646b6e JB |
4638 | idx = config->num_sec_device_types; |
4639 | ||
4640 | if (wps_dev_type_str2bin(pos, config->sec_device_type[idx])) | |
e3768e7c | 4641 | return -1; |
2f646b6e JB |
4642 | |
4643 | config->num_sec_device_types++; | |
e3768e7c JM |
4644 | return 0; |
4645 | } | |
21d996f7 JM |
4646 | |
4647 | ||
4648 | static int wpa_config_process_p2p_pref_chan( | |
4649 | const struct global_parse_data *data, | |
4650 | struct wpa_config *config, int line, const char *pos) | |
4651 | { | |
4652 | struct p2p_channel *pref = NULL, *n; | |
d2d16e31 | 4653 | size_t num = 0; |
21d996f7 JM |
4654 | const char *pos2; |
4655 | u8 op_class, chan; | |
4656 | ||
4657 | /* format: class:chan,class:chan,... */ | |
4658 | ||
4659 | while (*pos) { | |
4660 | op_class = atoi(pos); | |
4661 | pos2 = os_strchr(pos, ':'); | |
4662 | if (pos2 == NULL) | |
4663 | goto fail; | |
4664 | pos2++; | |
4665 | chan = atoi(pos2); | |
4666 | ||
067ffa26 JM |
4667 | n = os_realloc_array(pref, num + 1, |
4668 | sizeof(struct p2p_channel)); | |
21d996f7 JM |
4669 | if (n == NULL) |
4670 | goto fail; | |
4671 | pref = n; | |
4672 | pref[num].op_class = op_class; | |
4673 | pref[num].chan = chan; | |
4674 | num++; | |
4675 | ||
4676 | pos = os_strchr(pos2, ','); | |
4677 | if (pos == NULL) | |
4678 | break; | |
4679 | pos++; | |
4680 | } | |
4681 | ||
4682 | os_free(config->p2p_pref_chan); | |
4683 | config->p2p_pref_chan = pref; | |
4684 | config->num_p2p_pref_chan = num; | |
4685 | wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs", | |
4686 | (u8 *) config->p2p_pref_chan, | |
4687 | config->num_p2p_pref_chan * sizeof(struct p2p_channel)); | |
4688 | ||
4689 | return 0; | |
4690 | ||
4691 | fail: | |
4692 | os_free(pref); | |
4693 | wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line); | |
4694 | return -1; | |
4695 | } | |
556b30da JM |
4696 | |
4697 | ||
4698 | static int wpa_config_process_p2p_no_go_freq( | |
4699 | const struct global_parse_data *data, | |
4700 | struct wpa_config *config, int line, const char *pos) | |
4701 | { | |
4702 | int ret; | |
4703 | ||
4704 | ret = freq_range_list_parse(&config->p2p_no_go_freq, pos); | |
4705 | if (ret < 0) { | |
4706 | wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line); | |
4707 | return -1; | |
4708 | } | |
4709 | ||
4710 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items", | |
4711 | config->p2p_no_go_freq.num); | |
4712 | ||
4713 | return 0; | |
4714 | } | |
4715 | ||
9359cc84 JC |
4716 | |
4717 | static int wpa_config_process_p2p_device_persistent_mac_addr( | |
4718 | const struct global_parse_data *data, | |
4719 | struct wpa_config *config, int line, const char *pos) | |
4720 | { | |
4721 | if (hwaddr_aton2(pos, config->p2p_device_persistent_mac_addr) < 0) { | |
4722 | wpa_printf(MSG_ERROR, | |
4723 | "Line %d: Invalid p2p_device_persistent_mac_addr '%s'", | |
4724 | line, pos); | |
4725 | return -1; | |
4726 | } | |
4727 | ||
4728 | return 0; | |
4729 | } | |
4730 | ||
e3768e7c JM |
4731 | #endif /* CONFIG_P2P */ |
4732 | ||
121adf9c | 4733 | |
46ee0427 JM |
4734 | static int wpa_config_process_hessid( |
4735 | const struct global_parse_data *data, | |
4736 | struct wpa_config *config, int line, const char *pos) | |
4737 | { | |
4738 | if (hwaddr_aton2(pos, config->hessid) < 0) { | |
4739 | wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'", | |
4740 | line, pos); | |
4741 | return -1; | |
4742 | } | |
4743 | ||
4744 | return 0; | |
4745 | } | |
4746 | ||
4747 | ||
625f202a JM |
4748 | static int wpa_config_process_sae_groups( |
4749 | const struct global_parse_data *data, | |
4750 | struct wpa_config *config, int line, const char *pos) | |
4751 | { | |
4752 | int *groups = wpa_config_parse_int_array(pos); | |
4753 | if (groups == NULL) { | |
4754 | wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'", | |
4755 | line, pos); | |
4756 | return -1; | |
4757 | } | |
4758 | ||
4759 | os_free(config->sae_groups); | |
4760 | config->sae_groups = groups; | |
4761 | ||
4762 | return 0; | |
4763 | } | |
4764 | ||
4765 | ||
18a2eaab JM |
4766 | static int wpa_config_process_ap_vendor_elements( |
4767 | const struct global_parse_data *data, | |
4768 | struct wpa_config *config, int line, const char *pos) | |
4769 | { | |
4770 | struct wpabuf *tmp; | |
4771 | int len = os_strlen(pos) / 2; | |
4772 | u8 *p; | |
4773 | ||
4774 | if (!len) { | |
4775 | wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements", | |
4776 | line); | |
4777 | return -1; | |
4778 | } | |
4779 | ||
4780 | tmp = wpabuf_alloc(len); | |
4781 | if (tmp) { | |
4782 | p = wpabuf_put(tmp, len); | |
4783 | ||
4784 | if (hexstr2bin(pos, p, len)) { | |
4785 | wpa_printf(MSG_ERROR, "Line %d: invalid " | |
4786 | "ap_vendor_elements", line); | |
4787 | wpabuf_free(tmp); | |
4788 | return -1; | |
4789 | } | |
4790 | ||
4791 | wpabuf_free(config->ap_vendor_elements); | |
4792 | config->ap_vendor_elements = tmp; | |
4793 | } else { | |
4794 | wpa_printf(MSG_ERROR, "Cannot allocate memory for " | |
4795 | "ap_vendor_elements"); | |
4796 | return -1; | |
4797 | } | |
4798 | ||
4799 | return 0; | |
4800 | } | |
4801 | ||
4802 | ||
298f5185 | 4803 | #ifdef CONFIG_CTRL_IFACE |
ea61aa1d JM |
4804 | static int wpa_config_process_no_ctrl_interface( |
4805 | const struct global_parse_data *data, | |
4806 | struct wpa_config *config, int line, const char *pos) | |
4807 | { | |
4808 | wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL"); | |
4809 | os_free(config->ctrl_interface); | |
4810 | config->ctrl_interface = NULL; | |
4811 | return 0; | |
4812 | } | |
298f5185 | 4813 | #endif /* CONFIG_CTRL_IFACE */ |
ea61aa1d JM |
4814 | |
4815 | ||
10263dc2 OO |
4816 | static int wpa_config_get_int(const char *name, struct wpa_config *config, |
4817 | long offset, char *buf, size_t buflen, | |
4818 | int pretty_print) | |
4819 | { | |
4820 | int *val = (int *) (((u8 *) config) + (long) offset); | |
4821 | ||
4822 | if (pretty_print) | |
4823 | return os_snprintf(buf, buflen, "%s=%d\n", name, *val); | |
4824 | return os_snprintf(buf, buflen, "%d", *val); | |
4825 | } | |
4826 | ||
4827 | ||
4828 | static int wpa_config_get_str(const char *name, struct wpa_config *config, | |
4829 | long offset, char *buf, size_t buflen, | |
4830 | int pretty_print) | |
4831 | { | |
4832 | char **val = (char **) (((u8 *) config) + (long) offset); | |
4833 | int res; | |
4834 | ||
4835 | if (pretty_print) | |
4836 | res = os_snprintf(buf, buflen, "%s=%s\n", name, | |
4837 | *val ? *val : "null"); | |
4838 | else if (!*val) | |
4839 | return -1; | |
4840 | else | |
4841 | res = os_snprintf(buf, buflen, "%s", *val); | |
4842 | if (os_snprintf_error(buflen, res)) | |
4843 | res = -1; | |
4844 | ||
4845 | return res; | |
4846 | } | |
4847 | ||
4848 | ||
5c6c315f MK |
4849 | #ifdef CONFIG_P2P |
4850 | static int wpa_config_get_ipv4(const char *name, struct wpa_config *config, | |
4851 | long offset, char *buf, size_t buflen, | |
4852 | int pretty_print) | |
4853 | { | |
4854 | void *val = ((u8 *) config) + (long) offset; | |
4855 | int res; | |
4856 | char addr[INET_ADDRSTRLEN]; | |
4857 | ||
4858 | if (!val || !inet_ntop(AF_INET, val, addr, sizeof(addr))) | |
4859 | return -1; | |
4860 | ||
4861 | if (pretty_print) | |
4862 | res = os_snprintf(buf, buflen, "%s=%s\n", name, addr); | |
4863 | else | |
4864 | res = os_snprintf(buf, buflen, "%s", addr); | |
4865 | ||
4866 | if (os_snprintf_error(buflen, res)) | |
4867 | res = -1; | |
4868 | ||
4869 | return res; | |
4870 | } | |
4871 | #endif /* CONFIG_P2P */ | |
4872 | ||
4873 | ||
121adf9c JM |
4874 | #ifdef OFFSET |
4875 | #undef OFFSET | |
4876 | #endif /* OFFSET */ | |
4877 | /* OFFSET: Get offset of a variable within the wpa_config structure */ | |
4878 | #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v) | |
4879 | ||
10263dc2 OO |
4880 | #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL |
4881 | #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL | |
4882 | #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f) | |
121adf9c JM |
4883 | #define INT(f) _INT(f), NULL, NULL |
4884 | #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max | |
10263dc2 | 4885 | #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f) |
121adf9c JM |
4886 | #define STR(f) _STR(f), NULL, NULL |
4887 | #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max | |
10263dc2 | 4888 | #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL |
5c6c315f MK |
4889 | #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \ |
4890 | OFFSET(f), NULL, NULL | |
121adf9c JM |
4891 | |
4892 | static const struct global_parse_data global_fields[] = { | |
4893 | #ifdef CONFIG_CTRL_IFACE | |
1d47214a | 4894 | { STR(ctrl_interface), 0 }, |
ea61aa1d | 4895 | { FUNC_NO_VAR(no_ctrl_interface), 0 }, |
1d47214a | 4896 | { STR(ctrl_interface_group), 0 } /* deprecated */, |
121adf9c | 4897 | #endif /* CONFIG_CTRL_IFACE */ |
0836c04b HW |
4898 | #ifdef CONFIG_MACSEC |
4899 | { INT_RANGE(eapol_version, 1, 3), 0 }, | |
4900 | #else /* CONFIG_MACSEC */ | |
1d47214a | 4901 | { INT_RANGE(eapol_version, 1, 2), 0 }, |
0836c04b | 4902 | #endif /* CONFIG_MACSEC */ |
1d47214a | 4903 | { INT(ap_scan), 0 }, |
31392709 | 4904 | { FUNC(bgscan), 0 }, |
e45e8989 TP |
4905 | #ifdef CONFIG_MESH |
4906 | { INT(user_mpm), 0 }, | |
4b409368 | 4907 | { INT_RANGE(max_peer_links, 0, 255), 0 }, |
5a2a6de6 | 4908 | { INT(mesh_max_inactivity), 0 }, |
ecd40fef | 4909 | { INT(dot11RSNASAERetransPeriod), 0 }, |
e45e8989 | 4910 | #endif /* CONFIG_MESH */ |
54ddd743 | 4911 | { INT(disable_scan_offload), 0 }, |
1d47214a JM |
4912 | { INT(fast_reauth), 0 }, |
4913 | { STR(opensc_engine_path), 0 }, | |
4914 | { STR(pkcs11_engine_path), 0 }, | |
4915 | { STR(pkcs11_module_path), 0 }, | |
07e2de31 | 4916 | { STR(openssl_ciphers), 0 }, |
f64adcd7 JM |
4917 | { STR(pcsc_reader), 0 }, |
4918 | { STR(pcsc_pin), 0 }, | |
a5d44ac0 | 4919 | { INT(external_sim), 0 }, |
1d47214a JM |
4920 | { STR(driver_param), 0 }, |
4921 | { INT(dot11RSNAConfigPMKLifetime), 0 }, | |
4922 | { INT(dot11RSNAConfigPMKReauthThreshold), 0 }, | |
4923 | { INT(dot11RSNAConfigSATimeout), 0 }, | |
121adf9c | 4924 | #ifndef CONFIG_NO_CONFIG_WRITE |
1d47214a | 4925 | { INT(update_config), 0 }, |
121adf9c | 4926 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
1d47214a | 4927 | { FUNC_NO_VAR(load_dynamic_eap), 0 }, |
121adf9c | 4928 | #ifdef CONFIG_WPS |
1d47214a | 4929 | { FUNC(uuid), CFG_CHANGED_UUID }, |
183d3924 | 4930 | { INT_RANGE(auto_uuid, 0, 1), 0 }, |
cc6f2438 JM |
4931 | { STR_RANGE(device_name, 0, WPS_DEV_NAME_MAX_LEN), |
4932 | CFG_CHANGED_DEVICE_NAME }, | |
1c9cb49f JM |
4933 | { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING }, |
4934 | { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING }, | |
4935 | { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING }, | |
4936 | { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING }, | |
2f646b6e | 4937 | { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE }, |
1d47214a JM |
4938 | { FUNC(os_version), CFG_CHANGED_OS_VERSION }, |
4939 | { STR(config_methods), CFG_CHANGED_CONFIG_METHODS }, | |
4940 | { INT_RANGE(wps_cred_processing, 0, 2), 0 }, | |
339dc8bd | 4941 | { INT_RANGE(wps_cred_add_sae, 0, 1), 0 }, |
71dd3b78 | 4942 | { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION }, |
121adf9c | 4943 | #endif /* CONFIG_WPS */ |
e3768e7c JM |
4944 | #ifdef CONFIG_P2P |
4945 | { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE }, | |
86e2dcf5 PK |
4946 | { INT(p2p_listen_reg_class), CFG_CHANGED_P2P_LISTEN_CHANNEL }, |
4947 | { INT(p2p_listen_channel), CFG_CHANGED_P2P_LISTEN_CHANNEL }, | |
00eb2993 JM |
4948 | { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL }, |
4949 | { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL }, | |
e3768e7c JM |
4950 | { INT_RANGE(p2p_go_intent, 0, 15), 0 }, |
4951 | { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX }, | |
4952 | { INT_RANGE(persistent_reconnect, 0, 1), 0 }, | |
0f66abd2 | 4953 | { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS }, |
3071e181 | 4954 | { INT(p2p_group_idle), 0 }, |
1a471ff0 | 4955 | { INT_RANGE(p2p_go_freq_change_policy, 0, P2P_GO_FREQ_MOVE_MAX), 0 }, |
1b928f96 JM |
4956 | { INT_RANGE(p2p_passphrase_len, 8, 63), |
4957 | CFG_CHANGED_P2P_PASSPHRASE_LEN }, | |
21d996f7 | 4958 | { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN }, |
556b30da | 4959 | { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN }, |
51e9f228 | 4960 | { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 }, |
e3bd6e9d | 4961 | { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 }, |
a93a15bb | 4962 | { INT(p2p_go_ht40), 0 }, |
20ea1ca4 | 4963 | { INT(p2p_go_vht), 0 }, |
5a3319ab | 4964 | { INT(p2p_go_he), 0 }, |
99666225 | 4965 | { INT(p2p_go_edmg), 0 }, |
7a808c7e | 4966 | { INT(p2p_disabled), 0 }, |
0b8bcaa5 | 4967 | { INT_RANGE(p2p_go_ctwindow, 0, 127), 0 }, |
d76cd41a | 4968 | { INT(p2p_no_group_iface), 0 }, |
b277a2be | 4969 | { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 }, |
25ef8529 JM |
4970 | { IPV4(ip_addr_go), 0 }, |
4971 | { IPV4(ip_addr_mask), 0 }, | |
4972 | { IPV4(ip_addr_start), 0 }, | |
4973 | { IPV4(ip_addr_end), 0 }, | |
07c1e987 | 4974 | { INT_RANGE(p2p_cli_probe, 0, 1), 0 }, |
9359cc84 JC |
4975 | { INT(p2p_device_random_mac_addr), 0 }, |
4976 | { FUNC(p2p_device_persistent_mac_addr), 0 }, | |
a95906f9 | 4977 | { INT(p2p_interface_random_mac_addr), 0 }, |
e3768e7c | 4978 | #endif /* CONFIG_P2P */ |
1d47214a JM |
4979 | { FUNC(country), CFG_CHANGED_COUNTRY }, |
4980 | { INT(bss_max_count), 0 }, | |
78633c37 SL |
4981 | { INT(bss_expiration_age), 0 }, |
4982 | { INT(bss_expiration_scan_count), 0 }, | |
dae608d5 | 4983 | { INT_RANGE(filter_ssids, 0, 1), 0 }, |
bf8d6d24 | 4984 | { INT_RANGE(filter_rssi, -100, 0), 0 }, |
0d7e5a3a | 4985 | { INT(max_num_sta), 0 }, |
19e20c14 | 4986 | { INT_RANGE(ap_isolate, 0, 1), 0 }, |
46ee0427 | 4987 | { INT_RANGE(disassoc_low_ack, 0, 1), 0 }, |
66aadbd7 JK |
4988 | #ifdef CONFIG_HS20 |
4989 | { INT_RANGE(hs20, 0, 1), 0 }, | |
4990 | #endif /* CONFIG_HS20 */ | |
46ee0427 | 4991 | { INT_RANGE(interworking, 0, 1), 0 }, |
11540c0b | 4992 | { FUNC(hessid), 0 }, |
1298c145 | 4993 | { INT_RANGE(access_network_type, 0, 15), 0 }, |
63bc0ab0 SD |
4994 | { INT_RANGE(go_interworking, 0, 1), 0 }, |
4995 | { INT_RANGE(go_access_network_type, 0, 15), 0 }, | |
4996 | { INT_RANGE(go_internet, 0, 1), 0 }, | |
4997 | { INT_RANGE(go_venue_group, 0, 255), 0 }, | |
4998 | { INT_RANGE(go_venue_type, 0, 255), 0 }, | |
b0786fba | 4999 | { INT_RANGE(pbc_in_m1, 0, 1), 0 }, |
3f2c8ba6 | 5000 | { STR(autoscan), 0 }, |
042ec551 JM |
5001 | { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff), |
5002 | CFG_CHANGED_NFC_PASSWORD_TOKEN }, | |
5003 | { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN }, | |
5004 | { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN }, | |
5005 | { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN }, | |
462a7439 ES |
5006 | { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND }, |
5007 | { INT(p2p_go_max_inactivity), 0 }, | |
4d5bda5f | 5008 | { INT_RANGE(auto_interworking, 0, 1), 0 }, |
6e202021 | 5009 | { INT(okc), 0 }, |
62d49803 | 5010 | { INT(pmf), 0 }, |
625f202a | 5011 | { FUNC(sae_groups), 0 }, |
641d79f1 | 5012 | { INT_RANGE(sae_pwe, 0, 3), 0 }, |
d2b20838 | 5013 | { INT_RANGE(sae_pmkid_in_assoc, 0, 1), 0 }, |
18206e02 JM |
5014 | { INT(dtim_period), 0 }, |
5015 | { INT(beacon_int), 0 }, | |
18a2eaab | 5016 | { FUNC(ap_vendor_elements), 0 }, |
4342326f | 5017 | { INT_RANGE(ignore_old_scan_res, 0, 1), 0 }, |
f5ffc348 | 5018 | { FUNC(freq_list), 0 }, |
6124e858 | 5019 | { INT(scan_cur_freq), 0 }, |
4aa81868 | 5020 | { INT(sched_scan_interval), 0 }, |
d0330d57 | 5021 | { INT(sched_scan_start_delay), 0 }, |
800d5872 | 5022 | { INT(tdls_external_control), 0}, |
b572df86 | 5023 | { STR(osu_dir), 0 }, |
3c7863f8 | 5024 | { STR(wowlan_triggers), CFG_CHANGED_WOWLAN_TRIGGERS }, |
d3b20469 | 5025 | { INT(p2p_search_delay), 0}, |
c267753b JM |
5026 | { INT(mac_addr), 0 }, |
5027 | { INT(rand_addr_lifetime), 0 }, | |
5028 | { INT(preassoc_mac_addr), 0 }, | |
b41f2684 | 5029 | { INT(key_mgmt_offload), 0}, |
c35e35ed | 5030 | { INT(passive_scan), 0 }, |
59b416c7 | 5031 | { INT(reassoc_same_bss_optim), 0 }, |
94687a0a | 5032 | { INT(wps_priority), 0}, |
76ca15b7 AN |
5033 | #ifdef CONFIG_FST |
5034 | { STR_RANGE(fst_group_id, 1, FST_MAX_GROUP_ID_LEN), 0 }, | |
5035 | { INT_RANGE(fst_priority, 1, FST_MAX_PRIO_VALUE), 0 }, | |
5036 | { INT_RANGE(fst_llt, 1, FST_MAX_LLT_MS), 0 }, | |
5037 | #endif /* CONFIG_FST */ | |
f8c20186 | 5038 | { INT_RANGE(cert_in_cb, 0, 1), 0 }, |
73ed03f3 | 5039 | { INT_RANGE(wpa_rsc_relaxation, 0, 1), 0 }, |
bea48f77 | 5040 | { STR(sched_scan_plans), CFG_CHANGED_SCHED_SCAN_PLANS }, |
facf2c72 DS |
5041 | #ifdef CONFIG_MBO |
5042 | { STR(non_pref_chan), 0 }, | |
c5d193d7 DS |
5043 | { INT_RANGE(mbo_cell_capa, MBO_CELL_CAPA_AVAILABLE, |
5044 | MBO_CELL_CAPA_NOT_SUPPORTED), 0 }, | |
af8bc24d | 5045 | { INT_RANGE(disassoc_imminent_rssi_threshold, -120, 0), 0 }, |
332aadb8 | 5046 | { INT_RANGE(oce, 0, 3), 0 }, |
6d49aeb7 | 5047 | #endif /* CONFIG_MBO */ |
c86bef29 | 5048 | { INT(gas_address3), 0 }, |
d1723c55 LD |
5049 | { INT_RANGE(ftm_responder, 0, 1), 0 }, |
5050 | { INT_RANGE(ftm_initiator, 0, 1), 0 }, | |
1d9d21f3 VK |
5051 | { INT(gas_rand_addr_lifetime), 0 }, |
5052 | { INT_RANGE(gas_rand_mac_addr, 0, 2), 0 }, | |
5a5639b0 | 5053 | #ifdef CONFIG_DPP |
8528994e | 5054 | { INT_RANGE(dpp_config_processing, 0, 2), 0 }, |
5a5639b0 JM |
5055 | { STR(dpp_name), 0 }, |
5056 | { STR(dpp_mud_url), 0 }, | |
5057 | #endif /* CONFIG_DPP */ | |
d514b502 | 5058 | { INT_RANGE(coloc_intf_reporting, 0, 1), 0 }, |
ef59f987 AB |
5059 | #ifdef CONFIG_WNM |
5060 | { INT_RANGE(disable_btm, 0, 1), CFG_CHANGED_DISABLE_BTM }, | |
b17b7a8e | 5061 | { INT_RANGE(extended_key_id, 0, 1), 0 }, |
ef59f987 | 5062 | #endif /* CONFIG_WNM */ |
121adf9c JM |
5063 | }; |
5064 | ||
5065 | #undef FUNC | |
5066 | #undef _INT | |
5067 | #undef INT | |
5068 | #undef INT_RANGE | |
5069 | #undef _STR | |
5070 | #undef STR | |
5071 | #undef STR_RANGE | |
3f2c8ba6 | 5072 | #undef BIN |
25ef8529 | 5073 | #undef IPV4 |
e7ecab4a | 5074 | #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields) |
121adf9c JM |
5075 | |
5076 | ||
10263dc2 OO |
5077 | int wpa_config_dump_values(struct wpa_config *config, char *buf, size_t buflen) |
5078 | { | |
5079 | int result = 0; | |
5080 | size_t i; | |
5081 | ||
5082 | for (i = 0; i < NUM_GLOBAL_FIELDS; i++) { | |
5083 | const struct global_parse_data *field = &global_fields[i]; | |
5084 | int tmp; | |
5085 | ||
5086 | if (!field->get) | |
5087 | continue; | |
5088 | ||
5089 | tmp = field->get(field->name, config, (long) field->param1, | |
5090 | buf, buflen, 1); | |
5091 | if (tmp < 0) | |
5092 | return -1; | |
5093 | buf += tmp; | |
5094 | buflen -= tmp; | |
5095 | result += tmp; | |
5096 | } | |
5097 | return result; | |
5098 | } | |
5099 | ||
5100 | ||
5101 | int wpa_config_get_value(const char *name, struct wpa_config *config, | |
5102 | char *buf, size_t buflen) | |
5103 | { | |
5104 | size_t i; | |
5105 | ||
5106 | for (i = 0; i < NUM_GLOBAL_FIELDS; i++) { | |
5107 | const struct global_parse_data *field = &global_fields[i]; | |
5108 | ||
5109 | if (os_strcmp(name, field->name) != 0) | |
5110 | continue; | |
5111 | if (!field->get) | |
5112 | break; | |
5113 | return field->get(name, config, (long) field->param1, | |
5114 | buf, buflen, 0); | |
5115 | } | |
5116 | ||
5117 | return -1; | |
5118 | } | |
5119 | ||
5120 | ||
e50c50d5 DW |
5121 | int wpa_config_get_num_global_field_names(void) |
5122 | { | |
5123 | return NUM_GLOBAL_FIELDS; | |
5124 | } | |
5125 | ||
5126 | ||
5127 | const char * wpa_config_get_global_field_name(unsigned int i, int *no_var) | |
5128 | { | |
5129 | if (i >= NUM_GLOBAL_FIELDS) | |
5130 | return NULL; | |
5131 | ||
5132 | if (no_var) | |
5133 | *no_var = !global_fields[i].param1; | |
5134 | return global_fields[i].name; | |
5135 | } | |
5136 | ||
5137 | ||
121adf9c JM |
5138 | int wpa_config_process_global(struct wpa_config *config, char *pos, int line) |
5139 | { | |
5140 | size_t i; | |
5141 | int ret = 0; | |
5142 | ||
5143 | for (i = 0; i < NUM_GLOBAL_FIELDS; i++) { | |
5144 | const struct global_parse_data *field = &global_fields[i]; | |
5145 | size_t flen = os_strlen(field->name); | |
5146 | if (os_strncmp(pos, field->name, flen) != 0 || | |
5147 | pos[flen] != '=') | |
5148 | continue; | |
5149 | ||
5150 | if (field->parser(field, config, line, pos + flen + 1)) { | |
5151 | wpa_printf(MSG_ERROR, "Line %d: failed to " | |
5152 | "parse '%s'.", line, pos); | |
5153 | ret = -1; | |
5154 | } | |
042ec551 JM |
5155 | if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN) |
5156 | config->wps_nfc_pw_from_config = 1; | |
1d47214a | 5157 | config->changed_parameters |= field->changed_flag; |
121adf9c JM |
5158 | break; |
5159 | } | |
5160 | if (i == NUM_GLOBAL_FIELDS) { | |
c26effe1 YD |
5161 | #ifdef CONFIG_AP |
5162 | if (os_strncmp(pos, "wmm_ac_", 7) == 0) { | |
5163 | char *tmp = os_strchr(pos, '='); | |
5164 | if (tmp == NULL) { | |
5165 | if (line < 0) | |
5166 | return -1; | |
5167 | wpa_printf(MSG_ERROR, "Line %d: invalid line " | |
5168 | "'%s'", line, pos); | |
5169 | return -1; | |
5170 | } | |
5171 | *tmp++ = '\0'; | |
5172 | if (hostapd_config_wmm_ac(config->wmm_ac_params, pos, | |
5173 | tmp)) { | |
5174 | wpa_printf(MSG_ERROR, "Line %d: invalid WMM " | |
5175 | "AC item", line); | |
5176 | return -1; | |
5177 | } | |
21dc1627 | 5178 | return ret; |
c26effe1 YD |
5179 | } |
5180 | #endif /* CONFIG_AP */ | |
1d47214a JM |
5181 | if (line < 0) |
5182 | return -1; | |
121adf9c JM |
5183 | wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.", |
5184 | line, pos); | |
5185 | ret = -1; | |
5186 | } | |
5187 | ||
5188 | return ret; | |
5189 | } |