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