2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/uuid.h"
13 #include "utils/ip_addr.h"
14 #include "crypto/sha1.h"
15 #include "rsn_supp/wpa.h"
16 #include "eap_peer/eap.h"
21 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
22 #define NO_CONFIG_WRITE
26 * Structure for network configuration parsing. This data is used to implement
27 * a generic parser for each network block variable. The table of configuration
28 * variables is defined below in this file (ssid_fields[]).
31 /* Configuration variable name */
34 /* Parser function for this variable */
35 int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
36 int line, const char *value);
38 #ifndef NO_CONFIG_WRITE
39 /* Writer function (i.e., to get the variable in text format from
40 * internal presentation). */
41 char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
42 #endif /* NO_CONFIG_WRITE */
44 /* Variable specific parameters for the parser. */
45 void *param1, *param2, *param3, *param4;
47 /* 0 = this variable can be included in debug output and ctrl_iface
48 * 1 = this variable contains key/private data and it must not be
49 * included in debug output unless explicitly requested. In
50 * addition, this variable will not be readable through the
57 static int wpa_config_parse_str(const struct parse_data *data,
58 struct wpa_ssid *ssid,
59 int line, const char *value)
61 size_t res_len, *dst_len;
64 if (os_strcmp(value, "NULL") == 0) {
65 wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
72 tmp = wpa_config_parse_string(value, &res_len);
74 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
76 data->key_data ? "[KEY DATA REMOVED]" : value);
81 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
84 wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
88 if (data->param3 && res_len < (size_t) data->param3) {
89 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
90 "min_len=%ld)", line, data->name,
91 (unsigned long) res_len, (long) data->param3);
96 if (data->param4 && res_len > (size_t) data->param4) {
97 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
98 "max_len=%ld)", line, data->name,
99 (unsigned long) res_len, (long) data->param4);
105 dst = (char **) (((u8 *) ssid) + (long) data->param1);
106 dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
116 #ifndef NO_CONFIG_WRITE
117 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
121 buf = os_malloc(len + 3);
125 os_memcpy(buf + 1, value, len);
133 static char * wpa_config_write_string_hex(const u8 *value, size_t len)
137 buf = os_zalloc(2 * len + 1);
140 wpa_snprintf_hex(buf, 2 * len + 1, value, len);
146 static char * wpa_config_write_string(const u8 *value, size_t len)
151 if (is_hex(value, len))
152 return wpa_config_write_string_hex(value, len);
154 return wpa_config_write_string_ascii(value, len);
158 static char * wpa_config_write_str(const struct parse_data *data,
159 struct wpa_ssid *ssid)
164 src = (char **) (((u8 *) ssid) + (long) data->param1);
169 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
171 len = os_strlen(*src);
173 return wpa_config_write_string((const u8 *) *src, len);
175 #endif /* NO_CONFIG_WRITE */
178 static int wpa_config_parse_int(const struct parse_data *data,
179 struct wpa_ssid *ssid,
180 int line, const char *value)
185 dst = (int *) (((u8 *) ssid) + (long) data->param1);
186 val = strtol(value, &end, 0);
188 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
193 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
195 if (data->param3 && *dst < (long) data->param3) {
196 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
197 "min_value=%ld)", line, data->name, *dst,
198 (long) data->param3);
199 *dst = (long) data->param3;
203 if (data->param4 && *dst > (long) data->param4) {
204 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
205 "max_value=%ld)", line, data->name, *dst,
206 (long) data->param4);
207 *dst = (long) data->param4;
215 #ifndef NO_CONFIG_WRITE
216 static char * wpa_config_write_int(const struct parse_data *data,
217 struct wpa_ssid *ssid)
222 src = (int *) (((u8 *) ssid) + (long) data->param1);
224 value = os_malloc(20);
227 res = os_snprintf(value, 20, "%d", *src);
228 if (res < 0 || res >= 20) {
232 value[20 - 1] = '\0';
235 #endif /* NO_CONFIG_WRITE */
238 static int wpa_config_parse_bssid(const struct parse_data *data,
239 struct wpa_ssid *ssid, int line,
242 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
243 os_strcmp(value, "any") == 0) {
245 wpa_printf(MSG_MSGDUMP, "BSSID any");
248 if (hwaddr_aton(value, ssid->bssid)) {
249 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
254 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
259 #ifndef NO_CONFIG_WRITE
260 static char * wpa_config_write_bssid(const struct parse_data *data,
261 struct wpa_ssid *ssid)
266 if (!ssid->bssid_set)
269 value = os_malloc(20);
272 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
273 if (res < 0 || res >= 20) {
277 value[20 - 1] = '\0';
280 #endif /* NO_CONFIG_WRITE */
283 static int wpa_config_parse_psk(const struct parse_data *data,
284 struct wpa_ssid *ssid, int line,
287 #ifdef CONFIG_EXT_PASSWORD
288 if (os_strncmp(value, "ext:", 4) == 0) {
289 str_clear_free(ssid->passphrase);
290 ssid->passphrase = NULL;
292 os_free(ssid->ext_psk);
293 ssid->ext_psk = os_strdup(value + 4);
294 if (ssid->ext_psk == NULL)
296 wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
300 #endif /* CONFIG_EXT_PASSWORD */
303 #ifndef CONFIG_NO_PBKDF2
308 pos = os_strrchr(value, '"');
312 len = os_strlen(value);
313 if (len < 8 || len > 63) {
314 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
315 "length %lu (expected: 8..63) '%s'.",
316 line, (unsigned long) len, value);
319 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
321 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
322 os_memcmp(ssid->passphrase, value, len) == 0)
325 str_clear_free(ssid->passphrase);
326 ssid->passphrase = dup_binstr(value, len);
327 if (ssid->passphrase == NULL)
330 #else /* CONFIG_NO_PBKDF2 */
331 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
334 #endif /* CONFIG_NO_PBKDF2 */
337 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
338 value[PMK_LEN * 2] != '\0') {
339 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
344 str_clear_free(ssid->passphrase);
345 ssid->passphrase = NULL;
348 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
353 #ifndef NO_CONFIG_WRITE
354 static char * wpa_config_write_psk(const struct parse_data *data,
355 struct wpa_ssid *ssid)
357 #ifdef CONFIG_EXT_PASSWORD
359 size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
360 char *buf = os_malloc(len);
363 os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
366 #endif /* CONFIG_EXT_PASSWORD */
368 if (ssid->passphrase)
369 return wpa_config_write_string_ascii(
370 (const u8 *) ssid->passphrase,
371 os_strlen(ssid->passphrase));
374 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
378 #endif /* NO_CONFIG_WRITE */
381 static int wpa_config_parse_proto(const struct parse_data *data,
382 struct wpa_ssid *ssid, int line,
385 int val = 0, last, errors = 0;
386 char *start, *end, *buf;
388 buf = os_strdup(value);
393 while (*start != '\0') {
394 while (*start == ' ' || *start == '\t')
399 while (*end != ' ' && *end != '\t' && *end != '\0')
403 if (os_strcmp(start, "WPA") == 0)
404 val |= WPA_PROTO_WPA;
405 else if (os_strcmp(start, "RSN") == 0 ||
406 os_strcmp(start, "WPA2") == 0)
407 val |= WPA_PROTO_RSN;
408 else if (os_strcmp(start, "OSEN") == 0)
409 val |= WPA_PROTO_OSEN;
411 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
423 wpa_printf(MSG_ERROR,
424 "Line %d: no proto values configured.", line);
428 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
430 return errors ? -1 : 0;
434 #ifndef NO_CONFIG_WRITE
435 static char * wpa_config_write_proto(const struct parse_data *data,
436 struct wpa_ssid *ssid)
439 char *buf, *pos, *end;
441 pos = buf = os_zalloc(20);
446 if (ssid->proto & WPA_PROTO_WPA) {
447 ret = os_snprintf(pos, end - pos, "%sWPA",
448 pos == buf ? "" : " ");
449 if (ret < 0 || ret >= end - pos)
454 if (ssid->proto & WPA_PROTO_RSN) {
455 ret = os_snprintf(pos, end - pos, "%sRSN",
456 pos == buf ? "" : " ");
457 if (ret < 0 || ret >= end - pos)
462 if (ssid->proto & WPA_PROTO_OSEN) {
463 ret = os_snprintf(pos, end - pos, "%sOSEN",
464 pos == buf ? "" : " ");
465 if (ret < 0 || ret >= end - pos)
477 #endif /* NO_CONFIG_WRITE */
480 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
481 struct wpa_ssid *ssid, int line,
484 int val = 0, last, errors = 0;
485 char *start, *end, *buf;
487 buf = os_strdup(value);
492 while (*start != '\0') {
493 while (*start == ' ' || *start == '\t')
498 while (*end != ' ' && *end != '\t' && *end != '\0')
502 if (os_strcmp(start, "WPA-PSK") == 0)
503 val |= WPA_KEY_MGMT_PSK;
504 else if (os_strcmp(start, "WPA-EAP") == 0)
505 val |= WPA_KEY_MGMT_IEEE8021X;
506 else if (os_strcmp(start, "IEEE8021X") == 0)
507 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
508 else if (os_strcmp(start, "NONE") == 0)
509 val |= WPA_KEY_MGMT_NONE;
510 else if (os_strcmp(start, "WPA-NONE") == 0)
511 val |= WPA_KEY_MGMT_WPA_NONE;
512 #ifdef CONFIG_IEEE80211R
513 else if (os_strcmp(start, "FT-PSK") == 0)
514 val |= WPA_KEY_MGMT_FT_PSK;
515 else if (os_strcmp(start, "FT-EAP") == 0)
516 val |= WPA_KEY_MGMT_FT_IEEE8021X;
517 #endif /* CONFIG_IEEE80211R */
518 #ifdef CONFIG_IEEE80211W
519 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
520 val |= WPA_KEY_MGMT_PSK_SHA256;
521 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
522 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
523 #endif /* CONFIG_IEEE80211W */
525 else if (os_strcmp(start, "WPS") == 0)
526 val |= WPA_KEY_MGMT_WPS;
527 #endif /* CONFIG_WPS */
529 else if (os_strcmp(start, "SAE") == 0)
530 val |= WPA_KEY_MGMT_SAE;
531 else if (os_strcmp(start, "FT-SAE") == 0)
532 val |= WPA_KEY_MGMT_FT_SAE;
533 #endif /* CONFIG_SAE */
535 else if (os_strcmp(start, "OSEN") == 0)
536 val |= WPA_KEY_MGMT_OSEN;
537 #endif /* CONFIG_HS20 */
539 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
551 wpa_printf(MSG_ERROR,
552 "Line %d: no key_mgmt values configured.", line);
556 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
557 ssid->key_mgmt = val;
558 return errors ? -1 : 0;
562 #ifndef NO_CONFIG_WRITE
563 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
564 struct wpa_ssid *ssid)
566 char *buf, *pos, *end;
569 pos = buf = os_zalloc(100);
574 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
575 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
576 pos == buf ? "" : " ");
577 if (ret < 0 || ret >= end - pos) {
584 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
585 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
586 pos == buf ? "" : " ");
587 if (ret < 0 || ret >= end - pos) {
594 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
595 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
596 pos == buf ? "" : " ");
597 if (ret < 0 || ret >= end - pos) {
604 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
605 ret = os_snprintf(pos, end - pos, "%sNONE",
606 pos == buf ? "" : " ");
607 if (ret < 0 || ret >= end - pos) {
614 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
615 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
616 pos == buf ? "" : " ");
617 if (ret < 0 || ret >= end - pos) {
624 #ifdef CONFIG_IEEE80211R
625 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
626 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
627 pos == buf ? "" : " ");
628 if (ret < 0 || ret >= end - pos) {
635 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
636 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
637 pos == buf ? "" : " ");
638 if (ret < 0 || ret >= end - pos) {
644 #endif /* CONFIG_IEEE80211R */
646 #ifdef CONFIG_IEEE80211W
647 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
648 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
649 pos == buf ? "" : " ");
650 if (ret < 0 || ret >= end - pos) {
657 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
658 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
659 pos == buf ? "" : " ");
660 if (ret < 0 || ret >= end - pos) {
666 #endif /* CONFIG_IEEE80211W */
669 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
670 ret = os_snprintf(pos, end - pos, "%sWPS",
671 pos == buf ? "" : " ");
672 if (ret < 0 || ret >= end - pos) {
678 #endif /* CONFIG_WPS */
687 #endif /* NO_CONFIG_WRITE */
690 static int wpa_config_parse_cipher(int line, const char *value)
692 int val = wpa_parse_cipher(value);
694 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
699 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
707 #ifndef NO_CONFIG_WRITE
708 static char * wpa_config_write_cipher(int cipher)
710 char *buf = os_zalloc(50);
714 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
721 #endif /* NO_CONFIG_WRITE */
724 static int wpa_config_parse_pairwise(const struct parse_data *data,
725 struct wpa_ssid *ssid, int line,
729 val = wpa_config_parse_cipher(line, value);
732 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
733 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
734 "(0x%x).", line, val);
738 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
739 ssid->pairwise_cipher = val;
744 #ifndef NO_CONFIG_WRITE
745 static char * wpa_config_write_pairwise(const struct parse_data *data,
746 struct wpa_ssid *ssid)
748 return wpa_config_write_cipher(ssid->pairwise_cipher);
750 #endif /* NO_CONFIG_WRITE */
753 static int wpa_config_parse_group(const struct parse_data *data,
754 struct wpa_ssid *ssid, int line,
758 val = wpa_config_parse_cipher(line, value);
761 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
762 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
763 "(0x%x).", line, val);
767 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
768 ssid->group_cipher = val;
773 #ifndef NO_CONFIG_WRITE
774 static char * wpa_config_write_group(const struct parse_data *data,
775 struct wpa_ssid *ssid)
777 return wpa_config_write_cipher(ssid->group_cipher);
779 #endif /* NO_CONFIG_WRITE */
782 static int wpa_config_parse_auth_alg(const struct parse_data *data,
783 struct wpa_ssid *ssid, int line,
786 int val = 0, last, errors = 0;
787 char *start, *end, *buf;
789 buf = os_strdup(value);
794 while (*start != '\0') {
795 while (*start == ' ' || *start == '\t')
800 while (*end != ' ' && *end != '\t' && *end != '\0')
804 if (os_strcmp(start, "OPEN") == 0)
805 val |= WPA_AUTH_ALG_OPEN;
806 else if (os_strcmp(start, "SHARED") == 0)
807 val |= WPA_AUTH_ALG_SHARED;
808 else if (os_strcmp(start, "LEAP") == 0)
809 val |= WPA_AUTH_ALG_LEAP;
811 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
823 wpa_printf(MSG_ERROR,
824 "Line %d: no auth_alg values configured.", line);
828 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
829 ssid->auth_alg = val;
830 return errors ? -1 : 0;
834 #ifndef NO_CONFIG_WRITE
835 static char * wpa_config_write_auth_alg(const struct parse_data *data,
836 struct wpa_ssid *ssid)
838 char *buf, *pos, *end;
841 pos = buf = os_zalloc(30);
846 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
847 ret = os_snprintf(pos, end - pos, "%sOPEN",
848 pos == buf ? "" : " ");
849 if (ret < 0 || ret >= end - pos) {
856 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
857 ret = os_snprintf(pos, end - pos, "%sSHARED",
858 pos == buf ? "" : " ");
859 if (ret < 0 || ret >= end - pos) {
866 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
867 ret = os_snprintf(pos, end - pos, "%sLEAP",
868 pos == buf ? "" : " ");
869 if (ret < 0 || ret >= end - pos) {
883 #endif /* NO_CONFIG_WRITE */
886 static int * wpa_config_parse_int_array(const char *value)
894 freqs = os_calloc(len + 1, sizeof(int));
905 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
910 for (i = len; i <= len * 2; i++)
916 freqs[used] = atoi(pos);
917 if (freqs[used] == 0)
920 pos = os_strchr(pos + 1, ' ');
927 static int wpa_config_parse_scan_freq(const struct parse_data *data,
928 struct wpa_ssid *ssid, int line,
933 freqs = wpa_config_parse_int_array(value);
940 os_free(ssid->scan_freq);
941 ssid->scan_freq = freqs;
947 static int wpa_config_parse_freq_list(const struct parse_data *data,
948 struct wpa_ssid *ssid, int line,
953 freqs = wpa_config_parse_int_array(value);
960 os_free(ssid->freq_list);
961 ssid->freq_list = freqs;
967 #ifndef NO_CONFIG_WRITE
968 static char * wpa_config_write_freqs(const struct parse_data *data,
971 char *buf, *pos, *end;
979 for (i = 0; freqs[i]; i++)
982 pos = buf = os_zalloc(10 * count + 1);
985 end = buf + 10 * count + 1;
987 for (i = 0; freqs[i]; i++) {
988 ret = os_snprintf(pos, end - pos, "%s%u",
989 i == 0 ? "" : " ", freqs[i]);
990 if (ret < 0 || ret >= end - pos) {
1001 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1002 struct wpa_ssid *ssid)
1004 return wpa_config_write_freqs(data, ssid->scan_freq);
1008 static char * wpa_config_write_freq_list(const struct parse_data *data,
1009 struct wpa_ssid *ssid)
1011 return wpa_config_write_freqs(data, ssid->freq_list);
1013 #endif /* NO_CONFIG_WRITE */
1016 #ifdef IEEE8021X_EAPOL
1017 static int wpa_config_parse_eap(const struct parse_data *data,
1018 struct wpa_ssid *ssid, int line,
1021 int last, errors = 0;
1022 char *start, *end, *buf;
1023 struct eap_method_type *methods = NULL, *tmp;
1024 size_t num_methods = 0;
1026 buf = os_strdup(value);
1031 while (*start != '\0') {
1032 while (*start == ' ' || *start == '\t')
1037 while (*end != ' ' && *end != '\t' && *end != '\0')
1039 last = *end == '\0';
1042 methods = os_realloc_array(methods, num_methods + 1,
1044 if (methods == NULL) {
1049 methods[num_methods].method = eap_peer_get_type(
1050 start, &methods[num_methods].vendor);
1051 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1052 methods[num_methods].method == EAP_TYPE_NONE) {
1053 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1054 "'%s'", line, start);
1055 wpa_printf(MSG_ERROR, "You may need to add support for"
1056 " this EAP method during wpa_supplicant\n"
1057 "build time configuration.\n"
1058 "See README for more information.");
1060 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1061 methods[num_methods].method == EAP_TYPE_LEAP)
1073 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1074 if (methods == NULL) {
1078 methods[num_methods].vendor = EAP_VENDOR_IETF;
1079 methods[num_methods].method = EAP_TYPE_NONE;
1082 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1083 (u8 *) methods, num_methods * sizeof(*methods));
1084 os_free(ssid->eap.eap_methods);
1085 ssid->eap.eap_methods = methods;
1086 return errors ? -1 : 0;
1090 static char * wpa_config_write_eap(const struct parse_data *data,
1091 struct wpa_ssid *ssid)
1094 char *buf, *pos, *end;
1095 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1098 if (eap_methods == NULL)
1101 pos = buf = os_zalloc(100);
1106 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1107 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1108 name = eap_get_name(eap_methods[i].vendor,
1109 eap_methods[i].method);
1111 ret = os_snprintf(pos, end - pos, "%s%s",
1112 pos == buf ? "" : " ", name);
1113 if (ret < 0 || ret >= end - pos)
1125 static int wpa_config_parse_password(const struct parse_data *data,
1126 struct wpa_ssid *ssid, int line,
1131 if (os_strcmp(value, "NULL") == 0) {
1132 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1133 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1134 ssid->eap.password = NULL;
1135 ssid->eap.password_len = 0;
1139 #ifdef CONFIG_EXT_PASSWORD
1140 if (os_strncmp(value, "ext:", 4) == 0) {
1141 char *name = os_strdup(value + 4);
1144 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1145 ssid->eap.password = (u8 *) name;
1146 ssid->eap.password_len = os_strlen(name);
1147 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1148 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1151 #endif /* CONFIG_EXT_PASSWORD */
1153 if (os_strncmp(value, "hash:", 5) != 0) {
1157 tmp = wpa_config_parse_string(value, &res_len);
1159 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1163 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1164 (u8 *) tmp, res_len);
1166 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1167 ssid->eap.password = (u8 *) tmp;
1168 ssid->eap.password_len = res_len;
1169 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1170 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1176 /* NtPasswordHash: hash:<32 hex digits> */
1177 if (os_strlen(value + 5) != 2 * 16) {
1178 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1179 "(expected 32 hex digits)", line);
1183 hash = os_malloc(16);
1187 if (hexstr2bin(value + 5, hash, 16)) {
1189 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1193 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1195 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1196 ssid->eap.password = hash;
1197 ssid->eap.password_len = 16;
1198 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1199 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1205 static char * wpa_config_write_password(const struct parse_data *data,
1206 struct wpa_ssid *ssid)
1210 if (ssid->eap.password == NULL)
1213 #ifdef CONFIG_EXT_PASSWORD
1214 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1215 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1218 os_memcpy(buf, "ext:", 4);
1219 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1222 #endif /* CONFIG_EXT_PASSWORD */
1224 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1225 return wpa_config_write_string(
1226 ssid->eap.password, ssid->eap.password_len);
1229 buf = os_malloc(5 + 32 + 1);
1233 os_memcpy(buf, "hash:", 5);
1234 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1238 #endif /* IEEE8021X_EAPOL */
1241 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1242 const char *value, int idx)
1244 char *buf, title[20];
1247 buf = wpa_config_parse_string(value, len);
1249 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1253 if (*len > MAX_WEP_KEY_LEN) {
1254 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1259 if (*len && *len != 5 && *len != 13 && *len != 16) {
1260 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1261 "this network block will be ignored",
1262 line, (unsigned int) *len);
1264 os_memcpy(key, buf, *len);
1265 str_clear_free(buf);
1266 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1267 if (res >= 0 && (size_t) res < sizeof(title))
1268 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1273 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1274 struct wpa_ssid *ssid, int line,
1277 return wpa_config_parse_wep_key(ssid->wep_key[0],
1278 &ssid->wep_key_len[0], line,
1283 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1284 struct wpa_ssid *ssid, int line,
1287 return wpa_config_parse_wep_key(ssid->wep_key[1],
1288 &ssid->wep_key_len[1], line,
1293 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1294 struct wpa_ssid *ssid, int line,
1297 return wpa_config_parse_wep_key(ssid->wep_key[2],
1298 &ssid->wep_key_len[2], line,
1303 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1304 struct wpa_ssid *ssid, int line,
1307 return wpa_config_parse_wep_key(ssid->wep_key[3],
1308 &ssid->wep_key_len[3], line,
1313 #ifndef NO_CONFIG_WRITE
1314 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1316 if (ssid->wep_key_len[idx] == 0)
1318 return wpa_config_write_string(ssid->wep_key[idx],
1319 ssid->wep_key_len[idx]);
1323 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1324 struct wpa_ssid *ssid)
1326 return wpa_config_write_wep_key(ssid, 0);
1330 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1331 struct wpa_ssid *ssid)
1333 return wpa_config_write_wep_key(ssid, 1);
1337 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1338 struct wpa_ssid *ssid)
1340 return wpa_config_write_wep_key(ssid, 2);
1344 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1345 struct wpa_ssid *ssid)
1347 return wpa_config_write_wep_key(ssid, 3);
1349 #endif /* NO_CONFIG_WRITE */
1354 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1355 struct wpa_ssid *ssid, int line,
1358 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1359 os_strcmp(value, "any") == 0) {
1360 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1361 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1364 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1365 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1369 ssid->bssid_set = 1;
1370 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1371 MAC2STR(ssid->go_p2p_dev_addr));
1376 #ifndef NO_CONFIG_WRITE
1377 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1378 struct wpa_ssid *ssid)
1383 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1386 value = os_malloc(20);
1389 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1390 if (res < 0 || res >= 20) {
1394 value[20 - 1] = '\0';
1397 #endif /* NO_CONFIG_WRITE */
1400 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1401 struct wpa_ssid *ssid, int line,
1405 u8 *buf, *n, addr[ETH_ALEN];
1412 while (pos && *pos) {
1416 if (hwaddr_aton(pos, addr)) {
1418 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1419 "p2p_client_list address '%s'.",
1424 /* continue anyway since this could have been from a
1425 * truncated configuration file line */
1426 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1427 "truncated p2p_client_list address '%s'",
1430 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1436 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1437 os_memcpy(buf, addr, ETH_ALEN);
1439 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1443 pos = os_strchr(pos, ' ');
1446 os_free(ssid->p2p_client_list);
1447 ssid->p2p_client_list = buf;
1448 ssid->num_p2p_clients = count;
1454 #ifndef NO_CONFIG_WRITE
1455 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1456 struct wpa_ssid *ssid)
1458 char *value, *end, *pos;
1462 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1465 value = os_malloc(20 * ssid->num_p2p_clients);
1469 end = value + 20 * ssid->num_p2p_clients;
1471 for (i = ssid->num_p2p_clients; i > 0; i--) {
1472 res = os_snprintf(pos, end - pos, MACSTR " ",
1473 MAC2STR(ssid->p2p_client_list +
1474 (i - 1) * ETH_ALEN));
1475 if (res < 0 || res >= end - pos) {
1487 #endif /* NO_CONFIG_WRITE */
1490 static int wpa_config_parse_psk_list(const struct parse_data *data,
1491 struct wpa_ssid *ssid, int line,
1494 struct psk_list_entry *p;
1497 p = os_zalloc(sizeof(*p));
1502 if (os_strncmp(pos, "P2P-", 4) == 0) {
1507 if (hwaddr_aton(pos, p->addr)) {
1508 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1515 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1522 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1523 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1529 dl_list_add(&ssid->psk_list, &p->list);
1535 #ifndef NO_CONFIG_WRITE
1536 static char * wpa_config_write_psk_list(const struct parse_data *data,
1537 struct wpa_ssid *ssid)
1541 #endif /* NO_CONFIG_WRITE */
1543 #endif /* CONFIG_P2P */
1545 /* Helper macros for network block parser */
1550 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1551 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1553 /* STR: Define a string variable for an ASCII string; f = field name */
1554 #ifdef NO_CONFIG_WRITE
1555 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1556 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1557 #else /* NO_CONFIG_WRITE */
1558 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1559 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1560 #endif /* NO_CONFIG_WRITE */
1561 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1562 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1563 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1564 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1566 /* STR_LEN: Define a string variable with a separate variable for storing the
1567 * data length. Unlike STR(), this can be used to store arbitrary binary data
1568 * (i.e., even nul termination character). */
1569 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1570 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1571 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1572 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1573 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1575 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1576 * explicitly specified. */
1577 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1578 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1579 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1581 #ifdef NO_CONFIG_WRITE
1582 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1583 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1584 #else /* NO_CONFIG_WRITE */
1585 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1586 OFFSET(f), (void *) 0
1587 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1588 OFFSET(eap.f), (void *) 0
1589 #endif /* NO_CONFIG_WRITE */
1591 /* INT: Define an integer variable */
1592 #define INT(f) _INT(f), NULL, NULL, 0
1593 #define INTe(f) _INTe(f), NULL, NULL, 0
1595 /* INT_RANGE: Define an integer variable with allowed value range */
1596 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1598 /* FUNC: Define a configuration variable that uses a custom function for
1599 * parsing and writing the value. */
1600 #ifdef NO_CONFIG_WRITE
1601 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1602 #else /* NO_CONFIG_WRITE */
1603 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1604 NULL, NULL, NULL, NULL
1605 #endif /* NO_CONFIG_WRITE */
1606 #define FUNC(f) _FUNC(f), 0
1607 #define FUNC_KEY(f) _FUNC(f), 1
1610 * Table of network configuration variables. This table is used to parse each
1611 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1612 * that is inside a network block.
1614 * This table is generated using the helper macros defined above and with
1615 * generous help from the C pre-processor. The field name is stored as a string
1616 * into .name and for STR and INT types, the offset of the target buffer within
1617 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1618 * offset to the field containing the length of the configuration variable.
1619 * .param3 and .param4 can be used to mark the allowed range (length for STR
1620 * and value for INT).
1622 * For each configuration line in wpa_supplicant.conf, the parser goes through
1623 * this table and select the entry that matches with the field name. The parser
1624 * function (.parser) is then called to parse the actual value of the field.
1626 * This kind of mechanism makes it easy to add new configuration parameters,
1627 * since only one line needs to be added into this table and into the
1628 * struct wpa_ssid definition if the new variable is either a string or
1629 * integer. More complex types will need to use their own parser and writer
1632 static const struct parse_data ssid_fields[] = {
1633 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1634 { INT_RANGE(scan_ssid, 0, 1) },
1639 { INT(bg_scan_period) },
1643 { FUNC(scan_freq) },
1644 { FUNC(freq_list) },
1645 #ifdef IEEE8021X_EAPOL
1647 { STR_LENe(identity) },
1648 { STR_LENe(anonymous_identity) },
1649 { FUNC_KEY(password) },
1652 { STRe(client_cert) },
1653 { STRe(private_key) },
1654 { STR_KEYe(private_key_passwd) },
1656 { STRe(subject_match) },
1657 { STRe(altsubject_match) },
1658 { STRe(domain_suffix_match) },
1661 { STRe(client_cert2) },
1662 { STRe(private_key2) },
1663 { STR_KEYe(private_key2_passwd) },
1665 { STRe(subject_match2) },
1666 { STRe(altsubject_match2) },
1667 { STRe(domain_suffix_match2) },
1672 { STRe(engine_id) },
1675 { STRe(ca_cert_id) },
1677 { STRe(engine2_id) },
1680 { STRe(ca_cert2_id) },
1683 { INT(eapol_flags) },
1685 { STRe(openssl_ciphers) },
1686 #endif /* IEEE8021X_EAPOL */
1687 { FUNC_KEY(wep_key0) },
1688 { FUNC_KEY(wep_key1) },
1689 { FUNC_KEY(wep_key2) },
1690 { FUNC_KEY(wep_key3) },
1691 { INT(wep_tx_keyidx) },
1693 #ifdef IEEE8021X_EAPOL
1694 { INT(eap_workaround) },
1696 { INTe(fragment_size) },
1698 #endif /* IEEE8021X_EAPOL */
1699 { INT_RANGE(mode, 0, 4) },
1700 { INT_RANGE(proactive_key_caching, 0, 1) },
1701 { INT_RANGE(disabled, 0, 2) },
1703 #ifdef CONFIG_IEEE80211W
1704 { INT_RANGE(ieee80211w, 0, 2) },
1705 #endif /* CONFIG_IEEE80211W */
1706 { INT_RANGE(peerkey, 0, 1) },
1707 { INT_RANGE(mixed_cell, 0, 1) },
1708 { INT_RANGE(frequency, 0, 65000) },
1709 { INT(wpa_ptk_rekey) },
1711 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1713 { FUNC(go_p2p_dev_addr) },
1714 { FUNC(p2p_client_list) },
1716 #endif /* CONFIG_P2P */
1717 #ifdef CONFIG_HT_OVERRIDES
1718 { INT_RANGE(disable_ht, 0, 1) },
1719 { INT_RANGE(disable_ht40, -1, 1) },
1720 { INT_RANGE(disable_sgi, 0, 1) },
1721 { INT_RANGE(disable_ldpc, 0, 1) },
1722 { INT_RANGE(ht40_intolerant, 0, 1) },
1723 { INT_RANGE(disable_max_amsdu, -1, 1) },
1724 { INT_RANGE(ampdu_factor, -1, 3) },
1725 { INT_RANGE(ampdu_density, -1, 7) },
1727 #endif /* CONFIG_HT_OVERRIDES */
1728 #ifdef CONFIG_VHT_OVERRIDES
1729 { INT_RANGE(disable_vht, 0, 1) },
1731 { INT(vht_capa_mask) },
1732 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1733 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1734 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1735 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1736 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1737 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1738 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1739 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1740 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1741 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1742 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1743 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1744 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1745 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1746 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1747 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1748 #endif /* CONFIG_VHT_OVERRIDES */
1749 { INT(ap_max_inactivity) },
1750 { INT(dtim_period) },
1751 { INT(beacon_int) },
1752 #ifdef CONFIG_MACSEC
1753 { INT_RANGE(macsec_policy, 0, 1) },
1754 #endif /* CONFIG_MACSEC */
1756 { INT(update_identifier) },
1757 #endif /* CONFIG_HS20 */
1758 { INT_RANGE(mac_addr, 0, 2) },
1770 #undef STR_RANGE_KEY
1777 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1781 * wpa_config_add_prio_network - Add a network to priority lists
1782 * @config: Configuration data from wpa_config_read()
1783 * @ssid: Pointer to the network configuration to be added to the list
1784 * Returns: 0 on success, -1 on failure
1786 * This function is used to add a network block to the priority list of
1787 * networks. This must be called for each network when reading in the full
1788 * configuration. In addition, this can be used indirectly when updating
1789 * priorities by calling wpa_config_update_prio_list().
1791 int wpa_config_add_prio_network(struct wpa_config *config,
1792 struct wpa_ssid *ssid)
1795 struct wpa_ssid *prev, **nlist;
1798 * Add to an existing priority list if one is available for the
1799 * configured priority level for this network.
1801 for (prio = 0; prio < config->num_prio; prio++) {
1802 prev = config->pssid[prio];
1803 if (prev->priority == ssid->priority) {
1811 /* First network for this priority - add a new priority list */
1812 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1813 sizeof(struct wpa_ssid *));
1817 for (prio = 0; prio < config->num_prio; prio++) {
1818 if (nlist[prio]->priority < ssid->priority) {
1819 os_memmove(&nlist[prio + 1], &nlist[prio],
1820 (config->num_prio - prio) *
1821 sizeof(struct wpa_ssid *));
1828 config->pssid = nlist;
1835 * wpa_config_update_prio_list - Update network priority list
1836 * @config: Configuration data from wpa_config_read()
1837 * Returns: 0 on success, -1 on failure
1839 * This function is called to update the priority list of networks in the
1840 * configuration when a network is being added or removed. This is also called
1841 * if a priority for a network is changed.
1843 int wpa_config_update_prio_list(struct wpa_config *config)
1845 struct wpa_ssid *ssid;
1848 os_free(config->pssid);
1849 config->pssid = NULL;
1850 config->num_prio = 0;
1852 ssid = config->ssid;
1855 if (wpa_config_add_prio_network(config, ssid) < 0)
1864 #ifdef IEEE8021X_EAPOL
1865 static void eap_peer_config_free(struct eap_peer_config *eap)
1867 os_free(eap->eap_methods);
1868 bin_clear_free(eap->identity, eap->identity_len);
1869 os_free(eap->anonymous_identity);
1870 bin_clear_free(eap->password, eap->password_len);
1871 os_free(eap->ca_cert);
1872 os_free(eap->ca_path);
1873 os_free(eap->client_cert);
1874 os_free(eap->private_key);
1875 str_clear_free(eap->private_key_passwd);
1876 os_free(eap->dh_file);
1877 os_free(eap->subject_match);
1878 os_free(eap->altsubject_match);
1879 os_free(eap->domain_suffix_match);
1880 os_free(eap->ca_cert2);
1881 os_free(eap->ca_path2);
1882 os_free(eap->client_cert2);
1883 os_free(eap->private_key2);
1884 str_clear_free(eap->private_key2_passwd);
1885 os_free(eap->dh_file2);
1886 os_free(eap->subject_match2);
1887 os_free(eap->altsubject_match2);
1888 os_free(eap->domain_suffix_match2);
1889 os_free(eap->phase1);
1890 os_free(eap->phase2);
1892 str_clear_free(eap->pin);
1893 os_free(eap->engine_id);
1894 os_free(eap->key_id);
1895 os_free(eap->cert_id);
1896 os_free(eap->ca_cert_id);
1897 os_free(eap->key2_id);
1898 os_free(eap->cert2_id);
1899 os_free(eap->ca_cert2_id);
1900 str_clear_free(eap->pin2);
1901 os_free(eap->engine2_id);
1903 os_free(eap->pending_req_otp);
1904 os_free(eap->pac_file);
1905 bin_clear_free(eap->new_password, eap->new_password_len);
1906 str_clear_free(eap->external_sim_resp);
1907 os_free(eap->openssl_ciphers);
1909 #endif /* IEEE8021X_EAPOL */
1913 * wpa_config_free_ssid - Free network/ssid configuration data
1914 * @ssid: Configuration data for the network
1916 * This function frees all resources allocated for the network configuration
1919 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1921 struct psk_list_entry *psk;
1923 os_free(ssid->ssid);
1924 os_memset(ssid->psk, 0, sizeof(ssid->psk));
1925 str_clear_free(ssid->passphrase);
1926 os_free(ssid->ext_psk);
1927 #ifdef IEEE8021X_EAPOL
1928 eap_peer_config_free(&ssid->eap);
1929 #endif /* IEEE8021X_EAPOL */
1930 os_free(ssid->id_str);
1931 os_free(ssid->scan_freq);
1932 os_free(ssid->freq_list);
1933 os_free(ssid->bgscan);
1934 os_free(ssid->p2p_client_list);
1935 #ifdef CONFIG_HT_OVERRIDES
1936 os_free(ssid->ht_mcs);
1937 #endif /* CONFIG_HT_OVERRIDES */
1938 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
1940 dl_list_del(&psk->list);
1947 void wpa_config_free_cred(struct wpa_cred *cred)
1951 os_free(cred->realm);
1952 str_clear_free(cred->username);
1953 str_clear_free(cred->password);
1954 os_free(cred->ca_cert);
1955 os_free(cred->client_cert);
1956 os_free(cred->private_key);
1957 str_clear_free(cred->private_key_passwd);
1958 os_free(cred->imsi);
1959 str_clear_free(cred->milenage);
1960 for (i = 0; i < cred->num_domain; i++)
1961 os_free(cred->domain[i]);
1962 os_free(cred->domain);
1963 os_free(cred->domain_suffix_match);
1964 os_free(cred->eap_method);
1965 os_free(cred->phase1);
1966 os_free(cred->phase2);
1967 os_free(cred->excluded_ssid);
1968 os_free(cred->roaming_partner);
1969 os_free(cred->provisioning_sp);
1970 for (i = 0; i < cred->num_req_conn_capab; i++)
1971 os_free(cred->req_conn_capab_port[i]);
1972 os_free(cred->req_conn_capab_port);
1973 os_free(cred->req_conn_capab_proto);
1978 void wpa_config_flush_blobs(struct wpa_config *config)
1980 #ifndef CONFIG_NO_CONFIG_BLOBS
1981 struct wpa_config_blob *blob, *prev;
1983 blob = config->blobs;
1984 config->blobs = NULL;
1988 wpa_config_free_blob(prev);
1990 #endif /* CONFIG_NO_CONFIG_BLOBS */
1995 * wpa_config_free - Free configuration data
1996 * @config: Configuration data from wpa_config_read()
1998 * This function frees all resources allocated for the configuration data by
1999 * wpa_config_read().
2001 void wpa_config_free(struct wpa_config *config)
2003 struct wpa_ssid *ssid, *prev = NULL;
2004 struct wpa_cred *cred, *cprev;
2006 ssid = config->ssid;
2010 wpa_config_free_ssid(prev);
2013 cred = config->cred;
2017 wpa_config_free_cred(cprev);
2020 wpa_config_flush_blobs(config);
2022 wpabuf_free(config->wps_vendor_ext_m1);
2023 os_free(config->ctrl_interface);
2024 os_free(config->ctrl_interface_group);
2025 os_free(config->opensc_engine_path);
2026 os_free(config->pkcs11_engine_path);
2027 os_free(config->pkcs11_module_path);
2028 os_free(config->openssl_ciphers);
2029 os_free(config->pcsc_reader);
2030 str_clear_free(config->pcsc_pin);
2031 os_free(config->driver_param);
2032 os_free(config->device_name);
2033 os_free(config->manufacturer);
2034 os_free(config->model_name);
2035 os_free(config->model_number);
2036 os_free(config->serial_number);
2037 os_free(config->config_methods);
2038 os_free(config->p2p_ssid_postfix);
2039 os_free(config->pssid);
2040 os_free(config->p2p_pref_chan);
2041 os_free(config->p2p_no_go_freq.range);
2042 os_free(config->autoscan);
2043 os_free(config->freq_list);
2044 wpabuf_free(config->wps_nfc_dh_pubkey);
2045 wpabuf_free(config->wps_nfc_dh_privkey);
2046 wpabuf_free(config->wps_nfc_dev_pw);
2047 os_free(config->ext_password_backend);
2048 os_free(config->sae_groups);
2049 wpabuf_free(config->ap_vendor_elements);
2050 os_free(config->osu_dir);
2051 os_free(config->wowlan_triggers);
2057 * wpa_config_foreach_network - Iterate over each configured network
2058 * @config: Configuration data from wpa_config_read()
2059 * @func: Callback function to process each network
2060 * @arg: Opaque argument to pass to callback function
2062 * Iterate over the set of configured networks calling the specified
2063 * function for each item. We guard against callbacks removing the
2066 void wpa_config_foreach_network(struct wpa_config *config,
2067 void (*func)(void *, struct wpa_ssid *),
2070 struct wpa_ssid *ssid, *next;
2072 ssid = config->ssid;
2082 * wpa_config_get_network - Get configured network based on id
2083 * @config: Configuration data from wpa_config_read()
2084 * @id: Unique network id to search for
2085 * Returns: Network configuration or %NULL if not found
2087 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2089 struct wpa_ssid *ssid;
2091 ssid = config->ssid;
2103 * wpa_config_add_network - Add a new network with empty configuration
2104 * @config: Configuration data from wpa_config_read()
2105 * Returns: The new network configuration or %NULL if operation failed
2107 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2110 struct wpa_ssid *ssid, *last = NULL;
2113 ssid = config->ssid;
2122 ssid = os_zalloc(sizeof(*ssid));
2126 dl_list_init(&ssid->psk_list);
2130 config->ssid = ssid;
2132 wpa_config_update_prio_list(config);
2139 * wpa_config_remove_network - Remove a configured network based on id
2140 * @config: Configuration data from wpa_config_read()
2141 * @id: Unique network id to search for
2142 * Returns: 0 on success, or -1 if the network was not found
2144 int wpa_config_remove_network(struct wpa_config *config, int id)
2146 struct wpa_ssid *ssid, *prev = NULL;
2148 ssid = config->ssid;
2160 prev->next = ssid->next;
2162 config->ssid = ssid->next;
2164 wpa_config_update_prio_list(config);
2165 wpa_config_free_ssid(ssid);
2171 * wpa_config_set_network_defaults - Set network default values
2172 * @ssid: Pointer to network configuration data
2174 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2176 ssid->proto = DEFAULT_PROTO;
2177 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2178 ssid->group_cipher = DEFAULT_GROUP;
2179 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2180 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2181 #ifdef IEEE8021X_EAPOL
2182 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2183 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2184 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2185 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2186 #endif /* IEEE8021X_EAPOL */
2187 #ifdef CONFIG_HT_OVERRIDES
2188 ssid->disable_ht = DEFAULT_DISABLE_HT;
2189 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2190 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2191 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2192 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2193 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2194 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2195 #endif /* CONFIG_HT_OVERRIDES */
2196 #ifdef CONFIG_VHT_OVERRIDES
2197 ssid->vht_rx_mcs_nss_1 = -1;
2198 ssid->vht_rx_mcs_nss_2 = -1;
2199 ssid->vht_rx_mcs_nss_3 = -1;
2200 ssid->vht_rx_mcs_nss_4 = -1;
2201 ssid->vht_rx_mcs_nss_5 = -1;
2202 ssid->vht_rx_mcs_nss_6 = -1;
2203 ssid->vht_rx_mcs_nss_7 = -1;
2204 ssid->vht_rx_mcs_nss_8 = -1;
2205 ssid->vht_tx_mcs_nss_1 = -1;
2206 ssid->vht_tx_mcs_nss_2 = -1;
2207 ssid->vht_tx_mcs_nss_3 = -1;
2208 ssid->vht_tx_mcs_nss_4 = -1;
2209 ssid->vht_tx_mcs_nss_5 = -1;
2210 ssid->vht_tx_mcs_nss_6 = -1;
2211 ssid->vht_tx_mcs_nss_7 = -1;
2212 ssid->vht_tx_mcs_nss_8 = -1;
2213 #endif /* CONFIG_VHT_OVERRIDES */
2214 ssid->proactive_key_caching = -1;
2215 #ifdef CONFIG_IEEE80211W
2216 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2217 #endif /* CONFIG_IEEE80211W */
2218 ssid->mac_addr = -1;
2223 * wpa_config_set - Set a variable in network configuration
2224 * @ssid: Pointer to network configuration data
2225 * @var: Variable name, e.g., "ssid"
2226 * @value: Variable value
2227 * @line: Line number in configuration file or 0 if not used
2228 * Returns: 0 on success, -1 on failure
2230 * This function can be used to set network configuration variables based on
2231 * both the configuration file and management interface input. The value
2232 * parameter must be in the same format as the text-based configuration file is
2233 * using. For example, strings are using double quotation marks.
2235 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2241 if (ssid == NULL || var == NULL || value == NULL)
2244 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2245 const struct parse_data *field = &ssid_fields[i];
2246 if (os_strcmp(var, field->name) != 0)
2249 if (field->parser(field, ssid, line, value)) {
2251 wpa_printf(MSG_ERROR, "Line %d: failed to "
2252 "parse %s '%s'.", line, var, value);
2258 if (i == NUM_SSID_FIELDS) {
2260 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2261 "'%s'.", line, var);
2270 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2277 len = os_strlen(value);
2278 buf = os_malloc(len + 3);
2282 os_memcpy(buf + 1, value, len);
2284 buf[len + 2] = '\0';
2285 ret = wpa_config_set(ssid, var, buf, 0);
2292 * wpa_config_get_all - Get all options from network configuration
2293 * @ssid: Pointer to network configuration data
2294 * @get_keys: Determines if keys/passwords will be included in returned list
2295 * (if they may be exported)
2296 * Returns: %NULL terminated list of all set keys and their values in the form
2297 * of [key1, val1, key2, val2, ... , NULL]
2299 * This function can be used to get list of all configured network properties.
2300 * The caller is responsible for freeing the returned list and all its
2303 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2305 const struct parse_data *field;
2311 get_keys = get_keys && ssid->export_keys;
2313 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2318 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2319 field = &ssid_fields[i];
2320 if (field->key_data && !get_keys)
2322 value = field->writer(field, ssid);
2325 if (os_strlen(value) == 0) {
2330 key = os_strdup(field->name);
2336 props[fields_num * 2] = key;
2337 props[fields_num * 2 + 1] = value;
2353 #ifndef NO_CONFIG_WRITE
2355 * wpa_config_get - Get a variable in network configuration
2356 * @ssid: Pointer to network configuration data
2357 * @var: Variable name, e.g., "ssid"
2358 * Returns: Value of the variable or %NULL on failure
2360 * This function can be used to get network configuration variables. The
2361 * returned value is a copy of the configuration variable in text format, i.e,.
2362 * the same format that the text-based configuration file and wpa_config_set()
2363 * are using for the value. The caller is responsible for freeing the returned
2366 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2370 if (ssid == NULL || var == NULL)
2373 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2374 const struct parse_data *field = &ssid_fields[i];
2375 if (os_strcmp(var, field->name) == 0)
2376 return field->writer(field, ssid);
2384 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2385 * @ssid: Pointer to network configuration data
2386 * @var: Variable name, e.g., "ssid"
2387 * Returns: Value of the variable or %NULL on failure
2389 * This function can be used to get network configuration variable like
2390 * wpa_config_get(). The only difference is that this functions does not expose
2391 * key/password material from the configuration. In case a key/password field
2392 * is requested, the returned value is an empty string or %NULL if the variable
2393 * is not set or "*" if the variable is set (regardless of its value). The
2394 * returned value is a copy of the configuration variable in text format, i.e,.
2395 * the same format that the text-based configuration file and wpa_config_set()
2396 * are using for the value. The caller is responsible for freeing the returned
2399 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2403 if (ssid == NULL || var == NULL)
2406 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2407 const struct parse_data *field = &ssid_fields[i];
2408 if (os_strcmp(var, field->name) == 0) {
2409 char *res = field->writer(field, ssid);
2410 if (field->key_data) {
2411 if (res && res[0]) {
2412 wpa_printf(MSG_DEBUG, "Do not allow "
2413 "key_data field to be "
2415 str_clear_free(res);
2416 return os_strdup("*");
2428 #endif /* NO_CONFIG_WRITE */
2432 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2433 * @ssid: Pointer to network configuration data
2435 * This function must be called to update WPA PSK when either SSID or the
2436 * passphrase has changed for the network configuration.
2438 void wpa_config_update_psk(struct wpa_ssid *ssid)
2440 #ifndef CONFIG_NO_PBKDF2
2441 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2442 ssid->psk, PMK_LEN);
2443 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2444 ssid->psk, PMK_LEN);
2446 #endif /* CONFIG_NO_PBKDF2 */
2450 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2455 int *ports, *nports;
2457 unsigned int num_ports;
2459 proto = os_realloc_array(cred->req_conn_capab_proto,
2460 cred->num_req_conn_capab + 1, sizeof(u8));
2463 cred->req_conn_capab_proto = proto;
2465 port = os_realloc_array(cred->req_conn_capab_port,
2466 cred->num_req_conn_capab + 1, sizeof(int *));
2469 cred->req_conn_capab_port = port;
2471 proto[cred->num_req_conn_capab] = atoi(value);
2473 pos = os_strchr(value, ':');
2475 port[cred->num_req_conn_capab] = NULL;
2476 cred->num_req_conn_capab++;
2485 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2486 if (nports == NULL) {
2491 ports[num_ports++] = atoi(pos);
2493 pos = os_strchr(pos, ',');
2499 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2500 if (nports == NULL) {
2505 ports[num_ports] = -1;
2507 port[cred->num_req_conn_capab] = ports;
2508 cred->num_req_conn_capab++;
2513 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2514 const char *value, int line)
2519 if (os_strcmp(var, "temporary") == 0) {
2520 cred->temporary = atoi(value);
2524 if (os_strcmp(var, "priority") == 0) {
2525 cred->priority = atoi(value);
2529 if (os_strcmp(var, "sp_priority") == 0) {
2530 int prio = atoi(value);
2531 if (prio < 0 || prio > 255)
2533 cred->sp_priority = prio;
2537 if (os_strcmp(var, "pcsc") == 0) {
2538 cred->pcsc = atoi(value);
2542 if (os_strcmp(var, "eap") == 0) {
2543 struct eap_method_type method;
2544 method.method = eap_peer_get_type(value, &method.vendor);
2545 if (method.vendor == EAP_VENDOR_IETF &&
2546 method.method == EAP_TYPE_NONE) {
2547 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2548 "for a credential", line, value);
2551 os_free(cred->eap_method);
2552 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2553 if (cred->eap_method == NULL)
2555 os_memcpy(cred->eap_method, &method, sizeof(method));
2559 if (os_strcmp(var, "password") == 0 &&
2560 os_strncmp(value, "ext:", 4) == 0) {
2561 str_clear_free(cred->password);
2562 cred->password = os_strdup(value);
2563 cred->ext_password = 1;
2567 if (os_strcmp(var, "update_identifier") == 0) {
2568 cred->update_identifier = atoi(value);
2572 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2573 cred->min_dl_bandwidth_home = atoi(value);
2577 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2578 cred->min_ul_bandwidth_home = atoi(value);
2582 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2583 cred->min_dl_bandwidth_roaming = atoi(value);
2587 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2588 cred->min_ul_bandwidth_roaming = atoi(value);
2592 if (os_strcmp(var, "max_bss_load") == 0) {
2593 cred->max_bss_load = atoi(value);
2597 if (os_strcmp(var, "req_conn_capab") == 0)
2598 return wpa_config_set_cred_req_conn_capab(cred, value);
2600 if (os_strcmp(var, "ocsp") == 0) {
2601 cred->ocsp = atoi(value);
2605 if (os_strcmp(var, "sim_num") == 0) {
2606 cred->sim_num = atoi(value);
2610 val = wpa_config_parse_string(value, &len);
2612 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2613 "value '%s'.", line, var, value);
2617 if (os_strcmp(var, "realm") == 0) {
2618 os_free(cred->realm);
2623 if (os_strcmp(var, "username") == 0) {
2624 str_clear_free(cred->username);
2625 cred->username = val;
2629 if (os_strcmp(var, "password") == 0) {
2630 str_clear_free(cred->password);
2631 cred->password = val;
2632 cred->ext_password = 0;
2636 if (os_strcmp(var, "ca_cert") == 0) {
2637 os_free(cred->ca_cert);
2638 cred->ca_cert = val;
2642 if (os_strcmp(var, "client_cert") == 0) {
2643 os_free(cred->client_cert);
2644 cred->client_cert = val;
2648 if (os_strcmp(var, "private_key") == 0) {
2649 os_free(cred->private_key);
2650 cred->private_key = val;
2654 if (os_strcmp(var, "private_key_passwd") == 0) {
2655 str_clear_free(cred->private_key_passwd);
2656 cred->private_key_passwd = val;
2660 if (os_strcmp(var, "imsi") == 0) {
2661 os_free(cred->imsi);
2666 if (os_strcmp(var, "milenage") == 0) {
2667 str_clear_free(cred->milenage);
2668 cred->milenage = val;
2672 if (os_strcmp(var, "domain_suffix_match") == 0) {
2673 os_free(cred->domain_suffix_match);
2674 cred->domain_suffix_match = val;
2678 if (os_strcmp(var, "domain") == 0) {
2680 new_domain = os_realloc_array(cred->domain,
2681 cred->num_domain + 1,
2683 if (new_domain == NULL) {
2687 new_domain[cred->num_domain++] = val;
2688 cred->domain = new_domain;
2692 if (os_strcmp(var, "phase1") == 0) {
2693 os_free(cred->phase1);
2698 if (os_strcmp(var, "phase2") == 0) {
2699 os_free(cred->phase2);
2704 if (os_strcmp(var, "roaming_consortium") == 0) {
2705 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2706 wpa_printf(MSG_ERROR, "Line %d: invalid "
2707 "roaming_consortium length %d (3..15 "
2708 "expected)", line, (int) len);
2712 os_memcpy(cred->roaming_consortium, val, len);
2713 cred->roaming_consortium_len = len;
2718 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2719 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2721 wpa_printf(MSG_ERROR, "Line %d: invalid "
2722 "required_roaming_consortium length %d "
2723 "(3..15 expected)", line, (int) len);
2727 os_memcpy(cred->required_roaming_consortium, val, len);
2728 cred->required_roaming_consortium_len = len;
2733 if (os_strcmp(var, "excluded_ssid") == 0) {
2734 struct excluded_ssid *e;
2736 if (len > MAX_SSID_LEN) {
2737 wpa_printf(MSG_ERROR, "Line %d: invalid "
2738 "excluded_ssid length %d", line, (int) len);
2743 e = os_realloc_array(cred->excluded_ssid,
2744 cred->num_excluded_ssid + 1,
2745 sizeof(struct excluded_ssid));
2750 cred->excluded_ssid = e;
2752 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2753 os_memcpy(e->ssid, val, len);
2761 if (os_strcmp(var, "roaming_partner") == 0) {
2762 struct roaming_partner *p;
2765 p = os_realloc_array(cred->roaming_partner,
2766 cred->num_roaming_partner + 1,
2767 sizeof(struct roaming_partner));
2772 cred->roaming_partner = p;
2774 p = &cred->roaming_partner[cred->num_roaming_partner];
2776 pos = os_strchr(val, ',');
2782 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2786 os_memcpy(p->fqdn, val, pos - val);
2788 p->exact_match = atoi(pos);
2790 pos = os_strchr(pos, ',');
2797 p->priority = atoi(pos);
2799 pos = os_strchr(pos, ',');
2806 if (os_strlen(pos) >= sizeof(p->country)) {
2810 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2812 cred->num_roaming_partner++;
2818 if (os_strcmp(var, "provisioning_sp") == 0) {
2819 os_free(cred->provisioning_sp);
2820 cred->provisioning_sp = val;
2825 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2835 static char * alloc_int_str(int val)
2839 buf = os_malloc(20);
2842 os_snprintf(buf, 20, "%d", val);
2847 static char * alloc_strdup(const char *str)
2851 return os_strdup(str);
2855 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2857 if (os_strcmp(var, "temporary") == 0)
2858 return alloc_int_str(cred->temporary);
2860 if (os_strcmp(var, "priority") == 0)
2861 return alloc_int_str(cred->priority);
2863 if (os_strcmp(var, "sp_priority") == 0)
2864 return alloc_int_str(cred->sp_priority);
2866 if (os_strcmp(var, "pcsc") == 0)
2867 return alloc_int_str(cred->pcsc);
2869 if (os_strcmp(var, "eap") == 0) {
2870 if (!cred->eap_method)
2872 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2873 cred->eap_method[0].method));
2876 if (os_strcmp(var, "update_identifier") == 0)
2877 return alloc_int_str(cred->update_identifier);
2879 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
2880 return alloc_int_str(cred->min_dl_bandwidth_home);
2882 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
2883 return alloc_int_str(cred->min_ul_bandwidth_home);
2885 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
2886 return alloc_int_str(cred->min_dl_bandwidth_roaming);
2888 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
2889 return alloc_int_str(cred->min_ul_bandwidth_roaming);
2891 if (os_strcmp(var, "max_bss_load") == 0)
2892 return alloc_int_str(cred->max_bss_load);
2894 if (os_strcmp(var, "req_conn_capab") == 0) {
2896 char *buf, *end, *pos;
2899 if (!cred->num_req_conn_capab)
2902 buf = os_malloc(4000);
2907 for (i = 0; i < cred->num_req_conn_capab; i++) {
2910 ret = os_snprintf(pos, end - pos, "%s%u",
2912 cred->req_conn_capab_proto[i]);
2913 if (ret < 0 || ret >= end - pos)
2917 ports = cred->req_conn_capab_port[i];
2920 for (j = 0; ports[j] != -1; j++) {
2921 ret = os_snprintf(pos, end - pos,
2925 if (ret < 0 || ret >= end - pos)
2935 if (os_strcmp(var, "ocsp") == 0)
2936 return alloc_int_str(cred->ocsp);
2938 if (os_strcmp(var, "realm") == 0)
2939 return alloc_strdup(cred->realm);
2941 if (os_strcmp(var, "username") == 0)
2942 return alloc_strdup(cred->username);
2944 if (os_strcmp(var, "password") == 0) {
2945 if (!cred->password)
2947 return alloc_strdup("*");
2950 if (os_strcmp(var, "ca_cert") == 0)
2951 return alloc_strdup(cred->ca_cert);
2953 if (os_strcmp(var, "client_cert") == 0)
2954 return alloc_strdup(cred->client_cert);
2956 if (os_strcmp(var, "private_key") == 0)
2957 return alloc_strdup(cred->private_key);
2959 if (os_strcmp(var, "private_key_passwd") == 0) {
2960 if (!cred->private_key_passwd)
2962 return alloc_strdup("*");
2965 if (os_strcmp(var, "imsi") == 0)
2966 return alloc_strdup(cred->imsi);
2968 if (os_strcmp(var, "milenage") == 0) {
2969 if (!(cred->milenage))
2971 return alloc_strdup("*");
2974 if (os_strcmp(var, "domain_suffix_match") == 0)
2975 return alloc_strdup(cred->domain_suffix_match);
2977 if (os_strcmp(var, "domain") == 0) {
2979 char *buf, *end, *pos;
2982 if (!cred->num_domain)
2985 buf = os_malloc(4000);
2991 for (i = 0; i < cred->num_domain; i++) {
2992 ret = os_snprintf(pos, end - pos, "%s%s",
2993 i > 0 ? "\n" : "", cred->domain[i]);
2994 if (ret < 0 || ret >= end - pos)
3002 if (os_strcmp(var, "phase1") == 0)
3003 return alloc_strdup(cred->phase1);
3005 if (os_strcmp(var, "phase2") == 0)
3006 return alloc_strdup(cred->phase2);
3008 if (os_strcmp(var, "roaming_consortium") == 0) {
3012 if (!cred->roaming_consortium_len)
3014 buflen = cred->roaming_consortium_len * 2 + 1;
3015 buf = os_malloc(buflen);
3018 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3019 cred->roaming_consortium_len);
3023 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3027 if (!cred->required_roaming_consortium_len)
3029 buflen = cred->required_roaming_consortium_len * 2 + 1;
3030 buf = os_malloc(buflen);
3033 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3034 cred->required_roaming_consortium_len);
3038 if (os_strcmp(var, "excluded_ssid") == 0) {
3040 char *buf, *end, *pos;
3042 if (!cred->num_excluded_ssid)
3045 buf = os_malloc(4000);
3051 for (i = 0; i < cred->num_excluded_ssid; i++) {
3052 struct excluded_ssid *e;
3055 e = &cred->excluded_ssid[i];
3056 ret = os_snprintf(pos, end - pos, "%s%s",
3058 wpa_ssid_txt(e->ssid, e->ssid_len));
3059 if (ret < 0 || ret >= end - pos)
3067 if (os_strcmp(var, "roaming_partner") == 0) {
3069 char *buf, *end, *pos;
3071 if (!cred->num_roaming_partner)
3074 buf = os_malloc(4000);
3080 for (i = 0; i < cred->num_roaming_partner; i++) {
3081 struct roaming_partner *p;
3084 p = &cred->roaming_partner[i];
3085 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3087 p->fqdn, p->exact_match, p->priority,
3089 if (ret < 0 || ret >= end - pos)
3097 if (os_strcmp(var, "provisioning_sp") == 0)
3098 return alloc_strdup(cred->provisioning_sp);
3104 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3106 struct wpa_cred *cred;
3108 cred = config->cred;
3119 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3122 struct wpa_cred *cred, *last = NULL;
3125 cred = config->cred;
3134 cred = os_zalloc(sizeof(*cred));
3138 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3142 config->cred = cred;
3148 int wpa_config_remove_cred(struct wpa_config *config, int id)
3150 struct wpa_cred *cred, *prev = NULL;
3152 cred = config->cred;
3164 prev->next = cred->next;
3166 config->cred = cred->next;
3168 wpa_config_free_cred(cred);
3173 #ifndef CONFIG_NO_CONFIG_BLOBS
3175 * wpa_config_get_blob - Get a named configuration blob
3176 * @config: Configuration data from wpa_config_read()
3177 * @name: Name of the blob
3178 * Returns: Pointer to blob data or %NULL if not found
3180 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3183 struct wpa_config_blob *blob = config->blobs;
3186 if (os_strcmp(blob->name, name) == 0)
3195 * wpa_config_set_blob - Set or add a named configuration blob
3196 * @config: Configuration data from wpa_config_read()
3197 * @blob: New value for the blob
3199 * Adds a new configuration blob or replaces the current value of an existing
3202 void wpa_config_set_blob(struct wpa_config *config,
3203 struct wpa_config_blob *blob)
3205 wpa_config_remove_blob(config, blob->name);
3206 blob->next = config->blobs;
3207 config->blobs = blob;
3212 * wpa_config_free_blob - Free blob data
3213 * @blob: Pointer to blob to be freed
3215 void wpa_config_free_blob(struct wpa_config_blob *blob)
3218 os_free(blob->name);
3219 bin_clear_free(blob->data, blob->len);
3226 * wpa_config_remove_blob - Remove a named configuration blob
3227 * @config: Configuration data from wpa_config_read()
3228 * @name: Name of the blob to remove
3229 * Returns: 0 if blob was removed or -1 if blob was not found
3231 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3233 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3236 if (os_strcmp(pos->name, name) == 0) {
3238 prev->next = pos->next;
3240 config->blobs = pos->next;
3241 wpa_config_free_blob(pos);
3250 #endif /* CONFIG_NO_CONFIG_BLOBS */
3254 * wpa_config_alloc_empty - Allocate an empty configuration
3255 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3257 * @driver_param: Driver parameters
3258 * Returns: Pointer to allocated configuration data or %NULL on failure
3260 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3261 const char *driver_param)
3263 struct wpa_config *config;
3264 const int aCWmin = 4, aCWmax = 10;
3265 const struct hostapd_wmm_ac_params ac_bk =
3266 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3267 const struct hostapd_wmm_ac_params ac_be =
3268 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3269 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3270 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3271 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3272 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3274 config = os_zalloc(sizeof(*config));
3277 config->eapol_version = DEFAULT_EAPOL_VERSION;
3278 config->ap_scan = DEFAULT_AP_SCAN;
3279 config->fast_reauth = DEFAULT_FAST_REAUTH;
3280 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3281 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3282 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3283 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3284 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3285 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3286 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3287 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3288 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3289 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3290 config->wmm_ac_params[0] = ac_be;
3291 config->wmm_ac_params[1] = ac_bk;
3292 config->wmm_ac_params[2] = ac_vi;
3293 config->wmm_ac_params[3] = ac_vo;
3294 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3295 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3298 config->ctrl_interface = os_strdup(ctrl_interface);
3300 config->driver_param = os_strdup(driver_param);
3306 #ifndef CONFIG_NO_STDOUT_DEBUG
3308 * wpa_config_debug_dump_networks - Debug dump of configured networks
3309 * @config: Configuration data from wpa_config_read()
3311 void wpa_config_debug_dump_networks(struct wpa_config *config)
3314 struct wpa_ssid *ssid;
3316 for (prio = 0; prio < config->num_prio; prio++) {
3317 ssid = config->pssid[prio];
3318 wpa_printf(MSG_DEBUG, "Priority group %d",
3321 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3323 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3328 #endif /* CONFIG_NO_STDOUT_DEBUG */
3331 struct global_parse_data {
3333 int (*parser)(const struct global_parse_data *data,
3334 struct wpa_config *config, int line, const char *value);
3335 void *param1, *param2, *param3;
3336 unsigned int changed_flag;
3340 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3341 struct wpa_config *config, int line,
3347 dst = (int *) (((u8 *) config) + (long) data->param1);
3348 val = strtol(pos, &end, 0);
3350 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3356 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3358 if (data->param2 && *dst < (long) data->param2) {
3359 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3360 "min_value=%ld)", line, data->name, *dst,
3361 (long) data->param2);
3362 *dst = (long) data->param2;
3366 if (data->param3 && *dst > (long) data->param3) {
3367 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3368 "max_value=%ld)", line, data->name, *dst,
3369 (long) data->param3);
3370 *dst = (long) data->param3;
3378 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3379 struct wpa_config *config, int line,
3385 len = os_strlen(pos);
3386 if (data->param2 && len < (size_t) data->param2) {
3387 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3388 "min_len=%ld)", line, data->name,
3389 (unsigned long) len, (long) data->param2);
3393 if (data->param3 && len > (size_t) data->param3) {
3394 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3395 "max_len=%ld)", line, data->name,
3396 (unsigned long) len, (long) data->param3);
3400 tmp = os_strdup(pos);
3404 dst = (char **) (((u8 *) config) + (long) data->param1);
3407 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3413 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3414 struct wpa_config *config, int line,
3421 tmp = wpa_config_parse_string(pos, &len);
3423 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3428 res = wpa_global_config_parse_str(data, config, line, tmp);
3434 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3435 struct wpa_config *config, int line,
3439 struct wpabuf **dst, *tmp;
3441 len = os_strlen(pos);
3445 tmp = wpabuf_alloc(len / 2);
3449 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3454 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3457 wpa_printf(MSG_DEBUG, "%s", data->name);
3463 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3464 struct wpa_config *config, int line,
3469 freqs = wpa_config_parse_int_array(value);
3472 if (freqs[0] == 0) {
3476 os_free(config->freq_list);
3477 config->freq_list = freqs;
3483 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3484 struct wpa_config *config, int line,
3488 struct hostapd_ip_addr addr;
3490 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3492 if (addr.af != AF_INET)
3495 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3496 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3497 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3498 WPA_GET_BE32((u8 *) dst));
3502 #endif /* CONFIG_P2P */
3505 static int wpa_config_process_country(const struct global_parse_data *data,
3506 struct wpa_config *config, int line,
3509 if (!pos[0] || !pos[1]) {
3510 wpa_printf(MSG_DEBUG, "Invalid country set");
3513 config->country[0] = pos[0];
3514 config->country[1] = pos[1];
3515 wpa_printf(MSG_DEBUG, "country='%c%c'",
3516 config->country[0], config->country[1]);
3521 static int wpa_config_process_load_dynamic_eap(
3522 const struct global_parse_data *data, struct wpa_config *config,
3523 int line, const char *so)
3526 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3527 ret = eap_peer_method_load(so);
3529 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3532 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3533 "method '%s'.", line, so);
3543 static int wpa_config_process_uuid(const struct global_parse_data *data,
3544 struct wpa_config *config, int line,
3548 if (uuid_str2bin(pos, config->uuid)) {
3549 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3552 uuid_bin2str(config->uuid, buf, sizeof(buf));
3553 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3558 static int wpa_config_process_device_type(
3559 const struct global_parse_data *data,
3560 struct wpa_config *config, int line, const char *pos)
3562 return wps_dev_type_str2bin(pos, config->device_type);
3566 static int wpa_config_process_os_version(const struct global_parse_data *data,
3567 struct wpa_config *config, int line,
3570 if (hexstr2bin(pos, config->os_version, 4)) {
3571 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3574 wpa_printf(MSG_DEBUG, "os_version=%08x",
3575 WPA_GET_BE32(config->os_version));
3580 static int wpa_config_process_wps_vendor_ext_m1(
3581 const struct global_parse_data *data,
3582 struct wpa_config *config, int line, const char *pos)
3585 int len = os_strlen(pos) / 2;
3589 wpa_printf(MSG_ERROR, "Line %d: "
3590 "invalid wps_vendor_ext_m1", line);
3594 tmp = wpabuf_alloc(len);
3596 p = wpabuf_put(tmp, len);
3598 if (hexstr2bin(pos, p, len)) {
3599 wpa_printf(MSG_ERROR, "Line %d: "
3600 "invalid wps_vendor_ext_m1", line);
3605 wpabuf_free(config->wps_vendor_ext_m1);
3606 config->wps_vendor_ext_m1 = tmp;
3608 wpa_printf(MSG_ERROR, "Can not allocate "
3609 "memory for wps_vendor_ext_m1");
3616 #endif /* CONFIG_WPS */
3619 static int wpa_config_process_sec_device_type(
3620 const struct global_parse_data *data,
3621 struct wpa_config *config, int line, const char *pos)
3625 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3626 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3631 idx = config->num_sec_device_types;
3633 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3636 config->num_sec_device_types++;
3641 static int wpa_config_process_p2p_pref_chan(
3642 const struct global_parse_data *data,
3643 struct wpa_config *config, int line, const char *pos)
3645 struct p2p_channel *pref = NULL, *n;
3646 unsigned int num = 0;
3650 /* format: class:chan,class:chan,... */
3653 op_class = atoi(pos);
3654 pos2 = os_strchr(pos, ':');
3660 n = os_realloc_array(pref, num + 1,
3661 sizeof(struct p2p_channel));
3665 pref[num].op_class = op_class;
3666 pref[num].chan = chan;
3669 pos = os_strchr(pos2, ',');
3675 os_free(config->p2p_pref_chan);
3676 config->p2p_pref_chan = pref;
3677 config->num_p2p_pref_chan = num;
3678 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3679 (u8 *) config->p2p_pref_chan,
3680 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3686 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3691 static int wpa_config_process_p2p_no_go_freq(
3692 const struct global_parse_data *data,
3693 struct wpa_config *config, int line, const char *pos)
3697 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3699 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3703 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3704 config->p2p_no_go_freq.num);
3709 #endif /* CONFIG_P2P */
3712 static int wpa_config_process_hessid(
3713 const struct global_parse_data *data,
3714 struct wpa_config *config, int line, const char *pos)
3716 if (hwaddr_aton2(pos, config->hessid) < 0) {
3717 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3726 static int wpa_config_process_sae_groups(
3727 const struct global_parse_data *data,
3728 struct wpa_config *config, int line, const char *pos)
3730 int *groups = wpa_config_parse_int_array(pos);
3731 if (groups == NULL) {
3732 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3737 os_free(config->sae_groups);
3738 config->sae_groups = groups;
3744 static int wpa_config_process_ap_vendor_elements(
3745 const struct global_parse_data *data,
3746 struct wpa_config *config, int line, const char *pos)
3749 int len = os_strlen(pos) / 2;
3753 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3758 tmp = wpabuf_alloc(len);
3760 p = wpabuf_put(tmp, len);
3762 if (hexstr2bin(pos, p, len)) {
3763 wpa_printf(MSG_ERROR, "Line %d: invalid "
3764 "ap_vendor_elements", line);
3769 wpabuf_free(config->ap_vendor_elements);
3770 config->ap_vendor_elements = tmp;
3772 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3773 "ap_vendor_elements");
3781 #ifdef CONFIG_CTRL_IFACE
3782 static int wpa_config_process_no_ctrl_interface(
3783 const struct global_parse_data *data,
3784 struct wpa_config *config, int line, const char *pos)
3786 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3787 os_free(config->ctrl_interface);
3788 config->ctrl_interface = NULL;
3791 #endif /* CONFIG_CTRL_IFACE */
3797 /* OFFSET: Get offset of a variable within the wpa_config structure */
3798 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3800 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3801 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3802 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3803 #define INT(f) _INT(f), NULL, NULL
3804 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3805 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3806 #define STR(f) _STR(f), NULL, NULL
3807 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3808 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3809 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3811 static const struct global_parse_data global_fields[] = {
3812 #ifdef CONFIG_CTRL_IFACE
3813 { STR(ctrl_interface), 0 },
3814 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3815 { STR(ctrl_interface_group), 0 } /* deprecated */,
3816 #endif /* CONFIG_CTRL_IFACE */
3817 #ifdef CONFIG_MACSEC
3818 { INT_RANGE(eapol_version, 1, 3), 0 },
3819 #else /* CONFIG_MACSEC */
3820 { INT_RANGE(eapol_version, 1, 2), 0 },
3821 #endif /* CONFIG_MACSEC */
3822 { INT(ap_scan), 0 },
3823 { FUNC(bgscan), 0 },
3824 { INT(disable_scan_offload), 0 },
3825 { INT(fast_reauth), 0 },
3826 { STR(opensc_engine_path), 0 },
3827 { STR(pkcs11_engine_path), 0 },
3828 { STR(pkcs11_module_path), 0 },
3829 { STR(openssl_ciphers), 0 },
3830 { STR(pcsc_reader), 0 },
3831 { STR(pcsc_pin), 0 },
3832 { INT(external_sim), 0 },
3833 { STR(driver_param), 0 },
3834 { INT(dot11RSNAConfigPMKLifetime), 0 },
3835 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3836 { INT(dot11RSNAConfigSATimeout), 0 },
3837 #ifndef CONFIG_NO_CONFIG_WRITE
3838 { INT(update_config), 0 },
3839 #endif /* CONFIG_NO_CONFIG_WRITE */
3840 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3842 { FUNC(uuid), CFG_CHANGED_UUID },
3843 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3844 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3845 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3846 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3847 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3848 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3849 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3850 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3851 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3852 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3853 #endif /* CONFIG_WPS */
3855 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3856 { INT(p2p_listen_reg_class), 0 },
3857 { INT(p2p_listen_channel), 0 },
3858 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3859 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3860 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3861 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3862 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3863 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3864 { INT(p2p_group_idle), 0 },
3865 { INT_RANGE(p2p_passphrase_len, 8, 63),
3866 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3867 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3868 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3869 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3870 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3871 { INT(p2p_go_ht40), 0 },
3872 { INT(p2p_go_vht), 0 },
3873 { INT(p2p_disabled), 0 },
3874 { INT(p2p_no_group_iface), 0 },
3875 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
3876 { IPV4(ip_addr_go), 0 },
3877 { IPV4(ip_addr_mask), 0 },
3878 { IPV4(ip_addr_start), 0 },
3879 { IPV4(ip_addr_end), 0 },
3880 #endif /* CONFIG_P2P */
3881 { FUNC(country), CFG_CHANGED_COUNTRY },
3882 { INT(bss_max_count), 0 },
3883 { INT(bss_expiration_age), 0 },
3884 { INT(bss_expiration_scan_count), 0 },
3885 { INT_RANGE(filter_ssids, 0, 1), 0 },
3886 { INT_RANGE(filter_rssi, -100, 0), 0 },
3887 { INT(max_num_sta), 0 },
3888 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3890 { INT_RANGE(hs20, 0, 1), 0 },
3891 #endif /* CONFIG_HS20 */
3892 { INT_RANGE(interworking, 0, 1), 0 },
3893 { FUNC(hessid), 0 },
3894 { INT_RANGE(access_network_type, 0, 15), 0 },
3895 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3896 { STR(autoscan), 0 },
3897 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3898 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3899 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3900 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3901 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3902 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3903 { INT(p2p_go_max_inactivity), 0 },
3904 { INT_RANGE(auto_interworking, 0, 1), 0 },
3907 { FUNC(sae_groups), 0 },
3908 { INT(dtim_period), 0 },
3909 { INT(beacon_int), 0 },
3910 { FUNC(ap_vendor_elements), 0 },
3911 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
3912 { FUNC(freq_list), 0 },
3913 { INT(scan_cur_freq), 0 },
3914 { INT(sched_scan_interval), 0 },
3915 { INT(tdls_external_control), 0},
3916 { STR(osu_dir), 0 },
3917 { STR(wowlan_triggers), 0 },
3918 { INT(p2p_search_delay), 0},
3919 { INT(mac_addr), 0 },
3920 { INT(rand_addr_lifetime), 0 },
3921 { INT(preassoc_mac_addr), 0 },
3933 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
3936 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3941 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3942 const struct global_parse_data *field = &global_fields[i];
3943 size_t flen = os_strlen(field->name);
3944 if (os_strncmp(pos, field->name, flen) != 0 ||
3948 if (field->parser(field, config, line, pos + flen + 1)) {
3949 wpa_printf(MSG_ERROR, "Line %d: failed to "
3950 "parse '%s'.", line, pos);
3953 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
3954 config->wps_nfc_pw_from_config = 1;
3955 config->changed_parameters |= field->changed_flag;
3958 if (i == NUM_GLOBAL_FIELDS) {
3960 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
3961 char *tmp = os_strchr(pos, '=');
3965 wpa_printf(MSG_ERROR, "Line %d: invalid line "
3970 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
3972 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
3977 #endif /* CONFIG_AP */
3980 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",