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 "utils/ip_addr.h"
14 #include "crypto/sha1.h"
15 #include "rsn_supp/wpa.h"
16 #include "eap_peer/eap.h"
21 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
22 #define NO_CONFIG_WRITE
26 * Structure for network configuration parsing. This data is used to implement
27 * a generic parser for each network block variable. The table of configuration
28 * variables is defined below in this file (ssid_fields[]).
31 /* Configuration variable name */
34 /* Parser function for this variable */
35 int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
36 int line, const char *value);
38 #ifndef NO_CONFIG_WRITE
39 /* Writer function (i.e., to get the variable in text format from
40 * internal presentation). */
41 char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
42 #endif /* NO_CONFIG_WRITE */
44 /* Variable specific parameters for the parser. */
45 void *param1, *param2, *param3, *param4;
47 /* 0 = this variable can be included in debug output and ctrl_iface
48 * 1 = this variable contains key/private data and it must not be
49 * included in debug output unless explicitly requested. In
50 * addition, this variable will not be readable through the
57 static int wpa_config_parse_str(const struct parse_data *data,
58 struct wpa_ssid *ssid,
59 int line, const char *value)
61 size_t res_len, *dst_len;
64 if (os_strcmp(value, "NULL") == 0) {
65 wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
72 tmp = wpa_config_parse_string(value, &res_len);
74 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
76 data->key_data ? "[KEY DATA REMOVED]" : value);
81 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
84 wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
88 if (data->param3 && res_len < (size_t) data->param3) {
89 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
90 "min_len=%ld)", line, data->name,
91 (unsigned long) res_len, (long) data->param3);
96 if (data->param4 && res_len > (size_t) data->param4) {
97 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
98 "max_len=%ld)", line, data->name,
99 (unsigned long) res_len, (long) data->param4);
105 dst = (char **) (((u8 *) ssid) + (long) data->param1);
106 dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
116 #ifndef NO_CONFIG_WRITE
117 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
121 buf = os_malloc(len + 3);
125 os_memcpy(buf + 1, value, len);
133 static char * wpa_config_write_string_hex(const u8 *value, size_t len)
137 buf = os_zalloc(2 * len + 1);
140 wpa_snprintf_hex(buf, 2 * len + 1, value, len);
146 static char * wpa_config_write_string(const u8 *value, size_t len)
151 if (is_hex(value, len))
152 return wpa_config_write_string_hex(value, len);
154 return wpa_config_write_string_ascii(value, len);
158 static char * wpa_config_write_str(const struct parse_data *data,
159 struct wpa_ssid *ssid)
164 src = (char **) (((u8 *) ssid) + (long) data->param1);
169 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
171 len = os_strlen(*src);
173 return wpa_config_write_string((const u8 *) *src, len);
175 #endif /* NO_CONFIG_WRITE */
178 static int wpa_config_parse_int(const struct parse_data *data,
179 struct wpa_ssid *ssid,
180 int line, const char *value)
185 dst = (int *) (((u8 *) ssid) + (long) data->param1);
186 val = strtol(value, &end, 0);
188 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
193 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
195 if (data->param3 && *dst < (long) data->param3) {
196 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
197 "min_value=%ld)", line, data->name, *dst,
198 (long) data->param3);
199 *dst = (long) data->param3;
203 if (data->param4 && *dst > (long) data->param4) {
204 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
205 "max_value=%ld)", line, data->name, *dst,
206 (long) data->param4);
207 *dst = (long) data->param4;
215 #ifndef NO_CONFIG_WRITE
216 static char * wpa_config_write_int(const struct parse_data *data,
217 struct wpa_ssid *ssid)
222 src = (int *) (((u8 *) ssid) + (long) data->param1);
224 value = os_malloc(20);
227 res = os_snprintf(value, 20, "%d", *src);
228 if (res < 0 || res >= 20) {
232 value[20 - 1] = '\0';
235 #endif /* NO_CONFIG_WRITE */
238 static int wpa_config_parse_bssid(const struct parse_data *data,
239 struct wpa_ssid *ssid, int line,
242 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
243 os_strcmp(value, "any") == 0) {
245 wpa_printf(MSG_MSGDUMP, "BSSID any");
248 if (hwaddr_aton(value, ssid->bssid)) {
249 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
254 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
259 #ifndef NO_CONFIG_WRITE
260 static char * wpa_config_write_bssid(const struct parse_data *data,
261 struct wpa_ssid *ssid)
266 if (!ssid->bssid_set)
269 value = os_malloc(20);
272 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
273 if (res < 0 || res >= 20) {
277 value[20 - 1] = '\0';
280 #endif /* NO_CONFIG_WRITE */
283 static int wpa_config_parse_psk(const struct parse_data *data,
284 struct wpa_ssid *ssid, int line,
287 #ifdef CONFIG_EXT_PASSWORD
288 if (os_strncmp(value, "ext:", 4) == 0) {
289 os_free(ssid->passphrase);
290 ssid->passphrase = NULL;
292 os_free(ssid->ext_psk);
293 ssid->ext_psk = os_strdup(value + 4);
294 if (ssid->ext_psk == NULL)
296 wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
300 #endif /* CONFIG_EXT_PASSWORD */
303 #ifndef CONFIG_NO_PBKDF2
308 pos = os_strrchr(value, '"');
312 len = os_strlen(value);
313 if (len < 8 || len > 63) {
314 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
315 "length %lu (expected: 8..63) '%s'.",
316 line, (unsigned long) len, value);
319 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
321 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
322 os_memcmp(ssid->passphrase, value, len) == 0)
325 os_free(ssid->passphrase);
326 ssid->passphrase = dup_binstr(value, len);
327 if (ssid->passphrase == NULL)
330 #else /* CONFIG_NO_PBKDF2 */
331 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
334 #endif /* CONFIG_NO_PBKDF2 */
337 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
338 value[PMK_LEN * 2] != '\0') {
339 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
344 os_free(ssid->passphrase);
345 ssid->passphrase = NULL;
348 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
353 #ifndef NO_CONFIG_WRITE
354 static char * wpa_config_write_psk(const struct parse_data *data,
355 struct wpa_ssid *ssid)
357 #ifdef CONFIG_EXT_PASSWORD
359 size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
360 char *buf = os_malloc(len);
363 os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
366 #endif /* CONFIG_EXT_PASSWORD */
368 if (ssid->passphrase)
369 return wpa_config_write_string_ascii(
370 (const u8 *) ssid->passphrase,
371 os_strlen(ssid->passphrase));
374 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
378 #endif /* NO_CONFIG_WRITE */
381 static int wpa_config_parse_proto(const struct parse_data *data,
382 struct wpa_ssid *ssid, int line,
385 int val = 0, last, errors = 0;
386 char *start, *end, *buf;
388 buf = os_strdup(value);
393 while (*start != '\0') {
394 while (*start == ' ' || *start == '\t')
399 while (*end != ' ' && *end != '\t' && *end != '\0')
403 if (os_strcmp(start, "WPA") == 0)
404 val |= WPA_PROTO_WPA;
405 else if (os_strcmp(start, "RSN") == 0 ||
406 os_strcmp(start, "WPA2") == 0)
407 val |= WPA_PROTO_RSN;
408 else if (os_strcmp(start, "OSEN") == 0)
409 val |= WPA_PROTO_OSEN;
411 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
423 wpa_printf(MSG_ERROR,
424 "Line %d: no proto values configured.", line);
428 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
430 return errors ? -1 : 0;
434 #ifndef NO_CONFIG_WRITE
435 static char * wpa_config_write_proto(const struct parse_data *data,
436 struct wpa_ssid *ssid)
439 char *buf, *pos, *end;
441 pos = buf = os_zalloc(20);
446 if (ssid->proto & WPA_PROTO_WPA) {
447 ret = os_snprintf(pos, end - pos, "%sWPA",
448 pos == buf ? "" : " ");
449 if (ret < 0 || ret >= end - pos)
454 if (ssid->proto & WPA_PROTO_RSN) {
455 ret = os_snprintf(pos, end - pos, "%sRSN",
456 pos == buf ? "" : " ");
457 if (ret < 0 || ret >= end - pos)
462 if (ssid->proto & WPA_PROTO_OSEN) {
463 ret = os_snprintf(pos, end - pos, "%sOSEN",
464 pos == buf ? "" : " ");
465 if (ret < 0 || ret >= end - pos)
472 #endif /* NO_CONFIG_WRITE */
475 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
476 struct wpa_ssid *ssid, int line,
479 int val = 0, last, errors = 0;
480 char *start, *end, *buf;
482 buf = os_strdup(value);
487 while (*start != '\0') {
488 while (*start == ' ' || *start == '\t')
493 while (*end != ' ' && *end != '\t' && *end != '\0')
497 if (os_strcmp(start, "WPA-PSK") == 0)
498 val |= WPA_KEY_MGMT_PSK;
499 else if (os_strcmp(start, "WPA-EAP") == 0)
500 val |= WPA_KEY_MGMT_IEEE8021X;
501 else if (os_strcmp(start, "IEEE8021X") == 0)
502 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
503 else if (os_strcmp(start, "NONE") == 0)
504 val |= WPA_KEY_MGMT_NONE;
505 else if (os_strcmp(start, "WPA-NONE") == 0)
506 val |= WPA_KEY_MGMT_WPA_NONE;
507 #ifdef CONFIG_IEEE80211R
508 else if (os_strcmp(start, "FT-PSK") == 0)
509 val |= WPA_KEY_MGMT_FT_PSK;
510 else if (os_strcmp(start, "FT-EAP") == 0)
511 val |= WPA_KEY_MGMT_FT_IEEE8021X;
512 #endif /* CONFIG_IEEE80211R */
513 #ifdef CONFIG_IEEE80211W
514 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
515 val |= WPA_KEY_MGMT_PSK_SHA256;
516 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
517 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
518 #endif /* CONFIG_IEEE80211W */
520 else if (os_strcmp(start, "WPS") == 0)
521 val |= WPA_KEY_MGMT_WPS;
522 #endif /* CONFIG_WPS */
524 else if (os_strcmp(start, "SAE") == 0)
525 val |= WPA_KEY_MGMT_SAE;
526 else if (os_strcmp(start, "FT-SAE") == 0)
527 val |= WPA_KEY_MGMT_FT_SAE;
528 #endif /* CONFIG_SAE */
530 else if (os_strcmp(start, "OSEN") == 0)
531 val |= WPA_KEY_MGMT_OSEN;
532 #endif /* CONFIG_HS20 */
534 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
546 wpa_printf(MSG_ERROR,
547 "Line %d: no key_mgmt values configured.", line);
551 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
552 ssid->key_mgmt = val;
553 return errors ? -1 : 0;
557 #ifndef NO_CONFIG_WRITE
558 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
559 struct wpa_ssid *ssid)
561 char *buf, *pos, *end;
564 pos = buf = os_zalloc(100);
569 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
570 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
571 pos == buf ? "" : " ");
572 if (ret < 0 || ret >= end - pos) {
579 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
580 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
581 pos == buf ? "" : " ");
582 if (ret < 0 || ret >= end - pos) {
589 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
590 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
591 pos == buf ? "" : " ");
592 if (ret < 0 || ret >= end - pos) {
599 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
600 ret = os_snprintf(pos, end - pos, "%sNONE",
601 pos == buf ? "" : " ");
602 if (ret < 0 || ret >= end - pos) {
609 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
610 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
611 pos == buf ? "" : " ");
612 if (ret < 0 || ret >= end - pos) {
619 #ifdef CONFIG_IEEE80211R
620 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
621 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
622 pos == buf ? "" : " ");
623 if (ret < 0 || ret >= end - pos) {
630 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
631 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
632 pos == buf ? "" : " ");
633 if (ret < 0 || ret >= end - pos) {
639 #endif /* CONFIG_IEEE80211R */
641 #ifdef CONFIG_IEEE80211W
642 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
643 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
644 pos == buf ? "" : " ");
645 if (ret < 0 || ret >= end - pos) {
652 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
653 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
654 pos == buf ? "" : " ");
655 if (ret < 0 || ret >= end - pos) {
661 #endif /* CONFIG_IEEE80211W */
664 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
665 ret = os_snprintf(pos, end - pos, "%sWPS",
666 pos == buf ? "" : " ");
667 if (ret < 0 || ret >= end - pos) {
673 #endif /* CONFIG_WPS */
677 #endif /* NO_CONFIG_WRITE */
680 static int wpa_config_parse_cipher(int line, const char *value)
682 int val = wpa_parse_cipher(value);
684 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
689 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
697 #ifndef NO_CONFIG_WRITE
698 static char * wpa_config_write_cipher(int cipher)
700 char *buf = os_zalloc(50);
704 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
711 #endif /* NO_CONFIG_WRITE */
714 static int wpa_config_parse_pairwise(const struct parse_data *data,
715 struct wpa_ssid *ssid, int line,
719 val = wpa_config_parse_cipher(line, value);
722 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
723 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
724 "(0x%x).", line, val);
728 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
729 ssid->pairwise_cipher = val;
734 #ifndef NO_CONFIG_WRITE
735 static char * wpa_config_write_pairwise(const struct parse_data *data,
736 struct wpa_ssid *ssid)
738 return wpa_config_write_cipher(ssid->pairwise_cipher);
740 #endif /* NO_CONFIG_WRITE */
743 static int wpa_config_parse_group(const struct parse_data *data,
744 struct wpa_ssid *ssid, int line,
748 val = wpa_config_parse_cipher(line, value);
751 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
752 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
753 "(0x%x).", line, val);
757 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
758 ssid->group_cipher = val;
763 #ifndef NO_CONFIG_WRITE
764 static char * wpa_config_write_group(const struct parse_data *data,
765 struct wpa_ssid *ssid)
767 return wpa_config_write_cipher(ssid->group_cipher);
769 #endif /* NO_CONFIG_WRITE */
772 static int wpa_config_parse_auth_alg(const struct parse_data *data,
773 struct wpa_ssid *ssid, int line,
776 int val = 0, last, errors = 0;
777 char *start, *end, *buf;
779 buf = os_strdup(value);
784 while (*start != '\0') {
785 while (*start == ' ' || *start == '\t')
790 while (*end != ' ' && *end != '\t' && *end != '\0')
794 if (os_strcmp(start, "OPEN") == 0)
795 val |= WPA_AUTH_ALG_OPEN;
796 else if (os_strcmp(start, "SHARED") == 0)
797 val |= WPA_AUTH_ALG_SHARED;
798 else if (os_strcmp(start, "LEAP") == 0)
799 val |= WPA_AUTH_ALG_LEAP;
801 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
813 wpa_printf(MSG_ERROR,
814 "Line %d: no auth_alg values configured.", line);
818 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
819 ssid->auth_alg = val;
820 return errors ? -1 : 0;
824 #ifndef NO_CONFIG_WRITE
825 static char * wpa_config_write_auth_alg(const struct parse_data *data,
826 struct wpa_ssid *ssid)
828 char *buf, *pos, *end;
831 pos = buf = os_zalloc(30);
836 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
837 ret = os_snprintf(pos, end - pos, "%sOPEN",
838 pos == buf ? "" : " ");
839 if (ret < 0 || ret >= end - pos) {
846 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
847 ret = os_snprintf(pos, end - pos, "%sSHARED",
848 pos == buf ? "" : " ");
849 if (ret < 0 || ret >= end - pos) {
856 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
857 ret = os_snprintf(pos, end - pos, "%sLEAP",
858 pos == buf ? "" : " ");
859 if (ret < 0 || ret >= end - pos) {
868 #endif /* NO_CONFIG_WRITE */
871 static int * wpa_config_parse_int_array(const char *value)
879 freqs = os_calloc(len + 1, sizeof(int));
890 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
895 for (i = len; i <= len * 2; i++)
901 freqs[used] = atoi(pos);
902 if (freqs[used] == 0)
905 pos = os_strchr(pos + 1, ' ');
912 static int wpa_config_parse_scan_freq(const struct parse_data *data,
913 struct wpa_ssid *ssid, int line,
918 freqs = wpa_config_parse_int_array(value);
925 os_free(ssid->scan_freq);
926 ssid->scan_freq = freqs;
932 static int wpa_config_parse_freq_list(const struct parse_data *data,
933 struct wpa_ssid *ssid, int line,
938 freqs = wpa_config_parse_int_array(value);
945 os_free(ssid->freq_list);
946 ssid->freq_list = freqs;
952 #ifndef NO_CONFIG_WRITE
953 static char * wpa_config_write_freqs(const struct parse_data *data,
956 char *buf, *pos, *end;
964 for (i = 0; freqs[i]; i++)
967 pos = buf = os_zalloc(10 * count + 1);
970 end = buf + 10 * count + 1;
972 for (i = 0; freqs[i]; i++) {
973 ret = os_snprintf(pos, end - pos, "%s%u",
974 i == 0 ? "" : " ", freqs[i]);
975 if (ret < 0 || ret >= end - pos) {
986 static char * wpa_config_write_scan_freq(const struct parse_data *data,
987 struct wpa_ssid *ssid)
989 return wpa_config_write_freqs(data, ssid->scan_freq);
993 static char * wpa_config_write_freq_list(const struct parse_data *data,
994 struct wpa_ssid *ssid)
996 return wpa_config_write_freqs(data, ssid->freq_list);
998 #endif /* NO_CONFIG_WRITE */
1001 #ifdef IEEE8021X_EAPOL
1002 static int wpa_config_parse_eap(const struct parse_data *data,
1003 struct wpa_ssid *ssid, int line,
1006 int last, errors = 0;
1007 char *start, *end, *buf;
1008 struct eap_method_type *methods = NULL, *tmp;
1009 size_t num_methods = 0;
1011 buf = os_strdup(value);
1016 while (*start != '\0') {
1017 while (*start == ' ' || *start == '\t')
1022 while (*end != ' ' && *end != '\t' && *end != '\0')
1024 last = *end == '\0';
1027 methods = os_realloc_array(methods, num_methods + 1,
1029 if (methods == NULL) {
1034 methods[num_methods].method = eap_peer_get_type(
1035 start, &methods[num_methods].vendor);
1036 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1037 methods[num_methods].method == EAP_TYPE_NONE) {
1038 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1039 "'%s'", line, start);
1040 wpa_printf(MSG_ERROR, "You may need to add support for"
1041 " this EAP method during wpa_supplicant\n"
1042 "build time configuration.\n"
1043 "See README for more information.");
1045 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1046 methods[num_methods].method == EAP_TYPE_LEAP)
1058 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1059 if (methods == NULL) {
1063 methods[num_methods].vendor = EAP_VENDOR_IETF;
1064 methods[num_methods].method = EAP_TYPE_NONE;
1067 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1068 (u8 *) methods, num_methods * sizeof(*methods));
1069 os_free(ssid->eap.eap_methods);
1070 ssid->eap.eap_methods = methods;
1071 return errors ? -1 : 0;
1075 static char * wpa_config_write_eap(const struct parse_data *data,
1076 struct wpa_ssid *ssid)
1079 char *buf, *pos, *end;
1080 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1083 if (eap_methods == NULL)
1086 pos = buf = os_zalloc(100);
1091 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1092 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1093 name = eap_get_name(eap_methods[i].vendor,
1094 eap_methods[i].method);
1096 ret = os_snprintf(pos, end - pos, "%s%s",
1097 pos == buf ? "" : " ", name);
1098 if (ret < 0 || ret >= end - pos)
1110 static int wpa_config_parse_password(const struct parse_data *data,
1111 struct wpa_ssid *ssid, int line,
1116 if (os_strcmp(value, "NULL") == 0) {
1117 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1118 os_free(ssid->eap.password);
1119 ssid->eap.password = NULL;
1120 ssid->eap.password_len = 0;
1124 #ifdef CONFIG_EXT_PASSWORD
1125 if (os_strncmp(value, "ext:", 4) == 0) {
1126 char *name = os_strdup(value + 4);
1129 os_free(ssid->eap.password);
1130 ssid->eap.password = (u8 *) name;
1131 ssid->eap.password_len = os_strlen(name);
1132 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1133 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1136 #endif /* CONFIG_EXT_PASSWORD */
1138 if (os_strncmp(value, "hash:", 5) != 0) {
1142 tmp = wpa_config_parse_string(value, &res_len);
1144 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1148 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1149 (u8 *) tmp, res_len);
1151 os_free(ssid->eap.password);
1152 ssid->eap.password = (u8 *) tmp;
1153 ssid->eap.password_len = res_len;
1154 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1155 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1161 /* NtPasswordHash: hash:<32 hex digits> */
1162 if (os_strlen(value + 5) != 2 * 16) {
1163 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1164 "(expected 32 hex digits)", line);
1168 hash = os_malloc(16);
1172 if (hexstr2bin(value + 5, hash, 16)) {
1174 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1178 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1180 os_free(ssid->eap.password);
1181 ssid->eap.password = hash;
1182 ssid->eap.password_len = 16;
1183 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1184 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1190 static char * wpa_config_write_password(const struct parse_data *data,
1191 struct wpa_ssid *ssid)
1195 if (ssid->eap.password == NULL)
1198 #ifdef CONFIG_EXT_PASSWORD
1199 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1200 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1203 os_memcpy(buf, "ext:", 4);
1204 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1207 #endif /* CONFIG_EXT_PASSWORD */
1209 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1210 return wpa_config_write_string(
1211 ssid->eap.password, ssid->eap.password_len);
1214 buf = os_malloc(5 + 32 + 1);
1218 os_memcpy(buf, "hash:", 5);
1219 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1223 #endif /* IEEE8021X_EAPOL */
1226 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1227 const char *value, int idx)
1229 char *buf, title[20];
1232 buf = wpa_config_parse_string(value, len);
1234 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1238 if (*len > MAX_WEP_KEY_LEN) {
1239 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1244 if (*len && *len != 5 && *len != 13 && *len != 16) {
1245 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1246 "this network block will be ignored",
1247 line, (unsigned int) *len);
1249 os_memcpy(key, buf, *len);
1251 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1252 if (res >= 0 && (size_t) res < sizeof(title))
1253 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1258 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1259 struct wpa_ssid *ssid, int line,
1262 return wpa_config_parse_wep_key(ssid->wep_key[0],
1263 &ssid->wep_key_len[0], line,
1268 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1269 struct wpa_ssid *ssid, int line,
1272 return wpa_config_parse_wep_key(ssid->wep_key[1],
1273 &ssid->wep_key_len[1], line,
1278 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1279 struct wpa_ssid *ssid, int line,
1282 return wpa_config_parse_wep_key(ssid->wep_key[2],
1283 &ssid->wep_key_len[2], line,
1288 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1289 struct wpa_ssid *ssid, int line,
1292 return wpa_config_parse_wep_key(ssid->wep_key[3],
1293 &ssid->wep_key_len[3], line,
1298 #ifndef NO_CONFIG_WRITE
1299 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1301 if (ssid->wep_key_len[idx] == 0)
1303 return wpa_config_write_string(ssid->wep_key[idx],
1304 ssid->wep_key_len[idx]);
1308 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1309 struct wpa_ssid *ssid)
1311 return wpa_config_write_wep_key(ssid, 0);
1315 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1316 struct wpa_ssid *ssid)
1318 return wpa_config_write_wep_key(ssid, 1);
1322 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1323 struct wpa_ssid *ssid)
1325 return wpa_config_write_wep_key(ssid, 2);
1329 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1330 struct wpa_ssid *ssid)
1332 return wpa_config_write_wep_key(ssid, 3);
1334 #endif /* NO_CONFIG_WRITE */
1339 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1340 struct wpa_ssid *ssid, int line,
1343 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1344 os_strcmp(value, "any") == 0) {
1345 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1346 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1349 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1350 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1354 ssid->bssid_set = 1;
1355 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1356 MAC2STR(ssid->go_p2p_dev_addr));
1361 #ifndef NO_CONFIG_WRITE
1362 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1363 struct wpa_ssid *ssid)
1368 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1371 value = os_malloc(20);
1374 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1375 if (res < 0 || res >= 20) {
1379 value[20 - 1] = '\0';
1382 #endif /* NO_CONFIG_WRITE */
1385 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1386 struct wpa_ssid *ssid, int line,
1390 u8 *buf, *n, addr[ETH_ALEN];
1397 while (pos && *pos) {
1401 if (hwaddr_aton(pos, addr)) {
1403 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1404 "p2p_client_list address '%s'.",
1409 /* continue anyway since this could have been from a
1410 * truncated configuration file line */
1411 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1412 "truncated p2p_client_list address '%s'",
1415 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1421 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1422 os_memcpy(buf, addr, ETH_ALEN);
1424 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1428 pos = os_strchr(pos, ' ');
1431 os_free(ssid->p2p_client_list);
1432 ssid->p2p_client_list = buf;
1433 ssid->num_p2p_clients = count;
1439 #ifndef NO_CONFIG_WRITE
1440 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1441 struct wpa_ssid *ssid)
1443 char *value, *end, *pos;
1447 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1450 value = os_malloc(20 * ssid->num_p2p_clients);
1454 end = value + 20 * ssid->num_p2p_clients;
1456 for (i = ssid->num_p2p_clients; i > 0; i--) {
1457 res = os_snprintf(pos, end - pos, MACSTR " ",
1458 MAC2STR(ssid->p2p_client_list +
1459 (i - 1) * ETH_ALEN));
1460 if (res < 0 || res >= end - pos) {
1472 #endif /* NO_CONFIG_WRITE */
1475 static int wpa_config_parse_psk_list(const struct parse_data *data,
1476 struct wpa_ssid *ssid, int line,
1479 struct psk_list_entry *p;
1482 p = os_zalloc(sizeof(*p));
1487 if (os_strncmp(pos, "P2P-", 4) == 0) {
1492 if (hwaddr_aton(pos, p->addr)) {
1493 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1500 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1507 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1508 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1514 dl_list_add(&ssid->psk_list, &p->list);
1520 #ifndef NO_CONFIG_WRITE
1521 static char * wpa_config_write_psk_list(const struct parse_data *data,
1522 struct wpa_ssid *ssid)
1526 #endif /* NO_CONFIG_WRITE */
1528 #endif /* CONFIG_P2P */
1530 /* Helper macros for network block parser */
1535 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1536 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1538 /* STR: Define a string variable for an ASCII string; f = field name */
1539 #ifdef NO_CONFIG_WRITE
1540 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1541 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1542 #else /* NO_CONFIG_WRITE */
1543 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1544 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1545 #endif /* NO_CONFIG_WRITE */
1546 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1547 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1548 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1549 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1551 /* STR_LEN: Define a string variable with a separate variable for storing the
1552 * data length. Unlike STR(), this can be used to store arbitrary binary data
1553 * (i.e., even nul termination character). */
1554 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1555 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1556 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1557 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1558 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1560 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1561 * explicitly specified. */
1562 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1563 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1564 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1566 #ifdef NO_CONFIG_WRITE
1567 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1568 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1569 #else /* NO_CONFIG_WRITE */
1570 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1571 OFFSET(f), (void *) 0
1572 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1573 OFFSET(eap.f), (void *) 0
1574 #endif /* NO_CONFIG_WRITE */
1576 /* INT: Define an integer variable */
1577 #define INT(f) _INT(f), NULL, NULL, 0
1578 #define INTe(f) _INTe(f), NULL, NULL, 0
1580 /* INT_RANGE: Define an integer variable with allowed value range */
1581 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1583 /* FUNC: Define a configuration variable that uses a custom function for
1584 * parsing and writing the value. */
1585 #ifdef NO_CONFIG_WRITE
1586 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1587 #else /* NO_CONFIG_WRITE */
1588 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1589 NULL, NULL, NULL, NULL
1590 #endif /* NO_CONFIG_WRITE */
1591 #define FUNC(f) _FUNC(f), 0
1592 #define FUNC_KEY(f) _FUNC(f), 1
1595 * Table of network configuration variables. This table is used to parse each
1596 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1597 * that is inside a network block.
1599 * This table is generated using the helper macros defined above and with
1600 * generous help from the C pre-processor. The field name is stored as a string
1601 * into .name and for STR and INT types, the offset of the target buffer within
1602 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1603 * offset to the field containing the length of the configuration variable.
1604 * .param3 and .param4 can be used to mark the allowed range (length for STR
1605 * and value for INT).
1607 * For each configuration line in wpa_supplicant.conf, the parser goes through
1608 * this table and select the entry that matches with the field name. The parser
1609 * function (.parser) is then called to parse the actual value of the field.
1611 * This kind of mechanism makes it easy to add new configuration parameters,
1612 * since only one line needs to be added into this table and into the
1613 * struct wpa_ssid definition if the new variable is either a string or
1614 * integer. More complex types will need to use their own parser and writer
1617 static const struct parse_data ssid_fields[] = {
1618 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1619 { INT_RANGE(scan_ssid, 0, 1) },
1624 { INT(bg_scan_period) },
1628 { FUNC(scan_freq) },
1629 { FUNC(freq_list) },
1630 #ifdef IEEE8021X_EAPOL
1632 { STR_LENe(identity) },
1633 { STR_LENe(anonymous_identity) },
1634 { FUNC_KEY(password) },
1637 { STRe(client_cert) },
1638 { STRe(private_key) },
1639 { STR_KEYe(private_key_passwd) },
1641 { STRe(subject_match) },
1642 { STRe(altsubject_match) },
1643 { STRe(domain_suffix_match) },
1646 { STRe(client_cert2) },
1647 { STRe(private_key2) },
1648 { STR_KEYe(private_key2_passwd) },
1650 { STRe(subject_match2) },
1651 { STRe(altsubject_match2) },
1652 { STRe(domain_suffix_match2) },
1657 { STRe(engine_id) },
1660 { STRe(ca_cert_id) },
1662 { STRe(engine2_id) },
1665 { STRe(ca_cert2_id) },
1668 { INT(eapol_flags) },
1670 #endif /* IEEE8021X_EAPOL */
1671 { FUNC_KEY(wep_key0) },
1672 { FUNC_KEY(wep_key1) },
1673 { FUNC_KEY(wep_key2) },
1674 { FUNC_KEY(wep_key3) },
1675 { INT(wep_tx_keyidx) },
1677 #ifdef IEEE8021X_EAPOL
1678 { INT(eap_workaround) },
1680 { INTe(fragment_size) },
1682 #endif /* IEEE8021X_EAPOL */
1683 { INT_RANGE(mode, 0, 4) },
1684 { INT_RANGE(proactive_key_caching, 0, 1) },
1685 { INT_RANGE(disabled, 0, 2) },
1687 #ifdef CONFIG_IEEE80211W
1688 { INT_RANGE(ieee80211w, 0, 2) },
1689 #endif /* CONFIG_IEEE80211W */
1690 { INT_RANGE(peerkey, 0, 1) },
1691 { INT_RANGE(mixed_cell, 0, 1) },
1692 { INT_RANGE(frequency, 0, 65000) },
1693 { INT(wpa_ptk_rekey) },
1695 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1697 { FUNC(go_p2p_dev_addr) },
1698 { FUNC(p2p_client_list) },
1700 #endif /* CONFIG_P2P */
1701 #ifdef CONFIG_HT_OVERRIDES
1702 { INT_RANGE(disable_ht, 0, 1) },
1703 { INT_RANGE(disable_ht40, -1, 1) },
1704 { INT_RANGE(disable_sgi, 0, 1) },
1705 { INT_RANGE(disable_ldpc, 0, 1) },
1706 { INT_RANGE(ht40_intolerant, 0, 1) },
1707 { INT_RANGE(disable_max_amsdu, -1, 1) },
1708 { INT_RANGE(ampdu_factor, -1, 3) },
1709 { INT_RANGE(ampdu_density, -1, 7) },
1711 #endif /* CONFIG_HT_OVERRIDES */
1712 #ifdef CONFIG_VHT_OVERRIDES
1713 { INT_RANGE(disable_vht, 0, 1) },
1715 { INT(vht_capa_mask) },
1716 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1717 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1718 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1719 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1720 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1721 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1722 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1723 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1724 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1725 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1726 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1727 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1728 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1729 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1730 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1731 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1732 #endif /* CONFIG_VHT_OVERRIDES */
1733 { INT(ap_max_inactivity) },
1734 { INT(dtim_period) },
1735 { INT(beacon_int) },
1736 #ifdef CONFIG_MACSEC
1737 { INT_RANGE(macsec_policy, 0, 1) },
1738 #endif /* CONFIG_MACSEC */
1750 #undef STR_RANGE_KEY
1757 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1761 * wpa_config_add_prio_network - Add a network to priority lists
1762 * @config: Configuration data from wpa_config_read()
1763 * @ssid: Pointer to the network configuration to be added to the list
1764 * Returns: 0 on success, -1 on failure
1766 * This function is used to add a network block to the priority list of
1767 * networks. This must be called for each network when reading in the full
1768 * configuration. In addition, this can be used indirectly when updating
1769 * priorities by calling wpa_config_update_prio_list().
1771 int wpa_config_add_prio_network(struct wpa_config *config,
1772 struct wpa_ssid *ssid)
1775 struct wpa_ssid *prev, **nlist;
1778 * Add to an existing priority list if one is available for the
1779 * configured priority level for this network.
1781 for (prio = 0; prio < config->num_prio; prio++) {
1782 prev = config->pssid[prio];
1783 if (prev->priority == ssid->priority) {
1791 /* First network for this priority - add a new priority list */
1792 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1793 sizeof(struct wpa_ssid *));
1797 for (prio = 0; prio < config->num_prio; prio++) {
1798 if (nlist[prio]->priority < ssid->priority) {
1799 os_memmove(&nlist[prio + 1], &nlist[prio],
1800 (config->num_prio - prio) *
1801 sizeof(struct wpa_ssid *));
1808 config->pssid = nlist;
1815 * wpa_config_update_prio_list - Update network priority list
1816 * @config: Configuration data from wpa_config_read()
1817 * Returns: 0 on success, -1 on failure
1819 * This function is called to update the priority list of networks in the
1820 * configuration when a network is being added or removed. This is also called
1821 * if a priority for a network is changed.
1823 int wpa_config_update_prio_list(struct wpa_config *config)
1825 struct wpa_ssid *ssid;
1828 os_free(config->pssid);
1829 config->pssid = NULL;
1830 config->num_prio = 0;
1832 ssid = config->ssid;
1835 if (wpa_config_add_prio_network(config, ssid) < 0)
1844 #ifdef IEEE8021X_EAPOL
1845 static void eap_peer_config_free(struct eap_peer_config *eap)
1847 os_free(eap->eap_methods);
1848 os_free(eap->identity);
1849 os_free(eap->anonymous_identity);
1850 os_free(eap->password);
1851 os_free(eap->ca_cert);
1852 os_free(eap->ca_path);
1853 os_free(eap->client_cert);
1854 os_free(eap->private_key);
1855 os_free(eap->private_key_passwd);
1856 os_free(eap->dh_file);
1857 os_free(eap->subject_match);
1858 os_free(eap->altsubject_match);
1859 os_free(eap->domain_suffix_match);
1860 os_free(eap->ca_cert2);
1861 os_free(eap->ca_path2);
1862 os_free(eap->client_cert2);
1863 os_free(eap->private_key2);
1864 os_free(eap->private_key2_passwd);
1865 os_free(eap->dh_file2);
1866 os_free(eap->subject_match2);
1867 os_free(eap->altsubject_match2);
1868 os_free(eap->domain_suffix_match2);
1869 os_free(eap->phase1);
1870 os_free(eap->phase2);
1873 os_free(eap->engine_id);
1874 os_free(eap->key_id);
1875 os_free(eap->cert_id);
1876 os_free(eap->ca_cert_id);
1877 os_free(eap->key2_id);
1878 os_free(eap->cert2_id);
1879 os_free(eap->ca_cert2_id);
1881 os_free(eap->engine2_id);
1883 os_free(eap->pending_req_otp);
1884 os_free(eap->pac_file);
1885 os_free(eap->new_password);
1886 os_free(eap->external_sim_resp);
1888 #endif /* IEEE8021X_EAPOL */
1892 * wpa_config_free_ssid - Free network/ssid configuration data
1893 * @ssid: Configuration data for the network
1895 * This function frees all resources allocated for the network configuration
1898 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1900 struct psk_list_entry *psk;
1902 os_free(ssid->ssid);
1903 os_free(ssid->passphrase);
1904 os_free(ssid->ext_psk);
1905 #ifdef IEEE8021X_EAPOL
1906 eap_peer_config_free(&ssid->eap);
1907 #endif /* IEEE8021X_EAPOL */
1908 os_free(ssid->id_str);
1909 os_free(ssid->scan_freq);
1910 os_free(ssid->freq_list);
1911 os_free(ssid->bgscan);
1912 os_free(ssid->p2p_client_list);
1913 #ifdef CONFIG_HT_OVERRIDES
1914 os_free(ssid->ht_mcs);
1915 #endif /* CONFIG_HT_OVERRIDES */
1916 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
1918 dl_list_del(&psk->list);
1925 void wpa_config_free_cred(struct wpa_cred *cred)
1929 os_free(cred->realm);
1930 os_free(cred->username);
1931 os_free(cred->password);
1932 os_free(cred->ca_cert);
1933 os_free(cred->client_cert);
1934 os_free(cred->private_key);
1935 os_free(cred->private_key_passwd);
1936 os_free(cred->imsi);
1937 os_free(cred->milenage);
1938 for (i = 0; i < cred->num_domain; i++)
1939 os_free(cred->domain[i]);
1940 os_free(cred->domain);
1941 os_free(cred->domain_suffix_match);
1942 os_free(cred->eap_method);
1943 os_free(cred->phase1);
1944 os_free(cred->phase2);
1945 os_free(cred->excluded_ssid);
1946 os_free(cred->roaming_partner);
1947 os_free(cred->provisioning_sp);
1948 for (i = 0; i < cred->num_req_conn_capab; i++)
1949 os_free(cred->req_conn_capab_port[i]);
1950 os_free(cred->req_conn_capab_port);
1951 os_free(cred->req_conn_capab_proto);
1956 void wpa_config_flush_blobs(struct wpa_config *config)
1958 #ifndef CONFIG_NO_CONFIG_BLOBS
1959 struct wpa_config_blob *blob, *prev;
1961 blob = config->blobs;
1962 config->blobs = NULL;
1966 wpa_config_free_blob(prev);
1968 #endif /* CONFIG_NO_CONFIG_BLOBS */
1973 * wpa_config_free - Free configuration data
1974 * @config: Configuration data from wpa_config_read()
1976 * This function frees all resources allocated for the configuration data by
1977 * wpa_config_read().
1979 void wpa_config_free(struct wpa_config *config)
1981 struct wpa_ssid *ssid, *prev = NULL;
1982 struct wpa_cred *cred, *cprev;
1984 ssid = config->ssid;
1988 wpa_config_free_ssid(prev);
1991 cred = config->cred;
1995 wpa_config_free_cred(cprev);
1998 wpa_config_flush_blobs(config);
2000 wpabuf_free(config->wps_vendor_ext_m1);
2001 os_free(config->ctrl_interface);
2002 os_free(config->ctrl_interface_group);
2003 os_free(config->opensc_engine_path);
2004 os_free(config->pkcs11_engine_path);
2005 os_free(config->pkcs11_module_path);
2006 os_free(config->pcsc_reader);
2007 os_free(config->pcsc_pin);
2008 os_free(config->driver_param);
2009 os_free(config->device_name);
2010 os_free(config->manufacturer);
2011 os_free(config->model_name);
2012 os_free(config->model_number);
2013 os_free(config->serial_number);
2014 os_free(config->config_methods);
2015 os_free(config->p2p_ssid_postfix);
2016 os_free(config->pssid);
2017 os_free(config->p2p_pref_chan);
2018 os_free(config->p2p_no_go_freq.range);
2019 os_free(config->autoscan);
2020 os_free(config->freq_list);
2021 wpabuf_free(config->wps_nfc_dh_pubkey);
2022 wpabuf_free(config->wps_nfc_dh_privkey);
2023 wpabuf_free(config->wps_nfc_dev_pw);
2024 os_free(config->ext_password_backend);
2025 os_free(config->sae_groups);
2026 wpabuf_free(config->ap_vendor_elements);
2027 os_free(config->osu_dir);
2028 os_free(config->wowlan_triggers);
2034 * wpa_config_foreach_network - Iterate over each configured network
2035 * @config: Configuration data from wpa_config_read()
2036 * @func: Callback function to process each network
2037 * @arg: Opaque argument to pass to callback function
2039 * Iterate over the set of configured networks calling the specified
2040 * function for each item. We guard against callbacks removing the
2043 void wpa_config_foreach_network(struct wpa_config *config,
2044 void (*func)(void *, struct wpa_ssid *),
2047 struct wpa_ssid *ssid, *next;
2049 ssid = config->ssid;
2059 * wpa_config_get_network - Get configured network based on id
2060 * @config: Configuration data from wpa_config_read()
2061 * @id: Unique network id to search for
2062 * Returns: Network configuration or %NULL if not found
2064 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2066 struct wpa_ssid *ssid;
2068 ssid = config->ssid;
2080 * wpa_config_add_network - Add a new network with empty configuration
2081 * @config: Configuration data from wpa_config_read()
2082 * Returns: The new network configuration or %NULL if operation failed
2084 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2087 struct wpa_ssid *ssid, *last = NULL;
2090 ssid = config->ssid;
2099 ssid = os_zalloc(sizeof(*ssid));
2103 dl_list_init(&ssid->psk_list);
2107 config->ssid = ssid;
2109 wpa_config_update_prio_list(config);
2116 * wpa_config_remove_network - Remove a configured network based on id
2117 * @config: Configuration data from wpa_config_read()
2118 * @id: Unique network id to search for
2119 * Returns: 0 on success, or -1 if the network was not found
2121 int wpa_config_remove_network(struct wpa_config *config, int id)
2123 struct wpa_ssid *ssid, *prev = NULL;
2125 ssid = config->ssid;
2137 prev->next = ssid->next;
2139 config->ssid = ssid->next;
2141 wpa_config_update_prio_list(config);
2142 wpa_config_free_ssid(ssid);
2148 * wpa_config_set_network_defaults - Set network default values
2149 * @ssid: Pointer to network configuration data
2151 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2153 ssid->proto = DEFAULT_PROTO;
2154 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2155 ssid->group_cipher = DEFAULT_GROUP;
2156 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2157 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2158 #ifdef IEEE8021X_EAPOL
2159 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2160 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2161 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2162 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2163 #endif /* IEEE8021X_EAPOL */
2164 #ifdef CONFIG_HT_OVERRIDES
2165 ssid->disable_ht = DEFAULT_DISABLE_HT;
2166 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2167 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2168 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2169 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2170 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2171 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2172 #endif /* CONFIG_HT_OVERRIDES */
2173 #ifdef CONFIG_VHT_OVERRIDES
2174 ssid->vht_rx_mcs_nss_1 = -1;
2175 ssid->vht_rx_mcs_nss_2 = -1;
2176 ssid->vht_rx_mcs_nss_3 = -1;
2177 ssid->vht_rx_mcs_nss_4 = -1;
2178 ssid->vht_rx_mcs_nss_5 = -1;
2179 ssid->vht_rx_mcs_nss_6 = -1;
2180 ssid->vht_rx_mcs_nss_7 = -1;
2181 ssid->vht_rx_mcs_nss_8 = -1;
2182 ssid->vht_tx_mcs_nss_1 = -1;
2183 ssid->vht_tx_mcs_nss_2 = -1;
2184 ssid->vht_tx_mcs_nss_3 = -1;
2185 ssid->vht_tx_mcs_nss_4 = -1;
2186 ssid->vht_tx_mcs_nss_5 = -1;
2187 ssid->vht_tx_mcs_nss_6 = -1;
2188 ssid->vht_tx_mcs_nss_7 = -1;
2189 ssid->vht_tx_mcs_nss_8 = -1;
2190 #endif /* CONFIG_VHT_OVERRIDES */
2191 ssid->proactive_key_caching = -1;
2192 #ifdef CONFIG_IEEE80211W
2193 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2194 #endif /* CONFIG_IEEE80211W */
2199 * wpa_config_set - Set a variable in network configuration
2200 * @ssid: Pointer to network configuration data
2201 * @var: Variable name, e.g., "ssid"
2202 * @value: Variable value
2203 * @line: Line number in configuration file or 0 if not used
2204 * Returns: 0 on success, -1 on failure
2206 * This function can be used to set network configuration variables based on
2207 * both the configuration file and management interface input. The value
2208 * parameter must be in the same format as the text-based configuration file is
2209 * using. For example, strings are using double quotation marks.
2211 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2217 if (ssid == NULL || var == NULL || value == NULL)
2220 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2221 const struct parse_data *field = &ssid_fields[i];
2222 if (os_strcmp(var, field->name) != 0)
2225 if (field->parser(field, ssid, line, value)) {
2227 wpa_printf(MSG_ERROR, "Line %d: failed to "
2228 "parse %s '%s'.", line, var, value);
2234 if (i == NUM_SSID_FIELDS) {
2236 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2237 "'%s'.", line, var);
2246 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2253 len = os_strlen(value);
2254 buf = os_malloc(len + 3);
2258 os_memcpy(buf + 1, value, len);
2260 buf[len + 2] = '\0';
2261 ret = wpa_config_set(ssid, var, buf, 0);
2268 * wpa_config_get_all - Get all options from network configuration
2269 * @ssid: Pointer to network configuration data
2270 * @get_keys: Determines if keys/passwords will be included in returned list
2271 * (if they may be exported)
2272 * Returns: %NULL terminated list of all set keys and their values in the form
2273 * of [key1, val1, key2, val2, ... , NULL]
2275 * This function can be used to get list of all configured network properties.
2276 * The caller is responsible for freeing the returned list and all its
2279 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2281 const struct parse_data *field;
2287 get_keys = get_keys && ssid->export_keys;
2289 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2294 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2295 field = &ssid_fields[i];
2296 if (field->key_data && !get_keys)
2298 value = field->writer(field, ssid);
2301 if (os_strlen(value) == 0) {
2306 key = os_strdup(field->name);
2312 props[fields_num * 2] = key;
2313 props[fields_num * 2 + 1] = value;
2329 #ifndef NO_CONFIG_WRITE
2331 * wpa_config_get - Get a variable in network configuration
2332 * @ssid: Pointer to network configuration data
2333 * @var: Variable name, e.g., "ssid"
2334 * Returns: Value of the variable or %NULL on failure
2336 * This function can be used to get network configuration variables. The
2337 * returned value is a copy of the configuration variable in text format, i.e,.
2338 * the same format that the text-based configuration file and wpa_config_set()
2339 * are using for the value. The caller is responsible for freeing the returned
2342 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2346 if (ssid == NULL || var == NULL)
2349 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2350 const struct parse_data *field = &ssid_fields[i];
2351 if (os_strcmp(var, field->name) == 0)
2352 return field->writer(field, ssid);
2360 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2361 * @ssid: Pointer to network configuration data
2362 * @var: Variable name, e.g., "ssid"
2363 * Returns: Value of the variable or %NULL on failure
2365 * This function can be used to get network configuration variable like
2366 * wpa_config_get(). The only difference is that this functions does not expose
2367 * key/password material from the configuration. In case a key/password field
2368 * is requested, the returned value is an empty string or %NULL if the variable
2369 * is not set or "*" if the variable is set (regardless of its value). The
2370 * returned value is a copy of the configuration variable in text format, i.e,.
2371 * the same format that the text-based configuration file and wpa_config_set()
2372 * are using for the value. The caller is responsible for freeing the returned
2375 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2379 if (ssid == NULL || var == NULL)
2382 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2383 const struct parse_data *field = &ssid_fields[i];
2384 if (os_strcmp(var, field->name) == 0) {
2385 char *res = field->writer(field, ssid);
2386 if (field->key_data) {
2387 if (res && res[0]) {
2388 wpa_printf(MSG_DEBUG, "Do not allow "
2389 "key_data field to be "
2392 return os_strdup("*");
2404 #endif /* NO_CONFIG_WRITE */
2408 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2409 * @ssid: Pointer to network configuration data
2411 * This function must be called to update WPA PSK when either SSID or the
2412 * passphrase has changed for the network configuration.
2414 void wpa_config_update_psk(struct wpa_ssid *ssid)
2416 #ifndef CONFIG_NO_PBKDF2
2417 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2418 ssid->psk, PMK_LEN);
2419 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2420 ssid->psk, PMK_LEN);
2422 #endif /* CONFIG_NO_PBKDF2 */
2426 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2431 int *ports, *nports;
2433 unsigned int num_ports;
2435 proto = os_realloc_array(cred->req_conn_capab_proto,
2436 cred->num_req_conn_capab + 1, sizeof(u8));
2439 cred->req_conn_capab_proto = proto;
2441 port = os_realloc_array(cred->req_conn_capab_port,
2442 cred->num_req_conn_capab + 1, sizeof(int *));
2445 cred->req_conn_capab_port = port;
2447 proto[cred->num_req_conn_capab] = atoi(value);
2449 pos = os_strchr(value, ':');
2451 port[cred->num_req_conn_capab] = NULL;
2452 cred->num_req_conn_capab++;
2461 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2462 if (nports == NULL) {
2467 ports[num_ports++] = atoi(pos);
2469 pos = os_strchr(pos, ',');
2475 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2476 if (nports == NULL) {
2481 ports[num_ports] = -1;
2483 port[cred->num_req_conn_capab] = ports;
2484 cred->num_req_conn_capab++;
2489 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2490 const char *value, int line)
2495 if (os_strcmp(var, "temporary") == 0) {
2496 cred->temporary = atoi(value);
2500 if (os_strcmp(var, "priority") == 0) {
2501 cred->priority = atoi(value);
2505 if (os_strcmp(var, "sp_priority") == 0) {
2506 int prio = atoi(value);
2507 if (prio < 0 || prio > 255)
2509 cred->sp_priority = prio;
2513 if (os_strcmp(var, "pcsc") == 0) {
2514 cred->pcsc = atoi(value);
2518 if (os_strcmp(var, "eap") == 0) {
2519 struct eap_method_type method;
2520 method.method = eap_peer_get_type(value, &method.vendor);
2521 if (method.vendor == EAP_VENDOR_IETF &&
2522 method.method == EAP_TYPE_NONE) {
2523 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2524 "for a credential", line, value);
2527 os_free(cred->eap_method);
2528 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2529 if (cred->eap_method == NULL)
2531 os_memcpy(cred->eap_method, &method, sizeof(method));
2535 if (os_strcmp(var, "password") == 0 &&
2536 os_strncmp(value, "ext:", 4) == 0) {
2537 os_free(cred->password);
2538 cred->password = os_strdup(value);
2539 cred->ext_password = 1;
2543 if (os_strcmp(var, "update_identifier") == 0) {
2544 cred->update_identifier = atoi(value);
2548 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2549 cred->min_dl_bandwidth_home = atoi(value);
2553 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2554 cred->min_ul_bandwidth_home = atoi(value);
2558 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2559 cred->min_dl_bandwidth_roaming = atoi(value);
2563 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2564 cred->min_ul_bandwidth_roaming = atoi(value);
2568 if (os_strcmp(var, "max_bss_load") == 0) {
2569 cred->max_bss_load = atoi(value);
2573 if (os_strcmp(var, "req_conn_capab") == 0)
2574 return wpa_config_set_cred_req_conn_capab(cred, value);
2576 if (os_strcmp(var, "ocsp") == 0) {
2577 cred->ocsp = atoi(value);
2581 if (os_strcmp(var, "sim_num") == 0) {
2582 cred->sim_num = atoi(value);
2586 val = wpa_config_parse_string(value, &len);
2588 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2589 "value '%s'.", line, var, value);
2593 if (os_strcmp(var, "realm") == 0) {
2594 os_free(cred->realm);
2599 if (os_strcmp(var, "username") == 0) {
2600 os_free(cred->username);
2601 cred->username = val;
2605 if (os_strcmp(var, "password") == 0) {
2606 os_free(cred->password);
2607 cred->password = val;
2608 cred->ext_password = 0;
2612 if (os_strcmp(var, "ca_cert") == 0) {
2613 os_free(cred->ca_cert);
2614 cred->ca_cert = val;
2618 if (os_strcmp(var, "client_cert") == 0) {
2619 os_free(cred->client_cert);
2620 cred->client_cert = val;
2624 if (os_strcmp(var, "private_key") == 0) {
2625 os_free(cred->private_key);
2626 cred->private_key = val;
2630 if (os_strcmp(var, "private_key_passwd") == 0) {
2631 os_free(cred->private_key_passwd);
2632 cred->private_key_passwd = val;
2636 if (os_strcmp(var, "imsi") == 0) {
2637 os_free(cred->imsi);
2642 if (os_strcmp(var, "milenage") == 0) {
2643 os_free(cred->milenage);
2644 cred->milenage = val;
2648 if (os_strcmp(var, "domain_suffix_match") == 0) {
2649 os_free(cred->domain_suffix_match);
2650 cred->domain_suffix_match = val;
2654 if (os_strcmp(var, "domain") == 0) {
2656 new_domain = os_realloc_array(cred->domain,
2657 cred->num_domain + 1,
2659 if (new_domain == NULL) {
2663 new_domain[cred->num_domain++] = val;
2664 cred->domain = new_domain;
2668 if (os_strcmp(var, "phase1") == 0) {
2669 os_free(cred->phase1);
2674 if (os_strcmp(var, "phase2") == 0) {
2675 os_free(cred->phase2);
2680 if (os_strcmp(var, "roaming_consortium") == 0) {
2681 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2682 wpa_printf(MSG_ERROR, "Line %d: invalid "
2683 "roaming_consortium length %d (3..15 "
2684 "expected)", line, (int) len);
2688 os_memcpy(cred->roaming_consortium, val, len);
2689 cred->roaming_consortium_len = len;
2694 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2695 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2697 wpa_printf(MSG_ERROR, "Line %d: invalid "
2698 "required_roaming_consortium length %d "
2699 "(3..15 expected)", line, (int) len);
2703 os_memcpy(cred->required_roaming_consortium, val, len);
2704 cred->required_roaming_consortium_len = len;
2709 if (os_strcmp(var, "excluded_ssid") == 0) {
2710 struct excluded_ssid *e;
2712 if (len > MAX_SSID_LEN) {
2713 wpa_printf(MSG_ERROR, "Line %d: invalid "
2714 "excluded_ssid length %d", line, (int) len);
2719 e = os_realloc_array(cred->excluded_ssid,
2720 cred->num_excluded_ssid + 1,
2721 sizeof(struct excluded_ssid));
2726 cred->excluded_ssid = e;
2728 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2729 os_memcpy(e->ssid, val, len);
2737 if (os_strcmp(var, "roaming_partner") == 0) {
2738 struct roaming_partner *p;
2741 p = os_realloc_array(cred->roaming_partner,
2742 cred->num_roaming_partner + 1,
2743 sizeof(struct roaming_partner));
2748 cred->roaming_partner = p;
2750 p = &cred->roaming_partner[cred->num_roaming_partner];
2752 pos = os_strchr(val, ',');
2758 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2762 os_memcpy(p->fqdn, val, pos - val);
2764 p->exact_match = atoi(pos);
2766 pos = os_strchr(pos, ',');
2773 p->priority = atoi(pos);
2775 pos = os_strchr(pos, ',');
2782 if (os_strlen(pos) >= sizeof(p->country)) {
2786 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2788 cred->num_roaming_partner++;
2794 if (os_strcmp(var, "provisioning_sp") == 0) {
2795 os_free(cred->provisioning_sp);
2796 cred->provisioning_sp = val;
2801 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2811 char * alloc_int_str(int val)
2815 buf = os_malloc(20);
2818 os_snprintf(buf, 20, "%d", val);
2823 char * alloc_strdup(const char *str)
2827 return os_strdup(str);
2831 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2833 if (os_strcmp(var, "temporary") == 0)
2834 return alloc_int_str(cred->temporary);
2836 if (os_strcmp(var, "priority") == 0)
2837 return alloc_int_str(cred->priority);
2839 if (os_strcmp(var, "sp_priority") == 0)
2840 return alloc_int_str(cred->sp_priority);
2842 if (os_strcmp(var, "pcsc") == 0)
2843 return alloc_int_str(cred->pcsc);
2845 if (os_strcmp(var, "eap") == 0) {
2846 if (!cred->eap_method)
2848 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2849 cred->eap_method[0].method));
2852 if (os_strcmp(var, "update_identifier") == 0)
2853 return alloc_int_str(cred->update_identifier);
2855 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
2856 return alloc_int_str(cred->min_dl_bandwidth_home);
2858 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
2859 return alloc_int_str(cred->min_ul_bandwidth_home);
2861 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
2862 return alloc_int_str(cred->min_dl_bandwidth_roaming);
2864 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
2865 return alloc_int_str(cred->min_ul_bandwidth_roaming);
2867 if (os_strcmp(var, "max_bss_load") == 0)
2868 return alloc_int_str(cred->max_bss_load);
2870 if (os_strcmp(var, "req_conn_capab") == 0) {
2872 char *buf, *end, *pos;
2875 if (!cred->num_req_conn_capab)
2878 buf = os_malloc(4000);
2883 for (i = 0; i < cred->num_req_conn_capab; i++) {
2886 ret = os_snprintf(pos, end - pos, "%s%u",
2888 cred->req_conn_capab_proto[i]);
2889 if (ret < 0 || ret >= end - pos)
2893 ports = cred->req_conn_capab_port[i];
2896 for (j = 0; ports[j] != -1; j++) {
2897 ret = os_snprintf(pos, end - pos,
2901 if (ret < 0 || ret >= end - pos)
2911 if (os_strcmp(var, "ocsp") == 0)
2912 return alloc_int_str(cred->ocsp);
2914 if (os_strcmp(var, "realm") == 0)
2915 return alloc_strdup(cred->realm);
2917 if (os_strcmp(var, "username") == 0)
2918 return alloc_strdup(cred->username);
2920 if (os_strcmp(var, "password") == 0) {
2921 if (!cred->password)
2923 return alloc_strdup("*");
2926 if (os_strcmp(var, "ca_cert") == 0)
2927 return alloc_strdup(cred->ca_cert);
2929 if (os_strcmp(var, "client_cert") == 0)
2930 return alloc_strdup(cred->client_cert);
2932 if (os_strcmp(var, "private_key") == 0)
2933 return alloc_strdup(cred->private_key);
2935 if (os_strcmp(var, "private_key_passwd") == 0) {
2936 if (!cred->private_key_passwd)
2938 return alloc_strdup("*");
2941 if (os_strcmp(var, "imsi") == 0)
2942 return alloc_strdup(cred->imsi);
2944 if (os_strcmp(var, "milenage") == 0) {
2945 if (!(cred->milenage))
2947 return alloc_strdup("*");
2950 if (os_strcmp(var, "domain_suffix_match") == 0)
2951 return alloc_strdup(cred->domain_suffix_match);
2953 if (os_strcmp(var, "domain") == 0) {
2955 char *buf, *end, *pos;
2958 if (!cred->num_domain)
2961 buf = os_malloc(4000);
2967 for (i = 0; i < cred->num_domain; i++) {
2968 ret = os_snprintf(pos, end - pos, "%s%s",
2969 i > 0 ? "\n" : "", cred->domain[i]);
2970 if (ret < 0 || ret >= end - pos)
2978 if (os_strcmp(var, "phase1") == 0)
2979 return alloc_strdup(cred->phase1);
2981 if (os_strcmp(var, "phase2") == 0)
2982 return alloc_strdup(cred->phase2);
2984 if (os_strcmp(var, "roaming_consortium") == 0) {
2988 if (!cred->roaming_consortium_len)
2990 buflen = cred->roaming_consortium_len * 2 + 1;
2991 buf = os_malloc(buflen);
2994 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
2995 cred->roaming_consortium_len);
2999 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3003 if (!cred->required_roaming_consortium_len)
3005 buflen = cred->required_roaming_consortium_len * 2 + 1;
3006 buf = os_malloc(buflen);
3009 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3010 cred->required_roaming_consortium_len);
3014 if (os_strcmp(var, "excluded_ssid") == 0) {
3016 char *buf, *end, *pos;
3018 if (!cred->num_excluded_ssid)
3021 buf = os_malloc(4000);
3027 for (i = 0; i < cred->num_excluded_ssid; i++) {
3028 struct excluded_ssid *e;
3031 e = &cred->excluded_ssid[i];
3032 ret = os_snprintf(pos, end - pos, "%s%s",
3034 wpa_ssid_txt(e->ssid, e->ssid_len));
3035 if (ret < 0 || ret >= end - pos)
3043 if (os_strcmp(var, "roaming_partner") == 0) {
3045 char *buf, *end, *pos;
3047 if (!cred->num_roaming_partner)
3050 buf = os_malloc(4000);
3056 for (i = 0; i < cred->num_roaming_partner; i++) {
3057 struct roaming_partner *p;
3060 p = &cred->roaming_partner[i];
3061 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3063 p->fqdn, p->exact_match, p->priority,
3065 if (ret < 0 || ret >= end - pos)
3073 if (os_strcmp(var, "provisioning_sp") == 0)
3074 return alloc_strdup(cred->provisioning_sp);
3080 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3082 struct wpa_cred *cred;
3084 cred = config->cred;
3095 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3098 struct wpa_cred *cred, *last = NULL;
3101 cred = config->cred;
3110 cred = os_zalloc(sizeof(*cred));
3114 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3118 config->cred = cred;
3124 int wpa_config_remove_cred(struct wpa_config *config, int id)
3126 struct wpa_cred *cred, *prev = NULL;
3128 cred = config->cred;
3140 prev->next = cred->next;
3142 config->cred = cred->next;
3144 wpa_config_free_cred(cred);
3149 #ifndef CONFIG_NO_CONFIG_BLOBS
3151 * wpa_config_get_blob - Get a named configuration blob
3152 * @config: Configuration data from wpa_config_read()
3153 * @name: Name of the blob
3154 * Returns: Pointer to blob data or %NULL if not found
3156 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3159 struct wpa_config_blob *blob = config->blobs;
3162 if (os_strcmp(blob->name, name) == 0)
3171 * wpa_config_set_blob - Set or add a named configuration blob
3172 * @config: Configuration data from wpa_config_read()
3173 * @blob: New value for the blob
3175 * Adds a new configuration blob or replaces the current value of an existing
3178 void wpa_config_set_blob(struct wpa_config *config,
3179 struct wpa_config_blob *blob)
3181 wpa_config_remove_blob(config, blob->name);
3182 blob->next = config->blobs;
3183 config->blobs = blob;
3188 * wpa_config_free_blob - Free blob data
3189 * @blob: Pointer to blob to be freed
3191 void wpa_config_free_blob(struct wpa_config_blob *blob)
3194 os_free(blob->name);
3195 os_free(blob->data);
3202 * wpa_config_remove_blob - Remove a named configuration blob
3203 * @config: Configuration data from wpa_config_read()
3204 * @name: Name of the blob to remove
3205 * Returns: 0 if blob was removed or -1 if blob was not found
3207 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3209 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3212 if (os_strcmp(pos->name, name) == 0) {
3214 prev->next = pos->next;
3216 config->blobs = pos->next;
3217 wpa_config_free_blob(pos);
3226 #endif /* CONFIG_NO_CONFIG_BLOBS */
3230 * wpa_config_alloc_empty - Allocate an empty configuration
3231 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3233 * @driver_param: Driver parameters
3234 * Returns: Pointer to allocated configuration data or %NULL on failure
3236 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3237 const char *driver_param)
3239 struct wpa_config *config;
3240 const int aCWmin = 4, aCWmax = 10;
3241 const struct hostapd_wmm_ac_params ac_bk =
3242 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3243 const struct hostapd_wmm_ac_params ac_be =
3244 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3245 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3246 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3247 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3248 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3250 config = os_zalloc(sizeof(*config));
3253 config->eapol_version = DEFAULT_EAPOL_VERSION;
3254 config->ap_scan = DEFAULT_AP_SCAN;
3255 config->fast_reauth = DEFAULT_FAST_REAUTH;
3256 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3257 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3258 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3259 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3260 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3261 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3262 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3263 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3264 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3265 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3266 config->wmm_ac_params[0] = ac_be;
3267 config->wmm_ac_params[1] = ac_bk;
3268 config->wmm_ac_params[2] = ac_vi;
3269 config->wmm_ac_params[3] = ac_vo;
3270 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3273 config->ctrl_interface = os_strdup(ctrl_interface);
3275 config->driver_param = os_strdup(driver_param);
3281 #ifndef CONFIG_NO_STDOUT_DEBUG
3283 * wpa_config_debug_dump_networks - Debug dump of configured networks
3284 * @config: Configuration data from wpa_config_read()
3286 void wpa_config_debug_dump_networks(struct wpa_config *config)
3289 struct wpa_ssid *ssid;
3291 for (prio = 0; prio < config->num_prio; prio++) {
3292 ssid = config->pssid[prio];
3293 wpa_printf(MSG_DEBUG, "Priority group %d",
3296 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3298 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3303 #endif /* CONFIG_NO_STDOUT_DEBUG */
3306 struct global_parse_data {
3308 int (*parser)(const struct global_parse_data *data,
3309 struct wpa_config *config, int line, const char *value);
3310 void *param1, *param2, *param3;
3311 unsigned int changed_flag;
3315 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3316 struct wpa_config *config, int line,
3322 dst = (int *) (((u8 *) config) + (long) data->param1);
3323 val = strtol(pos, &end, 0);
3325 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3331 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3333 if (data->param2 && *dst < (long) data->param2) {
3334 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3335 "min_value=%ld)", line, data->name, *dst,
3336 (long) data->param2);
3337 *dst = (long) data->param2;
3341 if (data->param3 && *dst > (long) data->param3) {
3342 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3343 "max_value=%ld)", line, data->name, *dst,
3344 (long) data->param3);
3345 *dst = (long) data->param3;
3353 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3354 struct wpa_config *config, int line,
3360 len = os_strlen(pos);
3361 if (data->param2 && len < (size_t) data->param2) {
3362 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3363 "min_len=%ld)", line, data->name,
3364 (unsigned long) len, (long) data->param2);
3368 if (data->param3 && len > (size_t) data->param3) {
3369 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3370 "max_len=%ld)", line, data->name,
3371 (unsigned long) len, (long) data->param3);
3375 tmp = os_strdup(pos);
3379 dst = (char **) (((u8 *) config) + (long) data->param1);
3382 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3388 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3389 struct wpa_config *config, int line,
3396 tmp = wpa_config_parse_string(pos, &len);
3398 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3403 res = wpa_global_config_parse_str(data, config, line, tmp);
3409 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3410 struct wpa_config *config, int line,
3414 struct wpabuf **dst, *tmp;
3416 len = os_strlen(pos);
3420 tmp = wpabuf_alloc(len / 2);
3424 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3429 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3432 wpa_printf(MSG_DEBUG, "%s", data->name);
3438 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3439 struct wpa_config *config, int line,
3444 freqs = wpa_config_parse_int_array(value);
3447 if (freqs[0] == 0) {
3451 os_free(config->freq_list);
3452 config->freq_list = freqs;
3458 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3459 struct wpa_config *config, int line,
3463 struct hostapd_ip_addr addr;
3465 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3467 if (addr.af != AF_INET)
3470 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3471 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3472 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3473 WPA_GET_BE32((u8 *) dst));
3477 #endif /* CONFIG_P2P */
3480 static int wpa_config_process_country(const struct global_parse_data *data,
3481 struct wpa_config *config, int line,
3484 if (!pos[0] || !pos[1]) {
3485 wpa_printf(MSG_DEBUG, "Invalid country set");
3488 config->country[0] = pos[0];
3489 config->country[1] = pos[1];
3490 wpa_printf(MSG_DEBUG, "country='%c%c'",
3491 config->country[0], config->country[1]);
3496 static int wpa_config_process_load_dynamic_eap(
3497 const struct global_parse_data *data, struct wpa_config *config,
3498 int line, const char *so)
3501 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3502 ret = eap_peer_method_load(so);
3504 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3507 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3508 "method '%s'.", line, so);
3518 static int wpa_config_process_uuid(const struct global_parse_data *data,
3519 struct wpa_config *config, int line,
3523 if (uuid_str2bin(pos, config->uuid)) {
3524 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3527 uuid_bin2str(config->uuid, buf, sizeof(buf));
3528 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3533 static int wpa_config_process_device_type(
3534 const struct global_parse_data *data,
3535 struct wpa_config *config, int line, const char *pos)
3537 return wps_dev_type_str2bin(pos, config->device_type);
3541 static int wpa_config_process_os_version(const struct global_parse_data *data,
3542 struct wpa_config *config, int line,
3545 if (hexstr2bin(pos, config->os_version, 4)) {
3546 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3549 wpa_printf(MSG_DEBUG, "os_version=%08x",
3550 WPA_GET_BE32(config->os_version));
3555 static int wpa_config_process_wps_vendor_ext_m1(
3556 const struct global_parse_data *data,
3557 struct wpa_config *config, int line, const char *pos)
3560 int len = os_strlen(pos) / 2;
3564 wpa_printf(MSG_ERROR, "Line %d: "
3565 "invalid wps_vendor_ext_m1", line);
3569 tmp = wpabuf_alloc(len);
3571 p = wpabuf_put(tmp, len);
3573 if (hexstr2bin(pos, p, len)) {
3574 wpa_printf(MSG_ERROR, "Line %d: "
3575 "invalid wps_vendor_ext_m1", line);
3580 wpabuf_free(config->wps_vendor_ext_m1);
3581 config->wps_vendor_ext_m1 = tmp;
3583 wpa_printf(MSG_ERROR, "Can not allocate "
3584 "memory for wps_vendor_ext_m1");
3591 #endif /* CONFIG_WPS */
3594 static int wpa_config_process_sec_device_type(
3595 const struct global_parse_data *data,
3596 struct wpa_config *config, int line, const char *pos)
3600 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3601 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3606 idx = config->num_sec_device_types;
3608 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3611 config->num_sec_device_types++;
3616 static int wpa_config_process_p2p_pref_chan(
3617 const struct global_parse_data *data,
3618 struct wpa_config *config, int line, const char *pos)
3620 struct p2p_channel *pref = NULL, *n;
3621 unsigned int num = 0;
3625 /* format: class:chan,class:chan,... */
3628 op_class = atoi(pos);
3629 pos2 = os_strchr(pos, ':');
3635 n = os_realloc_array(pref, num + 1,
3636 sizeof(struct p2p_channel));
3640 pref[num].op_class = op_class;
3641 pref[num].chan = chan;
3644 pos = os_strchr(pos2, ',');
3650 os_free(config->p2p_pref_chan);
3651 config->p2p_pref_chan = pref;
3652 config->num_p2p_pref_chan = num;
3653 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3654 (u8 *) config->p2p_pref_chan,
3655 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3661 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3666 static int wpa_config_process_p2p_no_go_freq(
3667 const struct global_parse_data *data,
3668 struct wpa_config *config, int line, const char *pos)
3672 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3674 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3678 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3679 config->p2p_no_go_freq.num);
3684 #endif /* CONFIG_P2P */
3687 static int wpa_config_process_hessid(
3688 const struct global_parse_data *data,
3689 struct wpa_config *config, int line, const char *pos)
3691 if (hwaddr_aton2(pos, config->hessid) < 0) {
3692 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3701 static int wpa_config_process_sae_groups(
3702 const struct global_parse_data *data,
3703 struct wpa_config *config, int line, const char *pos)
3705 int *groups = wpa_config_parse_int_array(pos);
3706 if (groups == NULL) {
3707 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3712 os_free(config->sae_groups);
3713 config->sae_groups = groups;
3719 static int wpa_config_process_ap_vendor_elements(
3720 const struct global_parse_data *data,
3721 struct wpa_config *config, int line, const char *pos)
3724 int len = os_strlen(pos) / 2;
3728 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3733 tmp = wpabuf_alloc(len);
3735 p = wpabuf_put(tmp, len);
3737 if (hexstr2bin(pos, p, len)) {
3738 wpa_printf(MSG_ERROR, "Line %d: invalid "
3739 "ap_vendor_elements", line);
3744 wpabuf_free(config->ap_vendor_elements);
3745 config->ap_vendor_elements = tmp;
3747 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3748 "ap_vendor_elements");
3756 #ifdef CONFIG_CTRL_IFACE
3757 static int wpa_config_process_no_ctrl_interface(
3758 const struct global_parse_data *data,
3759 struct wpa_config *config, int line, const char *pos)
3761 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3762 os_free(config->ctrl_interface);
3763 config->ctrl_interface = NULL;
3766 #endif /* CONFIG_CTRL_IFACE */
3772 /* OFFSET: Get offset of a variable within the wpa_config structure */
3773 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3775 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3776 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3777 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3778 #define INT(f) _INT(f), NULL, NULL
3779 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3780 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3781 #define STR(f) _STR(f), NULL, NULL
3782 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3783 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3784 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3786 static const struct global_parse_data global_fields[] = {
3787 #ifdef CONFIG_CTRL_IFACE
3788 { STR(ctrl_interface), 0 },
3789 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3790 { STR(ctrl_interface_group), 0 } /* deprecated */,
3791 #endif /* CONFIG_CTRL_IFACE */
3792 #ifdef CONFIG_MACSEC
3793 { INT_RANGE(eapol_version, 1, 3), 0 },
3794 #else /* CONFIG_MACSEC */
3795 { INT_RANGE(eapol_version, 1, 2), 0 },
3796 #endif /* CONFIG_MACSEC */
3797 { INT(ap_scan), 0 },
3798 { FUNC(bgscan), 0 },
3799 { INT(disable_scan_offload), 0 },
3800 { INT(fast_reauth), 0 },
3801 { STR(opensc_engine_path), 0 },
3802 { STR(pkcs11_engine_path), 0 },
3803 { STR(pkcs11_module_path), 0 },
3804 { STR(pcsc_reader), 0 },
3805 { STR(pcsc_pin), 0 },
3806 { INT(external_sim), 0 },
3807 { STR(driver_param), 0 },
3808 { INT(dot11RSNAConfigPMKLifetime), 0 },
3809 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3810 { INT(dot11RSNAConfigSATimeout), 0 },
3811 #ifndef CONFIG_NO_CONFIG_WRITE
3812 { INT(update_config), 0 },
3813 #endif /* CONFIG_NO_CONFIG_WRITE */
3814 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3816 { FUNC(uuid), CFG_CHANGED_UUID },
3817 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3818 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3819 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3820 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3821 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3822 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3823 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3824 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3825 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3826 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3827 #endif /* CONFIG_WPS */
3829 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3830 { INT(p2p_listen_reg_class), 0 },
3831 { INT(p2p_listen_channel), 0 },
3832 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3833 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3834 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3835 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3836 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3837 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3838 { INT(p2p_group_idle), 0 },
3839 { INT_RANGE(p2p_passphrase_len, 8, 63),
3840 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3841 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3842 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3843 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3844 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3845 { INT(p2p_go_ht40), 0 },
3846 { INT(p2p_go_vht), 0 },
3847 { INT(p2p_disabled), 0 },
3848 { INT(p2p_no_group_iface), 0 },
3849 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
3850 { IPV4(ip_addr_go), 0 },
3851 { IPV4(ip_addr_mask), 0 },
3852 { IPV4(ip_addr_start), 0 },
3853 { IPV4(ip_addr_end), 0 },
3854 #endif /* CONFIG_P2P */
3855 { FUNC(country), CFG_CHANGED_COUNTRY },
3856 { INT(bss_max_count), 0 },
3857 { INT(bss_expiration_age), 0 },
3858 { INT(bss_expiration_scan_count), 0 },
3859 { INT_RANGE(filter_ssids, 0, 1), 0 },
3860 { INT_RANGE(filter_rssi, -100, 0), 0 },
3861 { INT(max_num_sta), 0 },
3862 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3864 { INT_RANGE(hs20, 0, 1), 0 },
3865 #endif /* CONFIG_HS20 */
3866 { INT_RANGE(interworking, 0, 1), 0 },
3867 { FUNC(hessid), 0 },
3868 { INT_RANGE(access_network_type, 0, 15), 0 },
3869 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3870 { STR(autoscan), 0 },
3871 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3872 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3873 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3874 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3875 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3876 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3877 { INT(p2p_go_max_inactivity), 0 },
3878 { INT_RANGE(auto_interworking, 0, 1), 0 },
3881 { FUNC(sae_groups), 0 },
3882 { INT(dtim_period), 0 },
3883 { INT(beacon_int), 0 },
3884 { FUNC(ap_vendor_elements), 0 },
3885 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
3886 { FUNC(freq_list), 0 },
3887 { INT(scan_cur_freq), 0 },
3888 { INT(sched_scan_interval), 0 },
3889 { INT(tdls_external_control), 0},
3890 { STR(osu_dir), 0 },
3891 { STR(wowlan_triggers), 0 },
3892 { INT(p2p_search_delay), 0},
3904 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
3907 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3912 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3913 const struct global_parse_data *field = &global_fields[i];
3914 size_t flen = os_strlen(field->name);
3915 if (os_strncmp(pos, field->name, flen) != 0 ||
3919 if (field->parser(field, config, line, pos + flen + 1)) {
3920 wpa_printf(MSG_ERROR, "Line %d: failed to "
3921 "parse '%s'.", line, pos);
3924 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
3925 config->wps_nfc_pw_from_config = 1;
3926 config->changed_parameters |= field->changed_flag;
3929 if (i == NUM_GLOBAL_FIELDS) {
3931 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
3932 char *tmp = os_strchr(pos, '=');
3936 wpa_printf(MSG_ERROR, "Line %d: invalid line "
3941 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
3943 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
3948 #endif /* CONFIG_AP */
3951 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",