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);
1913 * wpa_config_foreach_network - Iterate over each configured network
1914 * @config: Configuration data from wpa_config_read()
1915 * @func: Callback function to process each network
1916 * @arg: Opaque argument to pass to callback function
1918 * Iterate over the set of configured networks calling the specified
1919 * function for each item. We guard against callbacks removing the
1922 void wpa_config_foreach_network(struct wpa_config *config,
1923 void (*func)(void *, struct wpa_ssid *),
1926 struct wpa_ssid *ssid, *next;
1928 ssid = config->ssid;
1938 * wpa_config_get_network - Get configured network based on id
1939 * @config: Configuration data from wpa_config_read()
1940 * @id: Unique network id to search for
1941 * Returns: Network configuration or %NULL if not found
1943 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
1945 struct wpa_ssid *ssid;
1947 ssid = config->ssid;
1959 * wpa_config_add_network - Add a new network with empty configuration
1960 * @config: Configuration data from wpa_config_read()
1961 * Returns: The new network configuration or %NULL if operation failed
1963 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
1966 struct wpa_ssid *ssid, *last = NULL;
1969 ssid = config->ssid;
1978 ssid = os_zalloc(sizeof(*ssid));
1985 config->ssid = ssid;
1987 wpa_config_update_prio_list(config);
1994 * wpa_config_remove_network - Remove a configured network based on id
1995 * @config: Configuration data from wpa_config_read()
1996 * @id: Unique network id to search for
1997 * Returns: 0 on success, or -1 if the network was not found
1999 int wpa_config_remove_network(struct wpa_config *config, int id)
2001 struct wpa_ssid *ssid, *prev = NULL;
2003 ssid = config->ssid;
2015 prev->next = ssid->next;
2017 config->ssid = ssid->next;
2019 wpa_config_update_prio_list(config);
2020 wpa_config_free_ssid(ssid);
2026 * wpa_config_set_network_defaults - Set network default values
2027 * @ssid: Pointer to network configuration data
2029 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2031 ssid->proto = DEFAULT_PROTO;
2032 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2033 ssid->group_cipher = DEFAULT_GROUP;
2034 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2035 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2036 #ifdef IEEE8021X_EAPOL
2037 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2038 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2039 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2040 #endif /* IEEE8021X_EAPOL */
2041 #ifdef CONFIG_HT_OVERRIDES
2042 ssid->disable_ht = DEFAULT_DISABLE_HT;
2043 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2044 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2045 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2046 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2047 #endif /* CONFIG_HT_OVERRIDES */
2052 * wpa_config_set - Set a variable in network configuration
2053 * @ssid: Pointer to network configuration data
2054 * @var: Variable name, e.g., "ssid"
2055 * @value: Variable value
2056 * @line: Line number in configuration file or 0 if not used
2057 * Returns: 0 on success, -1 on failure
2059 * This function can be used to set network configuration variables based on
2060 * both the configuration file and management interface input. The value
2061 * parameter must be in the same format as the text-based configuration file is
2062 * using. For example, strings are using double quotation marks.
2064 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2070 if (ssid == NULL || var == NULL || value == NULL)
2073 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2074 const struct parse_data *field = &ssid_fields[i];
2075 if (os_strcmp(var, field->name) != 0)
2078 if (field->parser(field, ssid, line, value)) {
2080 wpa_printf(MSG_ERROR, "Line %d: failed to "
2081 "parse %s '%s'.", line, var, value);
2087 if (i == NUM_SSID_FIELDS) {
2089 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2090 "'%s'.", line, var);
2099 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2106 len = os_strlen(value);
2107 buf = os_malloc(len + 3);
2111 os_memcpy(buf + 1, value, len);
2113 buf[len + 2] = '\0';
2114 ret = wpa_config_set(ssid, var, buf, 0);
2121 * wpa_config_get_all - Get all options from network configuration
2122 * @ssid: Pointer to network configuration data
2123 * @get_keys: Determines if keys/passwords will be included in returned list
2124 * (if they may be exported)
2125 * Returns: %NULL terminated list of all set keys and their values in the form
2126 * of [key1, val1, key2, val2, ... , NULL]
2128 * This function can be used to get list of all configured network properties.
2129 * The caller is responsible for freeing the returned list and all its
2132 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2134 const struct parse_data *field;
2140 get_keys = get_keys && ssid->export_keys;
2142 props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
2147 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2148 field = &ssid_fields[i];
2149 if (field->key_data && !get_keys)
2151 value = field->writer(field, ssid);
2154 if (os_strlen(value) == 0) {
2159 key = os_strdup(field->name);
2165 props[fields_num * 2] = key;
2166 props[fields_num * 2 + 1] = value;
2182 #ifndef NO_CONFIG_WRITE
2184 * wpa_config_get - Get a variable in network configuration
2185 * @ssid: Pointer to network configuration data
2186 * @var: Variable name, e.g., "ssid"
2187 * Returns: Value of the variable or %NULL on failure
2189 * This function can be used to get network configuration variables. The
2190 * returned value is a copy of the configuration variable in text format, i.e,.
2191 * the same format that the text-based configuration file and wpa_config_set()
2192 * are using for the value. The caller is responsible for freeing the returned
2195 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2199 if (ssid == NULL || var == NULL)
2202 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2203 const struct parse_data *field = &ssid_fields[i];
2204 if (os_strcmp(var, field->name) == 0)
2205 return field->writer(field, ssid);
2213 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2214 * @ssid: Pointer to network configuration data
2215 * @var: Variable name, e.g., "ssid"
2216 * Returns: Value of the variable or %NULL on failure
2218 * This function can be used to get network configuration variable like
2219 * wpa_config_get(). The only difference is that this functions does not expose
2220 * key/password material from the configuration. In case a key/password field
2221 * is requested, the returned value is an empty string or %NULL if the variable
2222 * is not set or "*" if the variable is set (regardless of its value). The
2223 * returned value is a copy of the configuration variable in text format, i.e,.
2224 * the same format that the text-based configuration file and wpa_config_set()
2225 * are using for the value. The caller is responsible for freeing the returned
2228 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2232 if (ssid == NULL || var == NULL)
2235 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2236 const struct parse_data *field = &ssid_fields[i];
2237 if (os_strcmp(var, field->name) == 0) {
2238 char *res = field->writer(field, ssid);
2239 if (field->key_data) {
2240 if (res && res[0]) {
2241 wpa_printf(MSG_DEBUG, "Do not allow "
2242 "key_data field to be "
2245 return os_strdup("*");
2257 #endif /* NO_CONFIG_WRITE */
2261 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2262 * @ssid: Pointer to network configuration data
2264 * This function must be called to update WPA PSK when either SSID or the
2265 * passphrase has changed for the network configuration.
2267 void wpa_config_update_psk(struct wpa_ssid *ssid)
2269 #ifndef CONFIG_NO_PBKDF2
2270 pbkdf2_sha1(ssid->passphrase,
2271 (char *) ssid->ssid, ssid->ssid_len, 4096,
2272 ssid->psk, PMK_LEN);
2273 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2274 ssid->psk, PMK_LEN);
2276 #endif /* CONFIG_NO_PBKDF2 */
2280 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2281 const char *value, int line)
2286 if (os_strcmp(var, "priority") == 0) {
2287 cred->priority = atoi(value);
2291 if (os_strcmp(var, "pcsc") == 0) {
2292 cred->pcsc = atoi(value);
2296 val = wpa_config_parse_string(value, &len);
2298 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2299 "value '%s'.", line, var, value);
2303 if (os_strcmp(var, "realm") == 0) {
2304 os_free(cred->realm);
2309 if (os_strcmp(var, "username") == 0) {
2310 os_free(cred->username);
2311 cred->username = val;
2315 if (os_strcmp(var, "password") == 0) {
2316 os_free(cred->password);
2317 cred->password = val;
2321 if (os_strcmp(var, "ca_cert") == 0) {
2322 os_free(cred->ca_cert);
2323 cred->ca_cert = val;
2327 if (os_strcmp(var, "client_cert") == 0) {
2328 os_free(cred->client_cert);
2329 cred->client_cert = val;
2333 if (os_strcmp(var, "private_key") == 0) {
2334 os_free(cred->private_key);
2335 cred->private_key = val;
2339 if (os_strcmp(var, "private_key_passwd") == 0) {
2340 os_free(cred->private_key_passwd);
2341 cred->private_key_passwd = val;
2345 if (os_strcmp(var, "imsi") == 0) {
2346 os_free(cred->imsi);
2351 if (os_strcmp(var, "milenage") == 0) {
2352 os_free(cred->milenage);
2353 cred->milenage = val;
2357 if (os_strcmp(var, "domain") == 0) {
2358 os_free(cred->domain);
2364 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2374 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
2376 struct wpa_cred *cred;
2378 cred = config->cred;
2389 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
2392 struct wpa_cred *cred, *last = NULL;
2395 cred = config->cred;
2404 cred = os_zalloc(sizeof(*cred));
2411 config->cred = cred;
2417 int wpa_config_remove_cred(struct wpa_config *config, int id)
2419 struct wpa_cred *cred, *prev = NULL;
2421 cred = config->cred;
2433 prev->next = cred->next;
2435 config->cred = cred->next;
2437 wpa_config_free_cred(cred);
2442 #ifndef CONFIG_NO_CONFIG_BLOBS
2444 * wpa_config_get_blob - Get a named configuration blob
2445 * @config: Configuration data from wpa_config_read()
2446 * @name: Name of the blob
2447 * Returns: Pointer to blob data or %NULL if not found
2449 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
2452 struct wpa_config_blob *blob = config->blobs;
2455 if (os_strcmp(blob->name, name) == 0)
2464 * wpa_config_set_blob - Set or add a named configuration blob
2465 * @config: Configuration data from wpa_config_read()
2466 * @blob: New value for the blob
2468 * Adds a new configuration blob or replaces the current value of an existing
2471 void wpa_config_set_blob(struct wpa_config *config,
2472 struct wpa_config_blob *blob)
2474 wpa_config_remove_blob(config, blob->name);
2475 blob->next = config->blobs;
2476 config->blobs = blob;
2481 * wpa_config_free_blob - Free blob data
2482 * @blob: Pointer to blob to be freed
2484 void wpa_config_free_blob(struct wpa_config_blob *blob)
2487 os_free(blob->name);
2488 os_free(blob->data);
2495 * wpa_config_remove_blob - Remove a named configuration blob
2496 * @config: Configuration data from wpa_config_read()
2497 * @name: Name of the blob to remove
2498 * Returns: 0 if blob was removed or -1 if blob was not found
2500 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
2502 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
2505 if (os_strcmp(pos->name, name) == 0) {
2507 prev->next = pos->next;
2509 config->blobs = pos->next;
2510 wpa_config_free_blob(pos);
2519 #endif /* CONFIG_NO_CONFIG_BLOBS */
2523 * wpa_config_alloc_empty - Allocate an empty configuration
2524 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
2526 * @driver_param: Driver parameters
2527 * Returns: Pointer to allocated configuration data or %NULL on failure
2529 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
2530 const char *driver_param)
2532 struct wpa_config *config;
2534 config = os_zalloc(sizeof(*config));
2537 config->eapol_version = DEFAULT_EAPOL_VERSION;
2538 config->ap_scan = DEFAULT_AP_SCAN;
2539 config->fast_reauth = DEFAULT_FAST_REAUTH;
2540 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
2541 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
2542 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
2543 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
2544 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
2545 config->max_num_sta = DEFAULT_MAX_NUM_STA;
2546 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
2549 config->ctrl_interface = os_strdup(ctrl_interface);
2551 config->driver_param = os_strdup(driver_param);
2557 #ifndef CONFIG_NO_STDOUT_DEBUG
2559 * wpa_config_debug_dump_networks - Debug dump of configured networks
2560 * @config: Configuration data from wpa_config_read()
2562 void wpa_config_debug_dump_networks(struct wpa_config *config)
2565 struct wpa_ssid *ssid;
2567 for (prio = 0; prio < config->num_prio; prio++) {
2568 ssid = config->pssid[prio];
2569 wpa_printf(MSG_DEBUG, "Priority group %d",
2572 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
2574 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2579 #endif /* CONFIG_NO_STDOUT_DEBUG */
2582 struct global_parse_data {
2584 int (*parser)(const struct global_parse_data *data,
2585 struct wpa_config *config, int line, const char *value);
2586 void *param1, *param2, *param3;
2587 unsigned int changed_flag;
2591 static int wpa_global_config_parse_int(const struct global_parse_data *data,
2592 struct wpa_config *config, int line,
2596 dst = (int *) (((u8 *) config) + (long) data->param1);
2598 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
2600 if (data->param2 && *dst < (long) data->param2) {
2601 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
2602 "min_value=%ld)", line, data->name, *dst,
2603 (long) data->param2);
2604 *dst = (long) data->param2;
2608 if (data->param3 && *dst > (long) data->param3) {
2609 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
2610 "max_value=%ld)", line, data->name, *dst,
2611 (long) data->param3);
2612 *dst = (long) data->param3;
2620 static int wpa_global_config_parse_str(const struct global_parse_data *data,
2621 struct wpa_config *config, int line,
2627 len = os_strlen(pos);
2628 if (data->param2 && len < (size_t) data->param2) {
2629 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
2630 "min_len=%ld)", line, data->name,
2631 (unsigned long) len, (long) data->param2);
2635 if (data->param3 && len > (size_t) data->param3) {
2636 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
2637 "max_len=%ld)", line, data->name,
2638 (unsigned long) len, (long) data->param3);
2642 tmp = os_strdup(pos);
2646 dst = (char **) (((u8 *) config) + (long) data->param1);
2649 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
2655 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
2656 struct wpa_config *config, int line,
2660 struct wpabuf **dst, *tmp;
2662 len = os_strlen(pos);
2666 tmp = wpabuf_alloc(len / 2);
2670 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
2675 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
2678 wpa_printf(MSG_DEBUG, "%s", data->name);
2684 static int wpa_config_process_country(const struct global_parse_data *data,
2685 struct wpa_config *config, int line,
2688 if (!pos[0] || !pos[1]) {
2689 wpa_printf(MSG_DEBUG, "Invalid country set");
2692 config->country[0] = pos[0];
2693 config->country[1] = pos[1];
2694 wpa_printf(MSG_DEBUG, "country='%c%c'",
2695 config->country[0], config->country[1]);
2700 static int wpa_config_process_load_dynamic_eap(
2701 const struct global_parse_data *data, struct wpa_config *config,
2702 int line, const char *so)
2705 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
2706 ret = eap_peer_method_load(so);
2708 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
2711 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
2712 "method '%s'.", line, so);
2722 static int wpa_config_process_uuid(const struct global_parse_data *data,
2723 struct wpa_config *config, int line,
2727 if (uuid_str2bin(pos, config->uuid)) {
2728 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2731 uuid_bin2str(config->uuid, buf, sizeof(buf));
2732 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
2737 static int wpa_config_process_device_type(
2738 const struct global_parse_data *data,
2739 struct wpa_config *config, int line, const char *pos)
2741 return wps_dev_type_str2bin(pos, config->device_type);
2745 static int wpa_config_process_os_version(const struct global_parse_data *data,
2746 struct wpa_config *config, int line,
2749 if (hexstr2bin(pos, config->os_version, 4)) {
2750 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
2753 wpa_printf(MSG_DEBUG, "os_version=%08x",
2754 WPA_GET_BE32(config->os_version));
2759 static int wpa_config_process_wps_vendor_ext_m1(
2760 const struct global_parse_data *data,
2761 struct wpa_config *config, int line, const char *pos)
2764 int len = os_strlen(pos) / 2;
2768 wpa_printf(MSG_ERROR, "Line %d: "
2769 "invalid wps_vendor_ext_m1", line);
2773 tmp = wpabuf_alloc(len);
2775 p = wpabuf_put(tmp, len);
2777 if (hexstr2bin(pos, p, len)) {
2778 wpa_printf(MSG_ERROR, "Line %d: "
2779 "invalid wps_vendor_ext_m1", line);
2784 wpabuf_free(config->wps_vendor_ext_m1);
2785 config->wps_vendor_ext_m1 = tmp;
2787 wpa_printf(MSG_ERROR, "Can not allocate "
2788 "memory for wps_vendor_ext_m1");
2795 #endif /* CONFIG_WPS */
2798 static int wpa_config_process_sec_device_type(
2799 const struct global_parse_data *data,
2800 struct wpa_config *config, int line, const char *pos)
2804 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
2805 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
2810 idx = config->num_sec_device_types;
2812 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
2815 config->num_sec_device_types++;
2820 static int wpa_config_process_p2p_pref_chan(
2821 const struct global_parse_data *data,
2822 struct wpa_config *config, int line, const char *pos)
2824 struct p2p_channel *pref = NULL, *n;
2825 unsigned int num = 0;
2829 /* format: class:chan,class:chan,... */
2832 op_class = atoi(pos);
2833 pos2 = os_strchr(pos, ':');
2839 n = os_realloc(pref, (num + 1) * sizeof(struct p2p_channel));
2843 pref[num].op_class = op_class;
2844 pref[num].chan = chan;
2847 pos = os_strchr(pos2, ',');
2853 os_free(config->p2p_pref_chan);
2854 config->p2p_pref_chan = pref;
2855 config->num_p2p_pref_chan = num;
2856 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
2857 (u8 *) config->p2p_pref_chan,
2858 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
2864 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
2867 #endif /* CONFIG_P2P */
2870 static int wpa_config_process_hessid(
2871 const struct global_parse_data *data,
2872 struct wpa_config *config, int line, const char *pos)
2874 if (hwaddr_aton2(pos, config->hessid) < 0) {
2875 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
2887 /* OFFSET: Get offset of a variable within the wpa_config structure */
2888 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
2890 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
2891 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
2892 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
2893 #define INT(f) _INT(f), NULL, NULL
2894 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
2895 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
2896 #define STR(f) _STR(f), NULL, NULL
2897 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
2898 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
2900 static const struct global_parse_data global_fields[] = {
2901 #ifdef CONFIG_CTRL_IFACE
2902 { STR(ctrl_interface), 0 },
2903 { STR(ctrl_interface_group), 0 } /* deprecated */,
2904 #endif /* CONFIG_CTRL_IFACE */
2905 { INT_RANGE(eapol_version, 1, 2), 0 },
2906 { INT(ap_scan), 0 },
2907 { INT(disable_scan_offload), 0 },
2908 { INT(fast_reauth), 0 },
2909 { STR(opensc_engine_path), 0 },
2910 { STR(pkcs11_engine_path), 0 },
2911 { STR(pkcs11_module_path), 0 },
2912 { STR(pcsc_reader), 0 },
2913 { STR(pcsc_pin), 0 },
2914 { STR(driver_param), 0 },
2915 { INT(dot11RSNAConfigPMKLifetime), 0 },
2916 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
2917 { INT(dot11RSNAConfigSATimeout), 0 },
2918 #ifndef CONFIG_NO_CONFIG_WRITE
2919 { INT(update_config), 0 },
2920 #endif /* CONFIG_NO_CONFIG_WRITE */
2921 { FUNC_NO_VAR(load_dynamic_eap), 0 },
2923 { FUNC(uuid), CFG_CHANGED_UUID },
2924 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
2925 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
2926 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
2927 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
2928 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
2929 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
2930 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
2931 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
2932 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
2933 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
2934 #endif /* CONFIG_WPS */
2936 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
2937 { INT(p2p_listen_reg_class), 0 },
2938 { INT(p2p_listen_channel), 0 },
2939 { INT(p2p_oper_reg_class), 0 },
2940 { INT(p2p_oper_channel), 0 },
2941 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
2942 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
2943 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
2944 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
2945 { INT(p2p_group_idle), 0 },
2946 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
2947 #endif /* CONFIG_P2P */
2948 { FUNC(country), CFG_CHANGED_COUNTRY },
2949 { INT(bss_max_count), 0 },
2950 { INT(bss_expiration_age), 0 },
2951 { INT(bss_expiration_scan_count), 0 },
2952 { INT_RANGE(filter_ssids, 0, 1), 0 },
2953 { INT(max_num_sta), 0 },
2954 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
2956 { INT_RANGE(hs20, 0, 1), 0 },
2957 #endif /* CONFIG_HS20 */
2958 { INT_RANGE(interworking, 0, 1), 0 },
2959 { FUNC(hessid), 0 },
2960 { INT_RANGE(access_network_type, 0, 15), 0 },
2961 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
2962 { STR(autoscan), 0 },
2963 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff), 0 },
2964 { BIN(wps_nfc_dh_pubkey), 0 },
2965 { BIN(wps_nfc_dh_privkey), 0 },
2966 { BIN(wps_nfc_dev_pw), 0 }
2977 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
2980 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
2985 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
2986 const struct global_parse_data *field = &global_fields[i];
2987 size_t flen = os_strlen(field->name);
2988 if (os_strncmp(pos, field->name, flen) != 0 ||
2992 if (field->parser(field, config, line, pos + flen + 1)) {
2993 wpa_printf(MSG_ERROR, "Line %d: failed to "
2994 "parse '%s'.", line, pos);
2997 config->changed_parameters |= field->changed_flag;
3000 if (i == NUM_GLOBAL_FIELDS) {
3003 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",