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);
222 #endif /* NO_CONFIG_WRITE */
225 static int wpa_config_parse_int(const struct parse_data *data,
226 struct wpa_ssid *ssid,
227 int line, const char *value)
231 dst = (int *) (((u8 *) ssid) + (long) data->param1);
233 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
235 if (data->param3 && *dst < (long) data->param3) {
236 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
237 "min_value=%ld)", line, data->name, *dst,
238 (long) data->param3);
239 *dst = (long) data->param3;
243 if (data->param4 && *dst > (long) data->param4) {
244 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
245 "max_value=%ld)", line, data->name, *dst,
246 (long) data->param4);
247 *dst = (long) data->param4;
255 #ifndef NO_CONFIG_WRITE
256 static char * wpa_config_write_int(const struct parse_data *data,
257 struct wpa_ssid *ssid)
262 src = (int *) (((u8 *) ssid) + (long) data->param1);
264 value = os_malloc(20);
267 res = os_snprintf(value, 20, "%d", *src);
268 if (res < 0 || res >= 20) {
272 value[20 - 1] = '\0';
275 #endif /* NO_CONFIG_WRITE */
278 static int wpa_config_parse_bssid(const struct parse_data *data,
279 struct wpa_ssid *ssid, int line,
282 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
283 os_strcmp(value, "any") == 0) {
285 wpa_printf(MSG_MSGDUMP, "BSSID any");
288 if (hwaddr_aton(value, ssid->bssid)) {
289 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
294 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
299 #ifndef NO_CONFIG_WRITE
300 static char * wpa_config_write_bssid(const struct parse_data *data,
301 struct wpa_ssid *ssid)
306 if (!ssid->bssid_set)
309 value = os_malloc(20);
312 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
313 if (res < 0 || res >= 20) {
317 value[20 - 1] = '\0';
320 #endif /* NO_CONFIG_WRITE */
323 static int wpa_config_parse_psk(const struct parse_data *data,
324 struct wpa_ssid *ssid, int line,
327 #ifdef CONFIG_EXT_PASSWORD
328 if (os_strncmp(value, "ext:", 4) == 0) {
329 os_free(ssid->passphrase);
330 ssid->passphrase = NULL;
332 os_free(ssid->ext_psk);
333 ssid->ext_psk = os_strdup(value + 4);
334 if (ssid->ext_psk == NULL)
336 wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
340 #endif /* CONFIG_EXT_PASSWORD */
343 #ifndef CONFIG_NO_PBKDF2
348 pos = os_strrchr(value, '"');
352 len = os_strlen(value);
353 if (len < 8 || len > 63) {
354 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
355 "length %lu (expected: 8..63) '%s'.",
356 line, (unsigned long) len, value);
359 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
361 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
362 os_memcmp(ssid->passphrase, value, len) == 0)
365 os_free(ssid->passphrase);
366 ssid->passphrase = os_malloc(len + 1);
367 if (ssid->passphrase == NULL)
369 os_memcpy(ssid->passphrase, value, len);
370 ssid->passphrase[len] = '\0';
372 #else /* CONFIG_NO_PBKDF2 */
373 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
376 #endif /* CONFIG_NO_PBKDF2 */
379 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
380 value[PMK_LEN * 2] != '\0') {
381 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
386 os_free(ssid->passphrase);
387 ssid->passphrase = NULL;
390 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
395 #ifndef NO_CONFIG_WRITE
396 static char * wpa_config_write_psk(const struct parse_data *data,
397 struct wpa_ssid *ssid)
399 #ifdef CONFIG_EXT_PASSWORD
401 size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
402 char *buf = os_malloc(len);
405 os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
408 #endif /* CONFIG_EXT_PASSWORD */
410 if (ssid->passphrase)
411 return wpa_config_write_string_ascii(
412 (const u8 *) ssid->passphrase,
413 os_strlen(ssid->passphrase));
416 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
420 #endif /* NO_CONFIG_WRITE */
423 static int wpa_config_parse_proto(const struct parse_data *data,
424 struct wpa_ssid *ssid, int line,
427 int val = 0, last, errors = 0;
428 char *start, *end, *buf;
430 buf = os_strdup(value);
435 while (*start != '\0') {
436 while (*start == ' ' || *start == '\t')
441 while (*end != ' ' && *end != '\t' && *end != '\0')
445 if (os_strcmp(start, "WPA") == 0)
446 val |= WPA_PROTO_WPA;
447 else if (os_strcmp(start, "RSN") == 0 ||
448 os_strcmp(start, "WPA2") == 0)
449 val |= WPA_PROTO_RSN;
451 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
463 wpa_printf(MSG_ERROR,
464 "Line %d: no proto values configured.", line);
468 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
470 return errors ? -1 : 0;
474 #ifndef NO_CONFIG_WRITE
475 static char * wpa_config_write_proto(const struct parse_data *data,
476 struct wpa_ssid *ssid)
479 char *buf, *pos, *end;
481 pos = buf = os_zalloc(10);
486 if (ssid->proto & WPA_PROTO_WPA) {
487 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
488 if (ret < 0 || ret >= end - pos)
494 if (ssid->proto & WPA_PROTO_RSN) {
495 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
496 if (ret < 0 || ret >= end - pos)
504 #endif /* NO_CONFIG_WRITE */
507 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
508 struct wpa_ssid *ssid, int line,
511 int val = 0, last, errors = 0;
512 char *start, *end, *buf;
514 buf = os_strdup(value);
519 while (*start != '\0') {
520 while (*start == ' ' || *start == '\t')
525 while (*end != ' ' && *end != '\t' && *end != '\0')
529 if (os_strcmp(start, "WPA-PSK") == 0)
530 val |= WPA_KEY_MGMT_PSK;
531 else if (os_strcmp(start, "WPA-EAP") == 0)
532 val |= WPA_KEY_MGMT_IEEE8021X;
533 else if (os_strcmp(start, "IEEE8021X") == 0)
534 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
535 else if (os_strcmp(start, "NONE") == 0)
536 val |= WPA_KEY_MGMT_NONE;
537 else if (os_strcmp(start, "WPA-NONE") == 0)
538 val |= WPA_KEY_MGMT_WPA_NONE;
539 #ifdef CONFIG_IEEE80211R
540 else if (os_strcmp(start, "FT-PSK") == 0)
541 val |= WPA_KEY_MGMT_FT_PSK;
542 else if (os_strcmp(start, "FT-EAP") == 0)
543 val |= WPA_KEY_MGMT_FT_IEEE8021X;
544 #endif /* CONFIG_IEEE80211R */
545 #ifdef CONFIG_IEEE80211W
546 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
547 val |= WPA_KEY_MGMT_PSK_SHA256;
548 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
549 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
550 #endif /* CONFIG_IEEE80211W */
552 else if (os_strcmp(start, "WPS") == 0)
553 val |= WPA_KEY_MGMT_WPS;
554 #endif /* CONFIG_WPS */
556 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
568 wpa_printf(MSG_ERROR,
569 "Line %d: no key_mgmt values configured.", line);
573 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
574 ssid->key_mgmt = val;
575 return errors ? -1 : 0;
579 #ifndef NO_CONFIG_WRITE
580 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
581 struct wpa_ssid *ssid)
583 char *buf, *pos, *end;
586 pos = buf = os_zalloc(50);
591 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
592 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
593 pos == buf ? "" : " ");
594 if (ret < 0 || ret >= end - pos) {
601 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
602 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
603 pos == buf ? "" : " ");
604 if (ret < 0 || ret >= end - pos) {
611 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
612 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
613 pos == buf ? "" : " ");
614 if (ret < 0 || ret >= end - pos) {
621 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
622 ret = os_snprintf(pos, end - pos, "%sNONE",
623 pos == buf ? "" : " ");
624 if (ret < 0 || ret >= end - pos) {
631 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
632 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
633 pos == buf ? "" : " ");
634 if (ret < 0 || ret >= end - pos) {
641 #ifdef CONFIG_IEEE80211R
642 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
643 pos += os_snprintf(pos, end - pos, "%sFT-PSK",
644 pos == buf ? "" : " ");
646 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
647 pos += os_snprintf(pos, end - pos, "%sFT-EAP",
648 pos == buf ? "" : " ");
649 #endif /* CONFIG_IEEE80211R */
651 #ifdef CONFIG_IEEE80211W
652 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
653 pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
654 pos == buf ? "" : " ");
656 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
657 pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
658 pos == buf ? "" : " ");
659 #endif /* CONFIG_IEEE80211W */
662 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
663 pos += os_snprintf(pos, end - pos, "%sWPS",
664 pos == buf ? "" : " ");
665 #endif /* CONFIG_WPS */
669 #endif /* NO_CONFIG_WRITE */
672 static int wpa_config_parse_cipher(int line, const char *value)
675 char *start, *end, *buf;
677 buf = os_strdup(value);
682 while (*start != '\0') {
683 while (*start == ' ' || *start == '\t')
688 while (*end != ' ' && *end != '\t' && *end != '\0')
692 if (os_strcmp(start, "CCMP") == 0)
693 val |= WPA_CIPHER_CCMP;
694 else if (os_strcmp(start, "TKIP") == 0)
695 val |= WPA_CIPHER_TKIP;
696 else if (os_strcmp(start, "WEP104") == 0)
697 val |= WPA_CIPHER_WEP104;
698 else if (os_strcmp(start, "WEP40") == 0)
699 val |= WPA_CIPHER_WEP40;
700 else if (os_strcmp(start, "NONE") == 0)
701 val |= WPA_CIPHER_NONE;
703 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
716 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
724 #ifndef NO_CONFIG_WRITE
725 static char * wpa_config_write_cipher(int cipher)
727 char *buf, *pos, *end;
730 pos = buf = os_zalloc(50);
735 if (cipher & WPA_CIPHER_CCMP) {
736 ret = os_snprintf(pos, end - pos, "%sCCMP",
737 pos == buf ? "" : " ");
738 if (ret < 0 || ret >= end - pos) {
745 if (cipher & WPA_CIPHER_TKIP) {
746 ret = os_snprintf(pos, end - pos, "%sTKIP",
747 pos == buf ? "" : " ");
748 if (ret < 0 || ret >= end - pos) {
755 if (cipher & WPA_CIPHER_WEP104) {
756 ret = os_snprintf(pos, end - pos, "%sWEP104",
757 pos == buf ? "" : " ");
758 if (ret < 0 || ret >= end - pos) {
765 if (cipher & WPA_CIPHER_WEP40) {
766 ret = os_snprintf(pos, end - pos, "%sWEP40",
767 pos == buf ? "" : " ");
768 if (ret < 0 || ret >= end - pos) {
775 if (cipher & WPA_CIPHER_NONE) {
776 ret = os_snprintf(pos, end - pos, "%sNONE",
777 pos == buf ? "" : " ");
778 if (ret < 0 || ret >= end - pos) {
787 #endif /* NO_CONFIG_WRITE */
790 static int wpa_config_parse_pairwise(const struct parse_data *data,
791 struct wpa_ssid *ssid, int line,
795 val = wpa_config_parse_cipher(line, value);
798 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {
799 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
800 "(0x%x).", line, val);
804 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
805 ssid->pairwise_cipher = val;
810 #ifndef NO_CONFIG_WRITE
811 static char * wpa_config_write_pairwise(const struct parse_data *data,
812 struct wpa_ssid *ssid)
814 return wpa_config_write_cipher(ssid->pairwise_cipher);
816 #endif /* NO_CONFIG_WRITE */
819 static int wpa_config_parse_group(const struct parse_data *data,
820 struct wpa_ssid *ssid, int line,
824 val = wpa_config_parse_cipher(line, value);
827 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |
829 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
830 "(0x%x).", line, val);
834 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
835 ssid->group_cipher = val;
840 #ifndef NO_CONFIG_WRITE
841 static char * wpa_config_write_group(const struct parse_data *data,
842 struct wpa_ssid *ssid)
844 return wpa_config_write_cipher(ssid->group_cipher);
846 #endif /* NO_CONFIG_WRITE */
849 static int wpa_config_parse_auth_alg(const struct parse_data *data,
850 struct wpa_ssid *ssid, int line,
853 int val = 0, last, errors = 0;
854 char *start, *end, *buf;
856 buf = os_strdup(value);
861 while (*start != '\0') {
862 while (*start == ' ' || *start == '\t')
867 while (*end != ' ' && *end != '\t' && *end != '\0')
871 if (os_strcmp(start, "OPEN") == 0)
872 val |= WPA_AUTH_ALG_OPEN;
873 else if (os_strcmp(start, "SHARED") == 0)
874 val |= WPA_AUTH_ALG_SHARED;
875 else if (os_strcmp(start, "LEAP") == 0)
876 val |= WPA_AUTH_ALG_LEAP;
878 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
890 wpa_printf(MSG_ERROR,
891 "Line %d: no auth_alg values configured.", line);
895 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
896 ssid->auth_alg = val;
897 return errors ? -1 : 0;
901 #ifndef NO_CONFIG_WRITE
902 static char * wpa_config_write_auth_alg(const struct parse_data *data,
903 struct wpa_ssid *ssid)
905 char *buf, *pos, *end;
908 pos = buf = os_zalloc(30);
913 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
914 ret = os_snprintf(pos, end - pos, "%sOPEN",
915 pos == buf ? "" : " ");
916 if (ret < 0 || ret >= end - pos) {
923 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
924 ret = os_snprintf(pos, end - pos, "%sSHARED",
925 pos == buf ? "" : " ");
926 if (ret < 0 || ret >= end - pos) {
933 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
934 ret = os_snprintf(pos, end - pos, "%sLEAP",
935 pos == buf ? "" : " ");
936 if (ret < 0 || ret >= end - pos) {
945 #endif /* NO_CONFIG_WRITE */
948 static int * wpa_config_parse_freqs(const struct parse_data *data,
949 struct wpa_ssid *ssid, int line,
958 freqs = os_zalloc((len + 1) * sizeof(int));
969 n = os_realloc(freqs, (len * 2 + 1) * sizeof(int));
974 for (i = len; i <= len * 2; i++)
980 freqs[used] = atoi(pos);
981 if (freqs[used] == 0)
984 pos = os_strchr(pos + 1, ' ');
991 static int wpa_config_parse_scan_freq(const struct parse_data *data,
992 struct wpa_ssid *ssid, int line,
997 freqs = wpa_config_parse_freqs(data, ssid, line, value);
1000 os_free(ssid->scan_freq);
1001 ssid->scan_freq = freqs;
1007 static int wpa_config_parse_freq_list(const struct parse_data *data,
1008 struct wpa_ssid *ssid, int line,
1013 freqs = wpa_config_parse_freqs(data, ssid, line, value);
1016 os_free(ssid->freq_list);
1017 ssid->freq_list = freqs;
1023 #ifndef NO_CONFIG_WRITE
1024 static char * wpa_config_write_freqs(const struct parse_data *data,
1027 char *buf, *pos, *end;
1035 for (i = 0; freqs[i]; i++)
1038 pos = buf = os_zalloc(10 * count + 1);
1041 end = buf + 10 * count + 1;
1043 for (i = 0; freqs[i]; i++) {
1044 ret = os_snprintf(pos, end - pos, "%s%u",
1045 i == 0 ? "" : " ", freqs[i]);
1046 if (ret < 0 || ret >= end - pos) {
1057 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1058 struct wpa_ssid *ssid)
1060 return wpa_config_write_freqs(data, ssid->scan_freq);
1064 static char * wpa_config_write_freq_list(const struct parse_data *data,
1065 struct wpa_ssid *ssid)
1067 return wpa_config_write_freqs(data, ssid->freq_list);
1069 #endif /* NO_CONFIG_WRITE */
1072 #ifdef IEEE8021X_EAPOL
1073 static int wpa_config_parse_eap(const struct parse_data *data,
1074 struct wpa_ssid *ssid, int line,
1077 int last, errors = 0;
1078 char *start, *end, *buf;
1079 struct eap_method_type *methods = NULL, *tmp;
1080 size_t num_methods = 0;
1082 buf = os_strdup(value);
1087 while (*start != '\0') {
1088 while (*start == ' ' || *start == '\t')
1093 while (*end != ' ' && *end != '\t' && *end != '\0')
1095 last = *end == '\0';
1098 methods = os_realloc(methods,
1099 (num_methods + 1) * sizeof(*methods));
1100 if (methods == NULL) {
1105 methods[num_methods].method = eap_peer_get_type(
1106 start, &methods[num_methods].vendor);
1107 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1108 methods[num_methods].method == EAP_TYPE_NONE) {
1109 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1110 "'%s'", line, start);
1111 wpa_printf(MSG_ERROR, "You may need to add support for"
1112 " this EAP method during wpa_supplicant\n"
1113 "build time configuration.\n"
1114 "See README for more information.");
1116 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1117 methods[num_methods].method == EAP_TYPE_LEAP)
1129 methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));
1130 if (methods == NULL) {
1134 methods[num_methods].vendor = EAP_VENDOR_IETF;
1135 methods[num_methods].method = EAP_TYPE_NONE;
1138 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1139 (u8 *) methods, num_methods * sizeof(*methods));
1140 os_free(ssid->eap.eap_methods);
1141 ssid->eap.eap_methods = methods;
1142 return errors ? -1 : 0;
1146 static char * wpa_config_write_eap(const struct parse_data *data,
1147 struct wpa_ssid *ssid)
1150 char *buf, *pos, *end;
1151 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1154 if (eap_methods == NULL)
1157 pos = buf = os_zalloc(100);
1162 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1163 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1164 name = eap_get_name(eap_methods[i].vendor,
1165 eap_methods[i].method);
1167 ret = os_snprintf(pos, end - pos, "%s%s",
1168 pos == buf ? "" : " ", name);
1169 if (ret < 0 || ret >= end - pos)
1181 static int wpa_config_parse_password(const struct parse_data *data,
1182 struct wpa_ssid *ssid, int line,
1187 if (os_strcmp(value, "NULL") == 0) {
1188 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1189 os_free(ssid->eap.password);
1190 ssid->eap.password = NULL;
1191 ssid->eap.password_len = 0;
1195 #ifdef CONFIG_EXT_PASSWORD
1196 if (os_strncmp(value, "ext:", 4) == 0) {
1197 char *name = os_strdup(value + 4);
1200 os_free(ssid->eap.password);
1201 ssid->eap.password = (u8 *) name;
1202 ssid->eap.password_len = os_strlen(name);
1203 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1204 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1207 #endif /* CONFIG_EXT_PASSWORD */
1209 if (os_strncmp(value, "hash:", 5) != 0) {
1213 tmp = wpa_config_parse_string(value, &res_len);
1215 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1219 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1220 (u8 *) tmp, res_len);
1222 os_free(ssid->eap.password);
1223 ssid->eap.password = (u8 *) tmp;
1224 ssid->eap.password_len = res_len;
1225 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1226 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1232 /* NtPasswordHash: hash:<32 hex digits> */
1233 if (os_strlen(value + 5) != 2 * 16) {
1234 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1235 "(expected 32 hex digits)", line);
1239 hash = os_malloc(16);
1243 if (hexstr2bin(value + 5, hash, 16)) {
1245 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1249 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1251 os_free(ssid->eap.password);
1252 ssid->eap.password = hash;
1253 ssid->eap.password_len = 16;
1254 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1255 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1261 static char * wpa_config_write_password(const struct parse_data *data,
1262 struct wpa_ssid *ssid)
1266 if (ssid->eap.password == NULL)
1269 #ifdef CONFIG_EXT_PASSWORD
1270 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1271 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1274 os_memcpy(buf, "ext:", 4);
1275 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1278 #endif /* CONFIG_EXT_PASSWORD */
1280 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1281 return wpa_config_write_string(
1282 ssid->eap.password, ssid->eap.password_len);
1285 buf = os_malloc(5 + 32 + 1);
1289 os_memcpy(buf, "hash:", 5);
1290 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1294 #endif /* IEEE8021X_EAPOL */
1297 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1298 const char *value, int idx)
1300 char *buf, title[20];
1303 buf = wpa_config_parse_string(value, len);
1305 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1309 if (*len > MAX_WEP_KEY_LEN) {
1310 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1315 if (*len && *len != 5 && *len != 13 && *len != 16) {
1316 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1317 "this network block will be ignored",
1318 line, (unsigned int) *len);
1320 os_memcpy(key, buf, *len);
1322 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1323 if (res >= 0 && (size_t) res < sizeof(title))
1324 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1329 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1330 struct wpa_ssid *ssid, int line,
1333 return wpa_config_parse_wep_key(ssid->wep_key[0],
1334 &ssid->wep_key_len[0], line,
1339 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1340 struct wpa_ssid *ssid, int line,
1343 return wpa_config_parse_wep_key(ssid->wep_key[1],
1344 &ssid->wep_key_len[1], line,
1349 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1350 struct wpa_ssid *ssid, int line,
1353 return wpa_config_parse_wep_key(ssid->wep_key[2],
1354 &ssid->wep_key_len[2], line,
1359 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1360 struct wpa_ssid *ssid, int line,
1363 return wpa_config_parse_wep_key(ssid->wep_key[3],
1364 &ssid->wep_key_len[3], line,
1369 #ifndef NO_CONFIG_WRITE
1370 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1372 if (ssid->wep_key_len[idx] == 0)
1374 return wpa_config_write_string(ssid->wep_key[idx],
1375 ssid->wep_key_len[idx]);
1379 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1380 struct wpa_ssid *ssid)
1382 return wpa_config_write_wep_key(ssid, 0);
1386 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1387 struct wpa_ssid *ssid)
1389 return wpa_config_write_wep_key(ssid, 1);
1393 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1394 struct wpa_ssid *ssid)
1396 return wpa_config_write_wep_key(ssid, 2);
1400 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1401 struct wpa_ssid *ssid)
1403 return wpa_config_write_wep_key(ssid, 3);
1405 #endif /* NO_CONFIG_WRITE */
1410 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1411 struct wpa_ssid *ssid, int line,
1415 u8 *buf, *n, addr[ETH_ALEN];
1422 while (pos && *pos) {
1426 if (hwaddr_aton(pos, addr)) {
1427 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1428 "p2p_client_list address '%s'.",
1430 /* continue anyway */
1432 n = os_realloc(buf, (count + 1) * ETH_ALEN);
1438 os_memcpy(buf + count * ETH_ALEN, addr, ETH_ALEN);
1440 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1444 pos = os_strchr(pos, ' ');
1447 os_free(ssid->p2p_client_list);
1448 ssid->p2p_client_list = buf;
1449 ssid->num_p2p_clients = count;
1455 #ifndef NO_CONFIG_WRITE
1456 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1457 struct wpa_ssid *ssid)
1459 char *value, *end, *pos;
1463 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1466 value = os_malloc(20 * ssid->num_p2p_clients);
1470 end = value + 20 * ssid->num_p2p_clients;
1472 for (i = 0; i < ssid->num_p2p_clients; i++) {
1473 res = os_snprintf(pos, end - pos, MACSTR " ",
1474 MAC2STR(ssid->p2p_client_list +
1476 if (res < 0 || res >= end - pos) {
1488 #endif /* NO_CONFIG_WRITE */
1490 #endif /* CONFIG_P2P */
1492 /* Helper macros for network block parser */
1497 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1498 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1500 /* STR: Define a string variable for an ASCII string; f = field name */
1501 #ifdef NO_CONFIG_WRITE
1502 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1503 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1504 #else /* NO_CONFIG_WRITE */
1505 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1506 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1507 #endif /* NO_CONFIG_WRITE */
1508 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1509 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1510 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1511 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1513 /* STR_LEN: Define a string variable with a separate variable for storing the
1514 * data length. Unlike STR(), this can be used to store arbitrary binary data
1515 * (i.e., even nul termination character). */
1516 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1517 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1518 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1519 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1520 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1522 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1523 * explicitly specified. */
1524 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1525 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1526 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1528 #ifdef NO_CONFIG_WRITE
1529 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1530 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1531 #else /* NO_CONFIG_WRITE */
1532 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1533 OFFSET(f), (void *) 0
1534 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1535 OFFSET(eap.f), (void *) 0
1536 #endif /* NO_CONFIG_WRITE */
1538 /* INT: Define an integer variable */
1539 #define INT(f) _INT(f), NULL, NULL, 0
1540 #define INTe(f) _INTe(f), NULL, NULL, 0
1542 /* INT_RANGE: Define an integer variable with allowed value range */
1543 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1545 /* FUNC: Define a configuration variable that uses a custom function for
1546 * parsing and writing the value. */
1547 #ifdef NO_CONFIG_WRITE
1548 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1549 #else /* NO_CONFIG_WRITE */
1550 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1551 NULL, NULL, NULL, NULL
1552 #endif /* NO_CONFIG_WRITE */
1553 #define FUNC(f) _FUNC(f), 0
1554 #define FUNC_KEY(f) _FUNC(f), 1
1557 * Table of network configuration variables. This table is used to parse each
1558 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1559 * that is inside a network block.
1561 * This table is generated using the helper macros defined above and with
1562 * generous help from the C pre-processor. The field name is stored as a string
1563 * into .name and for STR and INT types, the offset of the target buffer within
1564 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1565 * offset to the field containing the length of the configuration variable.
1566 * .param3 and .param4 can be used to mark the allowed range (length for STR
1567 * and value for INT).
1569 * For each configuration line in wpa_supplicant.conf, the parser goes through
1570 * this table and select the entry that matches with the field name. The parser
1571 * function (.parser) is then called to parse the actual value of the field.
1573 * This kind of mechanism makes it easy to add new configuration parameters,
1574 * since only one line needs to be added into this table and into the
1575 * struct wpa_ssid definition if the new variable is either a string or
1576 * integer. More complex types will need to use their own parser and writer
1579 static const struct parse_data ssid_fields[] = {
1580 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1581 { INT_RANGE(scan_ssid, 0, 1) },
1586 { INT(bg_scan_period) },
1590 { FUNC(scan_freq) },
1591 { FUNC(freq_list) },
1592 #ifdef IEEE8021X_EAPOL
1594 { STR_LENe(identity) },
1595 { STR_LENe(anonymous_identity) },
1596 { FUNC_KEY(password) },
1599 { STRe(client_cert) },
1600 { STRe(private_key) },
1601 { STR_KEYe(private_key_passwd) },
1603 { STRe(subject_match) },
1604 { STRe(altsubject_match) },
1607 { STRe(client_cert2) },
1608 { STRe(private_key2) },
1609 { STR_KEYe(private_key2_passwd) },
1611 { STRe(subject_match2) },
1612 { STRe(altsubject_match2) },
1617 { STRe(engine_id) },
1620 { STRe(ca_cert_id) },
1622 { STRe(engine2_id) },
1625 { STRe(ca_cert2_id) },
1628 { INT(eapol_flags) },
1629 #endif /* IEEE8021X_EAPOL */
1630 { FUNC_KEY(wep_key0) },
1631 { FUNC_KEY(wep_key1) },
1632 { FUNC_KEY(wep_key2) },
1633 { FUNC_KEY(wep_key3) },
1634 { INT(wep_tx_keyidx) },
1636 #ifdef IEEE8021X_EAPOL
1637 { INT(eap_workaround) },
1639 { INTe(fragment_size) },
1640 #endif /* IEEE8021X_EAPOL */
1641 { INT_RANGE(mode, 0, 4) },
1642 { INT_RANGE(proactive_key_caching, 0, 1) },
1643 { INT_RANGE(disabled, 0, 2) },
1645 #ifdef CONFIG_IEEE80211W
1646 { INT_RANGE(ieee80211w, 0, 2) },
1647 #endif /* CONFIG_IEEE80211W */
1648 { INT_RANGE(peerkey, 0, 1) },
1649 { INT_RANGE(mixed_cell, 0, 1) },
1650 { INT_RANGE(frequency, 0, 10000) },
1651 { INT(wpa_ptk_rekey) },
1653 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1655 { FUNC(p2p_client_list) },
1656 #endif /* CONFIG_P2P */
1657 #ifdef CONFIG_HT_OVERRIDES
1658 { INT_RANGE(disable_ht, 0, 1) },
1659 { INT_RANGE(disable_ht40, -1, 1) },
1660 { INT_RANGE(disable_max_amsdu, -1, 1) },
1661 { INT_RANGE(ampdu_factor, -1, 3) },
1662 { INT_RANGE(ampdu_density, -1, 7) },
1664 #endif /* CONFIG_HT_OVERRIDES */
1665 { INT(ap_max_inactivity) },
1666 { INT(dtim_period) },
1678 #undef STR_RANGE_KEY
1685 #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
1689 * wpa_config_add_prio_network - Add a network to priority lists
1690 * @config: Configuration data from wpa_config_read()
1691 * @ssid: Pointer to the network configuration to be added to the list
1692 * Returns: 0 on success, -1 on failure
1694 * This function is used to add a network block to the priority list of
1695 * networks. This must be called for each network when reading in the full
1696 * configuration. In addition, this can be used indirectly when updating
1697 * priorities by calling wpa_config_update_prio_list().
1699 int wpa_config_add_prio_network(struct wpa_config *config,
1700 struct wpa_ssid *ssid)
1703 struct wpa_ssid *prev, **nlist;
1706 * Add to an existing priority list if one is available for the
1707 * configured priority level for this network.
1709 for (prio = 0; prio < config->num_prio; prio++) {
1710 prev = config->pssid[prio];
1711 if (prev->priority == ssid->priority) {
1719 /* First network for this priority - add a new priority list */
1720 nlist = os_realloc(config->pssid,
1721 (config->num_prio + 1) * sizeof(struct wpa_ssid *));
1725 for (prio = 0; prio < config->num_prio; prio++) {
1726 if (nlist[prio]->priority < ssid->priority) {
1727 os_memmove(&nlist[prio + 1], &nlist[prio],
1728 (config->num_prio - prio) *
1729 sizeof(struct wpa_ssid *));
1736 config->pssid = nlist;
1743 * wpa_config_update_prio_list - Update network priority list
1744 * @config: Configuration data from wpa_config_read()
1745 * Returns: 0 on success, -1 on failure
1747 * This function is called to update the priority list of networks in the
1748 * configuration when a network is being added or removed. This is also called
1749 * if a priority for a network is changed.
1751 int wpa_config_update_prio_list(struct wpa_config *config)
1753 struct wpa_ssid *ssid;
1756 os_free(config->pssid);
1757 config->pssid = NULL;
1758 config->num_prio = 0;
1760 ssid = config->ssid;
1763 if (wpa_config_add_prio_network(config, ssid) < 0)
1772 #ifdef IEEE8021X_EAPOL
1773 static void eap_peer_config_free(struct eap_peer_config *eap)
1775 os_free(eap->eap_methods);
1776 os_free(eap->identity);
1777 os_free(eap->anonymous_identity);
1778 os_free(eap->password);
1779 os_free(eap->ca_cert);
1780 os_free(eap->ca_path);
1781 os_free(eap->client_cert);
1782 os_free(eap->private_key);
1783 os_free(eap->private_key_passwd);
1784 os_free(eap->dh_file);
1785 os_free(eap->subject_match);
1786 os_free(eap->altsubject_match);
1787 os_free(eap->ca_cert2);
1788 os_free(eap->ca_path2);
1789 os_free(eap->client_cert2);
1790 os_free(eap->private_key2);
1791 os_free(eap->private_key2_passwd);
1792 os_free(eap->dh_file2);
1793 os_free(eap->subject_match2);
1794 os_free(eap->altsubject_match2);
1795 os_free(eap->phase1);
1796 os_free(eap->phase2);
1799 os_free(eap->engine_id);
1800 os_free(eap->key_id);
1801 os_free(eap->cert_id);
1802 os_free(eap->ca_cert_id);
1803 os_free(eap->key2_id);
1804 os_free(eap->cert2_id);
1805 os_free(eap->ca_cert2_id);
1807 os_free(eap->engine2_id);
1809 os_free(eap->pending_req_otp);
1810 os_free(eap->pac_file);
1811 os_free(eap->new_password);
1813 #endif /* IEEE8021X_EAPOL */
1817 * wpa_config_free_ssid - Free network/ssid configuration data
1818 * @ssid: Configuration data for the network
1820 * This function frees all resources allocated for the network configuration
1823 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1825 os_free(ssid->ssid);
1826 os_free(ssid->passphrase);
1827 os_free(ssid->ext_psk);
1828 #ifdef IEEE8021X_EAPOL
1829 eap_peer_config_free(&ssid->eap);
1830 #endif /* IEEE8021X_EAPOL */
1831 os_free(ssid->id_str);
1832 os_free(ssid->scan_freq);
1833 os_free(ssid->freq_list);
1834 os_free(ssid->bgscan);
1835 os_free(ssid->p2p_client_list);
1836 #ifdef CONFIG_HT_OVERRIDES
1837 os_free(ssid->ht_mcs);
1838 #endif /* CONFIG_HT_OVERRIDES */
1843 void wpa_config_free_cred(struct wpa_cred *cred)
1845 os_free(cred->realm);
1846 os_free(cred->username);
1847 os_free(cred->password);
1848 os_free(cred->ca_cert);
1849 os_free(cred->client_cert);
1850 os_free(cred->private_key);
1851 os_free(cred->private_key_passwd);
1852 os_free(cred->imsi);
1853 os_free(cred->milenage);
1854 os_free(cred->domain);
1855 os_free(cred->eap_method);
1856 os_free(cred->phase1);
1857 os_free(cred->phase2);
1863 * wpa_config_free - Free configuration data
1864 * @config: Configuration data from wpa_config_read()
1866 * This function frees all resources allocated for the configuration data by
1867 * wpa_config_read().
1869 void wpa_config_free(struct wpa_config *config)
1871 #ifndef CONFIG_NO_CONFIG_BLOBS
1872 struct wpa_config_blob *blob, *prevblob;
1873 #endif /* CONFIG_NO_CONFIG_BLOBS */
1874 struct wpa_ssid *ssid, *prev = NULL;
1875 struct wpa_cred *cred, *cprev;
1877 ssid = config->ssid;
1881 wpa_config_free_ssid(prev);
1884 cred = config->cred;
1888 wpa_config_free_cred(cprev);
1891 #ifndef CONFIG_NO_CONFIG_BLOBS
1892 blob = config->blobs;
1897 wpa_config_free_blob(prevblob);
1899 #endif /* CONFIG_NO_CONFIG_BLOBS */
1901 wpabuf_free(config->wps_vendor_ext_m1);
1902 os_free(config->ctrl_interface);
1903 os_free(config->ctrl_interface_group);
1904 os_free(config->opensc_engine_path);
1905 os_free(config->pkcs11_engine_path);
1906 os_free(config->pkcs11_module_path);
1907 os_free(config->pcsc_reader);
1908 os_free(config->pcsc_pin);
1909 os_free(config->driver_param);
1910 os_free(config->device_name);
1911 os_free(config->manufacturer);
1912 os_free(config->model_name);
1913 os_free(config->model_number);
1914 os_free(config->serial_number);
1915 os_free(config->config_methods);
1916 os_free(config->p2p_ssid_postfix);
1917 os_free(config->pssid);
1918 os_free(config->p2p_pref_chan);
1919 os_free(config->autoscan);
1920 wpabuf_free(config->wps_nfc_dh_pubkey);
1921 wpabuf_free(config->wps_nfc_dh_privkey);
1922 wpabuf_free(config->wps_nfc_dev_pw);
1923 os_free(config->ext_password_backend);
1929 * wpa_config_foreach_network - Iterate over each configured network
1930 * @config: Configuration data from wpa_config_read()
1931 * @func: Callback function to process each network
1932 * @arg: Opaque argument to pass to callback function
1934 * Iterate over the set of configured networks calling the specified
1935 * function for each item. We guard against callbacks removing the
1938 void wpa_config_foreach_network(struct wpa_config *config,
1939 void (*func)(void *, struct wpa_ssid *),
1942 struct wpa_ssid *ssid, *next;
1944 ssid = config->ssid;
1954 * wpa_config_get_network - Get configured network based on id
1955 * @config: Configuration data from wpa_config_read()
1956 * @id: Unique network id to search for
1957 * Returns: Network configuration or %NULL if not found
1959 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
1961 struct wpa_ssid *ssid;
1963 ssid = config->ssid;
1975 * wpa_config_add_network - Add a new network with empty configuration
1976 * @config: Configuration data from wpa_config_read()
1977 * Returns: The new network configuration or %NULL if operation failed
1979 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
1982 struct wpa_ssid *ssid, *last = NULL;
1985 ssid = config->ssid;
1994 ssid = os_zalloc(sizeof(*ssid));
2001 config->ssid = ssid;
2003 wpa_config_update_prio_list(config);
2010 * wpa_config_remove_network - Remove a configured network based on id
2011 * @config: Configuration data from wpa_config_read()
2012 * @id: Unique network id to search for
2013 * Returns: 0 on success, or -1 if the network was not found
2015 int wpa_config_remove_network(struct wpa_config *config, int id)
2017 struct wpa_ssid *ssid, *prev = NULL;
2019 ssid = config->ssid;
2031 prev->next = ssid->next;
2033 config->ssid = ssid->next;
2035 wpa_config_update_prio_list(config);
2036 wpa_config_free_ssid(ssid);
2042 * wpa_config_set_network_defaults - Set network default values
2043 * @ssid: Pointer to network configuration data
2045 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2047 ssid->proto = DEFAULT_PROTO;
2048 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2049 ssid->group_cipher = DEFAULT_GROUP;
2050 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2051 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2052 #ifdef IEEE8021X_EAPOL
2053 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2054 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2055 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2056 #endif /* IEEE8021X_EAPOL */
2057 #ifdef CONFIG_HT_OVERRIDES
2058 ssid->disable_ht = DEFAULT_DISABLE_HT;
2059 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2060 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2061 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2062 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2063 #endif /* CONFIG_HT_OVERRIDES */
2068 * wpa_config_set - Set a variable in network configuration
2069 * @ssid: Pointer to network configuration data
2070 * @var: Variable name, e.g., "ssid"
2071 * @value: Variable value
2072 * @line: Line number in configuration file or 0 if not used
2073 * Returns: 0 on success, -1 on failure
2075 * This function can be used to set network configuration variables based on
2076 * both the configuration file and management interface input. The value
2077 * parameter must be in the same format as the text-based configuration file is
2078 * using. For example, strings are using double quotation marks.
2080 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2086 if (ssid == NULL || var == NULL || value == NULL)
2089 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2090 const struct parse_data *field = &ssid_fields[i];
2091 if (os_strcmp(var, field->name) != 0)
2094 if (field->parser(field, ssid, line, value)) {
2096 wpa_printf(MSG_ERROR, "Line %d: failed to "
2097 "parse %s '%s'.", line, var, value);
2103 if (i == NUM_SSID_FIELDS) {
2105 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2106 "'%s'.", line, var);
2115 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2122 len = os_strlen(value);
2123 buf = os_malloc(len + 3);
2127 os_memcpy(buf + 1, value, len);
2129 buf[len + 2] = '\0';
2130 ret = wpa_config_set(ssid, var, buf, 0);
2137 * wpa_config_get_all - Get all options from network configuration
2138 * @ssid: Pointer to network configuration data
2139 * @get_keys: Determines if keys/passwords will be included in returned list
2140 * (if they may be exported)
2141 * Returns: %NULL terminated list of all set keys and their values in the form
2142 * of [key1, val1, key2, val2, ... , NULL]
2144 * This function can be used to get list of all configured network properties.
2145 * The caller is responsible for freeing the returned list and all its
2148 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2150 const struct parse_data *field;
2156 get_keys = get_keys && ssid->export_keys;
2158 props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
2163 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2164 field = &ssid_fields[i];
2165 if (field->key_data && !get_keys)
2167 value = field->writer(field, ssid);
2170 if (os_strlen(value) == 0) {
2175 key = os_strdup(field->name);
2181 props[fields_num * 2] = key;
2182 props[fields_num * 2 + 1] = value;
2198 #ifndef NO_CONFIG_WRITE
2200 * wpa_config_get - Get a variable in network configuration
2201 * @ssid: Pointer to network configuration data
2202 * @var: Variable name, e.g., "ssid"
2203 * Returns: Value of the variable or %NULL on failure
2205 * This function can be used to get network configuration variables. The
2206 * returned value is a copy of the configuration variable in text format, i.e,.
2207 * the same format that the text-based configuration file and wpa_config_set()
2208 * are using for the value. The caller is responsible for freeing the returned
2211 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2215 if (ssid == NULL || var == NULL)
2218 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2219 const struct parse_data *field = &ssid_fields[i];
2220 if (os_strcmp(var, field->name) == 0)
2221 return field->writer(field, ssid);
2229 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2230 * @ssid: Pointer to network configuration data
2231 * @var: Variable name, e.g., "ssid"
2232 * Returns: Value of the variable or %NULL on failure
2234 * This function can be used to get network configuration variable like
2235 * wpa_config_get(). The only difference is that this functions does not expose
2236 * key/password material from the configuration. In case a key/password field
2237 * is requested, the returned value is an empty string or %NULL if the variable
2238 * is not set or "*" if the variable is set (regardless of its value). The
2239 * returned value is a copy of the configuration variable in text format, i.e,.
2240 * the same format that the text-based configuration file and wpa_config_set()
2241 * are using for the value. The caller is responsible for freeing the returned
2244 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2248 if (ssid == NULL || var == NULL)
2251 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2252 const struct parse_data *field = &ssid_fields[i];
2253 if (os_strcmp(var, field->name) == 0) {
2254 char *res = field->writer(field, ssid);
2255 if (field->key_data) {
2256 if (res && res[0]) {
2257 wpa_printf(MSG_DEBUG, "Do not allow "
2258 "key_data field to be "
2261 return os_strdup("*");
2273 #endif /* NO_CONFIG_WRITE */
2277 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2278 * @ssid: Pointer to network configuration data
2280 * This function must be called to update WPA PSK when either SSID or the
2281 * passphrase has changed for the network configuration.
2283 void wpa_config_update_psk(struct wpa_ssid *ssid)
2285 #ifndef CONFIG_NO_PBKDF2
2286 pbkdf2_sha1(ssid->passphrase,
2287 (char *) ssid->ssid, ssid->ssid_len, 4096,
2288 ssid->psk, PMK_LEN);
2289 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2290 ssid->psk, PMK_LEN);
2292 #endif /* CONFIG_NO_PBKDF2 */
2296 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2297 const char *value, int line)
2302 if (os_strcmp(var, "priority") == 0) {
2303 cred->priority = atoi(value);
2307 if (os_strcmp(var, "pcsc") == 0) {
2308 cred->pcsc = atoi(value);
2312 if (os_strcmp(var, "eap") == 0) {
2313 struct eap_method_type method;
2314 method.method = eap_peer_get_type(value, &method.vendor);
2315 if (method.vendor == EAP_VENDOR_IETF &&
2316 method.method == EAP_TYPE_NONE) {
2317 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2318 "for a credential", line, value);
2321 os_free(cred->eap_method);
2322 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2323 if (cred->eap_method == NULL)
2325 os_memcpy(cred->eap_method, &method, sizeof(method));
2329 if (os_strcmp(var, "password") == 0 &&
2330 os_strncmp(value, "ext:", 4) == 0) {
2331 os_free(cred->password);
2332 cred->password = os_strdup(value);
2333 cred->ext_password = 1;
2337 val = wpa_config_parse_string(value, &len);
2339 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2340 "value '%s'.", line, var, value);
2344 if (os_strcmp(var, "realm") == 0) {
2345 os_free(cred->realm);
2350 if (os_strcmp(var, "username") == 0) {
2351 os_free(cred->username);
2352 cred->username = val;
2356 if (os_strcmp(var, "password") == 0) {
2357 os_free(cred->password);
2358 cred->password = val;
2359 cred->ext_password = 0;
2363 if (os_strcmp(var, "ca_cert") == 0) {
2364 os_free(cred->ca_cert);
2365 cred->ca_cert = val;
2369 if (os_strcmp(var, "client_cert") == 0) {
2370 os_free(cred->client_cert);
2371 cred->client_cert = val;
2375 if (os_strcmp(var, "private_key") == 0) {
2376 os_free(cred->private_key);
2377 cred->private_key = val;
2381 if (os_strcmp(var, "private_key_passwd") == 0) {
2382 os_free(cred->private_key_passwd);
2383 cred->private_key_passwd = val;
2387 if (os_strcmp(var, "imsi") == 0) {
2388 os_free(cred->imsi);
2393 if (os_strcmp(var, "milenage") == 0) {
2394 os_free(cred->milenage);
2395 cred->milenage = val;
2399 if (os_strcmp(var, "domain") == 0) {
2400 os_free(cred->domain);
2405 if (os_strcmp(var, "phase1") == 0) {
2406 os_free(cred->phase1);
2411 if (os_strcmp(var, "phase2") == 0) {
2412 os_free(cred->phase2);
2417 if (os_strcmp(var, "roaming_consortium") == 0) {
2418 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2419 wpa_printf(MSG_ERROR, "Line %d: invalid "
2420 "roaming_consortium length %d (3..15 "
2421 "expected)", line, (int) len);
2425 os_memcpy(cred->roaming_consortium, val, len);
2426 cred->roaming_consortium_len = len;
2432 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2442 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
2444 struct wpa_cred *cred;
2446 cred = config->cred;
2457 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
2460 struct wpa_cred *cred, *last = NULL;
2463 cred = config->cred;
2472 cred = os_zalloc(sizeof(*cred));
2479 config->cred = cred;
2485 int wpa_config_remove_cred(struct wpa_config *config, int id)
2487 struct wpa_cred *cred, *prev = NULL;
2489 cred = config->cred;
2501 prev->next = cred->next;
2503 config->cred = cred->next;
2505 wpa_config_free_cred(cred);
2510 #ifndef CONFIG_NO_CONFIG_BLOBS
2512 * wpa_config_get_blob - Get a named configuration blob
2513 * @config: Configuration data from wpa_config_read()
2514 * @name: Name of the blob
2515 * Returns: Pointer to blob data or %NULL if not found
2517 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
2520 struct wpa_config_blob *blob = config->blobs;
2523 if (os_strcmp(blob->name, name) == 0)
2532 * wpa_config_set_blob - Set or add a named configuration blob
2533 * @config: Configuration data from wpa_config_read()
2534 * @blob: New value for the blob
2536 * Adds a new configuration blob or replaces the current value of an existing
2539 void wpa_config_set_blob(struct wpa_config *config,
2540 struct wpa_config_blob *blob)
2542 wpa_config_remove_blob(config, blob->name);
2543 blob->next = config->blobs;
2544 config->blobs = blob;
2549 * wpa_config_free_blob - Free blob data
2550 * @blob: Pointer to blob to be freed
2552 void wpa_config_free_blob(struct wpa_config_blob *blob)
2555 os_free(blob->name);
2556 os_free(blob->data);
2563 * wpa_config_remove_blob - Remove a named configuration blob
2564 * @config: Configuration data from wpa_config_read()
2565 * @name: Name of the blob to remove
2566 * Returns: 0 if blob was removed or -1 if blob was not found
2568 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
2570 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
2573 if (os_strcmp(pos->name, name) == 0) {
2575 prev->next = pos->next;
2577 config->blobs = pos->next;
2578 wpa_config_free_blob(pos);
2587 #endif /* CONFIG_NO_CONFIG_BLOBS */
2591 * wpa_config_alloc_empty - Allocate an empty configuration
2592 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
2594 * @driver_param: Driver parameters
2595 * Returns: Pointer to allocated configuration data or %NULL on failure
2597 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
2598 const char *driver_param)
2600 struct wpa_config *config;
2602 config = os_zalloc(sizeof(*config));
2605 config->eapol_version = DEFAULT_EAPOL_VERSION;
2606 config->ap_scan = DEFAULT_AP_SCAN;
2607 config->fast_reauth = DEFAULT_FAST_REAUTH;
2608 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
2609 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
2610 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
2611 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
2612 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
2613 config->max_num_sta = DEFAULT_MAX_NUM_STA;
2614 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
2617 config->ctrl_interface = os_strdup(ctrl_interface);
2619 config->driver_param = os_strdup(driver_param);
2625 #ifndef CONFIG_NO_STDOUT_DEBUG
2627 * wpa_config_debug_dump_networks - Debug dump of configured networks
2628 * @config: Configuration data from wpa_config_read()
2630 void wpa_config_debug_dump_networks(struct wpa_config *config)
2633 struct wpa_ssid *ssid;
2635 for (prio = 0; prio < config->num_prio; prio++) {
2636 ssid = config->pssid[prio];
2637 wpa_printf(MSG_DEBUG, "Priority group %d",
2640 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
2642 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2647 #endif /* CONFIG_NO_STDOUT_DEBUG */
2650 struct global_parse_data {
2652 int (*parser)(const struct global_parse_data *data,
2653 struct wpa_config *config, int line, const char *value);
2654 void *param1, *param2, *param3;
2655 unsigned int changed_flag;
2659 static int wpa_global_config_parse_int(const struct global_parse_data *data,
2660 struct wpa_config *config, int line,
2664 dst = (int *) (((u8 *) config) + (long) data->param1);
2666 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
2668 if (data->param2 && *dst < (long) data->param2) {
2669 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
2670 "min_value=%ld)", line, data->name, *dst,
2671 (long) data->param2);
2672 *dst = (long) data->param2;
2676 if (data->param3 && *dst > (long) data->param3) {
2677 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
2678 "max_value=%ld)", line, data->name, *dst,
2679 (long) data->param3);
2680 *dst = (long) data->param3;
2688 static int wpa_global_config_parse_str(const struct global_parse_data *data,
2689 struct wpa_config *config, int line,
2695 len = os_strlen(pos);
2696 if (data->param2 && len < (size_t) data->param2) {
2697 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
2698 "min_len=%ld)", line, data->name,
2699 (unsigned long) len, (long) data->param2);
2703 if (data->param3 && len > (size_t) data->param3) {
2704 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
2705 "max_len=%ld)", line, data->name,
2706 (unsigned long) len, (long) data->param3);
2710 tmp = os_strdup(pos);
2714 dst = (char **) (((u8 *) config) + (long) data->param1);
2717 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
2723 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
2724 struct wpa_config *config, int line,
2728 struct wpabuf **dst, *tmp;
2730 len = os_strlen(pos);
2734 tmp = wpabuf_alloc(len / 2);
2738 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
2743 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
2746 wpa_printf(MSG_DEBUG, "%s", data->name);
2752 static int wpa_config_process_country(const struct global_parse_data *data,
2753 struct wpa_config *config, int line,
2756 if (!pos[0] || !pos[1]) {
2757 wpa_printf(MSG_DEBUG, "Invalid country set");
2760 config->country[0] = pos[0];
2761 config->country[1] = pos[1];
2762 wpa_printf(MSG_DEBUG, "country='%c%c'",
2763 config->country[0], config->country[1]);
2768 static int wpa_config_process_load_dynamic_eap(
2769 const struct global_parse_data *data, struct wpa_config *config,
2770 int line, const char *so)
2773 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
2774 ret = eap_peer_method_load(so);
2776 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
2779 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
2780 "method '%s'.", line, so);
2790 static int wpa_config_process_uuid(const struct global_parse_data *data,
2791 struct wpa_config *config, int line,
2795 if (uuid_str2bin(pos, config->uuid)) {
2796 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2799 uuid_bin2str(config->uuid, buf, sizeof(buf));
2800 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
2805 static int wpa_config_process_device_type(
2806 const struct global_parse_data *data,
2807 struct wpa_config *config, int line, const char *pos)
2809 return wps_dev_type_str2bin(pos, config->device_type);
2813 static int wpa_config_process_os_version(const struct global_parse_data *data,
2814 struct wpa_config *config, int line,
2817 if (hexstr2bin(pos, config->os_version, 4)) {
2818 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
2821 wpa_printf(MSG_DEBUG, "os_version=%08x",
2822 WPA_GET_BE32(config->os_version));
2827 static int wpa_config_process_wps_vendor_ext_m1(
2828 const struct global_parse_data *data,
2829 struct wpa_config *config, int line, const char *pos)
2832 int len = os_strlen(pos) / 2;
2836 wpa_printf(MSG_ERROR, "Line %d: "
2837 "invalid wps_vendor_ext_m1", line);
2841 tmp = wpabuf_alloc(len);
2843 p = wpabuf_put(tmp, len);
2845 if (hexstr2bin(pos, p, len)) {
2846 wpa_printf(MSG_ERROR, "Line %d: "
2847 "invalid wps_vendor_ext_m1", line);
2852 wpabuf_free(config->wps_vendor_ext_m1);
2853 config->wps_vendor_ext_m1 = tmp;
2855 wpa_printf(MSG_ERROR, "Can not allocate "
2856 "memory for wps_vendor_ext_m1");
2863 #endif /* CONFIG_WPS */
2866 static int wpa_config_process_sec_device_type(
2867 const struct global_parse_data *data,
2868 struct wpa_config *config, int line, const char *pos)
2872 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
2873 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
2878 idx = config->num_sec_device_types;
2880 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
2883 config->num_sec_device_types++;
2888 static int wpa_config_process_p2p_pref_chan(
2889 const struct global_parse_data *data,
2890 struct wpa_config *config, int line, const char *pos)
2892 struct p2p_channel *pref = NULL, *n;
2893 unsigned int num = 0;
2897 /* format: class:chan,class:chan,... */
2900 op_class = atoi(pos);
2901 pos2 = os_strchr(pos, ':');
2907 n = os_realloc(pref, (num + 1) * sizeof(struct p2p_channel));
2911 pref[num].op_class = op_class;
2912 pref[num].chan = chan;
2915 pos = os_strchr(pos2, ',');
2921 os_free(config->p2p_pref_chan);
2922 config->p2p_pref_chan = pref;
2923 config->num_p2p_pref_chan = num;
2924 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
2925 (u8 *) config->p2p_pref_chan,
2926 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
2932 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
2935 #endif /* CONFIG_P2P */
2938 static int wpa_config_process_hessid(
2939 const struct global_parse_data *data,
2940 struct wpa_config *config, int line, const char *pos)
2942 if (hwaddr_aton2(pos, config->hessid) < 0) {
2943 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
2955 /* OFFSET: Get offset of a variable within the wpa_config structure */
2956 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
2958 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
2959 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
2960 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
2961 #define INT(f) _INT(f), NULL, NULL
2962 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
2963 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
2964 #define STR(f) _STR(f), NULL, NULL
2965 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
2966 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
2968 static const struct global_parse_data global_fields[] = {
2969 #ifdef CONFIG_CTRL_IFACE
2970 { STR(ctrl_interface), 0 },
2971 { STR(ctrl_interface_group), 0 } /* deprecated */,
2972 #endif /* CONFIG_CTRL_IFACE */
2973 { INT_RANGE(eapol_version, 1, 2), 0 },
2974 { INT(ap_scan), 0 },
2975 { INT(disable_scan_offload), 0 },
2976 { INT(fast_reauth), 0 },
2977 { STR(opensc_engine_path), 0 },
2978 { STR(pkcs11_engine_path), 0 },
2979 { STR(pkcs11_module_path), 0 },
2980 { STR(pcsc_reader), 0 },
2981 { STR(pcsc_pin), 0 },
2982 { STR(driver_param), 0 },
2983 { INT(dot11RSNAConfigPMKLifetime), 0 },
2984 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
2985 { INT(dot11RSNAConfigSATimeout), 0 },
2986 #ifndef CONFIG_NO_CONFIG_WRITE
2987 { INT(update_config), 0 },
2988 #endif /* CONFIG_NO_CONFIG_WRITE */
2989 { FUNC_NO_VAR(load_dynamic_eap), 0 },
2991 { FUNC(uuid), CFG_CHANGED_UUID },
2992 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
2993 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
2994 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
2995 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
2996 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
2997 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
2998 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
2999 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3000 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3001 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3002 #endif /* CONFIG_WPS */
3004 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3005 { INT(p2p_listen_reg_class), 0 },
3006 { INT(p2p_listen_channel), 0 },
3007 { INT(p2p_oper_reg_class), 0 },
3008 { INT(p2p_oper_channel), 0 },
3009 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3010 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3011 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3012 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3013 { INT(p2p_group_idle), 0 },
3014 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3015 #endif /* CONFIG_P2P */
3016 { FUNC(country), CFG_CHANGED_COUNTRY },
3017 { INT(bss_max_count), 0 },
3018 { INT(bss_expiration_age), 0 },
3019 { INT(bss_expiration_scan_count), 0 },
3020 { INT_RANGE(filter_ssids, 0, 1), 0 },
3021 { INT_RANGE(filter_rssi, -100, 0), 0 },
3022 { INT(max_num_sta), 0 },
3023 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3025 { INT_RANGE(hs20, 0, 1), 0 },
3026 #endif /* CONFIG_HS20 */
3027 { INT_RANGE(interworking, 0, 1), 0 },
3028 { FUNC(hessid), 0 },
3029 { INT_RANGE(access_network_type, 0, 15), 0 },
3030 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3031 { STR(autoscan), 0 },
3032 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff), 0 },
3033 { BIN(wps_nfc_dh_pubkey), 0 },
3034 { BIN(wps_nfc_dh_privkey), 0 },
3035 { BIN(wps_nfc_dev_pw), 0 },
3036 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND }
3047 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
3050 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3055 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3056 const struct global_parse_data *field = &global_fields[i];
3057 size_t flen = os_strlen(field->name);
3058 if (os_strncmp(pos, field->name, flen) != 0 ||
3062 if (field->parser(field, config, line, pos + flen + 1)) {
3063 wpa_printf(MSG_ERROR, "Line %d: failed to "
3064 "parse '%s'.", line, pos);
3067 config->changed_parameters |= field->changed_flag;
3070 if (i == NUM_GLOBAL_FIELDS) {
3073 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",