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