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 int wpa_config_parse_str(const struct parse_data *data,
57 struct wpa_ssid *ssid,
58 int line, const char *value)
60 size_t res_len, *dst_len;
63 if (os_strcmp(value, "NULL") == 0) {
64 wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
71 tmp = wpa_config_parse_string(value, &res_len);
73 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
75 data->key_data ? "[KEY DATA REMOVED]" : value);
80 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
83 wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
87 if (data->param3 && res_len < (size_t) data->param3) {
88 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
89 "min_len=%ld)", line, data->name,
90 (unsigned long) res_len, (long) data->param3);
95 if (data->param4 && res_len > (size_t) data->param4) {
96 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
97 "max_len=%ld)", line, data->name,
98 (unsigned long) res_len, (long) data->param4);
104 dst = (char **) (((u8 *) ssid) + (long) data->param1);
105 dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
115 #ifndef NO_CONFIG_WRITE
116 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
120 buf = os_malloc(len + 3);
124 os_memcpy(buf + 1, value, len);
132 static char * wpa_config_write_string_hex(const u8 *value, size_t len)
136 buf = os_zalloc(2 * len + 1);
139 wpa_snprintf_hex(buf, 2 * len + 1, value, len);
145 static char * wpa_config_write_string(const u8 *value, size_t len)
150 if (is_hex(value, len))
151 return wpa_config_write_string_hex(value, len);
153 return wpa_config_write_string_ascii(value, len);
157 static char * wpa_config_write_str(const struct parse_data *data,
158 struct wpa_ssid *ssid)
163 src = (char **) (((u8 *) ssid) + (long) data->param1);
168 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
170 len = os_strlen(*src);
172 return wpa_config_write_string((const u8 *) *src, len);
174 #endif /* NO_CONFIG_WRITE */
177 static int wpa_config_parse_int(const struct parse_data *data,
178 struct wpa_ssid *ssid,
179 int line, const char *value)
184 dst = (int *) (((u8 *) ssid) + (long) data->param1);
185 val = strtol(value, &end, 0);
187 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
192 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
194 if (data->param3 && *dst < (long) data->param3) {
195 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
196 "min_value=%ld)", line, data->name, *dst,
197 (long) data->param3);
198 *dst = (long) data->param3;
202 if (data->param4 && *dst > (long) data->param4) {
203 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
204 "max_value=%ld)", line, data->name, *dst,
205 (long) data->param4);
206 *dst = (long) data->param4;
214 #ifndef NO_CONFIG_WRITE
215 static char * wpa_config_write_int(const struct parse_data *data,
216 struct wpa_ssid *ssid)
221 src = (int *) (((u8 *) ssid) + (long) data->param1);
223 value = os_malloc(20);
226 res = os_snprintf(value, 20, "%d", *src);
227 if (res < 0 || res >= 20) {
231 value[20 - 1] = '\0';
234 #endif /* NO_CONFIG_WRITE */
237 static int wpa_config_parse_bssid(const struct parse_data *data,
238 struct wpa_ssid *ssid, int line,
241 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
242 os_strcmp(value, "any") == 0) {
244 wpa_printf(MSG_MSGDUMP, "BSSID any");
247 if (hwaddr_aton(value, ssid->bssid)) {
248 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
253 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
258 #ifndef NO_CONFIG_WRITE
259 static char * wpa_config_write_bssid(const struct parse_data *data,
260 struct wpa_ssid *ssid)
265 if (!ssid->bssid_set)
268 value = os_malloc(20);
271 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
272 if (res < 0 || res >= 20) {
276 value[20 - 1] = '\0';
279 #endif /* NO_CONFIG_WRITE */
282 static int wpa_config_parse_psk(const struct parse_data *data,
283 struct wpa_ssid *ssid, int line,
286 #ifdef CONFIG_EXT_PASSWORD
287 if (os_strncmp(value, "ext:", 4) == 0) {
288 os_free(ssid->passphrase);
289 ssid->passphrase = NULL;
291 os_free(ssid->ext_psk);
292 ssid->ext_psk = os_strdup(value + 4);
293 if (ssid->ext_psk == NULL)
295 wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
299 #endif /* CONFIG_EXT_PASSWORD */
302 #ifndef CONFIG_NO_PBKDF2
307 pos = os_strrchr(value, '"');
311 len = os_strlen(value);
312 if (len < 8 || len > 63) {
313 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
314 "length %lu (expected: 8..63) '%s'.",
315 line, (unsigned long) len, value);
318 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
320 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
321 os_memcmp(ssid->passphrase, value, len) == 0)
324 os_free(ssid->passphrase);
325 ssid->passphrase = os_malloc(len + 1);
326 if (ssid->passphrase == NULL)
328 os_memcpy(ssid->passphrase, value, len);
329 ssid->passphrase[len] = '\0';
331 #else /* CONFIG_NO_PBKDF2 */
332 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
335 #endif /* CONFIG_NO_PBKDF2 */
338 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
339 value[PMK_LEN * 2] != '\0') {
340 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
345 os_free(ssid->passphrase);
346 ssid->passphrase = NULL;
349 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
354 #ifndef NO_CONFIG_WRITE
355 static char * wpa_config_write_psk(const struct parse_data *data,
356 struct wpa_ssid *ssid)
358 #ifdef CONFIG_EXT_PASSWORD
360 size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
361 char *buf = os_malloc(len);
364 os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
367 #endif /* CONFIG_EXT_PASSWORD */
369 if (ssid->passphrase)
370 return wpa_config_write_string_ascii(
371 (const u8 *) ssid->passphrase,
372 os_strlen(ssid->passphrase));
375 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
379 #endif /* NO_CONFIG_WRITE */
382 static int wpa_config_parse_proto(const struct parse_data *data,
383 struct wpa_ssid *ssid, int line,
386 int val = 0, last, errors = 0;
387 char *start, *end, *buf;
389 buf = os_strdup(value);
394 while (*start != '\0') {
395 while (*start == ' ' || *start == '\t')
400 while (*end != ' ' && *end != '\t' && *end != '\0')
404 if (os_strcmp(start, "WPA") == 0)
405 val |= WPA_PROTO_WPA;
406 else if (os_strcmp(start, "RSN") == 0 ||
407 os_strcmp(start, "WPA2") == 0)
408 val |= WPA_PROTO_RSN;
410 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
422 wpa_printf(MSG_ERROR,
423 "Line %d: no proto values configured.", line);
427 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
429 return errors ? -1 : 0;
433 #ifndef NO_CONFIG_WRITE
434 static char * wpa_config_write_proto(const struct parse_data *data,
435 struct wpa_ssid *ssid)
438 char *buf, *pos, *end;
440 pos = buf = os_zalloc(10);
445 if (ssid->proto & WPA_PROTO_WPA) {
446 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
447 if (ret < 0 || ret >= end - pos)
453 if (ssid->proto & WPA_PROTO_RSN) {
454 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
455 if (ret < 0 || ret >= end - pos)
463 #endif /* NO_CONFIG_WRITE */
466 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
467 struct wpa_ssid *ssid, int line,
470 int val = 0, last, errors = 0;
471 char *start, *end, *buf;
473 buf = os_strdup(value);
478 while (*start != '\0') {
479 while (*start == ' ' || *start == '\t')
484 while (*end != ' ' && *end != '\t' && *end != '\0')
488 if (os_strcmp(start, "WPA-PSK") == 0)
489 val |= WPA_KEY_MGMT_PSK;
490 else if (os_strcmp(start, "WPA-EAP") == 0)
491 val |= WPA_KEY_MGMT_IEEE8021X;
492 else if (os_strcmp(start, "IEEE8021X") == 0)
493 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
494 else if (os_strcmp(start, "NONE") == 0)
495 val |= WPA_KEY_MGMT_NONE;
496 else if (os_strcmp(start, "WPA-NONE") == 0)
497 val |= WPA_KEY_MGMT_WPA_NONE;
498 #ifdef CONFIG_IEEE80211R
499 else if (os_strcmp(start, "FT-PSK") == 0)
500 val |= WPA_KEY_MGMT_FT_PSK;
501 else if (os_strcmp(start, "FT-EAP") == 0)
502 val |= WPA_KEY_MGMT_FT_IEEE8021X;
503 #endif /* CONFIG_IEEE80211R */
504 #ifdef CONFIG_IEEE80211W
505 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
506 val |= WPA_KEY_MGMT_PSK_SHA256;
507 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
508 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
509 #endif /* CONFIG_IEEE80211W */
511 else if (os_strcmp(start, "WPS") == 0)
512 val |= WPA_KEY_MGMT_WPS;
513 #endif /* CONFIG_WPS */
515 else if (os_strcmp(start, "SAE") == 0)
516 val |= WPA_KEY_MGMT_SAE;
517 else if (os_strcmp(start, "FT-SAE") == 0)
518 val |= WPA_KEY_MGMT_FT_SAE;
519 #endif /* CONFIG_SAE */
521 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
533 wpa_printf(MSG_ERROR,
534 "Line %d: no key_mgmt values configured.", line);
538 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
539 ssid->key_mgmt = val;
540 return errors ? -1 : 0;
544 #ifndef NO_CONFIG_WRITE
545 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
546 struct wpa_ssid *ssid)
548 char *buf, *pos, *end;
551 pos = buf = os_zalloc(50);
556 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
557 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
558 pos == buf ? "" : " ");
559 if (ret < 0 || ret >= end - pos) {
566 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
567 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
568 pos == buf ? "" : " ");
569 if (ret < 0 || ret >= end - pos) {
576 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
577 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
578 pos == buf ? "" : " ");
579 if (ret < 0 || ret >= end - pos) {
586 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
587 ret = os_snprintf(pos, end - pos, "%sNONE",
588 pos == buf ? "" : " ");
589 if (ret < 0 || ret >= end - pos) {
596 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
597 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
598 pos == buf ? "" : " ");
599 if (ret < 0 || ret >= end - pos) {
606 #ifdef CONFIG_IEEE80211R
607 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
608 pos += os_snprintf(pos, end - pos, "%sFT-PSK",
609 pos == buf ? "" : " ");
611 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
612 pos += os_snprintf(pos, end - pos, "%sFT-EAP",
613 pos == buf ? "" : " ");
614 #endif /* CONFIG_IEEE80211R */
616 #ifdef CONFIG_IEEE80211W
617 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
618 pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
619 pos == buf ? "" : " ");
621 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
622 pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
623 pos == buf ? "" : " ");
624 #endif /* CONFIG_IEEE80211W */
627 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
628 pos += os_snprintf(pos, end - pos, "%sWPS",
629 pos == buf ? "" : " ");
630 #endif /* CONFIG_WPS */
634 #endif /* NO_CONFIG_WRITE */
637 static int wpa_config_parse_cipher(int line, const char *value)
639 int val = wpa_parse_cipher(value);
641 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
646 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
654 #ifndef NO_CONFIG_WRITE
655 static char * wpa_config_write_cipher(int cipher)
657 char *buf = os_zalloc(50);
661 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
668 #endif /* NO_CONFIG_WRITE */
671 static int wpa_config_parse_pairwise(const struct parse_data *data,
672 struct wpa_ssid *ssid, int line,
676 val = wpa_config_parse_cipher(line, value);
679 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
680 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
681 "(0x%x).", line, val);
685 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
686 ssid->pairwise_cipher = val;
691 #ifndef NO_CONFIG_WRITE
692 static char * wpa_config_write_pairwise(const struct parse_data *data,
693 struct wpa_ssid *ssid)
695 return wpa_config_write_cipher(ssid->pairwise_cipher);
697 #endif /* NO_CONFIG_WRITE */
700 static int wpa_config_parse_group(const struct parse_data *data,
701 struct wpa_ssid *ssid, int line,
705 val = wpa_config_parse_cipher(line, value);
708 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
709 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
710 "(0x%x).", line, val);
714 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
715 ssid->group_cipher = val;
720 #ifndef NO_CONFIG_WRITE
721 static char * wpa_config_write_group(const struct parse_data *data,
722 struct wpa_ssid *ssid)
724 return wpa_config_write_cipher(ssid->group_cipher);
726 #endif /* NO_CONFIG_WRITE */
729 static int wpa_config_parse_auth_alg(const struct parse_data *data,
730 struct wpa_ssid *ssid, int line,
733 int val = 0, last, errors = 0;
734 char *start, *end, *buf;
736 buf = os_strdup(value);
741 while (*start != '\0') {
742 while (*start == ' ' || *start == '\t')
747 while (*end != ' ' && *end != '\t' && *end != '\0')
751 if (os_strcmp(start, "OPEN") == 0)
752 val |= WPA_AUTH_ALG_OPEN;
753 else if (os_strcmp(start, "SHARED") == 0)
754 val |= WPA_AUTH_ALG_SHARED;
755 else if (os_strcmp(start, "LEAP") == 0)
756 val |= WPA_AUTH_ALG_LEAP;
758 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
770 wpa_printf(MSG_ERROR,
771 "Line %d: no auth_alg values configured.", line);
775 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
776 ssid->auth_alg = val;
777 return errors ? -1 : 0;
781 #ifndef NO_CONFIG_WRITE
782 static char * wpa_config_write_auth_alg(const struct parse_data *data,
783 struct wpa_ssid *ssid)
785 char *buf, *pos, *end;
788 pos = buf = os_zalloc(30);
793 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
794 ret = os_snprintf(pos, end - pos, "%sOPEN",
795 pos == buf ? "" : " ");
796 if (ret < 0 || ret >= end - pos) {
803 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
804 ret = os_snprintf(pos, end - pos, "%sSHARED",
805 pos == buf ? "" : " ");
806 if (ret < 0 || ret >= end - pos) {
813 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
814 ret = os_snprintf(pos, end - pos, "%sLEAP",
815 pos == buf ? "" : " ");
816 if (ret < 0 || ret >= end - pos) {
825 #endif /* NO_CONFIG_WRITE */
828 static int * wpa_config_parse_int_array(const char *value)
836 freqs = os_calloc(len + 1, sizeof(int));
847 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
852 for (i = len; i <= len * 2; i++)
858 freqs[used] = atoi(pos);
859 if (freqs[used] == 0)
862 pos = os_strchr(pos + 1, ' ');
869 static int wpa_config_parse_scan_freq(const struct parse_data *data,
870 struct wpa_ssid *ssid, int line,
875 freqs = wpa_config_parse_int_array(value);
878 os_free(ssid->scan_freq);
879 ssid->scan_freq = freqs;
885 static int wpa_config_parse_freq_list(const struct parse_data *data,
886 struct wpa_ssid *ssid, int line,
891 freqs = wpa_config_parse_int_array(value);
894 os_free(ssid->freq_list);
895 ssid->freq_list = freqs;
901 #ifndef NO_CONFIG_WRITE
902 static char * wpa_config_write_freqs(const struct parse_data *data,
905 char *buf, *pos, *end;
913 for (i = 0; freqs[i]; i++)
916 pos = buf = os_zalloc(10 * count + 1);
919 end = buf + 10 * count + 1;
921 for (i = 0; freqs[i]; i++) {
922 ret = os_snprintf(pos, end - pos, "%s%u",
923 i == 0 ? "" : " ", freqs[i]);
924 if (ret < 0 || ret >= end - pos) {
935 static char * wpa_config_write_scan_freq(const struct parse_data *data,
936 struct wpa_ssid *ssid)
938 return wpa_config_write_freqs(data, ssid->scan_freq);
942 static char * wpa_config_write_freq_list(const struct parse_data *data,
943 struct wpa_ssid *ssid)
945 return wpa_config_write_freqs(data, ssid->freq_list);
947 #endif /* NO_CONFIG_WRITE */
950 #ifdef IEEE8021X_EAPOL
951 static int wpa_config_parse_eap(const struct parse_data *data,
952 struct wpa_ssid *ssid, int line,
955 int last, errors = 0;
956 char *start, *end, *buf;
957 struct eap_method_type *methods = NULL, *tmp;
958 size_t num_methods = 0;
960 buf = os_strdup(value);
965 while (*start != '\0') {
966 while (*start == ' ' || *start == '\t')
971 while (*end != ' ' && *end != '\t' && *end != '\0')
976 methods = os_realloc_array(methods, num_methods + 1,
978 if (methods == NULL) {
983 methods[num_methods].method = eap_peer_get_type(
984 start, &methods[num_methods].vendor);
985 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
986 methods[num_methods].method == EAP_TYPE_NONE) {
987 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
988 "'%s'", line, start);
989 wpa_printf(MSG_ERROR, "You may need to add support for"
990 " this EAP method during wpa_supplicant\n"
991 "build time configuration.\n"
992 "See README for more information.");
994 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
995 methods[num_methods].method == EAP_TYPE_LEAP)
1007 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1008 if (methods == NULL) {
1012 methods[num_methods].vendor = EAP_VENDOR_IETF;
1013 methods[num_methods].method = EAP_TYPE_NONE;
1016 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1017 (u8 *) methods, num_methods * sizeof(*methods));
1018 os_free(ssid->eap.eap_methods);
1019 ssid->eap.eap_methods = methods;
1020 return errors ? -1 : 0;
1024 static char * wpa_config_write_eap(const struct parse_data *data,
1025 struct wpa_ssid *ssid)
1028 char *buf, *pos, *end;
1029 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1032 if (eap_methods == NULL)
1035 pos = buf = os_zalloc(100);
1040 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1041 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1042 name = eap_get_name(eap_methods[i].vendor,
1043 eap_methods[i].method);
1045 ret = os_snprintf(pos, end - pos, "%s%s",
1046 pos == buf ? "" : " ", name);
1047 if (ret < 0 || ret >= end - pos)
1059 static int wpa_config_parse_password(const struct parse_data *data,
1060 struct wpa_ssid *ssid, int line,
1065 if (os_strcmp(value, "NULL") == 0) {
1066 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1067 os_free(ssid->eap.password);
1068 ssid->eap.password = NULL;
1069 ssid->eap.password_len = 0;
1073 #ifdef CONFIG_EXT_PASSWORD
1074 if (os_strncmp(value, "ext:", 4) == 0) {
1075 char *name = os_strdup(value + 4);
1078 os_free(ssid->eap.password);
1079 ssid->eap.password = (u8 *) name;
1080 ssid->eap.password_len = os_strlen(name);
1081 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1082 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1085 #endif /* CONFIG_EXT_PASSWORD */
1087 if (os_strncmp(value, "hash:", 5) != 0) {
1091 tmp = wpa_config_parse_string(value, &res_len);
1093 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1097 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1098 (u8 *) tmp, res_len);
1100 os_free(ssid->eap.password);
1101 ssid->eap.password = (u8 *) tmp;
1102 ssid->eap.password_len = res_len;
1103 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1104 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1110 /* NtPasswordHash: hash:<32 hex digits> */
1111 if (os_strlen(value + 5) != 2 * 16) {
1112 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1113 "(expected 32 hex digits)", line);
1117 hash = os_malloc(16);
1121 if (hexstr2bin(value + 5, hash, 16)) {
1123 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1127 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1129 os_free(ssid->eap.password);
1130 ssid->eap.password = hash;
1131 ssid->eap.password_len = 16;
1132 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1133 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1139 static char * wpa_config_write_password(const struct parse_data *data,
1140 struct wpa_ssid *ssid)
1144 if (ssid->eap.password == NULL)
1147 #ifdef CONFIG_EXT_PASSWORD
1148 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1149 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1152 os_memcpy(buf, "ext:", 4);
1153 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1156 #endif /* CONFIG_EXT_PASSWORD */
1158 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1159 return wpa_config_write_string(
1160 ssid->eap.password, ssid->eap.password_len);
1163 buf = os_malloc(5 + 32 + 1);
1167 os_memcpy(buf, "hash:", 5);
1168 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1172 #endif /* IEEE8021X_EAPOL */
1175 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1176 const char *value, int idx)
1178 char *buf, title[20];
1181 buf = wpa_config_parse_string(value, len);
1183 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1187 if (*len > MAX_WEP_KEY_LEN) {
1188 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1193 if (*len && *len != 5 && *len != 13 && *len != 16) {
1194 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1195 "this network block will be ignored",
1196 line, (unsigned int) *len);
1198 os_memcpy(key, buf, *len);
1200 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1201 if (res >= 0 && (size_t) res < sizeof(title))
1202 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1207 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1208 struct wpa_ssid *ssid, int line,
1211 return wpa_config_parse_wep_key(ssid->wep_key[0],
1212 &ssid->wep_key_len[0], line,
1217 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1218 struct wpa_ssid *ssid, int line,
1221 return wpa_config_parse_wep_key(ssid->wep_key[1],
1222 &ssid->wep_key_len[1], line,
1227 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1228 struct wpa_ssid *ssid, int line,
1231 return wpa_config_parse_wep_key(ssid->wep_key[2],
1232 &ssid->wep_key_len[2], line,
1237 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1238 struct wpa_ssid *ssid, int line,
1241 return wpa_config_parse_wep_key(ssid->wep_key[3],
1242 &ssid->wep_key_len[3], line,
1247 #ifndef NO_CONFIG_WRITE
1248 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1250 if (ssid->wep_key_len[idx] == 0)
1252 return wpa_config_write_string(ssid->wep_key[idx],
1253 ssid->wep_key_len[idx]);
1257 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1258 struct wpa_ssid *ssid)
1260 return wpa_config_write_wep_key(ssid, 0);
1264 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1265 struct wpa_ssid *ssid)
1267 return wpa_config_write_wep_key(ssid, 1);
1271 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1272 struct wpa_ssid *ssid)
1274 return wpa_config_write_wep_key(ssid, 2);
1278 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1279 struct wpa_ssid *ssid)
1281 return wpa_config_write_wep_key(ssid, 3);
1283 #endif /* NO_CONFIG_WRITE */
1288 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1289 struct wpa_ssid *ssid, int line,
1293 u8 *buf, *n, addr[ETH_ALEN];
1300 while (pos && *pos) {
1304 if (hwaddr_aton(pos, addr)) {
1306 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1307 "p2p_client_list address '%s'.",
1312 /* continue anyway since this could have been from a
1313 * truncated configuration file line */
1314 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1315 "truncated p2p_client_list address '%s'",
1318 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1324 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1325 os_memcpy(buf, addr, ETH_ALEN);
1327 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1331 pos = os_strchr(pos, ' ');
1334 os_free(ssid->p2p_client_list);
1335 ssid->p2p_client_list = buf;
1336 ssid->num_p2p_clients = count;
1342 #ifndef NO_CONFIG_WRITE
1343 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1344 struct wpa_ssid *ssid)
1346 char *value, *end, *pos;
1350 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1353 value = os_malloc(20 * ssid->num_p2p_clients);
1357 end = value + 20 * ssid->num_p2p_clients;
1359 for (i = ssid->num_p2p_clients; i > 0; i--) {
1360 res = os_snprintf(pos, end - pos, MACSTR " ",
1361 MAC2STR(ssid->p2p_client_list +
1362 (i - 1) * ETH_ALEN));
1363 if (res < 0 || res >= end - pos) {
1375 #endif /* NO_CONFIG_WRITE */
1377 #endif /* CONFIG_P2P */
1379 /* Helper macros for network block parser */
1384 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1385 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1387 /* STR: Define a string variable for an ASCII string; f = field name */
1388 #ifdef NO_CONFIG_WRITE
1389 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1390 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1391 #else /* NO_CONFIG_WRITE */
1392 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1393 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1394 #endif /* NO_CONFIG_WRITE */
1395 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1396 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1397 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1398 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1400 /* STR_LEN: Define a string variable with a separate variable for storing the
1401 * data length. Unlike STR(), this can be used to store arbitrary binary data
1402 * (i.e., even nul termination character). */
1403 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1404 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1405 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1406 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1407 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1409 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1410 * explicitly specified. */
1411 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1412 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1413 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1415 #ifdef NO_CONFIG_WRITE
1416 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1417 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1418 #else /* NO_CONFIG_WRITE */
1419 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1420 OFFSET(f), (void *) 0
1421 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1422 OFFSET(eap.f), (void *) 0
1423 #endif /* NO_CONFIG_WRITE */
1425 /* INT: Define an integer variable */
1426 #define INT(f) _INT(f), NULL, NULL, 0
1427 #define INTe(f) _INTe(f), NULL, NULL, 0
1429 /* INT_RANGE: Define an integer variable with allowed value range */
1430 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1432 /* FUNC: Define a configuration variable that uses a custom function for
1433 * parsing and writing the value. */
1434 #ifdef NO_CONFIG_WRITE
1435 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1436 #else /* NO_CONFIG_WRITE */
1437 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1438 NULL, NULL, NULL, NULL
1439 #endif /* NO_CONFIG_WRITE */
1440 #define FUNC(f) _FUNC(f), 0
1441 #define FUNC_KEY(f) _FUNC(f), 1
1444 * Table of network configuration variables. This table is used to parse each
1445 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1446 * that is inside a network block.
1448 * This table is generated using the helper macros defined above and with
1449 * generous help from the C pre-processor. The field name is stored as a string
1450 * into .name and for STR and INT types, the offset of the target buffer within
1451 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1452 * offset to the field containing the length of the configuration variable.
1453 * .param3 and .param4 can be used to mark the allowed range (length for STR
1454 * and value for INT).
1456 * For each configuration line in wpa_supplicant.conf, the parser goes through
1457 * this table and select the entry that matches with the field name. The parser
1458 * function (.parser) is then called to parse the actual value of the field.
1460 * This kind of mechanism makes it easy to add new configuration parameters,
1461 * since only one line needs to be added into this table and into the
1462 * struct wpa_ssid definition if the new variable is either a string or
1463 * integer. More complex types will need to use their own parser and writer
1466 static const struct parse_data ssid_fields[] = {
1467 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1468 { INT_RANGE(scan_ssid, 0, 1) },
1473 { INT(bg_scan_period) },
1477 { FUNC(scan_freq) },
1478 { FUNC(freq_list) },
1479 #ifdef IEEE8021X_EAPOL
1481 { STR_LENe(identity) },
1482 { STR_LENe(anonymous_identity) },
1483 { FUNC_KEY(password) },
1486 { STRe(client_cert) },
1487 { STRe(private_key) },
1488 { STR_KEYe(private_key_passwd) },
1490 { STRe(subject_match) },
1491 { STRe(altsubject_match) },
1494 { STRe(client_cert2) },
1495 { STRe(private_key2) },
1496 { STR_KEYe(private_key2_passwd) },
1498 { STRe(subject_match2) },
1499 { STRe(altsubject_match2) },
1504 { STRe(engine_id) },
1507 { STRe(ca_cert_id) },
1509 { STRe(engine2_id) },
1512 { STRe(ca_cert2_id) },
1515 { INT(eapol_flags) },
1516 #endif /* IEEE8021X_EAPOL */
1517 { FUNC_KEY(wep_key0) },
1518 { FUNC_KEY(wep_key1) },
1519 { FUNC_KEY(wep_key2) },
1520 { FUNC_KEY(wep_key3) },
1521 { INT(wep_tx_keyidx) },
1523 #ifdef IEEE8021X_EAPOL
1524 { INT(eap_workaround) },
1526 { INTe(fragment_size) },
1527 #endif /* IEEE8021X_EAPOL */
1528 { INT_RANGE(mode, 0, 4) },
1529 { INT_RANGE(proactive_key_caching, 0, 1) },
1530 { INT_RANGE(disabled, 0, 2) },
1532 #ifdef CONFIG_IEEE80211W
1533 { INT_RANGE(ieee80211w, 0, 2) },
1534 #endif /* CONFIG_IEEE80211W */
1535 { INT_RANGE(peerkey, 0, 1) },
1536 { INT_RANGE(mixed_cell, 0, 1) },
1537 { INT_RANGE(frequency, 0, 65000) },
1538 { INT(wpa_ptk_rekey) },
1540 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1542 { FUNC(p2p_client_list) },
1543 #endif /* CONFIG_P2P */
1544 #ifdef CONFIG_HT_OVERRIDES
1545 { INT_RANGE(disable_ht, 0, 1) },
1546 { INT_RANGE(disable_ht40, -1, 1) },
1547 { INT_RANGE(disable_sgi, 0, 1) },
1548 { INT_RANGE(disable_max_amsdu, -1, 1) },
1549 { INT_RANGE(ampdu_factor, -1, 3) },
1550 { INT_RANGE(ampdu_density, -1, 7) },
1552 #endif /* CONFIG_HT_OVERRIDES */
1553 { INT(ap_max_inactivity) },
1554 { INT(dtim_period) },
1555 { INT(beacon_int) },
1567 #undef STR_RANGE_KEY
1574 #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
1578 * wpa_config_add_prio_network - Add a network to priority lists
1579 * @config: Configuration data from wpa_config_read()
1580 * @ssid: Pointer to the network configuration to be added to the list
1581 * Returns: 0 on success, -1 on failure
1583 * This function is used to add a network block to the priority list of
1584 * networks. This must be called for each network when reading in the full
1585 * configuration. In addition, this can be used indirectly when updating
1586 * priorities by calling wpa_config_update_prio_list().
1588 int wpa_config_add_prio_network(struct wpa_config *config,
1589 struct wpa_ssid *ssid)
1592 struct wpa_ssid *prev, **nlist;
1595 * Add to an existing priority list if one is available for the
1596 * configured priority level for this network.
1598 for (prio = 0; prio < config->num_prio; prio++) {
1599 prev = config->pssid[prio];
1600 if (prev->priority == ssid->priority) {
1608 /* First network for this priority - add a new priority list */
1609 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1610 sizeof(struct wpa_ssid *));
1614 for (prio = 0; prio < config->num_prio; prio++) {
1615 if (nlist[prio]->priority < ssid->priority) {
1616 os_memmove(&nlist[prio + 1], &nlist[prio],
1617 (config->num_prio - prio) *
1618 sizeof(struct wpa_ssid *));
1625 config->pssid = nlist;
1632 * wpa_config_update_prio_list - Update network priority list
1633 * @config: Configuration data from wpa_config_read()
1634 * Returns: 0 on success, -1 on failure
1636 * This function is called to update the priority list of networks in the
1637 * configuration when a network is being added or removed. This is also called
1638 * if a priority for a network is changed.
1640 int wpa_config_update_prio_list(struct wpa_config *config)
1642 struct wpa_ssid *ssid;
1645 os_free(config->pssid);
1646 config->pssid = NULL;
1647 config->num_prio = 0;
1649 ssid = config->ssid;
1652 if (wpa_config_add_prio_network(config, ssid) < 0)
1661 #ifdef IEEE8021X_EAPOL
1662 static void eap_peer_config_free(struct eap_peer_config *eap)
1664 os_free(eap->eap_methods);
1665 os_free(eap->identity);
1666 os_free(eap->anonymous_identity);
1667 os_free(eap->password);
1668 os_free(eap->ca_cert);
1669 os_free(eap->ca_path);
1670 os_free(eap->client_cert);
1671 os_free(eap->private_key);
1672 os_free(eap->private_key_passwd);
1673 os_free(eap->dh_file);
1674 os_free(eap->subject_match);
1675 os_free(eap->altsubject_match);
1676 os_free(eap->ca_cert2);
1677 os_free(eap->ca_path2);
1678 os_free(eap->client_cert2);
1679 os_free(eap->private_key2);
1680 os_free(eap->private_key2_passwd);
1681 os_free(eap->dh_file2);
1682 os_free(eap->subject_match2);
1683 os_free(eap->altsubject_match2);
1684 os_free(eap->phase1);
1685 os_free(eap->phase2);
1688 os_free(eap->engine_id);
1689 os_free(eap->key_id);
1690 os_free(eap->cert_id);
1691 os_free(eap->ca_cert_id);
1692 os_free(eap->key2_id);
1693 os_free(eap->cert2_id);
1694 os_free(eap->ca_cert2_id);
1696 os_free(eap->engine2_id);
1698 os_free(eap->pending_req_otp);
1699 os_free(eap->pac_file);
1700 os_free(eap->new_password);
1702 #endif /* IEEE8021X_EAPOL */
1706 * wpa_config_free_ssid - Free network/ssid configuration data
1707 * @ssid: Configuration data for the network
1709 * This function frees all resources allocated for the network configuration
1712 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1714 os_free(ssid->ssid);
1715 os_free(ssid->passphrase);
1716 os_free(ssid->ext_psk);
1717 #ifdef IEEE8021X_EAPOL
1718 eap_peer_config_free(&ssid->eap);
1719 #endif /* IEEE8021X_EAPOL */
1720 os_free(ssid->id_str);
1721 os_free(ssid->scan_freq);
1722 os_free(ssid->freq_list);
1723 os_free(ssid->bgscan);
1724 os_free(ssid->p2p_client_list);
1725 #ifdef CONFIG_HT_OVERRIDES
1726 os_free(ssid->ht_mcs);
1727 #endif /* CONFIG_HT_OVERRIDES */
1732 void wpa_config_free_cred(struct wpa_cred *cred)
1734 os_free(cred->realm);
1735 os_free(cred->username);
1736 os_free(cred->password);
1737 os_free(cred->ca_cert);
1738 os_free(cred->client_cert);
1739 os_free(cred->private_key);
1740 os_free(cred->private_key_passwd);
1741 os_free(cred->imsi);
1742 os_free(cred->milenage);
1743 os_free(cred->domain);
1744 os_free(cred->eap_method);
1745 os_free(cred->phase1);
1746 os_free(cred->phase2);
1747 os_free(cred->excluded_ssid);
1753 * wpa_config_free - Free configuration data
1754 * @config: Configuration data from wpa_config_read()
1756 * This function frees all resources allocated for the configuration data by
1757 * wpa_config_read().
1759 void wpa_config_free(struct wpa_config *config)
1761 #ifndef CONFIG_NO_CONFIG_BLOBS
1762 struct wpa_config_blob *blob, *prevblob;
1763 #endif /* CONFIG_NO_CONFIG_BLOBS */
1764 struct wpa_ssid *ssid, *prev = NULL;
1765 struct wpa_cred *cred, *cprev;
1767 ssid = config->ssid;
1771 wpa_config_free_ssid(prev);
1774 cred = config->cred;
1778 wpa_config_free_cred(cprev);
1781 #ifndef CONFIG_NO_CONFIG_BLOBS
1782 blob = config->blobs;
1787 wpa_config_free_blob(prevblob);
1789 #endif /* CONFIG_NO_CONFIG_BLOBS */
1791 wpabuf_free(config->wps_vendor_ext_m1);
1792 os_free(config->ctrl_interface);
1793 os_free(config->ctrl_interface_group);
1794 os_free(config->opensc_engine_path);
1795 os_free(config->pkcs11_engine_path);
1796 os_free(config->pkcs11_module_path);
1797 os_free(config->pcsc_reader);
1798 os_free(config->pcsc_pin);
1799 os_free(config->driver_param);
1800 os_free(config->device_name);
1801 os_free(config->manufacturer);
1802 os_free(config->model_name);
1803 os_free(config->model_number);
1804 os_free(config->serial_number);
1805 os_free(config->config_methods);
1806 os_free(config->p2p_ssid_postfix);
1807 os_free(config->pssid);
1808 os_free(config->p2p_pref_chan);
1809 os_free(config->autoscan);
1810 wpabuf_free(config->wps_nfc_dh_pubkey);
1811 wpabuf_free(config->wps_nfc_dh_privkey);
1812 wpabuf_free(config->wps_nfc_dev_pw);
1813 os_free(config->ext_password_backend);
1814 os_free(config->sae_groups);
1820 * wpa_config_foreach_network - Iterate over each configured network
1821 * @config: Configuration data from wpa_config_read()
1822 * @func: Callback function to process each network
1823 * @arg: Opaque argument to pass to callback function
1825 * Iterate over the set of configured networks calling the specified
1826 * function for each item. We guard against callbacks removing the
1829 void wpa_config_foreach_network(struct wpa_config *config,
1830 void (*func)(void *, struct wpa_ssid *),
1833 struct wpa_ssid *ssid, *next;
1835 ssid = config->ssid;
1845 * wpa_config_get_network - Get configured network based on id
1846 * @config: Configuration data from wpa_config_read()
1847 * @id: Unique network id to search for
1848 * Returns: Network configuration or %NULL if not found
1850 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
1852 struct wpa_ssid *ssid;
1854 ssid = config->ssid;
1866 * wpa_config_add_network - Add a new network with empty configuration
1867 * @config: Configuration data from wpa_config_read()
1868 * Returns: The new network configuration or %NULL if operation failed
1870 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
1873 struct wpa_ssid *ssid, *last = NULL;
1876 ssid = config->ssid;
1885 ssid = os_zalloc(sizeof(*ssid));
1892 config->ssid = ssid;
1894 wpa_config_update_prio_list(config);
1901 * wpa_config_remove_network - Remove a configured network based on id
1902 * @config: Configuration data from wpa_config_read()
1903 * @id: Unique network id to search for
1904 * Returns: 0 on success, or -1 if the network was not found
1906 int wpa_config_remove_network(struct wpa_config *config, int id)
1908 struct wpa_ssid *ssid, *prev = NULL;
1910 ssid = config->ssid;
1922 prev->next = ssid->next;
1924 config->ssid = ssid->next;
1926 wpa_config_update_prio_list(config);
1927 wpa_config_free_ssid(ssid);
1933 * wpa_config_set_network_defaults - Set network default values
1934 * @ssid: Pointer to network configuration data
1936 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
1938 ssid->proto = DEFAULT_PROTO;
1939 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
1940 ssid->group_cipher = DEFAULT_GROUP;
1941 ssid->key_mgmt = DEFAULT_KEY_MGMT;
1942 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
1943 #ifdef IEEE8021X_EAPOL
1944 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
1945 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
1946 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
1947 #endif /* IEEE8021X_EAPOL */
1948 #ifdef CONFIG_HT_OVERRIDES
1949 ssid->disable_ht = DEFAULT_DISABLE_HT;
1950 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
1951 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
1952 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
1953 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
1954 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
1955 #endif /* CONFIG_HT_OVERRIDES */
1956 ssid->proactive_key_caching = -1;
1957 #ifdef CONFIG_IEEE80211W
1958 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
1959 #endif /* CONFIG_IEEE80211W */
1964 * wpa_config_set - Set a variable in network configuration
1965 * @ssid: Pointer to network configuration data
1966 * @var: Variable name, e.g., "ssid"
1967 * @value: Variable value
1968 * @line: Line number in configuration file or 0 if not used
1969 * Returns: 0 on success, -1 on failure
1971 * This function can be used to set network configuration variables based on
1972 * both the configuration file and management interface input. The value
1973 * parameter must be in the same format as the text-based configuration file is
1974 * using. For example, strings are using double quotation marks.
1976 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
1982 if (ssid == NULL || var == NULL || value == NULL)
1985 for (i = 0; i < NUM_SSID_FIELDS; i++) {
1986 const struct parse_data *field = &ssid_fields[i];
1987 if (os_strcmp(var, field->name) != 0)
1990 if (field->parser(field, ssid, line, value)) {
1992 wpa_printf(MSG_ERROR, "Line %d: failed to "
1993 "parse %s '%s'.", line, var, value);
1999 if (i == NUM_SSID_FIELDS) {
2001 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2002 "'%s'.", line, var);
2011 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2018 len = os_strlen(value);
2019 buf = os_malloc(len + 3);
2023 os_memcpy(buf + 1, value, len);
2025 buf[len + 2] = '\0';
2026 ret = wpa_config_set(ssid, var, buf, 0);
2033 * wpa_config_get_all - Get all options from network configuration
2034 * @ssid: Pointer to network configuration data
2035 * @get_keys: Determines if keys/passwords will be included in returned list
2036 * (if they may be exported)
2037 * Returns: %NULL terminated list of all set keys and their values in the form
2038 * of [key1, val1, key2, val2, ... , NULL]
2040 * This function can be used to get list of all configured network properties.
2041 * The caller is responsible for freeing the returned list and all its
2044 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2046 const struct parse_data *field;
2052 get_keys = get_keys && ssid->export_keys;
2054 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2059 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2060 field = &ssid_fields[i];
2061 if (field->key_data && !get_keys)
2063 value = field->writer(field, ssid);
2066 if (os_strlen(value) == 0) {
2071 key = os_strdup(field->name);
2077 props[fields_num * 2] = key;
2078 props[fields_num * 2 + 1] = value;
2094 #ifndef NO_CONFIG_WRITE
2096 * wpa_config_get - Get a variable in network configuration
2097 * @ssid: Pointer to network configuration data
2098 * @var: Variable name, e.g., "ssid"
2099 * Returns: Value of the variable or %NULL on failure
2101 * This function can be used to get network configuration variables. The
2102 * returned value is a copy of the configuration variable in text format, i.e,.
2103 * the same format that the text-based configuration file and wpa_config_set()
2104 * are using for the value. The caller is responsible for freeing the returned
2107 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2111 if (ssid == NULL || var == NULL)
2114 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2115 const struct parse_data *field = &ssid_fields[i];
2116 if (os_strcmp(var, field->name) == 0)
2117 return field->writer(field, ssid);
2125 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2126 * @ssid: Pointer to network configuration data
2127 * @var: Variable name, e.g., "ssid"
2128 * Returns: Value of the variable or %NULL on failure
2130 * This function can be used to get network configuration variable like
2131 * wpa_config_get(). The only difference is that this functions does not expose
2132 * key/password material from the configuration. In case a key/password field
2133 * is requested, the returned value is an empty string or %NULL if the variable
2134 * is not set or "*" if the variable is set (regardless of its value). The
2135 * returned value is a copy of the configuration variable in text format, i.e,.
2136 * the same format that the text-based configuration file and wpa_config_set()
2137 * are using for the value. The caller is responsible for freeing the returned
2140 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2144 if (ssid == NULL || var == NULL)
2147 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2148 const struct parse_data *field = &ssid_fields[i];
2149 if (os_strcmp(var, field->name) == 0) {
2150 char *res = field->writer(field, ssid);
2151 if (field->key_data) {
2152 if (res && res[0]) {
2153 wpa_printf(MSG_DEBUG, "Do not allow "
2154 "key_data field to be "
2157 return os_strdup("*");
2169 #endif /* NO_CONFIG_WRITE */
2173 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2174 * @ssid: Pointer to network configuration data
2176 * This function must be called to update WPA PSK when either SSID or the
2177 * passphrase has changed for the network configuration.
2179 void wpa_config_update_psk(struct wpa_ssid *ssid)
2181 #ifndef CONFIG_NO_PBKDF2
2182 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2183 ssid->psk, PMK_LEN);
2184 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2185 ssid->psk, PMK_LEN);
2187 #endif /* CONFIG_NO_PBKDF2 */
2191 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2192 const char *value, int line)
2197 if (os_strcmp(var, "priority") == 0) {
2198 cred->priority = atoi(value);
2202 if (os_strcmp(var, "pcsc") == 0) {
2203 cred->pcsc = atoi(value);
2207 if (os_strcmp(var, "eap") == 0) {
2208 struct eap_method_type method;
2209 method.method = eap_peer_get_type(value, &method.vendor);
2210 if (method.vendor == EAP_VENDOR_IETF &&
2211 method.method == EAP_TYPE_NONE) {
2212 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2213 "for a credential", line, value);
2216 os_free(cred->eap_method);
2217 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2218 if (cred->eap_method == NULL)
2220 os_memcpy(cred->eap_method, &method, sizeof(method));
2224 if (os_strcmp(var, "password") == 0 &&
2225 os_strncmp(value, "ext:", 4) == 0) {
2226 os_free(cred->password);
2227 cred->password = os_strdup(value);
2228 cred->ext_password = 1;
2232 val = wpa_config_parse_string(value, &len);
2234 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2235 "value '%s'.", line, var, value);
2239 if (os_strcmp(var, "realm") == 0) {
2240 os_free(cred->realm);
2245 if (os_strcmp(var, "username") == 0) {
2246 os_free(cred->username);
2247 cred->username = val;
2251 if (os_strcmp(var, "password") == 0) {
2252 os_free(cred->password);
2253 cred->password = val;
2254 cred->ext_password = 0;
2258 if (os_strcmp(var, "ca_cert") == 0) {
2259 os_free(cred->ca_cert);
2260 cred->ca_cert = val;
2264 if (os_strcmp(var, "client_cert") == 0) {
2265 os_free(cred->client_cert);
2266 cred->client_cert = val;
2270 if (os_strcmp(var, "private_key") == 0) {
2271 os_free(cred->private_key);
2272 cred->private_key = val;
2276 if (os_strcmp(var, "private_key_passwd") == 0) {
2277 os_free(cred->private_key_passwd);
2278 cred->private_key_passwd = val;
2282 if (os_strcmp(var, "imsi") == 0) {
2283 os_free(cred->imsi);
2288 if (os_strcmp(var, "milenage") == 0) {
2289 os_free(cred->milenage);
2290 cred->milenage = val;
2294 if (os_strcmp(var, "domain") == 0) {
2295 os_free(cred->domain);
2300 if (os_strcmp(var, "phase1") == 0) {
2301 os_free(cred->phase1);
2306 if (os_strcmp(var, "phase2") == 0) {
2307 os_free(cred->phase2);
2312 if (os_strcmp(var, "roaming_consortium") == 0) {
2313 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2314 wpa_printf(MSG_ERROR, "Line %d: invalid "
2315 "roaming_consortium length %d (3..15 "
2316 "expected)", line, (int) len);
2320 os_memcpy(cred->roaming_consortium, val, len);
2321 cred->roaming_consortium_len = len;
2326 if (os_strcmp(var, "excluded_ssid") == 0) {
2327 struct excluded_ssid *e;
2329 if (len > MAX_SSID_LEN) {
2330 wpa_printf(MSG_ERROR, "Line %d: invalid "
2331 "excluded_ssid length %d", line, (int) len);
2336 e = os_realloc_array(cred->excluded_ssid,
2337 cred->num_excluded_ssid + 1,
2338 sizeof(struct excluded_ssid));
2343 cred->excluded_ssid = e;
2345 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2346 os_memcpy(e->ssid, val, len);
2355 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2365 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
2367 struct wpa_cred *cred;
2369 cred = config->cred;
2380 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
2383 struct wpa_cred *cred, *last = NULL;
2386 cred = config->cred;
2395 cred = os_zalloc(sizeof(*cred));
2402 config->cred = cred;
2408 int wpa_config_remove_cred(struct wpa_config *config, int id)
2410 struct wpa_cred *cred, *prev = NULL;
2412 cred = config->cred;
2424 prev->next = cred->next;
2426 config->cred = cred->next;
2428 wpa_config_free_cred(cred);
2433 #ifndef CONFIG_NO_CONFIG_BLOBS
2435 * wpa_config_get_blob - Get a named configuration blob
2436 * @config: Configuration data from wpa_config_read()
2437 * @name: Name of the blob
2438 * Returns: Pointer to blob data or %NULL if not found
2440 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
2443 struct wpa_config_blob *blob = config->blobs;
2446 if (os_strcmp(blob->name, name) == 0)
2455 * wpa_config_set_blob - Set or add a named configuration blob
2456 * @config: Configuration data from wpa_config_read()
2457 * @blob: New value for the blob
2459 * Adds a new configuration blob or replaces the current value of an existing
2462 void wpa_config_set_blob(struct wpa_config *config,
2463 struct wpa_config_blob *blob)
2465 wpa_config_remove_blob(config, blob->name);
2466 blob->next = config->blobs;
2467 config->blobs = blob;
2472 * wpa_config_free_blob - Free blob data
2473 * @blob: Pointer to blob to be freed
2475 void wpa_config_free_blob(struct wpa_config_blob *blob)
2478 os_free(blob->name);
2479 os_free(blob->data);
2486 * wpa_config_remove_blob - Remove a named configuration blob
2487 * @config: Configuration data from wpa_config_read()
2488 * @name: Name of the blob to remove
2489 * Returns: 0 if blob was removed or -1 if blob was not found
2491 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
2493 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
2496 if (os_strcmp(pos->name, name) == 0) {
2498 prev->next = pos->next;
2500 config->blobs = pos->next;
2501 wpa_config_free_blob(pos);
2510 #endif /* CONFIG_NO_CONFIG_BLOBS */
2514 * wpa_config_alloc_empty - Allocate an empty configuration
2515 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
2517 * @driver_param: Driver parameters
2518 * Returns: Pointer to allocated configuration data or %NULL on failure
2520 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
2521 const char *driver_param)
2523 struct wpa_config *config;
2524 const int aCWmin = 4, aCWmax = 10;
2525 const struct hostapd_wmm_ac_params ac_bk =
2526 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
2527 const struct hostapd_wmm_ac_params ac_be =
2528 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
2529 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
2530 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
2531 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
2532 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
2534 config = os_zalloc(sizeof(*config));
2537 config->eapol_version = DEFAULT_EAPOL_VERSION;
2538 config->ap_scan = DEFAULT_AP_SCAN;
2539 config->fast_reauth = DEFAULT_FAST_REAUTH;
2540 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
2541 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
2542 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
2543 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
2544 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
2545 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
2546 config->max_num_sta = DEFAULT_MAX_NUM_STA;
2547 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
2548 config->wmm_ac_params[0] = ac_be;
2549 config->wmm_ac_params[1] = ac_bk;
2550 config->wmm_ac_params[2] = ac_vi;
2551 config->wmm_ac_params[3] = ac_vo;
2554 config->ctrl_interface = os_strdup(ctrl_interface);
2556 config->driver_param = os_strdup(driver_param);
2562 #ifndef CONFIG_NO_STDOUT_DEBUG
2564 * wpa_config_debug_dump_networks - Debug dump of configured networks
2565 * @config: Configuration data from wpa_config_read()
2567 void wpa_config_debug_dump_networks(struct wpa_config *config)
2570 struct wpa_ssid *ssid;
2572 for (prio = 0; prio < config->num_prio; prio++) {
2573 ssid = config->pssid[prio];
2574 wpa_printf(MSG_DEBUG, "Priority group %d",
2577 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
2579 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2584 #endif /* CONFIG_NO_STDOUT_DEBUG */
2587 struct global_parse_data {
2589 int (*parser)(const struct global_parse_data *data,
2590 struct wpa_config *config, int line, const char *value);
2591 void *param1, *param2, *param3;
2592 unsigned int changed_flag;
2596 static int wpa_global_config_parse_int(const struct global_parse_data *data,
2597 struct wpa_config *config, int line,
2603 dst = (int *) (((u8 *) config) + (long) data->param1);
2604 val = strtol(pos, &end, 0);
2606 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
2612 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
2614 if (data->param2 && *dst < (long) data->param2) {
2615 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
2616 "min_value=%ld)", line, data->name, *dst,
2617 (long) data->param2);
2618 *dst = (long) data->param2;
2622 if (data->param3 && *dst > (long) data->param3) {
2623 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
2624 "max_value=%ld)", line, data->name, *dst,
2625 (long) data->param3);
2626 *dst = (long) data->param3;
2634 static int wpa_global_config_parse_str(const struct global_parse_data *data,
2635 struct wpa_config *config, int line,
2641 len = os_strlen(pos);
2642 if (data->param2 && len < (size_t) data->param2) {
2643 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
2644 "min_len=%ld)", line, data->name,
2645 (unsigned long) len, (long) data->param2);
2649 if (data->param3 && len > (size_t) data->param3) {
2650 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
2651 "max_len=%ld)", line, data->name,
2652 (unsigned long) len, (long) data->param3);
2656 tmp = os_strdup(pos);
2660 dst = (char **) (((u8 *) config) + (long) data->param1);
2663 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
2669 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
2670 struct wpa_config *config, int line,
2674 struct wpabuf **dst, *tmp;
2676 len = os_strlen(pos);
2680 tmp = wpabuf_alloc(len / 2);
2684 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
2689 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
2692 wpa_printf(MSG_DEBUG, "%s", data->name);
2698 static int wpa_config_process_country(const struct global_parse_data *data,
2699 struct wpa_config *config, int line,
2702 if (!pos[0] || !pos[1]) {
2703 wpa_printf(MSG_DEBUG, "Invalid country set");
2706 config->country[0] = pos[0];
2707 config->country[1] = pos[1];
2708 wpa_printf(MSG_DEBUG, "country='%c%c'",
2709 config->country[0], config->country[1]);
2714 static int wpa_config_process_load_dynamic_eap(
2715 const struct global_parse_data *data, struct wpa_config *config,
2716 int line, const char *so)
2719 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
2720 ret = eap_peer_method_load(so);
2722 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
2725 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
2726 "method '%s'.", line, so);
2736 static int wpa_config_process_uuid(const struct global_parse_data *data,
2737 struct wpa_config *config, int line,
2741 if (uuid_str2bin(pos, config->uuid)) {
2742 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
2745 uuid_bin2str(config->uuid, buf, sizeof(buf));
2746 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
2751 static int wpa_config_process_device_type(
2752 const struct global_parse_data *data,
2753 struct wpa_config *config, int line, const char *pos)
2755 return wps_dev_type_str2bin(pos, config->device_type);
2759 static int wpa_config_process_os_version(const struct global_parse_data *data,
2760 struct wpa_config *config, int line,
2763 if (hexstr2bin(pos, config->os_version, 4)) {
2764 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
2767 wpa_printf(MSG_DEBUG, "os_version=%08x",
2768 WPA_GET_BE32(config->os_version));
2773 static int wpa_config_process_wps_vendor_ext_m1(
2774 const struct global_parse_data *data,
2775 struct wpa_config *config, int line, const char *pos)
2778 int len = os_strlen(pos) / 2;
2782 wpa_printf(MSG_ERROR, "Line %d: "
2783 "invalid wps_vendor_ext_m1", line);
2787 tmp = wpabuf_alloc(len);
2789 p = wpabuf_put(tmp, len);
2791 if (hexstr2bin(pos, p, len)) {
2792 wpa_printf(MSG_ERROR, "Line %d: "
2793 "invalid wps_vendor_ext_m1", line);
2798 wpabuf_free(config->wps_vendor_ext_m1);
2799 config->wps_vendor_ext_m1 = tmp;
2801 wpa_printf(MSG_ERROR, "Can not allocate "
2802 "memory for wps_vendor_ext_m1");
2809 #endif /* CONFIG_WPS */
2812 static int wpa_config_process_sec_device_type(
2813 const struct global_parse_data *data,
2814 struct wpa_config *config, int line, const char *pos)
2818 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
2819 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
2824 idx = config->num_sec_device_types;
2826 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
2829 config->num_sec_device_types++;
2834 static int wpa_config_process_p2p_pref_chan(
2835 const struct global_parse_data *data,
2836 struct wpa_config *config, int line, const char *pos)
2838 struct p2p_channel *pref = NULL, *n;
2839 unsigned int num = 0;
2843 /* format: class:chan,class:chan,... */
2846 op_class = atoi(pos);
2847 pos2 = os_strchr(pos, ':');
2853 n = os_realloc_array(pref, num + 1,
2854 sizeof(struct p2p_channel));
2858 pref[num].op_class = op_class;
2859 pref[num].chan = chan;
2862 pos = os_strchr(pos2, ',');
2868 os_free(config->p2p_pref_chan);
2869 config->p2p_pref_chan = pref;
2870 config->num_p2p_pref_chan = num;
2871 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
2872 (u8 *) config->p2p_pref_chan,
2873 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
2879 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
2882 #endif /* CONFIG_P2P */
2885 static int wpa_config_process_hessid(
2886 const struct global_parse_data *data,
2887 struct wpa_config *config, int line, const char *pos)
2889 if (hwaddr_aton2(pos, config->hessid) < 0) {
2890 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
2899 static int wpa_config_process_sae_groups(
2900 const struct global_parse_data *data,
2901 struct wpa_config *config, int line, const char *pos)
2903 int *groups = wpa_config_parse_int_array(pos);
2904 if (groups == NULL) {
2905 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
2910 os_free(config->sae_groups);
2911 config->sae_groups = groups;
2920 /* OFFSET: Get offset of a variable within the wpa_config structure */
2921 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
2923 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
2924 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
2925 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
2926 #define INT(f) _INT(f), NULL, NULL
2927 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
2928 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
2929 #define STR(f) _STR(f), NULL, NULL
2930 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
2931 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
2933 static const struct global_parse_data global_fields[] = {
2934 #ifdef CONFIG_CTRL_IFACE
2935 { STR(ctrl_interface), 0 },
2936 { STR(ctrl_interface_group), 0 } /* deprecated */,
2937 #endif /* CONFIG_CTRL_IFACE */
2938 { INT_RANGE(eapol_version, 1, 2), 0 },
2939 { INT(ap_scan), 0 },
2940 { INT(disable_scan_offload), 0 },
2941 { INT(fast_reauth), 0 },
2942 { STR(opensc_engine_path), 0 },
2943 { STR(pkcs11_engine_path), 0 },
2944 { STR(pkcs11_module_path), 0 },
2945 { STR(pcsc_reader), 0 },
2946 { STR(pcsc_pin), 0 },
2947 { STR(driver_param), 0 },
2948 { INT(dot11RSNAConfigPMKLifetime), 0 },
2949 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
2950 { INT(dot11RSNAConfigSATimeout), 0 },
2951 #ifndef CONFIG_NO_CONFIG_WRITE
2952 { INT(update_config), 0 },
2953 #endif /* CONFIG_NO_CONFIG_WRITE */
2954 { FUNC_NO_VAR(load_dynamic_eap), 0 },
2956 { FUNC(uuid), CFG_CHANGED_UUID },
2957 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
2958 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
2959 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
2960 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
2961 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
2962 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
2963 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
2964 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
2965 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
2966 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
2967 #endif /* CONFIG_WPS */
2969 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
2970 { INT(p2p_listen_reg_class), 0 },
2971 { INT(p2p_listen_channel), 0 },
2972 { INT(p2p_oper_reg_class), 0 },
2973 { INT(p2p_oper_channel), 0 },
2974 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
2975 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
2976 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
2977 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
2978 { INT(p2p_group_idle), 0 },
2979 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
2980 { INT(p2p_go_ht40), 0 },
2981 { INT(p2p_disabled), 0 },
2982 { INT(p2p_no_group_iface), 0 },
2983 #endif /* CONFIG_P2P */
2984 { FUNC(country), CFG_CHANGED_COUNTRY },
2985 { INT(bss_max_count), 0 },
2986 { INT(bss_expiration_age), 0 },
2987 { INT(bss_expiration_scan_count), 0 },
2988 { INT_RANGE(filter_ssids, 0, 1), 0 },
2989 { INT_RANGE(filter_rssi, -100, 0), 0 },
2990 { INT(max_num_sta), 0 },
2991 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
2993 { INT_RANGE(hs20, 0, 1), 0 },
2994 #endif /* CONFIG_HS20 */
2995 { INT_RANGE(interworking, 0, 1), 0 },
2996 { FUNC(hessid), 0 },
2997 { INT_RANGE(access_network_type, 0, 15), 0 },
2998 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
2999 { STR(autoscan), 0 },
3000 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3001 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3002 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3003 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3004 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3005 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3006 { INT(p2p_go_max_inactivity), 0 },
3007 { INT_RANGE(auto_interworking, 0, 1), 0 },
3010 { FUNC(sae_groups), 0 },
3011 { INT(dtim_period), 0 },
3012 { INT(beacon_int), 0 },
3023 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
3026 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3031 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3032 const struct global_parse_data *field = &global_fields[i];
3033 size_t flen = os_strlen(field->name);
3034 if (os_strncmp(pos, field->name, flen) != 0 ||
3038 if (field->parser(field, config, line, pos + flen + 1)) {
3039 wpa_printf(MSG_ERROR, "Line %d: failed to "
3040 "parse '%s'.", line, pos);
3043 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
3044 config->wps_nfc_pw_from_config = 1;
3045 config->changed_parameters |= field->changed_flag;
3048 if (i == NUM_GLOBAL_FIELDS) {
3050 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
3051 char *tmp = os_strchr(pos, '=');
3055 wpa_printf(MSG_ERROR, "Line %d: invalid line "
3060 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
3062 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
3067 #endif /* CONFIG_AP */
3070 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",