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,
328 #ifndef CONFIG_NO_PBKDF2
333 pos = os_strrchr(value, '"');
337 len = os_strlen(value);
338 if (len < 8 || len > 63) {
339 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
340 "length %lu (expected: 8..63) '%s'.",
341 line, (unsigned long) len, value);
344 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
346 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
347 os_memcmp(ssid->passphrase, value, len) == 0)
350 os_free(ssid->passphrase);
351 ssid->passphrase = os_malloc(len + 1);
352 if (ssid->passphrase == NULL)
354 os_memcpy(ssid->passphrase, value, len);
355 ssid->passphrase[len] = '\0';
357 #else /* CONFIG_NO_PBKDF2 */
358 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
361 #endif /* CONFIG_NO_PBKDF2 */
364 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
365 value[PMK_LEN * 2] != '\0') {
366 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
371 os_free(ssid->passphrase);
372 ssid->passphrase = NULL;
375 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
380 #ifndef NO_CONFIG_WRITE
381 static char * wpa_config_write_psk(const struct parse_data *data,
382 struct wpa_ssid *ssid)
384 if (ssid->passphrase)
385 return wpa_config_write_string_ascii(
386 (const u8 *) ssid->passphrase,
387 os_strlen(ssid->passphrase));
390 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
394 #endif /* NO_CONFIG_WRITE */
397 static int wpa_config_parse_proto(const struct parse_data *data,
398 struct wpa_ssid *ssid, int line,
401 int val = 0, last, errors = 0;
402 char *start, *end, *buf;
404 buf = os_strdup(value);
409 while (*start != '\0') {
410 while (*start == ' ' || *start == '\t')
415 while (*end != ' ' && *end != '\t' && *end != '\0')
419 if (os_strcmp(start, "WPA") == 0)
420 val |= WPA_PROTO_WPA;
421 else if (os_strcmp(start, "RSN") == 0 ||
422 os_strcmp(start, "WPA2") == 0)
423 val |= WPA_PROTO_RSN;
425 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
437 wpa_printf(MSG_ERROR,
438 "Line %d: no proto values configured.", line);
442 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
444 return errors ? -1 : 0;
448 #ifndef NO_CONFIG_WRITE
449 static char * wpa_config_write_proto(const struct parse_data *data,
450 struct wpa_ssid *ssid)
453 char *buf, *pos, *end;
455 pos = buf = os_zalloc(10);
460 if (ssid->proto & WPA_PROTO_WPA) {
461 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
462 if (ret < 0 || ret >= end - pos)
468 if (ssid->proto & WPA_PROTO_RSN) {
469 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
470 if (ret < 0 || ret >= end - pos)
478 #endif /* NO_CONFIG_WRITE */
481 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
482 struct wpa_ssid *ssid, int line,
485 int val = 0, last, errors = 0;
486 char *start, *end, *buf;
488 buf = os_strdup(value);
493 while (*start != '\0') {
494 while (*start == ' ' || *start == '\t')
499 while (*end != ' ' && *end != '\t' && *end != '\0')
503 if (os_strcmp(start, "WPA-PSK") == 0)
504 val |= WPA_KEY_MGMT_PSK;
505 else if (os_strcmp(start, "WPA-EAP") == 0)
506 val |= WPA_KEY_MGMT_IEEE8021X;
507 else if (os_strcmp(start, "IEEE8021X") == 0)
508 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
509 else if (os_strcmp(start, "NONE") == 0)
510 val |= WPA_KEY_MGMT_NONE;
511 else if (os_strcmp(start, "WPA-NONE") == 0)
512 val |= WPA_KEY_MGMT_WPA_NONE;
513 #ifdef CONFIG_IEEE80211R
514 else if (os_strcmp(start, "FT-PSK") == 0)
515 val |= WPA_KEY_MGMT_FT_PSK;
516 else if (os_strcmp(start, "FT-EAP") == 0)
517 val |= WPA_KEY_MGMT_FT_IEEE8021X;
518 #endif /* CONFIG_IEEE80211R */
519 #ifdef CONFIG_IEEE80211W
520 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
521 val |= WPA_KEY_MGMT_PSK_SHA256;
522 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
523 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
524 #endif /* CONFIG_IEEE80211W */
526 else if (os_strcmp(start, "WPS") == 0)
527 val |= WPA_KEY_MGMT_WPS;
528 #endif /* CONFIG_WPS */
530 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
542 wpa_printf(MSG_ERROR,
543 "Line %d: no key_mgmt values configured.", line);
547 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
548 ssid->key_mgmt = val;
549 return errors ? -1 : 0;
553 #ifndef NO_CONFIG_WRITE
554 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
555 struct wpa_ssid *ssid)
557 char *buf, *pos, *end;
560 pos = buf = os_zalloc(50);
565 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
566 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
567 pos == buf ? "" : " ");
568 if (ret < 0 || ret >= end - pos) {
575 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
576 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
577 pos == buf ? "" : " ");
578 if (ret < 0 || ret >= end - pos) {
585 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
586 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
587 pos == buf ? "" : " ");
588 if (ret < 0 || ret >= end - pos) {
595 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
596 ret = os_snprintf(pos, end - pos, "%sNONE",
597 pos == buf ? "" : " ");
598 if (ret < 0 || ret >= end - pos) {
605 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
606 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
607 pos == buf ? "" : " ");
608 if (ret < 0 || ret >= end - pos) {
615 #ifdef CONFIG_IEEE80211R
616 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
617 pos += os_snprintf(pos, end - pos, "%sFT-PSK",
618 pos == buf ? "" : " ");
620 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
621 pos += os_snprintf(pos, end - pos, "%sFT-EAP",
622 pos == buf ? "" : " ");
623 #endif /* CONFIG_IEEE80211R */
625 #ifdef CONFIG_IEEE80211W
626 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
627 pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
628 pos == buf ? "" : " ");
630 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
631 pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
632 pos == buf ? "" : " ");
633 #endif /* CONFIG_IEEE80211W */
636 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
637 pos += os_snprintf(pos, end - pos, "%sWPS",
638 pos == buf ? "" : " ");
639 #endif /* CONFIG_WPS */
643 #endif /* NO_CONFIG_WRITE */
646 static int wpa_config_parse_cipher(int line, const char *value)
649 char *start, *end, *buf;
651 buf = os_strdup(value);
656 while (*start != '\0') {
657 while (*start == ' ' || *start == '\t')
662 while (*end != ' ' && *end != '\t' && *end != '\0')
666 if (os_strcmp(start, "CCMP") == 0)
667 val |= WPA_CIPHER_CCMP;
668 else if (os_strcmp(start, "TKIP") == 0)
669 val |= WPA_CIPHER_TKIP;
670 else if (os_strcmp(start, "WEP104") == 0)
671 val |= WPA_CIPHER_WEP104;
672 else if (os_strcmp(start, "WEP40") == 0)
673 val |= WPA_CIPHER_WEP40;
674 else if (os_strcmp(start, "NONE") == 0)
675 val |= WPA_CIPHER_NONE;
677 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
690 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
698 #ifndef NO_CONFIG_WRITE
699 static char * wpa_config_write_cipher(int cipher)
701 char *buf, *pos, *end;
704 pos = buf = os_zalloc(50);
709 if (cipher & WPA_CIPHER_CCMP) {
710 ret = os_snprintf(pos, end - pos, "%sCCMP",
711 pos == buf ? "" : " ");
712 if (ret < 0 || ret >= end - pos) {
719 if (cipher & WPA_CIPHER_TKIP) {
720 ret = os_snprintf(pos, end - pos, "%sTKIP",
721 pos == buf ? "" : " ");
722 if (ret < 0 || ret >= end - pos) {
729 if (cipher & WPA_CIPHER_WEP104) {
730 ret = os_snprintf(pos, end - pos, "%sWEP104",
731 pos == buf ? "" : " ");
732 if (ret < 0 || ret >= end - pos) {
739 if (cipher & WPA_CIPHER_WEP40) {
740 ret = os_snprintf(pos, end - pos, "%sWEP40",
741 pos == buf ? "" : " ");
742 if (ret < 0 || ret >= end - pos) {
749 if (cipher & WPA_CIPHER_NONE) {
750 ret = os_snprintf(pos, end - pos, "%sNONE",
751 pos == buf ? "" : " ");
752 if (ret < 0 || ret >= end - pos) {
761 #endif /* NO_CONFIG_WRITE */
764 static int wpa_config_parse_pairwise(const struct parse_data *data,
765 struct wpa_ssid *ssid, int line,
769 val = wpa_config_parse_cipher(line, value);
772 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {
773 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
774 "(0x%x).", line, val);
778 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
779 ssid->pairwise_cipher = val;
784 #ifndef NO_CONFIG_WRITE
785 static char * wpa_config_write_pairwise(const struct parse_data *data,
786 struct wpa_ssid *ssid)
788 return wpa_config_write_cipher(ssid->pairwise_cipher);
790 #endif /* NO_CONFIG_WRITE */
793 static int wpa_config_parse_group(const struct parse_data *data,
794 struct wpa_ssid *ssid, int line,
798 val = wpa_config_parse_cipher(line, value);
801 if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |
803 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
804 "(0x%x).", line, val);
808 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
809 ssid->group_cipher = val;
814 #ifndef NO_CONFIG_WRITE
815 static char * wpa_config_write_group(const struct parse_data *data,
816 struct wpa_ssid *ssid)
818 return wpa_config_write_cipher(ssid->group_cipher);
820 #endif /* NO_CONFIG_WRITE */
823 static int wpa_config_parse_auth_alg(const struct parse_data *data,
824 struct wpa_ssid *ssid, int line,
827 int val = 0, last, errors = 0;
828 char *start, *end, *buf;
830 buf = os_strdup(value);
835 while (*start != '\0') {
836 while (*start == ' ' || *start == '\t')
841 while (*end != ' ' && *end != '\t' && *end != '\0')
845 if (os_strcmp(start, "OPEN") == 0)
846 val |= WPA_AUTH_ALG_OPEN;
847 else if (os_strcmp(start, "SHARED") == 0)
848 val |= WPA_AUTH_ALG_SHARED;
849 else if (os_strcmp(start, "LEAP") == 0)
850 val |= WPA_AUTH_ALG_LEAP;
852 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
864 wpa_printf(MSG_ERROR,
865 "Line %d: no auth_alg values configured.", line);
869 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
870 ssid->auth_alg = val;
871 return errors ? -1 : 0;
875 #ifndef NO_CONFIG_WRITE
876 static char * wpa_config_write_auth_alg(const struct parse_data *data,
877 struct wpa_ssid *ssid)
879 char *buf, *pos, *end;
882 pos = buf = os_zalloc(30);
887 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
888 ret = os_snprintf(pos, end - pos, "%sOPEN",
889 pos == buf ? "" : " ");
890 if (ret < 0 || ret >= end - pos) {
897 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
898 ret = os_snprintf(pos, end - pos, "%sSHARED",
899 pos == buf ? "" : " ");
900 if (ret < 0 || ret >= end - pos) {
907 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
908 ret = os_snprintf(pos, end - pos, "%sLEAP",
909 pos == buf ? "" : " ");
910 if (ret < 0 || ret >= end - pos) {
919 #endif /* NO_CONFIG_WRITE */
922 static int * wpa_config_parse_freqs(const struct parse_data *data,
923 struct wpa_ssid *ssid, int line,
932 freqs = os_zalloc((len + 1) * sizeof(int));
943 n = os_realloc(freqs, (len * 2 + 1) * sizeof(int));
948 for (i = len; i <= len * 2; i++)
954 freqs[used] = atoi(pos);
955 if (freqs[used] == 0)
958 pos = os_strchr(pos + 1, ' ');
965 static int wpa_config_parse_scan_freq(const struct parse_data *data,
966 struct wpa_ssid *ssid, int line,
971 freqs = wpa_config_parse_freqs(data, ssid, line, value);
974 os_free(ssid->scan_freq);
975 ssid->scan_freq = freqs;
981 static int wpa_config_parse_freq_list(const struct parse_data *data,
982 struct wpa_ssid *ssid, int line,
987 freqs = wpa_config_parse_freqs(data, ssid, line, value);
990 os_free(ssid->freq_list);
991 ssid->freq_list = freqs;
997 #ifndef NO_CONFIG_WRITE
998 static char * wpa_config_write_freqs(const struct parse_data *data,
1001 char *buf, *pos, *end;
1009 for (i = 0; freqs[i]; i++)
1012 pos = buf = os_zalloc(10 * count + 1);
1015 end = buf + 10 * count + 1;
1017 for (i = 0; freqs[i]; i++) {
1018 ret = os_snprintf(pos, end - pos, "%s%u",
1019 i == 0 ? "" : " ", freqs[i]);
1020 if (ret < 0 || ret >= end - pos) {
1031 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1032 struct wpa_ssid *ssid)
1034 return wpa_config_write_freqs(data, ssid->scan_freq);
1038 static char * wpa_config_write_freq_list(const struct parse_data *data,
1039 struct wpa_ssid *ssid)
1041 return wpa_config_write_freqs(data, ssid->freq_list);
1043 #endif /* NO_CONFIG_WRITE */
1046 #ifdef IEEE8021X_EAPOL
1047 static int wpa_config_parse_eap(const struct parse_data *data,
1048 struct wpa_ssid *ssid, int line,
1051 int last, errors = 0;
1052 char *start, *end, *buf;
1053 struct eap_method_type *methods = NULL, *tmp;
1054 size_t num_methods = 0;
1056 buf = os_strdup(value);
1061 while (*start != '\0') {
1062 while (*start == ' ' || *start == '\t')
1067 while (*end != ' ' && *end != '\t' && *end != '\0')
1069 last = *end == '\0';
1072 methods = os_realloc(methods,
1073 (num_methods + 1) * sizeof(*methods));
1074 if (methods == NULL) {
1079 methods[num_methods].method = eap_peer_get_type(
1080 start, &methods[num_methods].vendor);
1081 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1082 methods[num_methods].method == EAP_TYPE_NONE) {
1083 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1084 "'%s'", line, start);
1085 wpa_printf(MSG_ERROR, "You may need to add support for"
1086 " this EAP method during wpa_supplicant\n"
1087 "build time configuration.\n"
1088 "See README for more information.");
1090 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1091 methods[num_methods].method == EAP_TYPE_LEAP)
1103 methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));
1104 if (methods == NULL) {
1108 methods[num_methods].vendor = EAP_VENDOR_IETF;
1109 methods[num_methods].method = EAP_TYPE_NONE;
1112 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1113 (u8 *) methods, num_methods * sizeof(*methods));
1114 os_free(ssid->eap.eap_methods);
1115 ssid->eap.eap_methods = methods;
1116 return errors ? -1 : 0;
1120 static char * wpa_config_write_eap(const struct parse_data *data,
1121 struct wpa_ssid *ssid)
1124 char *buf, *pos, *end;
1125 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1128 if (eap_methods == NULL)
1131 pos = buf = os_zalloc(100);
1136 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1137 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1138 name = eap_get_name(eap_methods[i].vendor,
1139 eap_methods[i].method);
1141 ret = os_snprintf(pos, end - pos, "%s%s",
1142 pos == buf ? "" : " ", name);
1143 if (ret < 0 || ret >= end - pos)
1155 static int wpa_config_parse_password(const struct parse_data *data,
1156 struct wpa_ssid *ssid, int line,
1161 if (os_strcmp(value, "NULL") == 0) {
1162 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1163 os_free(ssid->eap.password);
1164 ssid->eap.password = NULL;
1165 ssid->eap.password_len = 0;
1169 if (os_strncmp(value, "hash:", 5) != 0) {
1173 tmp = wpa_config_parse_string(value, &res_len);
1175 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1179 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1180 (u8 *) tmp, res_len);
1182 os_free(ssid->eap.password);
1183 ssid->eap.password = (u8 *) tmp;
1184 ssid->eap.password_len = res_len;
1185 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1191 /* NtPasswordHash: hash:<32 hex digits> */
1192 if (os_strlen(value + 5) != 2 * 16) {
1193 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1194 "(expected 32 hex digits)", line);
1198 hash = os_malloc(16);
1202 if (hexstr2bin(value + 5, hash, 16)) {
1204 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1208 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1210 os_free(ssid->eap.password);
1211 ssid->eap.password = hash;
1212 ssid->eap.password_len = 16;
1213 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1219 static char * wpa_config_write_password(const struct parse_data *data,
1220 struct wpa_ssid *ssid)
1224 if (ssid->eap.password == NULL)
1227 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1228 return wpa_config_write_string(
1229 ssid->eap.password, ssid->eap.password_len);
1232 buf = os_malloc(5 + 32 + 1);
1236 os_memcpy(buf, "hash:", 5);
1237 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1241 #endif /* IEEE8021X_EAPOL */
1244 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1245 const char *value, int idx)
1247 char *buf, title[20];
1250 buf = wpa_config_parse_string(value, len);
1252 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1256 if (*len > MAX_WEP_KEY_LEN) {
1257 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1262 if (*len && *len != 5 && *len != 13 && *len != 16) {
1263 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1264 "this network block will be ignored",
1265 line, (unsigned int) *len);
1267 os_memcpy(key, buf, *len);
1269 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1270 if (res >= 0 && (size_t) res < sizeof(title))
1271 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1276 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1277 struct wpa_ssid *ssid, int line,
1280 return wpa_config_parse_wep_key(ssid->wep_key[0],
1281 &ssid->wep_key_len[0], line,
1286 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1287 struct wpa_ssid *ssid, int line,
1290 return wpa_config_parse_wep_key(ssid->wep_key[1],
1291 &ssid->wep_key_len[1], line,
1296 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1297 struct wpa_ssid *ssid, int line,
1300 return wpa_config_parse_wep_key(ssid->wep_key[2],
1301 &ssid->wep_key_len[2], line,
1306 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1307 struct wpa_ssid *ssid, int line,
1310 return wpa_config_parse_wep_key(ssid->wep_key[3],
1311 &ssid->wep_key_len[3], line,
1316 #ifndef NO_CONFIG_WRITE
1317 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1319 if (ssid->wep_key_len[idx] == 0)
1321 return wpa_config_write_string(ssid->wep_key[idx],
1322 ssid->wep_key_len[idx]);
1326 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1327 struct wpa_ssid *ssid)
1329 return wpa_config_write_wep_key(ssid, 0);
1333 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1334 struct wpa_ssid *ssid)
1336 return wpa_config_write_wep_key(ssid, 1);
1340 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1341 struct wpa_ssid *ssid)
1343 return wpa_config_write_wep_key(ssid, 2);
1347 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1348 struct wpa_ssid *ssid)
1350 return wpa_config_write_wep_key(ssid, 3);
1352 #endif /* NO_CONFIG_WRITE */
1357 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1358 struct wpa_ssid *ssid, int line,
1362 u8 *buf, *n, addr[ETH_ALEN];
1369 while (pos && *pos) {
1373 if (hwaddr_aton(pos, addr)) {
1374 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1375 "p2p_client_list address '%s'.",
1377 /* continue anyway */
1379 n = os_realloc(buf, (count + 1) * ETH_ALEN);
1385 os_memcpy(buf + count * ETH_ALEN, addr, ETH_ALEN);
1387 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1391 pos = os_strchr(pos, ' ');
1394 os_free(ssid->p2p_client_list);
1395 ssid->p2p_client_list = buf;
1396 ssid->num_p2p_clients = count;
1402 #ifndef NO_CONFIG_WRITE
1403 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1404 struct wpa_ssid *ssid)
1406 char *value, *end, *pos;
1410 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1413 value = os_malloc(20 * ssid->num_p2p_clients);
1417 end = value + 20 * ssid->num_p2p_clients;
1419 for (i = 0; i < ssid->num_p2p_clients; i++) {
1420 res = os_snprintf(pos, end - pos, MACSTR " ",
1421 MAC2STR(ssid->p2p_client_list +
1423 if (res < 0 || res >= end - pos) {
1435 #endif /* NO_CONFIG_WRITE */
1437 #endif /* CONFIG_P2P */
1439 /* Helper macros for network block parser */
1444 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1445 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1447 /* STR: Define a string variable for an ASCII string; f = field name */
1448 #ifdef NO_CONFIG_WRITE
1449 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1450 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1451 #else /* NO_CONFIG_WRITE */
1452 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1453 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1454 #endif /* NO_CONFIG_WRITE */
1455 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1456 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1457 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1458 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1460 /* STR_LEN: Define a string variable with a separate variable for storing the
1461 * data length. Unlike STR(), this can be used to store arbitrary binary data
1462 * (i.e., even nul termination character). */
1463 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1464 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1465 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1466 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1467 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1469 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1470 * explicitly specified. */
1471 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1472 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1473 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1475 #ifdef NO_CONFIG_WRITE
1476 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1477 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1478 #else /* NO_CONFIG_WRITE */
1479 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1480 OFFSET(f), (void *) 0
1481 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1482 OFFSET(eap.f), (void *) 0
1483 #endif /* NO_CONFIG_WRITE */
1485 /* INT: Define an integer variable */
1486 #define INT(f) _INT(f), NULL, NULL, 0
1487 #define INTe(f) _INTe(f), NULL, NULL, 0
1489 /* INT_RANGE: Define an integer variable with allowed value range */
1490 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1492 /* FUNC: Define a configuration variable that uses a custom function for
1493 * parsing and writing the value. */
1494 #ifdef NO_CONFIG_WRITE
1495 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1496 #else /* NO_CONFIG_WRITE */
1497 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1498 NULL, NULL, NULL, NULL
1499 #endif /* NO_CONFIG_WRITE */
1500 #define FUNC(f) _FUNC(f), 0
1501 #define FUNC_KEY(f) _FUNC(f), 1
1504 * Table of network configuration variables. This table is used to parse each
1505 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1506 * that is inside a network block.
1508 * This table is generated using the helper macros defined above and with
1509 * generous help from the C pre-processor. The field name is stored as a string
1510 * into .name and for STR and INT types, the offset of the target buffer within
1511 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1512 * offset to the field containing the length of the configuration variable.
1513 * .param3 and .param4 can be used to mark the allowed range (length for STR
1514 * and value for INT).
1516 * For each configuration line in wpa_supplicant.conf, the parser goes through
1517 * this table and select the entry that matches with the field name. The parser
1518 * function (.parser) is then called to parse the actual value of the field.
1520 * This kind of mechanism makes it easy to add new configuration parameters,
1521 * since only one line needs to be added into this table and into the
1522 * struct wpa_ssid definition if the new variable is either a string or
1523 * integer. More complex types will need to use their own parser and writer
1526 static const struct parse_data ssid_fields[] = {
1527 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1528 { INT_RANGE(scan_ssid, 0, 1) },
1533 { INT(bg_scan_period) },
1537 { FUNC(scan_freq) },
1538 { FUNC(freq_list) },
1539 #ifdef IEEE8021X_EAPOL
1541 { STR_LENe(identity) },
1542 { STR_LENe(anonymous_identity) },
1543 { FUNC_KEY(password) },
1546 { STRe(client_cert) },
1547 { STRe(private_key) },
1548 { STR_KEYe(private_key_passwd) },
1550 { STRe(subject_match) },
1551 { STRe(altsubject_match) },
1554 { STRe(client_cert2) },
1555 { STRe(private_key2) },
1556 { STR_KEYe(private_key2_passwd) },
1558 { STRe(subject_match2) },
1559 { STRe(altsubject_match2) },
1564 { STRe(engine_id) },
1567 { STRe(ca_cert_id) },
1569 { STRe(engine2_id) },
1572 { STRe(ca_cert2_id) },
1575 { INT(eapol_flags) },
1576 #endif /* IEEE8021X_EAPOL */
1577 { FUNC_KEY(wep_key0) },
1578 { FUNC_KEY(wep_key1) },
1579 { FUNC_KEY(wep_key2) },
1580 { FUNC_KEY(wep_key3) },
1581 { INT(wep_tx_keyidx) },
1583 #ifdef IEEE8021X_EAPOL
1584 { INT(eap_workaround) },
1586 { INTe(fragment_size) },
1587 #endif /* IEEE8021X_EAPOL */
1588 { INT_RANGE(mode, 0, 4) },
1589 { INT_RANGE(proactive_key_caching, 0, 1) },
1590 { INT_RANGE(disabled, 0, 2) },
1592 #ifdef CONFIG_IEEE80211W
1593 { INT_RANGE(ieee80211w, 0, 2) },
1594 #endif /* CONFIG_IEEE80211W */
1595 { INT_RANGE(peerkey, 0, 1) },
1596 { INT_RANGE(mixed_cell, 0, 1) },
1597 { INT_RANGE(frequency, 0, 10000) },
1598 { INT(wpa_ptk_rekey) },
1600 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1602 { FUNC(p2p_client_list) },
1603 #endif /* CONFIG_P2P */
1604 #ifdef CONFIG_HT_OVERRIDES
1605 { INT_RANGE(disable_ht, 0, 1) },
1606 { INT_RANGE(disable_ht40, -1, 1) },
1607 { INT_RANGE(disable_max_amsdu, -1, 1) },
1608 { INT_RANGE(ampdu_factor, -1, 3) },
1609 { INT_RANGE(ampdu_density, -1, 7) },
1611 #endif /* CONFIG_HT_OVERRIDES */
1612 { INT(ap_max_inactivity) },
1624 #undef STR_RANGE_KEY
1631 #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
1635 * wpa_config_add_prio_network - Add a network to priority lists
1636 * @config: Configuration data from wpa_config_read()
1637 * @ssid: Pointer to the network configuration to be added to the list
1638 * Returns: 0 on success, -1 on failure
1640 * This function is used to add a network block to the priority list of
1641 * networks. This must be called for each network when reading in the full
1642 * configuration. In addition, this can be used indirectly when updating
1643 * priorities by calling wpa_config_update_prio_list().
1645 int wpa_config_add_prio_network(struct wpa_config *config,
1646 struct wpa_ssid *ssid)
1649 struct wpa_ssid *prev, **nlist;
1652 * Add to an existing priority list if one is available for the
1653 * configured priority level for this network.
1655 for (prio = 0; prio < config->num_prio; prio++) {
1656 prev = config->pssid[prio];
1657 if (prev->priority == ssid->priority) {
1665 /* First network for this priority - add a new priority list */
1666 nlist = os_realloc(config->pssid,
1667 (config->num_prio + 1) * sizeof(struct wpa_ssid *));
1671 for (prio = 0; prio < config->num_prio; prio++) {
1672 if (nlist[prio]->priority < ssid->priority) {
1673 os_memmove(&nlist[prio + 1], &nlist[prio],
1674 (config->num_prio - prio) *
1675 sizeof(struct wpa_ssid *));
1682 config->pssid = nlist;
1689 * wpa_config_update_prio_list - Update network priority list
1690 * @config: Configuration data from wpa_config_read()
1691 * Returns: 0 on success, -1 on failure
1693 * This function is called to update the priority list of networks in the
1694 * configuration when a network is being added or removed. This is also called
1695 * if a priority for a network is changed.
1697 int wpa_config_update_prio_list(struct wpa_config *config)
1699 struct wpa_ssid *ssid;
1702 os_free(config->pssid);
1703 config->pssid = NULL;
1704 config->num_prio = 0;
1706 ssid = config->ssid;
1709 if (wpa_config_add_prio_network(config, ssid) < 0)
1718 #ifdef IEEE8021X_EAPOL
1719 static void eap_peer_config_free(struct eap_peer_config *eap)
1721 os_free(eap->eap_methods);
1722 os_free(eap->identity);
1723 os_free(eap->anonymous_identity);
1724 os_free(eap->password);
1725 os_free(eap->ca_cert);
1726 os_free(eap->ca_path);
1727 os_free(eap->client_cert);
1728 os_free(eap->private_key);
1729 os_free(eap->private_key_passwd);
1730 os_free(eap->dh_file);
1731 os_free(eap->subject_match);
1732 os_free(eap->altsubject_match);
1733 os_free(eap->ca_cert2);
1734 os_free(eap->ca_path2);
1735 os_free(eap->client_cert2);
1736 os_free(eap->private_key2);
1737 os_free(eap->private_key2_passwd);
1738 os_free(eap->dh_file2);
1739 os_free(eap->subject_match2);
1740 os_free(eap->altsubject_match2);
1741 os_free(eap->phase1);
1742 os_free(eap->phase2);
1745 os_free(eap->engine_id);
1746 os_free(eap->key_id);
1747 os_free(eap->cert_id);
1748 os_free(eap->ca_cert_id);
1749 os_free(eap->key2_id);
1750 os_free(eap->cert2_id);
1751 os_free(eap->ca_cert2_id);
1753 os_free(eap->engine2_id);
1755 os_free(eap->pending_req_otp);
1756 os_free(eap->pac_file);
1757 os_free(eap->new_password);
1759 #endif /* IEEE8021X_EAPOL */
1763 * wpa_config_free_ssid - Free network/ssid configuration data
1764 * @ssid: Configuration data for the network
1766 * This function frees all resources allocated for the network configuration
1769 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1771 os_free(ssid->ssid);
1772 os_free(ssid->passphrase);
1773 #ifdef IEEE8021X_EAPOL
1774 eap_peer_config_free(&ssid->eap);
1775 #endif /* IEEE8021X_EAPOL */
1776 os_free(ssid->id_str);
1777 os_free(ssid->scan_freq);
1778 os_free(ssid->freq_list);
1779 os_free(ssid->bgscan);
1780 os_free(ssid->p2p_client_list);
1781 #ifdef CONFIG_HT_OVERRIDES
1782 os_free(ssid->ht_mcs);
1783 #endif /* CONFIG_HT_OVERRIDES */
1788 void wpa_config_free_cred(struct wpa_cred *cred)
1790 os_free(cred->realm);
1791 os_free(cred->username);
1792 os_free(cred->password);
1793 os_free(cred->ca_cert);
1794 os_free(cred->client_cert);
1795 os_free(cred->private_key);
1796 os_free(cred->private_key_passwd);
1797 os_free(cred->imsi);
1798 os_free(cred->milenage);
1799 os_free(cred->domain);
1805 * wpa_config_free - Free configuration data
1806 * @config: Configuration data from wpa_config_read()
1808 * This function frees all resources allocated for the configuration data by
1809 * wpa_config_read().
1811 void wpa_config_free(struct wpa_config *config)
1813 #ifndef CONFIG_NO_CONFIG_BLOBS
1814 struct wpa_config_blob *blob, *prevblob;
1815 #endif /* CONFIG_NO_CONFIG_BLOBS */
1816 struct wpa_ssid *ssid, *prev = NULL;
1817 struct wpa_cred *cred, *cprev;
1819 ssid = config->ssid;
1823 wpa_config_free_ssid(prev);
1826 cred = config->cred;
1830 wpa_config_free_cred(cprev);
1833 #ifndef CONFIG_NO_CONFIG_BLOBS
1834 blob = config->blobs;
1839 wpa_config_free_blob(prevblob);
1841 #endif /* CONFIG_NO_CONFIG_BLOBS */
1843 wpabuf_free(config->wps_vendor_ext_m1);
1844 os_free(config->ctrl_interface);
1845 os_free(config->ctrl_interface_group);
1846 os_free(config->opensc_engine_path);
1847 os_free(config->pkcs11_engine_path);
1848 os_free(config->pkcs11_module_path);
1849 os_free(config->pcsc_reader);
1850 os_free(config->pcsc_pin);
1851 os_free(config->driver_param);
1852 os_free(config->device_name);
1853 os_free(config->manufacturer);
1854 os_free(config->model_name);
1855 os_free(config->model_number);
1856 os_free(config->serial_number);
1857 os_free(config->config_methods);
1858 os_free(config->p2p_ssid_postfix);
1859 os_free(config->pssid);
1860 os_free(config->p2p_pref_chan);
1866 * wpa_config_foreach_network - Iterate over each configured network
1867 * @config: Configuration data from wpa_config_read()
1868 * @func: Callback function to process each network
1869 * @arg: Opaque argument to pass to callback function
1871 * Iterate over the set of configured networks calling the specified
1872 * function for each item. We guard against callbacks removing the
1875 void wpa_config_foreach_network(struct wpa_config *config,
1876 void (*func)(void *, struct wpa_ssid *),
1879 struct wpa_ssid *ssid, *next;
1881 ssid = config->ssid;
1891 * wpa_config_get_network - Get configured network based on id
1892 * @config: Configuration data from wpa_config_read()
1893 * @id: Unique network id to search for
1894 * Returns: Network configuration or %NULL if not found
1896 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
1898 struct wpa_ssid *ssid;
1900 ssid = config->ssid;
1912 * wpa_config_add_network - Add a new network with empty configuration
1913 * @config: Configuration data from wpa_config_read()
1914 * Returns: The new network configuration or %NULL if operation failed
1916 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
1919 struct wpa_ssid *ssid, *last = NULL;
1922 ssid = config->ssid;
1931 ssid = os_zalloc(sizeof(*ssid));
1938 config->ssid = ssid;
1940 wpa_config_update_prio_list(config);
1947 * wpa_config_remove_network - Remove a configured network based on id
1948 * @config: Configuration data from wpa_config_read()
1949 * @id: Unique network id to search for
1950 * Returns: 0 on success, or -1 if the network was not found
1952 int wpa_config_remove_network(struct wpa_config *config, int id)
1954 struct wpa_ssid *ssid, *prev = NULL;
1956 ssid = config->ssid;
1968 prev->next = ssid->next;
1970 config->ssid = ssid->next;
1972 wpa_config_update_prio_list(config);
1973 wpa_config_free_ssid(ssid);
1979 * wpa_config_set_network_defaults - Set network default values
1980 * @ssid: Pointer to network configuration data
1982 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
1984 ssid->proto = DEFAULT_PROTO;
1985 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
1986 ssid->group_cipher = DEFAULT_GROUP;
1987 ssid->key_mgmt = DEFAULT_KEY_MGMT;
1988 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
1989 #ifdef IEEE8021X_EAPOL
1990 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
1991 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
1992 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
1993 #endif /* IEEE8021X_EAPOL */
1994 #ifdef CONFIG_HT_OVERRIDES
1995 ssid->disable_ht = DEFAULT_DISABLE_HT;
1996 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
1997 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
1998 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
1999 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2000 #endif /* CONFIG_HT_OVERRIDES */
2005 * wpa_config_set - Set a variable in network configuration
2006 * @ssid: Pointer to network configuration data
2007 * @var: Variable name, e.g., "ssid"
2008 * @value: Variable value
2009 * @line: Line number in configuration file or 0 if not used
2010 * Returns: 0 on success, -1 on failure
2012 * This function can be used to set network configuration variables based on
2013 * both the configuration file and management interface input. The value
2014 * parameter must be in the same format as the text-based configuration file is
2015 * using. For example, strings are using double quotation marks.
2017 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2023 if (ssid == NULL || var == NULL || value == NULL)
2026 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2027 const struct parse_data *field = &ssid_fields[i];
2028 if (os_strcmp(var, field->name) != 0)
2031 if (field->parser(field, ssid, line, value)) {
2033 wpa_printf(MSG_ERROR, "Line %d: failed to "
2034 "parse %s '%s'.", line, var, value);
2040 if (i == NUM_SSID_FIELDS) {
2042 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2043 "'%s'.", line, var);
2052 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2059 len = os_strlen(value);
2060 buf = os_malloc(len + 3);
2064 os_memcpy(buf + 1, value, len);
2066 buf[len + 2] = '\0';
2067 ret = wpa_config_set(ssid, var, buf, 0);
2074 * wpa_config_get_all - Get all options from network configuration
2075 * @ssid: Pointer to network configuration data
2076 * @get_keys: Determines if keys/passwords will be included in returned list
2077 * (if they may be exported)
2078 * Returns: %NULL terminated list of all set keys and their values in the form
2079 * of [key1, val1, key2, val2, ... , NULL]
2081 * This function can be used to get list of all configured network properties.
2082 * The caller is responsible for freeing the returned list and all its
2085 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2087 const struct parse_data *field;
2093 get_keys = get_keys && ssid->export_keys;
2095 props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
2100 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2101 field = &ssid_fields[i];
2102 if (field->key_data && !get_keys)
2104 value = field->writer(field, ssid);
2107 if (os_strlen(value) == 0) {
2112 key = os_strdup(field->name);
2118 props[fields_num * 2] = key;
2119 props[fields_num * 2 + 1] = value;
2135 #ifndef NO_CONFIG_WRITE
2137 * wpa_config_get - Get a variable in network configuration
2138 * @ssid: Pointer to network configuration data
2139 * @var: Variable name, e.g., "ssid"
2140 * Returns: Value of the variable or %NULL on failure
2142 * This function can be used to get network configuration variables. The
2143 * returned value is a copy of the configuration variable in text format, i.e,.
2144 * the same format that the text-based configuration file and wpa_config_set()
2145 * are using for the value. The caller is responsible for freeing the returned
2148 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2152 if (ssid == NULL || var == NULL)
2155 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2156 const struct parse_data *field = &ssid_fields[i];
2157 if (os_strcmp(var, field->name) == 0)
2158 return field->writer(field, ssid);
2166 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2167 * @ssid: Pointer to network configuration data
2168 * @var: Variable name, e.g., "ssid"
2169 * Returns: Value of the variable or %NULL on failure
2171 * This function can be used to get network configuration variable like
2172 * wpa_config_get(). The only difference is that this functions does not expose
2173 * key/password material from the configuration. In case a key/password field
2174 * is requested, the returned value is an empty string or %NULL if the variable
2175 * is not set or "*" if the variable is set (regardless of its value). The
2176 * returned value is a copy of the configuration variable in text format, i.e,.
2177 * the same format that the text-based configuration file and wpa_config_set()
2178 * are using for the value. The caller is responsible for freeing the returned
2181 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2185 if (ssid == NULL || var == NULL)
2188 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2189 const struct parse_data *field = &ssid_fields[i];
2190 if (os_strcmp(var, field->name) == 0) {
2191 char *res = field->writer(field, ssid);
2192 if (field->key_data) {
2193 if (res && res[0]) {
2194 wpa_printf(MSG_DEBUG, "Do not allow "
2195 "key_data field to be "
2198 return os_strdup("*");
2210 #endif /* NO_CONFIG_WRITE */
2214 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2215 * @ssid: Pointer to network configuration data
2217 * This function must be called to update WPA PSK when either SSID or the
2218 * passphrase has changed for the network configuration.
2220 void wpa_config_update_psk(struct wpa_ssid *ssid)
2222 #ifndef CONFIG_NO_PBKDF2
2223 pbkdf2_sha1(ssid->passphrase,
2224 (char *) ssid->ssid, ssid->ssid_len, 4096,
2225 ssid->psk, PMK_LEN);
2226 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2227 ssid->psk, PMK_LEN);
2229 #endif /* CONFIG_NO_PBKDF2 */
2233 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2234 const char *value, int line)
2239 if (os_strcmp(var, "priority") == 0) {
2240 cred->priority = atoi(value);
2244 if (os_strcmp(var, "pcsc") == 0) {
2245 cred->pcsc = atoi(value);
2249 val = wpa_config_parse_string(value, &len);
2251 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2252 "value '%s'.", line, var, value);
2256 if (os_strcmp(var, "realm") == 0) {
2257 os_free(cred->realm);
2262 if (os_strcmp(var, "username") == 0) {
2263 os_free(cred->username);
2264 cred->username = val;
2268 if (os_strcmp(var, "password") == 0) {
2269 os_free(cred->password);
2270 cred->password = val;
2274 if (os_strcmp(var, "ca_cert") == 0) {
2275 os_free(cred->ca_cert);
2276 cred->ca_cert = val;
2280 if (os_strcmp(var, "client_cert") == 0) {
2281 os_free(cred->client_cert);
2282 cred->client_cert = val;
2286 if (os_strcmp(var, "private_key") == 0) {
2287 os_free(cred->private_key);
2288 cred->private_key = val;
2292 if (os_strcmp(var, "private_key_passwd") == 0) {
2293 os_free(cred->private_key_passwd);
2294 cred->private_key_passwd = val;
2298 if (os_strcmp(var, "imsi") == 0) {
2299 os_free(cred->imsi);
2304 if (os_strcmp(var, "milenage") == 0) {
2305 os_free(cred->milenage);
2306 cred->milenage = val;
2310 if (os_strcmp(var, "domain") == 0) {
2311 os_free(cred->domain);
2317 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2327 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
2329 struct wpa_cred *cred;
2331 cred = config->cred;
2342 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
2345 struct wpa_cred *cred, *last = NULL;
2348 cred = config->cred;
2357 cred = os_zalloc(sizeof(*cred));
2364 config->cred = cred;
2370 int wpa_config_remove_cred(struct wpa_config *config, int id)
2372 struct wpa_cred *cred, *prev = NULL;
2374 cred = config->cred;
2386 prev->next = cred->next;
2388 config->cred = cred->next;
2390 wpa_config_free_cred(cred);
2395 #ifndef CONFIG_NO_CONFIG_BLOBS
2397 * wpa_config_get_blob - Get a named configuration blob
2398 * @config: Configuration data from wpa_config_read()
2399 * @name: Name of the blob
2400 * Returns: Pointer to blob data or %NULL if not found
2402 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
2405 struct wpa_config_blob *blob = config->blobs;
2408 if (os_strcmp(blob->name, name) == 0)
2417 * wpa_config_set_blob - Set or add a named configuration blob
2418 * @config: Configuration data from wpa_config_read()
2419 * @blob: New value for the blob
2421 * Adds a new configuration blob or replaces the current value of an existing
2424 void wpa_config_set_blob(struct wpa_config *config,
2425 struct wpa_config_blob *blob)
2427 wpa_config_remove_blob(config, blob->name);
2428 blob->next = config->blobs;
2429 config->blobs = blob;
2434 * wpa_config_free_blob - Free blob data
2435 * @blob: Pointer to blob to be freed
2437 void wpa_config_free_blob(struct wpa_config_blob *blob)
2440 os_free(blob->name);
2441 os_free(blob->data);
2448 * wpa_config_remove_blob - Remove a named configuration blob
2449 * @config: Configuration data from wpa_config_read()
2450 * @name: Name of the blob to remove
2451 * Returns: 0 if blob was removed or -1 if blob was not found
2453 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
2455 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
2458 if (os_strcmp(pos->name, name) == 0) {
2460 prev->next = pos->next;
2462 config->blobs = pos->next;
2463 wpa_config_free_blob(pos);
2472 #endif /* CONFIG_NO_CONFIG_BLOBS */
2476 * wpa_config_alloc_empty - Allocate an empty configuration
2477 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
2479 * @driver_param: Driver parameters
2480 * Returns: Pointer to allocated configuration data or %NULL on failure
2482 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
2483 const char *driver_param)
2485 struct wpa_config *config;
2487 config = os_zalloc(sizeof(*config));
2490 config->eapol_version = DEFAULT_EAPOL_VERSION;
2491 config->ap_scan = DEFAULT_AP_SCAN;
2492 config->fast_reauth = DEFAULT_FAST_REAUTH;
2493 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
2494 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
2495 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
2496 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
2497 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
2498 config->max_num_sta = DEFAULT_MAX_NUM_STA;
2499 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
2502 config->ctrl_interface = os_strdup(ctrl_interface);
2504 config->driver_param = os_strdup(driver_param);
2510 #ifndef CONFIG_NO_STDOUT_DEBUG
2512 * wpa_config_debug_dump_networks - Debug dump of configured networks
2513 * @config: Configuration data from wpa_config_read()
2515 void wpa_config_debug_dump_networks(struct wpa_config *config)
2518 struct wpa_ssid *ssid;
2520 for (prio = 0; prio < config->num_prio; prio++) {
2521 ssid = config->pssid[prio];
2522 wpa_printf(MSG_DEBUG, "Priority group %d",
2525 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
2527 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2532 #endif /* CONFIG_NO_STDOUT_DEBUG */
2535 struct global_parse_data {
2537 int (*parser)(const struct global_parse_data *data,
2538 struct wpa_config *config, int line, const char *value);
2539 void *param1, *param2, *param3;
2540 unsigned int changed_flag;
2544 static int wpa_global_config_parse_int(const struct global_parse_data *data,
2545 struct wpa_config *config, int line,
2549 dst = (int *) (((u8 *) config) + (long) data->param1);
2551 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
2553 if (data->param2 && *dst < (long) data->param2) {
2554 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
2555 "min_value=%ld)", line, data->name, *dst,
2556 (long) data->param2);
2557 *dst = (long) data->param2;
2561 if (data->param3 && *dst > (long) data->param3) {
2562 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
2563 "max_value=%ld)", line, data->name, *dst,
2564 (long) data->param3);
2565 *dst = (long) data->param3;
2573 static int wpa_global_config_parse_str(const struct global_parse_data *data,
2574 struct wpa_config *config, int line,
2580 len = os_strlen(pos);
2581 if (data->param2 && len < (size_t) data->param2) {
2582 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
2583 "min_len=%ld)", line, data->name,
2584 (unsigned long) len, (long) data->param2);
2588 if (data->param3 && len > (size_t) data->param3) {
2589 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
2590 "max_len=%ld)", line, data->name,
2591 (unsigned long) len, (long) data->param3);
2595 tmp = os_strdup(pos);
2599 dst = (char **) (((u8 *) config) + (long) data->param1);
2602 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
2608 static int wpa_config_process_country(const struct global_parse_data *data,
2609 struct wpa_config *config, int line,
2612 if (!pos[0] || !pos[1]) {
2613 wpa_printf(MSG_DEBUG, "Invalid country set");
2616 config->country[0] = pos[0];
2617 config->country[1] = pos[1];
2618 wpa_printf(MSG_DEBUG, "country='%c%c'",
2619 config->country[0], config->country[1]);
2624 static int wpa_config_process_load_dynamic_eap(
2625 const struct global_parse_data *data, struct wpa_config *config,
2626 int line, const char *so)
2629 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
2630 ret = eap_peer_method_load(so);
2632 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
2635 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
2636 "method '%s'.", line, so);
2646 static int wpa_config_process_uuid(const struct global_parse_data *data,
2647 struct wpa_config *config, int line,
2651 if (uuid_str2bin(pos, config->uuid)) {
2652 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2655 uuid_bin2str(config->uuid, buf, sizeof(buf));
2656 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
2661 static int wpa_config_process_device_type(
2662 const struct global_parse_data *data,
2663 struct wpa_config *config, int line, const char *pos)
2665 return wps_dev_type_str2bin(pos, config->device_type);
2669 static int wpa_config_process_os_version(const struct global_parse_data *data,
2670 struct wpa_config *config, int line,
2673 if (hexstr2bin(pos, config->os_version, 4)) {
2674 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
2677 wpa_printf(MSG_DEBUG, "os_version=%08x",
2678 WPA_GET_BE32(config->os_version));
2683 static int wpa_config_process_wps_vendor_ext_m1(
2684 const struct global_parse_data *data,
2685 struct wpa_config *config, int line, const char *pos)
2688 int len = os_strlen(pos) / 2;
2692 wpa_printf(MSG_ERROR, "Line %d: "
2693 "invalid wps_vendor_ext_m1", line);
2697 tmp = wpabuf_alloc(len);
2699 p = wpabuf_put(tmp, len);
2701 if (hexstr2bin(pos, p, len)) {
2702 wpa_printf(MSG_ERROR, "Line %d: "
2703 "invalid wps_vendor_ext_m1", line);
2708 wpabuf_free(config->wps_vendor_ext_m1);
2709 config->wps_vendor_ext_m1 = tmp;
2711 wpa_printf(MSG_ERROR, "Can not allocate "
2712 "memory for wps_vendor_ext_m1");
2719 #endif /* CONFIG_WPS */
2722 static int wpa_config_process_sec_device_type(
2723 const struct global_parse_data *data,
2724 struct wpa_config *config, int line, const char *pos)
2728 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
2729 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
2734 idx = config->num_sec_device_types;
2736 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
2739 config->num_sec_device_types++;
2744 static int wpa_config_process_p2p_pref_chan(
2745 const struct global_parse_data *data,
2746 struct wpa_config *config, int line, const char *pos)
2748 struct p2p_channel *pref = NULL, *n;
2749 unsigned int num = 0;
2753 /* format: class:chan,class:chan,... */
2756 op_class = atoi(pos);
2757 pos2 = os_strchr(pos, ':');
2763 n = os_realloc(pref, (num + 1) * sizeof(struct p2p_channel));
2767 pref[num].op_class = op_class;
2768 pref[num].chan = chan;
2771 pos = os_strchr(pos2, ',');
2777 os_free(config->p2p_pref_chan);
2778 config->p2p_pref_chan = pref;
2779 config->num_p2p_pref_chan = num;
2780 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
2781 (u8 *) config->p2p_pref_chan,
2782 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
2788 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
2791 #endif /* CONFIG_P2P */
2794 static int wpa_config_process_hessid(
2795 const struct global_parse_data *data,
2796 struct wpa_config *config, int line, const char *pos)
2798 if (hwaddr_aton2(pos, config->hessid) < 0) {
2799 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
2811 /* OFFSET: Get offset of a variable within the wpa_config structure */
2812 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
2814 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
2815 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
2816 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
2817 #define INT(f) _INT(f), NULL, NULL
2818 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
2819 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
2820 #define STR(f) _STR(f), NULL, NULL
2821 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
2823 static const struct global_parse_data global_fields[] = {
2824 #ifdef CONFIG_CTRL_IFACE
2825 { STR(ctrl_interface), 0 },
2826 { STR(ctrl_interface_group), 0 } /* deprecated */,
2827 #endif /* CONFIG_CTRL_IFACE */
2828 { INT_RANGE(eapol_version, 1, 2), 0 },
2829 { INT(ap_scan), 0 },
2830 { INT(disable_scan_offload), 0 },
2831 { INT(fast_reauth), 0 },
2832 { STR(opensc_engine_path), 0 },
2833 { STR(pkcs11_engine_path), 0 },
2834 { STR(pkcs11_module_path), 0 },
2835 { STR(pcsc_reader), 0 },
2836 { STR(pcsc_pin), 0 },
2837 { STR(driver_param), 0 },
2838 { INT(dot11RSNAConfigPMKLifetime), 0 },
2839 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
2840 { INT(dot11RSNAConfigSATimeout), 0 },
2841 #ifndef CONFIG_NO_CONFIG_WRITE
2842 { INT(update_config), 0 },
2843 #endif /* CONFIG_NO_CONFIG_WRITE */
2844 { FUNC_NO_VAR(load_dynamic_eap), 0 },
2846 { FUNC(uuid), CFG_CHANGED_UUID },
2847 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
2848 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
2849 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
2850 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
2851 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
2852 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
2853 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
2854 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
2855 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
2856 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
2857 #endif /* CONFIG_WPS */
2859 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
2860 { INT(p2p_listen_reg_class), 0 },
2861 { INT(p2p_listen_channel), 0 },
2862 { INT(p2p_oper_reg_class), 0 },
2863 { INT(p2p_oper_channel), 0 },
2864 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
2865 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
2866 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
2867 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
2868 { INT(p2p_group_idle), 0 },
2869 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
2870 #endif /* CONFIG_P2P */
2871 { FUNC(country), CFG_CHANGED_COUNTRY },
2872 { INT(bss_max_count), 0 },
2873 { INT(bss_expiration_age), 0 },
2874 { INT(bss_expiration_scan_count), 0 },
2875 { INT_RANGE(filter_ssids, 0, 1), 0 },
2876 { INT(max_num_sta), 0 },
2877 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
2878 { INT_RANGE(interworking, 0, 1), 0 },
2879 { FUNC(hessid), 0 },
2880 { INT_RANGE(access_network_type, 0, 15), 0 },
2881 { INT_RANGE(pbc_in_m1, 0, 1), 0 }
2891 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
2894 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
2899 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
2900 const struct global_parse_data *field = &global_fields[i];
2901 size_t flen = os_strlen(field->name);
2902 if (os_strncmp(pos, field->name, flen) != 0 ||
2906 if (field->parser(field, config, line, pos + flen + 1)) {
2907 wpa_printf(MSG_ERROR, "Line %d: failed to "
2908 "parse '%s'.", line, pos);
2911 config->changed_parameters |= field->changed_flag;
2914 if (i == NUM_GLOBAL_FIELDS) {
2917 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",
2926 int wpas_network_disabled(struct wpa_ssid *ssid)
2936 for (i = 0; i < NUM_WEP_KEYS; i++) {
2937 size_t len = ssid->wep_key_len[i];
2938 if (len && len != 5 && len != 13 && len != 16)
2939 return 1; /* invalid WEP key */