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 */
538 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
539 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
541 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
553 wpa_printf(MSG_ERROR,
554 "Line %d: no key_mgmt values configured.", line);
558 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
559 ssid->key_mgmt = val;
560 return errors ? -1 : 0;
564 #ifndef NO_CONFIG_WRITE
565 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
566 struct wpa_ssid *ssid)
568 char *buf, *pos, *end;
571 pos = buf = os_zalloc(100);
576 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
577 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
578 pos == buf ? "" : " ");
579 if (ret < 0 || ret >= end - pos) {
586 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
587 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
588 pos == buf ? "" : " ");
589 if (ret < 0 || ret >= end - pos) {
596 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
597 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
598 pos == buf ? "" : " ");
599 if (ret < 0 || ret >= end - pos) {
606 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
607 ret = os_snprintf(pos, end - pos, "%sNONE",
608 pos == buf ? "" : " ");
609 if (ret < 0 || ret >= end - pos) {
616 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
617 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
618 pos == buf ? "" : " ");
619 if (ret < 0 || ret >= end - pos) {
626 #ifdef CONFIG_IEEE80211R
627 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
628 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
629 pos == buf ? "" : " ");
630 if (ret < 0 || ret >= end - pos) {
637 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
638 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
639 pos == buf ? "" : " ");
640 if (ret < 0 || ret >= end - pos) {
646 #endif /* CONFIG_IEEE80211R */
648 #ifdef CONFIG_IEEE80211W
649 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
650 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
651 pos == buf ? "" : " ");
652 if (ret < 0 || ret >= end - pos) {
659 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
660 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
661 pos == buf ? "" : " ");
662 if (ret < 0 || ret >= end - pos) {
668 #endif /* CONFIG_IEEE80211W */
671 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
672 ret = os_snprintf(pos, end - pos, "%sWPS",
673 pos == buf ? "" : " ");
674 if (ret < 0 || ret >= end - pos) {
680 #endif /* CONFIG_WPS */
683 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
684 ret = os_snprintf(pos, end - pos, "%sSAE",
685 pos == buf ? "" : " ");
686 if (ret < 0 || ret >= end - pos) {
693 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
694 ret = os_snprintf(pos, end - pos, "%sFT-SAE",
695 pos == buf ? "" : " ");
696 if (ret < 0 || ret >= end - pos) {
702 #endif /* CONFIG_SAE */
705 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) {
706 ret = os_snprintf(pos, end - pos, "%sOSEN",
707 pos == buf ? "" : " ");
708 if (ret < 0 || ret >= end - pos) {
714 #endif /* CONFIG_HS20 */
716 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
717 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B",
718 pos == buf ? "" : " ");
719 if (ret < 0 || ret >= end - pos) {
733 #endif /* NO_CONFIG_WRITE */
736 static int wpa_config_parse_cipher(int line, const char *value)
738 int val = wpa_parse_cipher(value);
740 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
745 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
753 #ifndef NO_CONFIG_WRITE
754 static char * wpa_config_write_cipher(int cipher)
756 char *buf = os_zalloc(50);
760 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
767 #endif /* NO_CONFIG_WRITE */
770 static int wpa_config_parse_pairwise(const struct parse_data *data,
771 struct wpa_ssid *ssid, int line,
775 val = wpa_config_parse_cipher(line, value);
778 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
779 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
780 "(0x%x).", line, val);
784 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
785 ssid->pairwise_cipher = val;
790 #ifndef NO_CONFIG_WRITE
791 static char * wpa_config_write_pairwise(const struct parse_data *data,
792 struct wpa_ssid *ssid)
794 return wpa_config_write_cipher(ssid->pairwise_cipher);
796 #endif /* NO_CONFIG_WRITE */
799 static int wpa_config_parse_group(const struct parse_data *data,
800 struct wpa_ssid *ssid, int line,
804 val = wpa_config_parse_cipher(line, value);
807 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
808 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
809 "(0x%x).", line, val);
813 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
814 ssid->group_cipher = val;
819 #ifndef NO_CONFIG_WRITE
820 static char * wpa_config_write_group(const struct parse_data *data,
821 struct wpa_ssid *ssid)
823 return wpa_config_write_cipher(ssid->group_cipher);
825 #endif /* NO_CONFIG_WRITE */
828 static int wpa_config_parse_auth_alg(const struct parse_data *data,
829 struct wpa_ssid *ssid, int line,
832 int val = 0, last, errors = 0;
833 char *start, *end, *buf;
835 buf = os_strdup(value);
840 while (*start != '\0') {
841 while (*start == ' ' || *start == '\t')
846 while (*end != ' ' && *end != '\t' && *end != '\0')
850 if (os_strcmp(start, "OPEN") == 0)
851 val |= WPA_AUTH_ALG_OPEN;
852 else if (os_strcmp(start, "SHARED") == 0)
853 val |= WPA_AUTH_ALG_SHARED;
854 else if (os_strcmp(start, "LEAP") == 0)
855 val |= WPA_AUTH_ALG_LEAP;
857 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
869 wpa_printf(MSG_ERROR,
870 "Line %d: no auth_alg values configured.", line);
874 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
875 ssid->auth_alg = val;
876 return errors ? -1 : 0;
880 #ifndef NO_CONFIG_WRITE
881 static char * wpa_config_write_auth_alg(const struct parse_data *data,
882 struct wpa_ssid *ssid)
884 char *buf, *pos, *end;
887 pos = buf = os_zalloc(30);
892 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
893 ret = os_snprintf(pos, end - pos, "%sOPEN",
894 pos == buf ? "" : " ");
895 if (ret < 0 || ret >= end - pos) {
902 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
903 ret = os_snprintf(pos, end - pos, "%sSHARED",
904 pos == buf ? "" : " ");
905 if (ret < 0 || ret >= end - pos) {
912 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
913 ret = os_snprintf(pos, end - pos, "%sLEAP",
914 pos == buf ? "" : " ");
915 if (ret < 0 || ret >= end - pos) {
929 #endif /* NO_CONFIG_WRITE */
932 static int * wpa_config_parse_int_array(const char *value)
940 freqs = os_calloc(len + 1, sizeof(int));
951 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
956 for (i = len; i <= len * 2; i++)
962 freqs[used] = atoi(pos);
963 if (freqs[used] == 0)
966 pos = os_strchr(pos + 1, ' ');
973 static int wpa_config_parse_scan_freq(const struct parse_data *data,
974 struct wpa_ssid *ssid, int line,
979 freqs = wpa_config_parse_int_array(value);
986 os_free(ssid->scan_freq);
987 ssid->scan_freq = freqs;
993 static int wpa_config_parse_freq_list(const struct parse_data *data,
994 struct wpa_ssid *ssid, int line,
999 freqs = wpa_config_parse_int_array(value);
1002 if (freqs[0] == 0) {
1006 os_free(ssid->freq_list);
1007 ssid->freq_list = freqs;
1013 #ifndef NO_CONFIG_WRITE
1014 static char * wpa_config_write_freqs(const struct parse_data *data,
1017 char *buf, *pos, *end;
1025 for (i = 0; freqs[i]; i++)
1028 pos = buf = os_zalloc(10 * count + 1);
1031 end = buf + 10 * count + 1;
1033 for (i = 0; freqs[i]; i++) {
1034 ret = os_snprintf(pos, end - pos, "%s%u",
1035 i == 0 ? "" : " ", freqs[i]);
1036 if (ret < 0 || ret >= end - pos) {
1047 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1048 struct wpa_ssid *ssid)
1050 return wpa_config_write_freqs(data, ssid->scan_freq);
1054 static char * wpa_config_write_freq_list(const struct parse_data *data,
1055 struct wpa_ssid *ssid)
1057 return wpa_config_write_freqs(data, ssid->freq_list);
1059 #endif /* NO_CONFIG_WRITE */
1062 #ifdef IEEE8021X_EAPOL
1063 static int wpa_config_parse_eap(const struct parse_data *data,
1064 struct wpa_ssid *ssid, int line,
1067 int last, errors = 0;
1068 char *start, *end, *buf;
1069 struct eap_method_type *methods = NULL, *tmp;
1070 size_t num_methods = 0;
1072 buf = os_strdup(value);
1077 while (*start != '\0') {
1078 while (*start == ' ' || *start == '\t')
1083 while (*end != ' ' && *end != '\t' && *end != '\0')
1085 last = *end == '\0';
1088 methods = os_realloc_array(methods, num_methods + 1,
1090 if (methods == NULL) {
1095 methods[num_methods].method = eap_peer_get_type(
1096 start, &methods[num_methods].vendor);
1097 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1098 methods[num_methods].method == EAP_TYPE_NONE) {
1099 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1100 "'%s'", line, start);
1101 wpa_printf(MSG_ERROR, "You may need to add support for"
1102 " this EAP method during wpa_supplicant\n"
1103 "build time configuration.\n"
1104 "See README for more information.");
1106 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1107 methods[num_methods].method == EAP_TYPE_LEAP)
1119 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1120 if (methods == NULL) {
1124 methods[num_methods].vendor = EAP_VENDOR_IETF;
1125 methods[num_methods].method = EAP_TYPE_NONE;
1128 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1129 (u8 *) methods, num_methods * sizeof(*methods));
1130 os_free(ssid->eap.eap_methods);
1131 ssid->eap.eap_methods = methods;
1132 return errors ? -1 : 0;
1136 static char * wpa_config_write_eap(const struct parse_data *data,
1137 struct wpa_ssid *ssid)
1140 char *buf, *pos, *end;
1141 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1144 if (eap_methods == NULL)
1147 pos = buf = os_zalloc(100);
1152 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1153 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1154 name = eap_get_name(eap_methods[i].vendor,
1155 eap_methods[i].method);
1157 ret = os_snprintf(pos, end - pos, "%s%s",
1158 pos == buf ? "" : " ", name);
1159 if (ret < 0 || ret >= end - pos)
1171 static int wpa_config_parse_password(const struct parse_data *data,
1172 struct wpa_ssid *ssid, int line,
1177 if (os_strcmp(value, "NULL") == 0) {
1178 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1179 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1180 ssid->eap.password = NULL;
1181 ssid->eap.password_len = 0;
1185 #ifdef CONFIG_EXT_PASSWORD
1186 if (os_strncmp(value, "ext:", 4) == 0) {
1187 char *name = os_strdup(value + 4);
1190 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1191 ssid->eap.password = (u8 *) name;
1192 ssid->eap.password_len = os_strlen(name);
1193 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1194 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1197 #endif /* CONFIG_EXT_PASSWORD */
1199 if (os_strncmp(value, "hash:", 5) != 0) {
1203 tmp = wpa_config_parse_string(value, &res_len);
1205 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1209 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1210 (u8 *) tmp, res_len);
1212 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1213 ssid->eap.password = (u8 *) tmp;
1214 ssid->eap.password_len = res_len;
1215 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1216 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1222 /* NtPasswordHash: hash:<32 hex digits> */
1223 if (os_strlen(value + 5) != 2 * 16) {
1224 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1225 "(expected 32 hex digits)", line);
1229 hash = os_malloc(16);
1233 if (hexstr2bin(value + 5, hash, 16)) {
1235 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1239 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1241 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1242 ssid->eap.password = hash;
1243 ssid->eap.password_len = 16;
1244 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1245 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1251 static char * wpa_config_write_password(const struct parse_data *data,
1252 struct wpa_ssid *ssid)
1256 if (ssid->eap.password == NULL)
1259 #ifdef CONFIG_EXT_PASSWORD
1260 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1261 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1264 os_memcpy(buf, "ext:", 4);
1265 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1268 #endif /* CONFIG_EXT_PASSWORD */
1270 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1271 return wpa_config_write_string(
1272 ssid->eap.password, ssid->eap.password_len);
1275 buf = os_malloc(5 + 32 + 1);
1279 os_memcpy(buf, "hash:", 5);
1280 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1284 #endif /* IEEE8021X_EAPOL */
1287 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1288 const char *value, int idx)
1290 char *buf, title[20];
1293 buf = wpa_config_parse_string(value, len);
1295 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1299 if (*len > MAX_WEP_KEY_LEN) {
1300 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1305 if (*len && *len != 5 && *len != 13 && *len != 16) {
1306 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1307 "this network block will be ignored",
1308 line, (unsigned int) *len);
1310 os_memcpy(key, buf, *len);
1311 str_clear_free(buf);
1312 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1313 if (res >= 0 && (size_t) res < sizeof(title))
1314 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1319 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1320 struct wpa_ssid *ssid, int line,
1323 return wpa_config_parse_wep_key(ssid->wep_key[0],
1324 &ssid->wep_key_len[0], line,
1329 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1330 struct wpa_ssid *ssid, int line,
1333 return wpa_config_parse_wep_key(ssid->wep_key[1],
1334 &ssid->wep_key_len[1], line,
1339 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1340 struct wpa_ssid *ssid, int line,
1343 return wpa_config_parse_wep_key(ssid->wep_key[2],
1344 &ssid->wep_key_len[2], line,
1349 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1350 struct wpa_ssid *ssid, int line,
1353 return wpa_config_parse_wep_key(ssid->wep_key[3],
1354 &ssid->wep_key_len[3], line,
1359 #ifndef NO_CONFIG_WRITE
1360 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1362 if (ssid->wep_key_len[idx] == 0)
1364 return wpa_config_write_string(ssid->wep_key[idx],
1365 ssid->wep_key_len[idx]);
1369 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1370 struct wpa_ssid *ssid)
1372 return wpa_config_write_wep_key(ssid, 0);
1376 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1377 struct wpa_ssid *ssid)
1379 return wpa_config_write_wep_key(ssid, 1);
1383 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1384 struct wpa_ssid *ssid)
1386 return wpa_config_write_wep_key(ssid, 2);
1390 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1391 struct wpa_ssid *ssid)
1393 return wpa_config_write_wep_key(ssid, 3);
1395 #endif /* NO_CONFIG_WRITE */
1400 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1401 struct wpa_ssid *ssid, int line,
1404 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1405 os_strcmp(value, "any") == 0) {
1406 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1407 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1410 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1411 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1415 ssid->bssid_set = 1;
1416 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1417 MAC2STR(ssid->go_p2p_dev_addr));
1422 #ifndef NO_CONFIG_WRITE
1423 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1424 struct wpa_ssid *ssid)
1429 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1432 value = os_malloc(20);
1435 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1436 if (res < 0 || res >= 20) {
1440 value[20 - 1] = '\0';
1443 #endif /* NO_CONFIG_WRITE */
1446 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1447 struct wpa_ssid *ssid, int line,
1451 u8 *buf, *n, addr[ETH_ALEN];
1458 while (pos && *pos) {
1462 if (hwaddr_aton(pos, addr)) {
1464 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1465 "p2p_client_list address '%s'.",
1470 /* continue anyway since this could have been from a
1471 * truncated configuration file line */
1472 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1473 "truncated p2p_client_list address '%s'",
1476 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1482 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1483 os_memcpy(buf, addr, ETH_ALEN);
1485 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1489 pos = os_strchr(pos, ' ');
1492 os_free(ssid->p2p_client_list);
1493 ssid->p2p_client_list = buf;
1494 ssid->num_p2p_clients = count;
1500 #ifndef NO_CONFIG_WRITE
1501 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1502 struct wpa_ssid *ssid)
1504 char *value, *end, *pos;
1508 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1511 value = os_malloc(20 * ssid->num_p2p_clients);
1515 end = value + 20 * ssid->num_p2p_clients;
1517 for (i = ssid->num_p2p_clients; i > 0; i--) {
1518 res = os_snprintf(pos, end - pos, MACSTR " ",
1519 MAC2STR(ssid->p2p_client_list +
1520 (i - 1) * ETH_ALEN));
1521 if (res < 0 || res >= end - pos) {
1533 #endif /* NO_CONFIG_WRITE */
1536 static int wpa_config_parse_psk_list(const struct parse_data *data,
1537 struct wpa_ssid *ssid, int line,
1540 struct psk_list_entry *p;
1543 p = os_zalloc(sizeof(*p));
1548 if (os_strncmp(pos, "P2P-", 4) == 0) {
1553 if (hwaddr_aton(pos, p->addr)) {
1554 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1561 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1568 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1569 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1575 dl_list_add(&ssid->psk_list, &p->list);
1581 #ifndef NO_CONFIG_WRITE
1582 static char * wpa_config_write_psk_list(const struct parse_data *data,
1583 struct wpa_ssid *ssid)
1587 #endif /* NO_CONFIG_WRITE */
1589 #endif /* CONFIG_P2P */
1594 static int wpa_config_parse_mesh_ht_mode(const struct parse_data *data,
1595 struct wpa_ssid *ssid, int line,
1600 if (os_strcmp(value, "NOHT") == 0)
1602 else if (os_strcmp(value, "HT20") == 0)
1604 else if (os_strcmp(value, "HT40-") == 0)
1605 htval = CHAN_HT40MINUS;
1606 else if (os_strcmp(value, "HT40+") == 0)
1607 htval = CHAN_HT40PLUS;
1609 wpa_printf(MSG_ERROR,
1610 "Line %d: no ht_mode configured.", line);
1614 wpa_printf(MSG_MSGDUMP, "mesh_ht_mode: 0x%x", htval);
1615 ssid->mesh_ht_mode = htval;
1620 static int wpa_config_parse_mesh_basic_rates(const struct parse_data *data,
1621 struct wpa_ssid *ssid, int line,
1624 int *rates = wpa_config_parse_int_array(value);
1626 if (rates == NULL) {
1627 wpa_printf(MSG_ERROR, "Line %d: Invalid mesh_basic_rates '%s'",
1631 if (rates[0] == 0) {
1636 os_free(ssid->mesh_basic_rates);
1637 ssid->mesh_basic_rates = rates;
1643 #ifndef NO_CONFIG_WRITE
1645 static char * wpa_config_write_mesh_ht_mode(const struct parse_data *data,
1646 struct wpa_ssid *ssid)
1650 switch (ssid->mesh_ht_mode) {
1660 case CHAN_HT40MINUS:
1667 return val ? os_strdup(val) : NULL;
1671 static char * wpa_config_write_mesh_basic_rates(const struct parse_data *data,
1672 struct wpa_ssid *ssid)
1674 return wpa_config_write_freqs(data, ssid->mesh_basic_rates);
1677 #endif /* NO_CONFIG_WRITE */
1679 #endif /* CONFIG_MESH */
1682 /* Helper macros for network block parser */
1687 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1688 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1690 /* STR: Define a string variable for an ASCII string; f = field name */
1691 #ifdef NO_CONFIG_WRITE
1692 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1693 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1694 #else /* NO_CONFIG_WRITE */
1695 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1696 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1697 #endif /* NO_CONFIG_WRITE */
1698 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1699 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1700 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1701 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1703 /* STR_LEN: Define a string variable with a separate variable for storing the
1704 * data length. Unlike STR(), this can be used to store arbitrary binary data
1705 * (i.e., even nul termination character). */
1706 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1707 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1708 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1709 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1710 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1712 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1713 * explicitly specified. */
1714 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1715 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1716 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1718 #ifdef NO_CONFIG_WRITE
1719 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1720 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1721 #else /* NO_CONFIG_WRITE */
1722 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1723 OFFSET(f), (void *) 0
1724 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1725 OFFSET(eap.f), (void *) 0
1726 #endif /* NO_CONFIG_WRITE */
1728 /* INT: Define an integer variable */
1729 #define INT(f) _INT(f), NULL, NULL, 0
1730 #define INTe(f) _INTe(f), NULL, NULL, 0
1732 /* INT_RANGE: Define an integer variable with allowed value range */
1733 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1735 /* FUNC: Define a configuration variable that uses a custom function for
1736 * parsing and writing the value. */
1737 #ifdef NO_CONFIG_WRITE
1738 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1739 #else /* NO_CONFIG_WRITE */
1740 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1741 NULL, NULL, NULL, NULL
1742 #endif /* NO_CONFIG_WRITE */
1743 #define FUNC(f) _FUNC(f), 0
1744 #define FUNC_KEY(f) _FUNC(f), 1
1747 * Table of network configuration variables. This table is used to parse each
1748 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1749 * that is inside a network block.
1751 * This table is generated using the helper macros defined above and with
1752 * generous help from the C pre-processor. The field name is stored as a string
1753 * into .name and for STR and INT types, the offset of the target buffer within
1754 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1755 * offset to the field containing the length of the configuration variable.
1756 * .param3 and .param4 can be used to mark the allowed range (length for STR
1757 * and value for INT).
1759 * For each configuration line in wpa_supplicant.conf, the parser goes through
1760 * this table and select the entry that matches with the field name. The parser
1761 * function (.parser) is then called to parse the actual value of the field.
1763 * This kind of mechanism makes it easy to add new configuration parameters,
1764 * since only one line needs to be added into this table and into the
1765 * struct wpa_ssid definition if the new variable is either a string or
1766 * integer. More complex types will need to use their own parser and writer
1769 static const struct parse_data ssid_fields[] = {
1770 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1771 { INT_RANGE(scan_ssid, 0, 1) },
1776 { INT(bg_scan_period) },
1780 { FUNC(scan_freq) },
1781 { FUNC(freq_list) },
1782 #ifdef IEEE8021X_EAPOL
1784 { STR_LENe(identity) },
1785 { STR_LENe(anonymous_identity) },
1786 { FUNC_KEY(password) },
1789 { STRe(client_cert) },
1790 { STRe(private_key) },
1791 { STR_KEYe(private_key_passwd) },
1793 { STRe(subject_match) },
1794 { STRe(altsubject_match) },
1795 { STRe(domain_suffix_match) },
1798 { STRe(client_cert2) },
1799 { STRe(private_key2) },
1800 { STR_KEYe(private_key2_passwd) },
1802 { STRe(subject_match2) },
1803 { STRe(altsubject_match2) },
1804 { STRe(domain_suffix_match2) },
1809 { STRe(engine_id) },
1812 { STRe(ca_cert_id) },
1814 { STRe(engine2_id) },
1817 { STRe(ca_cert2_id) },
1820 { INT(eapol_flags) },
1822 { STRe(openssl_ciphers) },
1823 #endif /* IEEE8021X_EAPOL */
1824 { FUNC_KEY(wep_key0) },
1825 { FUNC_KEY(wep_key1) },
1826 { FUNC_KEY(wep_key2) },
1827 { FUNC_KEY(wep_key3) },
1828 { INT(wep_tx_keyidx) },
1830 #ifdef IEEE8021X_EAPOL
1831 { INT(eap_workaround) },
1833 { INTe(fragment_size) },
1835 #endif /* IEEE8021X_EAPOL */
1837 { INT_RANGE(mode, 0, 5) },
1838 { INT_RANGE(no_auto_peer, 0, 1) },
1839 #else /* CONFIG_MESH */
1840 { INT_RANGE(mode, 0, 4) },
1841 #endif /* CONFIG_MESH */
1842 { INT_RANGE(proactive_key_caching, 0, 1) },
1843 { INT_RANGE(disabled, 0, 2) },
1845 #ifdef CONFIG_IEEE80211W
1846 { INT_RANGE(ieee80211w, 0, 2) },
1847 #endif /* CONFIG_IEEE80211W */
1848 { INT_RANGE(peerkey, 0, 1) },
1849 { INT_RANGE(mixed_cell, 0, 1) },
1850 { INT_RANGE(frequency, 0, 65000) },
1852 { FUNC(mesh_ht_mode) },
1853 { FUNC(mesh_basic_rates) },
1854 #endif /* CONFIG_MESH */
1855 { INT(wpa_ptk_rekey) },
1857 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1859 { FUNC(go_p2p_dev_addr) },
1860 { FUNC(p2p_client_list) },
1862 #endif /* CONFIG_P2P */
1863 #ifdef CONFIG_HT_OVERRIDES
1864 { INT_RANGE(disable_ht, 0, 1) },
1865 { INT_RANGE(disable_ht40, -1, 1) },
1866 { INT_RANGE(disable_sgi, 0, 1) },
1867 { INT_RANGE(disable_ldpc, 0, 1) },
1868 { INT_RANGE(ht40_intolerant, 0, 1) },
1869 { INT_RANGE(disable_max_amsdu, -1, 1) },
1870 { INT_RANGE(ampdu_factor, -1, 3) },
1871 { INT_RANGE(ampdu_density, -1, 7) },
1873 #endif /* CONFIG_HT_OVERRIDES */
1874 #ifdef CONFIG_VHT_OVERRIDES
1875 { INT_RANGE(disable_vht, 0, 1) },
1877 { INT(vht_capa_mask) },
1878 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1879 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1880 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1881 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1882 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1883 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1884 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1885 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1886 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1887 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1888 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1889 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1890 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1891 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1892 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1893 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1894 #endif /* CONFIG_VHT_OVERRIDES */
1895 { INT(ap_max_inactivity) },
1896 { INT(dtim_period) },
1897 { INT(beacon_int) },
1898 #ifdef CONFIG_MACSEC
1899 { INT_RANGE(macsec_policy, 0, 1) },
1900 #endif /* CONFIG_MACSEC */
1902 { INT(update_identifier) },
1903 #endif /* CONFIG_HS20 */
1904 { INT_RANGE(mac_addr, 0, 2) },
1916 #undef STR_RANGE_KEY
1923 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1927 * wpa_config_add_prio_network - Add a network to priority lists
1928 * @config: Configuration data from wpa_config_read()
1929 * @ssid: Pointer to the network configuration to be added to the list
1930 * Returns: 0 on success, -1 on failure
1932 * This function is used to add a network block to the priority list of
1933 * networks. This must be called for each network when reading in the full
1934 * configuration. In addition, this can be used indirectly when updating
1935 * priorities by calling wpa_config_update_prio_list().
1937 int wpa_config_add_prio_network(struct wpa_config *config,
1938 struct wpa_ssid *ssid)
1941 struct wpa_ssid *prev, **nlist;
1944 * Add to an existing priority list if one is available for the
1945 * configured priority level for this network.
1947 for (prio = 0; prio < config->num_prio; prio++) {
1948 prev = config->pssid[prio];
1949 if (prev->priority == ssid->priority) {
1957 /* First network for this priority - add a new priority list */
1958 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1959 sizeof(struct wpa_ssid *));
1963 for (prio = 0; prio < config->num_prio; prio++) {
1964 if (nlist[prio]->priority < ssid->priority) {
1965 os_memmove(&nlist[prio + 1], &nlist[prio],
1966 (config->num_prio - prio) *
1967 sizeof(struct wpa_ssid *));
1974 config->pssid = nlist;
1981 * wpa_config_update_prio_list - Update network priority list
1982 * @config: Configuration data from wpa_config_read()
1983 * Returns: 0 on success, -1 on failure
1985 * This function is called to update the priority list of networks in the
1986 * configuration when a network is being added or removed. This is also called
1987 * if a priority for a network is changed.
1989 int wpa_config_update_prio_list(struct wpa_config *config)
1991 struct wpa_ssid *ssid;
1994 os_free(config->pssid);
1995 config->pssid = NULL;
1996 config->num_prio = 0;
1998 ssid = config->ssid;
2001 if (wpa_config_add_prio_network(config, ssid) < 0)
2010 #ifdef IEEE8021X_EAPOL
2011 static void eap_peer_config_free(struct eap_peer_config *eap)
2013 os_free(eap->eap_methods);
2014 bin_clear_free(eap->identity, eap->identity_len);
2015 os_free(eap->anonymous_identity);
2016 bin_clear_free(eap->password, eap->password_len);
2017 os_free(eap->ca_cert);
2018 os_free(eap->ca_path);
2019 os_free(eap->client_cert);
2020 os_free(eap->private_key);
2021 str_clear_free(eap->private_key_passwd);
2022 os_free(eap->dh_file);
2023 os_free(eap->subject_match);
2024 os_free(eap->altsubject_match);
2025 os_free(eap->domain_suffix_match);
2026 os_free(eap->ca_cert2);
2027 os_free(eap->ca_path2);
2028 os_free(eap->client_cert2);
2029 os_free(eap->private_key2);
2030 str_clear_free(eap->private_key2_passwd);
2031 os_free(eap->dh_file2);
2032 os_free(eap->subject_match2);
2033 os_free(eap->altsubject_match2);
2034 os_free(eap->domain_suffix_match2);
2035 os_free(eap->phase1);
2036 os_free(eap->phase2);
2038 str_clear_free(eap->pin);
2039 os_free(eap->engine_id);
2040 os_free(eap->key_id);
2041 os_free(eap->cert_id);
2042 os_free(eap->ca_cert_id);
2043 os_free(eap->key2_id);
2044 os_free(eap->cert2_id);
2045 os_free(eap->ca_cert2_id);
2046 str_clear_free(eap->pin2);
2047 os_free(eap->engine2_id);
2049 os_free(eap->pending_req_otp);
2050 os_free(eap->pac_file);
2051 bin_clear_free(eap->new_password, eap->new_password_len);
2052 str_clear_free(eap->external_sim_resp);
2053 os_free(eap->openssl_ciphers);
2055 #endif /* IEEE8021X_EAPOL */
2059 * wpa_config_free_ssid - Free network/ssid configuration data
2060 * @ssid: Configuration data for the network
2062 * This function frees all resources allocated for the network configuration
2065 void wpa_config_free_ssid(struct wpa_ssid *ssid)
2067 struct psk_list_entry *psk;
2069 os_free(ssid->ssid);
2070 os_memset(ssid->psk, 0, sizeof(ssid->psk));
2071 str_clear_free(ssid->passphrase);
2072 os_free(ssid->ext_psk);
2073 #ifdef IEEE8021X_EAPOL
2074 eap_peer_config_free(&ssid->eap);
2075 #endif /* IEEE8021X_EAPOL */
2076 os_free(ssid->id_str);
2077 os_free(ssid->scan_freq);
2078 os_free(ssid->freq_list);
2079 os_free(ssid->bgscan);
2080 os_free(ssid->p2p_client_list);
2081 #ifdef CONFIG_HT_OVERRIDES
2082 os_free(ssid->ht_mcs);
2083 #endif /* CONFIG_HT_OVERRIDES */
2085 os_free(ssid->mesh_basic_rates);
2086 #endif /* CONFIG_MESH */
2087 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
2089 dl_list_del(&psk->list);
2096 void wpa_config_free_cred(struct wpa_cred *cred)
2100 os_free(cred->realm);
2101 str_clear_free(cred->username);
2102 str_clear_free(cred->password);
2103 os_free(cred->ca_cert);
2104 os_free(cred->client_cert);
2105 os_free(cred->private_key);
2106 str_clear_free(cred->private_key_passwd);
2107 os_free(cred->imsi);
2108 str_clear_free(cred->milenage);
2109 for (i = 0; i < cred->num_domain; i++)
2110 os_free(cred->domain[i]);
2111 os_free(cred->domain);
2112 os_free(cred->domain_suffix_match);
2113 os_free(cred->eap_method);
2114 os_free(cred->phase1);
2115 os_free(cred->phase2);
2116 os_free(cred->excluded_ssid);
2117 os_free(cred->roaming_partner);
2118 os_free(cred->provisioning_sp);
2119 for (i = 0; i < cred->num_req_conn_capab; i++)
2120 os_free(cred->req_conn_capab_port[i]);
2121 os_free(cred->req_conn_capab_port);
2122 os_free(cred->req_conn_capab_proto);
2127 void wpa_config_flush_blobs(struct wpa_config *config)
2129 #ifndef CONFIG_NO_CONFIG_BLOBS
2130 struct wpa_config_blob *blob, *prev;
2132 blob = config->blobs;
2133 config->blobs = NULL;
2137 wpa_config_free_blob(prev);
2139 #endif /* CONFIG_NO_CONFIG_BLOBS */
2144 * wpa_config_free - Free configuration data
2145 * @config: Configuration data from wpa_config_read()
2147 * This function frees all resources allocated for the configuration data by
2148 * wpa_config_read().
2150 void wpa_config_free(struct wpa_config *config)
2152 struct wpa_ssid *ssid, *prev = NULL;
2153 struct wpa_cred *cred, *cprev;
2155 ssid = config->ssid;
2159 wpa_config_free_ssid(prev);
2162 cred = config->cred;
2166 wpa_config_free_cred(cprev);
2169 wpa_config_flush_blobs(config);
2171 wpabuf_free(config->wps_vendor_ext_m1);
2172 os_free(config->ctrl_interface);
2173 os_free(config->ctrl_interface_group);
2174 os_free(config->opensc_engine_path);
2175 os_free(config->pkcs11_engine_path);
2176 os_free(config->pkcs11_module_path);
2177 os_free(config->openssl_ciphers);
2178 os_free(config->pcsc_reader);
2179 str_clear_free(config->pcsc_pin);
2180 os_free(config->driver_param);
2181 os_free(config->device_name);
2182 os_free(config->manufacturer);
2183 os_free(config->model_name);
2184 os_free(config->model_number);
2185 os_free(config->serial_number);
2186 os_free(config->config_methods);
2187 os_free(config->p2p_ssid_postfix);
2188 os_free(config->pssid);
2189 os_free(config->p2p_pref_chan);
2190 os_free(config->p2p_no_go_freq.range);
2191 os_free(config->autoscan);
2192 os_free(config->freq_list);
2193 wpabuf_free(config->wps_nfc_dh_pubkey);
2194 wpabuf_free(config->wps_nfc_dh_privkey);
2195 wpabuf_free(config->wps_nfc_dev_pw);
2196 os_free(config->ext_password_backend);
2197 os_free(config->sae_groups);
2198 wpabuf_free(config->ap_vendor_elements);
2199 os_free(config->osu_dir);
2200 os_free(config->wowlan_triggers);
2206 * wpa_config_foreach_network - Iterate over each configured network
2207 * @config: Configuration data from wpa_config_read()
2208 * @func: Callback function to process each network
2209 * @arg: Opaque argument to pass to callback function
2211 * Iterate over the set of configured networks calling the specified
2212 * function for each item. We guard against callbacks removing the
2215 void wpa_config_foreach_network(struct wpa_config *config,
2216 void (*func)(void *, struct wpa_ssid *),
2219 struct wpa_ssid *ssid, *next;
2221 ssid = config->ssid;
2231 * wpa_config_get_network - Get configured network based on id
2232 * @config: Configuration data from wpa_config_read()
2233 * @id: Unique network id to search for
2234 * Returns: Network configuration or %NULL if not found
2236 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2238 struct wpa_ssid *ssid;
2240 ssid = config->ssid;
2252 * wpa_config_add_network - Add a new network with empty configuration
2253 * @config: Configuration data from wpa_config_read()
2254 * Returns: The new network configuration or %NULL if operation failed
2256 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2259 struct wpa_ssid *ssid, *last = NULL;
2262 ssid = config->ssid;
2271 ssid = os_zalloc(sizeof(*ssid));
2275 dl_list_init(&ssid->psk_list);
2279 config->ssid = ssid;
2281 wpa_config_update_prio_list(config);
2288 * wpa_config_remove_network - Remove a configured network based on id
2289 * @config: Configuration data from wpa_config_read()
2290 * @id: Unique network id to search for
2291 * Returns: 0 on success, or -1 if the network was not found
2293 int wpa_config_remove_network(struct wpa_config *config, int id)
2295 struct wpa_ssid *ssid, *prev = NULL;
2297 ssid = config->ssid;
2309 prev->next = ssid->next;
2311 config->ssid = ssid->next;
2313 wpa_config_update_prio_list(config);
2314 wpa_config_free_ssid(ssid);
2320 * wpa_config_set_network_defaults - Set network default values
2321 * @ssid: Pointer to network configuration data
2323 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2325 ssid->proto = DEFAULT_PROTO;
2326 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2327 ssid->group_cipher = DEFAULT_GROUP;
2328 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2329 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2330 #ifdef IEEE8021X_EAPOL
2331 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2332 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2333 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2334 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2335 #endif /* IEEE8021X_EAPOL */
2337 ssid->mesh_ht_mode = DEFAULT_MESH_HT_MODE;
2338 #endif /* CONFIG_MESH */
2339 #ifdef CONFIG_HT_OVERRIDES
2340 ssid->disable_ht = DEFAULT_DISABLE_HT;
2341 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2342 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2343 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2344 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2345 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2346 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2347 #endif /* CONFIG_HT_OVERRIDES */
2348 #ifdef CONFIG_VHT_OVERRIDES
2349 ssid->vht_rx_mcs_nss_1 = -1;
2350 ssid->vht_rx_mcs_nss_2 = -1;
2351 ssid->vht_rx_mcs_nss_3 = -1;
2352 ssid->vht_rx_mcs_nss_4 = -1;
2353 ssid->vht_rx_mcs_nss_5 = -1;
2354 ssid->vht_rx_mcs_nss_6 = -1;
2355 ssid->vht_rx_mcs_nss_7 = -1;
2356 ssid->vht_rx_mcs_nss_8 = -1;
2357 ssid->vht_tx_mcs_nss_1 = -1;
2358 ssid->vht_tx_mcs_nss_2 = -1;
2359 ssid->vht_tx_mcs_nss_3 = -1;
2360 ssid->vht_tx_mcs_nss_4 = -1;
2361 ssid->vht_tx_mcs_nss_5 = -1;
2362 ssid->vht_tx_mcs_nss_6 = -1;
2363 ssid->vht_tx_mcs_nss_7 = -1;
2364 ssid->vht_tx_mcs_nss_8 = -1;
2365 #endif /* CONFIG_VHT_OVERRIDES */
2366 ssid->proactive_key_caching = -1;
2367 #ifdef CONFIG_IEEE80211W
2368 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2369 #endif /* CONFIG_IEEE80211W */
2370 ssid->mac_addr = -1;
2375 * wpa_config_set - Set a variable in network configuration
2376 * @ssid: Pointer to network configuration data
2377 * @var: Variable name, e.g., "ssid"
2378 * @value: Variable value
2379 * @line: Line number in configuration file or 0 if not used
2380 * Returns: 0 on success, -1 on failure
2382 * This function can be used to set network configuration variables based on
2383 * both the configuration file and management interface input. The value
2384 * parameter must be in the same format as the text-based configuration file is
2385 * using. For example, strings are using double quotation marks.
2387 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2393 if (ssid == NULL || var == NULL || value == NULL)
2396 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2397 const struct parse_data *field = &ssid_fields[i];
2398 if (os_strcmp(var, field->name) != 0)
2401 if (field->parser(field, ssid, line, value)) {
2403 wpa_printf(MSG_ERROR, "Line %d: failed to "
2404 "parse %s '%s'.", line, var, value);
2410 if (i == NUM_SSID_FIELDS) {
2412 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2413 "'%s'.", line, var);
2422 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2429 len = os_strlen(value);
2430 buf = os_malloc(len + 3);
2434 os_memcpy(buf + 1, value, len);
2436 buf[len + 2] = '\0';
2437 ret = wpa_config_set(ssid, var, buf, 0);
2444 * wpa_config_get_all - Get all options from network configuration
2445 * @ssid: Pointer to network configuration data
2446 * @get_keys: Determines if keys/passwords will be included in returned list
2447 * (if they may be exported)
2448 * Returns: %NULL terminated list of all set keys and their values in the form
2449 * of [key1, val1, key2, val2, ... , NULL]
2451 * This function can be used to get list of all configured network properties.
2452 * The caller is responsible for freeing the returned list and all its
2455 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2457 const struct parse_data *field;
2463 get_keys = get_keys && ssid->export_keys;
2465 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2470 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2471 field = &ssid_fields[i];
2472 if (field->key_data && !get_keys)
2474 value = field->writer(field, ssid);
2477 if (os_strlen(value) == 0) {
2482 key = os_strdup(field->name);
2488 props[fields_num * 2] = key;
2489 props[fields_num * 2 + 1] = value;
2505 #ifndef NO_CONFIG_WRITE
2507 * wpa_config_get - Get a variable in network configuration
2508 * @ssid: Pointer to network configuration data
2509 * @var: Variable name, e.g., "ssid"
2510 * Returns: Value of the variable or %NULL on failure
2512 * This function can be used to get network configuration variables. The
2513 * returned value is a copy of the configuration variable in text format, i.e,.
2514 * the same format that the text-based configuration file and wpa_config_set()
2515 * are using for the value. The caller is responsible for freeing the returned
2518 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2522 if (ssid == NULL || var == NULL)
2525 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2526 const struct parse_data *field = &ssid_fields[i];
2527 if (os_strcmp(var, field->name) == 0)
2528 return field->writer(field, ssid);
2536 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2537 * @ssid: Pointer to network configuration data
2538 * @var: Variable name, e.g., "ssid"
2539 * Returns: Value of the variable or %NULL on failure
2541 * This function can be used to get network configuration variable like
2542 * wpa_config_get(). The only difference is that this functions does not expose
2543 * key/password material from the configuration. In case a key/password field
2544 * is requested, the returned value is an empty string or %NULL if the variable
2545 * is not set or "*" if the variable is set (regardless of its value). The
2546 * returned value is a copy of the configuration variable in text format, i.e,.
2547 * the same format that the text-based configuration file and wpa_config_set()
2548 * are using for the value. The caller is responsible for freeing the returned
2551 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2555 if (ssid == NULL || var == NULL)
2558 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2559 const struct parse_data *field = &ssid_fields[i];
2560 if (os_strcmp(var, field->name) == 0) {
2561 char *res = field->writer(field, ssid);
2562 if (field->key_data) {
2563 if (res && res[0]) {
2564 wpa_printf(MSG_DEBUG, "Do not allow "
2565 "key_data field to be "
2567 str_clear_free(res);
2568 return os_strdup("*");
2580 #endif /* NO_CONFIG_WRITE */
2584 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2585 * @ssid: Pointer to network configuration data
2587 * This function must be called to update WPA PSK when either SSID or the
2588 * passphrase has changed for the network configuration.
2590 void wpa_config_update_psk(struct wpa_ssid *ssid)
2592 #ifndef CONFIG_NO_PBKDF2
2593 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2594 ssid->psk, PMK_LEN);
2595 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2596 ssid->psk, PMK_LEN);
2598 #endif /* CONFIG_NO_PBKDF2 */
2602 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2607 int *ports, *nports;
2609 unsigned int num_ports;
2611 proto = os_realloc_array(cred->req_conn_capab_proto,
2612 cred->num_req_conn_capab + 1, sizeof(u8));
2615 cred->req_conn_capab_proto = proto;
2617 port = os_realloc_array(cred->req_conn_capab_port,
2618 cred->num_req_conn_capab + 1, sizeof(int *));
2621 cred->req_conn_capab_port = port;
2623 proto[cred->num_req_conn_capab] = atoi(value);
2625 pos = os_strchr(value, ':');
2627 port[cred->num_req_conn_capab] = NULL;
2628 cred->num_req_conn_capab++;
2637 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2638 if (nports == NULL) {
2643 ports[num_ports++] = atoi(pos);
2645 pos = os_strchr(pos, ',');
2651 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2652 if (nports == NULL) {
2657 ports[num_ports] = -1;
2659 port[cred->num_req_conn_capab] = ports;
2660 cred->num_req_conn_capab++;
2665 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2666 const char *value, int line)
2671 if (os_strcmp(var, "temporary") == 0) {
2672 cred->temporary = atoi(value);
2676 if (os_strcmp(var, "priority") == 0) {
2677 cred->priority = atoi(value);
2681 if (os_strcmp(var, "sp_priority") == 0) {
2682 int prio = atoi(value);
2683 if (prio < 0 || prio > 255)
2685 cred->sp_priority = prio;
2689 if (os_strcmp(var, "pcsc") == 0) {
2690 cred->pcsc = atoi(value);
2694 if (os_strcmp(var, "eap") == 0) {
2695 struct eap_method_type method;
2696 method.method = eap_peer_get_type(value, &method.vendor);
2697 if (method.vendor == EAP_VENDOR_IETF &&
2698 method.method == EAP_TYPE_NONE) {
2699 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2700 "for a credential", line, value);
2703 os_free(cred->eap_method);
2704 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2705 if (cred->eap_method == NULL)
2707 os_memcpy(cred->eap_method, &method, sizeof(method));
2711 if (os_strcmp(var, "password") == 0 &&
2712 os_strncmp(value, "ext:", 4) == 0) {
2713 str_clear_free(cred->password);
2714 cred->password = os_strdup(value);
2715 cred->ext_password = 1;
2719 if (os_strcmp(var, "update_identifier") == 0) {
2720 cred->update_identifier = atoi(value);
2724 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2725 cred->min_dl_bandwidth_home = atoi(value);
2729 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2730 cred->min_ul_bandwidth_home = atoi(value);
2734 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2735 cred->min_dl_bandwidth_roaming = atoi(value);
2739 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2740 cred->min_ul_bandwidth_roaming = atoi(value);
2744 if (os_strcmp(var, "max_bss_load") == 0) {
2745 cred->max_bss_load = atoi(value);
2749 if (os_strcmp(var, "req_conn_capab") == 0)
2750 return wpa_config_set_cred_req_conn_capab(cred, value);
2752 if (os_strcmp(var, "ocsp") == 0) {
2753 cred->ocsp = atoi(value);
2757 if (os_strcmp(var, "sim_num") == 0) {
2758 cred->sim_num = atoi(value);
2762 val = wpa_config_parse_string(value, &len);
2764 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2765 "value '%s'.", line, var, value);
2769 if (os_strcmp(var, "realm") == 0) {
2770 os_free(cred->realm);
2775 if (os_strcmp(var, "username") == 0) {
2776 str_clear_free(cred->username);
2777 cred->username = val;
2781 if (os_strcmp(var, "password") == 0) {
2782 str_clear_free(cred->password);
2783 cred->password = val;
2784 cred->ext_password = 0;
2788 if (os_strcmp(var, "ca_cert") == 0) {
2789 os_free(cred->ca_cert);
2790 cred->ca_cert = val;
2794 if (os_strcmp(var, "client_cert") == 0) {
2795 os_free(cred->client_cert);
2796 cred->client_cert = val;
2800 if (os_strcmp(var, "private_key") == 0) {
2801 os_free(cred->private_key);
2802 cred->private_key = val;
2806 if (os_strcmp(var, "private_key_passwd") == 0) {
2807 str_clear_free(cred->private_key_passwd);
2808 cred->private_key_passwd = val;
2812 if (os_strcmp(var, "imsi") == 0) {
2813 os_free(cred->imsi);
2818 if (os_strcmp(var, "milenage") == 0) {
2819 str_clear_free(cred->milenage);
2820 cred->milenage = val;
2824 if (os_strcmp(var, "domain_suffix_match") == 0) {
2825 os_free(cred->domain_suffix_match);
2826 cred->domain_suffix_match = val;
2830 if (os_strcmp(var, "domain") == 0) {
2832 new_domain = os_realloc_array(cred->domain,
2833 cred->num_domain + 1,
2835 if (new_domain == NULL) {
2839 new_domain[cred->num_domain++] = val;
2840 cred->domain = new_domain;
2844 if (os_strcmp(var, "phase1") == 0) {
2845 os_free(cred->phase1);
2850 if (os_strcmp(var, "phase2") == 0) {
2851 os_free(cred->phase2);
2856 if (os_strcmp(var, "roaming_consortium") == 0) {
2857 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2858 wpa_printf(MSG_ERROR, "Line %d: invalid "
2859 "roaming_consortium length %d (3..15 "
2860 "expected)", line, (int) len);
2864 os_memcpy(cred->roaming_consortium, val, len);
2865 cred->roaming_consortium_len = len;
2870 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2871 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2873 wpa_printf(MSG_ERROR, "Line %d: invalid "
2874 "required_roaming_consortium length %d "
2875 "(3..15 expected)", line, (int) len);
2879 os_memcpy(cred->required_roaming_consortium, val, len);
2880 cred->required_roaming_consortium_len = len;
2885 if (os_strcmp(var, "excluded_ssid") == 0) {
2886 struct excluded_ssid *e;
2888 if (len > MAX_SSID_LEN) {
2889 wpa_printf(MSG_ERROR, "Line %d: invalid "
2890 "excluded_ssid length %d", line, (int) len);
2895 e = os_realloc_array(cred->excluded_ssid,
2896 cred->num_excluded_ssid + 1,
2897 sizeof(struct excluded_ssid));
2902 cred->excluded_ssid = e;
2904 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2905 os_memcpy(e->ssid, val, len);
2913 if (os_strcmp(var, "roaming_partner") == 0) {
2914 struct roaming_partner *p;
2917 p = os_realloc_array(cred->roaming_partner,
2918 cred->num_roaming_partner + 1,
2919 sizeof(struct roaming_partner));
2924 cred->roaming_partner = p;
2926 p = &cred->roaming_partner[cred->num_roaming_partner];
2928 pos = os_strchr(val, ',');
2934 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2938 os_memcpy(p->fqdn, val, pos - val);
2940 p->exact_match = atoi(pos);
2942 pos = os_strchr(pos, ',');
2949 p->priority = atoi(pos);
2951 pos = os_strchr(pos, ',');
2958 if (os_strlen(pos) >= sizeof(p->country)) {
2962 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2964 cred->num_roaming_partner++;
2970 if (os_strcmp(var, "provisioning_sp") == 0) {
2971 os_free(cred->provisioning_sp);
2972 cred->provisioning_sp = val;
2977 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2987 static char * alloc_int_str(int val)
2991 buf = os_malloc(20);
2994 os_snprintf(buf, 20, "%d", val);
2999 static char * alloc_strdup(const char *str)
3003 return os_strdup(str);
3007 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
3009 if (os_strcmp(var, "temporary") == 0)
3010 return alloc_int_str(cred->temporary);
3012 if (os_strcmp(var, "priority") == 0)
3013 return alloc_int_str(cred->priority);
3015 if (os_strcmp(var, "sp_priority") == 0)
3016 return alloc_int_str(cred->sp_priority);
3018 if (os_strcmp(var, "pcsc") == 0)
3019 return alloc_int_str(cred->pcsc);
3021 if (os_strcmp(var, "eap") == 0) {
3022 if (!cred->eap_method)
3024 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
3025 cred->eap_method[0].method));
3028 if (os_strcmp(var, "update_identifier") == 0)
3029 return alloc_int_str(cred->update_identifier);
3031 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
3032 return alloc_int_str(cred->min_dl_bandwidth_home);
3034 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
3035 return alloc_int_str(cred->min_ul_bandwidth_home);
3037 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
3038 return alloc_int_str(cred->min_dl_bandwidth_roaming);
3040 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
3041 return alloc_int_str(cred->min_ul_bandwidth_roaming);
3043 if (os_strcmp(var, "max_bss_load") == 0)
3044 return alloc_int_str(cred->max_bss_load);
3046 if (os_strcmp(var, "req_conn_capab") == 0) {
3048 char *buf, *end, *pos;
3051 if (!cred->num_req_conn_capab)
3054 buf = os_malloc(4000);
3059 for (i = 0; i < cred->num_req_conn_capab; i++) {
3062 ret = os_snprintf(pos, end - pos, "%s%u",
3064 cred->req_conn_capab_proto[i]);
3065 if (ret < 0 || ret >= end - pos)
3069 ports = cred->req_conn_capab_port[i];
3072 for (j = 0; ports[j] != -1; j++) {
3073 ret = os_snprintf(pos, end - pos,
3077 if (ret < 0 || ret >= end - pos)
3087 if (os_strcmp(var, "ocsp") == 0)
3088 return alloc_int_str(cred->ocsp);
3090 if (os_strcmp(var, "realm") == 0)
3091 return alloc_strdup(cred->realm);
3093 if (os_strcmp(var, "username") == 0)
3094 return alloc_strdup(cred->username);
3096 if (os_strcmp(var, "password") == 0) {
3097 if (!cred->password)
3099 return alloc_strdup("*");
3102 if (os_strcmp(var, "ca_cert") == 0)
3103 return alloc_strdup(cred->ca_cert);
3105 if (os_strcmp(var, "client_cert") == 0)
3106 return alloc_strdup(cred->client_cert);
3108 if (os_strcmp(var, "private_key") == 0)
3109 return alloc_strdup(cred->private_key);
3111 if (os_strcmp(var, "private_key_passwd") == 0) {
3112 if (!cred->private_key_passwd)
3114 return alloc_strdup("*");
3117 if (os_strcmp(var, "imsi") == 0)
3118 return alloc_strdup(cred->imsi);
3120 if (os_strcmp(var, "milenage") == 0) {
3121 if (!(cred->milenage))
3123 return alloc_strdup("*");
3126 if (os_strcmp(var, "domain_suffix_match") == 0)
3127 return alloc_strdup(cred->domain_suffix_match);
3129 if (os_strcmp(var, "domain") == 0) {
3131 char *buf, *end, *pos;
3134 if (!cred->num_domain)
3137 buf = os_malloc(4000);
3143 for (i = 0; i < cred->num_domain; i++) {
3144 ret = os_snprintf(pos, end - pos, "%s%s",
3145 i > 0 ? "\n" : "", cred->domain[i]);
3146 if (ret < 0 || ret >= end - pos)
3154 if (os_strcmp(var, "phase1") == 0)
3155 return alloc_strdup(cred->phase1);
3157 if (os_strcmp(var, "phase2") == 0)
3158 return alloc_strdup(cred->phase2);
3160 if (os_strcmp(var, "roaming_consortium") == 0) {
3164 if (!cred->roaming_consortium_len)
3166 buflen = cred->roaming_consortium_len * 2 + 1;
3167 buf = os_malloc(buflen);
3170 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3171 cred->roaming_consortium_len);
3175 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3179 if (!cred->required_roaming_consortium_len)
3181 buflen = cred->required_roaming_consortium_len * 2 + 1;
3182 buf = os_malloc(buflen);
3185 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3186 cred->required_roaming_consortium_len);
3190 if (os_strcmp(var, "excluded_ssid") == 0) {
3192 char *buf, *end, *pos;
3194 if (!cred->num_excluded_ssid)
3197 buf = os_malloc(4000);
3203 for (i = 0; i < cred->num_excluded_ssid; i++) {
3204 struct excluded_ssid *e;
3207 e = &cred->excluded_ssid[i];
3208 ret = os_snprintf(pos, end - pos, "%s%s",
3210 wpa_ssid_txt(e->ssid, e->ssid_len));
3211 if (ret < 0 || ret >= end - pos)
3219 if (os_strcmp(var, "roaming_partner") == 0) {
3221 char *buf, *end, *pos;
3223 if (!cred->num_roaming_partner)
3226 buf = os_malloc(4000);
3232 for (i = 0; i < cred->num_roaming_partner; i++) {
3233 struct roaming_partner *p;
3236 p = &cred->roaming_partner[i];
3237 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3239 p->fqdn, p->exact_match, p->priority,
3241 if (ret < 0 || ret >= end - pos)
3249 if (os_strcmp(var, "provisioning_sp") == 0)
3250 return alloc_strdup(cred->provisioning_sp);
3256 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3258 struct wpa_cred *cred;
3260 cred = config->cred;
3271 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3274 struct wpa_cred *cred, *last = NULL;
3277 cred = config->cred;
3286 cred = os_zalloc(sizeof(*cred));
3290 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3294 config->cred = cred;
3300 int wpa_config_remove_cred(struct wpa_config *config, int id)
3302 struct wpa_cred *cred, *prev = NULL;
3304 cred = config->cred;
3316 prev->next = cred->next;
3318 config->cred = cred->next;
3320 wpa_config_free_cred(cred);
3325 #ifndef CONFIG_NO_CONFIG_BLOBS
3327 * wpa_config_get_blob - Get a named configuration blob
3328 * @config: Configuration data from wpa_config_read()
3329 * @name: Name of the blob
3330 * Returns: Pointer to blob data or %NULL if not found
3332 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3335 struct wpa_config_blob *blob = config->blobs;
3338 if (os_strcmp(blob->name, name) == 0)
3347 * wpa_config_set_blob - Set or add a named configuration blob
3348 * @config: Configuration data from wpa_config_read()
3349 * @blob: New value for the blob
3351 * Adds a new configuration blob or replaces the current value of an existing
3354 void wpa_config_set_blob(struct wpa_config *config,
3355 struct wpa_config_blob *blob)
3357 wpa_config_remove_blob(config, blob->name);
3358 blob->next = config->blobs;
3359 config->blobs = blob;
3364 * wpa_config_free_blob - Free blob data
3365 * @blob: Pointer to blob to be freed
3367 void wpa_config_free_blob(struct wpa_config_blob *blob)
3370 os_free(blob->name);
3371 bin_clear_free(blob->data, blob->len);
3378 * wpa_config_remove_blob - Remove a named configuration blob
3379 * @config: Configuration data from wpa_config_read()
3380 * @name: Name of the blob to remove
3381 * Returns: 0 if blob was removed or -1 if blob was not found
3383 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3385 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3388 if (os_strcmp(pos->name, name) == 0) {
3390 prev->next = pos->next;
3392 config->blobs = pos->next;
3393 wpa_config_free_blob(pos);
3402 #endif /* CONFIG_NO_CONFIG_BLOBS */
3406 * wpa_config_alloc_empty - Allocate an empty configuration
3407 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3409 * @driver_param: Driver parameters
3410 * Returns: Pointer to allocated configuration data or %NULL on failure
3412 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3413 const char *driver_param)
3415 struct wpa_config *config;
3416 const int aCWmin = 4, aCWmax = 10;
3417 const struct hostapd_wmm_ac_params ac_bk =
3418 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3419 const struct hostapd_wmm_ac_params ac_be =
3420 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3421 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3422 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3423 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3424 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3426 config = os_zalloc(sizeof(*config));
3429 config->eapol_version = DEFAULT_EAPOL_VERSION;
3430 config->ap_scan = DEFAULT_AP_SCAN;
3431 config->user_mpm = DEFAULT_USER_MPM;
3432 config->fast_reauth = DEFAULT_FAST_REAUTH;
3433 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3434 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3435 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3436 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3437 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3438 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3439 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3440 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3441 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3442 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3443 config->wmm_ac_params[0] = ac_be;
3444 config->wmm_ac_params[1] = ac_bk;
3445 config->wmm_ac_params[2] = ac_vi;
3446 config->wmm_ac_params[3] = ac_vo;
3447 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3448 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3449 config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD;
3452 config->ctrl_interface = os_strdup(ctrl_interface);
3454 config->driver_param = os_strdup(driver_param);
3460 #ifndef CONFIG_NO_STDOUT_DEBUG
3462 * wpa_config_debug_dump_networks - Debug dump of configured networks
3463 * @config: Configuration data from wpa_config_read()
3465 void wpa_config_debug_dump_networks(struct wpa_config *config)
3468 struct wpa_ssid *ssid;
3470 for (prio = 0; prio < config->num_prio; prio++) {
3471 ssid = config->pssid[prio];
3472 wpa_printf(MSG_DEBUG, "Priority group %d",
3475 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3477 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3482 #endif /* CONFIG_NO_STDOUT_DEBUG */
3485 struct global_parse_data {
3487 int (*parser)(const struct global_parse_data *data,
3488 struct wpa_config *config, int line, const char *value);
3489 void *param1, *param2, *param3;
3490 unsigned int changed_flag;
3494 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3495 struct wpa_config *config, int line,
3501 dst = (int *) (((u8 *) config) + (long) data->param1);
3502 val = strtol(pos, &end, 0);
3504 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3510 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3512 if (data->param2 && *dst < (long) data->param2) {
3513 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3514 "min_value=%ld)", line, data->name, *dst,
3515 (long) data->param2);
3516 *dst = (long) data->param2;
3520 if (data->param3 && *dst > (long) data->param3) {
3521 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3522 "max_value=%ld)", line, data->name, *dst,
3523 (long) data->param3);
3524 *dst = (long) data->param3;
3532 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3533 struct wpa_config *config, int line,
3539 len = os_strlen(pos);
3540 if (data->param2 && len < (size_t) data->param2) {
3541 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3542 "min_len=%ld)", line, data->name,
3543 (unsigned long) len, (long) data->param2);
3547 if (data->param3 && len > (size_t) data->param3) {
3548 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3549 "max_len=%ld)", line, data->name,
3550 (unsigned long) len, (long) data->param3);
3554 tmp = os_strdup(pos);
3558 dst = (char **) (((u8 *) config) + (long) data->param1);
3561 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3567 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3568 struct wpa_config *config, int line,
3575 tmp = wpa_config_parse_string(pos, &len);
3577 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3582 res = wpa_global_config_parse_str(data, config, line, tmp);
3588 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3589 struct wpa_config *config, int line,
3593 struct wpabuf **dst, *tmp;
3595 len = os_strlen(pos);
3599 tmp = wpabuf_alloc(len / 2);
3603 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3608 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3611 wpa_printf(MSG_DEBUG, "%s", data->name);
3617 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3618 struct wpa_config *config, int line,
3623 freqs = wpa_config_parse_int_array(value);
3626 if (freqs[0] == 0) {
3630 os_free(config->freq_list);
3631 config->freq_list = freqs;
3637 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3638 struct wpa_config *config, int line,
3642 struct hostapd_ip_addr addr;
3644 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3646 if (addr.af != AF_INET)
3649 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3650 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3651 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3652 WPA_GET_BE32((u8 *) dst));
3656 #endif /* CONFIG_P2P */
3659 static int wpa_config_process_country(const struct global_parse_data *data,
3660 struct wpa_config *config, int line,
3663 if (!pos[0] || !pos[1]) {
3664 wpa_printf(MSG_DEBUG, "Invalid country set");
3667 config->country[0] = pos[0];
3668 config->country[1] = pos[1];
3669 wpa_printf(MSG_DEBUG, "country='%c%c'",
3670 config->country[0], config->country[1]);
3675 static int wpa_config_process_load_dynamic_eap(
3676 const struct global_parse_data *data, struct wpa_config *config,
3677 int line, const char *so)
3680 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3681 ret = eap_peer_method_load(so);
3683 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3686 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3687 "method '%s'.", line, so);
3697 static int wpa_config_process_uuid(const struct global_parse_data *data,
3698 struct wpa_config *config, int line,
3702 if (uuid_str2bin(pos, config->uuid)) {
3703 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3706 uuid_bin2str(config->uuid, buf, sizeof(buf));
3707 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3712 static int wpa_config_process_device_type(
3713 const struct global_parse_data *data,
3714 struct wpa_config *config, int line, const char *pos)
3716 return wps_dev_type_str2bin(pos, config->device_type);
3720 static int wpa_config_process_os_version(const struct global_parse_data *data,
3721 struct wpa_config *config, int line,
3724 if (hexstr2bin(pos, config->os_version, 4)) {
3725 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3728 wpa_printf(MSG_DEBUG, "os_version=%08x",
3729 WPA_GET_BE32(config->os_version));
3734 static int wpa_config_process_wps_vendor_ext_m1(
3735 const struct global_parse_data *data,
3736 struct wpa_config *config, int line, const char *pos)
3739 int len = os_strlen(pos) / 2;
3743 wpa_printf(MSG_ERROR, "Line %d: "
3744 "invalid wps_vendor_ext_m1", line);
3748 tmp = wpabuf_alloc(len);
3750 p = wpabuf_put(tmp, len);
3752 if (hexstr2bin(pos, p, len)) {
3753 wpa_printf(MSG_ERROR, "Line %d: "
3754 "invalid wps_vendor_ext_m1", line);
3759 wpabuf_free(config->wps_vendor_ext_m1);
3760 config->wps_vendor_ext_m1 = tmp;
3762 wpa_printf(MSG_ERROR, "Can not allocate "
3763 "memory for wps_vendor_ext_m1");
3770 #endif /* CONFIG_WPS */
3773 static int wpa_config_process_sec_device_type(
3774 const struct global_parse_data *data,
3775 struct wpa_config *config, int line, const char *pos)
3779 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3780 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3785 idx = config->num_sec_device_types;
3787 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3790 config->num_sec_device_types++;
3795 static int wpa_config_process_p2p_pref_chan(
3796 const struct global_parse_data *data,
3797 struct wpa_config *config, int line, const char *pos)
3799 struct p2p_channel *pref = NULL, *n;
3800 unsigned int num = 0;
3804 /* format: class:chan,class:chan,... */
3807 op_class = atoi(pos);
3808 pos2 = os_strchr(pos, ':');
3814 n = os_realloc_array(pref, num + 1,
3815 sizeof(struct p2p_channel));
3819 pref[num].op_class = op_class;
3820 pref[num].chan = chan;
3823 pos = os_strchr(pos2, ',');
3829 os_free(config->p2p_pref_chan);
3830 config->p2p_pref_chan = pref;
3831 config->num_p2p_pref_chan = num;
3832 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3833 (u8 *) config->p2p_pref_chan,
3834 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3840 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3845 static int wpa_config_process_p2p_no_go_freq(
3846 const struct global_parse_data *data,
3847 struct wpa_config *config, int line, const char *pos)
3851 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3853 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3857 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3858 config->p2p_no_go_freq.num);
3863 #endif /* CONFIG_P2P */
3866 static int wpa_config_process_hessid(
3867 const struct global_parse_data *data,
3868 struct wpa_config *config, int line, const char *pos)
3870 if (hwaddr_aton2(pos, config->hessid) < 0) {
3871 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3880 static int wpa_config_process_sae_groups(
3881 const struct global_parse_data *data,
3882 struct wpa_config *config, int line, const char *pos)
3884 int *groups = wpa_config_parse_int_array(pos);
3885 if (groups == NULL) {
3886 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3891 os_free(config->sae_groups);
3892 config->sae_groups = groups;
3898 static int wpa_config_process_ap_vendor_elements(
3899 const struct global_parse_data *data,
3900 struct wpa_config *config, int line, const char *pos)
3903 int len = os_strlen(pos) / 2;
3907 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3912 tmp = wpabuf_alloc(len);
3914 p = wpabuf_put(tmp, len);
3916 if (hexstr2bin(pos, p, len)) {
3917 wpa_printf(MSG_ERROR, "Line %d: invalid "
3918 "ap_vendor_elements", line);
3923 wpabuf_free(config->ap_vendor_elements);
3924 config->ap_vendor_elements = tmp;
3926 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3927 "ap_vendor_elements");
3935 #ifdef CONFIG_CTRL_IFACE
3936 static int wpa_config_process_no_ctrl_interface(
3937 const struct global_parse_data *data,
3938 struct wpa_config *config, int line, const char *pos)
3940 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3941 os_free(config->ctrl_interface);
3942 config->ctrl_interface = NULL;
3945 #endif /* CONFIG_CTRL_IFACE */
3951 /* OFFSET: Get offset of a variable within the wpa_config structure */
3952 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3954 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3955 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3956 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3957 #define INT(f) _INT(f), NULL, NULL
3958 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3959 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3960 #define STR(f) _STR(f), NULL, NULL
3961 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3962 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3963 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3965 static const struct global_parse_data global_fields[] = {
3966 #ifdef CONFIG_CTRL_IFACE
3967 { STR(ctrl_interface), 0 },
3968 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3969 { STR(ctrl_interface_group), 0 } /* deprecated */,
3970 #endif /* CONFIG_CTRL_IFACE */
3971 #ifdef CONFIG_MACSEC
3972 { INT_RANGE(eapol_version, 1, 3), 0 },
3973 #else /* CONFIG_MACSEC */
3974 { INT_RANGE(eapol_version, 1, 2), 0 },
3975 #endif /* CONFIG_MACSEC */
3976 { INT(ap_scan), 0 },
3977 { FUNC(bgscan), 0 },
3979 { INT(user_mpm), 0 },
3980 #endif /* CONFIG_MESH */
3981 { INT(disable_scan_offload), 0 },
3982 { INT(fast_reauth), 0 },
3983 { STR(opensc_engine_path), 0 },
3984 { STR(pkcs11_engine_path), 0 },
3985 { STR(pkcs11_module_path), 0 },
3986 { STR(openssl_ciphers), 0 },
3987 { STR(pcsc_reader), 0 },
3988 { STR(pcsc_pin), 0 },
3989 { INT(external_sim), 0 },
3990 { STR(driver_param), 0 },
3991 { INT(dot11RSNAConfigPMKLifetime), 0 },
3992 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3993 { INT(dot11RSNAConfigSATimeout), 0 },
3994 #ifndef CONFIG_NO_CONFIG_WRITE
3995 { INT(update_config), 0 },
3996 #endif /* CONFIG_NO_CONFIG_WRITE */
3997 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3999 { FUNC(uuid), CFG_CHANGED_UUID },
4000 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
4001 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
4002 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
4003 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
4004 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
4005 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
4006 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
4007 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
4008 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
4009 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
4010 #endif /* CONFIG_WPS */
4012 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
4013 { INT(p2p_listen_reg_class), 0 },
4014 { INT(p2p_listen_channel), 0 },
4015 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
4016 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
4017 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
4018 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
4019 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
4020 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
4021 { INT(p2p_group_idle), 0 },
4022 { INT_RANGE(p2p_passphrase_len, 8, 63),
4023 CFG_CHANGED_P2P_PASSPHRASE_LEN },
4024 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
4025 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
4026 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
4027 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
4028 { INT(p2p_go_ht40), 0 },
4029 { INT(p2p_go_vht), 0 },
4030 { INT(p2p_disabled), 0 },
4031 { INT(p2p_no_group_iface), 0 },
4032 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
4033 { IPV4(ip_addr_go), 0 },
4034 { IPV4(ip_addr_mask), 0 },
4035 { IPV4(ip_addr_start), 0 },
4036 { IPV4(ip_addr_end), 0 },
4037 #endif /* CONFIG_P2P */
4038 { FUNC(country), CFG_CHANGED_COUNTRY },
4039 { INT(bss_max_count), 0 },
4040 { INT(bss_expiration_age), 0 },
4041 { INT(bss_expiration_scan_count), 0 },
4042 { INT_RANGE(filter_ssids, 0, 1), 0 },
4043 { INT_RANGE(filter_rssi, -100, 0), 0 },
4044 { INT(max_num_sta), 0 },
4045 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
4047 { INT_RANGE(hs20, 0, 1), 0 },
4048 #endif /* CONFIG_HS20 */
4049 { INT_RANGE(interworking, 0, 1), 0 },
4050 { FUNC(hessid), 0 },
4051 { INT_RANGE(access_network_type, 0, 15), 0 },
4052 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
4053 { STR(autoscan), 0 },
4054 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
4055 CFG_CHANGED_NFC_PASSWORD_TOKEN },
4056 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4057 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4058 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4059 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
4060 { INT(p2p_go_max_inactivity), 0 },
4061 { INT_RANGE(auto_interworking, 0, 1), 0 },
4064 { FUNC(sae_groups), 0 },
4065 { INT(dtim_period), 0 },
4066 { INT(beacon_int), 0 },
4067 { FUNC(ap_vendor_elements), 0 },
4068 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
4069 { FUNC(freq_list), 0 },
4070 { INT(scan_cur_freq), 0 },
4071 { INT(sched_scan_interval), 0 },
4072 { INT(tdls_external_control), 0},
4073 { STR(osu_dir), 0 },
4074 { STR(wowlan_triggers), 0 },
4075 { INT(p2p_search_delay), 0},
4076 { INT(mac_addr), 0 },
4077 { INT(rand_addr_lifetime), 0 },
4078 { INT(preassoc_mac_addr), 0 },
4079 { INT(key_mgmt_offload), 0},
4091 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4094 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
4099 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
4100 const struct global_parse_data *field = &global_fields[i];
4101 size_t flen = os_strlen(field->name);
4102 if (os_strncmp(pos, field->name, flen) != 0 ||
4106 if (field->parser(field, config, line, pos + flen + 1)) {
4107 wpa_printf(MSG_ERROR, "Line %d: failed to "
4108 "parse '%s'.", line, pos);
4111 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
4112 config->wps_nfc_pw_from_config = 1;
4113 config->changed_parameters |= field->changed_flag;
4116 if (i == NUM_GLOBAL_FIELDS) {
4118 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
4119 char *tmp = os_strchr(pos, '=');
4123 wpa_printf(MSG_ERROR, "Line %d: invalid line "
4128 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
4130 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
4135 #endif /* CONFIG_AP */
4138 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",