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 */
681 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
682 ret = os_snprintf(pos, end - pos, "%sSAE",
683 pos == buf ? "" : " ");
684 if (ret < 0 || ret >= end - pos) {
691 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
692 ret = os_snprintf(pos, end - pos, "%sFT-SAE",
693 pos == buf ? "" : " ");
694 if (ret < 0 || ret >= end - pos) {
700 #endif /* CONFIG_SAE */
703 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) {
704 ret = os_snprintf(pos, end - pos, "%sOSEN",
705 pos == buf ? "" : " ");
706 if (ret < 0 || ret >= end - pos) {
712 #endif /* CONFIG_HS20 */
721 #endif /* NO_CONFIG_WRITE */
724 static int wpa_config_parse_cipher(int line, const char *value)
726 int val = wpa_parse_cipher(value);
728 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
733 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
741 #ifndef NO_CONFIG_WRITE
742 static char * wpa_config_write_cipher(int cipher)
744 char *buf = os_zalloc(50);
748 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
755 #endif /* NO_CONFIG_WRITE */
758 static int wpa_config_parse_pairwise(const struct parse_data *data,
759 struct wpa_ssid *ssid, int line,
763 val = wpa_config_parse_cipher(line, value);
766 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
767 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
768 "(0x%x).", line, val);
772 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
773 ssid->pairwise_cipher = val;
778 #ifndef NO_CONFIG_WRITE
779 static char * wpa_config_write_pairwise(const struct parse_data *data,
780 struct wpa_ssid *ssid)
782 return wpa_config_write_cipher(ssid->pairwise_cipher);
784 #endif /* NO_CONFIG_WRITE */
787 static int wpa_config_parse_group(const struct parse_data *data,
788 struct wpa_ssid *ssid, int line,
792 val = wpa_config_parse_cipher(line, value);
795 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
796 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
797 "(0x%x).", line, val);
801 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
802 ssid->group_cipher = val;
807 #ifndef NO_CONFIG_WRITE
808 static char * wpa_config_write_group(const struct parse_data *data,
809 struct wpa_ssid *ssid)
811 return wpa_config_write_cipher(ssid->group_cipher);
813 #endif /* NO_CONFIG_WRITE */
816 static int wpa_config_parse_auth_alg(const struct parse_data *data,
817 struct wpa_ssid *ssid, int line,
820 int val = 0, last, errors = 0;
821 char *start, *end, *buf;
823 buf = os_strdup(value);
828 while (*start != '\0') {
829 while (*start == ' ' || *start == '\t')
834 while (*end != ' ' && *end != '\t' && *end != '\0')
838 if (os_strcmp(start, "OPEN") == 0)
839 val |= WPA_AUTH_ALG_OPEN;
840 else if (os_strcmp(start, "SHARED") == 0)
841 val |= WPA_AUTH_ALG_SHARED;
842 else if (os_strcmp(start, "LEAP") == 0)
843 val |= WPA_AUTH_ALG_LEAP;
845 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
857 wpa_printf(MSG_ERROR,
858 "Line %d: no auth_alg values configured.", line);
862 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
863 ssid->auth_alg = val;
864 return errors ? -1 : 0;
868 #ifndef NO_CONFIG_WRITE
869 static char * wpa_config_write_auth_alg(const struct parse_data *data,
870 struct wpa_ssid *ssid)
872 char *buf, *pos, *end;
875 pos = buf = os_zalloc(30);
880 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
881 ret = os_snprintf(pos, end - pos, "%sOPEN",
882 pos == buf ? "" : " ");
883 if (ret < 0 || ret >= end - pos) {
890 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
891 ret = os_snprintf(pos, end - pos, "%sSHARED",
892 pos == buf ? "" : " ");
893 if (ret < 0 || ret >= end - pos) {
900 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
901 ret = os_snprintf(pos, end - pos, "%sLEAP",
902 pos == buf ? "" : " ");
903 if (ret < 0 || ret >= end - pos) {
917 #endif /* NO_CONFIG_WRITE */
920 static int * wpa_config_parse_int_array(const char *value)
928 freqs = os_calloc(len + 1, sizeof(int));
939 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
944 for (i = len; i <= len * 2; i++)
950 freqs[used] = atoi(pos);
951 if (freqs[used] == 0)
954 pos = os_strchr(pos + 1, ' ');
961 static int wpa_config_parse_scan_freq(const struct parse_data *data,
962 struct wpa_ssid *ssid, int line,
967 freqs = wpa_config_parse_int_array(value);
974 os_free(ssid->scan_freq);
975 ssid->scan_freq = freqs;
981 static int wpa_config_parse_freq_list(const struct parse_data *data,
982 struct wpa_ssid *ssid, int line,
987 freqs = wpa_config_parse_int_array(value);
994 os_free(ssid->freq_list);
995 ssid->freq_list = freqs;
1001 #ifndef NO_CONFIG_WRITE
1002 static char * wpa_config_write_freqs(const struct parse_data *data,
1005 char *buf, *pos, *end;
1013 for (i = 0; freqs[i]; i++)
1016 pos = buf = os_zalloc(10 * count + 1);
1019 end = buf + 10 * count + 1;
1021 for (i = 0; freqs[i]; i++) {
1022 ret = os_snprintf(pos, end - pos, "%s%u",
1023 i == 0 ? "" : " ", freqs[i]);
1024 if (ret < 0 || ret >= end - pos) {
1035 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1036 struct wpa_ssid *ssid)
1038 return wpa_config_write_freqs(data, ssid->scan_freq);
1042 static char * wpa_config_write_freq_list(const struct parse_data *data,
1043 struct wpa_ssid *ssid)
1045 return wpa_config_write_freqs(data, ssid->freq_list);
1047 #endif /* NO_CONFIG_WRITE */
1050 #ifdef IEEE8021X_EAPOL
1051 static int wpa_config_parse_eap(const struct parse_data *data,
1052 struct wpa_ssid *ssid, int line,
1055 int last, errors = 0;
1056 char *start, *end, *buf;
1057 struct eap_method_type *methods = NULL, *tmp;
1058 size_t num_methods = 0;
1060 buf = os_strdup(value);
1065 while (*start != '\0') {
1066 while (*start == ' ' || *start == '\t')
1071 while (*end != ' ' && *end != '\t' && *end != '\0')
1073 last = *end == '\0';
1076 methods = os_realloc_array(methods, num_methods + 1,
1078 if (methods == NULL) {
1083 methods[num_methods].method = eap_peer_get_type(
1084 start, &methods[num_methods].vendor);
1085 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1086 methods[num_methods].method == EAP_TYPE_NONE) {
1087 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1088 "'%s'", line, start);
1089 wpa_printf(MSG_ERROR, "You may need to add support for"
1090 " this EAP method during wpa_supplicant\n"
1091 "build time configuration.\n"
1092 "See README for more information.");
1094 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1095 methods[num_methods].method == EAP_TYPE_LEAP)
1107 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1108 if (methods == NULL) {
1112 methods[num_methods].vendor = EAP_VENDOR_IETF;
1113 methods[num_methods].method = EAP_TYPE_NONE;
1116 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1117 (u8 *) methods, num_methods * sizeof(*methods));
1118 os_free(ssid->eap.eap_methods);
1119 ssid->eap.eap_methods = methods;
1120 return errors ? -1 : 0;
1124 static char * wpa_config_write_eap(const struct parse_data *data,
1125 struct wpa_ssid *ssid)
1128 char *buf, *pos, *end;
1129 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1132 if (eap_methods == NULL)
1135 pos = buf = os_zalloc(100);
1140 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1141 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1142 name = eap_get_name(eap_methods[i].vendor,
1143 eap_methods[i].method);
1145 ret = os_snprintf(pos, end - pos, "%s%s",
1146 pos == buf ? "" : " ", name);
1147 if (ret < 0 || ret >= end - pos)
1159 static int wpa_config_parse_password(const struct parse_data *data,
1160 struct wpa_ssid *ssid, int line,
1165 if (os_strcmp(value, "NULL") == 0) {
1166 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1167 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1168 ssid->eap.password = NULL;
1169 ssid->eap.password_len = 0;
1173 #ifdef CONFIG_EXT_PASSWORD
1174 if (os_strncmp(value, "ext:", 4) == 0) {
1175 char *name = os_strdup(value + 4);
1178 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1179 ssid->eap.password = (u8 *) name;
1180 ssid->eap.password_len = os_strlen(name);
1181 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1182 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1185 #endif /* CONFIG_EXT_PASSWORD */
1187 if (os_strncmp(value, "hash:", 5) != 0) {
1191 tmp = wpa_config_parse_string(value, &res_len);
1193 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1197 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1198 (u8 *) tmp, res_len);
1200 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1201 ssid->eap.password = (u8 *) tmp;
1202 ssid->eap.password_len = res_len;
1203 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1204 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1210 /* NtPasswordHash: hash:<32 hex digits> */
1211 if (os_strlen(value + 5) != 2 * 16) {
1212 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1213 "(expected 32 hex digits)", line);
1217 hash = os_malloc(16);
1221 if (hexstr2bin(value + 5, hash, 16)) {
1223 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1227 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1229 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1230 ssid->eap.password = hash;
1231 ssid->eap.password_len = 16;
1232 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1233 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1239 static char * wpa_config_write_password(const struct parse_data *data,
1240 struct wpa_ssid *ssid)
1244 if (ssid->eap.password == NULL)
1247 #ifdef CONFIG_EXT_PASSWORD
1248 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1249 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1252 os_memcpy(buf, "ext:", 4);
1253 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1256 #endif /* CONFIG_EXT_PASSWORD */
1258 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1259 return wpa_config_write_string(
1260 ssid->eap.password, ssid->eap.password_len);
1263 buf = os_malloc(5 + 32 + 1);
1267 os_memcpy(buf, "hash:", 5);
1268 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1272 #endif /* IEEE8021X_EAPOL */
1275 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1276 const char *value, int idx)
1278 char *buf, title[20];
1281 buf = wpa_config_parse_string(value, len);
1283 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1287 if (*len > MAX_WEP_KEY_LEN) {
1288 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1293 if (*len && *len != 5 && *len != 13 && *len != 16) {
1294 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1295 "this network block will be ignored",
1296 line, (unsigned int) *len);
1298 os_memcpy(key, buf, *len);
1299 str_clear_free(buf);
1300 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1301 if (res >= 0 && (size_t) res < sizeof(title))
1302 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1307 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1308 struct wpa_ssid *ssid, int line,
1311 return wpa_config_parse_wep_key(ssid->wep_key[0],
1312 &ssid->wep_key_len[0], line,
1317 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1318 struct wpa_ssid *ssid, int line,
1321 return wpa_config_parse_wep_key(ssid->wep_key[1],
1322 &ssid->wep_key_len[1], line,
1327 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1328 struct wpa_ssid *ssid, int line,
1331 return wpa_config_parse_wep_key(ssid->wep_key[2],
1332 &ssid->wep_key_len[2], line,
1337 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1338 struct wpa_ssid *ssid, int line,
1341 return wpa_config_parse_wep_key(ssid->wep_key[3],
1342 &ssid->wep_key_len[3], line,
1347 #ifndef NO_CONFIG_WRITE
1348 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1350 if (ssid->wep_key_len[idx] == 0)
1352 return wpa_config_write_string(ssid->wep_key[idx],
1353 ssid->wep_key_len[idx]);
1357 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1358 struct wpa_ssid *ssid)
1360 return wpa_config_write_wep_key(ssid, 0);
1364 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1365 struct wpa_ssid *ssid)
1367 return wpa_config_write_wep_key(ssid, 1);
1371 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1372 struct wpa_ssid *ssid)
1374 return wpa_config_write_wep_key(ssid, 2);
1378 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1379 struct wpa_ssid *ssid)
1381 return wpa_config_write_wep_key(ssid, 3);
1383 #endif /* NO_CONFIG_WRITE */
1388 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1389 struct wpa_ssid *ssid, int line,
1392 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1393 os_strcmp(value, "any") == 0) {
1394 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1395 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1398 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1399 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1403 ssid->bssid_set = 1;
1404 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1405 MAC2STR(ssid->go_p2p_dev_addr));
1410 #ifndef NO_CONFIG_WRITE
1411 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1412 struct wpa_ssid *ssid)
1417 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1420 value = os_malloc(20);
1423 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1424 if (res < 0 || res >= 20) {
1428 value[20 - 1] = '\0';
1431 #endif /* NO_CONFIG_WRITE */
1434 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1435 struct wpa_ssid *ssid, int line,
1439 u8 *buf, *n, addr[ETH_ALEN];
1446 while (pos && *pos) {
1450 if (hwaddr_aton(pos, addr)) {
1452 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1453 "p2p_client_list address '%s'.",
1458 /* continue anyway since this could have been from a
1459 * truncated configuration file line */
1460 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1461 "truncated p2p_client_list address '%s'",
1464 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1470 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1471 os_memcpy(buf, addr, ETH_ALEN);
1473 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1477 pos = os_strchr(pos, ' ');
1480 os_free(ssid->p2p_client_list);
1481 ssid->p2p_client_list = buf;
1482 ssid->num_p2p_clients = count;
1488 #ifndef NO_CONFIG_WRITE
1489 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1490 struct wpa_ssid *ssid)
1492 char *value, *end, *pos;
1496 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1499 value = os_malloc(20 * ssid->num_p2p_clients);
1503 end = value + 20 * ssid->num_p2p_clients;
1505 for (i = ssid->num_p2p_clients; i > 0; i--) {
1506 res = os_snprintf(pos, end - pos, MACSTR " ",
1507 MAC2STR(ssid->p2p_client_list +
1508 (i - 1) * ETH_ALEN));
1509 if (res < 0 || res >= end - pos) {
1521 #endif /* NO_CONFIG_WRITE */
1524 static int wpa_config_parse_psk_list(const struct parse_data *data,
1525 struct wpa_ssid *ssid, int line,
1528 struct psk_list_entry *p;
1531 p = os_zalloc(sizeof(*p));
1536 if (os_strncmp(pos, "P2P-", 4) == 0) {
1541 if (hwaddr_aton(pos, p->addr)) {
1542 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1549 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1556 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1557 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1563 dl_list_add(&ssid->psk_list, &p->list);
1569 #ifndef NO_CONFIG_WRITE
1570 static char * wpa_config_write_psk_list(const struct parse_data *data,
1571 struct wpa_ssid *ssid)
1575 #endif /* NO_CONFIG_WRITE */
1577 #endif /* CONFIG_P2P */
1579 /* Helper macros for network block parser */
1584 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1585 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1587 /* STR: Define a string variable for an ASCII string; f = field name */
1588 #ifdef NO_CONFIG_WRITE
1589 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1590 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1591 #else /* NO_CONFIG_WRITE */
1592 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1593 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1594 #endif /* NO_CONFIG_WRITE */
1595 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1596 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1597 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1598 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1600 /* STR_LEN: Define a string variable with a separate variable for storing the
1601 * data length. Unlike STR(), this can be used to store arbitrary binary data
1602 * (i.e., even nul termination character). */
1603 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1604 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1605 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1606 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1607 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1609 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1610 * explicitly specified. */
1611 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1612 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1613 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1615 #ifdef NO_CONFIG_WRITE
1616 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1617 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1618 #else /* NO_CONFIG_WRITE */
1619 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1620 OFFSET(f), (void *) 0
1621 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1622 OFFSET(eap.f), (void *) 0
1623 #endif /* NO_CONFIG_WRITE */
1625 /* INT: Define an integer variable */
1626 #define INT(f) _INT(f), NULL, NULL, 0
1627 #define INTe(f) _INTe(f), NULL, NULL, 0
1629 /* INT_RANGE: Define an integer variable with allowed value range */
1630 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1632 /* FUNC: Define a configuration variable that uses a custom function for
1633 * parsing and writing the value. */
1634 #ifdef NO_CONFIG_WRITE
1635 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1636 #else /* NO_CONFIG_WRITE */
1637 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1638 NULL, NULL, NULL, NULL
1639 #endif /* NO_CONFIG_WRITE */
1640 #define FUNC(f) _FUNC(f), 0
1641 #define FUNC_KEY(f) _FUNC(f), 1
1644 * Table of network configuration variables. This table is used to parse each
1645 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1646 * that is inside a network block.
1648 * This table is generated using the helper macros defined above and with
1649 * generous help from the C pre-processor. The field name is stored as a string
1650 * into .name and for STR and INT types, the offset of the target buffer within
1651 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1652 * offset to the field containing the length of the configuration variable.
1653 * .param3 and .param4 can be used to mark the allowed range (length for STR
1654 * and value for INT).
1656 * For each configuration line in wpa_supplicant.conf, the parser goes through
1657 * this table and select the entry that matches with the field name. The parser
1658 * function (.parser) is then called to parse the actual value of the field.
1660 * This kind of mechanism makes it easy to add new configuration parameters,
1661 * since only one line needs to be added into this table and into the
1662 * struct wpa_ssid definition if the new variable is either a string or
1663 * integer. More complex types will need to use their own parser and writer
1666 static const struct parse_data ssid_fields[] = {
1667 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1668 { INT_RANGE(scan_ssid, 0, 1) },
1673 { INT(bg_scan_period) },
1677 { FUNC(scan_freq) },
1678 { FUNC(freq_list) },
1679 #ifdef IEEE8021X_EAPOL
1681 { STR_LENe(identity) },
1682 { STR_LENe(anonymous_identity) },
1683 { FUNC_KEY(password) },
1686 { STRe(client_cert) },
1687 { STRe(private_key) },
1688 { STR_KEYe(private_key_passwd) },
1690 { STRe(subject_match) },
1691 { STRe(altsubject_match) },
1692 { STRe(domain_suffix_match) },
1695 { STRe(client_cert2) },
1696 { STRe(private_key2) },
1697 { STR_KEYe(private_key2_passwd) },
1699 { STRe(subject_match2) },
1700 { STRe(altsubject_match2) },
1701 { STRe(domain_suffix_match2) },
1706 { STRe(engine_id) },
1709 { STRe(ca_cert_id) },
1711 { STRe(engine2_id) },
1714 { STRe(ca_cert2_id) },
1717 { INT(eapol_flags) },
1719 { STRe(openssl_ciphers) },
1720 #endif /* IEEE8021X_EAPOL */
1721 { FUNC_KEY(wep_key0) },
1722 { FUNC_KEY(wep_key1) },
1723 { FUNC_KEY(wep_key2) },
1724 { FUNC_KEY(wep_key3) },
1725 { INT(wep_tx_keyidx) },
1727 #ifdef IEEE8021X_EAPOL
1728 { INT(eap_workaround) },
1730 { INTe(fragment_size) },
1732 #endif /* IEEE8021X_EAPOL */
1734 { INT_RANGE(mode, 0, 5) },
1735 { INT_RANGE(no_auto_peer, 0, 1) },
1736 #else /* CONFIG_MESH */
1737 { INT_RANGE(mode, 0, 4) },
1738 #endif /* CONFIG_MESH */
1739 { INT_RANGE(proactive_key_caching, 0, 1) },
1740 { INT_RANGE(disabled, 0, 2) },
1742 #ifdef CONFIG_IEEE80211W
1743 { INT_RANGE(ieee80211w, 0, 2) },
1744 #endif /* CONFIG_IEEE80211W */
1745 { INT_RANGE(peerkey, 0, 1) },
1746 { INT_RANGE(mixed_cell, 0, 1) },
1747 { INT_RANGE(frequency, 0, 65000) },
1748 { INT(wpa_ptk_rekey) },
1750 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1752 { FUNC(go_p2p_dev_addr) },
1753 { FUNC(p2p_client_list) },
1755 #endif /* CONFIG_P2P */
1756 #ifdef CONFIG_HT_OVERRIDES
1757 { INT_RANGE(disable_ht, 0, 1) },
1758 { INT_RANGE(disable_ht40, -1, 1) },
1759 { INT_RANGE(disable_sgi, 0, 1) },
1760 { INT_RANGE(disable_ldpc, 0, 1) },
1761 { INT_RANGE(ht40_intolerant, 0, 1) },
1762 { INT_RANGE(disable_max_amsdu, -1, 1) },
1763 { INT_RANGE(ampdu_factor, -1, 3) },
1764 { INT_RANGE(ampdu_density, -1, 7) },
1766 #endif /* CONFIG_HT_OVERRIDES */
1767 #ifdef CONFIG_VHT_OVERRIDES
1768 { INT_RANGE(disable_vht, 0, 1) },
1770 { INT(vht_capa_mask) },
1771 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1772 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1773 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1774 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1775 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1776 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1777 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1778 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1779 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1780 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1781 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1782 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1783 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1784 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1785 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1786 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1787 #endif /* CONFIG_VHT_OVERRIDES */
1788 { INT(ap_max_inactivity) },
1789 { INT(dtim_period) },
1790 { INT(beacon_int) },
1791 #ifdef CONFIG_MACSEC
1792 { INT_RANGE(macsec_policy, 0, 1) },
1793 #endif /* CONFIG_MACSEC */
1795 { INT(update_identifier) },
1796 #endif /* CONFIG_HS20 */
1797 { INT_RANGE(mac_addr, 0, 2) },
1809 #undef STR_RANGE_KEY
1816 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1820 * wpa_config_add_prio_network - Add a network to priority lists
1821 * @config: Configuration data from wpa_config_read()
1822 * @ssid: Pointer to the network configuration to be added to the list
1823 * Returns: 0 on success, -1 on failure
1825 * This function is used to add a network block to the priority list of
1826 * networks. This must be called for each network when reading in the full
1827 * configuration. In addition, this can be used indirectly when updating
1828 * priorities by calling wpa_config_update_prio_list().
1830 int wpa_config_add_prio_network(struct wpa_config *config,
1831 struct wpa_ssid *ssid)
1834 struct wpa_ssid *prev, **nlist;
1837 * Add to an existing priority list if one is available for the
1838 * configured priority level for this network.
1840 for (prio = 0; prio < config->num_prio; prio++) {
1841 prev = config->pssid[prio];
1842 if (prev->priority == ssid->priority) {
1850 /* First network for this priority - add a new priority list */
1851 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1852 sizeof(struct wpa_ssid *));
1856 for (prio = 0; prio < config->num_prio; prio++) {
1857 if (nlist[prio]->priority < ssid->priority) {
1858 os_memmove(&nlist[prio + 1], &nlist[prio],
1859 (config->num_prio - prio) *
1860 sizeof(struct wpa_ssid *));
1867 config->pssid = nlist;
1874 * wpa_config_update_prio_list - Update network priority list
1875 * @config: Configuration data from wpa_config_read()
1876 * Returns: 0 on success, -1 on failure
1878 * This function is called to update the priority list of networks in the
1879 * configuration when a network is being added or removed. This is also called
1880 * if a priority for a network is changed.
1882 int wpa_config_update_prio_list(struct wpa_config *config)
1884 struct wpa_ssid *ssid;
1887 os_free(config->pssid);
1888 config->pssid = NULL;
1889 config->num_prio = 0;
1891 ssid = config->ssid;
1894 if (wpa_config_add_prio_network(config, ssid) < 0)
1903 #ifdef IEEE8021X_EAPOL
1904 static void eap_peer_config_free(struct eap_peer_config *eap)
1906 os_free(eap->eap_methods);
1907 bin_clear_free(eap->identity, eap->identity_len);
1908 os_free(eap->anonymous_identity);
1909 bin_clear_free(eap->password, eap->password_len);
1910 os_free(eap->ca_cert);
1911 os_free(eap->ca_path);
1912 os_free(eap->client_cert);
1913 os_free(eap->private_key);
1914 str_clear_free(eap->private_key_passwd);
1915 os_free(eap->dh_file);
1916 os_free(eap->subject_match);
1917 os_free(eap->altsubject_match);
1918 os_free(eap->domain_suffix_match);
1919 os_free(eap->ca_cert2);
1920 os_free(eap->ca_path2);
1921 os_free(eap->client_cert2);
1922 os_free(eap->private_key2);
1923 str_clear_free(eap->private_key2_passwd);
1924 os_free(eap->dh_file2);
1925 os_free(eap->subject_match2);
1926 os_free(eap->altsubject_match2);
1927 os_free(eap->domain_suffix_match2);
1928 os_free(eap->phase1);
1929 os_free(eap->phase2);
1931 str_clear_free(eap->pin);
1932 os_free(eap->engine_id);
1933 os_free(eap->key_id);
1934 os_free(eap->cert_id);
1935 os_free(eap->ca_cert_id);
1936 os_free(eap->key2_id);
1937 os_free(eap->cert2_id);
1938 os_free(eap->ca_cert2_id);
1939 str_clear_free(eap->pin2);
1940 os_free(eap->engine2_id);
1942 os_free(eap->pending_req_otp);
1943 os_free(eap->pac_file);
1944 bin_clear_free(eap->new_password, eap->new_password_len);
1945 str_clear_free(eap->external_sim_resp);
1946 os_free(eap->openssl_ciphers);
1948 #endif /* IEEE8021X_EAPOL */
1952 * wpa_config_free_ssid - Free network/ssid configuration data
1953 * @ssid: Configuration data for the network
1955 * This function frees all resources allocated for the network configuration
1958 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1960 struct psk_list_entry *psk;
1962 os_free(ssid->ssid);
1963 os_memset(ssid->psk, 0, sizeof(ssid->psk));
1964 str_clear_free(ssid->passphrase);
1965 os_free(ssid->ext_psk);
1966 #ifdef IEEE8021X_EAPOL
1967 eap_peer_config_free(&ssid->eap);
1968 #endif /* IEEE8021X_EAPOL */
1969 os_free(ssid->id_str);
1970 os_free(ssid->scan_freq);
1971 os_free(ssid->freq_list);
1972 os_free(ssid->bgscan);
1973 os_free(ssid->p2p_client_list);
1974 #ifdef CONFIG_HT_OVERRIDES
1975 os_free(ssid->ht_mcs);
1976 #endif /* CONFIG_HT_OVERRIDES */
1977 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
1979 dl_list_del(&psk->list);
1986 void wpa_config_free_cred(struct wpa_cred *cred)
1990 os_free(cred->realm);
1991 str_clear_free(cred->username);
1992 str_clear_free(cred->password);
1993 os_free(cred->ca_cert);
1994 os_free(cred->client_cert);
1995 os_free(cred->private_key);
1996 str_clear_free(cred->private_key_passwd);
1997 os_free(cred->imsi);
1998 str_clear_free(cred->milenage);
1999 for (i = 0; i < cred->num_domain; i++)
2000 os_free(cred->domain[i]);
2001 os_free(cred->domain);
2002 os_free(cred->domain_suffix_match);
2003 os_free(cred->eap_method);
2004 os_free(cred->phase1);
2005 os_free(cred->phase2);
2006 os_free(cred->excluded_ssid);
2007 os_free(cred->roaming_partner);
2008 os_free(cred->provisioning_sp);
2009 for (i = 0; i < cred->num_req_conn_capab; i++)
2010 os_free(cred->req_conn_capab_port[i]);
2011 os_free(cred->req_conn_capab_port);
2012 os_free(cred->req_conn_capab_proto);
2017 void wpa_config_flush_blobs(struct wpa_config *config)
2019 #ifndef CONFIG_NO_CONFIG_BLOBS
2020 struct wpa_config_blob *blob, *prev;
2022 blob = config->blobs;
2023 config->blobs = NULL;
2027 wpa_config_free_blob(prev);
2029 #endif /* CONFIG_NO_CONFIG_BLOBS */
2034 * wpa_config_free - Free configuration data
2035 * @config: Configuration data from wpa_config_read()
2037 * This function frees all resources allocated for the configuration data by
2038 * wpa_config_read().
2040 void wpa_config_free(struct wpa_config *config)
2042 struct wpa_ssid *ssid, *prev = NULL;
2043 struct wpa_cred *cred, *cprev;
2045 ssid = config->ssid;
2049 wpa_config_free_ssid(prev);
2052 cred = config->cred;
2056 wpa_config_free_cred(cprev);
2059 wpa_config_flush_blobs(config);
2061 wpabuf_free(config->wps_vendor_ext_m1);
2062 os_free(config->ctrl_interface);
2063 os_free(config->ctrl_interface_group);
2064 os_free(config->opensc_engine_path);
2065 os_free(config->pkcs11_engine_path);
2066 os_free(config->pkcs11_module_path);
2067 os_free(config->openssl_ciphers);
2068 os_free(config->pcsc_reader);
2069 str_clear_free(config->pcsc_pin);
2070 os_free(config->driver_param);
2071 os_free(config->device_name);
2072 os_free(config->manufacturer);
2073 os_free(config->model_name);
2074 os_free(config->model_number);
2075 os_free(config->serial_number);
2076 os_free(config->config_methods);
2077 os_free(config->p2p_ssid_postfix);
2078 os_free(config->pssid);
2079 os_free(config->p2p_pref_chan);
2080 os_free(config->p2p_no_go_freq.range);
2081 os_free(config->autoscan);
2082 os_free(config->freq_list);
2083 wpabuf_free(config->wps_nfc_dh_pubkey);
2084 wpabuf_free(config->wps_nfc_dh_privkey);
2085 wpabuf_free(config->wps_nfc_dev_pw);
2086 os_free(config->ext_password_backend);
2087 os_free(config->sae_groups);
2088 wpabuf_free(config->ap_vendor_elements);
2089 os_free(config->osu_dir);
2090 os_free(config->wowlan_triggers);
2096 * wpa_config_foreach_network - Iterate over each configured network
2097 * @config: Configuration data from wpa_config_read()
2098 * @func: Callback function to process each network
2099 * @arg: Opaque argument to pass to callback function
2101 * Iterate over the set of configured networks calling the specified
2102 * function for each item. We guard against callbacks removing the
2105 void wpa_config_foreach_network(struct wpa_config *config,
2106 void (*func)(void *, struct wpa_ssid *),
2109 struct wpa_ssid *ssid, *next;
2111 ssid = config->ssid;
2121 * wpa_config_get_network - Get configured network based on id
2122 * @config: Configuration data from wpa_config_read()
2123 * @id: Unique network id to search for
2124 * Returns: Network configuration or %NULL if not found
2126 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2128 struct wpa_ssid *ssid;
2130 ssid = config->ssid;
2142 * wpa_config_add_network - Add a new network with empty configuration
2143 * @config: Configuration data from wpa_config_read()
2144 * Returns: The new network configuration or %NULL if operation failed
2146 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2149 struct wpa_ssid *ssid, *last = NULL;
2152 ssid = config->ssid;
2161 ssid = os_zalloc(sizeof(*ssid));
2165 dl_list_init(&ssid->psk_list);
2169 config->ssid = ssid;
2171 wpa_config_update_prio_list(config);
2178 * wpa_config_remove_network - Remove a configured network based on id
2179 * @config: Configuration data from wpa_config_read()
2180 * @id: Unique network id to search for
2181 * Returns: 0 on success, or -1 if the network was not found
2183 int wpa_config_remove_network(struct wpa_config *config, int id)
2185 struct wpa_ssid *ssid, *prev = NULL;
2187 ssid = config->ssid;
2199 prev->next = ssid->next;
2201 config->ssid = ssid->next;
2203 wpa_config_update_prio_list(config);
2204 wpa_config_free_ssid(ssid);
2210 * wpa_config_set_network_defaults - Set network default values
2211 * @ssid: Pointer to network configuration data
2213 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2215 ssid->proto = DEFAULT_PROTO;
2216 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2217 ssid->group_cipher = DEFAULT_GROUP;
2218 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2219 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2220 #ifdef IEEE8021X_EAPOL
2221 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2222 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2223 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2224 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2225 #endif /* IEEE8021X_EAPOL */
2226 #ifdef CONFIG_HT_OVERRIDES
2227 ssid->disable_ht = DEFAULT_DISABLE_HT;
2228 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2229 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2230 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2231 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2232 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2233 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2234 #endif /* CONFIG_HT_OVERRIDES */
2235 #ifdef CONFIG_VHT_OVERRIDES
2236 ssid->vht_rx_mcs_nss_1 = -1;
2237 ssid->vht_rx_mcs_nss_2 = -1;
2238 ssid->vht_rx_mcs_nss_3 = -1;
2239 ssid->vht_rx_mcs_nss_4 = -1;
2240 ssid->vht_rx_mcs_nss_5 = -1;
2241 ssid->vht_rx_mcs_nss_6 = -1;
2242 ssid->vht_rx_mcs_nss_7 = -1;
2243 ssid->vht_rx_mcs_nss_8 = -1;
2244 ssid->vht_tx_mcs_nss_1 = -1;
2245 ssid->vht_tx_mcs_nss_2 = -1;
2246 ssid->vht_tx_mcs_nss_3 = -1;
2247 ssid->vht_tx_mcs_nss_4 = -1;
2248 ssid->vht_tx_mcs_nss_5 = -1;
2249 ssid->vht_tx_mcs_nss_6 = -1;
2250 ssid->vht_tx_mcs_nss_7 = -1;
2251 ssid->vht_tx_mcs_nss_8 = -1;
2252 #endif /* CONFIG_VHT_OVERRIDES */
2253 ssid->proactive_key_caching = -1;
2254 #ifdef CONFIG_IEEE80211W
2255 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2256 #endif /* CONFIG_IEEE80211W */
2257 ssid->mac_addr = -1;
2262 * wpa_config_set - Set a variable in network configuration
2263 * @ssid: Pointer to network configuration data
2264 * @var: Variable name, e.g., "ssid"
2265 * @value: Variable value
2266 * @line: Line number in configuration file or 0 if not used
2267 * Returns: 0 on success, -1 on failure
2269 * This function can be used to set network configuration variables based on
2270 * both the configuration file and management interface input. The value
2271 * parameter must be in the same format as the text-based configuration file is
2272 * using. For example, strings are using double quotation marks.
2274 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2280 if (ssid == NULL || var == NULL || value == NULL)
2283 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2284 const struct parse_data *field = &ssid_fields[i];
2285 if (os_strcmp(var, field->name) != 0)
2288 if (field->parser(field, ssid, line, value)) {
2290 wpa_printf(MSG_ERROR, "Line %d: failed to "
2291 "parse %s '%s'.", line, var, value);
2297 if (i == NUM_SSID_FIELDS) {
2299 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2300 "'%s'.", line, var);
2309 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2316 len = os_strlen(value);
2317 buf = os_malloc(len + 3);
2321 os_memcpy(buf + 1, value, len);
2323 buf[len + 2] = '\0';
2324 ret = wpa_config_set(ssid, var, buf, 0);
2331 * wpa_config_get_all - Get all options from network configuration
2332 * @ssid: Pointer to network configuration data
2333 * @get_keys: Determines if keys/passwords will be included in returned list
2334 * (if they may be exported)
2335 * Returns: %NULL terminated list of all set keys and their values in the form
2336 * of [key1, val1, key2, val2, ... , NULL]
2338 * This function can be used to get list of all configured network properties.
2339 * The caller is responsible for freeing the returned list and all its
2342 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2344 const struct parse_data *field;
2350 get_keys = get_keys && ssid->export_keys;
2352 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2357 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2358 field = &ssid_fields[i];
2359 if (field->key_data && !get_keys)
2361 value = field->writer(field, ssid);
2364 if (os_strlen(value) == 0) {
2369 key = os_strdup(field->name);
2375 props[fields_num * 2] = key;
2376 props[fields_num * 2 + 1] = value;
2392 #ifndef NO_CONFIG_WRITE
2394 * wpa_config_get - Get a variable in network configuration
2395 * @ssid: Pointer to network configuration data
2396 * @var: Variable name, e.g., "ssid"
2397 * Returns: Value of the variable or %NULL on failure
2399 * This function can be used to get network configuration variables. The
2400 * returned value is a copy of the configuration variable in text format, i.e,.
2401 * the same format that the text-based configuration file and wpa_config_set()
2402 * are using for the value. The caller is responsible for freeing the returned
2405 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2409 if (ssid == NULL || var == NULL)
2412 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2413 const struct parse_data *field = &ssid_fields[i];
2414 if (os_strcmp(var, field->name) == 0)
2415 return field->writer(field, ssid);
2423 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2424 * @ssid: Pointer to network configuration data
2425 * @var: Variable name, e.g., "ssid"
2426 * Returns: Value of the variable or %NULL on failure
2428 * This function can be used to get network configuration variable like
2429 * wpa_config_get(). The only difference is that this functions does not expose
2430 * key/password material from the configuration. In case a key/password field
2431 * is requested, the returned value is an empty string or %NULL if the variable
2432 * is not set or "*" if the variable is set (regardless of its value). The
2433 * returned value is a copy of the configuration variable in text format, i.e,.
2434 * the same format that the text-based configuration file and wpa_config_set()
2435 * are using for the value. The caller is responsible for freeing the returned
2438 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2442 if (ssid == NULL || var == NULL)
2445 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2446 const struct parse_data *field = &ssid_fields[i];
2447 if (os_strcmp(var, field->name) == 0) {
2448 char *res = field->writer(field, ssid);
2449 if (field->key_data) {
2450 if (res && res[0]) {
2451 wpa_printf(MSG_DEBUG, "Do not allow "
2452 "key_data field to be "
2454 str_clear_free(res);
2455 return os_strdup("*");
2467 #endif /* NO_CONFIG_WRITE */
2471 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2472 * @ssid: Pointer to network configuration data
2474 * This function must be called to update WPA PSK when either SSID or the
2475 * passphrase has changed for the network configuration.
2477 void wpa_config_update_psk(struct wpa_ssid *ssid)
2479 #ifndef CONFIG_NO_PBKDF2
2480 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2481 ssid->psk, PMK_LEN);
2482 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2483 ssid->psk, PMK_LEN);
2485 #endif /* CONFIG_NO_PBKDF2 */
2489 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2494 int *ports, *nports;
2496 unsigned int num_ports;
2498 proto = os_realloc_array(cred->req_conn_capab_proto,
2499 cred->num_req_conn_capab + 1, sizeof(u8));
2502 cred->req_conn_capab_proto = proto;
2504 port = os_realloc_array(cred->req_conn_capab_port,
2505 cred->num_req_conn_capab + 1, sizeof(int *));
2508 cred->req_conn_capab_port = port;
2510 proto[cred->num_req_conn_capab] = atoi(value);
2512 pos = os_strchr(value, ':');
2514 port[cred->num_req_conn_capab] = NULL;
2515 cred->num_req_conn_capab++;
2524 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2525 if (nports == NULL) {
2530 ports[num_ports++] = atoi(pos);
2532 pos = os_strchr(pos, ',');
2538 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2539 if (nports == NULL) {
2544 ports[num_ports] = -1;
2546 port[cred->num_req_conn_capab] = ports;
2547 cred->num_req_conn_capab++;
2552 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2553 const char *value, int line)
2558 if (os_strcmp(var, "temporary") == 0) {
2559 cred->temporary = atoi(value);
2563 if (os_strcmp(var, "priority") == 0) {
2564 cred->priority = atoi(value);
2568 if (os_strcmp(var, "sp_priority") == 0) {
2569 int prio = atoi(value);
2570 if (prio < 0 || prio > 255)
2572 cred->sp_priority = prio;
2576 if (os_strcmp(var, "pcsc") == 0) {
2577 cred->pcsc = atoi(value);
2581 if (os_strcmp(var, "eap") == 0) {
2582 struct eap_method_type method;
2583 method.method = eap_peer_get_type(value, &method.vendor);
2584 if (method.vendor == EAP_VENDOR_IETF &&
2585 method.method == EAP_TYPE_NONE) {
2586 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2587 "for a credential", line, value);
2590 os_free(cred->eap_method);
2591 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2592 if (cred->eap_method == NULL)
2594 os_memcpy(cred->eap_method, &method, sizeof(method));
2598 if (os_strcmp(var, "password") == 0 &&
2599 os_strncmp(value, "ext:", 4) == 0) {
2600 str_clear_free(cred->password);
2601 cred->password = os_strdup(value);
2602 cred->ext_password = 1;
2606 if (os_strcmp(var, "update_identifier") == 0) {
2607 cred->update_identifier = atoi(value);
2611 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2612 cred->min_dl_bandwidth_home = atoi(value);
2616 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2617 cred->min_ul_bandwidth_home = atoi(value);
2621 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2622 cred->min_dl_bandwidth_roaming = atoi(value);
2626 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2627 cred->min_ul_bandwidth_roaming = atoi(value);
2631 if (os_strcmp(var, "max_bss_load") == 0) {
2632 cred->max_bss_load = atoi(value);
2636 if (os_strcmp(var, "req_conn_capab") == 0)
2637 return wpa_config_set_cred_req_conn_capab(cred, value);
2639 if (os_strcmp(var, "ocsp") == 0) {
2640 cred->ocsp = atoi(value);
2644 if (os_strcmp(var, "sim_num") == 0) {
2645 cred->sim_num = atoi(value);
2649 val = wpa_config_parse_string(value, &len);
2651 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2652 "value '%s'.", line, var, value);
2656 if (os_strcmp(var, "realm") == 0) {
2657 os_free(cred->realm);
2662 if (os_strcmp(var, "username") == 0) {
2663 str_clear_free(cred->username);
2664 cred->username = val;
2668 if (os_strcmp(var, "password") == 0) {
2669 str_clear_free(cred->password);
2670 cred->password = val;
2671 cred->ext_password = 0;
2675 if (os_strcmp(var, "ca_cert") == 0) {
2676 os_free(cred->ca_cert);
2677 cred->ca_cert = val;
2681 if (os_strcmp(var, "client_cert") == 0) {
2682 os_free(cred->client_cert);
2683 cred->client_cert = val;
2687 if (os_strcmp(var, "private_key") == 0) {
2688 os_free(cred->private_key);
2689 cred->private_key = val;
2693 if (os_strcmp(var, "private_key_passwd") == 0) {
2694 str_clear_free(cred->private_key_passwd);
2695 cred->private_key_passwd = val;
2699 if (os_strcmp(var, "imsi") == 0) {
2700 os_free(cred->imsi);
2705 if (os_strcmp(var, "milenage") == 0) {
2706 str_clear_free(cred->milenage);
2707 cred->milenage = val;
2711 if (os_strcmp(var, "domain_suffix_match") == 0) {
2712 os_free(cred->domain_suffix_match);
2713 cred->domain_suffix_match = val;
2717 if (os_strcmp(var, "domain") == 0) {
2719 new_domain = os_realloc_array(cred->domain,
2720 cred->num_domain + 1,
2722 if (new_domain == NULL) {
2726 new_domain[cred->num_domain++] = val;
2727 cred->domain = new_domain;
2731 if (os_strcmp(var, "phase1") == 0) {
2732 os_free(cred->phase1);
2737 if (os_strcmp(var, "phase2") == 0) {
2738 os_free(cred->phase2);
2743 if (os_strcmp(var, "roaming_consortium") == 0) {
2744 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2745 wpa_printf(MSG_ERROR, "Line %d: invalid "
2746 "roaming_consortium length %d (3..15 "
2747 "expected)", line, (int) len);
2751 os_memcpy(cred->roaming_consortium, val, len);
2752 cred->roaming_consortium_len = len;
2757 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2758 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2760 wpa_printf(MSG_ERROR, "Line %d: invalid "
2761 "required_roaming_consortium length %d "
2762 "(3..15 expected)", line, (int) len);
2766 os_memcpy(cred->required_roaming_consortium, val, len);
2767 cred->required_roaming_consortium_len = len;
2772 if (os_strcmp(var, "excluded_ssid") == 0) {
2773 struct excluded_ssid *e;
2775 if (len > MAX_SSID_LEN) {
2776 wpa_printf(MSG_ERROR, "Line %d: invalid "
2777 "excluded_ssid length %d", line, (int) len);
2782 e = os_realloc_array(cred->excluded_ssid,
2783 cred->num_excluded_ssid + 1,
2784 sizeof(struct excluded_ssid));
2789 cred->excluded_ssid = e;
2791 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2792 os_memcpy(e->ssid, val, len);
2800 if (os_strcmp(var, "roaming_partner") == 0) {
2801 struct roaming_partner *p;
2804 p = os_realloc_array(cred->roaming_partner,
2805 cred->num_roaming_partner + 1,
2806 sizeof(struct roaming_partner));
2811 cred->roaming_partner = p;
2813 p = &cred->roaming_partner[cred->num_roaming_partner];
2815 pos = os_strchr(val, ',');
2821 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2825 os_memcpy(p->fqdn, val, pos - val);
2827 p->exact_match = atoi(pos);
2829 pos = os_strchr(pos, ',');
2836 p->priority = atoi(pos);
2838 pos = os_strchr(pos, ',');
2845 if (os_strlen(pos) >= sizeof(p->country)) {
2849 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2851 cred->num_roaming_partner++;
2857 if (os_strcmp(var, "provisioning_sp") == 0) {
2858 os_free(cred->provisioning_sp);
2859 cred->provisioning_sp = val;
2864 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2874 static char * alloc_int_str(int val)
2878 buf = os_malloc(20);
2881 os_snprintf(buf, 20, "%d", val);
2886 static char * alloc_strdup(const char *str)
2890 return os_strdup(str);
2894 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2896 if (os_strcmp(var, "temporary") == 0)
2897 return alloc_int_str(cred->temporary);
2899 if (os_strcmp(var, "priority") == 0)
2900 return alloc_int_str(cred->priority);
2902 if (os_strcmp(var, "sp_priority") == 0)
2903 return alloc_int_str(cred->sp_priority);
2905 if (os_strcmp(var, "pcsc") == 0)
2906 return alloc_int_str(cred->pcsc);
2908 if (os_strcmp(var, "eap") == 0) {
2909 if (!cred->eap_method)
2911 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2912 cred->eap_method[0].method));
2915 if (os_strcmp(var, "update_identifier") == 0)
2916 return alloc_int_str(cred->update_identifier);
2918 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
2919 return alloc_int_str(cred->min_dl_bandwidth_home);
2921 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
2922 return alloc_int_str(cred->min_ul_bandwidth_home);
2924 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
2925 return alloc_int_str(cred->min_dl_bandwidth_roaming);
2927 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
2928 return alloc_int_str(cred->min_ul_bandwidth_roaming);
2930 if (os_strcmp(var, "max_bss_load") == 0)
2931 return alloc_int_str(cred->max_bss_load);
2933 if (os_strcmp(var, "req_conn_capab") == 0) {
2935 char *buf, *end, *pos;
2938 if (!cred->num_req_conn_capab)
2941 buf = os_malloc(4000);
2946 for (i = 0; i < cred->num_req_conn_capab; i++) {
2949 ret = os_snprintf(pos, end - pos, "%s%u",
2951 cred->req_conn_capab_proto[i]);
2952 if (ret < 0 || ret >= end - pos)
2956 ports = cred->req_conn_capab_port[i];
2959 for (j = 0; ports[j] != -1; j++) {
2960 ret = os_snprintf(pos, end - pos,
2964 if (ret < 0 || ret >= end - pos)
2974 if (os_strcmp(var, "ocsp") == 0)
2975 return alloc_int_str(cred->ocsp);
2977 if (os_strcmp(var, "realm") == 0)
2978 return alloc_strdup(cred->realm);
2980 if (os_strcmp(var, "username") == 0)
2981 return alloc_strdup(cred->username);
2983 if (os_strcmp(var, "password") == 0) {
2984 if (!cred->password)
2986 return alloc_strdup("*");
2989 if (os_strcmp(var, "ca_cert") == 0)
2990 return alloc_strdup(cred->ca_cert);
2992 if (os_strcmp(var, "client_cert") == 0)
2993 return alloc_strdup(cred->client_cert);
2995 if (os_strcmp(var, "private_key") == 0)
2996 return alloc_strdup(cred->private_key);
2998 if (os_strcmp(var, "private_key_passwd") == 0) {
2999 if (!cred->private_key_passwd)
3001 return alloc_strdup("*");
3004 if (os_strcmp(var, "imsi") == 0)
3005 return alloc_strdup(cred->imsi);
3007 if (os_strcmp(var, "milenage") == 0) {
3008 if (!(cred->milenage))
3010 return alloc_strdup("*");
3013 if (os_strcmp(var, "domain_suffix_match") == 0)
3014 return alloc_strdup(cred->domain_suffix_match);
3016 if (os_strcmp(var, "domain") == 0) {
3018 char *buf, *end, *pos;
3021 if (!cred->num_domain)
3024 buf = os_malloc(4000);
3030 for (i = 0; i < cred->num_domain; i++) {
3031 ret = os_snprintf(pos, end - pos, "%s%s",
3032 i > 0 ? "\n" : "", cred->domain[i]);
3033 if (ret < 0 || ret >= end - pos)
3041 if (os_strcmp(var, "phase1") == 0)
3042 return alloc_strdup(cred->phase1);
3044 if (os_strcmp(var, "phase2") == 0)
3045 return alloc_strdup(cred->phase2);
3047 if (os_strcmp(var, "roaming_consortium") == 0) {
3051 if (!cred->roaming_consortium_len)
3053 buflen = cred->roaming_consortium_len * 2 + 1;
3054 buf = os_malloc(buflen);
3057 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3058 cred->roaming_consortium_len);
3062 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3066 if (!cred->required_roaming_consortium_len)
3068 buflen = cred->required_roaming_consortium_len * 2 + 1;
3069 buf = os_malloc(buflen);
3072 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3073 cred->required_roaming_consortium_len);
3077 if (os_strcmp(var, "excluded_ssid") == 0) {
3079 char *buf, *end, *pos;
3081 if (!cred->num_excluded_ssid)
3084 buf = os_malloc(4000);
3090 for (i = 0; i < cred->num_excluded_ssid; i++) {
3091 struct excluded_ssid *e;
3094 e = &cred->excluded_ssid[i];
3095 ret = os_snprintf(pos, end - pos, "%s%s",
3097 wpa_ssid_txt(e->ssid, e->ssid_len));
3098 if (ret < 0 || ret >= end - pos)
3106 if (os_strcmp(var, "roaming_partner") == 0) {
3108 char *buf, *end, *pos;
3110 if (!cred->num_roaming_partner)
3113 buf = os_malloc(4000);
3119 for (i = 0; i < cred->num_roaming_partner; i++) {
3120 struct roaming_partner *p;
3123 p = &cred->roaming_partner[i];
3124 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3126 p->fqdn, p->exact_match, p->priority,
3128 if (ret < 0 || ret >= end - pos)
3136 if (os_strcmp(var, "provisioning_sp") == 0)
3137 return alloc_strdup(cred->provisioning_sp);
3143 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3145 struct wpa_cred *cred;
3147 cred = config->cred;
3158 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3161 struct wpa_cred *cred, *last = NULL;
3164 cred = config->cred;
3173 cred = os_zalloc(sizeof(*cred));
3177 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3181 config->cred = cred;
3187 int wpa_config_remove_cred(struct wpa_config *config, int id)
3189 struct wpa_cred *cred, *prev = NULL;
3191 cred = config->cred;
3203 prev->next = cred->next;
3205 config->cred = cred->next;
3207 wpa_config_free_cred(cred);
3212 #ifndef CONFIG_NO_CONFIG_BLOBS
3214 * wpa_config_get_blob - Get a named configuration blob
3215 * @config: Configuration data from wpa_config_read()
3216 * @name: Name of the blob
3217 * Returns: Pointer to blob data or %NULL if not found
3219 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3222 struct wpa_config_blob *blob = config->blobs;
3225 if (os_strcmp(blob->name, name) == 0)
3234 * wpa_config_set_blob - Set or add a named configuration blob
3235 * @config: Configuration data from wpa_config_read()
3236 * @blob: New value for the blob
3238 * Adds a new configuration blob or replaces the current value of an existing
3241 void wpa_config_set_blob(struct wpa_config *config,
3242 struct wpa_config_blob *blob)
3244 wpa_config_remove_blob(config, blob->name);
3245 blob->next = config->blobs;
3246 config->blobs = blob;
3251 * wpa_config_free_blob - Free blob data
3252 * @blob: Pointer to blob to be freed
3254 void wpa_config_free_blob(struct wpa_config_blob *blob)
3257 os_free(blob->name);
3258 bin_clear_free(blob->data, blob->len);
3265 * wpa_config_remove_blob - Remove a named configuration blob
3266 * @config: Configuration data from wpa_config_read()
3267 * @name: Name of the blob to remove
3268 * Returns: 0 if blob was removed or -1 if blob was not found
3270 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3272 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3275 if (os_strcmp(pos->name, name) == 0) {
3277 prev->next = pos->next;
3279 config->blobs = pos->next;
3280 wpa_config_free_blob(pos);
3289 #endif /* CONFIG_NO_CONFIG_BLOBS */
3293 * wpa_config_alloc_empty - Allocate an empty configuration
3294 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3296 * @driver_param: Driver parameters
3297 * Returns: Pointer to allocated configuration data or %NULL on failure
3299 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3300 const char *driver_param)
3302 struct wpa_config *config;
3303 const int aCWmin = 4, aCWmax = 10;
3304 const struct hostapd_wmm_ac_params ac_bk =
3305 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3306 const struct hostapd_wmm_ac_params ac_be =
3307 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3308 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3309 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3310 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3311 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3313 config = os_zalloc(sizeof(*config));
3316 config->eapol_version = DEFAULT_EAPOL_VERSION;
3317 config->ap_scan = DEFAULT_AP_SCAN;
3318 config->user_mpm = DEFAULT_USER_MPM;
3319 config->fast_reauth = DEFAULT_FAST_REAUTH;
3320 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3321 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3322 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3323 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3324 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3325 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3326 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3327 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3328 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3329 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3330 config->wmm_ac_params[0] = ac_be;
3331 config->wmm_ac_params[1] = ac_bk;
3332 config->wmm_ac_params[2] = ac_vi;
3333 config->wmm_ac_params[3] = ac_vo;
3334 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3335 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3336 config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD;
3339 config->ctrl_interface = os_strdup(ctrl_interface);
3341 config->driver_param = os_strdup(driver_param);
3347 #ifndef CONFIG_NO_STDOUT_DEBUG
3349 * wpa_config_debug_dump_networks - Debug dump of configured networks
3350 * @config: Configuration data from wpa_config_read()
3352 void wpa_config_debug_dump_networks(struct wpa_config *config)
3355 struct wpa_ssid *ssid;
3357 for (prio = 0; prio < config->num_prio; prio++) {
3358 ssid = config->pssid[prio];
3359 wpa_printf(MSG_DEBUG, "Priority group %d",
3362 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3364 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3369 #endif /* CONFIG_NO_STDOUT_DEBUG */
3372 struct global_parse_data {
3374 int (*parser)(const struct global_parse_data *data,
3375 struct wpa_config *config, int line, const char *value);
3376 void *param1, *param2, *param3;
3377 unsigned int changed_flag;
3381 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3382 struct wpa_config *config, int line,
3388 dst = (int *) (((u8 *) config) + (long) data->param1);
3389 val = strtol(pos, &end, 0);
3391 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3397 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3399 if (data->param2 && *dst < (long) data->param2) {
3400 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3401 "min_value=%ld)", line, data->name, *dst,
3402 (long) data->param2);
3403 *dst = (long) data->param2;
3407 if (data->param3 && *dst > (long) data->param3) {
3408 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3409 "max_value=%ld)", line, data->name, *dst,
3410 (long) data->param3);
3411 *dst = (long) data->param3;
3419 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3420 struct wpa_config *config, int line,
3426 len = os_strlen(pos);
3427 if (data->param2 && len < (size_t) data->param2) {
3428 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3429 "min_len=%ld)", line, data->name,
3430 (unsigned long) len, (long) data->param2);
3434 if (data->param3 && len > (size_t) data->param3) {
3435 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3436 "max_len=%ld)", line, data->name,
3437 (unsigned long) len, (long) data->param3);
3441 tmp = os_strdup(pos);
3445 dst = (char **) (((u8 *) config) + (long) data->param1);
3448 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3454 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3455 struct wpa_config *config, int line,
3462 tmp = wpa_config_parse_string(pos, &len);
3464 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3469 res = wpa_global_config_parse_str(data, config, line, tmp);
3475 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3476 struct wpa_config *config, int line,
3480 struct wpabuf **dst, *tmp;
3482 len = os_strlen(pos);
3486 tmp = wpabuf_alloc(len / 2);
3490 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3495 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3498 wpa_printf(MSG_DEBUG, "%s", data->name);
3504 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3505 struct wpa_config *config, int line,
3510 freqs = wpa_config_parse_int_array(value);
3513 if (freqs[0] == 0) {
3517 os_free(config->freq_list);
3518 config->freq_list = freqs;
3524 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3525 struct wpa_config *config, int line,
3529 struct hostapd_ip_addr addr;
3531 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3533 if (addr.af != AF_INET)
3536 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3537 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3538 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3539 WPA_GET_BE32((u8 *) dst));
3543 #endif /* CONFIG_P2P */
3546 static int wpa_config_process_country(const struct global_parse_data *data,
3547 struct wpa_config *config, int line,
3550 if (!pos[0] || !pos[1]) {
3551 wpa_printf(MSG_DEBUG, "Invalid country set");
3554 config->country[0] = pos[0];
3555 config->country[1] = pos[1];
3556 wpa_printf(MSG_DEBUG, "country='%c%c'",
3557 config->country[0], config->country[1]);
3562 static int wpa_config_process_load_dynamic_eap(
3563 const struct global_parse_data *data, struct wpa_config *config,
3564 int line, const char *so)
3567 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3568 ret = eap_peer_method_load(so);
3570 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3573 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3574 "method '%s'.", line, so);
3584 static int wpa_config_process_uuid(const struct global_parse_data *data,
3585 struct wpa_config *config, int line,
3589 if (uuid_str2bin(pos, config->uuid)) {
3590 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3593 uuid_bin2str(config->uuid, buf, sizeof(buf));
3594 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3599 static int wpa_config_process_device_type(
3600 const struct global_parse_data *data,
3601 struct wpa_config *config, int line, const char *pos)
3603 return wps_dev_type_str2bin(pos, config->device_type);
3607 static int wpa_config_process_os_version(const struct global_parse_data *data,
3608 struct wpa_config *config, int line,
3611 if (hexstr2bin(pos, config->os_version, 4)) {
3612 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3615 wpa_printf(MSG_DEBUG, "os_version=%08x",
3616 WPA_GET_BE32(config->os_version));
3621 static int wpa_config_process_wps_vendor_ext_m1(
3622 const struct global_parse_data *data,
3623 struct wpa_config *config, int line, const char *pos)
3626 int len = os_strlen(pos) / 2;
3630 wpa_printf(MSG_ERROR, "Line %d: "
3631 "invalid wps_vendor_ext_m1", line);
3635 tmp = wpabuf_alloc(len);
3637 p = wpabuf_put(tmp, len);
3639 if (hexstr2bin(pos, p, len)) {
3640 wpa_printf(MSG_ERROR, "Line %d: "
3641 "invalid wps_vendor_ext_m1", line);
3646 wpabuf_free(config->wps_vendor_ext_m1);
3647 config->wps_vendor_ext_m1 = tmp;
3649 wpa_printf(MSG_ERROR, "Can not allocate "
3650 "memory for wps_vendor_ext_m1");
3657 #endif /* CONFIG_WPS */
3660 static int wpa_config_process_sec_device_type(
3661 const struct global_parse_data *data,
3662 struct wpa_config *config, int line, const char *pos)
3666 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3667 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3672 idx = config->num_sec_device_types;
3674 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3677 config->num_sec_device_types++;
3682 static int wpa_config_process_p2p_pref_chan(
3683 const struct global_parse_data *data,
3684 struct wpa_config *config, int line, const char *pos)
3686 struct p2p_channel *pref = NULL, *n;
3687 unsigned int num = 0;
3691 /* format: class:chan,class:chan,... */
3694 op_class = atoi(pos);
3695 pos2 = os_strchr(pos, ':');
3701 n = os_realloc_array(pref, num + 1,
3702 sizeof(struct p2p_channel));
3706 pref[num].op_class = op_class;
3707 pref[num].chan = chan;
3710 pos = os_strchr(pos2, ',');
3716 os_free(config->p2p_pref_chan);
3717 config->p2p_pref_chan = pref;
3718 config->num_p2p_pref_chan = num;
3719 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3720 (u8 *) config->p2p_pref_chan,
3721 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3727 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3732 static int wpa_config_process_p2p_no_go_freq(
3733 const struct global_parse_data *data,
3734 struct wpa_config *config, int line, const char *pos)
3738 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3740 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3744 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3745 config->p2p_no_go_freq.num);
3750 #endif /* CONFIG_P2P */
3753 static int wpa_config_process_hessid(
3754 const struct global_parse_data *data,
3755 struct wpa_config *config, int line, const char *pos)
3757 if (hwaddr_aton2(pos, config->hessid) < 0) {
3758 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3767 static int wpa_config_process_sae_groups(
3768 const struct global_parse_data *data,
3769 struct wpa_config *config, int line, const char *pos)
3771 int *groups = wpa_config_parse_int_array(pos);
3772 if (groups == NULL) {
3773 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3778 os_free(config->sae_groups);
3779 config->sae_groups = groups;
3785 static int wpa_config_process_ap_vendor_elements(
3786 const struct global_parse_data *data,
3787 struct wpa_config *config, int line, const char *pos)
3790 int len = os_strlen(pos) / 2;
3794 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3799 tmp = wpabuf_alloc(len);
3801 p = wpabuf_put(tmp, len);
3803 if (hexstr2bin(pos, p, len)) {
3804 wpa_printf(MSG_ERROR, "Line %d: invalid "
3805 "ap_vendor_elements", line);
3810 wpabuf_free(config->ap_vendor_elements);
3811 config->ap_vendor_elements = tmp;
3813 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3814 "ap_vendor_elements");
3822 #ifdef CONFIG_CTRL_IFACE
3823 static int wpa_config_process_no_ctrl_interface(
3824 const struct global_parse_data *data,
3825 struct wpa_config *config, int line, const char *pos)
3827 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3828 os_free(config->ctrl_interface);
3829 config->ctrl_interface = NULL;
3832 #endif /* CONFIG_CTRL_IFACE */
3838 /* OFFSET: Get offset of a variable within the wpa_config structure */
3839 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3841 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3842 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3843 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3844 #define INT(f) _INT(f), NULL, NULL
3845 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3846 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3847 #define STR(f) _STR(f), NULL, NULL
3848 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3849 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3850 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3852 static const struct global_parse_data global_fields[] = {
3853 #ifdef CONFIG_CTRL_IFACE
3854 { STR(ctrl_interface), 0 },
3855 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3856 { STR(ctrl_interface_group), 0 } /* deprecated */,
3857 #endif /* CONFIG_CTRL_IFACE */
3858 #ifdef CONFIG_MACSEC
3859 { INT_RANGE(eapol_version, 1, 3), 0 },
3860 #else /* CONFIG_MACSEC */
3861 { INT_RANGE(eapol_version, 1, 2), 0 },
3862 #endif /* CONFIG_MACSEC */
3863 { INT(ap_scan), 0 },
3864 { FUNC(bgscan), 0 },
3866 { INT(user_mpm), 0 },
3867 #endif /* CONFIG_MESH */
3868 { INT(disable_scan_offload), 0 },
3869 { INT(fast_reauth), 0 },
3870 { STR(opensc_engine_path), 0 },
3871 { STR(pkcs11_engine_path), 0 },
3872 { STR(pkcs11_module_path), 0 },
3873 { STR(openssl_ciphers), 0 },
3874 { STR(pcsc_reader), 0 },
3875 { STR(pcsc_pin), 0 },
3876 { INT(external_sim), 0 },
3877 { STR(driver_param), 0 },
3878 { INT(dot11RSNAConfigPMKLifetime), 0 },
3879 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3880 { INT(dot11RSNAConfigSATimeout), 0 },
3881 #ifndef CONFIG_NO_CONFIG_WRITE
3882 { INT(update_config), 0 },
3883 #endif /* CONFIG_NO_CONFIG_WRITE */
3884 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3886 { FUNC(uuid), CFG_CHANGED_UUID },
3887 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3888 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3889 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3890 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3891 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3892 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3893 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3894 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3895 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3896 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3897 #endif /* CONFIG_WPS */
3899 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3900 { INT(p2p_listen_reg_class), 0 },
3901 { INT(p2p_listen_channel), 0 },
3902 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3903 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3904 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3905 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3906 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3907 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3908 { INT(p2p_group_idle), 0 },
3909 { INT_RANGE(p2p_passphrase_len, 8, 63),
3910 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3911 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3912 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3913 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3914 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3915 { INT(p2p_go_ht40), 0 },
3916 { INT(p2p_go_vht), 0 },
3917 { INT(p2p_disabled), 0 },
3918 { INT(p2p_no_group_iface), 0 },
3919 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
3920 { IPV4(ip_addr_go), 0 },
3921 { IPV4(ip_addr_mask), 0 },
3922 { IPV4(ip_addr_start), 0 },
3923 { IPV4(ip_addr_end), 0 },
3924 #endif /* CONFIG_P2P */
3925 { FUNC(country), CFG_CHANGED_COUNTRY },
3926 { INT(bss_max_count), 0 },
3927 { INT(bss_expiration_age), 0 },
3928 { INT(bss_expiration_scan_count), 0 },
3929 { INT_RANGE(filter_ssids, 0, 1), 0 },
3930 { INT_RANGE(filter_rssi, -100, 0), 0 },
3931 { INT(max_num_sta), 0 },
3932 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3934 { INT_RANGE(hs20, 0, 1), 0 },
3935 #endif /* CONFIG_HS20 */
3936 { INT_RANGE(interworking, 0, 1), 0 },
3937 { FUNC(hessid), 0 },
3938 { INT_RANGE(access_network_type, 0, 15), 0 },
3939 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3940 { STR(autoscan), 0 },
3941 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3942 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3943 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3944 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3945 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3946 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3947 { INT(p2p_go_max_inactivity), 0 },
3948 { INT_RANGE(auto_interworking, 0, 1), 0 },
3951 { FUNC(sae_groups), 0 },
3952 { INT(dtim_period), 0 },
3953 { INT(beacon_int), 0 },
3954 { FUNC(ap_vendor_elements), 0 },
3955 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
3956 { FUNC(freq_list), 0 },
3957 { INT(scan_cur_freq), 0 },
3958 { INT(sched_scan_interval), 0 },
3959 { INT(tdls_external_control), 0},
3960 { STR(osu_dir), 0 },
3961 { STR(wowlan_triggers), 0 },
3962 { INT(p2p_search_delay), 0},
3963 { INT(mac_addr), 0 },
3964 { INT(rand_addr_lifetime), 0 },
3965 { INT(preassoc_mac_addr), 0 },
3966 { INT(key_mgmt_offload), 0},
3978 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
3981 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3986 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3987 const struct global_parse_data *field = &global_fields[i];
3988 size_t flen = os_strlen(field->name);
3989 if (os_strncmp(pos, field->name, flen) != 0 ||
3993 if (field->parser(field, config, line, pos + flen + 1)) {
3994 wpa_printf(MSG_ERROR, "Line %d: failed to "
3995 "parse '%s'.", line, pos);
3998 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
3999 config->wps_nfc_pw_from_config = 1;
4000 config->changed_parameters |= field->changed_flag;
4003 if (i == NUM_GLOBAL_FIELDS) {
4005 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
4006 char *tmp = os_strchr(pos, '=');
4010 wpa_printf(MSG_ERROR, "Line %d: invalid line "
4015 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
4017 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
4022 #endif /* CONFIG_AP */
4025 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",