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 */
1591 /* Helper macros for network block parser */
1596 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1597 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1599 /* STR: Define a string variable for an ASCII string; f = field name */
1600 #ifdef NO_CONFIG_WRITE
1601 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1602 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1603 #else /* NO_CONFIG_WRITE */
1604 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1605 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1606 #endif /* NO_CONFIG_WRITE */
1607 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1608 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1609 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1610 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1612 /* STR_LEN: Define a string variable with a separate variable for storing the
1613 * data length. Unlike STR(), this can be used to store arbitrary binary data
1614 * (i.e., even nul termination character). */
1615 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1616 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1617 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1618 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1619 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1621 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1622 * explicitly specified. */
1623 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1624 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1625 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1627 #ifdef NO_CONFIG_WRITE
1628 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1629 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1630 #else /* NO_CONFIG_WRITE */
1631 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1632 OFFSET(f), (void *) 0
1633 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1634 OFFSET(eap.f), (void *) 0
1635 #endif /* NO_CONFIG_WRITE */
1637 /* INT: Define an integer variable */
1638 #define INT(f) _INT(f), NULL, NULL, 0
1639 #define INTe(f) _INTe(f), NULL, NULL, 0
1641 /* INT_RANGE: Define an integer variable with allowed value range */
1642 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1644 /* FUNC: Define a configuration variable that uses a custom function for
1645 * parsing and writing the value. */
1646 #ifdef NO_CONFIG_WRITE
1647 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1648 #else /* NO_CONFIG_WRITE */
1649 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1650 NULL, NULL, NULL, NULL
1651 #endif /* NO_CONFIG_WRITE */
1652 #define FUNC(f) _FUNC(f), 0
1653 #define FUNC_KEY(f) _FUNC(f), 1
1656 * Table of network configuration variables. This table is used to parse each
1657 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1658 * that is inside a network block.
1660 * This table is generated using the helper macros defined above and with
1661 * generous help from the C pre-processor. The field name is stored as a string
1662 * into .name and for STR and INT types, the offset of the target buffer within
1663 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1664 * offset to the field containing the length of the configuration variable.
1665 * .param3 and .param4 can be used to mark the allowed range (length for STR
1666 * and value for INT).
1668 * For each configuration line in wpa_supplicant.conf, the parser goes through
1669 * this table and select the entry that matches with the field name. The parser
1670 * function (.parser) is then called to parse the actual value of the field.
1672 * This kind of mechanism makes it easy to add new configuration parameters,
1673 * since only one line needs to be added into this table and into the
1674 * struct wpa_ssid definition if the new variable is either a string or
1675 * integer. More complex types will need to use their own parser and writer
1678 static const struct parse_data ssid_fields[] = {
1679 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1680 { INT_RANGE(scan_ssid, 0, 1) },
1685 { INT(bg_scan_period) },
1689 { FUNC(scan_freq) },
1690 { FUNC(freq_list) },
1691 #ifdef IEEE8021X_EAPOL
1693 { STR_LENe(identity) },
1694 { STR_LENe(anonymous_identity) },
1695 { FUNC_KEY(password) },
1698 { STRe(client_cert) },
1699 { STRe(private_key) },
1700 { STR_KEYe(private_key_passwd) },
1702 { STRe(subject_match) },
1703 { STRe(altsubject_match) },
1704 { STRe(domain_suffix_match) },
1707 { STRe(client_cert2) },
1708 { STRe(private_key2) },
1709 { STR_KEYe(private_key2_passwd) },
1711 { STRe(subject_match2) },
1712 { STRe(altsubject_match2) },
1713 { STRe(domain_suffix_match2) },
1718 { STRe(engine_id) },
1721 { STRe(ca_cert_id) },
1723 { STRe(engine2_id) },
1726 { STRe(ca_cert2_id) },
1729 { INT(eapol_flags) },
1731 { STRe(openssl_ciphers) },
1732 #endif /* IEEE8021X_EAPOL */
1733 { FUNC_KEY(wep_key0) },
1734 { FUNC_KEY(wep_key1) },
1735 { FUNC_KEY(wep_key2) },
1736 { FUNC_KEY(wep_key3) },
1737 { INT(wep_tx_keyidx) },
1739 #ifdef IEEE8021X_EAPOL
1740 { INT(eap_workaround) },
1742 { INTe(fragment_size) },
1744 #endif /* IEEE8021X_EAPOL */
1746 { INT_RANGE(mode, 0, 5) },
1747 { INT_RANGE(no_auto_peer, 0, 1) },
1748 #else /* CONFIG_MESH */
1749 { INT_RANGE(mode, 0, 4) },
1750 #endif /* CONFIG_MESH */
1751 { INT_RANGE(proactive_key_caching, 0, 1) },
1752 { INT_RANGE(disabled, 0, 2) },
1754 #ifdef CONFIG_IEEE80211W
1755 { INT_RANGE(ieee80211w, 0, 2) },
1756 #endif /* CONFIG_IEEE80211W */
1757 { INT_RANGE(peerkey, 0, 1) },
1758 { INT_RANGE(mixed_cell, 0, 1) },
1759 { INT_RANGE(frequency, 0, 65000) },
1760 { INT(wpa_ptk_rekey) },
1762 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1764 { FUNC(go_p2p_dev_addr) },
1765 { FUNC(p2p_client_list) },
1767 #endif /* CONFIG_P2P */
1768 #ifdef CONFIG_HT_OVERRIDES
1769 { INT_RANGE(disable_ht, 0, 1) },
1770 { INT_RANGE(disable_ht40, -1, 1) },
1771 { INT_RANGE(disable_sgi, 0, 1) },
1772 { INT_RANGE(disable_ldpc, 0, 1) },
1773 { INT_RANGE(ht40_intolerant, 0, 1) },
1774 { INT_RANGE(disable_max_amsdu, -1, 1) },
1775 { INT_RANGE(ampdu_factor, -1, 3) },
1776 { INT_RANGE(ampdu_density, -1, 7) },
1778 #endif /* CONFIG_HT_OVERRIDES */
1779 #ifdef CONFIG_VHT_OVERRIDES
1780 { INT_RANGE(disable_vht, 0, 1) },
1782 { INT(vht_capa_mask) },
1783 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1784 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1785 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1786 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1787 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1788 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1789 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1790 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1791 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1792 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1793 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1794 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1795 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1796 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1797 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1798 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1799 #endif /* CONFIG_VHT_OVERRIDES */
1800 { INT(ap_max_inactivity) },
1801 { INT(dtim_period) },
1802 { INT(beacon_int) },
1803 #ifdef CONFIG_MACSEC
1804 { INT_RANGE(macsec_policy, 0, 1) },
1805 #endif /* CONFIG_MACSEC */
1807 { INT(update_identifier) },
1808 #endif /* CONFIG_HS20 */
1809 { INT_RANGE(mac_addr, 0, 2) },
1821 #undef STR_RANGE_KEY
1828 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1832 * wpa_config_add_prio_network - Add a network to priority lists
1833 * @config: Configuration data from wpa_config_read()
1834 * @ssid: Pointer to the network configuration to be added to the list
1835 * Returns: 0 on success, -1 on failure
1837 * This function is used to add a network block to the priority list of
1838 * networks. This must be called for each network when reading in the full
1839 * configuration. In addition, this can be used indirectly when updating
1840 * priorities by calling wpa_config_update_prio_list().
1842 int wpa_config_add_prio_network(struct wpa_config *config,
1843 struct wpa_ssid *ssid)
1846 struct wpa_ssid *prev, **nlist;
1849 * Add to an existing priority list if one is available for the
1850 * configured priority level for this network.
1852 for (prio = 0; prio < config->num_prio; prio++) {
1853 prev = config->pssid[prio];
1854 if (prev->priority == ssid->priority) {
1862 /* First network for this priority - add a new priority list */
1863 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1864 sizeof(struct wpa_ssid *));
1868 for (prio = 0; prio < config->num_prio; prio++) {
1869 if (nlist[prio]->priority < ssid->priority) {
1870 os_memmove(&nlist[prio + 1], &nlist[prio],
1871 (config->num_prio - prio) *
1872 sizeof(struct wpa_ssid *));
1879 config->pssid = nlist;
1886 * wpa_config_update_prio_list - Update network priority list
1887 * @config: Configuration data from wpa_config_read()
1888 * Returns: 0 on success, -1 on failure
1890 * This function is called to update the priority list of networks in the
1891 * configuration when a network is being added or removed. This is also called
1892 * if a priority for a network is changed.
1894 int wpa_config_update_prio_list(struct wpa_config *config)
1896 struct wpa_ssid *ssid;
1899 os_free(config->pssid);
1900 config->pssid = NULL;
1901 config->num_prio = 0;
1903 ssid = config->ssid;
1906 if (wpa_config_add_prio_network(config, ssid) < 0)
1915 #ifdef IEEE8021X_EAPOL
1916 static void eap_peer_config_free(struct eap_peer_config *eap)
1918 os_free(eap->eap_methods);
1919 bin_clear_free(eap->identity, eap->identity_len);
1920 os_free(eap->anonymous_identity);
1921 bin_clear_free(eap->password, eap->password_len);
1922 os_free(eap->ca_cert);
1923 os_free(eap->ca_path);
1924 os_free(eap->client_cert);
1925 os_free(eap->private_key);
1926 str_clear_free(eap->private_key_passwd);
1927 os_free(eap->dh_file);
1928 os_free(eap->subject_match);
1929 os_free(eap->altsubject_match);
1930 os_free(eap->domain_suffix_match);
1931 os_free(eap->ca_cert2);
1932 os_free(eap->ca_path2);
1933 os_free(eap->client_cert2);
1934 os_free(eap->private_key2);
1935 str_clear_free(eap->private_key2_passwd);
1936 os_free(eap->dh_file2);
1937 os_free(eap->subject_match2);
1938 os_free(eap->altsubject_match2);
1939 os_free(eap->domain_suffix_match2);
1940 os_free(eap->phase1);
1941 os_free(eap->phase2);
1943 str_clear_free(eap->pin);
1944 os_free(eap->engine_id);
1945 os_free(eap->key_id);
1946 os_free(eap->cert_id);
1947 os_free(eap->ca_cert_id);
1948 os_free(eap->key2_id);
1949 os_free(eap->cert2_id);
1950 os_free(eap->ca_cert2_id);
1951 str_clear_free(eap->pin2);
1952 os_free(eap->engine2_id);
1954 os_free(eap->pending_req_otp);
1955 os_free(eap->pac_file);
1956 bin_clear_free(eap->new_password, eap->new_password_len);
1957 str_clear_free(eap->external_sim_resp);
1958 os_free(eap->openssl_ciphers);
1960 #endif /* IEEE8021X_EAPOL */
1964 * wpa_config_free_ssid - Free network/ssid configuration data
1965 * @ssid: Configuration data for the network
1967 * This function frees all resources allocated for the network configuration
1970 void wpa_config_free_ssid(struct wpa_ssid *ssid)
1972 struct psk_list_entry *psk;
1974 os_free(ssid->ssid);
1975 os_memset(ssid->psk, 0, sizeof(ssid->psk));
1976 str_clear_free(ssid->passphrase);
1977 os_free(ssid->ext_psk);
1978 #ifdef IEEE8021X_EAPOL
1979 eap_peer_config_free(&ssid->eap);
1980 #endif /* IEEE8021X_EAPOL */
1981 os_free(ssid->id_str);
1982 os_free(ssid->scan_freq);
1983 os_free(ssid->freq_list);
1984 os_free(ssid->bgscan);
1985 os_free(ssid->p2p_client_list);
1986 #ifdef CONFIG_HT_OVERRIDES
1987 os_free(ssid->ht_mcs);
1988 #endif /* CONFIG_HT_OVERRIDES */
1989 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
1991 dl_list_del(&psk->list);
1998 void wpa_config_free_cred(struct wpa_cred *cred)
2002 os_free(cred->realm);
2003 str_clear_free(cred->username);
2004 str_clear_free(cred->password);
2005 os_free(cred->ca_cert);
2006 os_free(cred->client_cert);
2007 os_free(cred->private_key);
2008 str_clear_free(cred->private_key_passwd);
2009 os_free(cred->imsi);
2010 str_clear_free(cred->milenage);
2011 for (i = 0; i < cred->num_domain; i++)
2012 os_free(cred->domain[i]);
2013 os_free(cred->domain);
2014 os_free(cred->domain_suffix_match);
2015 os_free(cred->eap_method);
2016 os_free(cred->phase1);
2017 os_free(cred->phase2);
2018 os_free(cred->excluded_ssid);
2019 os_free(cred->roaming_partner);
2020 os_free(cred->provisioning_sp);
2021 for (i = 0; i < cred->num_req_conn_capab; i++)
2022 os_free(cred->req_conn_capab_port[i]);
2023 os_free(cred->req_conn_capab_port);
2024 os_free(cred->req_conn_capab_proto);
2029 void wpa_config_flush_blobs(struct wpa_config *config)
2031 #ifndef CONFIG_NO_CONFIG_BLOBS
2032 struct wpa_config_blob *blob, *prev;
2034 blob = config->blobs;
2035 config->blobs = NULL;
2039 wpa_config_free_blob(prev);
2041 #endif /* CONFIG_NO_CONFIG_BLOBS */
2046 * wpa_config_free - Free configuration data
2047 * @config: Configuration data from wpa_config_read()
2049 * This function frees all resources allocated for the configuration data by
2050 * wpa_config_read().
2052 void wpa_config_free(struct wpa_config *config)
2054 struct wpa_ssid *ssid, *prev = NULL;
2055 struct wpa_cred *cred, *cprev;
2057 ssid = config->ssid;
2061 wpa_config_free_ssid(prev);
2064 cred = config->cred;
2068 wpa_config_free_cred(cprev);
2071 wpa_config_flush_blobs(config);
2073 wpabuf_free(config->wps_vendor_ext_m1);
2074 os_free(config->ctrl_interface);
2075 os_free(config->ctrl_interface_group);
2076 os_free(config->opensc_engine_path);
2077 os_free(config->pkcs11_engine_path);
2078 os_free(config->pkcs11_module_path);
2079 os_free(config->openssl_ciphers);
2080 os_free(config->pcsc_reader);
2081 str_clear_free(config->pcsc_pin);
2082 os_free(config->driver_param);
2083 os_free(config->device_name);
2084 os_free(config->manufacturer);
2085 os_free(config->model_name);
2086 os_free(config->model_number);
2087 os_free(config->serial_number);
2088 os_free(config->config_methods);
2089 os_free(config->p2p_ssid_postfix);
2090 os_free(config->pssid);
2091 os_free(config->p2p_pref_chan);
2092 os_free(config->p2p_no_go_freq.range);
2093 os_free(config->autoscan);
2094 os_free(config->freq_list);
2095 wpabuf_free(config->wps_nfc_dh_pubkey);
2096 wpabuf_free(config->wps_nfc_dh_privkey);
2097 wpabuf_free(config->wps_nfc_dev_pw);
2098 os_free(config->ext_password_backend);
2099 os_free(config->sae_groups);
2100 wpabuf_free(config->ap_vendor_elements);
2101 os_free(config->osu_dir);
2102 os_free(config->wowlan_triggers);
2108 * wpa_config_foreach_network - Iterate over each configured network
2109 * @config: Configuration data from wpa_config_read()
2110 * @func: Callback function to process each network
2111 * @arg: Opaque argument to pass to callback function
2113 * Iterate over the set of configured networks calling the specified
2114 * function for each item. We guard against callbacks removing the
2117 void wpa_config_foreach_network(struct wpa_config *config,
2118 void (*func)(void *, struct wpa_ssid *),
2121 struct wpa_ssid *ssid, *next;
2123 ssid = config->ssid;
2133 * wpa_config_get_network - Get configured network based on id
2134 * @config: Configuration data from wpa_config_read()
2135 * @id: Unique network id to search for
2136 * Returns: Network configuration or %NULL if not found
2138 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2140 struct wpa_ssid *ssid;
2142 ssid = config->ssid;
2154 * wpa_config_add_network - Add a new network with empty configuration
2155 * @config: Configuration data from wpa_config_read()
2156 * Returns: The new network configuration or %NULL if operation failed
2158 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2161 struct wpa_ssid *ssid, *last = NULL;
2164 ssid = config->ssid;
2173 ssid = os_zalloc(sizeof(*ssid));
2177 dl_list_init(&ssid->psk_list);
2181 config->ssid = ssid;
2183 wpa_config_update_prio_list(config);
2190 * wpa_config_remove_network - Remove a configured network based on id
2191 * @config: Configuration data from wpa_config_read()
2192 * @id: Unique network id to search for
2193 * Returns: 0 on success, or -1 if the network was not found
2195 int wpa_config_remove_network(struct wpa_config *config, int id)
2197 struct wpa_ssid *ssid, *prev = NULL;
2199 ssid = config->ssid;
2211 prev->next = ssid->next;
2213 config->ssid = ssid->next;
2215 wpa_config_update_prio_list(config);
2216 wpa_config_free_ssid(ssid);
2222 * wpa_config_set_network_defaults - Set network default values
2223 * @ssid: Pointer to network configuration data
2225 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2227 ssid->proto = DEFAULT_PROTO;
2228 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2229 ssid->group_cipher = DEFAULT_GROUP;
2230 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2231 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2232 #ifdef IEEE8021X_EAPOL
2233 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2234 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2235 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2236 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2237 #endif /* IEEE8021X_EAPOL */
2238 #ifdef CONFIG_HT_OVERRIDES
2239 ssid->disable_ht = DEFAULT_DISABLE_HT;
2240 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2241 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2242 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2243 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2244 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2245 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2246 #endif /* CONFIG_HT_OVERRIDES */
2247 #ifdef CONFIG_VHT_OVERRIDES
2248 ssid->vht_rx_mcs_nss_1 = -1;
2249 ssid->vht_rx_mcs_nss_2 = -1;
2250 ssid->vht_rx_mcs_nss_3 = -1;
2251 ssid->vht_rx_mcs_nss_4 = -1;
2252 ssid->vht_rx_mcs_nss_5 = -1;
2253 ssid->vht_rx_mcs_nss_6 = -1;
2254 ssid->vht_rx_mcs_nss_7 = -1;
2255 ssid->vht_rx_mcs_nss_8 = -1;
2256 ssid->vht_tx_mcs_nss_1 = -1;
2257 ssid->vht_tx_mcs_nss_2 = -1;
2258 ssid->vht_tx_mcs_nss_3 = -1;
2259 ssid->vht_tx_mcs_nss_4 = -1;
2260 ssid->vht_tx_mcs_nss_5 = -1;
2261 ssid->vht_tx_mcs_nss_6 = -1;
2262 ssid->vht_tx_mcs_nss_7 = -1;
2263 ssid->vht_tx_mcs_nss_8 = -1;
2264 #endif /* CONFIG_VHT_OVERRIDES */
2265 ssid->proactive_key_caching = -1;
2266 #ifdef CONFIG_IEEE80211W
2267 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2268 #endif /* CONFIG_IEEE80211W */
2269 ssid->mac_addr = -1;
2274 * wpa_config_set - Set a variable in network configuration
2275 * @ssid: Pointer to network configuration data
2276 * @var: Variable name, e.g., "ssid"
2277 * @value: Variable value
2278 * @line: Line number in configuration file or 0 if not used
2279 * Returns: 0 on success, -1 on failure
2281 * This function can be used to set network configuration variables based on
2282 * both the configuration file and management interface input. The value
2283 * parameter must be in the same format as the text-based configuration file is
2284 * using. For example, strings are using double quotation marks.
2286 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2292 if (ssid == NULL || var == NULL || value == NULL)
2295 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2296 const struct parse_data *field = &ssid_fields[i];
2297 if (os_strcmp(var, field->name) != 0)
2300 if (field->parser(field, ssid, line, value)) {
2302 wpa_printf(MSG_ERROR, "Line %d: failed to "
2303 "parse %s '%s'.", line, var, value);
2309 if (i == NUM_SSID_FIELDS) {
2311 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2312 "'%s'.", line, var);
2321 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2328 len = os_strlen(value);
2329 buf = os_malloc(len + 3);
2333 os_memcpy(buf + 1, value, len);
2335 buf[len + 2] = '\0';
2336 ret = wpa_config_set(ssid, var, buf, 0);
2343 * wpa_config_get_all - Get all options from network configuration
2344 * @ssid: Pointer to network configuration data
2345 * @get_keys: Determines if keys/passwords will be included in returned list
2346 * (if they may be exported)
2347 * Returns: %NULL terminated list of all set keys and their values in the form
2348 * of [key1, val1, key2, val2, ... , NULL]
2350 * This function can be used to get list of all configured network properties.
2351 * The caller is responsible for freeing the returned list and all its
2354 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2356 const struct parse_data *field;
2362 get_keys = get_keys && ssid->export_keys;
2364 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2369 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2370 field = &ssid_fields[i];
2371 if (field->key_data && !get_keys)
2373 value = field->writer(field, ssid);
2376 if (os_strlen(value) == 0) {
2381 key = os_strdup(field->name);
2387 props[fields_num * 2] = key;
2388 props[fields_num * 2 + 1] = value;
2404 #ifndef NO_CONFIG_WRITE
2406 * wpa_config_get - Get a variable in network configuration
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 variables. The
2412 * returned value is a copy of the configuration variable in text format, i.e,.
2413 * the same format that the text-based configuration file and wpa_config_set()
2414 * are using for the value. The caller is responsible for freeing the returned
2417 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2421 if (ssid == NULL || var == NULL)
2424 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2425 const struct parse_data *field = &ssid_fields[i];
2426 if (os_strcmp(var, field->name) == 0)
2427 return field->writer(field, ssid);
2435 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2436 * @ssid: Pointer to network configuration data
2437 * @var: Variable name, e.g., "ssid"
2438 * Returns: Value of the variable or %NULL on failure
2440 * This function can be used to get network configuration variable like
2441 * wpa_config_get(). The only difference is that this functions does not expose
2442 * key/password material from the configuration. In case a key/password field
2443 * is requested, the returned value is an empty string or %NULL if the variable
2444 * is not set or "*" if the variable is set (regardless of its value). The
2445 * returned value is a copy of the configuration variable in text format, i.e,.
2446 * the same format that the text-based configuration file and wpa_config_set()
2447 * are using for the value. The caller is responsible for freeing the returned
2450 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2454 if (ssid == NULL || var == NULL)
2457 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2458 const struct parse_data *field = &ssid_fields[i];
2459 if (os_strcmp(var, field->name) == 0) {
2460 char *res = field->writer(field, ssid);
2461 if (field->key_data) {
2462 if (res && res[0]) {
2463 wpa_printf(MSG_DEBUG, "Do not allow "
2464 "key_data field to be "
2466 str_clear_free(res);
2467 return os_strdup("*");
2479 #endif /* NO_CONFIG_WRITE */
2483 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2484 * @ssid: Pointer to network configuration data
2486 * This function must be called to update WPA PSK when either SSID or the
2487 * passphrase has changed for the network configuration.
2489 void wpa_config_update_psk(struct wpa_ssid *ssid)
2491 #ifndef CONFIG_NO_PBKDF2
2492 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2493 ssid->psk, PMK_LEN);
2494 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2495 ssid->psk, PMK_LEN);
2497 #endif /* CONFIG_NO_PBKDF2 */
2501 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2506 int *ports, *nports;
2508 unsigned int num_ports;
2510 proto = os_realloc_array(cred->req_conn_capab_proto,
2511 cred->num_req_conn_capab + 1, sizeof(u8));
2514 cred->req_conn_capab_proto = proto;
2516 port = os_realloc_array(cred->req_conn_capab_port,
2517 cred->num_req_conn_capab + 1, sizeof(int *));
2520 cred->req_conn_capab_port = port;
2522 proto[cred->num_req_conn_capab] = atoi(value);
2524 pos = os_strchr(value, ':');
2526 port[cred->num_req_conn_capab] = NULL;
2527 cred->num_req_conn_capab++;
2536 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2537 if (nports == NULL) {
2542 ports[num_ports++] = atoi(pos);
2544 pos = os_strchr(pos, ',');
2550 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2551 if (nports == NULL) {
2556 ports[num_ports] = -1;
2558 port[cred->num_req_conn_capab] = ports;
2559 cred->num_req_conn_capab++;
2564 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2565 const char *value, int line)
2570 if (os_strcmp(var, "temporary") == 0) {
2571 cred->temporary = atoi(value);
2575 if (os_strcmp(var, "priority") == 0) {
2576 cred->priority = atoi(value);
2580 if (os_strcmp(var, "sp_priority") == 0) {
2581 int prio = atoi(value);
2582 if (prio < 0 || prio > 255)
2584 cred->sp_priority = prio;
2588 if (os_strcmp(var, "pcsc") == 0) {
2589 cred->pcsc = atoi(value);
2593 if (os_strcmp(var, "eap") == 0) {
2594 struct eap_method_type method;
2595 method.method = eap_peer_get_type(value, &method.vendor);
2596 if (method.vendor == EAP_VENDOR_IETF &&
2597 method.method == EAP_TYPE_NONE) {
2598 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2599 "for a credential", line, value);
2602 os_free(cred->eap_method);
2603 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2604 if (cred->eap_method == NULL)
2606 os_memcpy(cred->eap_method, &method, sizeof(method));
2610 if (os_strcmp(var, "password") == 0 &&
2611 os_strncmp(value, "ext:", 4) == 0) {
2612 str_clear_free(cred->password);
2613 cred->password = os_strdup(value);
2614 cred->ext_password = 1;
2618 if (os_strcmp(var, "update_identifier") == 0) {
2619 cred->update_identifier = atoi(value);
2623 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2624 cred->min_dl_bandwidth_home = atoi(value);
2628 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2629 cred->min_ul_bandwidth_home = atoi(value);
2633 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2634 cred->min_dl_bandwidth_roaming = atoi(value);
2638 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2639 cred->min_ul_bandwidth_roaming = atoi(value);
2643 if (os_strcmp(var, "max_bss_load") == 0) {
2644 cred->max_bss_load = atoi(value);
2648 if (os_strcmp(var, "req_conn_capab") == 0)
2649 return wpa_config_set_cred_req_conn_capab(cred, value);
2651 if (os_strcmp(var, "ocsp") == 0) {
2652 cred->ocsp = atoi(value);
2656 if (os_strcmp(var, "sim_num") == 0) {
2657 cred->sim_num = atoi(value);
2661 val = wpa_config_parse_string(value, &len);
2663 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2664 "value '%s'.", line, var, value);
2668 if (os_strcmp(var, "realm") == 0) {
2669 os_free(cred->realm);
2674 if (os_strcmp(var, "username") == 0) {
2675 str_clear_free(cred->username);
2676 cred->username = val;
2680 if (os_strcmp(var, "password") == 0) {
2681 str_clear_free(cred->password);
2682 cred->password = val;
2683 cred->ext_password = 0;
2687 if (os_strcmp(var, "ca_cert") == 0) {
2688 os_free(cred->ca_cert);
2689 cred->ca_cert = val;
2693 if (os_strcmp(var, "client_cert") == 0) {
2694 os_free(cred->client_cert);
2695 cred->client_cert = val;
2699 if (os_strcmp(var, "private_key") == 0) {
2700 os_free(cred->private_key);
2701 cred->private_key = val;
2705 if (os_strcmp(var, "private_key_passwd") == 0) {
2706 str_clear_free(cred->private_key_passwd);
2707 cred->private_key_passwd = val;
2711 if (os_strcmp(var, "imsi") == 0) {
2712 os_free(cred->imsi);
2717 if (os_strcmp(var, "milenage") == 0) {
2718 str_clear_free(cred->milenage);
2719 cred->milenage = val;
2723 if (os_strcmp(var, "domain_suffix_match") == 0) {
2724 os_free(cred->domain_suffix_match);
2725 cred->domain_suffix_match = val;
2729 if (os_strcmp(var, "domain") == 0) {
2731 new_domain = os_realloc_array(cred->domain,
2732 cred->num_domain + 1,
2734 if (new_domain == NULL) {
2738 new_domain[cred->num_domain++] = val;
2739 cred->domain = new_domain;
2743 if (os_strcmp(var, "phase1") == 0) {
2744 os_free(cred->phase1);
2749 if (os_strcmp(var, "phase2") == 0) {
2750 os_free(cred->phase2);
2755 if (os_strcmp(var, "roaming_consortium") == 0) {
2756 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2757 wpa_printf(MSG_ERROR, "Line %d: invalid "
2758 "roaming_consortium length %d (3..15 "
2759 "expected)", line, (int) len);
2763 os_memcpy(cred->roaming_consortium, val, len);
2764 cred->roaming_consortium_len = len;
2769 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2770 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2772 wpa_printf(MSG_ERROR, "Line %d: invalid "
2773 "required_roaming_consortium length %d "
2774 "(3..15 expected)", line, (int) len);
2778 os_memcpy(cred->required_roaming_consortium, val, len);
2779 cred->required_roaming_consortium_len = len;
2784 if (os_strcmp(var, "excluded_ssid") == 0) {
2785 struct excluded_ssid *e;
2787 if (len > MAX_SSID_LEN) {
2788 wpa_printf(MSG_ERROR, "Line %d: invalid "
2789 "excluded_ssid length %d", line, (int) len);
2794 e = os_realloc_array(cred->excluded_ssid,
2795 cred->num_excluded_ssid + 1,
2796 sizeof(struct excluded_ssid));
2801 cred->excluded_ssid = e;
2803 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2804 os_memcpy(e->ssid, val, len);
2812 if (os_strcmp(var, "roaming_partner") == 0) {
2813 struct roaming_partner *p;
2816 p = os_realloc_array(cred->roaming_partner,
2817 cred->num_roaming_partner + 1,
2818 sizeof(struct roaming_partner));
2823 cred->roaming_partner = p;
2825 p = &cred->roaming_partner[cred->num_roaming_partner];
2827 pos = os_strchr(val, ',');
2833 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2837 os_memcpy(p->fqdn, val, pos - val);
2839 p->exact_match = atoi(pos);
2841 pos = os_strchr(pos, ',');
2848 p->priority = atoi(pos);
2850 pos = os_strchr(pos, ',');
2857 if (os_strlen(pos) >= sizeof(p->country)) {
2861 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2863 cred->num_roaming_partner++;
2869 if (os_strcmp(var, "provisioning_sp") == 0) {
2870 os_free(cred->provisioning_sp);
2871 cred->provisioning_sp = val;
2876 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2886 static char * alloc_int_str(int val)
2890 buf = os_malloc(20);
2893 os_snprintf(buf, 20, "%d", val);
2898 static char * alloc_strdup(const char *str)
2902 return os_strdup(str);
2906 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2908 if (os_strcmp(var, "temporary") == 0)
2909 return alloc_int_str(cred->temporary);
2911 if (os_strcmp(var, "priority") == 0)
2912 return alloc_int_str(cred->priority);
2914 if (os_strcmp(var, "sp_priority") == 0)
2915 return alloc_int_str(cred->sp_priority);
2917 if (os_strcmp(var, "pcsc") == 0)
2918 return alloc_int_str(cred->pcsc);
2920 if (os_strcmp(var, "eap") == 0) {
2921 if (!cred->eap_method)
2923 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2924 cred->eap_method[0].method));
2927 if (os_strcmp(var, "update_identifier") == 0)
2928 return alloc_int_str(cred->update_identifier);
2930 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
2931 return alloc_int_str(cred->min_dl_bandwidth_home);
2933 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
2934 return alloc_int_str(cred->min_ul_bandwidth_home);
2936 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
2937 return alloc_int_str(cred->min_dl_bandwidth_roaming);
2939 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
2940 return alloc_int_str(cred->min_ul_bandwidth_roaming);
2942 if (os_strcmp(var, "max_bss_load") == 0)
2943 return alloc_int_str(cred->max_bss_load);
2945 if (os_strcmp(var, "req_conn_capab") == 0) {
2947 char *buf, *end, *pos;
2950 if (!cred->num_req_conn_capab)
2953 buf = os_malloc(4000);
2958 for (i = 0; i < cred->num_req_conn_capab; i++) {
2961 ret = os_snprintf(pos, end - pos, "%s%u",
2963 cred->req_conn_capab_proto[i]);
2964 if (ret < 0 || ret >= end - pos)
2968 ports = cred->req_conn_capab_port[i];
2971 for (j = 0; ports[j] != -1; j++) {
2972 ret = os_snprintf(pos, end - pos,
2976 if (ret < 0 || ret >= end - pos)
2986 if (os_strcmp(var, "ocsp") == 0)
2987 return alloc_int_str(cred->ocsp);
2989 if (os_strcmp(var, "realm") == 0)
2990 return alloc_strdup(cred->realm);
2992 if (os_strcmp(var, "username") == 0)
2993 return alloc_strdup(cred->username);
2995 if (os_strcmp(var, "password") == 0) {
2996 if (!cred->password)
2998 return alloc_strdup("*");
3001 if (os_strcmp(var, "ca_cert") == 0)
3002 return alloc_strdup(cred->ca_cert);
3004 if (os_strcmp(var, "client_cert") == 0)
3005 return alloc_strdup(cred->client_cert);
3007 if (os_strcmp(var, "private_key") == 0)
3008 return alloc_strdup(cred->private_key);
3010 if (os_strcmp(var, "private_key_passwd") == 0) {
3011 if (!cred->private_key_passwd)
3013 return alloc_strdup("*");
3016 if (os_strcmp(var, "imsi") == 0)
3017 return alloc_strdup(cred->imsi);
3019 if (os_strcmp(var, "milenage") == 0) {
3020 if (!(cred->milenage))
3022 return alloc_strdup("*");
3025 if (os_strcmp(var, "domain_suffix_match") == 0)
3026 return alloc_strdup(cred->domain_suffix_match);
3028 if (os_strcmp(var, "domain") == 0) {
3030 char *buf, *end, *pos;
3033 if (!cred->num_domain)
3036 buf = os_malloc(4000);
3042 for (i = 0; i < cred->num_domain; i++) {
3043 ret = os_snprintf(pos, end - pos, "%s%s",
3044 i > 0 ? "\n" : "", cred->domain[i]);
3045 if (ret < 0 || ret >= end - pos)
3053 if (os_strcmp(var, "phase1") == 0)
3054 return alloc_strdup(cred->phase1);
3056 if (os_strcmp(var, "phase2") == 0)
3057 return alloc_strdup(cred->phase2);
3059 if (os_strcmp(var, "roaming_consortium") == 0) {
3063 if (!cred->roaming_consortium_len)
3065 buflen = cred->roaming_consortium_len * 2 + 1;
3066 buf = os_malloc(buflen);
3069 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3070 cred->roaming_consortium_len);
3074 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3078 if (!cred->required_roaming_consortium_len)
3080 buflen = cred->required_roaming_consortium_len * 2 + 1;
3081 buf = os_malloc(buflen);
3084 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3085 cred->required_roaming_consortium_len);
3089 if (os_strcmp(var, "excluded_ssid") == 0) {
3091 char *buf, *end, *pos;
3093 if (!cred->num_excluded_ssid)
3096 buf = os_malloc(4000);
3102 for (i = 0; i < cred->num_excluded_ssid; i++) {
3103 struct excluded_ssid *e;
3106 e = &cred->excluded_ssid[i];
3107 ret = os_snprintf(pos, end - pos, "%s%s",
3109 wpa_ssid_txt(e->ssid, e->ssid_len));
3110 if (ret < 0 || ret >= end - pos)
3118 if (os_strcmp(var, "roaming_partner") == 0) {
3120 char *buf, *end, *pos;
3122 if (!cred->num_roaming_partner)
3125 buf = os_malloc(4000);
3131 for (i = 0; i < cred->num_roaming_partner; i++) {
3132 struct roaming_partner *p;
3135 p = &cred->roaming_partner[i];
3136 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3138 p->fqdn, p->exact_match, p->priority,
3140 if (ret < 0 || ret >= end - pos)
3148 if (os_strcmp(var, "provisioning_sp") == 0)
3149 return alloc_strdup(cred->provisioning_sp);
3155 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3157 struct wpa_cred *cred;
3159 cred = config->cred;
3170 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3173 struct wpa_cred *cred, *last = NULL;
3176 cred = config->cred;
3185 cred = os_zalloc(sizeof(*cred));
3189 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3193 config->cred = cred;
3199 int wpa_config_remove_cred(struct wpa_config *config, int id)
3201 struct wpa_cred *cred, *prev = NULL;
3203 cred = config->cred;
3215 prev->next = cred->next;
3217 config->cred = cred->next;
3219 wpa_config_free_cred(cred);
3224 #ifndef CONFIG_NO_CONFIG_BLOBS
3226 * wpa_config_get_blob - Get a named configuration blob
3227 * @config: Configuration data from wpa_config_read()
3228 * @name: Name of the blob
3229 * Returns: Pointer to blob data or %NULL if not found
3231 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3234 struct wpa_config_blob *blob = config->blobs;
3237 if (os_strcmp(blob->name, name) == 0)
3246 * wpa_config_set_blob - Set or add a named configuration blob
3247 * @config: Configuration data from wpa_config_read()
3248 * @blob: New value for the blob
3250 * Adds a new configuration blob or replaces the current value of an existing
3253 void wpa_config_set_blob(struct wpa_config *config,
3254 struct wpa_config_blob *blob)
3256 wpa_config_remove_blob(config, blob->name);
3257 blob->next = config->blobs;
3258 config->blobs = blob;
3263 * wpa_config_free_blob - Free blob data
3264 * @blob: Pointer to blob to be freed
3266 void wpa_config_free_blob(struct wpa_config_blob *blob)
3269 os_free(blob->name);
3270 bin_clear_free(blob->data, blob->len);
3277 * wpa_config_remove_blob - Remove a named configuration blob
3278 * @config: Configuration data from wpa_config_read()
3279 * @name: Name of the blob to remove
3280 * Returns: 0 if blob was removed or -1 if blob was not found
3282 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3284 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3287 if (os_strcmp(pos->name, name) == 0) {
3289 prev->next = pos->next;
3291 config->blobs = pos->next;
3292 wpa_config_free_blob(pos);
3301 #endif /* CONFIG_NO_CONFIG_BLOBS */
3305 * wpa_config_alloc_empty - Allocate an empty configuration
3306 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3308 * @driver_param: Driver parameters
3309 * Returns: Pointer to allocated configuration data or %NULL on failure
3311 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3312 const char *driver_param)
3314 struct wpa_config *config;
3315 const int aCWmin = 4, aCWmax = 10;
3316 const struct hostapd_wmm_ac_params ac_bk =
3317 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3318 const struct hostapd_wmm_ac_params ac_be =
3319 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3320 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3321 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3322 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3323 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3325 config = os_zalloc(sizeof(*config));
3328 config->eapol_version = DEFAULT_EAPOL_VERSION;
3329 config->ap_scan = DEFAULT_AP_SCAN;
3330 config->user_mpm = DEFAULT_USER_MPM;
3331 config->fast_reauth = DEFAULT_FAST_REAUTH;
3332 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3333 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3334 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3335 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3336 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3337 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3338 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3339 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3340 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3341 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3342 config->wmm_ac_params[0] = ac_be;
3343 config->wmm_ac_params[1] = ac_bk;
3344 config->wmm_ac_params[2] = ac_vi;
3345 config->wmm_ac_params[3] = ac_vo;
3346 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3347 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3348 config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD;
3351 config->ctrl_interface = os_strdup(ctrl_interface);
3353 config->driver_param = os_strdup(driver_param);
3359 #ifndef CONFIG_NO_STDOUT_DEBUG
3361 * wpa_config_debug_dump_networks - Debug dump of configured networks
3362 * @config: Configuration data from wpa_config_read()
3364 void wpa_config_debug_dump_networks(struct wpa_config *config)
3367 struct wpa_ssid *ssid;
3369 for (prio = 0; prio < config->num_prio; prio++) {
3370 ssid = config->pssid[prio];
3371 wpa_printf(MSG_DEBUG, "Priority group %d",
3374 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3376 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3381 #endif /* CONFIG_NO_STDOUT_DEBUG */
3384 struct global_parse_data {
3386 int (*parser)(const struct global_parse_data *data,
3387 struct wpa_config *config, int line, const char *value);
3388 void *param1, *param2, *param3;
3389 unsigned int changed_flag;
3393 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3394 struct wpa_config *config, int line,
3400 dst = (int *) (((u8 *) config) + (long) data->param1);
3401 val = strtol(pos, &end, 0);
3403 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3409 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3411 if (data->param2 && *dst < (long) data->param2) {
3412 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3413 "min_value=%ld)", line, data->name, *dst,
3414 (long) data->param2);
3415 *dst = (long) data->param2;
3419 if (data->param3 && *dst > (long) data->param3) {
3420 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3421 "max_value=%ld)", line, data->name, *dst,
3422 (long) data->param3);
3423 *dst = (long) data->param3;
3431 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3432 struct wpa_config *config, int line,
3438 len = os_strlen(pos);
3439 if (data->param2 && len < (size_t) data->param2) {
3440 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3441 "min_len=%ld)", line, data->name,
3442 (unsigned long) len, (long) data->param2);
3446 if (data->param3 && len > (size_t) data->param3) {
3447 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3448 "max_len=%ld)", line, data->name,
3449 (unsigned long) len, (long) data->param3);
3453 tmp = os_strdup(pos);
3457 dst = (char **) (((u8 *) config) + (long) data->param1);
3460 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3466 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3467 struct wpa_config *config, int line,
3474 tmp = wpa_config_parse_string(pos, &len);
3476 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3481 res = wpa_global_config_parse_str(data, config, line, tmp);
3487 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3488 struct wpa_config *config, int line,
3492 struct wpabuf **dst, *tmp;
3494 len = os_strlen(pos);
3498 tmp = wpabuf_alloc(len / 2);
3502 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3507 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3510 wpa_printf(MSG_DEBUG, "%s", data->name);
3516 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3517 struct wpa_config *config, int line,
3522 freqs = wpa_config_parse_int_array(value);
3525 if (freqs[0] == 0) {
3529 os_free(config->freq_list);
3530 config->freq_list = freqs;
3536 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3537 struct wpa_config *config, int line,
3541 struct hostapd_ip_addr addr;
3543 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3545 if (addr.af != AF_INET)
3548 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3549 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3550 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3551 WPA_GET_BE32((u8 *) dst));
3555 #endif /* CONFIG_P2P */
3558 static int wpa_config_process_country(const struct global_parse_data *data,
3559 struct wpa_config *config, int line,
3562 if (!pos[0] || !pos[1]) {
3563 wpa_printf(MSG_DEBUG, "Invalid country set");
3566 config->country[0] = pos[0];
3567 config->country[1] = pos[1];
3568 wpa_printf(MSG_DEBUG, "country='%c%c'",
3569 config->country[0], config->country[1]);
3574 static int wpa_config_process_load_dynamic_eap(
3575 const struct global_parse_data *data, struct wpa_config *config,
3576 int line, const char *so)
3579 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3580 ret = eap_peer_method_load(so);
3582 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3585 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3586 "method '%s'.", line, so);
3596 static int wpa_config_process_uuid(const struct global_parse_data *data,
3597 struct wpa_config *config, int line,
3601 if (uuid_str2bin(pos, config->uuid)) {
3602 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3605 uuid_bin2str(config->uuid, buf, sizeof(buf));
3606 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3611 static int wpa_config_process_device_type(
3612 const struct global_parse_data *data,
3613 struct wpa_config *config, int line, const char *pos)
3615 return wps_dev_type_str2bin(pos, config->device_type);
3619 static int wpa_config_process_os_version(const struct global_parse_data *data,
3620 struct wpa_config *config, int line,
3623 if (hexstr2bin(pos, config->os_version, 4)) {
3624 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3627 wpa_printf(MSG_DEBUG, "os_version=%08x",
3628 WPA_GET_BE32(config->os_version));
3633 static int wpa_config_process_wps_vendor_ext_m1(
3634 const struct global_parse_data *data,
3635 struct wpa_config *config, int line, const char *pos)
3638 int len = os_strlen(pos) / 2;
3642 wpa_printf(MSG_ERROR, "Line %d: "
3643 "invalid wps_vendor_ext_m1", line);
3647 tmp = wpabuf_alloc(len);
3649 p = wpabuf_put(tmp, len);
3651 if (hexstr2bin(pos, p, len)) {
3652 wpa_printf(MSG_ERROR, "Line %d: "
3653 "invalid wps_vendor_ext_m1", line);
3658 wpabuf_free(config->wps_vendor_ext_m1);
3659 config->wps_vendor_ext_m1 = tmp;
3661 wpa_printf(MSG_ERROR, "Can not allocate "
3662 "memory for wps_vendor_ext_m1");
3669 #endif /* CONFIG_WPS */
3672 static int wpa_config_process_sec_device_type(
3673 const struct global_parse_data *data,
3674 struct wpa_config *config, int line, const char *pos)
3678 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3679 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3684 idx = config->num_sec_device_types;
3686 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3689 config->num_sec_device_types++;
3694 static int wpa_config_process_p2p_pref_chan(
3695 const struct global_parse_data *data,
3696 struct wpa_config *config, int line, const char *pos)
3698 struct p2p_channel *pref = NULL, *n;
3699 unsigned int num = 0;
3703 /* format: class:chan,class:chan,... */
3706 op_class = atoi(pos);
3707 pos2 = os_strchr(pos, ':');
3713 n = os_realloc_array(pref, num + 1,
3714 sizeof(struct p2p_channel));
3718 pref[num].op_class = op_class;
3719 pref[num].chan = chan;
3722 pos = os_strchr(pos2, ',');
3728 os_free(config->p2p_pref_chan);
3729 config->p2p_pref_chan = pref;
3730 config->num_p2p_pref_chan = num;
3731 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3732 (u8 *) config->p2p_pref_chan,
3733 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3739 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3744 static int wpa_config_process_p2p_no_go_freq(
3745 const struct global_parse_data *data,
3746 struct wpa_config *config, int line, const char *pos)
3750 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3752 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3756 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3757 config->p2p_no_go_freq.num);
3762 #endif /* CONFIG_P2P */
3765 static int wpa_config_process_hessid(
3766 const struct global_parse_data *data,
3767 struct wpa_config *config, int line, const char *pos)
3769 if (hwaddr_aton2(pos, config->hessid) < 0) {
3770 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3779 static int wpa_config_process_sae_groups(
3780 const struct global_parse_data *data,
3781 struct wpa_config *config, int line, const char *pos)
3783 int *groups = wpa_config_parse_int_array(pos);
3784 if (groups == NULL) {
3785 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3790 os_free(config->sae_groups);
3791 config->sae_groups = groups;
3797 static int wpa_config_process_ap_vendor_elements(
3798 const struct global_parse_data *data,
3799 struct wpa_config *config, int line, const char *pos)
3802 int len = os_strlen(pos) / 2;
3806 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3811 tmp = wpabuf_alloc(len);
3813 p = wpabuf_put(tmp, len);
3815 if (hexstr2bin(pos, p, len)) {
3816 wpa_printf(MSG_ERROR, "Line %d: invalid "
3817 "ap_vendor_elements", line);
3822 wpabuf_free(config->ap_vendor_elements);
3823 config->ap_vendor_elements = tmp;
3825 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3826 "ap_vendor_elements");
3834 #ifdef CONFIG_CTRL_IFACE
3835 static int wpa_config_process_no_ctrl_interface(
3836 const struct global_parse_data *data,
3837 struct wpa_config *config, int line, const char *pos)
3839 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3840 os_free(config->ctrl_interface);
3841 config->ctrl_interface = NULL;
3844 #endif /* CONFIG_CTRL_IFACE */
3850 /* OFFSET: Get offset of a variable within the wpa_config structure */
3851 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3853 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3854 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3855 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3856 #define INT(f) _INT(f), NULL, NULL
3857 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3858 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3859 #define STR(f) _STR(f), NULL, NULL
3860 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3861 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3862 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3864 static const struct global_parse_data global_fields[] = {
3865 #ifdef CONFIG_CTRL_IFACE
3866 { STR(ctrl_interface), 0 },
3867 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3868 { STR(ctrl_interface_group), 0 } /* deprecated */,
3869 #endif /* CONFIG_CTRL_IFACE */
3870 #ifdef CONFIG_MACSEC
3871 { INT_RANGE(eapol_version, 1, 3), 0 },
3872 #else /* CONFIG_MACSEC */
3873 { INT_RANGE(eapol_version, 1, 2), 0 },
3874 #endif /* CONFIG_MACSEC */
3875 { INT(ap_scan), 0 },
3876 { FUNC(bgscan), 0 },
3878 { INT(user_mpm), 0 },
3879 #endif /* CONFIG_MESH */
3880 { INT(disable_scan_offload), 0 },
3881 { INT(fast_reauth), 0 },
3882 { STR(opensc_engine_path), 0 },
3883 { STR(pkcs11_engine_path), 0 },
3884 { STR(pkcs11_module_path), 0 },
3885 { STR(openssl_ciphers), 0 },
3886 { STR(pcsc_reader), 0 },
3887 { STR(pcsc_pin), 0 },
3888 { INT(external_sim), 0 },
3889 { STR(driver_param), 0 },
3890 { INT(dot11RSNAConfigPMKLifetime), 0 },
3891 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3892 { INT(dot11RSNAConfigSATimeout), 0 },
3893 #ifndef CONFIG_NO_CONFIG_WRITE
3894 { INT(update_config), 0 },
3895 #endif /* CONFIG_NO_CONFIG_WRITE */
3896 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3898 { FUNC(uuid), CFG_CHANGED_UUID },
3899 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3900 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3901 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3902 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3903 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3904 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3905 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3906 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3907 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3908 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3909 #endif /* CONFIG_WPS */
3911 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3912 { INT(p2p_listen_reg_class), 0 },
3913 { INT(p2p_listen_channel), 0 },
3914 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3915 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3916 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3917 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3918 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3919 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3920 { INT(p2p_group_idle), 0 },
3921 { INT_RANGE(p2p_passphrase_len, 8, 63),
3922 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3923 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3924 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3925 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3926 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3927 { INT(p2p_go_ht40), 0 },
3928 { INT(p2p_go_vht), 0 },
3929 { INT(p2p_disabled), 0 },
3930 { INT(p2p_no_group_iface), 0 },
3931 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
3932 { IPV4(ip_addr_go), 0 },
3933 { IPV4(ip_addr_mask), 0 },
3934 { IPV4(ip_addr_start), 0 },
3935 { IPV4(ip_addr_end), 0 },
3936 #endif /* CONFIG_P2P */
3937 { FUNC(country), CFG_CHANGED_COUNTRY },
3938 { INT(bss_max_count), 0 },
3939 { INT(bss_expiration_age), 0 },
3940 { INT(bss_expiration_scan_count), 0 },
3941 { INT_RANGE(filter_ssids, 0, 1), 0 },
3942 { INT_RANGE(filter_rssi, -100, 0), 0 },
3943 { INT(max_num_sta), 0 },
3944 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
3946 { INT_RANGE(hs20, 0, 1), 0 },
3947 #endif /* CONFIG_HS20 */
3948 { INT_RANGE(interworking, 0, 1), 0 },
3949 { FUNC(hessid), 0 },
3950 { INT_RANGE(access_network_type, 0, 15), 0 },
3951 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
3952 { STR(autoscan), 0 },
3953 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
3954 CFG_CHANGED_NFC_PASSWORD_TOKEN },
3955 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3956 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3957 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
3958 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
3959 { INT(p2p_go_max_inactivity), 0 },
3960 { INT_RANGE(auto_interworking, 0, 1), 0 },
3963 { FUNC(sae_groups), 0 },
3964 { INT(dtim_period), 0 },
3965 { INT(beacon_int), 0 },
3966 { FUNC(ap_vendor_elements), 0 },
3967 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
3968 { FUNC(freq_list), 0 },
3969 { INT(scan_cur_freq), 0 },
3970 { INT(sched_scan_interval), 0 },
3971 { INT(tdls_external_control), 0},
3972 { STR(osu_dir), 0 },
3973 { STR(wowlan_triggers), 0 },
3974 { INT(p2p_search_delay), 0},
3975 { INT(mac_addr), 0 },
3976 { INT(rand_addr_lifetime), 0 },
3977 { INT(preassoc_mac_addr), 0 },
3978 { INT(key_mgmt_offload), 0},
3990 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
3993 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
3998 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
3999 const struct global_parse_data *field = &global_fields[i];
4000 size_t flen = os_strlen(field->name);
4001 if (os_strncmp(pos, field->name, flen) != 0 ||
4005 if (field->parser(field, config, line, pos + flen + 1)) {
4006 wpa_printf(MSG_ERROR, "Line %d: failed to "
4007 "parse '%s'.", line, pos);
4010 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
4011 config->wps_nfc_pw_from_config = 1;
4012 config->changed_parameters |= field->changed_flag;
4015 if (i == NUM_GLOBAL_FIELDS) {
4017 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
4018 char *tmp = os_strchr(pos, '=');
4022 wpa_printf(MSG_ERROR, "Line %d: invalid line "
4027 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
4029 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
4034 #endif /* CONFIG_AP */
4037 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",