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 "crypto/sha1.h"
14 #include "rsn_supp/wpa.h"
15 #include "eap_peer/eap.h"
20 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
21 #define NO_CONFIG_WRITE
25 * Structure for network configuration parsing. This data is used to implement
26 * a generic parser for each network block variable. The table of configuration
27 * variables is defined below in this file (ssid_fields[]).
30 /* Configuration variable name */
33 /* Parser function for this variable */
34 int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
35 int line, const char *value);
37 #ifndef NO_CONFIG_WRITE
38 /* Writer function (i.e., to get the variable in text format from
39 * internal presentation). */
40 char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
41 #endif /* NO_CONFIG_WRITE */
43 /* Variable specific parameters for the parser. */
44 void *param1, *param2, *param3, *param4;
46 /* 0 = this variable can be included in debug output and ctrl_iface
47 * 1 = this variable contains key/private data and it must not be
48 * included in debug output unless explicitly requested. In
49 * addition, this variable will not be readable through the
56 static char * wpa_config_parse_string(const char *value, size_t *len)
62 pos = os_strrchr(value, '"');
63 if (pos == NULL || pos[1] != '\0')
66 str = os_malloc(*len + 1);
69 os_memcpy(str, value, *len);
74 size_t tlen, hlen = os_strlen(value);
78 str = os_malloc(tlen + 1);
81 if (hexstr2bin(value, str, tlen)) {
92 static int wpa_config_parse_str(const struct parse_data *data,
93 struct wpa_ssid *ssid,
94 int line, const char *value)
96 size_t res_len, *dst_len;
99 if (os_strcmp(value, "NULL") == 0) {
100 wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
107 tmp = wpa_config_parse_string(value, &res_len);
109 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
111 data->key_data ? "[KEY DATA REMOVED]" : value);
115 if (data->key_data) {
116 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
117 (u8 *) tmp, res_len);
119 wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
120 (u8 *) tmp, res_len);
123 if (data->param3 && res_len < (size_t) data->param3) {
124 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
125 "min_len=%ld)", line, data->name,
126 (unsigned long) res_len, (long) data->param3);
131 if (data->param4 && res_len > (size_t) data->param4) {
132 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
133 "max_len=%ld)", line, data->name,
134 (unsigned long) res_len, (long) data->param4);
140 dst = (char **) (((u8 *) ssid) + (long) data->param1);
141 dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
151 #ifndef NO_CONFIG_WRITE
152 static int is_hex(const u8 *data, size_t len)
156 for (i = 0; i < len; i++) {
157 if (data[i] < 32 || data[i] >= 127)
164 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
168 buf = os_malloc(len + 3);
172 os_memcpy(buf + 1, value, len);
180 static char * wpa_config_write_string_hex(const u8 *value, size_t len)
184 buf = os_zalloc(2 * len + 1);
187 wpa_snprintf_hex(buf, 2 * len + 1, value, len);
193 static char * wpa_config_write_string(const u8 *value, size_t len)
198 if (is_hex(value, len))
199 return wpa_config_write_string_hex(value, len);
201 return wpa_config_write_string_ascii(value, len);
205 static char * wpa_config_write_str(const struct parse_data *data,
206 struct wpa_ssid *ssid)
211 src = (char **) (((u8 *) ssid) + (long) data->param1);
216 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
218 len = os_strlen(*src);
220 return wpa_config_write_string((const u8 *) *src, len);
223 #ifdef WPA_UNICODE_SSID
224 static char * wpa_config_write_str_unicode(const struct parse_data *data,
225 struct wpa_ssid *ssid)
230 src = (char **) (((u8 *) ssid) + (long) data->param1);
235 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
237 len = os_strlen(*src);
239 return wpa_config_write_string_ascii((const u8 *) *src, len);
242 #endif /* NO_CONFIG_WRITE */
245 static int wpa_config_parse_int(const struct parse_data *data,
246 struct wpa_ssid *ssid,
247 int line, const char *value)
251 dst = (int *) (((u8 *) ssid) + (long) data->param1);
253 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
255 if (data->param3 && *dst < (long) data->param3) {
256 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
257 "min_value=%ld)", line, data->name, *dst,
258 (long) data->param3);
259 *dst = (long) data->param3;
263 if (data->param4 && *dst > (long) data->param4) {
264 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
265 "max_value=%ld)", line, data->name, *dst,
266 (long) data->param4);
267 *dst = (long) data->param4;
275 #ifndef NO_CONFIG_WRITE
276 static char * wpa_config_write_int(const struct parse_data *data,
277 struct wpa_ssid *ssid)
282 src = (int *) (((u8 *) ssid) + (long) data->param1);
284 value = os_malloc(20);
287 res = os_snprintf(value, 20, "%d", *src);
288 if (res < 0 || res >= 20) {
292 value[20 - 1] = '\0';
295 #endif /* NO_CONFIG_WRITE */
298 static int wpa_config_parse_bssid(const struct parse_data *data,
299 struct wpa_ssid *ssid, int line,
302 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
303 os_strcmp(value, "any") == 0) {
305 wpa_printf(MSG_MSGDUMP, "BSSID any");
308 if (hwaddr_aton(value, ssid->bssid)) {
309 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
314 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
319 #ifndef NO_CONFIG_WRITE
320 static char * wpa_config_write_bssid(const struct parse_data *data,
321 struct wpa_ssid *ssid)
326 if (!ssid->bssid_set)
329 value = os_malloc(20);
332 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
333 if (res < 0 || res >= 20) {
337 value[20 - 1] = '\0';
340 #endif /* NO_CONFIG_WRITE */
343 static int wpa_config_parse_psk(const struct parse_data *data,
344 struct wpa_ssid *ssid, int line,
348 #ifndef CONFIG_NO_PBKDF2
353 pos = os_strrchr(value, '"');
357 len = os_strlen(value);
358 if (len < 8 || len > 63) {
359 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
360 "length %lu (expected: 8..63) '%s'.",
361 line, (unsigned long) len, value);
364 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
366 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
367 os_memcmp(ssid->passphrase, value, len) == 0)
370 os_free(ssid->passphrase);
371 ssid->passphrase = os_malloc(len + 1);
372 if (ssid->passphrase == NULL)
374 os_memcpy(ssid->passphrase, value, len);
375 ssid->passphrase[len] = '\0';
377 #else /* CONFIG_NO_PBKDF2 */
378 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
381 #endif /* CONFIG_NO_PBKDF2 */
384 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
385 value[PMK_LEN * 2] != '\0') {
386 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
391 os_free(ssid->passphrase);
392 ssid->passphrase = NULL;
395 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
400 #ifndef NO_CONFIG_WRITE
401 static char * wpa_config_write_psk(const struct parse_data *data,
402 struct wpa_ssid *ssid)
404 if (ssid->passphrase)
405 return wpa_config_write_string_ascii(
406 (const u8 *) ssid->passphrase,
407 os_strlen(ssid->passphrase));
410 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
414 #endif /* NO_CONFIG_WRITE */
417 static int wpa_config_parse_proto(const struct parse_data *data,
418 struct wpa_ssid *ssid, int line,
421 int val = 0, last, errors = 0;
422 char *start, *end, *buf;
424 buf = os_strdup(value);
429 while (*start != '\0') {
430 while (*start == ' ' || *start == '\t')
435 while (*end != ' ' && *end != '\t' && *end != '\0')
439 if (os_strcmp(start, "WPA") == 0)
440 val |= WPA_PROTO_WPA;
441 else if (os_strcmp(start, "RSN") == 0 ||
442 os_strcmp(start, "WPA2") == 0)
443 val |= WPA_PROTO_RSN;
445 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
457 wpa_printf(MSG_ERROR,
458 "Line %d: no proto values configured.", line);
462 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
464 return errors ? -1 : 0;
468 #ifndef NO_CONFIG_WRITE
469 static char * wpa_config_write_proto(const struct parse_data *data,
470 struct wpa_ssid *ssid)
473 char *buf, *pos, *end;
475 pos = buf = os_zalloc(10);
480 if (ssid->proto & WPA_PROTO_WPA) {
481 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
482 if (ret < 0 || ret >= end - pos)
488 if (ssid->proto & WPA_PROTO_RSN) {
489 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
490 if (ret < 0 || ret >= end - pos)
498 #endif /* NO_CONFIG_WRITE */
501 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
502 struct wpa_ssid *ssid, int line,
505 int val = 0, last, errors = 0;
506 char *start, *end, *buf;
508 buf = os_strdup(value);
513 while (*start != '\0') {
514 while (*start == ' ' || *start == '\t')
519 while (*end != ' ' && *end != '\t' && *end != '\0')
523 if (os_strcmp(start, "WPA-PSK") == 0)
524 val |= WPA_KEY_MGMT_PSK;
525 else if (os_strcmp(start, "WPA-EAP") == 0)
526 val |= WPA_KEY_MGMT_IEEE8021X;
527 else if (os_strcmp(start, "IEEE8021X") == 0)
528 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
529 else if (os_strcmp(start, "NONE") == 0)
530 val |= WPA_KEY_MGMT_NONE;
531 else if (os_strcmp(start, "WPA-NONE") == 0)
532 val |= WPA_KEY_MGMT_WPA_NONE;
533 #ifdef CONFIG_IEEE80211R
534 else if (os_strcmp(start, "FT-PSK") == 0)
535 val |= WPA_KEY_MGMT_FT_PSK;
536 else if (os_strcmp(start, "FT-EAP") == 0)
537 val |= WPA_KEY_MGMT_FT_IEEE8021X;
538 #endif /* CONFIG_IEEE80211R */
539 #ifdef CONFIG_IEEE80211W
540 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
541 val |= WPA_KEY_MGMT_PSK_SHA256;
542 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
543 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
544 #endif /* CONFIG_IEEE80211W */
546 else if (os_strcmp(start, "WPS") == 0)
547 val |= WPA_KEY_MGMT_WPS;
548 #endif /* CONFIG_WPS */
550 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
562 wpa_printf(MSG_ERROR,
563 "Line %d: no key_mgmt values configured.", line);
567 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
568 ssid->key_mgmt = val;
569 return errors ? -1 : 0;
573 #ifndef NO_CONFIG_WRITE
574 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
575 struct wpa_ssid *ssid)
577 char *buf, *pos, *end;
580 pos = buf = os_zalloc(50);
585 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
586 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
587 pos == buf ? "" : " ");
588 if (ret < 0 || ret >= end - pos) {
595 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
596 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
597 pos == buf ? "" : " ");
598 if (ret < 0 || ret >= end - pos) {
605 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
606 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
607 pos == buf ? "" : " ");
608 if (ret < 0 || ret >= end - pos) {
615 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
616 ret = os_snprintf(pos, end - pos, "%sNONE",
617 pos == buf ? "" : " ");
618 if (ret < 0 || ret >= end - pos) {
625 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
626 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
627 pos == buf ? "" : " ");
628 if (ret < 0 || ret >= end - pos) {
635 #ifdef CONFIG_IEEE80211R
636 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
637 pos += os_snprintf(pos, end - pos, "%sFT-PSK",
638 pos == buf ? "" : " ");
640 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
641 pos += os_snprintf(pos, end - pos, "%sFT-EAP",
642 pos == buf ? "" : " ");
643 #endif /* CONFIG_IEEE80211R */
645 #ifdef CONFIG_IEEE80211W
646 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
647 pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
648 pos == buf ? "" : " ");
650 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
651 pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
652 pos == buf ? "" : " ");
653 #endif /* CONFIG_IEEE80211W */
656 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
657 pos += os_snprintf(pos, end - pos, "%sWPS",
658 pos == buf ? "" : " ");
659 #endif /* CONFIG_WPS */
663 #endif /* NO_CONFIG_WRITE */
666 static int wpa_config_parse_cipher(int line, const char *value)
669 char *start, *end, *buf;
671 buf = os_strdup(value);
676 while (*start != '\0') {
677 while (*start == ' ' || *start == '\t')
682 while (*end != ' ' && *end != '\t' && *end != '\0')
686 if (os_strcmp(start, "CCMP") == 0)
687 val |= WPA_CIPHER_CCMP;
688 else if (os_strcmp(start, "TKIP") == 0)
689 val |= WPA_CIPHER_TKIP;
690 else if (os_strcmp(start, "WEP104") == 0)
691 val |= WPA_CIPHER_WEP104;
692 else if (os_strcmp(start, "WEP40") == 0)
693 val |= WPA_CIPHER_WEP40;
694 else if (os_strcmp(start, "NONE") == 0)
695 val |= WPA_CIPHER_NONE;
697 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
710 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
718 #ifndef NO_CONFIG_WRITE
719 static char * wpa_config_write_cipher(int cipher)
721 char *buf, *pos, *end;
724 pos = buf = os_zalloc(50);
729 if (cipher & WPA_CIPHER_CCMP) {
730 ret = os_snprintf(pos, end - pos, "%sCCMP",
731 pos == buf ? "" : " ");
732 if (ret < 0 || ret >= end - pos) {
739 if (cipher & WPA_CIPHER_TKIP) {
740 ret = os_snprintf(pos, end - pos, "%sTKIP",
741 pos == buf ? "" : " ");
742 if (ret < 0 || ret >= end - pos) {
749 if (cipher & WPA_CIPHER_WEP104) {
750 ret = os_snprintf(pos, end - pos, "%sWEP104",
751 pos == buf ? "" : " ");
752 if (ret < 0 || ret >= end - pos) {
759 if (cipher & WPA_CIPHER_WEP40) {
760 ret = os_snprintf(pos, end - pos, "%sWEP40",
761 pos == buf ? "" : " ");
762 if (ret < 0 || ret >= end - pos) {
769 if (cipher & WPA_CIPHER_NONE) {
770 ret = os_snprintf(pos, end - pos, "%sNONE",
771 pos == buf ? "" : " ");
772 if (ret < 0 || ret >= end - pos) {
781 #endif /* NO_CONFIG_WRITE */
784 static int wpa_config_parse_pairwise(const struct parse_data *data,
785 struct wpa_ssid *ssid, int line,
789 val = wpa_config_parse_cipher(line, value);
792 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {
793 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
794 "(0x%x).", line, val);
798 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
799 ssid->pairwise_cipher = val;
804 #ifndef NO_CONFIG_WRITE
805 static char * wpa_config_write_pairwise(const struct parse_data *data,
806 struct wpa_ssid *ssid)
808 return wpa_config_write_cipher(ssid->pairwise_cipher);
810 #endif /* NO_CONFIG_WRITE */
813 static int wpa_config_parse_group(const struct parse_data *data,
814 struct wpa_ssid *ssid, int line,
818 val = wpa_config_parse_cipher(line, value);
821 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |
823 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
824 "(0x%x).", line, val);
828 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
829 ssid->group_cipher = val;
834 #ifndef NO_CONFIG_WRITE
835 static char * wpa_config_write_group(const struct parse_data *data,
836 struct wpa_ssid *ssid)
838 return wpa_config_write_cipher(ssid->group_cipher);
840 #endif /* NO_CONFIG_WRITE */
843 static int wpa_config_parse_auth_alg(const struct parse_data *data,
844 struct wpa_ssid *ssid, int line,
847 int val = 0, last, errors = 0;
848 char *start, *end, *buf;
850 buf = os_strdup(value);
855 while (*start != '\0') {
856 while (*start == ' ' || *start == '\t')
861 while (*end != ' ' && *end != '\t' && *end != '\0')
865 if (os_strcmp(start, "OPEN") == 0)
866 val |= WPA_AUTH_ALG_OPEN;
867 else if (os_strcmp(start, "SHARED") == 0)
868 val |= WPA_AUTH_ALG_SHARED;
869 else if (os_strcmp(start, "LEAP") == 0)
870 val |= WPA_AUTH_ALG_LEAP;
872 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
884 wpa_printf(MSG_ERROR,
885 "Line %d: no auth_alg values configured.", line);
889 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
890 ssid->auth_alg = val;
891 return errors ? -1 : 0;
895 #ifndef NO_CONFIG_WRITE
896 static char * wpa_config_write_auth_alg(const struct parse_data *data,
897 struct wpa_ssid *ssid)
899 char *buf, *pos, *end;
902 pos = buf = os_zalloc(30);
907 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
908 ret = os_snprintf(pos, end - pos, "%sOPEN",
909 pos == buf ? "" : " ");
910 if (ret < 0 || ret >= end - pos) {
917 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
918 ret = os_snprintf(pos, end - pos, "%sSHARED",
919 pos == buf ? "" : " ");
920 if (ret < 0 || ret >= end - pos) {
927 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
928 ret = os_snprintf(pos, end - pos, "%sLEAP",
929 pos == buf ? "" : " ");
930 if (ret < 0 || ret >= end - pos) {
939 #endif /* NO_CONFIG_WRITE */
942 static int * wpa_config_parse_freqs(const struct parse_data *data,
943 struct wpa_ssid *ssid, int line,
952 freqs = os_zalloc((len + 1) * sizeof(int));
963 n = os_realloc(freqs, (len * 2 + 1) * sizeof(int));
968 for (i = len; i <= len * 2; i++)
974 freqs[used] = atoi(pos);
975 if (freqs[used] == 0)
978 pos = os_strchr(pos + 1, ' ');
985 static int wpa_config_parse_scan_freq(const struct parse_data *data,
986 struct wpa_ssid *ssid, int line,
991 freqs = wpa_config_parse_freqs(data, ssid, line, value);
994 os_free(ssid->scan_freq);
995 ssid->scan_freq = freqs;
1001 static int wpa_config_parse_freq_list(const struct parse_data *data,
1002 struct wpa_ssid *ssid, int line,
1007 freqs = wpa_config_parse_freqs(data, ssid, line, value);
1010 os_free(ssid->freq_list);
1011 ssid->freq_list = freqs;
1017 #ifndef NO_CONFIG_WRITE
1018 static char * wpa_config_write_freqs(const struct parse_data *data,
1021 char *buf, *pos, *end;
1029 for (i = 0; freqs[i]; i++)
1032 pos = buf = os_zalloc(10 * count + 1);
1035 end = buf + 10 * count + 1;
1037 for (i = 0; freqs[i]; i++) {
1038 ret = os_snprintf(pos, end - pos, "%s%u",
1039 i == 0 ? "" : " ", freqs[i]);
1040 if (ret < 0 || ret >= end - pos) {
1051 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1052 struct wpa_ssid *ssid)
1054 return wpa_config_write_freqs(data, ssid->scan_freq);
1058 static char * wpa_config_write_freq_list(const struct parse_data *data,
1059 struct wpa_ssid *ssid)
1061 return wpa_config_write_freqs(data, ssid->freq_list);
1063 #endif /* NO_CONFIG_WRITE */
1066 #ifdef IEEE8021X_EAPOL
1067 static int wpa_config_parse_eap(const struct parse_data *data,
1068 struct wpa_ssid *ssid, int line,
1071 int last, errors = 0;
1072 char *start, *end, *buf;
1073 struct eap_method_type *methods = NULL, *tmp;
1074 size_t num_methods = 0;
1076 buf = os_strdup(value);
1081 while (*start != '\0') {
1082 while (*start == ' ' || *start == '\t')
1087 while (*end != ' ' && *end != '\t' && *end != '\0')
1089 last = *end == '\0';
1092 methods = os_realloc(methods,
1093 (num_methods + 1) * sizeof(*methods));
1094 if (methods == NULL) {
1099 methods[num_methods].method = eap_peer_get_type(
1100 start, &methods[num_methods].vendor);
1101 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1102 methods[num_methods].method == EAP_TYPE_NONE) {
1103 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1104 "'%s'", line, start);
1105 wpa_printf(MSG_ERROR, "You may need to add support for"
1106 " this EAP method during wpa_supplicant\n"
1107 "build time configuration.\n"
1108 "See README for more information.");
1110 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1111 methods[num_methods].method == EAP_TYPE_LEAP)
1123 methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));
1124 if (methods == NULL) {
1128 methods[num_methods].vendor = EAP_VENDOR_IETF;
1129 methods[num_methods].method = EAP_TYPE_NONE;
1132 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1133 (u8 *) methods, num_methods * sizeof(*methods));
1134 os_free(ssid->eap.eap_methods);
1135 ssid->eap.eap_methods = methods;
1136 return errors ? -1 : 0;
1140 static char * wpa_config_write_eap(const struct parse_data *data,
1141 struct wpa_ssid *ssid)
1144 char *buf, *pos, *end;
1145 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1148 if (eap_methods == NULL)
1151 pos = buf = os_zalloc(100);
1156 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1157 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1158 name = eap_get_name(eap_methods[i].vendor,
1159 eap_methods[i].method);
1161 ret = os_snprintf(pos, end - pos, "%s%s",
1162 pos == buf ? "" : " ", name);
1163 if (ret < 0 || ret >= end - pos)
1175 static int wpa_config_parse_password(const struct parse_data *data,
1176 struct wpa_ssid *ssid, int line,
1181 if (os_strcmp(value, "NULL") == 0) {
1182 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1183 os_free(ssid->eap.password);
1184 ssid->eap.password = NULL;
1185 ssid->eap.password_len = 0;
1189 if (os_strncmp(value, "hash:", 5) != 0) {
1193 tmp = wpa_config_parse_string(value, &res_len);
1195 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1199 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1200 (u8 *) tmp, res_len);
1202 os_free(ssid->eap.password);
1203 ssid->eap.password = (u8 *) tmp;
1204 ssid->eap.password_len = res_len;
1205 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1211 /* NtPasswordHash: hash:<32 hex digits> */
1212 if (os_strlen(value + 5) != 2 * 16) {
1213 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1214 "(expected 32 hex digits)", line);
1218 hash = os_malloc(16);
1222 if (hexstr2bin(value + 5, hash, 16)) {
1224 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1228 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1230 os_free(ssid->eap.password);
1231 ssid->eap.password = hash;
1232 ssid->eap.password_len = 16;
1233 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1239 static char * wpa_config_write_password(const struct parse_data *data,
1240 struct wpa_ssid *ssid)
1244 if (ssid->eap.password == NULL)
1247 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1248 return wpa_config_write_string(
1249 ssid->eap.password, ssid->eap.password_len);
1252 buf = os_malloc(5 + 32 + 1);
1256 os_memcpy(buf, "hash:", 5);
1257 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1261 #endif /* IEEE8021X_EAPOL */
1264 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1265 const char *value, int idx)
1267 char *buf, title[20];
1270 buf = wpa_config_parse_string(value, len);
1272 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1276 if (*len > MAX_WEP_KEY_LEN) {
1277 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1282 if (*len && *len != 5 && *len != 13 && *len != 16) {
1283 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1284 "this network block will be ignored",
1285 line, (unsigned int) *len);
1287 os_memcpy(key, buf, *len);
1289 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1290 if (res >= 0 && (size_t) res < sizeof(title))
1291 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1296 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1297 struct wpa_ssid *ssid, int line,
1300 return wpa_config_parse_wep_key(ssid->wep_key[0],
1301 &ssid->wep_key_len[0], line,
1306 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1307 struct wpa_ssid *ssid, int line,
1310 return wpa_config_parse_wep_key(ssid->wep_key[1],
1311 &ssid->wep_key_len[1], line,
1316 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1317 struct wpa_ssid *ssid, int line,
1320 return wpa_config_parse_wep_key(ssid->wep_key[2],
1321 &ssid->wep_key_len[2], line,
1326 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1327 struct wpa_ssid *ssid, int line,
1330 return wpa_config_parse_wep_key(ssid->wep_key[3],
1331 &ssid->wep_key_len[3], line,
1336 #ifndef NO_CONFIG_WRITE
1337 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1339 if (ssid->wep_key_len[idx] == 0)
1341 return wpa_config_write_string(ssid->wep_key[idx],
1342 ssid->wep_key_len[idx]);
1346 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1347 struct wpa_ssid *ssid)
1349 return wpa_config_write_wep_key(ssid, 0);
1353 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1354 struct wpa_ssid *ssid)
1356 return wpa_config_write_wep_key(ssid, 1);
1360 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1361 struct wpa_ssid *ssid)
1363 return wpa_config_write_wep_key(ssid, 2);
1367 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1368 struct wpa_ssid *ssid)
1370 return wpa_config_write_wep_key(ssid, 3);
1372 #endif /* NO_CONFIG_WRITE */
1377 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1378 struct wpa_ssid *ssid, int line,
1382 u8 *buf, *n, addr[ETH_ALEN];
1389 while (pos && *pos) {
1393 if (hwaddr_aton(pos, addr)) {
1394 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1395 "p2p_client_list address '%s'.",
1397 /* continue anyway */
1399 n = os_realloc(buf, (count + 1) * ETH_ALEN);
1405 os_memcpy(buf + count * ETH_ALEN, addr, ETH_ALEN);
1407 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1411 pos = os_strchr(pos, ' ');
1414 os_free(ssid->p2p_client_list);
1415 ssid->p2p_client_list = buf;
1416 ssid->num_p2p_clients = count;
1422 #ifndef NO_CONFIG_WRITE
1423 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1424 struct wpa_ssid *ssid)
1426 char *value, *end, *pos;
1430 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1433 value = os_malloc(20 * ssid->num_p2p_clients);
1437 end = value + 20 * ssid->num_p2p_clients;
1439 for (i = 0; i < ssid->num_p2p_clients; i++) {
1440 res = os_snprintf(pos, end - pos, MACSTR " ",
1441 MAC2STR(ssid->p2p_client_list +
1443 if (res < 0 || res >= end - pos) {
1455 #endif /* NO_CONFIG_WRITE */
1457 #endif /* CONFIG_P2P */
1459 /* Helper macros for network block parser */
1464 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1465 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1467 /* STR: Define a string variable for an ASCII string; f = field name */
1468 #ifdef NO_CONFIG_WRITE
1469 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1470 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1471 #else /* NO_CONFIG_WRITE */
1472 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1473 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1474 #endif /* NO_CONFIG_WRITE */
1475 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1476 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1477 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1478 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1480 /* STR_LEN: Define a string variable with a separate variable for storing the
1481 * data length. Unlike STR(), this can be used to store arbitrary binary data
1482 * (i.e., even nul termination character). */
1483 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1484 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1485 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1486 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1487 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1489 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1490 * explicitly specified. */
1491 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1492 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1493 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1495 #ifdef NO_CONFIG_WRITE
1496 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1497 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1498 #else /* NO_CONFIG_WRITE */
1499 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1500 OFFSET(f), (void *) 0
1501 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1502 OFFSET(eap.f), (void *) 0
1503 #ifdef WPA_UNICODE_SSID
1504 /* STR_* variants that do not force conversion to ASCII */
1505 #define _STR_UNICODE(f) #f, wpa_config_parse_str, wpa_config_write_str_unicode, OFFSET(f)
1506 #define STR_UNICODE(f) _STR_UNICODE(f), NULL, NULL, NULL, 0
1507 #define _STR_LEN_UNICODE(f) _STR_UNICODE(f), OFFSET(f ## _len)
1508 #define STR_LEN_UNICODE(f) _STR_LEN_UNICODE(f), NULL, NULL, 0
1509 #define _STR_RANGE_UNICODE(f, min, max) _STR_LEN_UNICODE(f), (void *) (min), (void *) (max)
1510 #define STR_RANGE_UNICODE(f, min, max) _STR_RANGE_UNICODE(f, min, max), 0
1512 #endif /* NO_CONFIG_WRITE */
1514 /* INT: Define an integer variable */
1515 #define INT(f) _INT(f), NULL, NULL, 0
1516 #define INTe(f) _INTe(f), NULL, NULL, 0
1518 /* INT_RANGE: Define an integer variable with allowed value range */
1519 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1521 /* FUNC: Define a configuration variable that uses a custom function for
1522 * parsing and writing the value. */
1523 #ifdef NO_CONFIG_WRITE
1524 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1525 #else /* NO_CONFIG_WRITE */
1526 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1527 NULL, NULL, NULL, NULL
1528 #endif /* NO_CONFIG_WRITE */
1529 #define FUNC(f) _FUNC(f), 0
1530 #define FUNC_KEY(f) _FUNC(f), 1
1533 * Table of network configuration variables. This table is used to parse each
1534 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1535 * that is inside a network block.
1537 * This table is generated using the helper macros defined above and with
1538 * generous help from the C pre-processor. The field name is stored as a string
1539 * into .name and for STR and INT types, the offset of the target buffer within
1540 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1541 * offset to the field containing the length of the configuration variable.
1542 * .param3 and .param4 can be used to mark the allowed range (length for STR
1543 * and value for INT).
1545 * For each configuration line in wpa_supplicant.conf, the parser goes through
1546 * this table and select the entry that matches with the field name. The parser
1547 * function (.parser) is then called to parse the actual value of the field.
1549 * This kind of mechanism makes it easy to add new configuration parameters,
1550 * since only one line needs to be added into this table and into the
1551 * struct wpa_ssid definition if the new variable is either a string or
1552 * integer. More complex types will need to use their own parser and writer
1555 static const struct parse_data ssid_fields[] = {
1556 #ifdef WPA_UNICODE_SSID
1557 { STR_RANGE_UNICODE(ssid, 0, MAX_SSID_LEN) },
1559 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1561 { INT_RANGE(scan_ssid, 0, 1) },
1566 { INT(bg_scan_period) },
1570 { FUNC(scan_freq) },
1571 { FUNC(freq_list) },
1572 #ifdef IEEE8021X_EAPOL
1574 { STR_LENe(identity) },
1575 { STR_LENe(anonymous_identity) },
1576 { FUNC_KEY(password) },
1579 { STRe(client_cert) },
1580 { STRe(private_key) },
1581 { STR_KEYe(private_key_passwd) },
1583 { STRe(subject_match) },
1584 { STRe(altsubject_match) },
1587 { STRe(client_cert2) },
1588 { STRe(private_key2) },
1589 { STR_KEYe(private_key2_passwd) },
1591 { STRe(subject_match2) },
1592 { STRe(altsubject_match2) },
1597 { STRe(engine_id) },
1600 { STRe(ca_cert_id) },
1602 { STRe(engine2_id) },
1605 { STRe(ca_cert2_id) },
1608 { INT(eapol_flags) },
1609 #endif /* IEEE8021X_EAPOL */
1610 { FUNC_KEY(wep_key0) },
1611 { FUNC_KEY(wep_key1) },
1612 { FUNC_KEY(wep_key2) },
1613 { FUNC_KEY(wep_key3) },
1614 { INT(wep_tx_keyidx) },
1616 #ifdef IEEE8021X_EAPOL
1617 { INT(eap_workaround) },
1619 { INTe(fragment_size) },
1620 #endif /* IEEE8021X_EAPOL */
1621 { INT_RANGE(mode, 0, 4) },
1622 { INT_RANGE(proactive_key_caching, 0, 1) },
1623 { INT_RANGE(disabled, 0, 2) },
1625 #ifdef CONFIG_IEEE80211W
1626 { INT_RANGE(ieee80211w, 0, 2) },
1627 #endif /* CONFIG_IEEE80211W */
1628 { INT_RANGE(peerkey, 0, 1) },
1629 { INT_RANGE(mixed_cell, 0, 1) },
1630 { INT_RANGE(frequency, 0, 10000) },
1631 { INT(wpa_ptk_rekey) },
1633 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1635 { FUNC(p2p_client_list) },
1636 #endif /* CONFIG_P2P */
1637 #ifdef CONFIG_HT_OVERRIDES
1638 { INT_RANGE(disable_ht, 0, 1) },
1639 { INT_RANGE(disable_ht40, -1, 1) },
1640 { INT_RANGE(disable_max_amsdu, -1, 1) },
1641 { INT_RANGE(ampdu_factor, -1, 3) },
1642 { INT_RANGE(ampdu_density, -1, 7) },
1644 #endif /* CONFIG_HT_OVERRIDES */
1645 { INT(ap_max_inactivity) },
1646 { INT(dtim_period) },
1649 #ifdef WPA_UNICODE_SSID
1652 #undef _STR_LEN_UNICODE
1653 #undef STR_LEN_UNICODE
1654 #undef _STR_RANGE_UNICODE
1655 #undef STR_RANGE_UNICODE
1667 #undef STR_RANGE_KEY
1674 #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
1678 * wpa_config_add_prio_network - Add a network to priority lists
1679 * @config: Configuration data from wpa_config_read()
1680 * @ssid: Pointer to the network configuration to be added to the list
1681 * Returns: 0 on success, -1 on failure
1683 * This function is used to add a network block to the priority list of
1684 * networks. This must be called for each network when reading in the full
1685 * configuration. In addition, this can be used indirectly when updating
1686 * priorities by calling wpa_config_update_prio_list().
1688 int wpa_config_add_prio_network(struct wpa_config *config,
1689 struct wpa_ssid *ssid)
1692 struct wpa_ssid *prev, **nlist;
1695 * Add to an existing priority list if one is available for the
1696 * configured priority level for this network.
1698 for (prio = 0; prio < config->num_prio; prio++) {
1699 prev = config->pssid[prio];
1700 if (prev->priority == ssid->priority) {
1708 /* First network for this priority - add a new priority list */
1709 nlist = os_realloc(config->pssid,
1710 (config->num_prio + 1) * sizeof(struct wpa_ssid *));
1714 for (prio = 0; prio < config->num_prio; prio++) {
1715 if (nlist[prio]->priority < ssid->priority) {
1716 os_memmove(&nlist[prio + 1], &nlist[prio],
1717 (config->num_prio - prio) *
1718 sizeof(struct wpa_ssid *));
1725 config->pssid = nlist;
1732 * wpa_config_update_prio_list - Update network priority list
1733 * @config: Configuration data from wpa_config_read()
1734 * Returns: 0 on success, -1 on failure
1736 * This function is called to update the priority list of networks in the
1737 * configuration when a network is being added or removed. This is also called
1738 * if a priority for a network is changed.
1740 int wpa_config_update_prio_list(struct wpa_config *config)
1742 struct wpa_ssid *ssid;
1745 os_free(config->pssid);
1746 config->pssid = NULL;
1747 config->num_prio = 0;
1749 ssid = config->ssid;
1752 if (wpa_config_add_prio_network(config, ssid) < 0)
1761 #ifdef IEEE8021X_EAPOL
1762 static void eap_peer_config_free(struct eap_peer_config *eap)
1764 os_free(eap->eap_methods);
1765 os_free(eap->identity);
1766 os_free(eap->anonymous_identity);
1767 os_free(eap->password);
1768 os_free(eap->ca_cert);
1769 os_free(eap->ca_path);
1770 os_free(eap->client_cert);
1771 os_free(eap->private_key);
1772 os_free(eap->private_key_passwd);
1773 os_free(eap->dh_file);
1774 os_free(eap->subject_match);
1775 os_free(eap->altsubject_match);
1776 os_free(eap->ca_cert2);
1777 os_free(eap->ca_path2);
1778 os_free(eap->client_cert2);
1779 os_free(eap->private_key2);
1780 os_free(eap->private_key2_passwd);
1781 os_free(eap->dh_file2);
1782 os_free(eap->subject_match2);
1783 os_free(eap->altsubject_match2);
1784 os_free(eap->phase1);
1785 os_free(eap->phase2);
1788 os_free(eap->engine_id);
1789 os_free(eap->key_id);
1790 os_free(eap->cert_id);
1791 os_free(eap->ca_cert_id);
1792 os_free(eap->key2_id);
1793 os_free(eap->cert2_id);
1794 os_free(eap->ca_cert2_id);
1796 os_free(eap->engine2_id);
1798 os_free(eap->pending_req_otp);
1799 os_free(eap->pac_file);
1800 os_free(eap->new_password);
1802 #endif /* IEEE8021X_EAPOL */
1806 * wpa_config_free_ssid - Free network/ssid configuration data
1807 * @ssid: Configuration data for the network
1809 * This function frees all resources allocated for the network configuration
1812 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1814 os_free(ssid->ssid);
1815 os_free(ssid->passphrase);
1816 #ifdef IEEE8021X_EAPOL
1817 eap_peer_config_free(&ssid->eap);
1818 #endif /* IEEE8021X_EAPOL */
1819 os_free(ssid->id_str);
1820 os_free(ssid->scan_freq);
1821 os_free(ssid->freq_list);
1822 os_free(ssid->bgscan);
1823 os_free(ssid->p2p_client_list);
1824 #ifdef CONFIG_HT_OVERRIDES
1825 os_free(ssid->ht_mcs);
1826 #endif /* CONFIG_HT_OVERRIDES */
1831 void wpa_config_free_cred(struct wpa_cred *cred)
1833 os_free(cred->realm);
1834 os_free(cred->username);
1835 os_free(cred->password);
1836 os_free(cred->ca_cert);
1837 os_free(cred->client_cert);
1838 os_free(cred->private_key);
1839 os_free(cred->private_key_passwd);
1840 os_free(cred->imsi);
1841 os_free(cred->milenage);
1842 os_free(cred->domain);
1848 * wpa_config_free - Free configuration data
1849 * @config: Configuration data from wpa_config_read()
1851 * This function frees all resources allocated for the configuration data by
1852 * wpa_config_read().
1854 void wpa_config_free(struct wpa_config *config)
1856 #ifndef CONFIG_NO_CONFIG_BLOBS
1857 struct wpa_config_blob *blob, *prevblob;
1858 #endif /* CONFIG_NO_CONFIG_BLOBS */
1859 struct wpa_ssid *ssid, *prev = NULL;
1860 struct wpa_cred *cred, *cprev;
1862 ssid = config->ssid;
1866 wpa_config_free_ssid(prev);
1869 cred = config->cred;
1873 wpa_config_free_cred(cprev);
1876 #ifndef CONFIG_NO_CONFIG_BLOBS
1877 blob = config->blobs;
1882 wpa_config_free_blob(prevblob);
1884 #endif /* CONFIG_NO_CONFIG_BLOBS */
1886 wpabuf_free(config->wps_vendor_ext_m1);
1887 os_free(config->ctrl_interface);
1888 os_free(config->ctrl_interface_group);
1889 os_free(config->opensc_engine_path);
1890 os_free(config->pkcs11_engine_path);
1891 os_free(config->pkcs11_module_path);
1892 os_free(config->pcsc_reader);
1893 os_free(config->pcsc_pin);
1894 os_free(config->driver_param);
1895 os_free(config->device_name);
1896 os_free(config->manufacturer);
1897 os_free(config->model_name);
1898 os_free(config->model_number);
1899 os_free(config->serial_number);
1900 os_free(config->config_methods);
1901 os_free(config->p2p_ssid_postfix);
1902 os_free(config->pssid);
1903 os_free(config->p2p_pref_chan);
1904 os_free(config->autoscan);
1905 wpabuf_free(config->wps_nfc_dh_pubkey);
1906 wpabuf_free(config->wps_nfc_dh_privkey);
1907 wpabuf_free(config->wps_nfc_dev_pw);
1909 os_free(config->prioritize);
1916 * wpa_config_foreach_network - Iterate over each configured network
1917 * @config: Configuration data from wpa_config_read()
1918 * @func: Callback function to process each network
1919 * @arg: Opaque argument to pass to callback function
1921 * Iterate over the set of configured networks calling the specified
1922 * function for each item. We guard against callbacks removing the
1925 void wpa_config_foreach_network(struct wpa_config *config,
1926 void (*func)(void *, struct wpa_ssid *),
1929 struct wpa_ssid *ssid, *next;
1931 ssid = config->ssid;
1941 * wpa_config_get_network - Get configured network based on id
1942 * @config: Configuration data from wpa_config_read()
1943 * @id: Unique network id to search for
1944 * Returns: Network configuration or %NULL if not found
1946 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
1948 struct wpa_ssid *ssid;
1950 ssid = config->ssid;
1962 * wpa_config_add_network - Add a new network with empty configuration
1963 * @config: Configuration data from wpa_config_read()
1964 * Returns: The new network configuration or %NULL if operation failed
1966 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
1969 struct wpa_ssid *ssid, *last = NULL;
1972 ssid = config->ssid;
1981 ssid = os_zalloc(sizeof(*ssid));
1988 config->ssid = ssid;
1990 wpa_config_update_prio_list(config);
1997 * wpa_config_remove_network - Remove a configured network based on id
1998 * @config: Configuration data from wpa_config_read()
1999 * @id: Unique network id to search for
2000 * Returns: 0 on success, or -1 if the network was not found
2002 int wpa_config_remove_network(struct wpa_config *config, int id)
2004 struct wpa_ssid *ssid, *prev = NULL;
2006 ssid = config->ssid;
2018 prev->next = ssid->next;
2020 config->ssid = ssid->next;
2022 wpa_config_update_prio_list(config);
2023 wpa_config_free_ssid(ssid);
2029 * wpa_config_set_network_defaults - Set network default values
2030 * @ssid: Pointer to network configuration data
2032 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2034 ssid->proto = DEFAULT_PROTO;
2035 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2036 ssid->group_cipher = DEFAULT_GROUP;
2037 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2038 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2039 #ifdef IEEE8021X_EAPOL
2040 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2041 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2042 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2043 #endif /* IEEE8021X_EAPOL */
2044 #ifdef CONFIG_HT_OVERRIDES
2045 ssid->disable_ht = DEFAULT_DISABLE_HT;
2046 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2047 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2048 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2049 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2050 #endif /* CONFIG_HT_OVERRIDES */
2055 * wpa_config_set - Set a variable in network configuration
2056 * @ssid: Pointer to network configuration data
2057 * @var: Variable name, e.g., "ssid"
2058 * @value: Variable value
2059 * @line: Line number in configuration file or 0 if not used
2060 * Returns: 0 on success, -1 on failure
2062 * This function can be used to set network configuration variables based on
2063 * both the configuration file and management interface input. The value
2064 * parameter must be in the same format as the text-based configuration file is
2065 * using. For example, strings are using double quotation marks.
2067 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2073 if (ssid == NULL || var == NULL || value == NULL)
2076 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2077 const struct parse_data *field = &ssid_fields[i];
2078 if (os_strcmp(var, field->name) != 0)
2081 if (field->parser(field, ssid, line, value)) {
2083 wpa_printf(MSG_ERROR, "Line %d: failed to "
2084 "parse %s '%s'.", line, var, value);
2090 if (i == NUM_SSID_FIELDS) {
2092 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2093 "'%s'.", line, var);
2102 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2109 len = os_strlen(value);
2110 buf = os_malloc(len + 3);
2114 os_memcpy(buf + 1, value, len);
2116 buf[len + 2] = '\0';
2117 ret = wpa_config_set(ssid, var, buf, 0);
2124 * wpa_config_get_all - Get all options from network configuration
2125 * @ssid: Pointer to network configuration data
2126 * @get_keys: Determines if keys/passwords will be included in returned list
2127 * (if they may be exported)
2128 * Returns: %NULL terminated list of all set keys and their values in the form
2129 * of [key1, val1, key2, val2, ... , NULL]
2131 * This function can be used to get list of all configured network properties.
2132 * The caller is responsible for freeing the returned list and all its
2135 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2137 const struct parse_data *field;
2143 get_keys = get_keys && ssid->export_keys;
2145 props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
2150 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2151 field = &ssid_fields[i];
2152 if (field->key_data && !get_keys)
2154 value = field->writer(field, ssid);
2157 if (os_strlen(value) == 0) {
2162 key = os_strdup(field->name);
2168 props[fields_num * 2] = key;
2169 props[fields_num * 2 + 1] = value;
2185 #ifndef NO_CONFIG_WRITE
2187 * wpa_config_get - Get a variable in network configuration
2188 * @ssid: Pointer to network configuration data
2189 * @var: Variable name, e.g., "ssid"
2190 * Returns: Value of the variable or %NULL on failure
2192 * This function can be used to get network configuration variables. The
2193 * returned value is a copy of the configuration variable in text format, i.e,.
2194 * the same format that the text-based configuration file and wpa_config_set()
2195 * are using for the value. The caller is responsible for freeing the returned
2198 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2202 if (ssid == NULL || var == NULL)
2205 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2206 const struct parse_data *field = &ssid_fields[i];
2207 if (os_strcmp(var, field->name) == 0)
2208 return field->writer(field, ssid);
2216 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2217 * @ssid: Pointer to network configuration data
2218 * @var: Variable name, e.g., "ssid"
2219 * Returns: Value of the variable or %NULL on failure
2221 * This function can be used to get network configuration variable like
2222 * wpa_config_get(). The only difference is that this functions does not expose
2223 * key/password material from the configuration. In case a key/password field
2224 * is requested, the returned value is an empty string or %NULL if the variable
2225 * is not set or "*" if the variable is set (regardless of its value). The
2226 * returned value is a copy of the configuration variable in text format, i.e,.
2227 * the same format that the text-based configuration file and wpa_config_set()
2228 * are using for the value. The caller is responsible for freeing the returned
2231 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2235 if (ssid == NULL || var == NULL)
2238 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2239 const struct parse_data *field = &ssid_fields[i];
2240 if (os_strcmp(var, field->name) == 0) {
2241 char *res = field->writer(field, ssid);
2242 if (field->key_data) {
2243 if (res && res[0]) {
2244 wpa_printf(MSG_DEBUG, "Do not allow "
2245 "key_data field to be "
2248 return os_strdup("*");
2260 #endif /* NO_CONFIG_WRITE */
2264 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2265 * @ssid: Pointer to network configuration data
2267 * This function must be called to update WPA PSK when either SSID or the
2268 * passphrase has changed for the network configuration.
2270 void wpa_config_update_psk(struct wpa_ssid *ssid)
2272 #ifndef CONFIG_NO_PBKDF2
2273 pbkdf2_sha1(ssid->passphrase,
2274 (char *) ssid->ssid, ssid->ssid_len, 4096,
2275 ssid->psk, PMK_LEN);
2276 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2277 ssid->psk, PMK_LEN);
2279 #endif /* CONFIG_NO_PBKDF2 */
2283 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2284 const char *value, int line)
2289 if (os_strcmp(var, "priority") == 0) {
2290 cred->priority = atoi(value);
2294 if (os_strcmp(var, "pcsc") == 0) {
2295 cred->pcsc = atoi(value);
2299 val = wpa_config_parse_string(value, &len);
2301 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2302 "value '%s'.", line, var, value);
2306 if (os_strcmp(var, "realm") == 0) {
2307 os_free(cred->realm);
2312 if (os_strcmp(var, "username") == 0) {
2313 os_free(cred->username);
2314 cred->username = val;
2318 if (os_strcmp(var, "password") == 0) {
2319 os_free(cred->password);
2320 cred->password = val;
2324 if (os_strcmp(var, "ca_cert") == 0) {
2325 os_free(cred->ca_cert);
2326 cred->ca_cert = val;
2330 if (os_strcmp(var, "client_cert") == 0) {
2331 os_free(cred->client_cert);
2332 cred->client_cert = val;
2336 if (os_strcmp(var, "private_key") == 0) {
2337 os_free(cred->private_key);
2338 cred->private_key = val;
2342 if (os_strcmp(var, "private_key_passwd") == 0) {
2343 os_free(cred->private_key_passwd);
2344 cred->private_key_passwd = val;
2348 if (os_strcmp(var, "imsi") == 0) {
2349 os_free(cred->imsi);
2354 if (os_strcmp(var, "milenage") == 0) {
2355 os_free(cred->milenage);
2356 cred->milenage = val;
2360 if (os_strcmp(var, "domain") == 0) {
2361 os_free(cred->domain);
2367 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2377 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
2379 struct wpa_cred *cred;
2381 cred = config->cred;
2392 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
2395 struct wpa_cred *cred, *last = NULL;
2398 cred = config->cred;
2407 cred = os_zalloc(sizeof(*cred));
2414 config->cred = cred;
2420 int wpa_config_remove_cred(struct wpa_config *config, int id)
2422 struct wpa_cred *cred, *prev = NULL;
2424 cred = config->cred;
2436 prev->next = cred->next;
2438 config->cred = cred->next;
2440 wpa_config_free_cred(cred);
2445 #ifndef CONFIG_NO_CONFIG_BLOBS
2447 * wpa_config_get_blob - Get a named configuration blob
2448 * @config: Configuration data from wpa_config_read()
2449 * @name: Name of the blob
2450 * Returns: Pointer to blob data or %NULL if not found
2452 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
2455 struct wpa_config_blob *blob = config->blobs;
2458 if (os_strcmp(blob->name, name) == 0)
2467 * wpa_config_set_blob - Set or add a named configuration blob
2468 * @config: Configuration data from wpa_config_read()
2469 * @blob: New value for the blob
2471 * Adds a new configuration blob or replaces the current value of an existing
2474 void wpa_config_set_blob(struct wpa_config *config,
2475 struct wpa_config_blob *blob)
2477 wpa_config_remove_blob(config, blob->name);
2478 blob->next = config->blobs;
2479 config->blobs = blob;
2484 * wpa_config_free_blob - Free blob data
2485 * @blob: Pointer to blob to be freed
2487 void wpa_config_free_blob(struct wpa_config_blob *blob)
2490 os_free(blob->name);
2491 os_free(blob->data);
2498 * wpa_config_remove_blob - Remove a named configuration blob
2499 * @config: Configuration data from wpa_config_read()
2500 * @name: Name of the blob to remove
2501 * Returns: 0 if blob was removed or -1 if blob was not found
2503 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
2505 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
2508 if (os_strcmp(pos->name, name) == 0) {
2510 prev->next = pos->next;
2512 config->blobs = pos->next;
2513 wpa_config_free_blob(pos);
2522 #endif /* CONFIG_NO_CONFIG_BLOBS */
2526 * wpa_config_alloc_empty - Allocate an empty configuration
2527 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
2529 * @driver_param: Driver parameters
2530 * Returns: Pointer to allocated configuration data or %NULL on failure
2532 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
2533 const char *driver_param)
2535 struct wpa_config *config;
2537 config = os_zalloc(sizeof(*config));
2540 config->eapol_version = DEFAULT_EAPOL_VERSION;
2541 config->ap_scan = DEFAULT_AP_SCAN;
2542 config->fast_reauth = DEFAULT_FAST_REAUTH;
2543 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
2544 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
2545 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
2546 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
2547 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
2548 config->max_num_sta = DEFAULT_MAX_NUM_STA;
2549 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
2552 config->ctrl_interface = os_strdup(ctrl_interface);
2554 config->driver_param = os_strdup(driver_param);
2560 #ifndef CONFIG_NO_STDOUT_DEBUG
2562 * wpa_config_debug_dump_networks - Debug dump of configured networks
2563 * @config: Configuration data from wpa_config_read()
2565 void wpa_config_debug_dump_networks(struct wpa_config *config)
2568 struct wpa_ssid *ssid;
2570 for (prio = 0; prio < config->num_prio; prio++) {
2571 ssid = config->pssid[prio];
2572 wpa_printf(MSG_DEBUG, "Priority group %d",
2575 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
2577 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2582 #endif /* CONFIG_NO_STDOUT_DEBUG */
2585 struct global_parse_data {
2587 int (*parser)(const struct global_parse_data *data,
2588 struct wpa_config *config, int line, const char *value);
2589 void *param1, *param2, *param3;
2590 unsigned int changed_flag;
2594 static int wpa_global_config_parse_int(const struct global_parse_data *data,
2595 struct wpa_config *config, int line,
2599 dst = (int *) (((u8 *) config) + (long) data->param1);
2601 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
2603 if (data->param2 && *dst < (long) data->param2) {
2604 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
2605 "min_value=%ld)", line, data->name, *dst,
2606 (long) data->param2);
2607 *dst = (long) data->param2;
2611 if (data->param3 && *dst > (long) data->param3) {
2612 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
2613 "max_value=%ld)", line, data->name, *dst,
2614 (long) data->param3);
2615 *dst = (long) data->param3;
2623 static int wpa_global_config_parse_str(const struct global_parse_data *data,
2624 struct wpa_config *config, int line,
2630 len = os_strlen(pos);
2631 if (data->param2 && len < (size_t) data->param2) {
2632 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
2633 "min_len=%ld)", line, data->name,
2634 (unsigned long) len, (long) data->param2);
2638 if (data->param3 && len > (size_t) data->param3) {
2639 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
2640 "max_len=%ld)", line, data->name,
2641 (unsigned long) len, (long) data->param3);
2645 tmp = os_strdup(pos);
2649 dst = (char **) (((u8 *) config) + (long) data->param1);
2652 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
2658 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
2659 struct wpa_config *config, int line,
2663 struct wpabuf **dst, *tmp;
2665 len = os_strlen(pos);
2669 tmp = wpabuf_alloc(len / 2);
2673 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
2678 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
2681 wpa_printf(MSG_DEBUG, "%s", data->name);
2687 static int wpa_config_process_country(const struct global_parse_data *data,
2688 struct wpa_config *config, int line,
2691 if (!pos[0] || !pos[1]) {
2692 wpa_printf(MSG_DEBUG, "Invalid country set");
2695 config->country[0] = pos[0];
2696 config->country[1] = pos[1];
2697 wpa_printf(MSG_DEBUG, "country='%c%c'",
2698 config->country[0], config->country[1]);
2703 static int wpa_config_process_load_dynamic_eap(
2704 const struct global_parse_data *data, struct wpa_config *config,
2705 int line, const char *so)
2708 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
2709 ret = eap_peer_method_load(so);
2711 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
2714 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
2715 "method '%s'.", line, so);
2725 static int wpa_config_process_uuid(const struct global_parse_data *data,
2726 struct wpa_config *config, int line,
2730 if (uuid_str2bin(pos, config->uuid)) {
2731 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2734 uuid_bin2str(config->uuid, buf, sizeof(buf));
2735 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
2740 static int wpa_config_process_device_type(
2741 const struct global_parse_data *data,
2742 struct wpa_config *config, int line, const char *pos)
2744 return wps_dev_type_str2bin(pos, config->device_type);
2748 static int wpa_config_process_os_version(const struct global_parse_data *data,
2749 struct wpa_config *config, int line,
2752 if (hexstr2bin(pos, config->os_version, 4)) {
2753 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
2756 wpa_printf(MSG_DEBUG, "os_version=%08x",
2757 WPA_GET_BE32(config->os_version));
2762 static int wpa_config_process_wps_vendor_ext_m1(
2763 const struct global_parse_data *data,
2764 struct wpa_config *config, int line, const char *pos)
2767 int len = os_strlen(pos) / 2;
2771 wpa_printf(MSG_ERROR, "Line %d: "
2772 "invalid wps_vendor_ext_m1", line);
2776 tmp = wpabuf_alloc(len);
2778 p = wpabuf_put(tmp, len);
2780 if (hexstr2bin(pos, p, len)) {
2781 wpa_printf(MSG_ERROR, "Line %d: "
2782 "invalid wps_vendor_ext_m1", line);
2787 wpabuf_free(config->wps_vendor_ext_m1);
2788 config->wps_vendor_ext_m1 = tmp;
2790 wpa_printf(MSG_ERROR, "Can not allocate "
2791 "memory for wps_vendor_ext_m1");
2798 #endif /* CONFIG_WPS */
2801 static int wpa_config_process_sec_device_type(
2802 const struct global_parse_data *data,
2803 struct wpa_config *config, int line, const char *pos)
2807 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
2808 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
2813 idx = config->num_sec_device_types;
2815 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
2818 config->num_sec_device_types++;
2823 static int wpa_config_process_p2p_pref_chan(
2824 const struct global_parse_data *data,
2825 struct wpa_config *config, int line, const char *pos)
2827 struct p2p_channel *pref = NULL, *n;
2828 unsigned int num = 0;
2832 /* format: class:chan,class:chan,... */
2835 op_class = atoi(pos);
2836 pos2 = os_strchr(pos, ':');
2842 n = os_realloc(pref, (num + 1) * sizeof(struct p2p_channel));
2846 pref[num].op_class = op_class;
2847 pref[num].chan = chan;
2850 pos = os_strchr(pos2, ',');
2856 os_free(config->p2p_pref_chan);
2857 config->p2p_pref_chan = pref;
2858 config->num_p2p_pref_chan = num;
2859 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
2860 (u8 *) config->p2p_pref_chan,
2861 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
2867 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
2870 #endif /* CONFIG_P2P */
2873 static int wpa_config_process_hessid(
2874 const struct global_parse_data *data,
2875 struct wpa_config *config, int line, const char *pos)
2877 if (hwaddr_aton2(pos, config->hessid) < 0) {
2878 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
2890 /* OFFSET: Get offset of a variable within the wpa_config structure */
2891 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
2893 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
2894 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
2895 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
2896 #define INT(f) _INT(f), NULL, NULL
2897 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
2898 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
2899 #define STR(f) _STR(f), NULL, NULL
2900 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
2901 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
2903 static const struct global_parse_data global_fields[] = {
2904 #ifdef CONFIG_CTRL_IFACE
2905 { STR(ctrl_interface), 0 },
2906 { STR(ctrl_interface_group), 0 } /* deprecated */,
2907 #endif /* CONFIG_CTRL_IFACE */
2908 { INT_RANGE(eapol_version, 1, 2), 0 },
2909 { INT(ap_scan), 0 },
2910 { INT(disable_scan_offload), 0 },
2911 { INT(fast_reauth), 0 },
2912 { STR(opensc_engine_path), 0 },
2913 { STR(pkcs11_engine_path), 0 },
2914 { STR(pkcs11_module_path), 0 },
2915 { STR(pcsc_reader), 0 },
2916 { STR(pcsc_pin), 0 },
2917 { STR(driver_param), 0 },
2918 { INT(dot11RSNAConfigPMKLifetime), 0 },
2919 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
2920 { INT(dot11RSNAConfigSATimeout), 0 },
2921 #ifndef CONFIG_NO_CONFIG_WRITE
2922 { INT(update_config), 0 },
2923 #endif /* CONFIG_NO_CONFIG_WRITE */
2924 { FUNC_NO_VAR(load_dynamic_eap), 0 },
2926 { FUNC(uuid), CFG_CHANGED_UUID },
2927 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
2928 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
2929 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
2930 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
2931 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
2932 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
2933 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
2934 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
2935 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
2936 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
2937 #endif /* CONFIG_WPS */
2939 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
2940 { INT(p2p_listen_reg_class), 0 },
2941 { INT(p2p_listen_channel), 0 },
2942 { INT(p2p_oper_reg_class), 0 },
2943 { INT(p2p_oper_channel), 0 },
2944 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
2945 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
2946 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
2947 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
2948 { INT(p2p_group_idle), 0 },
2949 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
2950 #endif /* CONFIG_P2P */
2952 { STR_RANGE(prioritize, 0, 32), CFG_CHANGED_IFACE_PRIORITY },
2954 { FUNC(country), CFG_CHANGED_COUNTRY },
2955 { INT(bss_max_count), 0 },
2956 { INT(bss_expiration_age), 0 },
2957 { INT(bss_expiration_scan_count), 0 },
2958 { INT_RANGE(filter_ssids, 0, 1), 0 },
2959 { INT(max_num_sta), 0 },
2960 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
2962 { INT_RANGE(hs20, 0, 1), 0 },
2963 #endif /* CONFIG_HS20 */
2964 { INT_RANGE(interworking, 0, 1), 0 },
2965 { FUNC(hessid), 0 },
2966 { INT_RANGE(access_network_type, 0, 15), 0 },
2967 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
2968 { STR(autoscan), 0 },
2969 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff), 0 },
2970 { BIN(wps_nfc_dh_pubkey), 0 },
2971 { BIN(wps_nfc_dh_privkey), 0 },
2972 { BIN(wps_nfc_dev_pw), 0 }
2983 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
2986 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
2991 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
2992 const struct global_parse_data *field = &global_fields[i];
2993 size_t flen = os_strlen(field->name);
2994 if (os_strncmp(pos, field->name, flen) != 0 ||
2998 if (field->parser(field, config, line, pos + flen + 1)) {
2999 wpa_printf(MSG_ERROR, "Line %d: failed to "
3000 "parse '%s'.", line, pos);
3003 config->changed_parameters |= field->changed_flag;
3006 if (i == NUM_GLOBAL_FIELDS) {
3009 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",