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 (os_snprintf_error(20, res)) {
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 (os_snprintf_error(20, res)) {
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);
365 res = os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
366 if (os_snprintf_error(len, res)) {
372 #endif /* CONFIG_EXT_PASSWORD */
374 if (ssid->passphrase)
375 return wpa_config_write_string_ascii(
376 (const u8 *) ssid->passphrase,
377 os_strlen(ssid->passphrase));
380 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
384 #endif /* NO_CONFIG_WRITE */
387 static int wpa_config_parse_proto(const struct parse_data *data,
388 struct wpa_ssid *ssid, int line,
391 int val = 0, last, errors = 0;
392 char *start, *end, *buf;
394 buf = os_strdup(value);
399 while (*start != '\0') {
400 while (*start == ' ' || *start == '\t')
405 while (*end != ' ' && *end != '\t' && *end != '\0')
409 if (os_strcmp(start, "WPA") == 0)
410 val |= WPA_PROTO_WPA;
411 else if (os_strcmp(start, "RSN") == 0 ||
412 os_strcmp(start, "WPA2") == 0)
413 val |= WPA_PROTO_RSN;
414 else if (os_strcmp(start, "OSEN") == 0)
415 val |= WPA_PROTO_OSEN;
417 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
429 wpa_printf(MSG_ERROR,
430 "Line %d: no proto values configured.", line);
434 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
436 return errors ? -1 : 0;
440 #ifndef NO_CONFIG_WRITE
441 static char * wpa_config_write_proto(const struct parse_data *data,
442 struct wpa_ssid *ssid)
445 char *buf, *pos, *end;
447 pos = buf = os_zalloc(20);
452 if (ssid->proto & WPA_PROTO_WPA) {
453 ret = os_snprintf(pos, end - pos, "%sWPA",
454 pos == buf ? "" : " ");
455 if (os_snprintf_error(end - pos, ret))
460 if (ssid->proto & WPA_PROTO_RSN) {
461 ret = os_snprintf(pos, end - pos, "%sRSN",
462 pos == buf ? "" : " ");
463 if (os_snprintf_error(end - pos, ret))
468 if (ssid->proto & WPA_PROTO_OSEN) {
469 ret = os_snprintf(pos, end - pos, "%sOSEN",
470 pos == buf ? "" : " ");
471 if (os_snprintf_error(end - pos, ret))
483 #endif /* NO_CONFIG_WRITE */
486 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
487 struct wpa_ssid *ssid, int line,
490 int val = 0, last, errors = 0;
491 char *start, *end, *buf;
493 buf = os_strdup(value);
498 while (*start != '\0') {
499 while (*start == ' ' || *start == '\t')
504 while (*end != ' ' && *end != '\t' && *end != '\0')
508 if (os_strcmp(start, "WPA-PSK") == 0)
509 val |= WPA_KEY_MGMT_PSK;
510 else if (os_strcmp(start, "WPA-EAP") == 0)
511 val |= WPA_KEY_MGMT_IEEE8021X;
512 else if (os_strcmp(start, "IEEE8021X") == 0)
513 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
514 else if (os_strcmp(start, "NONE") == 0)
515 val |= WPA_KEY_MGMT_NONE;
516 else if (os_strcmp(start, "WPA-NONE") == 0)
517 val |= WPA_KEY_MGMT_WPA_NONE;
518 #ifdef CONFIG_IEEE80211R
519 else if (os_strcmp(start, "FT-PSK") == 0)
520 val |= WPA_KEY_MGMT_FT_PSK;
521 else if (os_strcmp(start, "FT-EAP") == 0)
522 val |= WPA_KEY_MGMT_FT_IEEE8021X;
523 #endif /* CONFIG_IEEE80211R */
524 #ifdef CONFIG_IEEE80211W
525 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
526 val |= WPA_KEY_MGMT_PSK_SHA256;
527 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
528 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
529 #endif /* CONFIG_IEEE80211W */
531 else if (os_strcmp(start, "WPS") == 0)
532 val |= WPA_KEY_MGMT_WPS;
533 #endif /* CONFIG_WPS */
535 else if (os_strcmp(start, "SAE") == 0)
536 val |= WPA_KEY_MGMT_SAE;
537 else if (os_strcmp(start, "FT-SAE") == 0)
538 val |= WPA_KEY_MGMT_FT_SAE;
539 #endif /* CONFIG_SAE */
541 else if (os_strcmp(start, "OSEN") == 0)
542 val |= WPA_KEY_MGMT_OSEN;
543 #endif /* CONFIG_HS20 */
544 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
545 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
547 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
559 wpa_printf(MSG_ERROR,
560 "Line %d: no key_mgmt values configured.", line);
564 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
565 ssid->key_mgmt = val;
566 return errors ? -1 : 0;
570 #ifndef NO_CONFIG_WRITE
571 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
572 struct wpa_ssid *ssid)
574 char *buf, *pos, *end;
577 pos = buf = os_zalloc(100);
582 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
583 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
584 pos == buf ? "" : " ");
585 if (os_snprintf_error(end - pos, ret)) {
592 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
593 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
594 pos == buf ? "" : " ");
595 if (os_snprintf_error(end - pos, ret)) {
602 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
603 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
604 pos == buf ? "" : " ");
605 if (os_snprintf_error(end - pos, ret)) {
612 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
613 ret = os_snprintf(pos, end - pos, "%sNONE",
614 pos == buf ? "" : " ");
615 if (os_snprintf_error(end - pos, ret)) {
622 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
623 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
624 pos == buf ? "" : " ");
625 if (os_snprintf_error(end - pos, ret)) {
632 #ifdef CONFIG_IEEE80211R
633 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
634 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
635 pos == buf ? "" : " ");
636 if (os_snprintf_error(end - pos, ret)) {
643 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
644 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
645 pos == buf ? "" : " ");
646 if (os_snprintf_error(end - pos, ret)) {
652 #endif /* CONFIG_IEEE80211R */
654 #ifdef CONFIG_IEEE80211W
655 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
656 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
657 pos == buf ? "" : " ");
658 if (os_snprintf_error(end - pos, ret)) {
665 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
666 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
667 pos == buf ? "" : " ");
668 if (os_snprintf_error(end - pos, ret)) {
674 #endif /* CONFIG_IEEE80211W */
677 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
678 ret = os_snprintf(pos, end - pos, "%sWPS",
679 pos == buf ? "" : " ");
680 if (os_snprintf_error(end - pos, ret)) {
686 #endif /* CONFIG_WPS */
689 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
690 ret = os_snprintf(pos, end - pos, "%sSAE",
691 pos == buf ? "" : " ");
692 if (os_snprintf_error(end - pos, ret)) {
699 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
700 ret = os_snprintf(pos, end - pos, "%sFT-SAE",
701 pos == buf ? "" : " ");
702 if (os_snprintf_error(end - pos, ret)) {
708 #endif /* CONFIG_SAE */
711 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) {
712 ret = os_snprintf(pos, end - pos, "%sOSEN",
713 pos == buf ? "" : " ");
714 if (os_snprintf_error(end - pos, ret)) {
720 #endif /* CONFIG_HS20 */
722 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
723 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B",
724 pos == buf ? "" : " ");
725 if (os_snprintf_error(end - pos, ret)) {
739 #endif /* NO_CONFIG_WRITE */
742 static int wpa_config_parse_cipher(int line, const char *value)
744 int val = wpa_parse_cipher(value);
746 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
751 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
759 #ifndef NO_CONFIG_WRITE
760 static char * wpa_config_write_cipher(int cipher)
762 char *buf = os_zalloc(50);
766 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
773 #endif /* NO_CONFIG_WRITE */
776 static int wpa_config_parse_pairwise(const struct parse_data *data,
777 struct wpa_ssid *ssid, int line,
781 val = wpa_config_parse_cipher(line, value);
784 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
785 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
786 "(0x%x).", line, val);
790 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
791 ssid->pairwise_cipher = val;
796 #ifndef NO_CONFIG_WRITE
797 static char * wpa_config_write_pairwise(const struct parse_data *data,
798 struct wpa_ssid *ssid)
800 return wpa_config_write_cipher(ssid->pairwise_cipher);
802 #endif /* NO_CONFIG_WRITE */
805 static int wpa_config_parse_group(const struct parse_data *data,
806 struct wpa_ssid *ssid, int line,
810 val = wpa_config_parse_cipher(line, value);
813 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
814 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
815 "(0x%x).", line, val);
819 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
820 ssid->group_cipher = val;
825 #ifndef NO_CONFIG_WRITE
826 static char * wpa_config_write_group(const struct parse_data *data,
827 struct wpa_ssid *ssid)
829 return wpa_config_write_cipher(ssid->group_cipher);
831 #endif /* NO_CONFIG_WRITE */
834 static int wpa_config_parse_auth_alg(const struct parse_data *data,
835 struct wpa_ssid *ssid, int line,
838 int val = 0, last, errors = 0;
839 char *start, *end, *buf;
841 buf = os_strdup(value);
846 while (*start != '\0') {
847 while (*start == ' ' || *start == '\t')
852 while (*end != ' ' && *end != '\t' && *end != '\0')
856 if (os_strcmp(start, "OPEN") == 0)
857 val |= WPA_AUTH_ALG_OPEN;
858 else if (os_strcmp(start, "SHARED") == 0)
859 val |= WPA_AUTH_ALG_SHARED;
860 else if (os_strcmp(start, "LEAP") == 0)
861 val |= WPA_AUTH_ALG_LEAP;
863 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
875 wpa_printf(MSG_ERROR,
876 "Line %d: no auth_alg values configured.", line);
880 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
881 ssid->auth_alg = val;
882 return errors ? -1 : 0;
886 #ifndef NO_CONFIG_WRITE
887 static char * wpa_config_write_auth_alg(const struct parse_data *data,
888 struct wpa_ssid *ssid)
890 char *buf, *pos, *end;
893 pos = buf = os_zalloc(30);
898 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
899 ret = os_snprintf(pos, end - pos, "%sOPEN",
900 pos == buf ? "" : " ");
901 if (os_snprintf_error(end - pos, ret)) {
908 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
909 ret = os_snprintf(pos, end - pos, "%sSHARED",
910 pos == buf ? "" : " ");
911 if (os_snprintf_error(end - pos, ret)) {
918 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
919 ret = os_snprintf(pos, end - pos, "%sLEAP",
920 pos == buf ? "" : " ");
921 if (os_snprintf_error(end - pos, ret)) {
935 #endif /* NO_CONFIG_WRITE */
938 static int * wpa_config_parse_int_array(const char *value)
946 freqs = os_calloc(len + 1, sizeof(int));
957 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
962 for (i = len; i <= len * 2; i++)
968 freqs[used] = atoi(pos);
969 if (freqs[used] == 0)
972 pos = os_strchr(pos + 1, ' ');
979 static int wpa_config_parse_scan_freq(const struct parse_data *data,
980 struct wpa_ssid *ssid, int line,
985 freqs = wpa_config_parse_int_array(value);
992 os_free(ssid->scan_freq);
993 ssid->scan_freq = freqs;
999 static int wpa_config_parse_freq_list(const struct parse_data *data,
1000 struct wpa_ssid *ssid, int line,
1005 freqs = wpa_config_parse_int_array(value);
1008 if (freqs[0] == 0) {
1012 os_free(ssid->freq_list);
1013 ssid->freq_list = freqs;
1019 #ifndef NO_CONFIG_WRITE
1020 static char * wpa_config_write_freqs(const struct parse_data *data,
1023 char *buf, *pos, *end;
1031 for (i = 0; freqs[i]; i++)
1034 pos = buf = os_zalloc(10 * count + 1);
1037 end = buf + 10 * count + 1;
1039 for (i = 0; freqs[i]; i++) {
1040 ret = os_snprintf(pos, end - pos, "%s%u",
1041 i == 0 ? "" : " ", freqs[i]);
1042 if (os_snprintf_error(end - pos, ret)) {
1053 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1054 struct wpa_ssid *ssid)
1056 return wpa_config_write_freqs(data, ssid->scan_freq);
1060 static char * wpa_config_write_freq_list(const struct parse_data *data,
1061 struct wpa_ssid *ssid)
1063 return wpa_config_write_freqs(data, ssid->freq_list);
1065 #endif /* NO_CONFIG_WRITE */
1068 #ifdef IEEE8021X_EAPOL
1069 static int wpa_config_parse_eap(const struct parse_data *data,
1070 struct wpa_ssid *ssid, int line,
1073 int last, errors = 0;
1074 char *start, *end, *buf;
1075 struct eap_method_type *methods = NULL, *tmp;
1076 size_t num_methods = 0;
1078 buf = os_strdup(value);
1083 while (*start != '\0') {
1084 while (*start == ' ' || *start == '\t')
1089 while (*end != ' ' && *end != '\t' && *end != '\0')
1091 last = *end == '\0';
1094 methods = os_realloc_array(methods, num_methods + 1,
1096 if (methods == NULL) {
1101 methods[num_methods].method = eap_peer_get_type(
1102 start, &methods[num_methods].vendor);
1103 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1104 methods[num_methods].method == EAP_TYPE_NONE) {
1105 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1106 "'%s'", line, start);
1107 wpa_printf(MSG_ERROR, "You may need to add support for"
1108 " this EAP method during wpa_supplicant\n"
1109 "build time configuration.\n"
1110 "See README for more information.");
1112 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1113 methods[num_methods].method == EAP_TYPE_LEAP)
1125 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1126 if (methods == NULL) {
1130 methods[num_methods].vendor = EAP_VENDOR_IETF;
1131 methods[num_methods].method = EAP_TYPE_NONE;
1134 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1135 (u8 *) methods, num_methods * sizeof(*methods));
1136 os_free(ssid->eap.eap_methods);
1137 ssid->eap.eap_methods = methods;
1138 return errors ? -1 : 0;
1142 static char * wpa_config_write_eap(const struct parse_data *data,
1143 struct wpa_ssid *ssid)
1146 char *buf, *pos, *end;
1147 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1150 if (eap_methods == NULL)
1153 pos = buf = os_zalloc(100);
1158 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1159 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1160 name = eap_get_name(eap_methods[i].vendor,
1161 eap_methods[i].method);
1163 ret = os_snprintf(pos, end - pos, "%s%s",
1164 pos == buf ? "" : " ", name);
1165 if (os_snprintf_error(end - pos, ret))
1177 static int wpa_config_parse_password(const struct parse_data *data,
1178 struct wpa_ssid *ssid, int line,
1183 if (os_strcmp(value, "NULL") == 0) {
1184 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1185 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1186 ssid->eap.password = NULL;
1187 ssid->eap.password_len = 0;
1191 #ifdef CONFIG_EXT_PASSWORD
1192 if (os_strncmp(value, "ext:", 4) == 0) {
1193 char *name = os_strdup(value + 4);
1196 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1197 ssid->eap.password = (u8 *) name;
1198 ssid->eap.password_len = os_strlen(name);
1199 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1200 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1203 #endif /* CONFIG_EXT_PASSWORD */
1205 if (os_strncmp(value, "hash:", 5) != 0) {
1209 tmp = wpa_config_parse_string(value, &res_len);
1211 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1215 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1216 (u8 *) tmp, res_len);
1218 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1219 ssid->eap.password = (u8 *) tmp;
1220 ssid->eap.password_len = res_len;
1221 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1222 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1228 /* NtPasswordHash: hash:<32 hex digits> */
1229 if (os_strlen(value + 5) != 2 * 16) {
1230 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1231 "(expected 32 hex digits)", line);
1235 hash = os_malloc(16);
1239 if (hexstr2bin(value + 5, hash, 16)) {
1241 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1245 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1247 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1248 ssid->eap.password = hash;
1249 ssid->eap.password_len = 16;
1250 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1251 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1257 static char * wpa_config_write_password(const struct parse_data *data,
1258 struct wpa_ssid *ssid)
1262 if (ssid->eap.password == NULL)
1265 #ifdef CONFIG_EXT_PASSWORD
1266 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1267 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1270 os_memcpy(buf, "ext:", 4);
1271 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1274 #endif /* CONFIG_EXT_PASSWORD */
1276 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1277 return wpa_config_write_string(
1278 ssid->eap.password, ssid->eap.password_len);
1281 buf = os_malloc(5 + 32 + 1);
1285 os_memcpy(buf, "hash:", 5);
1286 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1290 #endif /* IEEE8021X_EAPOL */
1293 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1294 const char *value, int idx)
1296 char *buf, title[20];
1299 buf = wpa_config_parse_string(value, len);
1301 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1305 if (*len > MAX_WEP_KEY_LEN) {
1306 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1311 if (*len && *len != 5 && *len != 13 && *len != 16) {
1312 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1313 "this network block will be ignored",
1314 line, (unsigned int) *len);
1316 os_memcpy(key, buf, *len);
1317 str_clear_free(buf);
1318 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1319 if (!os_snprintf_error(sizeof(title), res))
1320 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1325 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1326 struct wpa_ssid *ssid, int line,
1329 return wpa_config_parse_wep_key(ssid->wep_key[0],
1330 &ssid->wep_key_len[0], line,
1335 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1336 struct wpa_ssid *ssid, int line,
1339 return wpa_config_parse_wep_key(ssid->wep_key[1],
1340 &ssid->wep_key_len[1], line,
1345 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1346 struct wpa_ssid *ssid, int line,
1349 return wpa_config_parse_wep_key(ssid->wep_key[2],
1350 &ssid->wep_key_len[2], line,
1355 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1356 struct wpa_ssid *ssid, int line,
1359 return wpa_config_parse_wep_key(ssid->wep_key[3],
1360 &ssid->wep_key_len[3], line,
1365 #ifndef NO_CONFIG_WRITE
1366 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1368 if (ssid->wep_key_len[idx] == 0)
1370 return wpa_config_write_string(ssid->wep_key[idx],
1371 ssid->wep_key_len[idx]);
1375 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1376 struct wpa_ssid *ssid)
1378 return wpa_config_write_wep_key(ssid, 0);
1382 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1383 struct wpa_ssid *ssid)
1385 return wpa_config_write_wep_key(ssid, 1);
1389 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1390 struct wpa_ssid *ssid)
1392 return wpa_config_write_wep_key(ssid, 2);
1396 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1397 struct wpa_ssid *ssid)
1399 return wpa_config_write_wep_key(ssid, 3);
1401 #endif /* NO_CONFIG_WRITE */
1406 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1407 struct wpa_ssid *ssid, int line,
1410 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1411 os_strcmp(value, "any") == 0) {
1412 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1413 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1416 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1417 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1421 ssid->bssid_set = 1;
1422 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1423 MAC2STR(ssid->go_p2p_dev_addr));
1428 #ifndef NO_CONFIG_WRITE
1429 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1430 struct wpa_ssid *ssid)
1435 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1438 value = os_malloc(20);
1441 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1442 if (os_snprintf_error(20, res)) {
1446 value[20 - 1] = '\0';
1449 #endif /* NO_CONFIG_WRITE */
1452 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1453 struct wpa_ssid *ssid, int line,
1457 u8 *buf, *n, addr[ETH_ALEN];
1464 while (pos && *pos) {
1468 if (hwaddr_aton(pos, addr)) {
1470 wpa_printf(MSG_ERROR, "Line %d: Invalid "
1471 "p2p_client_list address '%s'.",
1476 /* continue anyway since this could have been from a
1477 * truncated configuration file line */
1478 wpa_printf(MSG_INFO, "Line %d: Ignore likely "
1479 "truncated p2p_client_list address '%s'",
1482 n = os_realloc_array(buf, count + 1, ETH_ALEN);
1488 os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
1489 os_memcpy(buf, addr, ETH_ALEN);
1491 wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
1495 pos = os_strchr(pos, ' ');
1498 os_free(ssid->p2p_client_list);
1499 ssid->p2p_client_list = buf;
1500 ssid->num_p2p_clients = count;
1506 #ifndef NO_CONFIG_WRITE
1507 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1508 struct wpa_ssid *ssid)
1510 char *value, *end, *pos;
1514 if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
1517 value = os_malloc(20 * ssid->num_p2p_clients);
1521 end = value + 20 * ssid->num_p2p_clients;
1523 for (i = ssid->num_p2p_clients; i > 0; i--) {
1524 res = os_snprintf(pos, end - pos, MACSTR " ",
1525 MAC2STR(ssid->p2p_client_list +
1526 (i - 1) * ETH_ALEN));
1527 if (os_snprintf_error(end - pos, res)) {
1539 #endif /* NO_CONFIG_WRITE */
1542 static int wpa_config_parse_psk_list(const struct parse_data *data,
1543 struct wpa_ssid *ssid, int line,
1546 struct psk_list_entry *p;
1549 p = os_zalloc(sizeof(*p));
1554 if (os_strncmp(pos, "P2P-", 4) == 0) {
1559 if (hwaddr_aton(pos, p->addr)) {
1560 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1567 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1574 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1575 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1581 dl_list_add(&ssid->psk_list, &p->list);
1587 #ifndef NO_CONFIG_WRITE
1588 static char * wpa_config_write_psk_list(const struct parse_data *data,
1589 struct wpa_ssid *ssid)
1593 #endif /* NO_CONFIG_WRITE */
1595 #endif /* CONFIG_P2P */
1600 static int wpa_config_parse_mesh_basic_rates(const struct parse_data *data,
1601 struct wpa_ssid *ssid, int line,
1604 int *rates = wpa_config_parse_int_array(value);
1606 if (rates == NULL) {
1607 wpa_printf(MSG_ERROR, "Line %d: Invalid mesh_basic_rates '%s'",
1611 if (rates[0] == 0) {
1616 os_free(ssid->mesh_basic_rates);
1617 ssid->mesh_basic_rates = rates;
1623 #ifndef NO_CONFIG_WRITE
1625 static char * wpa_config_write_mesh_basic_rates(const struct parse_data *data,
1626 struct wpa_ssid *ssid)
1628 return wpa_config_write_freqs(data, ssid->mesh_basic_rates);
1631 #endif /* NO_CONFIG_WRITE */
1633 #endif /* CONFIG_MESH */
1636 /* Helper macros for network block parser */
1641 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1642 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1644 /* STR: Define a string variable for an ASCII string; f = field name */
1645 #ifdef NO_CONFIG_WRITE
1646 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1647 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1648 #else /* NO_CONFIG_WRITE */
1649 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1650 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1651 #endif /* NO_CONFIG_WRITE */
1652 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1653 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1654 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1655 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1657 /* STR_LEN: Define a string variable with a separate variable for storing the
1658 * data length. Unlike STR(), this can be used to store arbitrary binary data
1659 * (i.e., even nul termination character). */
1660 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1661 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1662 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1663 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1664 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1666 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1667 * explicitly specified. */
1668 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1669 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1670 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1672 #ifdef NO_CONFIG_WRITE
1673 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1674 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1675 #else /* NO_CONFIG_WRITE */
1676 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1677 OFFSET(f), (void *) 0
1678 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1679 OFFSET(eap.f), (void *) 0
1680 #endif /* NO_CONFIG_WRITE */
1682 /* INT: Define an integer variable */
1683 #define INT(f) _INT(f), NULL, NULL, 0
1684 #define INTe(f) _INTe(f), NULL, NULL, 0
1686 /* INT_RANGE: Define an integer variable with allowed value range */
1687 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1689 /* FUNC: Define a configuration variable that uses a custom function for
1690 * parsing and writing the value. */
1691 #ifdef NO_CONFIG_WRITE
1692 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1693 #else /* NO_CONFIG_WRITE */
1694 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1695 NULL, NULL, NULL, NULL
1696 #endif /* NO_CONFIG_WRITE */
1697 #define FUNC(f) _FUNC(f), 0
1698 #define FUNC_KEY(f) _FUNC(f), 1
1701 * Table of network configuration variables. This table is used to parse each
1702 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1703 * that is inside a network block.
1705 * This table is generated using the helper macros defined above and with
1706 * generous help from the C pre-processor. The field name is stored as a string
1707 * into .name and for STR and INT types, the offset of the target buffer within
1708 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1709 * offset to the field containing the length of the configuration variable.
1710 * .param3 and .param4 can be used to mark the allowed range (length for STR
1711 * and value for INT).
1713 * For each configuration line in wpa_supplicant.conf, the parser goes through
1714 * this table and select the entry that matches with the field name. The parser
1715 * function (.parser) is then called to parse the actual value of the field.
1717 * This kind of mechanism makes it easy to add new configuration parameters,
1718 * since only one line needs to be added into this table and into the
1719 * struct wpa_ssid definition if the new variable is either a string or
1720 * integer. More complex types will need to use their own parser and writer
1723 static const struct parse_data ssid_fields[] = {
1724 { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
1725 { INT_RANGE(scan_ssid, 0, 1) },
1730 { INT(bg_scan_period) },
1734 { FUNC(scan_freq) },
1735 { FUNC(freq_list) },
1736 #ifdef IEEE8021X_EAPOL
1738 { STR_LENe(identity) },
1739 { STR_LENe(anonymous_identity) },
1740 { FUNC_KEY(password) },
1743 { STRe(client_cert) },
1744 { STRe(private_key) },
1745 { STR_KEYe(private_key_passwd) },
1747 { STRe(subject_match) },
1748 { STRe(altsubject_match) },
1749 { STRe(domain_suffix_match) },
1752 { STRe(client_cert2) },
1753 { STRe(private_key2) },
1754 { STR_KEYe(private_key2_passwd) },
1756 { STRe(subject_match2) },
1757 { STRe(altsubject_match2) },
1758 { STRe(domain_suffix_match2) },
1763 { STRe(engine_id) },
1766 { STRe(ca_cert_id) },
1768 { STRe(engine2_id) },
1771 { STRe(ca_cert2_id) },
1774 { INT(eapol_flags) },
1776 { STRe(openssl_ciphers) },
1778 #endif /* IEEE8021X_EAPOL */
1779 { FUNC_KEY(wep_key0) },
1780 { FUNC_KEY(wep_key1) },
1781 { FUNC_KEY(wep_key2) },
1782 { FUNC_KEY(wep_key3) },
1783 { INT(wep_tx_keyidx) },
1785 #ifdef IEEE8021X_EAPOL
1786 { INT(eap_workaround) },
1788 { INTe(fragment_size) },
1790 #endif /* IEEE8021X_EAPOL */
1792 { INT_RANGE(mode, 0, 5) },
1793 { INT_RANGE(no_auto_peer, 0, 1) },
1794 #else /* CONFIG_MESH */
1795 { INT_RANGE(mode, 0, 4) },
1796 #endif /* CONFIG_MESH */
1797 { INT_RANGE(proactive_key_caching, 0, 1) },
1798 { INT_RANGE(disabled, 0, 2) },
1800 #ifdef CONFIG_IEEE80211W
1801 { INT_RANGE(ieee80211w, 0, 2) },
1802 #endif /* CONFIG_IEEE80211W */
1803 { INT_RANGE(peerkey, 0, 1) },
1804 { INT_RANGE(mixed_cell, 0, 1) },
1805 { INT_RANGE(frequency, 0, 65000) },
1807 { FUNC(mesh_basic_rates) },
1808 { INT(dot11MeshMaxRetries) },
1809 { INT(dot11MeshRetryTimeout) },
1810 { INT(dot11MeshConfirmTimeout) },
1811 { INT(dot11MeshHoldingTimeout) },
1812 #endif /* CONFIG_MESH */
1813 { INT(wpa_ptk_rekey) },
1815 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
1817 { FUNC(go_p2p_dev_addr) },
1818 { FUNC(p2p_client_list) },
1820 #endif /* CONFIG_P2P */
1821 #ifdef CONFIG_HT_OVERRIDES
1822 { INT_RANGE(disable_ht, 0, 1) },
1823 { INT_RANGE(disable_ht40, -1, 1) },
1824 { INT_RANGE(disable_sgi, 0, 1) },
1825 { INT_RANGE(disable_ldpc, 0, 1) },
1826 { INT_RANGE(ht40_intolerant, 0, 1) },
1827 { INT_RANGE(disable_max_amsdu, -1, 1) },
1828 { INT_RANGE(ampdu_factor, -1, 3) },
1829 { INT_RANGE(ampdu_density, -1, 7) },
1831 #endif /* CONFIG_HT_OVERRIDES */
1832 #ifdef CONFIG_VHT_OVERRIDES
1833 { INT_RANGE(disable_vht, 0, 1) },
1835 { INT(vht_capa_mask) },
1836 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
1837 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
1838 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
1839 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
1840 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
1841 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
1842 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
1843 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
1844 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
1845 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
1846 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
1847 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
1848 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
1849 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
1850 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
1851 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
1852 #endif /* CONFIG_VHT_OVERRIDES */
1853 { INT(ap_max_inactivity) },
1854 { INT(dtim_period) },
1855 { INT(beacon_int) },
1856 #ifdef CONFIG_MACSEC
1857 { INT_RANGE(macsec_policy, 0, 1) },
1858 #endif /* CONFIG_MACSEC */
1860 { INT(update_identifier) },
1861 #endif /* CONFIG_HS20 */
1862 { INT_RANGE(mac_addr, 0, 2) },
1874 #undef STR_RANGE_KEY
1881 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
1885 * wpa_config_add_prio_network - Add a network to priority lists
1886 * @config: Configuration data from wpa_config_read()
1887 * @ssid: Pointer to the network configuration to be added to the list
1888 * Returns: 0 on success, -1 on failure
1890 * This function is used to add a network block to the priority list of
1891 * networks. This must be called for each network when reading in the full
1892 * configuration. In addition, this can be used indirectly when updating
1893 * priorities by calling wpa_config_update_prio_list().
1895 int wpa_config_add_prio_network(struct wpa_config *config,
1896 struct wpa_ssid *ssid)
1899 struct wpa_ssid *prev, **nlist;
1902 * Add to an existing priority list if one is available for the
1903 * configured priority level for this network.
1905 for (prio = 0; prio < config->num_prio; prio++) {
1906 prev = config->pssid[prio];
1907 if (prev->priority == ssid->priority) {
1915 /* First network for this priority - add a new priority list */
1916 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
1917 sizeof(struct wpa_ssid *));
1921 for (prio = 0; prio < config->num_prio; prio++) {
1922 if (nlist[prio]->priority < ssid->priority) {
1923 os_memmove(&nlist[prio + 1], &nlist[prio],
1924 (config->num_prio - prio) *
1925 sizeof(struct wpa_ssid *));
1932 config->pssid = nlist;
1939 * wpa_config_update_prio_list - Update network priority list
1940 * @config: Configuration data from wpa_config_read()
1941 * Returns: 0 on success, -1 on failure
1943 * This function is called to update the priority list of networks in the
1944 * configuration when a network is being added or removed. This is also called
1945 * if a priority for a network is changed.
1947 int wpa_config_update_prio_list(struct wpa_config *config)
1949 struct wpa_ssid *ssid;
1952 os_free(config->pssid);
1953 config->pssid = NULL;
1954 config->num_prio = 0;
1956 ssid = config->ssid;
1959 if (wpa_config_add_prio_network(config, ssid) < 0)
1968 #ifdef IEEE8021X_EAPOL
1969 static void eap_peer_config_free(struct eap_peer_config *eap)
1971 os_free(eap->eap_methods);
1972 bin_clear_free(eap->identity, eap->identity_len);
1973 os_free(eap->anonymous_identity);
1974 bin_clear_free(eap->password, eap->password_len);
1975 os_free(eap->ca_cert);
1976 os_free(eap->ca_path);
1977 os_free(eap->client_cert);
1978 os_free(eap->private_key);
1979 str_clear_free(eap->private_key_passwd);
1980 os_free(eap->dh_file);
1981 os_free(eap->subject_match);
1982 os_free(eap->altsubject_match);
1983 os_free(eap->domain_suffix_match);
1984 os_free(eap->ca_cert2);
1985 os_free(eap->ca_path2);
1986 os_free(eap->client_cert2);
1987 os_free(eap->private_key2);
1988 str_clear_free(eap->private_key2_passwd);
1989 os_free(eap->dh_file2);
1990 os_free(eap->subject_match2);
1991 os_free(eap->altsubject_match2);
1992 os_free(eap->domain_suffix_match2);
1993 os_free(eap->phase1);
1994 os_free(eap->phase2);
1996 str_clear_free(eap->pin);
1997 os_free(eap->engine_id);
1998 os_free(eap->key_id);
1999 os_free(eap->cert_id);
2000 os_free(eap->ca_cert_id);
2001 os_free(eap->key2_id);
2002 os_free(eap->cert2_id);
2003 os_free(eap->ca_cert2_id);
2004 str_clear_free(eap->pin2);
2005 os_free(eap->engine2_id);
2007 os_free(eap->pending_req_otp);
2008 os_free(eap->pac_file);
2009 bin_clear_free(eap->new_password, eap->new_password_len);
2010 str_clear_free(eap->external_sim_resp);
2011 os_free(eap->openssl_ciphers);
2013 #endif /* IEEE8021X_EAPOL */
2017 * wpa_config_free_ssid - Free network/ssid configuration data
2018 * @ssid: Configuration data for the network
2020 * This function frees all resources allocated for the network configuration
2023 void wpa_config_free_ssid(struct wpa_ssid *ssid)
2025 struct psk_list_entry *psk;
2027 os_free(ssid->ssid);
2028 str_clear_free(ssid->passphrase);
2029 os_free(ssid->ext_psk);
2030 #ifdef IEEE8021X_EAPOL
2031 eap_peer_config_free(&ssid->eap);
2032 #endif /* IEEE8021X_EAPOL */
2033 os_free(ssid->id_str);
2034 os_free(ssid->scan_freq);
2035 os_free(ssid->freq_list);
2036 os_free(ssid->bgscan);
2037 os_free(ssid->p2p_client_list);
2038 #ifdef CONFIG_HT_OVERRIDES
2039 os_free(ssid->ht_mcs);
2040 #endif /* CONFIG_HT_OVERRIDES */
2042 os_free(ssid->mesh_basic_rates);
2043 #endif /* CONFIG_MESH */
2044 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
2046 dl_list_del(&psk->list);
2047 bin_clear_free(psk, sizeof(*psk));
2049 bin_clear_free(ssid, sizeof(*ssid));
2053 void wpa_config_free_cred(struct wpa_cred *cred)
2057 os_free(cred->realm);
2058 str_clear_free(cred->username);
2059 str_clear_free(cred->password);
2060 os_free(cred->ca_cert);
2061 os_free(cred->client_cert);
2062 os_free(cred->private_key);
2063 str_clear_free(cred->private_key_passwd);
2064 os_free(cred->imsi);
2065 str_clear_free(cred->milenage);
2066 for (i = 0; i < cred->num_domain; i++)
2067 os_free(cred->domain[i]);
2068 os_free(cred->domain);
2069 os_free(cred->domain_suffix_match);
2070 os_free(cred->eap_method);
2071 os_free(cred->phase1);
2072 os_free(cred->phase2);
2073 os_free(cred->excluded_ssid);
2074 os_free(cred->roaming_partner);
2075 os_free(cred->provisioning_sp);
2076 for (i = 0; i < cred->num_req_conn_capab; i++)
2077 os_free(cred->req_conn_capab_port[i]);
2078 os_free(cred->req_conn_capab_port);
2079 os_free(cred->req_conn_capab_proto);
2084 void wpa_config_flush_blobs(struct wpa_config *config)
2086 #ifndef CONFIG_NO_CONFIG_BLOBS
2087 struct wpa_config_blob *blob, *prev;
2089 blob = config->blobs;
2090 config->blobs = NULL;
2094 wpa_config_free_blob(prev);
2096 #endif /* CONFIG_NO_CONFIG_BLOBS */
2101 * wpa_config_free - Free configuration data
2102 * @config: Configuration data from wpa_config_read()
2104 * This function frees all resources allocated for the configuration data by
2105 * wpa_config_read().
2107 void wpa_config_free(struct wpa_config *config)
2109 struct wpa_ssid *ssid, *prev = NULL;
2110 struct wpa_cred *cred, *cprev;
2113 ssid = config->ssid;
2117 wpa_config_free_ssid(prev);
2120 cred = config->cred;
2124 wpa_config_free_cred(cprev);
2127 wpa_config_flush_blobs(config);
2129 wpabuf_free(config->wps_vendor_ext_m1);
2130 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++)
2131 wpabuf_free(config->wps_vendor_ext[i]);
2132 os_free(config->ctrl_interface);
2133 os_free(config->ctrl_interface_group);
2134 os_free(config->opensc_engine_path);
2135 os_free(config->pkcs11_engine_path);
2136 os_free(config->pkcs11_module_path);
2137 os_free(config->openssl_ciphers);
2138 os_free(config->pcsc_reader);
2139 str_clear_free(config->pcsc_pin);
2140 os_free(config->driver_param);
2141 os_free(config->device_name);
2142 os_free(config->manufacturer);
2143 os_free(config->model_name);
2144 os_free(config->model_number);
2145 os_free(config->serial_number);
2146 os_free(config->config_methods);
2147 os_free(config->p2p_ssid_postfix);
2148 os_free(config->pssid);
2149 os_free(config->p2p_pref_chan);
2150 os_free(config->p2p_no_go_freq.range);
2151 os_free(config->autoscan);
2152 os_free(config->freq_list);
2153 wpabuf_free(config->wps_nfc_dh_pubkey);
2154 wpabuf_free(config->wps_nfc_dh_privkey);
2155 wpabuf_free(config->wps_nfc_dev_pw);
2156 os_free(config->ext_password_backend);
2157 os_free(config->sae_groups);
2158 wpabuf_free(config->ap_vendor_elements);
2159 os_free(config->osu_dir);
2160 os_free(config->wowlan_triggers);
2166 * wpa_config_foreach_network - Iterate over each configured network
2167 * @config: Configuration data from wpa_config_read()
2168 * @func: Callback function to process each network
2169 * @arg: Opaque argument to pass to callback function
2171 * Iterate over the set of configured networks calling the specified
2172 * function for each item. We guard against callbacks removing the
2175 void wpa_config_foreach_network(struct wpa_config *config,
2176 void (*func)(void *, struct wpa_ssid *),
2179 struct wpa_ssid *ssid, *next;
2181 ssid = config->ssid;
2191 * wpa_config_get_network - Get configured network based on id
2192 * @config: Configuration data from wpa_config_read()
2193 * @id: Unique network id to search for
2194 * Returns: Network configuration or %NULL if not found
2196 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2198 struct wpa_ssid *ssid;
2200 ssid = config->ssid;
2212 * wpa_config_add_network - Add a new network with empty configuration
2213 * @config: Configuration data from wpa_config_read()
2214 * Returns: The new network configuration or %NULL if operation failed
2216 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2219 struct wpa_ssid *ssid, *last = NULL;
2222 ssid = config->ssid;
2231 ssid = os_zalloc(sizeof(*ssid));
2235 dl_list_init(&ssid->psk_list);
2239 config->ssid = ssid;
2241 wpa_config_update_prio_list(config);
2248 * wpa_config_remove_network - Remove a configured network based on id
2249 * @config: Configuration data from wpa_config_read()
2250 * @id: Unique network id to search for
2251 * Returns: 0 on success, or -1 if the network was not found
2253 int wpa_config_remove_network(struct wpa_config *config, int id)
2255 struct wpa_ssid *ssid, *prev = NULL;
2257 ssid = config->ssid;
2269 prev->next = ssid->next;
2271 config->ssid = ssid->next;
2273 wpa_config_update_prio_list(config);
2274 wpa_config_free_ssid(ssid);
2280 * wpa_config_set_network_defaults - Set network default values
2281 * @ssid: Pointer to network configuration data
2283 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2285 ssid->proto = DEFAULT_PROTO;
2286 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2287 ssid->group_cipher = DEFAULT_GROUP;
2288 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2289 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2290 #ifdef IEEE8021X_EAPOL
2291 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2292 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2293 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2294 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2295 #endif /* IEEE8021X_EAPOL */
2297 ssid->dot11MeshMaxRetries = DEFAULT_MESH_MAX_RETRIES;
2298 ssid->dot11MeshRetryTimeout = DEFAULT_MESH_RETRY_TIMEOUT;
2299 ssid->dot11MeshConfirmTimeout = DEFAULT_MESH_CONFIRM_TIMEOUT;
2300 ssid->dot11MeshHoldingTimeout = DEFAULT_MESH_HOLDING_TIMEOUT;
2301 #endif /* CONFIG_MESH */
2302 #ifdef CONFIG_HT_OVERRIDES
2303 ssid->disable_ht = DEFAULT_DISABLE_HT;
2304 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2305 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2306 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2307 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2308 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2309 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2310 #endif /* CONFIG_HT_OVERRIDES */
2311 #ifdef CONFIG_VHT_OVERRIDES
2312 ssid->vht_rx_mcs_nss_1 = -1;
2313 ssid->vht_rx_mcs_nss_2 = -1;
2314 ssid->vht_rx_mcs_nss_3 = -1;
2315 ssid->vht_rx_mcs_nss_4 = -1;
2316 ssid->vht_rx_mcs_nss_5 = -1;
2317 ssid->vht_rx_mcs_nss_6 = -1;
2318 ssid->vht_rx_mcs_nss_7 = -1;
2319 ssid->vht_rx_mcs_nss_8 = -1;
2320 ssid->vht_tx_mcs_nss_1 = -1;
2321 ssid->vht_tx_mcs_nss_2 = -1;
2322 ssid->vht_tx_mcs_nss_3 = -1;
2323 ssid->vht_tx_mcs_nss_4 = -1;
2324 ssid->vht_tx_mcs_nss_5 = -1;
2325 ssid->vht_tx_mcs_nss_6 = -1;
2326 ssid->vht_tx_mcs_nss_7 = -1;
2327 ssid->vht_tx_mcs_nss_8 = -1;
2328 #endif /* CONFIG_VHT_OVERRIDES */
2329 ssid->proactive_key_caching = -1;
2330 #ifdef CONFIG_IEEE80211W
2331 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2332 #endif /* CONFIG_IEEE80211W */
2333 ssid->mac_addr = -1;
2338 * wpa_config_set - Set a variable in network configuration
2339 * @ssid: Pointer to network configuration data
2340 * @var: Variable name, e.g., "ssid"
2341 * @value: Variable value
2342 * @line: Line number in configuration file or 0 if not used
2343 * Returns: 0 on success, -1 on failure
2345 * This function can be used to set network configuration variables based on
2346 * both the configuration file and management interface input. The value
2347 * parameter must be in the same format as the text-based configuration file is
2348 * using. For example, strings are using double quotation marks.
2350 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2356 if (ssid == NULL || var == NULL || value == NULL)
2359 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2360 const struct parse_data *field = &ssid_fields[i];
2361 if (os_strcmp(var, field->name) != 0)
2364 if (field->parser(field, ssid, line, value)) {
2366 wpa_printf(MSG_ERROR, "Line %d: failed to "
2367 "parse %s '%s'.", line, var, value);
2373 if (i == NUM_SSID_FIELDS) {
2375 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2376 "'%s'.", line, var);
2385 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2392 len = os_strlen(value);
2393 buf = os_malloc(len + 3);
2397 os_memcpy(buf + 1, value, len);
2399 buf[len + 2] = '\0';
2400 ret = wpa_config_set(ssid, var, buf, 0);
2407 * wpa_config_get_all - Get all options from network configuration
2408 * @ssid: Pointer to network configuration data
2409 * @get_keys: Determines if keys/passwords will be included in returned list
2410 * (if they may be exported)
2411 * Returns: %NULL terminated list of all set keys and their values in the form
2412 * of [key1, val1, key2, val2, ... , NULL]
2414 * This function can be used to get list of all configured network properties.
2415 * The caller is responsible for freeing the returned list and all its
2418 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2420 const struct parse_data *field;
2426 get_keys = get_keys && ssid->export_keys;
2428 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2433 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2434 field = &ssid_fields[i];
2435 if (field->key_data && !get_keys)
2437 value = field->writer(field, ssid);
2440 if (os_strlen(value) == 0) {
2445 key = os_strdup(field->name);
2451 props[fields_num * 2] = key;
2452 props[fields_num * 2 + 1] = value;
2468 #ifndef NO_CONFIG_WRITE
2470 * wpa_config_get - Get a variable in network configuration
2471 * @ssid: Pointer to network configuration data
2472 * @var: Variable name, e.g., "ssid"
2473 * Returns: Value of the variable or %NULL on failure
2475 * This function can be used to get network configuration variables. The
2476 * returned value is a copy of the configuration variable in text format, i.e,.
2477 * the same format that the text-based configuration file and wpa_config_set()
2478 * are using for the value. The caller is responsible for freeing the returned
2481 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2485 if (ssid == NULL || var == NULL)
2488 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2489 const struct parse_data *field = &ssid_fields[i];
2490 if (os_strcmp(var, field->name) == 0)
2491 return field->writer(field, ssid);
2499 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2500 * @ssid: Pointer to network configuration data
2501 * @var: Variable name, e.g., "ssid"
2502 * Returns: Value of the variable or %NULL on failure
2504 * This function can be used to get network configuration variable like
2505 * wpa_config_get(). The only difference is that this functions does not expose
2506 * key/password material from the configuration. In case a key/password field
2507 * is requested, the returned value is an empty string or %NULL if the variable
2508 * is not set or "*" if the variable is set (regardless of its value). The
2509 * returned value is a copy of the configuration variable in text format, i.e,.
2510 * the same format that the text-based configuration file and wpa_config_set()
2511 * are using for the value. The caller is responsible for freeing the returned
2514 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2518 if (ssid == NULL || var == NULL)
2521 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2522 const struct parse_data *field = &ssid_fields[i];
2523 if (os_strcmp(var, field->name) == 0) {
2524 char *res = field->writer(field, ssid);
2525 if (field->key_data) {
2526 if (res && res[0]) {
2527 wpa_printf(MSG_DEBUG, "Do not allow "
2528 "key_data field to be "
2530 str_clear_free(res);
2531 return os_strdup("*");
2543 #endif /* NO_CONFIG_WRITE */
2547 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2548 * @ssid: Pointer to network configuration data
2550 * This function must be called to update WPA PSK when either SSID or the
2551 * passphrase has changed for the network configuration.
2553 void wpa_config_update_psk(struct wpa_ssid *ssid)
2555 #ifndef CONFIG_NO_PBKDF2
2556 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2557 ssid->psk, PMK_LEN);
2558 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2559 ssid->psk, PMK_LEN);
2561 #endif /* CONFIG_NO_PBKDF2 */
2565 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2570 int *ports, *nports;
2572 unsigned int num_ports;
2574 proto = os_realloc_array(cred->req_conn_capab_proto,
2575 cred->num_req_conn_capab + 1, sizeof(u8));
2578 cred->req_conn_capab_proto = proto;
2580 port = os_realloc_array(cred->req_conn_capab_port,
2581 cred->num_req_conn_capab + 1, sizeof(int *));
2584 cred->req_conn_capab_port = port;
2586 proto[cred->num_req_conn_capab] = atoi(value);
2588 pos = os_strchr(value, ':');
2590 port[cred->num_req_conn_capab] = NULL;
2591 cred->num_req_conn_capab++;
2600 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2601 if (nports == NULL) {
2606 ports[num_ports++] = atoi(pos);
2608 pos = os_strchr(pos, ',');
2614 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2615 if (nports == NULL) {
2620 ports[num_ports] = -1;
2622 port[cred->num_req_conn_capab] = ports;
2623 cred->num_req_conn_capab++;
2628 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2629 const char *value, int line)
2634 if (os_strcmp(var, "temporary") == 0) {
2635 cred->temporary = atoi(value);
2639 if (os_strcmp(var, "priority") == 0) {
2640 cred->priority = atoi(value);
2644 if (os_strcmp(var, "sp_priority") == 0) {
2645 int prio = atoi(value);
2646 if (prio < 0 || prio > 255)
2648 cred->sp_priority = prio;
2652 if (os_strcmp(var, "pcsc") == 0) {
2653 cred->pcsc = atoi(value);
2657 if (os_strcmp(var, "eap") == 0) {
2658 struct eap_method_type method;
2659 method.method = eap_peer_get_type(value, &method.vendor);
2660 if (method.vendor == EAP_VENDOR_IETF &&
2661 method.method == EAP_TYPE_NONE) {
2662 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2663 "for a credential", line, value);
2666 os_free(cred->eap_method);
2667 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2668 if (cred->eap_method == NULL)
2670 os_memcpy(cred->eap_method, &method, sizeof(method));
2674 if (os_strcmp(var, "password") == 0 &&
2675 os_strncmp(value, "ext:", 4) == 0) {
2676 str_clear_free(cred->password);
2677 cred->password = os_strdup(value);
2678 cred->ext_password = 1;
2682 if (os_strcmp(var, "update_identifier") == 0) {
2683 cred->update_identifier = atoi(value);
2687 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2688 cred->min_dl_bandwidth_home = atoi(value);
2692 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2693 cred->min_ul_bandwidth_home = atoi(value);
2697 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2698 cred->min_dl_bandwidth_roaming = atoi(value);
2702 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2703 cred->min_ul_bandwidth_roaming = atoi(value);
2707 if (os_strcmp(var, "max_bss_load") == 0) {
2708 cred->max_bss_load = atoi(value);
2712 if (os_strcmp(var, "req_conn_capab") == 0)
2713 return wpa_config_set_cred_req_conn_capab(cred, value);
2715 if (os_strcmp(var, "ocsp") == 0) {
2716 cred->ocsp = atoi(value);
2720 if (os_strcmp(var, "sim_num") == 0) {
2721 cred->sim_num = atoi(value);
2725 val = wpa_config_parse_string(value, &len);
2727 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2728 "value '%s'.", line, var, value);
2732 if (os_strcmp(var, "realm") == 0) {
2733 os_free(cred->realm);
2738 if (os_strcmp(var, "username") == 0) {
2739 str_clear_free(cred->username);
2740 cred->username = val;
2744 if (os_strcmp(var, "password") == 0) {
2745 str_clear_free(cred->password);
2746 cred->password = val;
2747 cred->ext_password = 0;
2751 if (os_strcmp(var, "ca_cert") == 0) {
2752 os_free(cred->ca_cert);
2753 cred->ca_cert = val;
2757 if (os_strcmp(var, "client_cert") == 0) {
2758 os_free(cred->client_cert);
2759 cred->client_cert = val;
2763 if (os_strcmp(var, "private_key") == 0) {
2764 os_free(cred->private_key);
2765 cred->private_key = val;
2769 if (os_strcmp(var, "private_key_passwd") == 0) {
2770 str_clear_free(cred->private_key_passwd);
2771 cred->private_key_passwd = val;
2775 if (os_strcmp(var, "imsi") == 0) {
2776 os_free(cred->imsi);
2781 if (os_strcmp(var, "milenage") == 0) {
2782 str_clear_free(cred->milenage);
2783 cred->milenage = val;
2787 if (os_strcmp(var, "domain_suffix_match") == 0) {
2788 os_free(cred->domain_suffix_match);
2789 cred->domain_suffix_match = val;
2793 if (os_strcmp(var, "domain") == 0) {
2795 new_domain = os_realloc_array(cred->domain,
2796 cred->num_domain + 1,
2798 if (new_domain == NULL) {
2802 new_domain[cred->num_domain++] = val;
2803 cred->domain = new_domain;
2807 if (os_strcmp(var, "phase1") == 0) {
2808 os_free(cred->phase1);
2813 if (os_strcmp(var, "phase2") == 0) {
2814 os_free(cred->phase2);
2819 if (os_strcmp(var, "roaming_consortium") == 0) {
2820 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
2821 wpa_printf(MSG_ERROR, "Line %d: invalid "
2822 "roaming_consortium length %d (3..15 "
2823 "expected)", line, (int) len);
2827 os_memcpy(cred->roaming_consortium, val, len);
2828 cred->roaming_consortium_len = len;
2833 if (os_strcmp(var, "required_roaming_consortium") == 0) {
2834 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
2836 wpa_printf(MSG_ERROR, "Line %d: invalid "
2837 "required_roaming_consortium length %d "
2838 "(3..15 expected)", line, (int) len);
2842 os_memcpy(cred->required_roaming_consortium, val, len);
2843 cred->required_roaming_consortium_len = len;
2848 if (os_strcmp(var, "excluded_ssid") == 0) {
2849 struct excluded_ssid *e;
2851 if (len > MAX_SSID_LEN) {
2852 wpa_printf(MSG_ERROR, "Line %d: invalid "
2853 "excluded_ssid length %d", line, (int) len);
2858 e = os_realloc_array(cred->excluded_ssid,
2859 cred->num_excluded_ssid + 1,
2860 sizeof(struct excluded_ssid));
2865 cred->excluded_ssid = e;
2867 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
2868 os_memcpy(e->ssid, val, len);
2876 if (os_strcmp(var, "roaming_partner") == 0) {
2877 struct roaming_partner *p;
2880 p = os_realloc_array(cred->roaming_partner,
2881 cred->num_roaming_partner + 1,
2882 sizeof(struct roaming_partner));
2887 cred->roaming_partner = p;
2889 p = &cred->roaming_partner[cred->num_roaming_partner];
2891 pos = os_strchr(val, ',');
2897 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
2901 os_memcpy(p->fqdn, val, pos - val);
2903 p->exact_match = atoi(pos);
2905 pos = os_strchr(pos, ',');
2912 p->priority = atoi(pos);
2914 pos = os_strchr(pos, ',');
2921 if (os_strlen(pos) >= sizeof(p->country)) {
2925 os_memcpy(p->country, pos, os_strlen(pos) + 1);
2927 cred->num_roaming_partner++;
2933 if (os_strcmp(var, "provisioning_sp") == 0) {
2934 os_free(cred->provisioning_sp);
2935 cred->provisioning_sp = val;
2940 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
2950 static char * alloc_int_str(int val)
2952 const unsigned int bufsize = 20;
2956 buf = os_malloc(bufsize);
2959 res = os_snprintf(buf, bufsize, "%d", val);
2960 if (os_snprintf_error(bufsize, res)) {
2968 static char * alloc_strdup(const char *str)
2972 return os_strdup(str);
2976 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
2978 if (os_strcmp(var, "temporary") == 0)
2979 return alloc_int_str(cred->temporary);
2981 if (os_strcmp(var, "priority") == 0)
2982 return alloc_int_str(cred->priority);
2984 if (os_strcmp(var, "sp_priority") == 0)
2985 return alloc_int_str(cred->sp_priority);
2987 if (os_strcmp(var, "pcsc") == 0)
2988 return alloc_int_str(cred->pcsc);
2990 if (os_strcmp(var, "eap") == 0) {
2991 if (!cred->eap_method)
2993 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
2994 cred->eap_method[0].method));
2997 if (os_strcmp(var, "update_identifier") == 0)
2998 return alloc_int_str(cred->update_identifier);
3000 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
3001 return alloc_int_str(cred->min_dl_bandwidth_home);
3003 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
3004 return alloc_int_str(cred->min_ul_bandwidth_home);
3006 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
3007 return alloc_int_str(cred->min_dl_bandwidth_roaming);
3009 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
3010 return alloc_int_str(cred->min_ul_bandwidth_roaming);
3012 if (os_strcmp(var, "max_bss_load") == 0)
3013 return alloc_int_str(cred->max_bss_load);
3015 if (os_strcmp(var, "req_conn_capab") == 0) {
3017 char *buf, *end, *pos;
3020 if (!cred->num_req_conn_capab)
3023 buf = os_malloc(4000);
3028 for (i = 0; i < cred->num_req_conn_capab; i++) {
3031 ret = os_snprintf(pos, end - pos, "%s%u",
3033 cred->req_conn_capab_proto[i]);
3034 if (os_snprintf_error(end - pos, ret))
3038 ports = cred->req_conn_capab_port[i];
3041 for (j = 0; ports[j] != -1; j++) {
3042 ret = os_snprintf(pos, end - pos,
3046 if (os_snprintf_error(end - pos, ret))
3056 if (os_strcmp(var, "ocsp") == 0)
3057 return alloc_int_str(cred->ocsp);
3059 if (os_strcmp(var, "realm") == 0)
3060 return alloc_strdup(cred->realm);
3062 if (os_strcmp(var, "username") == 0)
3063 return alloc_strdup(cred->username);
3065 if (os_strcmp(var, "password") == 0) {
3066 if (!cred->password)
3068 return alloc_strdup("*");
3071 if (os_strcmp(var, "ca_cert") == 0)
3072 return alloc_strdup(cred->ca_cert);
3074 if (os_strcmp(var, "client_cert") == 0)
3075 return alloc_strdup(cred->client_cert);
3077 if (os_strcmp(var, "private_key") == 0)
3078 return alloc_strdup(cred->private_key);
3080 if (os_strcmp(var, "private_key_passwd") == 0) {
3081 if (!cred->private_key_passwd)
3083 return alloc_strdup("*");
3086 if (os_strcmp(var, "imsi") == 0)
3087 return alloc_strdup(cred->imsi);
3089 if (os_strcmp(var, "milenage") == 0) {
3090 if (!(cred->milenage))
3092 return alloc_strdup("*");
3095 if (os_strcmp(var, "domain_suffix_match") == 0)
3096 return alloc_strdup(cred->domain_suffix_match);
3098 if (os_strcmp(var, "domain") == 0) {
3100 char *buf, *end, *pos;
3103 if (!cred->num_domain)
3106 buf = os_malloc(4000);
3112 for (i = 0; i < cred->num_domain; i++) {
3113 ret = os_snprintf(pos, end - pos, "%s%s",
3114 i > 0 ? "\n" : "", cred->domain[i]);
3115 if (os_snprintf_error(end - pos, ret))
3123 if (os_strcmp(var, "phase1") == 0)
3124 return alloc_strdup(cred->phase1);
3126 if (os_strcmp(var, "phase2") == 0)
3127 return alloc_strdup(cred->phase2);
3129 if (os_strcmp(var, "roaming_consortium") == 0) {
3133 if (!cred->roaming_consortium_len)
3135 buflen = cred->roaming_consortium_len * 2 + 1;
3136 buf = os_malloc(buflen);
3139 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3140 cred->roaming_consortium_len);
3144 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3148 if (!cred->required_roaming_consortium_len)
3150 buflen = cred->required_roaming_consortium_len * 2 + 1;
3151 buf = os_malloc(buflen);
3154 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3155 cred->required_roaming_consortium_len);
3159 if (os_strcmp(var, "excluded_ssid") == 0) {
3161 char *buf, *end, *pos;
3163 if (!cred->num_excluded_ssid)
3166 buf = os_malloc(4000);
3172 for (i = 0; i < cred->num_excluded_ssid; i++) {
3173 struct excluded_ssid *e;
3176 e = &cred->excluded_ssid[i];
3177 ret = os_snprintf(pos, end - pos, "%s%s",
3179 wpa_ssid_txt(e->ssid, e->ssid_len));
3180 if (os_snprintf_error(end - pos, ret))
3188 if (os_strcmp(var, "roaming_partner") == 0) {
3190 char *buf, *end, *pos;
3192 if (!cred->num_roaming_partner)
3195 buf = os_malloc(4000);
3201 for (i = 0; i < cred->num_roaming_partner; i++) {
3202 struct roaming_partner *p;
3205 p = &cred->roaming_partner[i];
3206 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3208 p->fqdn, p->exact_match, p->priority,
3210 if (os_snprintf_error(end - pos, ret))
3218 if (os_strcmp(var, "provisioning_sp") == 0)
3219 return alloc_strdup(cred->provisioning_sp);
3225 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3227 struct wpa_cred *cred;
3229 cred = config->cred;
3240 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3243 struct wpa_cred *cred, *last = NULL;
3246 cred = config->cred;
3255 cred = os_zalloc(sizeof(*cred));
3259 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3263 config->cred = cred;
3269 int wpa_config_remove_cred(struct wpa_config *config, int id)
3271 struct wpa_cred *cred, *prev = NULL;
3273 cred = config->cred;
3285 prev->next = cred->next;
3287 config->cred = cred->next;
3289 wpa_config_free_cred(cred);
3294 #ifndef CONFIG_NO_CONFIG_BLOBS
3296 * wpa_config_get_blob - Get a named configuration blob
3297 * @config: Configuration data from wpa_config_read()
3298 * @name: Name of the blob
3299 * Returns: Pointer to blob data or %NULL if not found
3301 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3304 struct wpa_config_blob *blob = config->blobs;
3307 if (os_strcmp(blob->name, name) == 0)
3316 * wpa_config_set_blob - Set or add a named configuration blob
3317 * @config: Configuration data from wpa_config_read()
3318 * @blob: New value for the blob
3320 * Adds a new configuration blob or replaces the current value of an existing
3323 void wpa_config_set_blob(struct wpa_config *config,
3324 struct wpa_config_blob *blob)
3326 wpa_config_remove_blob(config, blob->name);
3327 blob->next = config->blobs;
3328 config->blobs = blob;
3333 * wpa_config_free_blob - Free blob data
3334 * @blob: Pointer to blob to be freed
3336 void wpa_config_free_blob(struct wpa_config_blob *blob)
3339 os_free(blob->name);
3340 bin_clear_free(blob->data, blob->len);
3347 * wpa_config_remove_blob - Remove a named configuration blob
3348 * @config: Configuration data from wpa_config_read()
3349 * @name: Name of the blob to remove
3350 * Returns: 0 if blob was removed or -1 if blob was not found
3352 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3354 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3357 if (os_strcmp(pos->name, name) == 0) {
3359 prev->next = pos->next;
3361 config->blobs = pos->next;
3362 wpa_config_free_blob(pos);
3371 #endif /* CONFIG_NO_CONFIG_BLOBS */
3375 * wpa_config_alloc_empty - Allocate an empty configuration
3376 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3378 * @driver_param: Driver parameters
3379 * Returns: Pointer to allocated configuration data or %NULL on failure
3381 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3382 const char *driver_param)
3384 struct wpa_config *config;
3385 const int aCWmin = 4, aCWmax = 10;
3386 const struct hostapd_wmm_ac_params ac_bk =
3387 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3388 const struct hostapd_wmm_ac_params ac_be =
3389 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3390 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3391 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3392 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3393 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3395 config = os_zalloc(sizeof(*config));
3398 config->eapol_version = DEFAULT_EAPOL_VERSION;
3399 config->ap_scan = DEFAULT_AP_SCAN;
3400 config->user_mpm = DEFAULT_USER_MPM;
3401 config->max_peer_links = DEFAULT_MAX_PEER_LINKS;
3402 config->fast_reauth = DEFAULT_FAST_REAUTH;
3403 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3404 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3405 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3406 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3407 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3408 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3409 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3410 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3411 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3412 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3413 config->wmm_ac_params[0] = ac_be;
3414 config->wmm_ac_params[1] = ac_bk;
3415 config->wmm_ac_params[2] = ac_vi;
3416 config->wmm_ac_params[3] = ac_vo;
3417 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3418 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3419 config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD;
3422 config->ctrl_interface = os_strdup(ctrl_interface);
3424 config->driver_param = os_strdup(driver_param);
3430 #ifndef CONFIG_NO_STDOUT_DEBUG
3432 * wpa_config_debug_dump_networks - Debug dump of configured networks
3433 * @config: Configuration data from wpa_config_read()
3435 void wpa_config_debug_dump_networks(struct wpa_config *config)
3438 struct wpa_ssid *ssid;
3440 for (prio = 0; prio < config->num_prio; prio++) {
3441 ssid = config->pssid[prio];
3442 wpa_printf(MSG_DEBUG, "Priority group %d",
3445 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3447 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3452 #endif /* CONFIG_NO_STDOUT_DEBUG */
3455 struct global_parse_data {
3457 int (*parser)(const struct global_parse_data *data,
3458 struct wpa_config *config, int line, const char *value);
3459 void *param1, *param2, *param3;
3460 unsigned int changed_flag;
3464 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3465 struct wpa_config *config, int line,
3471 dst = (int *) (((u8 *) config) + (long) data->param1);
3472 val = strtol(pos, &end, 0);
3474 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3480 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3482 if (data->param2 && *dst < (long) data->param2) {
3483 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3484 "min_value=%ld)", line, data->name, *dst,
3485 (long) data->param2);
3486 *dst = (long) data->param2;
3490 if (data->param3 && *dst > (long) data->param3) {
3491 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3492 "max_value=%ld)", line, data->name, *dst,
3493 (long) data->param3);
3494 *dst = (long) data->param3;
3502 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3503 struct wpa_config *config, int line,
3509 len = os_strlen(pos);
3510 if (data->param2 && len < (size_t) data->param2) {
3511 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3512 "min_len=%ld)", line, data->name,
3513 (unsigned long) len, (long) data->param2);
3517 if (data->param3 && len > (size_t) data->param3) {
3518 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3519 "max_len=%ld)", line, data->name,
3520 (unsigned long) len, (long) data->param3);
3524 tmp = os_strdup(pos);
3528 dst = (char **) (((u8 *) config) + (long) data->param1);
3531 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3537 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3538 struct wpa_config *config, int line,
3545 tmp = wpa_config_parse_string(pos, &len);
3547 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3552 res = wpa_global_config_parse_str(data, config, line, tmp);
3558 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3559 struct wpa_config *config, int line,
3563 struct wpabuf **dst, *tmp;
3565 len = os_strlen(pos);
3569 tmp = wpabuf_alloc(len / 2);
3573 if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
3578 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3581 wpa_printf(MSG_DEBUG, "%s", data->name);
3587 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3588 struct wpa_config *config, int line,
3593 freqs = wpa_config_parse_int_array(value);
3596 if (freqs[0] == 0) {
3600 os_free(config->freq_list);
3601 config->freq_list = freqs;
3607 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3608 struct wpa_config *config, int line,
3612 struct hostapd_ip_addr addr;
3614 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3616 if (addr.af != AF_INET)
3619 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3620 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3621 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3622 WPA_GET_BE32((u8 *) dst));
3626 #endif /* CONFIG_P2P */
3629 static int wpa_config_process_country(const struct global_parse_data *data,
3630 struct wpa_config *config, int line,
3633 if (!pos[0] || !pos[1]) {
3634 wpa_printf(MSG_DEBUG, "Invalid country set");
3637 config->country[0] = pos[0];
3638 config->country[1] = pos[1];
3639 wpa_printf(MSG_DEBUG, "country='%c%c'",
3640 config->country[0], config->country[1]);
3645 static int wpa_config_process_load_dynamic_eap(
3646 const struct global_parse_data *data, struct wpa_config *config,
3647 int line, const char *so)
3650 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3651 ret = eap_peer_method_load(so);
3653 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3656 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3657 "method '%s'.", line, so);
3667 static int wpa_config_process_uuid(const struct global_parse_data *data,
3668 struct wpa_config *config, int line,
3672 if (uuid_str2bin(pos, config->uuid)) {
3673 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3676 uuid_bin2str(config->uuid, buf, sizeof(buf));
3677 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3682 static int wpa_config_process_device_type(
3683 const struct global_parse_data *data,
3684 struct wpa_config *config, int line, const char *pos)
3686 return wps_dev_type_str2bin(pos, config->device_type);
3690 static int wpa_config_process_os_version(const struct global_parse_data *data,
3691 struct wpa_config *config, int line,
3694 if (hexstr2bin(pos, config->os_version, 4)) {
3695 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3698 wpa_printf(MSG_DEBUG, "os_version=%08x",
3699 WPA_GET_BE32(config->os_version));
3704 static int wpa_config_process_wps_vendor_ext_m1(
3705 const struct global_parse_data *data,
3706 struct wpa_config *config, int line, const char *pos)
3709 int len = os_strlen(pos) / 2;
3713 wpa_printf(MSG_ERROR, "Line %d: "
3714 "invalid wps_vendor_ext_m1", line);
3718 tmp = wpabuf_alloc(len);
3720 p = wpabuf_put(tmp, len);
3722 if (hexstr2bin(pos, p, len)) {
3723 wpa_printf(MSG_ERROR, "Line %d: "
3724 "invalid wps_vendor_ext_m1", line);
3729 wpabuf_free(config->wps_vendor_ext_m1);
3730 config->wps_vendor_ext_m1 = tmp;
3732 wpa_printf(MSG_ERROR, "Can not allocate "
3733 "memory for wps_vendor_ext_m1");
3740 #endif /* CONFIG_WPS */
3743 static int wpa_config_process_sec_device_type(
3744 const struct global_parse_data *data,
3745 struct wpa_config *config, int line, const char *pos)
3749 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3750 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3755 idx = config->num_sec_device_types;
3757 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
3760 config->num_sec_device_types++;
3765 static int wpa_config_process_p2p_pref_chan(
3766 const struct global_parse_data *data,
3767 struct wpa_config *config, int line, const char *pos)
3769 struct p2p_channel *pref = NULL, *n;
3770 unsigned int num = 0;
3774 /* format: class:chan,class:chan,... */
3777 op_class = atoi(pos);
3778 pos2 = os_strchr(pos, ':');
3784 n = os_realloc_array(pref, num + 1,
3785 sizeof(struct p2p_channel));
3789 pref[num].op_class = op_class;
3790 pref[num].chan = chan;
3793 pos = os_strchr(pos2, ',');
3799 os_free(config->p2p_pref_chan);
3800 config->p2p_pref_chan = pref;
3801 config->num_p2p_pref_chan = num;
3802 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
3803 (u8 *) config->p2p_pref_chan,
3804 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
3810 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
3815 static int wpa_config_process_p2p_no_go_freq(
3816 const struct global_parse_data *data,
3817 struct wpa_config *config, int line, const char *pos)
3821 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
3823 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
3827 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
3828 config->p2p_no_go_freq.num);
3833 #endif /* CONFIG_P2P */
3836 static int wpa_config_process_hessid(
3837 const struct global_parse_data *data,
3838 struct wpa_config *config, int line, const char *pos)
3840 if (hwaddr_aton2(pos, config->hessid) < 0) {
3841 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
3850 static int wpa_config_process_sae_groups(
3851 const struct global_parse_data *data,
3852 struct wpa_config *config, int line, const char *pos)
3854 int *groups = wpa_config_parse_int_array(pos);
3855 if (groups == NULL) {
3856 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
3861 os_free(config->sae_groups);
3862 config->sae_groups = groups;
3868 static int wpa_config_process_ap_vendor_elements(
3869 const struct global_parse_data *data,
3870 struct wpa_config *config, int line, const char *pos)
3873 int len = os_strlen(pos) / 2;
3877 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
3882 tmp = wpabuf_alloc(len);
3884 p = wpabuf_put(tmp, len);
3886 if (hexstr2bin(pos, p, len)) {
3887 wpa_printf(MSG_ERROR, "Line %d: invalid "
3888 "ap_vendor_elements", line);
3893 wpabuf_free(config->ap_vendor_elements);
3894 config->ap_vendor_elements = tmp;
3896 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
3897 "ap_vendor_elements");
3905 #ifdef CONFIG_CTRL_IFACE
3906 static int wpa_config_process_no_ctrl_interface(
3907 const struct global_parse_data *data,
3908 struct wpa_config *config, int line, const char *pos)
3910 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
3911 os_free(config->ctrl_interface);
3912 config->ctrl_interface = NULL;
3915 #endif /* CONFIG_CTRL_IFACE */
3921 /* OFFSET: Get offset of a variable within the wpa_config structure */
3922 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
3924 #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
3925 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
3926 #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
3927 #define INT(f) _INT(f), NULL, NULL
3928 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
3929 #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
3930 #define STR(f) _STR(f), NULL, NULL
3931 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
3932 #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
3933 #define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
3935 static const struct global_parse_data global_fields[] = {
3936 #ifdef CONFIG_CTRL_IFACE
3937 { STR(ctrl_interface), 0 },
3938 { FUNC_NO_VAR(no_ctrl_interface), 0 },
3939 { STR(ctrl_interface_group), 0 } /* deprecated */,
3940 #endif /* CONFIG_CTRL_IFACE */
3941 #ifdef CONFIG_MACSEC
3942 { INT_RANGE(eapol_version, 1, 3), 0 },
3943 #else /* CONFIG_MACSEC */
3944 { INT_RANGE(eapol_version, 1, 2), 0 },
3945 #endif /* CONFIG_MACSEC */
3946 { INT(ap_scan), 0 },
3947 { FUNC(bgscan), 0 },
3949 { INT(user_mpm), 0 },
3950 { INT_RANGE(max_peer_links, 0, 255), 0 },
3951 #endif /* CONFIG_MESH */
3952 { INT(disable_scan_offload), 0 },
3953 { INT(fast_reauth), 0 },
3954 { STR(opensc_engine_path), 0 },
3955 { STR(pkcs11_engine_path), 0 },
3956 { STR(pkcs11_module_path), 0 },
3957 { STR(openssl_ciphers), 0 },
3958 { STR(pcsc_reader), 0 },
3959 { STR(pcsc_pin), 0 },
3960 { INT(external_sim), 0 },
3961 { STR(driver_param), 0 },
3962 { INT(dot11RSNAConfigPMKLifetime), 0 },
3963 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
3964 { INT(dot11RSNAConfigSATimeout), 0 },
3965 #ifndef CONFIG_NO_CONFIG_WRITE
3966 { INT(update_config), 0 },
3967 #endif /* CONFIG_NO_CONFIG_WRITE */
3968 { FUNC_NO_VAR(load_dynamic_eap), 0 },
3970 { FUNC(uuid), CFG_CHANGED_UUID },
3971 { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
3972 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
3973 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
3974 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
3975 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
3976 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
3977 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
3978 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
3979 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
3980 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
3981 #endif /* CONFIG_WPS */
3983 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
3984 { INT(p2p_listen_reg_class), 0 },
3985 { INT(p2p_listen_channel), 0 },
3986 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
3987 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
3988 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
3989 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
3990 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
3991 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
3992 { INT(p2p_group_idle), 0 },
3993 { INT_RANGE(p2p_passphrase_len, 8, 63),
3994 CFG_CHANGED_P2P_PASSPHRASE_LEN },
3995 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
3996 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
3997 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
3998 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
3999 { INT(p2p_go_ht40), 0 },
4000 { INT(p2p_go_vht), 0 },
4001 { INT(p2p_disabled), 0 },
4002 { INT(p2p_no_group_iface), 0 },
4003 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
4004 { IPV4(ip_addr_go), 0 },
4005 { IPV4(ip_addr_mask), 0 },
4006 { IPV4(ip_addr_start), 0 },
4007 { IPV4(ip_addr_end), 0 },
4008 #endif /* CONFIG_P2P */
4009 { FUNC(country), CFG_CHANGED_COUNTRY },
4010 { INT(bss_max_count), 0 },
4011 { INT(bss_expiration_age), 0 },
4012 { INT(bss_expiration_scan_count), 0 },
4013 { INT_RANGE(filter_ssids, 0, 1), 0 },
4014 { INT_RANGE(filter_rssi, -100, 0), 0 },
4015 { INT(max_num_sta), 0 },
4016 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
4018 { INT_RANGE(hs20, 0, 1), 0 },
4019 #endif /* CONFIG_HS20 */
4020 { INT_RANGE(interworking, 0, 1), 0 },
4021 { FUNC(hessid), 0 },
4022 { INT_RANGE(access_network_type, 0, 15), 0 },
4023 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
4024 { STR(autoscan), 0 },
4025 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
4026 CFG_CHANGED_NFC_PASSWORD_TOKEN },
4027 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4028 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4029 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4030 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
4031 { INT(p2p_go_max_inactivity), 0 },
4032 { INT_RANGE(auto_interworking, 0, 1), 0 },
4035 { FUNC(sae_groups), 0 },
4036 { INT(dtim_period), 0 },
4037 { INT(beacon_int), 0 },
4038 { FUNC(ap_vendor_elements), 0 },
4039 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
4040 { FUNC(freq_list), 0 },
4041 { INT(scan_cur_freq), 0 },
4042 { INT(sched_scan_interval), 0 },
4043 { INT(tdls_external_control), 0},
4044 { STR(osu_dir), 0 },
4045 { STR(wowlan_triggers), 0 },
4046 { INT(p2p_search_delay), 0},
4047 { INT(mac_addr), 0 },
4048 { INT(rand_addr_lifetime), 0 },
4049 { INT(preassoc_mac_addr), 0 },
4050 { INT(key_mgmt_offload), 0},
4062 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4065 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
4070 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
4071 const struct global_parse_data *field = &global_fields[i];
4072 size_t flen = os_strlen(field->name);
4073 if (os_strncmp(pos, field->name, flen) != 0 ||
4077 if (field->parser(field, config, line, pos + flen + 1)) {
4078 wpa_printf(MSG_ERROR, "Line %d: failed to "
4079 "parse '%s'.", line, pos);
4082 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
4083 config->wps_nfc_pw_from_config = 1;
4084 config->changed_parameters |= field->changed_flag;
4087 if (i == NUM_GLOBAL_FIELDS) {
4089 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
4090 char *tmp = os_strchr(pos, '=');
4094 wpa_printf(MSG_ERROR, "Line %d: invalid line "
4099 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
4101 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
4106 #endif /* CONFIG_AP */
4109 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",