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 str_clear_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 str_clear_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 str_clear_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)
477 #endif /* NO_CONFIG_WRITE */
480 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
481 struct wpa_ssid *ssid, int line,
484 int val = 0, last, errors = 0;
485 char *start, *end, *buf;
487 buf = os_strdup(value);
492 while (*start != '\0') {
493 while (*start == ' ' || *start == '\t')
498 while (*end != ' ' && *end != '\t' && *end != '\0')
502 if (os_strcmp(start, "WPA-PSK") == 0)
503 val |= WPA_KEY_MGMT_PSK;
504 else if (os_strcmp(start, "WPA-EAP") == 0)
505 val |= WPA_KEY_MGMT_IEEE8021X;
506 else if (os_strcmp(start, "IEEE8021X") == 0)
507 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
508 else if (os_strcmp(start, "NONE") == 0)
509 val |= WPA_KEY_MGMT_NONE;
510 else if (os_strcmp(start, "WPA-NONE") == 0)
511 val |= WPA_KEY_MGMT_WPA_NONE;
512 #ifdef CONFIG_IEEE80211R
513 else if (os_strcmp(start, "FT-PSK") == 0)
514 val |= WPA_KEY_MGMT_FT_PSK;
515 else if (os_strcmp(start, "FT-EAP") == 0)
516 val |= WPA_KEY_MGMT_FT_IEEE8021X;
517 #endif /* CONFIG_IEEE80211R */
518 #ifdef CONFIG_IEEE80211W
519 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
520 val |= WPA_KEY_MGMT_PSK_SHA256;
521 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
522 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
523 #endif /* CONFIG_IEEE80211W */
525 else if (os_strcmp(start, "WPS") == 0)
526 val |= WPA_KEY_MGMT_WPS;
527 #endif /* CONFIG_WPS */
529 else if (os_strcmp(start, "SAE") == 0)
530 val |= WPA_KEY_MGMT_SAE;
531 else if (os_strcmp(start, "FT-SAE") == 0)
532 val |= WPA_KEY_MGMT_FT_SAE;
533 #endif /* CONFIG_SAE */
535 else if (os_strcmp(start, "OSEN") == 0)
536 val |= WPA_KEY_MGMT_OSEN;
537 #endif /* CONFIG_HS20 */
539 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
551 wpa_printf(MSG_ERROR,
552 "Line %d: no key_mgmt values configured.", line);
556 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
557 ssid->key_mgmt = val;
558 return errors ? -1 : 0;
562 #ifndef NO_CONFIG_WRITE
563 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
564 struct wpa_ssid *ssid)
566 char *buf, *pos, *end;
569 pos = buf = os_zalloc(100);
574 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
575 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
576 pos == buf ? "" : " ");
577 if (ret < 0 || ret >= end - pos) {
584 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
585 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
586 pos == buf ? "" : " ");
587 if (ret < 0 || ret >= end - pos) {
594 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
595 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
596 pos == buf ? "" : " ");
597 if (ret < 0 || ret >= end - pos) {
604 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
605 ret = os_snprintf(pos, end - pos, "%sNONE",
606 pos == buf ? "" : " ");
607 if (ret < 0 || ret >= end - pos) {
614 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
615 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
616 pos == buf ? "" : " ");
617 if (ret < 0 || ret >= end - pos) {
624 #ifdef CONFIG_IEEE80211R
625 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
626 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
627 pos == buf ? "" : " ");
628 if (ret < 0 || ret >= end - pos) {
635 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
636 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
637 pos == buf ? "" : " ");
638 if (ret < 0 || ret >= end - pos) {
644 #endif /* CONFIG_IEEE80211R */
646 #ifdef CONFIG_IEEE80211W
647 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
648 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
649 pos == buf ? "" : " ");
650 if (ret < 0 || ret >= end - pos) {
657 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
658 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
659 pos == buf ? "" : " ");
660 if (ret < 0 || ret >= end - pos) {
666 #endif /* CONFIG_IEEE80211W */
669 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
670 ret = os_snprintf(pos, end - pos, "%sWPS",
671 pos == buf ? "" : " ");
672 if (ret < 0 || ret >= end - pos) {
678 #endif /* CONFIG_WPS */
681 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
682 ret = os_snprintf(pos, end - pos, "%sSAE",
683 pos == buf ? "" : " ");
684 if (ret < 0 || ret >= end - pos) {
691 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
692 ret = os_snprintf(pos, end - pos, "%sFT-SAE",
693 pos == buf ? "" : " ");
694 if (ret < 0 || ret >= end - pos) {
700 #endif /* CONFIG_SAE */
709 #endif /* NO_CONFIG_WRITE */
712 static int wpa_config_parse_cipher(int line, const char *value)
714 int val = wpa_parse_cipher(value);
716 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
721 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
729 #ifndef NO_CONFIG_WRITE
730 static char * wpa_config_write_cipher(int cipher)
732 char *buf = os_zalloc(50);
736 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
743 #endif /* NO_CONFIG_WRITE */
746 static int wpa_config_parse_pairwise(const struct parse_data *data,
747 struct wpa_ssid *ssid, int line,
751 val = wpa_config_parse_cipher(line, value);
754 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
755 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
756 "(0x%x).", line, val);
760 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
761 ssid->pairwise_cipher = val;
766 #ifndef NO_CONFIG_WRITE
767 static char * wpa_config_write_pairwise(const struct parse_data *data,
768 struct wpa_ssid *ssid)
770 return wpa_config_write_cipher(ssid->pairwise_cipher);
772 #endif /* NO_CONFIG_WRITE */
775 static int wpa_config_parse_group(const struct parse_data *data,
776 struct wpa_ssid *ssid, int line,
780 val = wpa_config_parse_cipher(line, value);
783 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
784 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
785 "(0x%x).", line, val);
789 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
790 ssid->group_cipher = val;
795 #ifndef NO_CONFIG_WRITE
796 static char * wpa_config_write_group(const struct parse_data *data,
797 struct wpa_ssid *ssid)
799 return wpa_config_write_cipher(ssid->group_cipher);
801 #endif /* NO_CONFIG_WRITE */
804 static int wpa_config_parse_auth_alg(const struct parse_data *data,
805 struct wpa_ssid *ssid, int line,
808 int val = 0, last, errors = 0;
809 char *start, *end, *buf;
811 buf = os_strdup(value);
816 while (*start != '\0') {
817 while (*start == ' ' || *start == '\t')
822 while (*end != ' ' && *end != '\t' && *end != '\0')
826 if (os_strcmp(start, "OPEN") == 0)
827 val |= WPA_AUTH_ALG_OPEN;
828 else if (os_strcmp(start, "SHARED") == 0)
829 val |= WPA_AUTH_ALG_SHARED;
830 else if (os_strcmp(start, "LEAP") == 0)
831 val |= WPA_AUTH_ALG_LEAP;
833 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
845 wpa_printf(MSG_ERROR,
846 "Line %d: no auth_alg values configured.", line);
850 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
851 ssid->auth_alg = val;
852 return errors ? -1 : 0;
856 #ifndef NO_CONFIG_WRITE
857 static char * wpa_config_write_auth_alg(const struct parse_data *data,
858 struct wpa_ssid *ssid)
860 char *buf, *pos, *end;
863 pos = buf = os_zalloc(30);
868 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
869 ret = os_snprintf(pos, end - pos, "%sOPEN",
870 pos == buf ? "" : " ");
871 if (ret < 0 || ret >= end - pos) {
878 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
879 ret = os_snprintf(pos, end - pos, "%sSHARED",
880 pos == buf ? "" : " ");
881 if (ret < 0 || ret >= end - pos) {
888 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
889 ret = os_snprintf(pos, end - pos, "%sLEAP",
890 pos == buf ? "" : " ");
891 if (ret < 0 || ret >= end - pos) {
905 #endif /* NO_CONFIG_WRITE */
908 static int * wpa_config_parse_int_array(const char *value)
916 freqs = os_calloc(len + 1, sizeof(int));
927 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
932 for (i = len; i <= len * 2; i++)
938 freqs[used] = atoi(pos);
939 if (freqs[used] == 0)
942 pos = os_strchr(pos + 1, ' ');
949 static int wpa_config_parse_scan_freq(const struct parse_data *data,
950 struct wpa_ssid *ssid, int line,
955 freqs = wpa_config_parse_int_array(value);
962 os_free(ssid->scan_freq);
963 ssid->scan_freq = freqs;
969 static int wpa_config_parse_freq_list(const struct parse_data *data,
970 struct wpa_ssid *ssid, int line,
975 freqs = wpa_config_parse_int_array(value);
982 os_free(ssid->freq_list);
983 ssid->freq_list = freqs;
989 #ifndef NO_CONFIG_WRITE
990 static char * wpa_config_write_freqs(const struct parse_data *data,
993 char *buf, *pos, *end;
1001 for (i = 0; freqs[i]; i++)
1004 pos = buf = os_zalloc(10 * count + 1);
1007 end = buf + 10 * count + 1;
1009 for (i = 0; freqs[i]; i++) {
1010 ret = os_snprintf(pos, end - pos, "%s%u",
1011 i == 0 ? "" : " ", freqs[i]);
1012 if (ret < 0 || ret >= end - pos) {
1023 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1024 struct wpa_ssid *ssid)
1026 return wpa_config_write_freqs(data, ssid->scan_freq);
1030 static char * wpa_config_write_freq_list(const struct parse_data *data,
1031 struct wpa_ssid *ssid)
1033 return wpa_config_write_freqs(data, ssid->freq_list);
1035 #endif /* NO_CONFIG_WRITE */
1038 #ifdef IEEE8021X_EAPOL
1039 static int wpa_config_parse_eap(const struct parse_data *data,
1040 struct wpa_ssid *ssid, int line,
1043 int last, errors = 0;
1044 char *start, *end, *buf;
1045 struct eap_method_type *methods = NULL, *tmp;
1046 size_t num_methods = 0;
1048 buf = os_strdup(value);
1053 while (*start != '\0') {
1054 while (*start == ' ' || *start == '\t')
1059 while (*end != ' ' && *end != '\t' && *end != '\0')
1061 last = *end == '\0';
1064 methods = os_realloc_array(methods, num_methods + 1,
1066 if (methods == NULL) {
1071 methods[num_methods].method = eap_peer_get_type(
1072 start, &methods[num_methods].vendor);
1073 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1074 methods[num_methods].method == EAP_TYPE_NONE) {
1075 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1076 "'%s'", line, start);
1077 wpa_printf(MSG_ERROR, "You may need to add support for"
1078 " this EAP method during wpa_supplicant\n"
1079 "build time configuration.\n"
1080 "See README for more information.");
1082 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1083 methods[num_methods].method == EAP_TYPE_LEAP)
1095 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1096 if (methods == NULL) {
1100 methods[num_methods].vendor = EAP_VENDOR_IETF;
1101 methods[num_methods].method = EAP_TYPE_NONE;
1104 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1105 (u8 *) methods, num_methods * sizeof(*methods));
1106 os_free(ssid->eap.eap_methods);
1107 ssid->eap.eap_methods = methods;
1108 return errors ? -1 : 0;
1112 static char * wpa_config_write_eap(const struct parse_data *data,
1113 struct wpa_ssid *ssid)
1116 char *buf, *pos, *end;
1117 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1120 if (eap_methods == NULL)
1123 pos = buf = os_zalloc(100);
1128 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1129 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1130 name = eap_get_name(eap_methods[i].vendor,
1131 eap_methods[i].method);
1133 ret = os_snprintf(pos, end - pos, "%s%s",
1134 pos == buf ? "" : " ", name);
1135 if (ret < 0 || ret >= end - pos)
1147 static int wpa_config_parse_password(const struct parse_data *data,
1148 struct wpa_ssid *ssid, int line,
1153 if (os_strcmp(value, "NULL") == 0) {
1154 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1155 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1156 ssid->eap.password = NULL;
1157 ssid->eap.password_len = 0;
1161 #ifdef CONFIG_EXT_PASSWORD
1162 if (os_strncmp(value, "ext:", 4) == 0) {
1163 char *name = os_strdup(value + 4);
1166 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1167 ssid->eap.password = (u8 *) name;
1168 ssid->eap.password_len = os_strlen(name);
1169 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1170 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1173 #endif /* CONFIG_EXT_PASSWORD */
1175 if (os_strncmp(value, "hash:", 5) != 0) {
1179 tmp = wpa_config_parse_string(value, &res_len);
1181 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1185 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1186 (u8 *) tmp, res_len);
1188 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1189 ssid->eap.password = (u8 *) tmp;
1190 ssid->eap.password_len = res_len;
1191 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1192 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1198 /* NtPasswordHash: hash:<32 hex digits> */
1199 if (os_strlen(value + 5) != 2 * 16) {
1200 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1201 "(expected 32 hex digits)", line);
1205 hash = os_malloc(16);
1209 if (hexstr2bin(value + 5, hash, 16)) {
1211 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1215 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1217 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1218 ssid->eap.password = hash;
1219 ssid->eap.password_len = 16;
1220 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1221 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1227 static char * wpa_config_write_password(const struct parse_data *data,
1228 struct wpa_ssid *ssid)
1232 if (ssid->eap.password == NULL)
1235 #ifdef CONFIG_EXT_PASSWORD
1236 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1237 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1240 os_memcpy(buf, "ext:", 4);
1241 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1244 #endif /* CONFIG_EXT_PASSWORD */
1246 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1247 return wpa_config_write_string(
1248 ssid->eap.password, ssid->eap.password_len);
1251 buf = os_malloc(5 + 32 + 1);
1255 os_memcpy(buf, "hash:", 5);
1256 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1260 #endif /* IEEE8021X_EAPOL */
1263 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1264 const char *value, int idx)
1266 char *buf, title[20];
1269 buf = wpa_config_parse_string(value, len);
1271 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1275 if (*len > MAX_WEP_KEY_LEN) {
1276 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1281 if (*len && *len != 5 && *len != 13 && *len != 16) {
1282 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1283 "this network block will be ignored",
1284 line, (unsigned int) *len);
1286 os_memcpy(key, buf, *len);
1287 str_clear_free(buf);
1288 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1289 if (res >= 0 && (size_t) res < sizeof(title))
1290 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1295 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1296 struct wpa_ssid *ssid, int line,
1299 return wpa_config_parse_wep_key(ssid->wep_key[0],
1300 &ssid->wep_key_len[0], line,
1305 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1306 struct wpa_ssid *ssid, int line,
1309 return wpa_config_parse_wep_key(ssid->wep_key[1],
1310 &ssid->wep_key_len[1], line,
1315 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1316 struct wpa_ssid *ssid, int line,
1319 return wpa_config_parse_wep_key(ssid->wep_key[2],
1320 &ssid->wep_key_len[2], line,
1325 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1326 struct wpa_ssid *ssid, int line,
1329 return wpa_config_parse_wep_key(ssid->wep_key[3],
1330 &ssid->wep_key_len[3], line,
1335 #ifndef NO_CONFIG_WRITE
1336 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1338 if (ssid->wep_key_len[idx] == 0)
1340 return wpa_config_write_string(ssid->wep_key[idx],
1341 ssid->wep_key_len[idx]);
1345 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1346 struct wpa_ssid *ssid)
1348 return wpa_config_write_wep_key(ssid, 0);
1352 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1353 struct wpa_ssid *ssid)
1355 return wpa_config_write_wep_key(ssid, 1);
1359 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1360 struct wpa_ssid *ssid)
1362 return wpa_config_write_wep_key(ssid, 2);
1366 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1367 struct wpa_ssid *ssid)
1369 return wpa_config_write_wep_key(ssid, 3);
1371 #endif /* NO_CONFIG_WRITE */
1376 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1377 struct wpa_ssid *ssid, int line,
1380 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1381 os_strcmp(value, "any") == 0) {
1382 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1383 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1386 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1387 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1391 ssid->bssid_set = 1;
1392 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1393 MAC2STR(ssid->go_p2p_dev_addr));
1398 #ifndef NO_CONFIG_WRITE
1399 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1400 struct wpa_ssid *ssid)
1405 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1408 value = os_malloc(20);
1411 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1412 if (res < 0 || res >= 20) {
1416 value[20 - 1] = '\0';
1419 #endif /* NO_CONFIG_WRITE */
1422 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1423 struct wpa_ssid *ssid, int line,
1427 u8 *buf, *n, addr[ETH_ALEN];
1434 while (pos && *pos) {
1438 if (hwaddr_aton(pos, addr)) {
1440 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1441 "p2p_client_list address '%s'.",
1446 /* continue anyway since this could have been from a
1447 * truncated configuration file line */
1448 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1449 "truncated p2p_client_list address '%s'",
1452 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1458 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1459 os_memcpy(buf, addr, ETH_ALEN);
1461 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1465 pos = os_strchr(pos, ' ');
1468 os_free(ssid->p2p_client_list);
1469 ssid->p2p_client_list = buf;
1470 ssid->num_p2p_clients = count;
1476 #ifndef NO_CONFIG_WRITE
1477 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1478 struct wpa_ssid *ssid)
1480 char *value, *end, *pos;
1484 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1487 value = os_malloc(20 * ssid->num_p2p_clients);
1491 end = value + 20 * ssid->num_p2p_clients;
1493 for (i = ssid->num_p2p_clients; i > 0; i--) {
1494 res = os_snprintf(pos, end - pos, MACSTR " ",
1495 MAC2STR(ssid->p2p_client_list +
1496 (i - 1) * ETH_ALEN));
1497 if (res < 0 || res >= end - pos) {
1509 #endif /* NO_CONFIG_WRITE */
1512 static int wpa_config_parse_psk_list(const struct parse_data *data,
1513 struct wpa_ssid *ssid, int line,
1516 struct psk_list_entry *p;
1519 p = os_zalloc(sizeof(*p));
1524 if (os_strncmp(pos, "P2P-", 4) == 0) {
1529 if (hwaddr_aton(pos, p->addr)) {
1530 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1537 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1544 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1545 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1551 dl_list_add(&ssid->psk_list, &p->list);
1557 #ifndef NO_CONFIG_WRITE
1558 static char * wpa_config_write_psk_list(const struct parse_data *data,
1559 struct wpa_ssid *ssid)
1563 #endif /* NO_CONFIG_WRITE */
1565 #endif /* CONFIG_P2P */
1567 /* Helper macros for network block parser */
1572 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1573 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1575 /* STR: Define a string variable for an ASCII string; f = field name */
1576 #ifdef NO_CONFIG_WRITE
1577 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1578 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1579 #else /* NO_CONFIG_WRITE */
1580 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1581 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1582 #endif /* NO_CONFIG_WRITE */
1583 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1584 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1585 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1586 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1588 /* STR_LEN: Define a string variable with a separate variable for storing the
1589 * data length. Unlike STR(), this can be used to store arbitrary binary data
1590 * (i.e., even nul termination character). */
1591 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1592 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1593 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1594 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1595 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1597 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1598 * explicitly specified. */
1599 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1600 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1601 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1603 #ifdef NO_CONFIG_WRITE
1604 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1605 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1606 #else /* NO_CONFIG_WRITE */
1607 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1608 OFFSET(f), (void *) 0
1609 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1610 OFFSET(eap.f), (void *) 0
1611 #endif /* NO_CONFIG_WRITE */
1613 /* INT: Define an integer variable */
1614 #define INT(f) _INT(f), NULL, NULL, 0
1615 #define INTe(f) _INTe(f), NULL, NULL, 0
1617 /* INT_RANGE: Define an integer variable with allowed value range */
1618 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1620 /* FUNC: Define a configuration variable that uses a custom function for
1621 * parsing and writing the value. */
1622 #ifdef NO_CONFIG_WRITE
1623 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1624 #else /* NO_CONFIG_WRITE */
1625 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1626 NULL, NULL, NULL, NULL
1627 #endif /* NO_CONFIG_WRITE */
1628 #define FUNC(f) _FUNC(f), 0
1629 #define FUNC_KEY(f) _FUNC(f), 1
1632 * Table of network configuration variables. This table is used to parse each
1633 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1634 * that is inside a network block.
1636 * This table is generated using the helper macros defined above and with
1637 * generous help from the C pre-processor. The field name is stored as a string
1638 * into .name and for STR and INT types, the offset of the target buffer within
1639 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1640 * offset to the field containing the length of the configuration variable.
1641 * .param3 and .param4 can be used to mark the allowed range (length for STR
1642 * and value for INT).
1644 * For each configuration line in wpa_supplicant.conf, the parser goes through
1645 * this table and select the entry that matches with the field name. The parser
1646 * function (.parser) is then called to parse the actual value of the field.
1648 * This kind of mechanism makes it easy to add new configuration parameters,
1649 * since only one line needs to be added into this table and into the
1650 * struct wpa_ssid definition if the new variable is either a string or
1651 * integer. More complex types will need to use their own parser and writer
1654 static const struct parse_data ssid_fields[] = {
1655 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1656 { INT_RANGE(scan_ssid, 0, 1) },
1661 { INT(bg_scan_period) },
1665 { FUNC(scan_freq) },
1666 { FUNC(freq_list) },
1667 #ifdef IEEE8021X_EAPOL
1669 { STR_LENe(identity) },
1670 { STR_LENe(anonymous_identity) },
1671 { FUNC_KEY(password) },
1674 { STRe(client_cert) },
1675 { STRe(private_key) },
1676 { STR_KEYe(private_key_passwd) },
1678 { STRe(subject_match) },
1679 { STRe(altsubject_match) },
1680 { STRe(domain_suffix_match) },
1683 { STRe(client_cert2) },
1684 { STRe(private_key2) },
1685 { STR_KEYe(private_key2_passwd) },
1687 { STRe(subject_match2) },
1688 { STRe(altsubject_match2) },
1689 { STRe(domain_suffix_match2) },
1694 { STRe(engine_id) },
1697 { STRe(ca_cert_id) },
1699 { STRe(engine2_id) },
1702 { STRe(ca_cert2_id) },
1705 { INT(eapol_flags) },
1707 { STRe(openssl_ciphers) },
1708 #endif /* IEEE8021X_EAPOL */
1709 { FUNC_KEY(wep_key0) },
1710 { FUNC_KEY(wep_key1) },
1711 { FUNC_KEY(wep_key2) },
1712 { FUNC_KEY(wep_key3) },
1713 { INT(wep_tx_keyidx) },
1715 #ifdef IEEE8021X_EAPOL
1716 { INT(eap_workaround) },
1718 { INTe(fragment_size) },
1720 #endif /* IEEE8021X_EAPOL */
1721 { INT_RANGE(mode, 0, 4) },
1722 { INT_RANGE(proactive_key_caching, 0, 1) },
1723 { INT_RANGE(disabled, 0, 2) },
1725 #ifdef CONFIG_IEEE80211W
1726 { INT_RANGE(ieee80211w, 0, 2) },
1727 #endif /* CONFIG_IEEE80211W */
1728 { INT_RANGE(peerkey, 0, 1) },
1729 { INT_RANGE(mixed_cell, 0, 1) },
1730 { INT_RANGE(frequency, 0, 65000) },
1731 { INT(wpa_ptk_rekey) },
1733 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1735 { FUNC(go_p2p_dev_addr) },
1736 { FUNC(p2p_client_list) },
1738 #endif /* CONFIG_P2P */
1739 #ifdef CONFIG_HT_OVERRIDES
1740 { INT_RANGE(disable_ht, 0, 1) },
1741 { INT_RANGE(disable_ht40, -1, 1) },
1742 { INT_RANGE(disable_sgi, 0, 1) },
1743 { INT_RANGE(disable_ldpc, 0, 1) },
1744 { INT_RANGE(ht40_intolerant, 0, 1) },
1745 { INT_RANGE(disable_max_amsdu, -1, 1) },
1746 { INT_RANGE(ampdu_factor, -1, 3) },
1747 { INT_RANGE(ampdu_density, -1, 7) },
1749 #endif /* CONFIG_HT_OVERRIDES */
1750 #ifdef CONFIG_VHT_OVERRIDES
1751 { INT_RANGE(disable_vht, 0, 1) },
1753 { INT(vht_capa_mask) },
1754 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1755 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1756 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1757 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1758 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1759 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1760 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1761 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1762 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1763 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1764 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1765 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1766 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1767 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1768 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1769 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1770 #endif /* CONFIG_VHT_OVERRIDES */
1771 { INT(ap_max_inactivity) },
1772 { INT(dtim_period) },
1773 { INT(beacon_int) },
1774 #ifdef CONFIG_MACSEC
1775 { INT_RANGE(macsec_policy, 0, 1) },
1776 #endif /* CONFIG_MACSEC */
1778 { INT(update_identifier) },
1779 #endif /* CONFIG_HS20 */
1780 { INT_RANGE(mac_addr, 0, 2) },
1792 #undef STR_RANGE_KEY
1799 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1803 * wpa_config_add_prio_network - Add a network to priority lists
1804 * @config: Configuration data from wpa_config_read()
1805 * @ssid: Pointer to the network configuration to be added to the list
1806 * Returns: 0 on success, -1 on failure
1808 * This function is used to add a network block to the priority list of
1809 * networks. This must be called for each network when reading in the full
1810 * configuration. In addition, this can be used indirectly when updating
1811 * priorities by calling wpa_config_update_prio_list().
1813 int wpa_config_add_prio_network(struct wpa_config *config,
1814 struct wpa_ssid *ssid)
1817 struct wpa_ssid *prev, **nlist;
1820 * Add to an existing priority list if one is available for the
1821 * configured priority level for this network.
1823 for (prio = 0; prio < config->num_prio; prio++) {
1824 prev = config->pssid[prio];
1825 if (prev->priority == ssid->priority) {
1833 /* First network for this priority - add a new priority list */
1834 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1835 sizeof(struct wpa_ssid *));
1839 for (prio = 0; prio < config->num_prio; prio++) {
1840 if (nlist[prio]->priority < ssid->priority) {
1841 os_memmove(&nlist[prio + 1], &nlist[prio],
1842 (config->num_prio - prio) *
1843 sizeof(struct wpa_ssid *));
1850 config->pssid = nlist;
1857 * wpa_config_update_prio_list - Update network priority list
1858 * @config: Configuration data from wpa_config_read()
1859 * Returns: 0 on success, -1 on failure
1861 * This function is called to update the priority list of networks in the
1862 * configuration when a network is being added or removed. This is also called
1863 * if a priority for a network is changed.
1865 int wpa_config_update_prio_list(struct wpa_config *config)
1867 struct wpa_ssid *ssid;
1870 os_free(config->pssid);
1871 config->pssid = NULL;
1872 config->num_prio = 0;
1874 ssid = config->ssid;
1877 if (wpa_config_add_prio_network(config, ssid) < 0)
1886 #ifdef IEEE8021X_EAPOL
1887 static void eap_peer_config_free(struct eap_peer_config *eap)
1889 os_free(eap->eap_methods);
1890 bin_clear_free(eap->identity, eap->identity_len);
1891 os_free(eap->anonymous_identity);
1892 bin_clear_free(eap->password, eap->password_len);
1893 os_free(eap->ca_cert);
1894 os_free(eap->ca_path);
1895 os_free(eap->client_cert);
1896 os_free(eap->private_key);
1897 str_clear_free(eap->private_key_passwd);
1898 os_free(eap->dh_file);
1899 os_free(eap->subject_match);
1900 os_free(eap->altsubject_match);
1901 os_free(eap->domain_suffix_match);
1902 os_free(eap->ca_cert2);
1903 os_free(eap->ca_path2);
1904 os_free(eap->client_cert2);
1905 os_free(eap->private_key2);
1906 str_clear_free(eap->private_key2_passwd);
1907 os_free(eap->dh_file2);
1908 os_free(eap->subject_match2);
1909 os_free(eap->altsubject_match2);
1910 os_free(eap->domain_suffix_match2);
1911 os_free(eap->phase1);
1912 os_free(eap->phase2);
1914 str_clear_free(eap->pin);
1915 os_free(eap->engine_id);
1916 os_free(eap->key_id);
1917 os_free(eap->cert_id);
1918 os_free(eap->ca_cert_id);
1919 os_free(eap->key2_id);
1920 os_free(eap->cert2_id);
1921 os_free(eap->ca_cert2_id);
1922 str_clear_free(eap->pin2);
1923 os_free(eap->engine2_id);
1925 os_free(eap->pending_req_otp);
1926 os_free(eap->pac_file);
1927 bin_clear_free(eap->new_password, eap->new_password_len);
1928 str_clear_free(eap->external_sim_resp);
1929 os_free(eap->openssl_ciphers);
1931 #endif /* IEEE8021X_EAPOL */
1935 * wpa_config_free_ssid - Free network/ssid configuration data
1936 * @ssid: Configuration data for the network
1938 * This function frees all resources allocated for the network configuration
1941 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1943 struct psk_list_entry *psk;
1945 os_free(ssid->ssid);
1946 os_memset(ssid->psk, 0, sizeof(ssid->psk));
1947 str_clear_free(ssid->passphrase);
1948 os_free(ssid->ext_psk);
1949 #ifdef IEEE8021X_EAPOL
1950 eap_peer_config_free(&ssid->eap);
1951 #endif /* IEEE8021X_EAPOL */
1952 os_free(ssid->id_str);
1953 os_free(ssid->scan_freq);
1954 os_free(ssid->freq_list);
1955 os_free(ssid->bgscan);
1956 os_free(ssid->p2p_client_list);
1957 #ifdef CONFIG_HT_OVERRIDES
1958 os_free(ssid->ht_mcs);
1959 #endif /* CONFIG_HT_OVERRIDES */
1960 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
1962 dl_list_del(&psk->list);
1969 void wpa_config_free_cred(struct wpa_cred *cred)
1973 os_free(cred->realm);
1974 str_clear_free(cred->username);
1975 str_clear_free(cred->password);
1976 os_free(cred->ca_cert);
1977 os_free(cred->client_cert);
1978 os_free(cred->private_key);
1979 str_clear_free(cred->private_key_passwd);
1980 os_free(cred->imsi);
1981 str_clear_free(cred->milenage);
1982 for (i = 0; i < cred->num_domain; i++)
1983 os_free(cred->domain[i]);
1984 os_free(cred->domain);
1985 os_free(cred->domain_suffix_match);
1986 os_free(cred->eap_method);
1987 os_free(cred->phase1);
1988 os_free(cred->phase2);
1989 os_free(cred->excluded_ssid);
1990 os_free(cred->roaming_partner);
1991 os_free(cred->provisioning_sp);
1992 for (i = 0; i < cred->num_req_conn_capab; i++)
1993 os_free(cred->req_conn_capab_port[i]);
1994 os_free(cred->req_conn_capab_port);
1995 os_free(cred->req_conn_capab_proto);
2000 void wpa_config_flush_blobs(struct wpa_config *config)
2002 #ifndef CONFIG_NO_CONFIG_BLOBS
2003 struct wpa_config_blob *blob, *prev;
2005 blob = config->blobs;
2006 config->blobs = NULL;
2010 wpa_config_free_blob(prev);
2012 #endif /* CONFIG_NO_CONFIG_BLOBS */
2017 * wpa_config_free - Free configuration data
2018 * @config: Configuration data from wpa_config_read()
2020 * This function frees all resources allocated for the configuration data by
2021 * wpa_config_read().
2023 void wpa_config_free(struct wpa_config *config)
2025 struct wpa_ssid *ssid, *prev = NULL;
2026 struct wpa_cred *cred, *cprev;
2028 ssid = config->ssid;
2032 wpa_config_free_ssid(prev);
2035 cred = config->cred;
2039 wpa_config_free_cred(cprev);
2042 wpa_config_flush_blobs(config);
2044 wpabuf_free(config->wps_vendor_ext_m1);
2045 os_free(config->ctrl_interface);
2046 os_free(config->ctrl_interface_group);
2047 os_free(config->opensc_engine_path);
2048 os_free(config->pkcs11_engine_path);
2049 os_free(config->pkcs11_module_path);
2050 os_free(config->openssl_ciphers);
2051 os_free(config->pcsc_reader);
2052 str_clear_free(config->pcsc_pin);
2053 os_free(config->driver_param);
2054 os_free(config->device_name);
2055 os_free(config->manufacturer);
2056 os_free(config->model_name);
2057 os_free(config->model_number);
2058 os_free(config->serial_number);
2059 os_free(config->config_methods);
2060 os_free(config->p2p_ssid_postfix);
2061 os_free(config->pssid);
2062 os_free(config->p2p_pref_chan);
2063 os_free(config->p2p_no_go_freq.range);
2064 os_free(config->autoscan);
2065 os_free(config->freq_list);
2066 wpabuf_free(config->wps_nfc_dh_pubkey);
2067 wpabuf_free(config->wps_nfc_dh_privkey);
2068 wpabuf_free(config->wps_nfc_dev_pw);
2069 os_free(config->ext_password_backend);
2070 os_free(config->sae_groups);
2071 wpabuf_free(config->ap_vendor_elements);
2072 os_free(config->osu_dir);
2073 os_free(config->wowlan_triggers);
2079 * wpa_config_foreach_network - Iterate over each configured network
2080 * @config: Configuration data from wpa_config_read()
2081 * @func: Callback function to process each network
2082 * @arg: Opaque argument to pass to callback function
2084 * Iterate over the set of configured networks calling the specified
2085 * function for each item. We guard against callbacks removing the
2088 void wpa_config_foreach_network(struct wpa_config *config,
2089 void (*func)(void *, struct wpa_ssid *),
2092 struct wpa_ssid *ssid, *next;
2094 ssid = config->ssid;
2104 * wpa_config_get_network - Get configured network based on id
2105 * @config: Configuration data from wpa_config_read()
2106 * @id: Unique network id to search for
2107 * Returns: Network configuration or %NULL if not found
2109 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2111 struct wpa_ssid *ssid;
2113 ssid = config->ssid;
2125 * wpa_config_add_network - Add a new network with empty configuration
2126 * @config: Configuration data from wpa_config_read()
2127 * Returns: The new network configuration or %NULL if operation failed
2129 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2132 struct wpa_ssid *ssid, *last = NULL;
2135 ssid = config->ssid;
2144 ssid = os_zalloc(sizeof(*ssid));
2148 dl_list_init(&ssid->psk_list);
2152 config->ssid = ssid;
2154 wpa_config_update_prio_list(config);
2161 * wpa_config_remove_network - Remove a configured network based on id
2162 * @config: Configuration data from wpa_config_read()
2163 * @id: Unique network id to search for
2164 * Returns: 0 on success, or -1 if the network was not found
2166 int wpa_config_remove_network(struct wpa_config *config, int id)
2168 struct wpa_ssid *ssid, *prev = NULL;
2170 ssid = config->ssid;
2182 prev->next = ssid->next;
2184 config->ssid = ssid->next;
2186 wpa_config_update_prio_list(config);
2187 wpa_config_free_ssid(ssid);
2193 * wpa_config_set_network_defaults - Set network default values
2194 * @ssid: Pointer to network configuration data
2196 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2198 ssid->proto = DEFAULT_PROTO;
2199 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2200 ssid->group_cipher = DEFAULT_GROUP;
2201 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2202 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2203 #ifdef IEEE8021X_EAPOL
2204 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2205 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2206 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2207 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2208 #endif /* IEEE8021X_EAPOL */
2209 #ifdef CONFIG_HT_OVERRIDES
2210 ssid->disable_ht = DEFAULT_DISABLE_HT;
2211 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2212 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2213 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2214 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2215 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2216 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2217 #endif /* CONFIG_HT_OVERRIDES */
2218 #ifdef CONFIG_VHT_OVERRIDES
2219 ssid->vht_rx_mcs_nss_1 = -1;
2220 ssid->vht_rx_mcs_nss_2 = -1;
2221 ssid->vht_rx_mcs_nss_3 = -1;
2222 ssid->vht_rx_mcs_nss_4 = -1;
2223 ssid->vht_rx_mcs_nss_5 = -1;
2224 ssid->vht_rx_mcs_nss_6 = -1;
2225 ssid->vht_rx_mcs_nss_7 = -1;
2226 ssid->vht_rx_mcs_nss_8 = -1;
2227 ssid->vht_tx_mcs_nss_1 = -1;
2228 ssid->vht_tx_mcs_nss_2 = -1;
2229 ssid->vht_tx_mcs_nss_3 = -1;
2230 ssid->vht_tx_mcs_nss_4 = -1;
2231 ssid->vht_tx_mcs_nss_5 = -1;
2232 ssid->vht_tx_mcs_nss_6 = -1;
2233 ssid->vht_tx_mcs_nss_7 = -1;
2234 ssid->vht_tx_mcs_nss_8 = -1;
2235 #endif /* CONFIG_VHT_OVERRIDES */
2236 ssid->proactive_key_caching = -1;
2237 #ifdef CONFIG_IEEE80211W
2238 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2239 #endif /* CONFIG_IEEE80211W */
2240 ssid->mac_addr = -1;
2245 * wpa_config_set - Set a variable in network configuration
2246 * @ssid: Pointer to network configuration data
2247 * @var: Variable name, e.g., "ssid"
2248 * @value: Variable value
2249 * @line: Line number in configuration file or 0 if not used
2250 * Returns: 0 on success, -1 on failure
2252 * This function can be used to set network configuration variables based on
2253 * both the configuration file and management interface input. The value
2254 * parameter must be in the same format as the text-based configuration file is
2255 * using. For example, strings are using double quotation marks.
2257 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2263 if (ssid == NULL || var == NULL || value == NULL)
2266 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2267 const struct parse_data *field = &ssid_fields[i];
2268 if (os_strcmp(var, field->name) != 0)
2271 if (field->parser(field, ssid, line, value)) {
2273 wpa_printf(MSG_ERROR, "Line %d: failed to "
2274 "parse %s '%s'.", line, var, value);
2280 if (i == NUM_SSID_FIELDS) {
2282 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2283 "'%s'.", line, var);
2292 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2299 len = os_strlen(value);
2300 buf = os_malloc(len + 3);
2304 os_memcpy(buf + 1, value, len);
2306 buf[len + 2] = '\0';
2307 ret = wpa_config_set(ssid, var, buf, 0);
2314 * wpa_config_get_all - Get all options from network configuration
2315 * @ssid: Pointer to network configuration data
2316 * @get_keys: Determines if keys/passwords will be included in returned list
2317 * (if they may be exported)
2318 * Returns: %NULL terminated list of all set keys and their values in the form
2319 * of [key1, val1, key2, val2, ... , NULL]
2321 * This function can be used to get list of all configured network properties.
2322 * The caller is responsible for freeing the returned list and all its
2325 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2327 const struct parse_data *field;
2333 get_keys = get_keys && ssid->export_keys;
2335 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2340 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2341 field = &ssid_fields[i];
2342 if (field->key_data && !get_keys)
2344 value = field->writer(field, ssid);
2347 if (os_strlen(value) == 0) {
2352 key = os_strdup(field->name);
2358 props[fields_num * 2] = key;
2359 props[fields_num * 2 + 1] = value;
2375 #ifndef NO_CONFIG_WRITE
2377 * wpa_config_get - Get a variable in network configuration
2378 * @ssid: Pointer to network configuration data
2379 * @var: Variable name, e.g., "ssid"
2380 * Returns: Value of the variable or %NULL on failure
2382 * This function can be used to get network configuration variables. The
2383 * returned value is a copy of the configuration variable in text format, i.e,.
2384 * the same format that the text-based configuration file and wpa_config_set()
2385 * are using for the value. The caller is responsible for freeing the returned
2388 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2392 if (ssid == NULL || var == NULL)
2395 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2396 const struct parse_data *field = &ssid_fields[i];
2397 if (os_strcmp(var, field->name) == 0)
2398 return field->writer(field, ssid);
2406 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2407 * @ssid: Pointer to network configuration data
2408 * @var: Variable name, e.g., "ssid"
2409 * Returns: Value of the variable or %NULL on failure
2411 * This function can be used to get network configuration variable like
2412 * wpa_config_get(). The only difference is that this functions does not expose
2413 * key/password material from the configuration. In case a key/password field
2414 * is requested, the returned value is an empty string or %NULL if the variable
2415 * is not set or "*" if the variable is set (regardless of its value). The
2416 * returned value is a copy of the configuration variable in text format, i.e,.
2417 * the same format that the text-based configuration file and wpa_config_set()
2418 * are using for the value. The caller is responsible for freeing the returned
2421 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2425 if (ssid == NULL || var == NULL)
2428 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2429 const struct parse_data *field = &ssid_fields[i];
2430 if (os_strcmp(var, field->name) == 0) {
2431 char *res = field->writer(field, ssid);
2432 if (field->key_data) {
2433 if (res && res[0]) {
2434 wpa_printf(MSG_DEBUG, "Do not allow "
2435 "key_data field to be "
2437 str_clear_free(res);
2438 return os_strdup("*");
2450 #endif /* NO_CONFIG_WRITE */
2454 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2455 * @ssid: Pointer to network configuration data
2457 * This function must be called to update WPA PSK when either SSID or the
2458 * passphrase has changed for the network configuration.
2460 void wpa_config_update_psk(struct wpa_ssid *ssid)
2462 #ifndef CONFIG_NO_PBKDF2
2463 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2464 ssid->psk, PMK_LEN);
2465 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2466 ssid->psk, PMK_LEN);
2468 #endif /* CONFIG_NO_PBKDF2 */
2472 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2477 int *ports, *nports;
2479 unsigned int num_ports;
2481 proto = os_realloc_array(cred->req_conn_capab_proto,
2482 cred->num_req_conn_capab + 1, sizeof(u8));
2485 cred->req_conn_capab_proto = proto;
2487 port = os_realloc_array(cred->req_conn_capab_port,
2488 cred->num_req_conn_capab + 1, sizeof(int *));
2491 cred->req_conn_capab_port = port;
2493 proto[cred->num_req_conn_capab] = atoi(value);
2495 pos = os_strchr(value, ':');
2497 port[cred->num_req_conn_capab] = NULL;
2498 cred->num_req_conn_capab++;
2507 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2508 if (nports == NULL) {
2513 ports[num_ports++] = atoi(pos);
2515 pos = os_strchr(pos, ',');
2521 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2522 if (nports == NULL) {
2527 ports[num_ports] = -1;
2529 port[cred->num_req_conn_capab] = ports;
2530 cred->num_req_conn_capab++;
2535 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2536 const char *value, int line)
2541 if (os_strcmp(var, "temporary") == 0) {
2542 cred->temporary = atoi(value);
2546 if (os_strcmp(var, "priority") == 0) {
2547 cred->priority = atoi(value);
2551 if (os_strcmp(var, "sp_priority") == 0) {
2552 int prio = atoi(value);
2553 if (prio < 0 || prio > 255)
2555 cred->sp_priority = prio;
2559 if (os_strcmp(var, "pcsc") == 0) {
2560 cred->pcsc = atoi(value);
2564 if (os_strcmp(var, "eap") == 0) {
2565 struct eap_method_type method;
2566 method.method = eap_peer_get_type(value, &method.vendor);
2567 if (method.vendor == EAP_VENDOR_IETF &&
2568 method.method == EAP_TYPE_NONE) {
2569 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2570 "for a credential", line, value);
2573 os_free(cred->eap_method);
2574 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2575 if (cred->eap_method == NULL)
2577 os_memcpy(cred->eap_method, &method, sizeof(method));
2581 if (os_strcmp(var, "password") == 0 &&
2582 os_strncmp(value, "ext:", 4) == 0) {
2583 str_clear_free(cred->password);
2584 cred->password = os_strdup(value);
2585 cred->ext_password = 1;
2589 if (os_strcmp(var, "update_identifier") == 0) {
2590 cred->update_identifier = atoi(value);
2594 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2595 cred->min_dl_bandwidth_home = atoi(value);
2599 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2600 cred->min_ul_bandwidth_home = atoi(value);
2604 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2605 cred->min_dl_bandwidth_roaming = atoi(value);
2609 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2610 cred->min_ul_bandwidth_roaming = atoi(value);
2614 if (os_strcmp(var, "max_bss_load") == 0) {
2615 cred->max_bss_load = atoi(value);
2619 if (os_strcmp(var, "req_conn_capab") == 0)
2620 return wpa_config_set_cred_req_conn_capab(cred, value);
2622 if (os_strcmp(var, "ocsp") == 0) {
2623 cred->ocsp = atoi(value);
2627 if (os_strcmp(var, "sim_num") == 0) {
2628 cred->sim_num = atoi(value);
2632 val = wpa_config_parse_string(value, &len);
2634 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2635 "value '%s'.", line, var, value);
2639 if (os_strcmp(var, "realm") == 0) {
2640 os_free(cred->realm);
2645 if (os_strcmp(var, "username") == 0) {
2646 str_clear_free(cred->username);
2647 cred->username = val;
2651 if (os_strcmp(var, "password") == 0) {
2652 str_clear_free(cred->password);
2653 cred->password = val;
2654 cred->ext_password = 0;
2658 if (os_strcmp(var, "ca_cert") == 0) {
2659 os_free(cred->ca_cert);
2660 cred->ca_cert = val;
2664 if (os_strcmp(var, "client_cert") == 0) {
2665 os_free(cred->client_cert);
2666 cred->client_cert = val;
2670 if (os_strcmp(var, "private_key") == 0) {
2671 os_free(cred->private_key);
2672 cred->private_key = val;
2676 if (os_strcmp(var, "private_key_passwd") == 0) {
2677 str_clear_free(cred->private_key_passwd);
2678 cred->private_key_passwd = val;
2682 if (os_strcmp(var, "imsi") == 0) {
2683 os_free(cred->imsi);
2688 if (os_strcmp(var, "milenage") == 0) {
2689 str_clear_free(cred->milenage);
2690 cred->milenage = val;
2694 if (os_strcmp(var, "domain_suffix_match") == 0) {
2695 os_free(cred->domain_suffix_match);
2696 cred->domain_suffix_match = val;
2700 if (os_strcmp(var, "domain") == 0) {
2702 new_domain = os_realloc_array(cred->domain,
2703 cred->num_domain + 1,
2705 if (new_domain == NULL) {
2709 new_domain[cred->num_domain++] = val;
2710 cred->domain = new_domain;
2714 if (os_strcmp(var, "phase1") == 0) {
2715 os_free(cred->phase1);
2720 if (os_strcmp(var, "phase2") == 0) {
2721 os_free(cred->phase2);
2726 if (os_strcmp(var, "roaming_consortium") == 0) {
2727 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2728 wpa_printf(MSG_ERROR, "Line %d: invalid "
2729 "roaming_consortium length %d (3..15 "
2730 "expected)", line, (int) len);
2734 os_memcpy(cred->roaming_consortium, val, len);
2735 cred->roaming_consortium_len = len;
2740 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2741 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2743 wpa_printf(MSG_ERROR, "Line %d: invalid "
2744 "required_roaming_consortium length %d "
2745 "(3..15 expected)", line, (int) len);
2749 os_memcpy(cred->required_roaming_consortium, val, len);
2750 cred->required_roaming_consortium_len = len;
2755 if (os_strcmp(var, "excluded_ssid") == 0) {
2756 struct excluded_ssid *e;
2758 if (len > MAX_SSID_LEN) {
2759 wpa_printf(MSG_ERROR, "Line %d: invalid "
2760 "excluded_ssid length %d", line, (int) len);
2765 e = os_realloc_array(cred->excluded_ssid,
2766 cred->num_excluded_ssid + 1,
2767 sizeof(struct excluded_ssid));
2772 cred->excluded_ssid = e;
2774 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2775 os_memcpy(e->ssid, val, len);
2783 if (os_strcmp(var, "roaming_partner") == 0) {
2784 struct roaming_partner *p;
2787 p = os_realloc_array(cred->roaming_partner,
2788 cred->num_roaming_partner + 1,
2789 sizeof(struct roaming_partner));
2794 cred->roaming_partner = p;
2796 p = &cred->roaming_partner[cred->num_roaming_partner];
2798 pos = os_strchr(val, ',');
2804 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2808 os_memcpy(p->fqdn, val, pos - val);
2810 p->exact_match = atoi(pos);
2812 pos = os_strchr(pos, ',');
2819 p->priority = atoi(pos);
2821 pos = os_strchr(pos, ',');
2828 if (os_strlen(pos) >= sizeof(p->country)) {
2832 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2834 cred->num_roaming_partner++;
2840 if (os_strcmp(var, "provisioning_sp") == 0) {
2841 os_free(cred->provisioning_sp);
2842 cred->provisioning_sp = val;
2847 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2857 static char * alloc_int_str(int val)
2861 buf = os_malloc(20);
2864 os_snprintf(buf, 20, "%d", val);
2869 static char * alloc_strdup(const char *str)
2873 return os_strdup(str);
2877 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2879 if (os_strcmp(var, "temporary") == 0)
2880 return alloc_int_str(cred->temporary);
2882 if (os_strcmp(var, "priority") == 0)
2883 return alloc_int_str(cred->priority);
2885 if (os_strcmp(var, "sp_priority") == 0)
2886 return alloc_int_str(cred->sp_priority);
2888 if (os_strcmp(var, "pcsc") == 0)
2889 return alloc_int_str(cred->pcsc);
2891 if (os_strcmp(var, "eap") == 0) {
2892 if (!cred->eap_method)
2894 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2895 cred->eap_method[0].method));
2898 if (os_strcmp(var, "update_identifier") == 0)
2899 return alloc_int_str(cred->update_identifier);
2901 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
2902 return alloc_int_str(cred->min_dl_bandwidth_home);
2904 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
2905 return alloc_int_str(cred->min_ul_bandwidth_home);
2907 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
2908 return alloc_int_str(cred->min_dl_bandwidth_roaming);
2910 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
2911 return alloc_int_str(cred->min_ul_bandwidth_roaming);
2913 if (os_strcmp(var, "max_bss_load") == 0)
2914 return alloc_int_str(cred->max_bss_load);
2916 if (os_strcmp(var, "req_conn_capab") == 0) {
2918 char *buf, *end, *pos;
2921 if (!cred->num_req_conn_capab)
2924 buf = os_malloc(4000);
2929 for (i = 0; i < cred->num_req_conn_capab; i++) {
2932 ret = os_snprintf(pos, end - pos, "%s%u",
2934 cred->req_conn_capab_proto[i]);
2935 if (ret < 0 || ret >= end - pos)
2939 ports = cred->req_conn_capab_port[i];
2942 for (j = 0; ports[j] != -1; j++) {
2943 ret = os_snprintf(pos, end - pos,
2947 if (ret < 0 || ret >= end - pos)
2957 if (os_strcmp(var, "ocsp") == 0)
2958 return alloc_int_str(cred->ocsp);
2960 if (os_strcmp(var, "realm") == 0)
2961 return alloc_strdup(cred->realm);
2963 if (os_strcmp(var, "username") == 0)
2964 return alloc_strdup(cred->username);
2966 if (os_strcmp(var, "password") == 0) {
2967 if (!cred->password)
2969 return alloc_strdup("*");
2972 if (os_strcmp(var, "ca_cert") == 0)
2973 return alloc_strdup(cred->ca_cert);
2975 if (os_strcmp(var, "client_cert") == 0)
2976 return alloc_strdup(cred->client_cert);
2978 if (os_strcmp(var, "private_key") == 0)
2979 return alloc_strdup(cred->private_key);
2981 if (os_strcmp(var, "private_key_passwd") == 0) {
2982 if (!cred->private_key_passwd)
2984 return alloc_strdup("*");
2987 if (os_strcmp(var, "imsi") == 0)
2988 return alloc_strdup(cred->imsi);
2990 if (os_strcmp(var, "milenage") == 0) {
2991 if (!(cred->milenage))
2993 return alloc_strdup("*");
2996 if (os_strcmp(var, "domain_suffix_match") == 0)
2997 return alloc_strdup(cred->domain_suffix_match);
2999 if (os_strcmp(var, "domain") == 0) {
3001 char *buf, *end, *pos;
3004 if (!cred->num_domain)
3007 buf = os_malloc(4000);
3013 for (i = 0; i < cred->num_domain; i++) {
3014 ret = os_snprintf(pos, end - pos, "%s%s",
3015 i > 0 ? "\n" : "", cred->domain[i]);
3016 if (ret < 0 || ret >= end - pos)
3024 if (os_strcmp(var, "phase1") == 0)
3025 return alloc_strdup(cred->phase1);
3027 if (os_strcmp(var, "phase2") == 0)
3028 return alloc_strdup(cred->phase2);
3030 if (os_strcmp(var, "roaming_consortium") == 0) {
3034 if (!cred->roaming_consortium_len)
3036 buflen = cred->roaming_consortium_len * 2 + 1;
3037 buf = os_malloc(buflen);
3040 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3041 cred->roaming_consortium_len);
3045 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3049 if (!cred->required_roaming_consortium_len)
3051 buflen = cred->required_roaming_consortium_len * 2 + 1;
3052 buf = os_malloc(buflen);
3055 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3056 cred->required_roaming_consortium_len);
3060 if (os_strcmp(var, "excluded_ssid") == 0) {
3062 char *buf, *end, *pos;
3064 if (!cred->num_excluded_ssid)
3067 buf = os_malloc(4000);
3073 for (i = 0; i < cred->num_excluded_ssid; i++) {
3074 struct excluded_ssid *e;
3077 e = &cred->excluded_ssid[i];
3078 ret = os_snprintf(pos, end - pos, "%s%s",
3080 wpa_ssid_txt(e->ssid, e->ssid_len));
3081 if (ret < 0 || ret >= end - pos)
3089 if (os_strcmp(var, "roaming_partner") == 0) {
3091 char *buf, *end, *pos;
3093 if (!cred->num_roaming_partner)
3096 buf = os_malloc(4000);
3102 for (i = 0; i < cred->num_roaming_partner; i++) {
3103 struct roaming_partner *p;
3106 p = &cred->roaming_partner[i];
3107 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3109 p->fqdn, p->exact_match, p->priority,
3111 if (ret < 0 || ret >= end - pos)
3119 if (os_strcmp(var, "provisioning_sp") == 0)
3120 return alloc_strdup(cred->provisioning_sp);
3126 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3128 struct wpa_cred *cred;
3130 cred = config->cred;
3141 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3144 struct wpa_cred *cred, *last = NULL;
3147 cred = config->cred;
3156 cred = os_zalloc(sizeof(*cred));
3160 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3164 config->cred = cred;
3170 int wpa_config_remove_cred(struct wpa_config *config, int id)
3172 struct wpa_cred *cred, *prev = NULL;
3174 cred = config->cred;
3186 prev->next = cred->next;
3188 config->cred = cred->next;
3190 wpa_config_free_cred(cred);
3195 #ifndef CONFIG_NO_CONFIG_BLOBS
3197 * wpa_config_get_blob - Get a named configuration blob
3198 * @config: Configuration data from wpa_config_read()
3199 * @name: Name of the blob
3200 * Returns: Pointer to blob data or %NULL if not found
3202 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3205 struct wpa_config_blob *blob = config->blobs;
3208 if (os_strcmp(blob->name, name) == 0)
3217 * wpa_config_set_blob - Set or add a named configuration blob
3218 * @config: Configuration data from wpa_config_read()
3219 * @blob: New value for the blob
3221 * Adds a new configuration blob or replaces the current value of an existing
3224 void wpa_config_set_blob(struct wpa_config *config,
3225 struct wpa_config_blob *blob)
3227 wpa_config_remove_blob(config, blob->name);
3228 blob->next = config->blobs;
3229 config->blobs = blob;
3234 * wpa_config_free_blob - Free blob data
3235 * @blob: Pointer to blob to be freed
3237 void wpa_config_free_blob(struct wpa_config_blob *blob)
3240 os_free(blob->name);
3241 bin_clear_free(blob->data, blob->len);
3248 * wpa_config_remove_blob - Remove a named configuration blob
3249 * @config: Configuration data from wpa_config_read()
3250 * @name: Name of the blob to remove
3251 * Returns: 0 if blob was removed or -1 if blob was not found
3253 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3255 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3258 if (os_strcmp(pos->name, name) == 0) {
3260 prev->next = pos->next;
3262 config->blobs = pos->next;
3263 wpa_config_free_blob(pos);
3272 #endif /* CONFIG_NO_CONFIG_BLOBS */
3276 * wpa_config_alloc_empty - Allocate an empty configuration
3277 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3279 * @driver_param: Driver parameters
3280 * Returns: Pointer to allocated configuration data or %NULL on failure
3282 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3283 const char *driver_param)
3285 struct wpa_config *config;
3286 const int aCWmin = 4, aCWmax = 10;
3287 const struct hostapd_wmm_ac_params ac_bk =
3288 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3289 const struct hostapd_wmm_ac_params ac_be =
3290 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3291 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3292 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3293 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3294 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3296 config = os_zalloc(sizeof(*config));
3299 config->eapol_version = DEFAULT_EAPOL_VERSION;
3300 config->ap_scan = DEFAULT_AP_SCAN;
3301 config->fast_reauth = DEFAULT_FAST_REAUTH;
3302 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3303 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3304 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3305 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3306 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3307 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3308 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3309 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3310 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3311 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3312 config->wmm_ac_params[0] = ac_be;
3313 config->wmm_ac_params[1] = ac_bk;
3314 config->wmm_ac_params[2] = ac_vi;
3315 config->wmm_ac_params[3] = ac_vo;
3316 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3317 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3320 config->ctrl_interface = os_strdup(ctrl_interface);
3322 config->driver_param = os_strdup(driver_param);
3328 #ifndef CONFIG_NO_STDOUT_DEBUG
3330 * wpa_config_debug_dump_networks - Debug dump of configured networks
3331 * @config: Configuration data from wpa_config_read()
3333 void wpa_config_debug_dump_networks(struct wpa_config *config)
3336 struct wpa_ssid *ssid;
3338 for (prio = 0; prio < config->num_prio; prio++) {
3339 ssid = config->pssid[prio];
3340 wpa_printf(MSG_DEBUG, "Priority group %d",
3343 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3345 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3350 #endif /* CONFIG_NO_STDOUT_DEBUG */
3353 struct global_parse_data {
3355 int (*parser)(const struct global_parse_data *data,
3356 struct wpa_config *config, int line, const char *value);
3357 void *param1, *param2, *param3;
3358 unsigned int changed_flag;
3362 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3363 struct wpa_config *config, int line,
3369 dst = (int *) (((u8 *) config) + (long) data->param1);
3370 val = strtol(pos, &end, 0);
3372 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3378 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3380 if (data->param2 && *dst < (long) data->param2) {
3381 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3382 "min_value=%ld)", line, data->name, *dst,
3383 (long) data->param2);
3384 *dst = (long) data->param2;
3388 if (data->param3 && *dst > (long) data->param3) {
3389 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3390 "max_value=%ld)", line, data->name, *dst,
3391 (long) data->param3);
3392 *dst = (long) data->param3;
3400 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3401 struct wpa_config *config, int line,
3407 len = os_strlen(pos);
3408 if (data->param2 && len < (size_t) data->param2) {
3409 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3410 "min_len=%ld)", line, data->name,
3411 (unsigned long) len, (long) data->param2);
3415 if (data->param3 && len > (size_t) data->param3) {
3416 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3417 "max_len=%ld)", line, data->name,
3418 (unsigned long) len, (long) data->param3);
3422 tmp = os_strdup(pos);
3426 dst = (char **) (((u8 *) config) + (long) data->param1);
3429 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3435 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3436 struct wpa_config *config, int line,
3443 tmp = wpa_config_parse_string(pos, &len);
3445 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3450 res = wpa_global_config_parse_str(data, config, line, tmp);
3456 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3457 struct wpa_config *config, int line,
3461 struct wpabuf **dst, *tmp;
3463 len = os_strlen(pos);
3467 tmp = wpabuf_alloc(len / 2);
3471 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3476 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3479 wpa_printf(MSG_DEBUG, "%s", data->name);
3485 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3486 struct wpa_config *config, int line,
3491 freqs = wpa_config_parse_int_array(value);
3494 if (freqs[0] == 0) {
3498 os_free(config->freq_list);
3499 config->freq_list = freqs;
3505 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3506 struct wpa_config *config, int line,
3510 struct hostapd_ip_addr addr;
3512 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3514 if (addr.af != AF_INET)
3517 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3518 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3519 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3520 WPA_GET_BE32((u8 *) dst));
3524 #endif /* CONFIG_P2P */
3527 static int wpa_config_process_country(const struct global_parse_data *data,
3528 struct wpa_config *config, int line,
3531 if (!pos[0] || !pos[1]) {
3532 wpa_printf(MSG_DEBUG, "Invalid country set");
3535 config->country[0] = pos[0];
3536 config->country[1] = pos[1];
3537 wpa_printf(MSG_DEBUG, "country='%c%c'",
3538 config->country[0], config->country[1]);
3543 static int wpa_config_process_load_dynamic_eap(
3544 const struct global_parse_data *data, struct wpa_config *config,
3545 int line, const char *so)
3548 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3549 ret = eap_peer_method_load(so);
3551 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3554 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3555 "method '%s'.", line, so);
3565 static int wpa_config_process_uuid(const struct global_parse_data *data,
3566 struct wpa_config *config, int line,
3570 if (uuid_str2bin(pos, config->uuid)) {
3571 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3574 uuid_bin2str(config->uuid, buf, sizeof(buf));
3575 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3580 static int wpa_config_process_device_type(
3581 const struct global_parse_data *data,
3582 struct wpa_config *config, int line, const char *pos)
3584 return wps_dev_type_str2bin(pos, config->device_type);
3588 static int wpa_config_process_os_version(const struct global_parse_data *data,
3589 struct wpa_config *config, int line,
3592 if (hexstr2bin(pos, config->os_version, 4)) {
3593 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3596 wpa_printf(MSG_DEBUG, "os_version=%08x",
3597 WPA_GET_BE32(config->os_version));
3602 static int wpa_config_process_wps_vendor_ext_m1(
3603 const struct global_parse_data *data,
3604 struct wpa_config *config, int line, const char *pos)
3607 int len = os_strlen(pos) / 2;
3611 wpa_printf(MSG_ERROR, "Line %d: "
3612 "invalid wps_vendor_ext_m1", line);
3616 tmp = wpabuf_alloc(len);
3618 p = wpabuf_put(tmp, len);
3620 if (hexstr2bin(pos, p, len)) {
3621 wpa_printf(MSG_ERROR, "Line %d: "
3622 "invalid wps_vendor_ext_m1", line);
3627 wpabuf_free(config->wps_vendor_ext_m1);
3628 config->wps_vendor_ext_m1 = tmp;
3630 wpa_printf(MSG_ERROR, "Can not allocate "
3631 "memory for wps_vendor_ext_m1");
3638 #endif /* CONFIG_WPS */
3641 static int wpa_config_process_sec_device_type(
3642 const struct global_parse_data *data,
3643 struct wpa_config *config, int line, const char *pos)
3647 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3648 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3653 idx = config->num_sec_device_types;
3655 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3658 config->num_sec_device_types++;
3663 static int wpa_config_process_p2p_pref_chan(
3664 const struct global_parse_data *data,
3665 struct wpa_config *config, int line, const char *pos)
3667 struct p2p_channel *pref = NULL, *n;
3668 unsigned int num = 0;
3672 /* format: class:chan,class:chan,... */
3675 op_class = atoi(pos);
3676 pos2 = os_strchr(pos, ':');
3682 n = os_realloc_array(pref, num + 1,
3683 sizeof(struct p2p_channel));
3687 pref[num].op_class = op_class;
3688 pref[num].chan = chan;
3691 pos = os_strchr(pos2, ',');
3697 os_free(config->p2p_pref_chan);
3698 config->p2p_pref_chan = pref;
3699 config->num_p2p_pref_chan = num;
3700 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3701 (u8 *) config->p2p_pref_chan,
3702 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3708 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3713 static int wpa_config_process_p2p_no_go_freq(
3714 const struct global_parse_data *data,
3715 struct wpa_config *config, int line, const char *pos)
3719 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3721 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3725 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3726 config->p2p_no_go_freq.num);
3731 #endif /* CONFIG_P2P */
3734 static int wpa_config_process_hessid(
3735 const struct global_parse_data *data,
3736 struct wpa_config *config, int line, const char *pos)
3738 if (hwaddr_aton2(pos, config->hessid) < 0) {
3739 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3748 static int wpa_config_process_sae_groups(
3749 const struct global_parse_data *data,
3750 struct wpa_config *config, int line, const char *pos)
3752 int *groups = wpa_config_parse_int_array(pos);
3753 if (groups == NULL) {
3754 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3759 os_free(config->sae_groups);
3760 config->sae_groups = groups;
3766 static int wpa_config_process_ap_vendor_elements(
3767 const struct global_parse_data *data,
3768 struct wpa_config *config, int line, const char *pos)
3771 int len = os_strlen(pos) / 2;
3775 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3780 tmp = wpabuf_alloc(len);
3782 p = wpabuf_put(tmp, len);
3784 if (hexstr2bin(pos, p, len)) {
3785 wpa_printf(MSG_ERROR, "Line %d: invalid "
3786 "ap_vendor_elements", line);
3791 wpabuf_free(config->ap_vendor_elements);
3792 config->ap_vendor_elements = tmp;
3794 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3795 "ap_vendor_elements");
3803 #ifdef CONFIG_CTRL_IFACE
3804 static int wpa_config_process_no_ctrl_interface(
3805 const struct global_parse_data *data,
3806 struct wpa_config *config, int line, const char *pos)
3808 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3809 os_free(config->ctrl_interface);
3810 config->ctrl_interface = NULL;
3813 #endif /* CONFIG_CTRL_IFACE */
3819 /* OFFSET: Get offset of a variable within the wpa_config structure */
3820 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3822 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3823 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3824 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3825 #define INT(f) _INT(f), NULL, NULL
3826 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3827 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3828 #define STR(f) _STR(f), NULL, NULL
3829 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3830 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3831 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3833 static const struct global_parse_data global_fields[] = {
3834 #ifdef CONFIG_CTRL_IFACE
3835 { STR(ctrl_interface), 0 },
3836 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3837 { STR(ctrl_interface_group), 0 } /* deprecated */,
3838 #endif /* CONFIG_CTRL_IFACE */
3839 #ifdef CONFIG_MACSEC
3840 { INT_RANGE(eapol_version, 1, 3), 0 },
3841 #else /* CONFIG_MACSEC */
3842 { INT_RANGE(eapol_version, 1, 2), 0 },
3843 #endif /* CONFIG_MACSEC */
3844 { INT(ap_scan), 0 },
3845 { FUNC(bgscan), 0 },
3846 { INT(disable_scan_offload), 0 },
3847 { INT(fast_reauth), 0 },
3848 { STR(opensc_engine_path), 0 },
3849 { STR(pkcs11_engine_path), 0 },
3850 { STR(pkcs11_module_path), 0 },
3851 { STR(openssl_ciphers), 0 },
3852 { STR(pcsc_reader), 0 },
3853 { STR(pcsc_pin), 0 },
3854 { INT(external_sim), 0 },
3855 { STR(driver_param), 0 },
3856 { INT(dot11RSNAConfigPMKLifetime), 0 },
3857 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3858 { INT(dot11RSNAConfigSATimeout), 0 },
3859 #ifndef CONFIG_NO_CONFIG_WRITE
3860 { INT(update_config), 0 },
3861 #endif /* CONFIG_NO_CONFIG_WRITE */
3862 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3864 { FUNC(uuid), CFG_CHANGED_UUID },
3865 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3866 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3867 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3868 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3869 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3870 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3871 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3872 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3873 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3874 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3875 #endif /* CONFIG_WPS */
3877 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3878 { INT(p2p_listen_reg_class), 0 },
3879 { INT(p2p_listen_channel), 0 },
3880 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3881 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3882 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3883 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3884 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3885 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3886 { INT(p2p_group_idle), 0 },
3887 { INT_RANGE(p2p_passphrase_len, 8, 63),
3888 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3889 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3890 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3891 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3892 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3893 { INT(p2p_go_ht40), 0 },
3894 { INT(p2p_go_vht), 0 },
3895 { INT(p2p_disabled), 0 },
3896 { INT(p2p_no_group_iface), 0 },
3897 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
3898 { IPV4(ip_addr_go), 0 },
3899 { IPV4(ip_addr_mask), 0 },
3900 { IPV4(ip_addr_start), 0 },
3901 { IPV4(ip_addr_end), 0 },
3902 #endif /* CONFIG_P2P */
3903 { FUNC(country), CFG_CHANGED_COUNTRY },
3904 { INT(bss_max_count), 0 },
3905 { INT(bss_expiration_age), 0 },
3906 { INT(bss_expiration_scan_count), 0 },
3907 { INT_RANGE(filter_ssids, 0, 1), 0 },
3908 { INT_RANGE(filter_rssi, -100, 0), 0 },
3909 { INT(max_num_sta), 0 },
3910 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3912 { INT_RANGE(hs20, 0, 1), 0 },
3913 #endif /* CONFIG_HS20 */
3914 { INT_RANGE(interworking, 0, 1), 0 },
3915 { FUNC(hessid), 0 },
3916 { INT_RANGE(access_network_type, 0, 15), 0 },
3917 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3918 { STR(autoscan), 0 },
3919 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3920 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3921 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3922 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3923 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3924 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3925 { INT(p2p_go_max_inactivity), 0 },
3926 { INT_RANGE(auto_interworking, 0, 1), 0 },
3929 { FUNC(sae_groups), 0 },
3930 { INT(dtim_period), 0 },
3931 { INT(beacon_int), 0 },
3932 { FUNC(ap_vendor_elements), 0 },
3933 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
3934 { FUNC(freq_list), 0 },
3935 { INT(scan_cur_freq), 0 },
3936 { INT(sched_scan_interval), 0 },
3937 { INT(tdls_external_control), 0},
3938 { STR(osu_dir), 0 },
3939 { STR(wowlan_triggers), 0 },
3940 { INT(p2p_search_delay), 0},
3941 { INT(mac_addr), 0 },
3942 { INT(rand_addr_lifetime), 0 },
3943 { INT(preassoc_mac_addr), 0 },
3955 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
3958 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3963 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3964 const struct global_parse_data *field = &global_fields[i];
3965 size_t flen = os_strlen(field->name);
3966 if (os_strncmp(pos, field->name, flen) != 0 ||
3970 if (field->parser(field, config, line, pos + flen + 1)) {
3971 wpa_printf(MSG_ERROR, "Line %d: failed to "
3972 "parse '%s'.", line, pos);
3975 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
3976 config->wps_nfc_pw_from_config = 1;
3977 config->changed_parameters |= field->changed_flag;
3980 if (i == NUM_GLOBAL_FIELDS) {
3982 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
3983 char *tmp = os_strchr(pos, '=');
3987 wpa_printf(MSG_ERROR, "Line %d: invalid line "
3992 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
3994 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
3999 #endif /* CONFIG_AP */
4002 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",