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