2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2015, 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"
22 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
23 #define NO_CONFIG_WRITE
27 * Structure for network configuration parsing. This data is used to implement
28 * a generic parser for each network block variable. The table of configuration
29 * variables is defined below in this file (ssid_fields[]).
32 /* Configuration variable name */
35 /* Parser function for this variable. The parser functions return 0 or 1
36 * to indicate success. Value 0 indicates that the parameter value may
37 * have changed while value 1 means that the value did not change.
38 * Error cases (failure to parse the string) are indicated by returning
40 int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
41 int line, const char *value);
43 #ifndef NO_CONFIG_WRITE
44 /* Writer function (i.e., to get the variable in text format from
45 * internal presentation). */
46 char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
47 #endif /* NO_CONFIG_WRITE */
49 /* Variable specific parameters for the parser. */
50 void *param1, *param2, *param3, *param4;
52 /* 0 = this variable can be included in debug output and ctrl_iface
53 * 1 = this variable contains key/private data and it must not be
54 * included in debug output unless explicitly requested. In
55 * addition, this variable will not be readable through the
62 static int wpa_config_parse_str(const struct parse_data *data,
63 struct wpa_ssid *ssid,
64 int line, const char *value)
66 size_t res_len, *dst_len, prev_len;
69 if (os_strcmp(value, "NULL") == 0) {
70 wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
77 tmp = wpa_config_parse_string(value, &res_len);
79 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
81 data->key_data ? "[KEY DATA REMOVED]" : value);
86 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
89 wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
93 if (data->param3 && res_len < (size_t) data->param3) {
94 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
95 "min_len=%ld)", line, data->name,
96 (unsigned long) res_len, (long) data->param3);
101 if (data->param4 && res_len > (size_t) data->param4) {
102 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
103 "max_len=%ld)", line, data->name,
104 (unsigned long) res_len, (long) data->param4);
110 dst = (char **) (((u8 *) ssid) + (long) data->param1);
111 dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
116 prev_len = os_strlen(*dst);
119 if ((*dst == NULL && tmp == NULL) ||
120 (*dst && tmp && prev_len == res_len &&
121 os_memcmp(*dst, tmp, res_len) == 0)) {
122 /* No change to the previously configured value */
136 #ifndef NO_CONFIG_WRITE
137 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
141 buf = os_malloc(len + 3);
145 os_memcpy(buf + 1, value, len);
153 static char * wpa_config_write_string_hex(const u8 *value, size_t len)
157 buf = os_zalloc(2 * len + 1);
160 wpa_snprintf_hex(buf, 2 * len + 1, value, len);
166 static char * wpa_config_write_string(const u8 *value, size_t len)
171 if (is_hex(value, len))
172 return wpa_config_write_string_hex(value, len);
174 return wpa_config_write_string_ascii(value, len);
178 static char * wpa_config_write_str(const struct parse_data *data,
179 struct wpa_ssid *ssid)
184 src = (char **) (((u8 *) ssid) + (long) data->param1);
189 len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
191 len = os_strlen(*src);
193 return wpa_config_write_string((const u8 *) *src, len);
195 #endif /* NO_CONFIG_WRITE */
198 static int wpa_config_parse_int(const struct parse_data *data,
199 struct wpa_ssid *ssid,
200 int line, const char *value)
205 dst = (int *) (((u8 *) ssid) + (long) data->param1);
206 val = strtol(value, &end, 0);
208 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
216 wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
218 if (data->param3 && *dst < (long) data->param3) {
219 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
220 "min_value=%ld)", line, data->name, *dst,
221 (long) data->param3);
222 *dst = (long) data->param3;
226 if (data->param4 && *dst > (long) data->param4) {
227 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
228 "max_value=%ld)", line, data->name, *dst,
229 (long) data->param4);
230 *dst = (long) data->param4;
238 #ifndef NO_CONFIG_WRITE
239 static char * wpa_config_write_int(const struct parse_data *data,
240 struct wpa_ssid *ssid)
245 src = (int *) (((u8 *) ssid) + (long) data->param1);
247 value = os_malloc(20);
250 res = os_snprintf(value, 20, "%d", *src);
251 if (os_snprintf_error(20, res)) {
255 value[20 - 1] = '\0';
258 #endif /* NO_CONFIG_WRITE */
261 static int wpa_config_parse_addr_list(const struct parse_data *data,
262 int line, const char *value,
263 u8 **list, size_t *num, char *name,
264 u8 abort_on_error, u8 masked)
267 u8 *buf, *n, addr[2 * ETH_ALEN];
274 while (pos && *pos) {
278 if (hwaddr_masked_aton(pos, addr, &addr[ETH_ALEN], masked)) {
279 if (abort_on_error || count == 0) {
280 wpa_printf(MSG_ERROR,
281 "Line %d: Invalid %s address '%s'",
286 /* continue anyway since this could have been from a
287 * truncated configuration file line */
289 "Line %d: Ignore likely truncated %s address '%s'",
292 n = os_realloc_array(buf, count + 1, 2 * ETH_ALEN);
298 os_memmove(buf + 2 * ETH_ALEN, buf,
299 count * 2 * ETH_ALEN);
300 os_memcpy(buf, addr, 2 * ETH_ALEN);
302 wpa_printf(MSG_MSGDUMP,
303 "%s: addr=" MACSTR " mask=" MACSTR,
305 MAC2STR(&addr[ETH_ALEN]));
308 pos = os_strchr(pos, ' ');
319 #ifndef NO_CONFIG_WRITE
320 static char * wpa_config_write_addr_list(const struct parse_data *data,
321 const u8 *list, size_t num, char *name)
323 char *value, *end, *pos;
327 if (list == NULL || num == 0)
330 value = os_malloc(2 * 20 * num);
334 end = value + 2 * 20 * num;
336 for (i = num; i > 0; i--) {
337 const u8 *a = list + (i - 1) * 2 * ETH_ALEN;
338 const u8 *m = a + ETH_ALEN;
342 res = hwaddr_mask_txt(pos, end - pos, a, m);
352 #endif /* NO_CONFIG_WRITE */
354 static int wpa_config_parse_bssid(const struct parse_data *data,
355 struct wpa_ssid *ssid, int line,
358 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
359 os_strcmp(value, "any") == 0) {
361 wpa_printf(MSG_MSGDUMP, "BSSID any");
364 if (hwaddr_aton(value, ssid->bssid)) {
365 wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
370 wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
375 #ifndef NO_CONFIG_WRITE
376 static char * wpa_config_write_bssid(const struct parse_data *data,
377 struct wpa_ssid *ssid)
382 if (!ssid->bssid_set)
385 value = os_malloc(20);
388 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
389 if (os_snprintf_error(20, res)) {
393 value[20 - 1] = '\0';
396 #endif /* NO_CONFIG_WRITE */
399 static int wpa_config_parse_bssid_blacklist(const struct parse_data *data,
400 struct wpa_ssid *ssid, int line,
403 return wpa_config_parse_addr_list(data, line, value,
404 &ssid->bssid_blacklist,
405 &ssid->num_bssid_blacklist,
406 "bssid_blacklist", 1, 1);
410 #ifndef NO_CONFIG_WRITE
411 static char * wpa_config_write_bssid_blacklist(const struct parse_data *data,
412 struct wpa_ssid *ssid)
414 return wpa_config_write_addr_list(data, ssid->bssid_blacklist,
415 ssid->num_bssid_blacklist,
418 #endif /* NO_CONFIG_WRITE */
421 static int wpa_config_parse_bssid_whitelist(const struct parse_data *data,
422 struct wpa_ssid *ssid, int line,
425 return wpa_config_parse_addr_list(data, line, value,
426 &ssid->bssid_whitelist,
427 &ssid->num_bssid_whitelist,
428 "bssid_whitelist", 1, 1);
432 #ifndef NO_CONFIG_WRITE
433 static char * wpa_config_write_bssid_whitelist(const struct parse_data *data,
434 struct wpa_ssid *ssid)
436 return wpa_config_write_addr_list(data, ssid->bssid_whitelist,
437 ssid->num_bssid_whitelist,
440 #endif /* NO_CONFIG_WRITE */
443 static int wpa_config_parse_psk(const struct parse_data *data,
444 struct wpa_ssid *ssid, int line,
447 #ifdef CONFIG_EXT_PASSWORD
448 if (os_strncmp(value, "ext:", 4) == 0) {
449 str_clear_free(ssid->passphrase);
450 ssid->passphrase = NULL;
452 os_free(ssid->ext_psk);
453 ssid->ext_psk = os_strdup(value + 4);
454 if (ssid->ext_psk == NULL)
456 wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
460 #endif /* CONFIG_EXT_PASSWORD */
463 #ifndef CONFIG_NO_PBKDF2
468 pos = os_strrchr(value, '"');
472 len = os_strlen(value);
473 if (len < 8 || len > 63) {
474 wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
475 "length %lu (expected: 8..63) '%s'.",
476 line, (unsigned long) len, value);
479 wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
481 if (has_ctrl_char((u8 *) value, len)) {
482 wpa_printf(MSG_ERROR,
483 "Line %d: Invalid passphrase character",
487 if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
488 os_memcmp(ssid->passphrase, value, len) == 0) {
489 /* No change to the previously configured value */
493 str_clear_free(ssid->passphrase);
494 ssid->passphrase = dup_binstr(value, len);
495 if (ssid->passphrase == NULL)
498 #else /* CONFIG_NO_PBKDF2 */
499 wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
502 #endif /* CONFIG_NO_PBKDF2 */
505 if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
506 value[PMK_LEN * 2] != '\0') {
507 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
512 str_clear_free(ssid->passphrase);
513 ssid->passphrase = NULL;
516 wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
521 #ifndef NO_CONFIG_WRITE
522 static char * wpa_config_write_psk(const struct parse_data *data,
523 struct wpa_ssid *ssid)
525 #ifdef CONFIG_EXT_PASSWORD
527 size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
528 char *buf = os_malloc(len);
533 res = os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
534 if (os_snprintf_error(len, res)) {
540 #endif /* CONFIG_EXT_PASSWORD */
542 if (ssid->passphrase)
543 return wpa_config_write_string_ascii(
544 (const u8 *) ssid->passphrase,
545 os_strlen(ssid->passphrase));
548 return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
552 #endif /* NO_CONFIG_WRITE */
555 static int wpa_config_parse_proto(const struct parse_data *data,
556 struct wpa_ssid *ssid, int line,
559 int val = 0, last, errors = 0;
560 char *start, *end, *buf;
562 buf = os_strdup(value);
567 while (*start != '\0') {
568 while (*start == ' ' || *start == '\t')
573 while (*end != ' ' && *end != '\t' && *end != '\0')
577 if (os_strcmp(start, "WPA") == 0)
578 val |= WPA_PROTO_WPA;
579 else if (os_strcmp(start, "RSN") == 0 ||
580 os_strcmp(start, "WPA2") == 0)
581 val |= WPA_PROTO_RSN;
582 else if (os_strcmp(start, "OSEN") == 0)
583 val |= WPA_PROTO_OSEN;
585 wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
597 wpa_printf(MSG_ERROR,
598 "Line %d: no proto values configured.", line);
602 if (!errors && ssid->proto == val)
604 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
606 return errors ? -1 : 0;
610 #ifndef NO_CONFIG_WRITE
611 static char * wpa_config_write_proto(const struct parse_data *data,
612 struct wpa_ssid *ssid)
615 char *buf, *pos, *end;
617 pos = buf = os_zalloc(20);
622 if (ssid->proto & WPA_PROTO_WPA) {
623 ret = os_snprintf(pos, end - pos, "%sWPA",
624 pos == buf ? "" : " ");
625 if (os_snprintf_error(end - pos, ret))
630 if (ssid->proto & WPA_PROTO_RSN) {
631 ret = os_snprintf(pos, end - pos, "%sRSN",
632 pos == buf ? "" : " ");
633 if (os_snprintf_error(end - pos, ret))
638 if (ssid->proto & WPA_PROTO_OSEN) {
639 ret = os_snprintf(pos, end - pos, "%sOSEN",
640 pos == buf ? "" : " ");
641 if (os_snprintf_error(end - pos, ret))
653 #endif /* NO_CONFIG_WRITE */
656 static int wpa_config_parse_key_mgmt(const struct parse_data *data,
657 struct wpa_ssid *ssid, int line,
660 int val = 0, last, errors = 0;
661 char *start, *end, *buf;
663 buf = os_strdup(value);
668 while (*start != '\0') {
669 while (*start == ' ' || *start == '\t')
674 while (*end != ' ' && *end != '\t' && *end != '\0')
678 if (os_strcmp(start, "WPA-PSK") == 0)
679 val |= WPA_KEY_MGMT_PSK;
680 else if (os_strcmp(start, "WPA-EAP") == 0)
681 val |= WPA_KEY_MGMT_IEEE8021X;
682 else if (os_strcmp(start, "IEEE8021X") == 0)
683 val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
684 else if (os_strcmp(start, "NONE") == 0)
685 val |= WPA_KEY_MGMT_NONE;
686 else if (os_strcmp(start, "WPA-NONE") == 0)
687 val |= WPA_KEY_MGMT_WPA_NONE;
688 #ifdef CONFIG_IEEE80211R
689 else if (os_strcmp(start, "FT-PSK") == 0)
690 val |= WPA_KEY_MGMT_FT_PSK;
691 else if (os_strcmp(start, "FT-EAP") == 0)
692 val |= WPA_KEY_MGMT_FT_IEEE8021X;
693 #endif /* CONFIG_IEEE80211R */
694 #ifdef CONFIG_IEEE80211W
695 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
696 val |= WPA_KEY_MGMT_PSK_SHA256;
697 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
698 val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
699 #endif /* CONFIG_IEEE80211W */
701 else if (os_strcmp(start, "WPS") == 0)
702 val |= WPA_KEY_MGMT_WPS;
703 #endif /* CONFIG_WPS */
705 else if (os_strcmp(start, "SAE") == 0)
706 val |= WPA_KEY_MGMT_SAE;
707 else if (os_strcmp(start, "FT-SAE") == 0)
708 val |= WPA_KEY_MGMT_FT_SAE;
709 #endif /* CONFIG_SAE */
711 else if (os_strcmp(start, "OSEN") == 0)
712 val |= WPA_KEY_MGMT_OSEN;
713 #endif /* CONFIG_HS20 */
715 else if (os_strcmp(start, "WPA-EAP-SUITE-B") == 0)
716 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B;
717 #endif /* CONFIG_SUITEB */
718 #ifdef CONFIG_SUITEB192
719 else if (os_strcmp(start, "WPA-EAP-SUITE-B-192") == 0)
720 val |= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
721 #endif /* CONFIG_SUITEB192 */
723 wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
735 wpa_printf(MSG_ERROR,
736 "Line %d: no key_mgmt values configured.", line);
740 if (!errors && ssid->key_mgmt == val)
742 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
743 ssid->key_mgmt = val;
744 return errors ? -1 : 0;
748 #ifndef NO_CONFIG_WRITE
749 static char * wpa_config_write_key_mgmt(const struct parse_data *data,
750 struct wpa_ssid *ssid)
752 char *buf, *pos, *end;
755 pos = buf = os_zalloc(100);
760 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
761 ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
762 pos == buf ? "" : " ");
763 if (os_snprintf_error(end - pos, ret)) {
770 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
771 ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
772 pos == buf ? "" : " ");
773 if (os_snprintf_error(end - pos, ret)) {
780 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
781 ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
782 pos == buf ? "" : " ");
783 if (os_snprintf_error(end - pos, ret)) {
790 if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
791 ret = os_snprintf(pos, end - pos, "%sNONE",
792 pos == buf ? "" : " ");
793 if (os_snprintf_error(end - pos, ret)) {
800 if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
801 ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
802 pos == buf ? "" : " ");
803 if (os_snprintf_error(end - pos, ret)) {
810 #ifdef CONFIG_IEEE80211R
811 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
812 ret = os_snprintf(pos, end - pos, "%sFT-PSK",
813 pos == buf ? "" : " ");
814 if (os_snprintf_error(end - pos, ret)) {
821 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
822 ret = os_snprintf(pos, end - pos, "%sFT-EAP",
823 pos == buf ? "" : " ");
824 if (os_snprintf_error(end - pos, ret)) {
830 #endif /* CONFIG_IEEE80211R */
832 #ifdef CONFIG_IEEE80211W
833 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
834 ret = os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
835 pos == buf ? "" : " ");
836 if (os_snprintf_error(end - pos, ret)) {
843 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
844 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
845 pos == buf ? "" : " ");
846 if (os_snprintf_error(end - pos, ret)) {
852 #endif /* CONFIG_IEEE80211W */
855 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
856 ret = os_snprintf(pos, end - pos, "%sWPS",
857 pos == buf ? "" : " ");
858 if (os_snprintf_error(end - pos, ret)) {
864 #endif /* CONFIG_WPS */
867 if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
868 ret = os_snprintf(pos, end - pos, "%sSAE",
869 pos == buf ? "" : " ");
870 if (os_snprintf_error(end - pos, ret)) {
877 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
878 ret = os_snprintf(pos, end - pos, "%sFT-SAE",
879 pos == buf ? "" : " ");
880 if (os_snprintf_error(end - pos, ret)) {
886 #endif /* CONFIG_SAE */
889 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) {
890 ret = os_snprintf(pos, end - pos, "%sOSEN",
891 pos == buf ? "" : " ");
892 if (os_snprintf_error(end - pos, ret)) {
898 #endif /* CONFIG_HS20 */
901 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
902 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B",
903 pos == buf ? "" : " ");
904 if (os_snprintf_error(end - pos, ret)) {
910 #endif /* CONFIG_SUITEB */
912 #ifdef CONFIG_SUITEB192
913 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
914 ret = os_snprintf(pos, end - pos, "%sWPA-EAP-SUITE-B-192",
915 pos == buf ? "" : " ");
916 if (os_snprintf_error(end - pos, ret)) {
922 #endif /* CONFIG_SUITEB192 */
931 #endif /* NO_CONFIG_WRITE */
934 static int wpa_config_parse_cipher(int line, const char *value)
938 #else /* CONFIG_NO_WPA */
939 int val = wpa_parse_cipher(value);
941 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
946 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
951 #endif /* CONFIG_NO_WPA */
955 #ifndef NO_CONFIG_WRITE
956 static char * wpa_config_write_cipher(int cipher)
960 #else /* CONFIG_NO_WPA */
961 char *buf = os_zalloc(50);
965 if (wpa_write_ciphers(buf, buf + 50, cipher, " ") < 0) {
971 #endif /* CONFIG_NO_WPA */
973 #endif /* NO_CONFIG_WRITE */
976 static int wpa_config_parse_pairwise(const struct parse_data *data,
977 struct wpa_ssid *ssid, int line,
981 val = wpa_config_parse_cipher(line, value);
984 if (val & ~WPA_ALLOWED_PAIRWISE_CIPHERS) {
985 wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
986 "(0x%x).", line, val);
990 if (ssid->pairwise_cipher == val)
992 wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
993 ssid->pairwise_cipher = val;
998 #ifndef NO_CONFIG_WRITE
999 static char * wpa_config_write_pairwise(const struct parse_data *data,
1000 struct wpa_ssid *ssid)
1002 return wpa_config_write_cipher(ssid->pairwise_cipher);
1004 #endif /* NO_CONFIG_WRITE */
1007 static int wpa_config_parse_group(const struct parse_data *data,
1008 struct wpa_ssid *ssid, int line,
1012 val = wpa_config_parse_cipher(line, value);
1017 * Backwards compatibility - filter out WEP ciphers that were previously
1020 val &= ~(WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40);
1022 if (val & ~WPA_ALLOWED_GROUP_CIPHERS) {
1023 wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
1024 "(0x%x).", line, val);
1028 if (ssid->group_cipher == val)
1030 wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
1031 ssid->group_cipher = val;
1036 #ifndef NO_CONFIG_WRITE
1037 static char * wpa_config_write_group(const struct parse_data *data,
1038 struct wpa_ssid *ssid)
1040 return wpa_config_write_cipher(ssid->group_cipher);
1042 #endif /* NO_CONFIG_WRITE */
1045 static int wpa_config_parse_auth_alg(const struct parse_data *data,
1046 struct wpa_ssid *ssid, int line,
1049 int val = 0, last, errors = 0;
1050 char *start, *end, *buf;
1052 buf = os_strdup(value);
1057 while (*start != '\0') {
1058 while (*start == ' ' || *start == '\t')
1063 while (*end != ' ' && *end != '\t' && *end != '\0')
1065 last = *end == '\0';
1067 if (os_strcmp(start, "OPEN") == 0)
1068 val |= WPA_AUTH_ALG_OPEN;
1069 else if (os_strcmp(start, "SHARED") == 0)
1070 val |= WPA_AUTH_ALG_SHARED;
1071 else if (os_strcmp(start, "LEAP") == 0)
1072 val |= WPA_AUTH_ALG_LEAP;
1074 wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
1086 wpa_printf(MSG_ERROR,
1087 "Line %d: no auth_alg values configured.", line);
1091 if (!errors && ssid->auth_alg == val)
1093 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
1094 ssid->auth_alg = val;
1095 return errors ? -1 : 0;
1099 #ifndef NO_CONFIG_WRITE
1100 static char * wpa_config_write_auth_alg(const struct parse_data *data,
1101 struct wpa_ssid *ssid)
1103 char *buf, *pos, *end;
1106 pos = buf = os_zalloc(30);
1111 if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
1112 ret = os_snprintf(pos, end - pos, "%sOPEN",
1113 pos == buf ? "" : " ");
1114 if (os_snprintf_error(end - pos, ret)) {
1121 if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
1122 ret = os_snprintf(pos, end - pos, "%sSHARED",
1123 pos == buf ? "" : " ");
1124 if (os_snprintf_error(end - pos, ret)) {
1131 if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
1132 ret = os_snprintf(pos, end - pos, "%sLEAP",
1133 pos == buf ? "" : " ");
1134 if (os_snprintf_error(end - pos, ret)) {
1148 #endif /* NO_CONFIG_WRITE */
1151 static int * wpa_config_parse_int_array(const char *value)
1159 freqs = os_calloc(len + 1, sizeof(int));
1170 n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
1175 for (i = len; i <= len * 2; i++)
1181 freqs[used] = atoi(pos);
1182 if (freqs[used] == 0)
1185 pos = os_strchr(pos + 1, ' ');
1192 static int wpa_config_parse_scan_freq(const struct parse_data *data,
1193 struct wpa_ssid *ssid, int line,
1198 freqs = wpa_config_parse_int_array(value);
1201 if (freqs[0] == 0) {
1205 os_free(ssid->scan_freq);
1206 ssid->scan_freq = freqs;
1212 static int wpa_config_parse_freq_list(const struct parse_data *data,
1213 struct wpa_ssid *ssid, int line,
1218 freqs = wpa_config_parse_int_array(value);
1221 if (freqs[0] == 0) {
1225 os_free(ssid->freq_list);
1226 ssid->freq_list = freqs;
1232 #ifndef NO_CONFIG_WRITE
1233 static char * wpa_config_write_freqs(const struct parse_data *data,
1236 char *buf, *pos, *end;
1244 for (i = 0; freqs[i]; i++)
1247 pos = buf = os_zalloc(10 * count + 1);
1250 end = buf + 10 * count + 1;
1252 for (i = 0; freqs[i]; i++) {
1253 ret = os_snprintf(pos, end - pos, "%s%u",
1254 i == 0 ? "" : " ", freqs[i]);
1255 if (os_snprintf_error(end - pos, ret)) {
1266 static char * wpa_config_write_scan_freq(const struct parse_data *data,
1267 struct wpa_ssid *ssid)
1269 return wpa_config_write_freqs(data, ssid->scan_freq);
1273 static char * wpa_config_write_freq_list(const struct parse_data *data,
1274 struct wpa_ssid *ssid)
1276 return wpa_config_write_freqs(data, ssid->freq_list);
1278 #endif /* NO_CONFIG_WRITE */
1281 #ifdef IEEE8021X_EAPOL
1282 static int wpa_config_parse_eap(const struct parse_data *data,
1283 struct wpa_ssid *ssid, int line,
1286 int last, errors = 0;
1287 char *start, *end, *buf;
1288 struct eap_method_type *methods = NULL, *tmp;
1289 size_t num_methods = 0;
1291 buf = os_strdup(value);
1296 while (*start != '\0') {
1297 while (*start == ' ' || *start == '\t')
1302 while (*end != ' ' && *end != '\t' && *end != '\0')
1304 last = *end == '\0';
1307 methods = os_realloc_array(methods, num_methods + 1,
1309 if (methods == NULL) {
1314 methods[num_methods].method = eap_peer_get_type(
1315 start, &methods[num_methods].vendor);
1316 if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1317 methods[num_methods].method == EAP_TYPE_NONE) {
1318 wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
1319 "'%s'", line, start);
1320 wpa_printf(MSG_ERROR, "You may need to add support for"
1321 " this EAP method during wpa_supplicant\n"
1322 "build time configuration.\n"
1323 "See README for more information.");
1325 } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
1326 methods[num_methods].method == EAP_TYPE_LEAP)
1338 methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
1339 if (methods == NULL) {
1343 methods[num_methods].vendor = EAP_VENDOR_IETF;
1344 methods[num_methods].method = EAP_TYPE_NONE;
1347 if (!errors && ssid->eap.eap_methods) {
1348 struct eap_method_type *prev_m;
1349 size_t i, j, prev_methods, match = 0;
1351 prev_m = ssid->eap.eap_methods;
1352 for (i = 0; prev_m[i].vendor != EAP_VENDOR_IETF ||
1353 prev_m[i].method != EAP_TYPE_NONE; i++) {
1354 /* Count the methods */
1356 prev_methods = i + 1;
1358 for (i = 0; prev_methods == num_methods && i < prev_methods;
1360 for (j = 0; j < num_methods; j++) {
1361 if (prev_m[i].vendor == methods[j].vendor &&
1362 prev_m[i].method == methods[j].method) {
1368 if (match == num_methods) {
1373 wpa_hexdump(MSG_MSGDUMP, "eap methods",
1374 (u8 *) methods, num_methods * sizeof(*methods));
1375 os_free(ssid->eap.eap_methods);
1376 ssid->eap.eap_methods = methods;
1377 return errors ? -1 : 0;
1381 #ifndef NO_CONFIG_WRITE
1382 static char * wpa_config_write_eap(const struct parse_data *data,
1383 struct wpa_ssid *ssid)
1386 char *buf, *pos, *end;
1387 const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
1390 if (eap_methods == NULL)
1393 pos = buf = os_zalloc(100);
1398 for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
1399 eap_methods[i].method != EAP_TYPE_NONE; i++) {
1400 name = eap_get_name(eap_methods[i].vendor,
1401 eap_methods[i].method);
1403 ret = os_snprintf(pos, end - pos, "%s%s",
1404 pos == buf ? "" : " ", name);
1405 if (os_snprintf_error(end - pos, ret))
1415 #endif /* NO_CONFIG_WRITE */
1418 static int wpa_config_parse_password(const struct parse_data *data,
1419 struct wpa_ssid *ssid, int line,
1424 if (os_strcmp(value, "NULL") == 0) {
1425 if (!ssid->eap.password)
1426 return 1; /* Already unset */
1427 wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
1428 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1429 ssid->eap.password = NULL;
1430 ssid->eap.password_len = 0;
1434 #ifdef CONFIG_EXT_PASSWORD
1435 if (os_strncmp(value, "ext:", 4) == 0) {
1436 char *name = os_strdup(value + 4);
1439 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1440 ssid->eap.password = (u8 *) name;
1441 ssid->eap.password_len = os_strlen(name);
1442 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1443 ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
1446 #endif /* CONFIG_EXT_PASSWORD */
1448 if (os_strncmp(value, "hash:", 5) != 0) {
1452 tmp = wpa_config_parse_string(value, &res_len);
1454 wpa_printf(MSG_ERROR, "Line %d: failed to parse "
1458 wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
1459 (u8 *) tmp, res_len);
1461 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1462 ssid->eap.password = (u8 *) tmp;
1463 ssid->eap.password_len = res_len;
1464 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1465 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1471 /* NtPasswordHash: hash:<32 hex digits> */
1472 if (os_strlen(value + 5) != 2 * 16) {
1473 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
1474 "(expected 32 hex digits)", line);
1478 hash = os_malloc(16);
1482 if (hexstr2bin(value + 5, hash, 16)) {
1484 wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
1488 wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
1490 if (ssid->eap.password && ssid->eap.password_len == 16 &&
1491 os_memcmp(ssid->eap.password, hash, 16) == 0 &&
1492 (ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1493 bin_clear_free(hash, 16);
1496 bin_clear_free(ssid->eap.password, ssid->eap.password_len);
1497 ssid->eap.password = hash;
1498 ssid->eap.password_len = 16;
1499 ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1500 ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1506 #ifndef NO_CONFIG_WRITE
1507 static char * wpa_config_write_password(const struct parse_data *data,
1508 struct wpa_ssid *ssid)
1512 if (ssid->eap.password == NULL)
1515 #ifdef CONFIG_EXT_PASSWORD
1516 if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
1517 buf = os_zalloc(4 + ssid->eap.password_len + 1);
1520 os_memcpy(buf, "ext:", 4);
1521 os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
1524 #endif /* CONFIG_EXT_PASSWORD */
1526 if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
1527 return wpa_config_write_string(
1528 ssid->eap.password, ssid->eap.password_len);
1531 buf = os_malloc(5 + 32 + 1);
1535 os_memcpy(buf, "hash:", 5);
1536 wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
1540 #endif /* NO_CONFIG_WRITE */
1541 #endif /* IEEE8021X_EAPOL */
1544 static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
1545 const char *value, int idx)
1547 char *buf, title[20];
1550 buf = wpa_config_parse_string(value, len);
1552 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
1556 if (*len > MAX_WEP_KEY_LEN) {
1557 wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
1562 if (*len && *len != 5 && *len != 13 && *len != 16) {
1563 wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
1564 "this network block will be ignored",
1565 line, (unsigned int) *len);
1567 os_memcpy(key, buf, *len);
1568 str_clear_free(buf);
1569 res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
1570 if (!os_snprintf_error(sizeof(title), res))
1571 wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
1576 static int wpa_config_parse_wep_key0(const struct parse_data *data,
1577 struct wpa_ssid *ssid, int line,
1580 return wpa_config_parse_wep_key(ssid->wep_key[0],
1581 &ssid->wep_key_len[0], line,
1586 static int wpa_config_parse_wep_key1(const struct parse_data *data,
1587 struct wpa_ssid *ssid, int line,
1590 return wpa_config_parse_wep_key(ssid->wep_key[1],
1591 &ssid->wep_key_len[1], line,
1596 static int wpa_config_parse_wep_key2(const struct parse_data *data,
1597 struct wpa_ssid *ssid, int line,
1600 return wpa_config_parse_wep_key(ssid->wep_key[2],
1601 &ssid->wep_key_len[2], line,
1606 static int wpa_config_parse_wep_key3(const struct parse_data *data,
1607 struct wpa_ssid *ssid, int line,
1610 return wpa_config_parse_wep_key(ssid->wep_key[3],
1611 &ssid->wep_key_len[3], line,
1616 #ifndef NO_CONFIG_WRITE
1617 static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
1619 if (ssid->wep_key_len[idx] == 0)
1621 return wpa_config_write_string(ssid->wep_key[idx],
1622 ssid->wep_key_len[idx]);
1626 static char * wpa_config_write_wep_key0(const struct parse_data *data,
1627 struct wpa_ssid *ssid)
1629 return wpa_config_write_wep_key(ssid, 0);
1633 static char * wpa_config_write_wep_key1(const struct parse_data *data,
1634 struct wpa_ssid *ssid)
1636 return wpa_config_write_wep_key(ssid, 1);
1640 static char * wpa_config_write_wep_key2(const struct parse_data *data,
1641 struct wpa_ssid *ssid)
1643 return wpa_config_write_wep_key(ssid, 2);
1647 static char * wpa_config_write_wep_key3(const struct parse_data *data,
1648 struct wpa_ssid *ssid)
1650 return wpa_config_write_wep_key(ssid, 3);
1652 #endif /* NO_CONFIG_WRITE */
1657 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data *data,
1658 struct wpa_ssid *ssid, int line,
1661 if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
1662 os_strcmp(value, "any") == 0) {
1663 os_memset(ssid->go_p2p_dev_addr, 0, ETH_ALEN);
1664 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address any");
1667 if (hwaddr_aton(value, ssid->go_p2p_dev_addr)) {
1668 wpa_printf(MSG_ERROR, "Line %d: Invalid GO P2P Device Address '%s'.",
1672 ssid->bssid_set = 1;
1673 wpa_printf(MSG_MSGDUMP, "GO P2P Device Address " MACSTR,
1674 MAC2STR(ssid->go_p2p_dev_addr));
1679 #ifndef NO_CONFIG_WRITE
1680 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data *data,
1681 struct wpa_ssid *ssid)
1686 if (is_zero_ether_addr(ssid->go_p2p_dev_addr))
1689 value = os_malloc(20);
1692 res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->go_p2p_dev_addr));
1693 if (os_snprintf_error(20, res)) {
1697 value[20 - 1] = '\0';
1700 #endif /* NO_CONFIG_WRITE */
1703 static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
1704 struct wpa_ssid *ssid, int line,
1707 return wpa_config_parse_addr_list(data, line, value,
1708 &ssid->p2p_client_list,
1709 &ssid->num_p2p_clients,
1710 "p2p_client_list", 0, 0);
1714 #ifndef NO_CONFIG_WRITE
1715 static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
1716 struct wpa_ssid *ssid)
1718 return wpa_config_write_addr_list(data, ssid->p2p_client_list,
1719 ssid->num_p2p_clients,
1722 #endif /* NO_CONFIG_WRITE */
1725 static int wpa_config_parse_psk_list(const struct parse_data *data,
1726 struct wpa_ssid *ssid, int line,
1729 struct psk_list_entry *p;
1732 p = os_zalloc(sizeof(*p));
1737 if (os_strncmp(pos, "P2P-", 4) == 0) {
1742 if (hwaddr_aton(pos, p->addr)) {
1743 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list address '%s'",
1750 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list '%s'",
1757 if (hexstr2bin(pos, p->psk, PMK_LEN) || pos[PMK_LEN * 2] != '\0') {
1758 wpa_printf(MSG_ERROR, "Line %d: Invalid psk_list PSK '%s'",
1764 dl_list_add(&ssid->psk_list, &p->list);
1770 #ifndef NO_CONFIG_WRITE
1771 static char * wpa_config_write_psk_list(const struct parse_data *data,
1772 struct wpa_ssid *ssid)
1776 #endif /* NO_CONFIG_WRITE */
1778 #endif /* CONFIG_P2P */
1783 static int wpa_config_parse_mesh_basic_rates(const struct parse_data *data,
1784 struct wpa_ssid *ssid, int line,
1787 int *rates = wpa_config_parse_int_array(value);
1789 if (rates == NULL) {
1790 wpa_printf(MSG_ERROR, "Line %d: Invalid mesh_basic_rates '%s'",
1794 if (rates[0] == 0) {
1799 os_free(ssid->mesh_basic_rates);
1800 ssid->mesh_basic_rates = rates;
1806 #ifndef NO_CONFIG_WRITE
1808 static char * wpa_config_write_mesh_basic_rates(const struct parse_data *data,
1809 struct wpa_ssid *ssid)
1811 return wpa_config_write_freqs(data, ssid->mesh_basic_rates);
1814 #endif /* NO_CONFIG_WRITE */
1816 #endif /* CONFIG_MESH */
1819 /* Helper macros for network block parser */
1824 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1825 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1827 /* STR: Define a string variable for an ASCII string; f = field name */
1828 #ifdef NO_CONFIG_WRITE
1829 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1830 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1831 #else /* NO_CONFIG_WRITE */
1832 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1833 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1834 #endif /* NO_CONFIG_WRITE */
1835 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1836 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1837 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1838 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1840 /* STR_LEN: Define a string variable with a separate variable for storing the
1841 * data length. Unlike STR(), this can be used to store arbitrary binary data
1842 * (i.e., even nul termination character). */
1843 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1844 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1845 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1846 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1847 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1849 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1850 * explicitly specified. */
1851 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1852 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1853 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1855 #ifdef NO_CONFIG_WRITE
1856 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1857 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1858 #else /* NO_CONFIG_WRITE */
1859 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1860 OFFSET(f), (void *) 0
1861 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1862 OFFSET(eap.f), (void *) 0
1863 #endif /* NO_CONFIG_WRITE */
1865 /* INT: Define an integer variable */
1866 #define INT(f) _INT(f), NULL, NULL, 0
1867 #define INTe(f) _INTe(f), NULL, NULL, 0
1869 /* INT_RANGE: Define an integer variable with allowed value range */
1870 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1872 /* FUNC: Define a configuration variable that uses a custom function for
1873 * parsing and writing the value. */
1874 #ifdef NO_CONFIG_WRITE
1875 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1876 #else /* NO_CONFIG_WRITE */
1877 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1878 NULL, NULL, NULL, NULL
1879 #endif /* NO_CONFIG_WRITE */
1880 #define FUNC(f) _FUNC(f), 0
1881 #define FUNC_KEY(f) _FUNC(f), 1
1884 * Table of network configuration variables. This table is used to parse each
1885 * network configuration variable, e.g., each line in wpa_supplicant.conf file
1886 * that is inside a network block.
1888 * This table is generated using the helper macros defined above and with
1889 * generous help from the C pre-processor. The field name is stored as a string
1890 * into .name and for STR and INT types, the offset of the target buffer within
1891 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
1892 * offset to the field containing the length of the configuration variable.
1893 * .param3 and .param4 can be used to mark the allowed range (length for STR
1894 * and value for INT).
1896 * For each configuration line in wpa_supplicant.conf, the parser goes through
1897 * this table and select the entry that matches with the field name. The parser
1898 * function (.parser) is then called to parse the actual value of the field.
1900 * This kind of mechanism makes it easy to add new configuration parameters,
1901 * since only one line needs to be added into this table and into the
1902 * struct wpa_ssid definition if the new variable is either a string or
1903 * integer. More complex types will need to use their own parser and writer
1906 static const struct parse_data ssid_fields[] = {
1907 { STR_RANGE(ssid, 0, SSID_MAX_LEN) },
1908 { INT_RANGE(scan_ssid, 0, 1) },
1910 { FUNC(bssid_blacklist) },
1911 { FUNC(bssid_whitelist) },
1913 { INT(mem_only_psk) },
1916 { INT(bg_scan_period) },
1920 { FUNC(scan_freq) },
1921 { FUNC(freq_list) },
1922 { INT_RANGE(max_oper_chwidth, VHT_CHANWIDTH_USE_HT,
1923 VHT_CHANWIDTH_80P80MHZ) },
1924 #ifdef IEEE8021X_EAPOL
1926 { STR_LENe(identity) },
1927 { STR_LENe(anonymous_identity) },
1928 { FUNC_KEY(password) },
1931 { STRe(client_cert) },
1932 { STRe(private_key) },
1933 { STR_KEYe(private_key_passwd) },
1935 { STRe(subject_match) },
1936 { STRe(altsubject_match) },
1937 { STRe(domain_suffix_match) },
1938 { STRe(domain_match) },
1941 { STRe(client_cert2) },
1942 { STRe(private_key2) },
1943 { STR_KEYe(private_key2_passwd) },
1945 { STRe(subject_match2) },
1946 { STRe(altsubject_match2) },
1947 { STRe(domain_suffix_match2) },
1948 { STRe(domain_match2) },
1953 { STRe(engine_id) },
1956 { STRe(ca_cert_id) },
1958 { STRe(engine2_id) },
1961 { STRe(ca_cert2_id) },
1964 { INT(eapol_flags) },
1966 { STRe(openssl_ciphers) },
1968 #endif /* IEEE8021X_EAPOL */
1969 { FUNC_KEY(wep_key0) },
1970 { FUNC_KEY(wep_key1) },
1971 { FUNC_KEY(wep_key2) },
1972 { FUNC_KEY(wep_key3) },
1973 { INT(wep_tx_keyidx) },
1975 #ifdef IEEE8021X_EAPOL
1976 { INT(eap_workaround) },
1978 { INTe(fragment_size) },
1980 #endif /* IEEE8021X_EAPOL */
1982 { INT_RANGE(mode, 0, 5) },
1983 { INT_RANGE(no_auto_peer, 0, 1) },
1984 #else /* CONFIG_MESH */
1985 { INT_RANGE(mode, 0, 4) },
1986 #endif /* CONFIG_MESH */
1987 { INT_RANGE(proactive_key_caching, 0, 1) },
1988 { INT_RANGE(disabled, 0, 2) },
1990 #ifdef CONFIG_IEEE80211W
1991 { INT_RANGE(ieee80211w, 0, 2) },
1992 #endif /* CONFIG_IEEE80211W */
1993 { INT_RANGE(peerkey, 0, 1) },
1994 { INT_RANGE(mixed_cell, 0, 1) },
1995 { INT_RANGE(frequency, 0, 65000) },
1996 { INT_RANGE(fixed_freq, 0, 1) },
1998 { INT_RANGE(acs, 0, 1) },
1999 #endif /* CONFIG_ACS */
2001 { FUNC(mesh_basic_rates) },
2002 { INT(dot11MeshMaxRetries) },
2003 { INT(dot11MeshRetryTimeout) },
2004 { INT(dot11MeshConfirmTimeout) },
2005 { INT(dot11MeshHoldingTimeout) },
2006 #endif /* CONFIG_MESH */
2007 { INT(wpa_ptk_rekey) },
2008 { INT(group_rekey) },
2010 { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
2012 { FUNC(go_p2p_dev_addr) },
2013 { FUNC(p2p_client_list) },
2015 #endif /* CONFIG_P2P */
2016 #ifdef CONFIG_HT_OVERRIDES
2017 { INT_RANGE(disable_ht, 0, 1) },
2018 { INT_RANGE(disable_ht40, -1, 1) },
2019 { INT_RANGE(disable_sgi, 0, 1) },
2020 { INT_RANGE(disable_ldpc, 0, 1) },
2021 { INT_RANGE(ht40_intolerant, 0, 1) },
2022 { INT_RANGE(disable_max_amsdu, -1, 1) },
2023 { INT_RANGE(ampdu_factor, -1, 3) },
2024 { INT_RANGE(ampdu_density, -1, 7) },
2026 #endif /* CONFIG_HT_OVERRIDES */
2027 #ifdef CONFIG_VHT_OVERRIDES
2028 { INT_RANGE(disable_vht, 0, 1) },
2030 { INT(vht_capa_mask) },
2031 { INT_RANGE(vht_rx_mcs_nss_1, -1, 3) },
2032 { INT_RANGE(vht_rx_mcs_nss_2, -1, 3) },
2033 { INT_RANGE(vht_rx_mcs_nss_3, -1, 3) },
2034 { INT_RANGE(vht_rx_mcs_nss_4, -1, 3) },
2035 { INT_RANGE(vht_rx_mcs_nss_5, -1, 3) },
2036 { INT_RANGE(vht_rx_mcs_nss_6, -1, 3) },
2037 { INT_RANGE(vht_rx_mcs_nss_7, -1, 3) },
2038 { INT_RANGE(vht_rx_mcs_nss_8, -1, 3) },
2039 { INT_RANGE(vht_tx_mcs_nss_1, -1, 3) },
2040 { INT_RANGE(vht_tx_mcs_nss_2, -1, 3) },
2041 { INT_RANGE(vht_tx_mcs_nss_3, -1, 3) },
2042 { INT_RANGE(vht_tx_mcs_nss_4, -1, 3) },
2043 { INT_RANGE(vht_tx_mcs_nss_5, -1, 3) },
2044 { INT_RANGE(vht_tx_mcs_nss_6, -1, 3) },
2045 { INT_RANGE(vht_tx_mcs_nss_7, -1, 3) },
2046 { INT_RANGE(vht_tx_mcs_nss_8, -1, 3) },
2047 #endif /* CONFIG_VHT_OVERRIDES */
2048 { INT(ap_max_inactivity) },
2049 { INT(dtim_period) },
2050 { INT(beacon_int) },
2051 #ifdef CONFIG_MACSEC
2052 { INT_RANGE(macsec_policy, 0, 1) },
2053 #endif /* CONFIG_MACSEC */
2055 { INT(update_identifier) },
2056 #endif /* CONFIG_HS20 */
2057 { INT_RANGE(mac_addr, 0, 2) },
2058 { INT_RANGE(pbss, 0, 2) },
2059 { INT_RANGE(wps_disabled, 0, 1) },
2071 #undef STR_RANGE_KEY
2078 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2082 * wpa_config_add_prio_network - Add a network to priority lists
2083 * @config: Configuration data from wpa_config_read()
2084 * @ssid: Pointer to the network configuration to be added to the list
2085 * Returns: 0 on success, -1 on failure
2087 * This function is used to add a network block to the priority list of
2088 * networks. This must be called for each network when reading in the full
2089 * configuration. In addition, this can be used indirectly when updating
2090 * priorities by calling wpa_config_update_prio_list().
2092 int wpa_config_add_prio_network(struct wpa_config *config,
2093 struct wpa_ssid *ssid)
2096 struct wpa_ssid *prev, **nlist;
2099 * Add to an existing priority list if one is available for the
2100 * configured priority level for this network.
2102 for (prio = 0; prio < config->num_prio; prio++) {
2103 prev = config->pssid[prio];
2104 if (prev->priority == ssid->priority) {
2112 /* First network for this priority - add a new priority list */
2113 nlist = os_realloc_array(config->pssid, config->num_prio + 1,
2114 sizeof(struct wpa_ssid *));
2118 for (prio = 0; prio < config->num_prio; prio++) {
2119 if (nlist[prio]->priority < ssid->priority) {
2120 os_memmove(&nlist[prio + 1], &nlist[prio],
2121 (config->num_prio - prio) *
2122 sizeof(struct wpa_ssid *));
2129 config->pssid = nlist;
2136 * wpa_config_update_prio_list - Update network priority list
2137 * @config: Configuration data from wpa_config_read()
2138 * Returns: 0 on success, -1 on failure
2140 * This function is called to update the priority list of networks in the
2141 * configuration when a network is being added or removed. This is also called
2142 * if a priority for a network is changed.
2144 int wpa_config_update_prio_list(struct wpa_config *config)
2146 struct wpa_ssid *ssid;
2149 os_free(config->pssid);
2150 config->pssid = NULL;
2151 config->num_prio = 0;
2153 ssid = config->ssid;
2156 if (wpa_config_add_prio_network(config, ssid) < 0)
2165 #ifdef IEEE8021X_EAPOL
2166 static void eap_peer_config_free(struct eap_peer_config *eap)
2168 os_free(eap->eap_methods);
2169 bin_clear_free(eap->identity, eap->identity_len);
2170 os_free(eap->anonymous_identity);
2171 bin_clear_free(eap->password, eap->password_len);
2172 os_free(eap->ca_cert);
2173 os_free(eap->ca_path);
2174 os_free(eap->client_cert);
2175 os_free(eap->private_key);
2176 str_clear_free(eap->private_key_passwd);
2177 os_free(eap->dh_file);
2178 os_free(eap->subject_match);
2179 os_free(eap->altsubject_match);
2180 os_free(eap->domain_suffix_match);
2181 os_free(eap->domain_match);
2182 os_free(eap->ca_cert2);
2183 os_free(eap->ca_path2);
2184 os_free(eap->client_cert2);
2185 os_free(eap->private_key2);
2186 str_clear_free(eap->private_key2_passwd);
2187 os_free(eap->dh_file2);
2188 os_free(eap->subject_match2);
2189 os_free(eap->altsubject_match2);
2190 os_free(eap->domain_suffix_match2);
2191 os_free(eap->domain_match2);
2192 os_free(eap->phase1);
2193 os_free(eap->phase2);
2195 str_clear_free(eap->pin);
2196 os_free(eap->engine_id);
2197 os_free(eap->key_id);
2198 os_free(eap->cert_id);
2199 os_free(eap->ca_cert_id);
2200 os_free(eap->key2_id);
2201 os_free(eap->cert2_id);
2202 os_free(eap->ca_cert2_id);
2203 str_clear_free(eap->pin2);
2204 os_free(eap->engine2_id);
2206 os_free(eap->pending_req_otp);
2207 os_free(eap->pac_file);
2208 bin_clear_free(eap->new_password, eap->new_password_len);
2209 str_clear_free(eap->external_sim_resp);
2210 os_free(eap->openssl_ciphers);
2212 #endif /* IEEE8021X_EAPOL */
2216 * wpa_config_free_ssid - Free network/ssid configuration data
2217 * @ssid: Configuration data for the network
2219 * This function frees all resources allocated for the network configuration
2222 void wpa_config_free_ssid(struct wpa_ssid *ssid)
2224 struct psk_list_entry *psk;
2226 os_free(ssid->ssid);
2227 str_clear_free(ssid->passphrase);
2228 os_free(ssid->ext_psk);
2229 #ifdef IEEE8021X_EAPOL
2230 eap_peer_config_free(&ssid->eap);
2231 #endif /* IEEE8021X_EAPOL */
2232 os_free(ssid->id_str);
2233 os_free(ssid->scan_freq);
2234 os_free(ssid->freq_list);
2235 os_free(ssid->bgscan);
2236 os_free(ssid->p2p_client_list);
2237 os_free(ssid->bssid_blacklist);
2238 os_free(ssid->bssid_whitelist);
2239 #ifdef CONFIG_HT_OVERRIDES
2240 os_free(ssid->ht_mcs);
2241 #endif /* CONFIG_HT_OVERRIDES */
2243 os_free(ssid->mesh_basic_rates);
2244 #endif /* CONFIG_MESH */
2245 while ((psk = dl_list_first(&ssid->psk_list, struct psk_list_entry,
2247 dl_list_del(&psk->list);
2248 bin_clear_free(psk, sizeof(*psk));
2250 bin_clear_free(ssid, sizeof(*ssid));
2254 void wpa_config_free_cred(struct wpa_cred *cred)
2258 os_free(cred->realm);
2259 str_clear_free(cred->username);
2260 str_clear_free(cred->password);
2261 os_free(cred->ca_cert);
2262 os_free(cred->client_cert);
2263 os_free(cred->private_key);
2264 str_clear_free(cred->private_key_passwd);
2265 os_free(cred->imsi);
2266 str_clear_free(cred->milenage);
2267 for (i = 0; i < cred->num_domain; i++)
2268 os_free(cred->domain[i]);
2269 os_free(cred->domain);
2270 os_free(cred->domain_suffix_match);
2271 os_free(cred->eap_method);
2272 os_free(cred->phase1);
2273 os_free(cred->phase2);
2274 os_free(cred->excluded_ssid);
2275 os_free(cred->roaming_partner);
2276 os_free(cred->provisioning_sp);
2277 for (i = 0; i < cred->num_req_conn_capab; i++)
2278 os_free(cred->req_conn_capab_port[i]);
2279 os_free(cred->req_conn_capab_port);
2280 os_free(cred->req_conn_capab_proto);
2285 void wpa_config_flush_blobs(struct wpa_config *config)
2287 #ifndef CONFIG_NO_CONFIG_BLOBS
2288 struct wpa_config_blob *blob, *prev;
2290 blob = config->blobs;
2291 config->blobs = NULL;
2295 wpa_config_free_blob(prev);
2297 #endif /* CONFIG_NO_CONFIG_BLOBS */
2302 * wpa_config_free - Free configuration data
2303 * @config: Configuration data from wpa_config_read()
2305 * This function frees all resources allocated for the configuration data by
2306 * wpa_config_read().
2308 void wpa_config_free(struct wpa_config *config)
2310 struct wpa_ssid *ssid, *prev = NULL;
2311 struct wpa_cred *cred, *cprev;
2314 ssid = config->ssid;
2318 wpa_config_free_ssid(prev);
2321 cred = config->cred;
2325 wpa_config_free_cred(cprev);
2328 wpa_config_flush_blobs(config);
2330 wpabuf_free(config->wps_vendor_ext_m1);
2331 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++)
2332 wpabuf_free(config->wps_vendor_ext[i]);
2333 os_free(config->ctrl_interface);
2334 os_free(config->ctrl_interface_group);
2335 os_free(config->opensc_engine_path);
2336 os_free(config->pkcs11_engine_path);
2337 os_free(config->pkcs11_module_path);
2338 os_free(config->openssl_ciphers);
2339 os_free(config->pcsc_reader);
2340 str_clear_free(config->pcsc_pin);
2341 os_free(config->driver_param);
2342 os_free(config->device_name);
2343 os_free(config->manufacturer);
2344 os_free(config->model_name);
2345 os_free(config->model_number);
2346 os_free(config->serial_number);
2347 os_free(config->config_methods);
2348 os_free(config->p2p_ssid_postfix);
2349 os_free(config->pssid);
2350 os_free(config->p2p_pref_chan);
2351 os_free(config->p2p_no_go_freq.range);
2352 os_free(config->autoscan);
2353 os_free(config->freq_list);
2354 wpabuf_free(config->wps_nfc_dh_pubkey);
2355 wpabuf_free(config->wps_nfc_dh_privkey);
2356 wpabuf_free(config->wps_nfc_dev_pw);
2357 os_free(config->ext_password_backend);
2358 os_free(config->sae_groups);
2359 wpabuf_free(config->ap_vendor_elements);
2360 os_free(config->osu_dir);
2361 os_free(config->bgscan);
2362 os_free(config->wowlan_triggers);
2363 os_free(config->fst_group_id);
2364 os_free(config->sched_scan_plans);
2366 os_free(config->non_pref_chan);
2367 #endif /* CONFIG_MBO */
2374 * wpa_config_foreach_network - Iterate over each configured network
2375 * @config: Configuration data from wpa_config_read()
2376 * @func: Callback function to process each network
2377 * @arg: Opaque argument to pass to callback function
2379 * Iterate over the set of configured networks calling the specified
2380 * function for each item. We guard against callbacks removing the
2383 void wpa_config_foreach_network(struct wpa_config *config,
2384 void (*func)(void *, struct wpa_ssid *),
2387 struct wpa_ssid *ssid, *next;
2389 ssid = config->ssid;
2399 * wpa_config_get_network - Get configured network based on id
2400 * @config: Configuration data from wpa_config_read()
2401 * @id: Unique network id to search for
2402 * Returns: Network configuration or %NULL if not found
2404 struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
2406 struct wpa_ssid *ssid;
2408 ssid = config->ssid;
2420 * wpa_config_add_network - Add a new network with empty configuration
2421 * @config: Configuration data from wpa_config_read()
2422 * Returns: The new network configuration or %NULL if operation failed
2424 struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
2427 struct wpa_ssid *ssid, *last = NULL;
2430 ssid = config->ssid;
2439 ssid = os_zalloc(sizeof(*ssid));
2443 dl_list_init(&ssid->psk_list);
2447 config->ssid = ssid;
2449 wpa_config_update_prio_list(config);
2456 * wpa_config_remove_network - Remove a configured network based on id
2457 * @config: Configuration data from wpa_config_read()
2458 * @id: Unique network id to search for
2459 * Returns: 0 on success, or -1 if the network was not found
2461 int wpa_config_remove_network(struct wpa_config *config, int id)
2463 struct wpa_ssid *ssid, *prev = NULL;
2465 ssid = config->ssid;
2477 prev->next = ssid->next;
2479 config->ssid = ssid->next;
2481 wpa_config_update_prio_list(config);
2482 wpa_config_free_ssid(ssid);
2488 * wpa_config_set_network_defaults - Set network default values
2489 * @ssid: Pointer to network configuration data
2491 void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
2493 ssid->proto = DEFAULT_PROTO;
2494 ssid->pairwise_cipher = DEFAULT_PAIRWISE;
2495 ssid->group_cipher = DEFAULT_GROUP;
2496 ssid->key_mgmt = DEFAULT_KEY_MGMT;
2497 ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
2498 #ifdef IEEE8021X_EAPOL
2499 ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
2500 ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
2501 ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
2502 ssid->eap.sim_num = DEFAULT_USER_SELECTED_SIM;
2503 #endif /* IEEE8021X_EAPOL */
2505 ssid->dot11MeshMaxRetries = DEFAULT_MESH_MAX_RETRIES;
2506 ssid->dot11MeshRetryTimeout = DEFAULT_MESH_RETRY_TIMEOUT;
2507 ssid->dot11MeshConfirmTimeout = DEFAULT_MESH_CONFIRM_TIMEOUT;
2508 ssid->dot11MeshHoldingTimeout = DEFAULT_MESH_HOLDING_TIMEOUT;
2509 #endif /* CONFIG_MESH */
2510 #ifdef CONFIG_HT_OVERRIDES
2511 ssid->disable_ht = DEFAULT_DISABLE_HT;
2512 ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
2513 ssid->disable_sgi = DEFAULT_DISABLE_SGI;
2514 ssid->disable_ldpc = DEFAULT_DISABLE_LDPC;
2515 ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
2516 ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
2517 ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
2518 #endif /* CONFIG_HT_OVERRIDES */
2519 #ifdef CONFIG_VHT_OVERRIDES
2520 ssid->vht_rx_mcs_nss_1 = -1;
2521 ssid->vht_rx_mcs_nss_2 = -1;
2522 ssid->vht_rx_mcs_nss_3 = -1;
2523 ssid->vht_rx_mcs_nss_4 = -1;
2524 ssid->vht_rx_mcs_nss_5 = -1;
2525 ssid->vht_rx_mcs_nss_6 = -1;
2526 ssid->vht_rx_mcs_nss_7 = -1;
2527 ssid->vht_rx_mcs_nss_8 = -1;
2528 ssid->vht_tx_mcs_nss_1 = -1;
2529 ssid->vht_tx_mcs_nss_2 = -1;
2530 ssid->vht_tx_mcs_nss_3 = -1;
2531 ssid->vht_tx_mcs_nss_4 = -1;
2532 ssid->vht_tx_mcs_nss_5 = -1;
2533 ssid->vht_tx_mcs_nss_6 = -1;
2534 ssid->vht_tx_mcs_nss_7 = -1;
2535 ssid->vht_tx_mcs_nss_8 = -1;
2536 #endif /* CONFIG_VHT_OVERRIDES */
2537 ssid->proactive_key_caching = -1;
2538 #ifdef CONFIG_IEEE80211W
2539 ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
2540 #endif /* CONFIG_IEEE80211W */
2541 ssid->mac_addr = -1;
2546 * wpa_config_set - Set a variable in network configuration
2547 * @ssid: Pointer to network configuration data
2548 * @var: Variable name, e.g., "ssid"
2549 * @value: Variable value
2550 * @line: Line number in configuration file or 0 if not used
2551 * Returns: 0 on success with possible change in the value, 1 on success with
2552 * no change to previously configured value, or -1 on failure
2554 * This function can be used to set network configuration variables based on
2555 * both the configuration file and management interface input. The value
2556 * parameter must be in the same format as the text-based configuration file is
2557 * using. For example, strings are using double quotation marks.
2559 int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
2565 if (ssid == NULL || var == NULL || value == NULL)
2568 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2569 const struct parse_data *field = &ssid_fields[i];
2570 if (os_strcmp(var, field->name) != 0)
2573 ret = field->parser(field, ssid, line, value);
2576 wpa_printf(MSG_ERROR, "Line %d: failed to "
2577 "parse %s '%s'.", line, var, value);
2583 if (i == NUM_SSID_FIELDS) {
2585 wpa_printf(MSG_ERROR, "Line %d: unknown network field "
2586 "'%s'.", line, var);
2595 int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
2602 len = os_strlen(value);
2603 buf = os_malloc(len + 3);
2607 os_memcpy(buf + 1, value, len);
2609 buf[len + 2] = '\0';
2610 ret = wpa_config_set(ssid, var, buf, 0);
2617 * wpa_config_get_all - Get all options from network configuration
2618 * @ssid: Pointer to network configuration data
2619 * @get_keys: Determines if keys/passwords will be included in returned list
2620 * (if they may be exported)
2621 * Returns: %NULL terminated list of all set keys and their values in the form
2622 * of [key1, val1, key2, val2, ... , NULL]
2624 * This function can be used to get list of all configured network properties.
2625 * The caller is responsible for freeing the returned list and all its
2628 char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
2630 #ifdef NO_CONFIG_WRITE
2632 #else /* NO_CONFIG_WRITE */
2633 const struct parse_data *field;
2639 get_keys = get_keys && ssid->export_keys;
2641 props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
2646 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2647 field = &ssid_fields[i];
2648 if (field->key_data && !get_keys)
2650 value = field->writer(field, ssid);
2653 if (os_strlen(value) == 0) {
2658 key = os_strdup(field->name);
2664 props[fields_num * 2] = key;
2665 props[fields_num * 2 + 1] = value;
2673 for (i = 0; props[i]; i++)
2677 #endif /* NO_CONFIG_WRITE */
2681 #ifndef NO_CONFIG_WRITE
2683 * wpa_config_get - Get a variable in network configuration
2684 * @ssid: Pointer to network configuration data
2685 * @var: Variable name, e.g., "ssid"
2686 * Returns: Value of the variable or %NULL on failure
2688 * This function can be used to get network configuration variables. The
2689 * returned value is a copy of the configuration variable in text format, i.e,.
2690 * the same format that the text-based configuration file and wpa_config_set()
2691 * are using for the value. The caller is responsible for freeing the returned
2694 char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
2698 if (ssid == NULL || var == NULL)
2701 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2702 const struct parse_data *field = &ssid_fields[i];
2703 if (os_strcmp(var, field->name) == 0) {
2704 char *ret = field->writer(field, ssid);
2706 if (ret && has_newline(ret)) {
2707 wpa_printf(MSG_ERROR,
2708 "Found newline in value for %s; not returning it",
2723 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2724 * @ssid: Pointer to network configuration data
2725 * @var: Variable name, e.g., "ssid"
2726 * Returns: Value of the variable or %NULL on failure
2728 * This function can be used to get network configuration variable like
2729 * wpa_config_get(). The only difference is that this functions does not expose
2730 * key/password material from the configuration. In case a key/password field
2731 * is requested, the returned value is an empty string or %NULL if the variable
2732 * is not set or "*" if the variable is set (regardless of its value). The
2733 * returned value is a copy of the configuration variable in text format, i.e,.
2734 * the same format that the text-based configuration file and wpa_config_set()
2735 * are using for the value. The caller is responsible for freeing the returned
2738 char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
2742 if (ssid == NULL || var == NULL)
2745 for (i = 0; i < NUM_SSID_FIELDS; i++) {
2746 const struct parse_data *field = &ssid_fields[i];
2747 if (os_strcmp(var, field->name) == 0) {
2748 char *res = field->writer(field, ssid);
2749 if (field->key_data) {
2750 if (res && res[0]) {
2751 wpa_printf(MSG_DEBUG, "Do not allow "
2752 "key_data field to be "
2754 str_clear_free(res);
2755 return os_strdup("*");
2767 #endif /* NO_CONFIG_WRITE */
2771 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2772 * @ssid: Pointer to network configuration data
2774 * This function must be called to update WPA PSK when either SSID or the
2775 * passphrase has changed for the network configuration.
2777 void wpa_config_update_psk(struct wpa_ssid *ssid)
2779 #ifndef CONFIG_NO_PBKDF2
2780 pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
2781 ssid->psk, PMK_LEN);
2782 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
2783 ssid->psk, PMK_LEN);
2785 #endif /* CONFIG_NO_PBKDF2 */
2789 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred *cred,
2794 int *ports, *nports;
2796 unsigned int num_ports;
2798 proto = os_realloc_array(cred->req_conn_capab_proto,
2799 cred->num_req_conn_capab + 1, sizeof(u8));
2802 cred->req_conn_capab_proto = proto;
2804 port = os_realloc_array(cred->req_conn_capab_port,
2805 cred->num_req_conn_capab + 1, sizeof(int *));
2808 cred->req_conn_capab_port = port;
2810 proto[cred->num_req_conn_capab] = atoi(value);
2812 pos = os_strchr(value, ':');
2814 port[cred->num_req_conn_capab] = NULL;
2815 cred->num_req_conn_capab++;
2824 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2825 if (nports == NULL) {
2830 ports[num_ports++] = atoi(pos);
2832 pos = os_strchr(pos, ',');
2838 nports = os_realloc_array(ports, num_ports + 1, sizeof(int));
2839 if (nports == NULL) {
2844 ports[num_ports] = -1;
2846 port[cred->num_req_conn_capab] = ports;
2847 cred->num_req_conn_capab++;
2852 int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
2853 const char *value, int line)
2858 if (os_strcmp(var, "temporary") == 0) {
2859 cred->temporary = atoi(value);
2863 if (os_strcmp(var, "priority") == 0) {
2864 cred->priority = atoi(value);
2868 if (os_strcmp(var, "sp_priority") == 0) {
2869 int prio = atoi(value);
2870 if (prio < 0 || prio > 255)
2872 cred->sp_priority = prio;
2876 if (os_strcmp(var, "pcsc") == 0) {
2877 cred->pcsc = atoi(value);
2881 if (os_strcmp(var, "eap") == 0) {
2882 struct eap_method_type method;
2883 method.method = eap_peer_get_type(value, &method.vendor);
2884 if (method.vendor == EAP_VENDOR_IETF &&
2885 method.method == EAP_TYPE_NONE) {
2886 wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
2887 "for a credential", line, value);
2890 os_free(cred->eap_method);
2891 cred->eap_method = os_malloc(sizeof(*cred->eap_method));
2892 if (cred->eap_method == NULL)
2894 os_memcpy(cred->eap_method, &method, sizeof(method));
2898 if (os_strcmp(var, "password") == 0 &&
2899 os_strncmp(value, "ext:", 4) == 0) {
2900 if (has_newline(value))
2902 str_clear_free(cred->password);
2903 cred->password = os_strdup(value);
2904 cred->ext_password = 1;
2908 if (os_strcmp(var, "update_identifier") == 0) {
2909 cred->update_identifier = atoi(value);
2913 if (os_strcmp(var, "min_dl_bandwidth_home") == 0) {
2914 cred->min_dl_bandwidth_home = atoi(value);
2918 if (os_strcmp(var, "min_ul_bandwidth_home") == 0) {
2919 cred->min_ul_bandwidth_home = atoi(value);
2923 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0) {
2924 cred->min_dl_bandwidth_roaming = atoi(value);
2928 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0) {
2929 cred->min_ul_bandwidth_roaming = atoi(value);
2933 if (os_strcmp(var, "max_bss_load") == 0) {
2934 cred->max_bss_load = atoi(value);
2938 if (os_strcmp(var, "req_conn_capab") == 0)
2939 return wpa_config_set_cred_req_conn_capab(cred, value);
2941 if (os_strcmp(var, "ocsp") == 0) {
2942 cred->ocsp = atoi(value);
2946 if (os_strcmp(var, "sim_num") == 0) {
2947 cred->sim_num = atoi(value);
2951 val = wpa_config_parse_string(value, &len);
2953 (os_strcmp(var, "excluded_ssid") != 0 &&
2954 os_strcmp(var, "roaming_consortium") != 0 &&
2955 os_strcmp(var, "required_roaming_consortium") != 0 &&
2956 has_newline(val))) {
2957 wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
2958 "value '%s'.", line, var, value);
2963 if (os_strcmp(var, "realm") == 0) {
2964 os_free(cred->realm);
2969 if (os_strcmp(var, "username") == 0) {
2970 str_clear_free(cred->username);
2971 cred->username = val;
2975 if (os_strcmp(var, "password") == 0) {
2976 str_clear_free(cred->password);
2977 cred->password = val;
2978 cred->ext_password = 0;
2982 if (os_strcmp(var, "ca_cert") == 0) {
2983 os_free(cred->ca_cert);
2984 cred->ca_cert = val;
2988 if (os_strcmp(var, "client_cert") == 0) {
2989 os_free(cred->client_cert);
2990 cred->client_cert = val;
2994 if (os_strcmp(var, "private_key") == 0) {
2995 os_free(cred->private_key);
2996 cred->private_key = val;
3000 if (os_strcmp(var, "private_key_passwd") == 0) {
3001 str_clear_free(cred->private_key_passwd);
3002 cred->private_key_passwd = val;
3006 if (os_strcmp(var, "imsi") == 0) {
3007 os_free(cred->imsi);
3012 if (os_strcmp(var, "milenage") == 0) {
3013 str_clear_free(cred->milenage);
3014 cred->milenage = val;
3018 if (os_strcmp(var, "domain_suffix_match") == 0) {
3019 os_free(cred->domain_suffix_match);
3020 cred->domain_suffix_match = val;
3024 if (os_strcmp(var, "domain") == 0) {
3026 new_domain = os_realloc_array(cred->domain,
3027 cred->num_domain + 1,
3029 if (new_domain == NULL) {
3033 new_domain[cred->num_domain++] = val;
3034 cred->domain = new_domain;
3038 if (os_strcmp(var, "phase1") == 0) {
3039 os_free(cred->phase1);
3044 if (os_strcmp(var, "phase2") == 0) {
3045 os_free(cred->phase2);
3050 if (os_strcmp(var, "roaming_consortium") == 0) {
3051 if (len < 3 || len > sizeof(cred->roaming_consortium)) {
3052 wpa_printf(MSG_ERROR, "Line %d: invalid "
3053 "roaming_consortium length %d (3..15 "
3054 "expected)", line, (int) len);
3058 os_memcpy(cred->roaming_consortium, val, len);
3059 cred->roaming_consortium_len = len;
3064 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3065 if (len < 3 || len > sizeof(cred->required_roaming_consortium))
3067 wpa_printf(MSG_ERROR, "Line %d: invalid "
3068 "required_roaming_consortium length %d "
3069 "(3..15 expected)", line, (int) len);
3073 os_memcpy(cred->required_roaming_consortium, val, len);
3074 cred->required_roaming_consortium_len = len;
3079 if (os_strcmp(var, "excluded_ssid") == 0) {
3080 struct excluded_ssid *e;
3082 if (len > SSID_MAX_LEN) {
3083 wpa_printf(MSG_ERROR, "Line %d: invalid "
3084 "excluded_ssid length %d", line, (int) len);
3089 e = os_realloc_array(cred->excluded_ssid,
3090 cred->num_excluded_ssid + 1,
3091 sizeof(struct excluded_ssid));
3096 cred->excluded_ssid = e;
3098 e = &cred->excluded_ssid[cred->num_excluded_ssid++];
3099 os_memcpy(e->ssid, val, len);
3107 if (os_strcmp(var, "roaming_partner") == 0) {
3108 struct roaming_partner *p;
3111 p = os_realloc_array(cred->roaming_partner,
3112 cred->num_roaming_partner + 1,
3113 sizeof(struct roaming_partner));
3118 cred->roaming_partner = p;
3120 p = &cred->roaming_partner[cred->num_roaming_partner];
3122 pos = os_strchr(val, ',');
3128 if (pos - val - 1 >= (int) sizeof(p->fqdn)) {
3132 os_memcpy(p->fqdn, val, pos - val);
3134 p->exact_match = atoi(pos);
3136 pos = os_strchr(pos, ',');
3143 p->priority = atoi(pos);
3145 pos = os_strchr(pos, ',');
3152 if (os_strlen(pos) >= sizeof(p->country)) {
3156 os_memcpy(p->country, pos, os_strlen(pos) + 1);
3158 cred->num_roaming_partner++;
3164 if (os_strcmp(var, "provisioning_sp") == 0) {
3165 os_free(cred->provisioning_sp);
3166 cred->provisioning_sp = val;
3171 wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
3181 static char * alloc_int_str(int val)
3183 const unsigned int bufsize = 20;
3187 buf = os_malloc(bufsize);
3190 res = os_snprintf(buf, bufsize, "%d", val);
3191 if (os_snprintf_error(bufsize, res)) {
3199 static char * alloc_strdup(const char *str)
3203 return os_strdup(str);
3207 char * wpa_config_get_cred_no_key(struct wpa_cred *cred, const char *var)
3209 if (os_strcmp(var, "temporary") == 0)
3210 return alloc_int_str(cred->temporary);
3212 if (os_strcmp(var, "priority") == 0)
3213 return alloc_int_str(cred->priority);
3215 if (os_strcmp(var, "sp_priority") == 0)
3216 return alloc_int_str(cred->sp_priority);
3218 if (os_strcmp(var, "pcsc") == 0)
3219 return alloc_int_str(cred->pcsc);
3221 if (os_strcmp(var, "eap") == 0) {
3222 if (!cred->eap_method)
3224 return alloc_strdup(eap_get_name(cred->eap_method[0].vendor,
3225 cred->eap_method[0].method));
3228 if (os_strcmp(var, "update_identifier") == 0)
3229 return alloc_int_str(cred->update_identifier);
3231 if (os_strcmp(var, "min_dl_bandwidth_home") == 0)
3232 return alloc_int_str(cred->min_dl_bandwidth_home);
3234 if (os_strcmp(var, "min_ul_bandwidth_home") == 0)
3235 return alloc_int_str(cred->min_ul_bandwidth_home);
3237 if (os_strcmp(var, "min_dl_bandwidth_roaming") == 0)
3238 return alloc_int_str(cred->min_dl_bandwidth_roaming);
3240 if (os_strcmp(var, "min_ul_bandwidth_roaming") == 0)
3241 return alloc_int_str(cred->min_ul_bandwidth_roaming);
3243 if (os_strcmp(var, "max_bss_load") == 0)
3244 return alloc_int_str(cred->max_bss_load);
3246 if (os_strcmp(var, "req_conn_capab") == 0) {
3248 char *buf, *end, *pos;
3251 if (!cred->num_req_conn_capab)
3254 buf = os_malloc(4000);
3259 for (i = 0; i < cred->num_req_conn_capab; i++) {
3262 ret = os_snprintf(pos, end - pos, "%s%u",
3264 cred->req_conn_capab_proto[i]);
3265 if (os_snprintf_error(end - pos, ret))
3269 ports = cred->req_conn_capab_port[i];
3272 for (j = 0; ports[j] != -1; j++) {
3273 ret = os_snprintf(pos, end - pos,
3277 if (os_snprintf_error(end - pos, ret))
3287 if (os_strcmp(var, "ocsp") == 0)
3288 return alloc_int_str(cred->ocsp);
3290 if (os_strcmp(var, "realm") == 0)
3291 return alloc_strdup(cred->realm);
3293 if (os_strcmp(var, "username") == 0)
3294 return alloc_strdup(cred->username);
3296 if (os_strcmp(var, "password") == 0) {
3297 if (!cred->password)
3299 return alloc_strdup("*");
3302 if (os_strcmp(var, "ca_cert") == 0)
3303 return alloc_strdup(cred->ca_cert);
3305 if (os_strcmp(var, "client_cert") == 0)
3306 return alloc_strdup(cred->client_cert);
3308 if (os_strcmp(var, "private_key") == 0)
3309 return alloc_strdup(cred->private_key);
3311 if (os_strcmp(var, "private_key_passwd") == 0) {
3312 if (!cred->private_key_passwd)
3314 return alloc_strdup("*");
3317 if (os_strcmp(var, "imsi") == 0)
3318 return alloc_strdup(cred->imsi);
3320 if (os_strcmp(var, "milenage") == 0) {
3321 if (!(cred->milenage))
3323 return alloc_strdup("*");
3326 if (os_strcmp(var, "domain_suffix_match") == 0)
3327 return alloc_strdup(cred->domain_suffix_match);
3329 if (os_strcmp(var, "domain") == 0) {
3331 char *buf, *end, *pos;
3334 if (!cred->num_domain)
3337 buf = os_malloc(4000);
3343 for (i = 0; i < cred->num_domain; i++) {
3344 ret = os_snprintf(pos, end - pos, "%s%s",
3345 i > 0 ? "\n" : "", cred->domain[i]);
3346 if (os_snprintf_error(end - pos, ret))
3354 if (os_strcmp(var, "phase1") == 0)
3355 return alloc_strdup(cred->phase1);
3357 if (os_strcmp(var, "phase2") == 0)
3358 return alloc_strdup(cred->phase2);
3360 if (os_strcmp(var, "roaming_consortium") == 0) {
3364 if (!cred->roaming_consortium_len)
3366 buflen = cred->roaming_consortium_len * 2 + 1;
3367 buf = os_malloc(buflen);
3370 wpa_snprintf_hex(buf, buflen, cred->roaming_consortium,
3371 cred->roaming_consortium_len);
3375 if (os_strcmp(var, "required_roaming_consortium") == 0) {
3379 if (!cred->required_roaming_consortium_len)
3381 buflen = cred->required_roaming_consortium_len * 2 + 1;
3382 buf = os_malloc(buflen);
3385 wpa_snprintf_hex(buf, buflen, cred->required_roaming_consortium,
3386 cred->required_roaming_consortium_len);
3390 if (os_strcmp(var, "excluded_ssid") == 0) {
3392 char *buf, *end, *pos;
3394 if (!cred->num_excluded_ssid)
3397 buf = os_malloc(4000);
3403 for (i = 0; i < cred->num_excluded_ssid; i++) {
3404 struct excluded_ssid *e;
3407 e = &cred->excluded_ssid[i];
3408 ret = os_snprintf(pos, end - pos, "%s%s",
3410 wpa_ssid_txt(e->ssid, e->ssid_len));
3411 if (os_snprintf_error(end - pos, ret))
3419 if (os_strcmp(var, "roaming_partner") == 0) {
3421 char *buf, *end, *pos;
3423 if (!cred->num_roaming_partner)
3426 buf = os_malloc(4000);
3432 for (i = 0; i < cred->num_roaming_partner; i++) {
3433 struct roaming_partner *p;
3436 p = &cred->roaming_partner[i];
3437 ret = os_snprintf(pos, end - pos, "%s%s,%d,%u,%s",
3439 p->fqdn, p->exact_match, p->priority,
3441 if (os_snprintf_error(end - pos, ret))
3449 if (os_strcmp(var, "provisioning_sp") == 0)
3450 return alloc_strdup(cred->provisioning_sp);
3456 struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
3458 struct wpa_cred *cred;
3460 cred = config->cred;
3471 struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
3474 struct wpa_cred *cred, *last = NULL;
3477 cred = config->cred;
3486 cred = os_zalloc(sizeof(*cred));
3490 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
3494 config->cred = cred;
3500 int wpa_config_remove_cred(struct wpa_config *config, int id)
3502 struct wpa_cred *cred, *prev = NULL;
3504 cred = config->cred;
3516 prev->next = cred->next;
3518 config->cred = cred->next;
3520 wpa_config_free_cred(cred);
3525 #ifndef CONFIG_NO_CONFIG_BLOBS
3527 * wpa_config_get_blob - Get a named configuration blob
3528 * @config: Configuration data from wpa_config_read()
3529 * @name: Name of the blob
3530 * Returns: Pointer to blob data or %NULL if not found
3532 const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
3535 struct wpa_config_blob *blob = config->blobs;
3538 if (os_strcmp(blob->name, name) == 0)
3547 * wpa_config_set_blob - Set or add a named configuration blob
3548 * @config: Configuration data from wpa_config_read()
3549 * @blob: New value for the blob
3551 * Adds a new configuration blob or replaces the current value of an existing
3554 void wpa_config_set_blob(struct wpa_config *config,
3555 struct wpa_config_blob *blob)
3557 wpa_config_remove_blob(config, blob->name);
3558 blob->next = config->blobs;
3559 config->blobs = blob;
3564 * wpa_config_free_blob - Free blob data
3565 * @blob: Pointer to blob to be freed
3567 void wpa_config_free_blob(struct wpa_config_blob *blob)
3570 os_free(blob->name);
3571 bin_clear_free(blob->data, blob->len);
3578 * wpa_config_remove_blob - Remove a named configuration blob
3579 * @config: Configuration data from wpa_config_read()
3580 * @name: Name of the blob to remove
3581 * Returns: 0 if blob was removed or -1 if blob was not found
3583 int wpa_config_remove_blob(struct wpa_config *config, const char *name)
3585 struct wpa_config_blob *pos = config->blobs, *prev = NULL;
3588 if (os_strcmp(pos->name, name) == 0) {
3590 prev->next = pos->next;
3592 config->blobs = pos->next;
3593 wpa_config_free_blob(pos);
3602 #endif /* CONFIG_NO_CONFIG_BLOBS */
3606 * wpa_config_alloc_empty - Allocate an empty configuration
3607 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3609 * @driver_param: Driver parameters
3610 * Returns: Pointer to allocated configuration data or %NULL on failure
3612 struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
3613 const char *driver_param)
3615 struct wpa_config *config;
3616 const int aCWmin = 4, aCWmax = 10;
3617 const struct hostapd_wmm_ac_params ac_bk =
3618 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3619 const struct hostapd_wmm_ac_params ac_be =
3620 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3621 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
3622 { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
3623 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
3624 { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
3626 config = os_zalloc(sizeof(*config));
3629 config->eapol_version = DEFAULT_EAPOL_VERSION;
3630 config->ap_scan = DEFAULT_AP_SCAN;
3631 config->user_mpm = DEFAULT_USER_MPM;
3632 config->max_peer_links = DEFAULT_MAX_PEER_LINKS;
3633 config->mesh_max_inactivity = DEFAULT_MESH_MAX_INACTIVITY;
3634 config->dot11RSNASAERetransPeriod =
3635 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD;
3636 config->fast_reauth = DEFAULT_FAST_REAUTH;
3637 config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
3638 config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
3639 config->p2p_go_freq_change_policy = DEFAULT_P2P_GO_FREQ_MOVE;
3640 config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
3641 config->p2p_optimize_listen_chan = DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN;
3642 config->p2p_go_ctwindow = DEFAULT_P2P_GO_CTWINDOW;
3643 config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
3644 config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
3645 config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
3646 config->max_num_sta = DEFAULT_MAX_NUM_STA;
3647 config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
3648 config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ;
3649 config->wmm_ac_params[0] = ac_be;
3650 config->wmm_ac_params[1] = ac_bk;
3651 config->wmm_ac_params[2] = ac_vi;
3652 config->wmm_ac_params[3] = ac_vo;
3653 config->p2p_search_delay = DEFAULT_P2P_SEARCH_DELAY;
3654 config->rand_addr_lifetime = DEFAULT_RAND_ADDR_LIFETIME;
3655 config->key_mgmt_offload = DEFAULT_KEY_MGMT_OFFLOAD;
3656 config->cert_in_cb = DEFAULT_CERT_IN_CB;
3657 config->wpa_rsc_relaxation = DEFAULT_WPA_RSC_RELAXATION;
3660 config->mbo_cell_capa = DEFAULT_MBO_CELL_CAPA;
3661 #endif /* CONFIG_MBO */
3664 config->ctrl_interface = os_strdup(ctrl_interface);
3666 config->driver_param = os_strdup(driver_param);
3672 #ifndef CONFIG_NO_STDOUT_DEBUG
3674 * wpa_config_debug_dump_networks - Debug dump of configured networks
3675 * @config: Configuration data from wpa_config_read()
3677 void wpa_config_debug_dump_networks(struct wpa_config *config)
3680 struct wpa_ssid *ssid;
3682 for (prio = 0; prio < config->num_prio; prio++) {
3683 ssid = config->pssid[prio];
3684 wpa_printf(MSG_DEBUG, "Priority group %d",
3687 wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
3689 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3694 #endif /* CONFIG_NO_STDOUT_DEBUG */
3697 struct global_parse_data {
3699 int (*parser)(const struct global_parse_data *data,
3700 struct wpa_config *config, int line, const char *value);
3701 int (*get)(const char *name, struct wpa_config *config, long offset,
3702 char *buf, size_t buflen, int pretty_print);
3703 void *param1, *param2, *param3;
3704 unsigned int changed_flag;
3708 static int wpa_global_config_parse_int(const struct global_parse_data *data,
3709 struct wpa_config *config, int line,
3715 dst = (int *) (((u8 *) config) + (long) data->param1);
3716 val = strtol(pos, &end, 0);
3718 wpa_printf(MSG_ERROR, "Line %d: invalid number \"%s\"",
3724 wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
3726 if (data->param2 && *dst < (long) data->param2) {
3727 wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
3728 "min_value=%ld)", line, data->name, *dst,
3729 (long) data->param2);
3730 *dst = (long) data->param2;
3734 if (data->param3 && *dst > (long) data->param3) {
3735 wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
3736 "max_value=%ld)", line, data->name, *dst,
3737 (long) data->param3);
3738 *dst = (long) data->param3;
3746 static int wpa_global_config_parse_str(const struct global_parse_data *data,
3747 struct wpa_config *config, int line,
3753 len = os_strlen(pos);
3754 if (data->param2 && len < (size_t) data->param2) {
3755 wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
3756 "min_len=%ld)", line, data->name,
3757 (unsigned long) len, (long) data->param2);
3761 if (data->param3 && len > (size_t) data->param3) {
3762 wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
3763 "max_len=%ld)", line, data->name,
3764 (unsigned long) len, (long) data->param3);
3768 if (has_newline(pos)) {
3769 wpa_printf(MSG_ERROR, "Line %d: invalid %s value with newline",
3774 tmp = os_strdup(pos);
3778 dst = (char **) (((u8 *) config) + (long) data->param1);
3781 wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
3787 static int wpa_config_process_bgscan(const struct global_parse_data *data,
3788 struct wpa_config *config, int line,
3795 tmp = wpa_config_parse_string(pos, &len);
3797 wpa_printf(MSG_ERROR, "Line %d: failed to parse %s",
3802 res = wpa_global_config_parse_str(data, config, line, tmp);
3808 static int wpa_global_config_parse_bin(const struct global_parse_data *data,
3809 struct wpa_config *config, int line,
3812 struct wpabuf **dst, *tmp;
3814 tmp = wpabuf_parse_bin(pos);
3818 dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
3821 wpa_printf(MSG_DEBUG, "%s", data->name);
3827 static int wpa_config_process_freq_list(const struct global_parse_data *data,
3828 struct wpa_config *config, int line,
3833 freqs = wpa_config_parse_int_array(value);
3836 if (freqs[0] == 0) {
3840 os_free(config->freq_list);
3841 config->freq_list = freqs;
3847 static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
3848 struct wpa_config *config, int line,
3852 struct hostapd_ip_addr addr;
3854 if (hostapd_parse_ip_addr(pos, &addr) < 0)
3856 if (addr.af != AF_INET)
3859 dst = (u32 *) (((u8 *) config) + (long) data->param1);
3860 os_memcpy(dst, &addr.u.v4.s_addr, 4);
3861 wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name,
3862 WPA_GET_BE32((u8 *) dst));
3866 #endif /* CONFIG_P2P */
3869 static int wpa_config_process_country(const struct global_parse_data *data,
3870 struct wpa_config *config, int line,
3873 if (!pos[0] || !pos[1]) {
3874 wpa_printf(MSG_DEBUG, "Invalid country set");
3877 config->country[0] = pos[0];
3878 config->country[1] = pos[1];
3879 wpa_printf(MSG_DEBUG, "country='%c%c'",
3880 config->country[0], config->country[1]);
3885 static int wpa_config_process_load_dynamic_eap(
3886 const struct global_parse_data *data, struct wpa_config *config,
3887 int line, const char *so)
3890 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
3891 ret = eap_peer_method_load(so);
3893 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
3896 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
3897 "method '%s'.", line, so);
3907 static int wpa_config_process_uuid(const struct global_parse_data *data,
3908 struct wpa_config *config, int line,
3912 if (uuid_str2bin(pos, config->uuid)) {
3913 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
3916 uuid_bin2str(config->uuid, buf, sizeof(buf));
3917 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
3922 static int wpa_config_process_device_type(
3923 const struct global_parse_data *data,
3924 struct wpa_config *config, int line, const char *pos)
3926 return wps_dev_type_str2bin(pos, config->device_type);
3930 static int wpa_config_process_os_version(const struct global_parse_data *data,
3931 struct wpa_config *config, int line,
3934 if (hexstr2bin(pos, config->os_version, 4)) {
3935 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
3938 wpa_printf(MSG_DEBUG, "os_version=%08x",
3939 WPA_GET_BE32(config->os_version));
3944 static int wpa_config_process_wps_vendor_ext_m1(
3945 const struct global_parse_data *data,
3946 struct wpa_config *config, int line, const char *pos)
3949 int len = os_strlen(pos) / 2;
3953 wpa_printf(MSG_ERROR, "Line %d: "
3954 "invalid wps_vendor_ext_m1", line);
3958 tmp = wpabuf_alloc(len);
3960 p = wpabuf_put(tmp, len);
3962 if (hexstr2bin(pos, p, len)) {
3963 wpa_printf(MSG_ERROR, "Line %d: "
3964 "invalid wps_vendor_ext_m1", line);
3969 wpabuf_free(config->wps_vendor_ext_m1);
3970 config->wps_vendor_ext_m1 = tmp;
3972 wpa_printf(MSG_ERROR, "Can not allocate "
3973 "memory for wps_vendor_ext_m1");
3980 #endif /* CONFIG_WPS */
3983 static int wpa_config_process_sec_device_type(
3984 const struct global_parse_data *data,
3985 struct wpa_config *config, int line, const char *pos)
3989 if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
3990 wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
3995 idx = config->num_sec_device_types;
3997 if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
4000 config->num_sec_device_types++;
4005 static int wpa_config_process_p2p_pref_chan(
4006 const struct global_parse_data *data,
4007 struct wpa_config *config, int line, const char *pos)
4009 struct p2p_channel *pref = NULL, *n;
4010 unsigned int num = 0;
4014 /* format: class:chan,class:chan,... */
4017 op_class = atoi(pos);
4018 pos2 = os_strchr(pos, ':');
4024 n = os_realloc_array(pref, num + 1,
4025 sizeof(struct p2p_channel));
4029 pref[num].op_class = op_class;
4030 pref[num].chan = chan;
4033 pos = os_strchr(pos2, ',');
4039 os_free(config->p2p_pref_chan);
4040 config->p2p_pref_chan = pref;
4041 config->num_p2p_pref_chan = num;
4042 wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
4043 (u8 *) config->p2p_pref_chan,
4044 config->num_p2p_pref_chan * sizeof(struct p2p_channel));
4050 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
4055 static int wpa_config_process_p2p_no_go_freq(
4056 const struct global_parse_data *data,
4057 struct wpa_config *config, int line, const char *pos)
4061 ret = freq_range_list_parse(&config->p2p_no_go_freq, pos);
4063 wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_no_go_freq", line);
4067 wpa_printf(MSG_DEBUG, "P2P: p2p_no_go_freq with %u items",
4068 config->p2p_no_go_freq.num);
4073 #endif /* CONFIG_P2P */
4076 static int wpa_config_process_hessid(
4077 const struct global_parse_data *data,
4078 struct wpa_config *config, int line, const char *pos)
4080 if (hwaddr_aton2(pos, config->hessid) < 0) {
4081 wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
4090 static int wpa_config_process_sae_groups(
4091 const struct global_parse_data *data,
4092 struct wpa_config *config, int line, const char *pos)
4094 int *groups = wpa_config_parse_int_array(pos);
4095 if (groups == NULL) {
4096 wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
4101 os_free(config->sae_groups);
4102 config->sae_groups = groups;
4108 static int wpa_config_process_ap_vendor_elements(
4109 const struct global_parse_data *data,
4110 struct wpa_config *config, int line, const char *pos)
4113 int len = os_strlen(pos) / 2;
4117 wpa_printf(MSG_ERROR, "Line %d: invalid ap_vendor_elements",
4122 tmp = wpabuf_alloc(len);
4124 p = wpabuf_put(tmp, len);
4126 if (hexstr2bin(pos, p, len)) {
4127 wpa_printf(MSG_ERROR, "Line %d: invalid "
4128 "ap_vendor_elements", line);
4133 wpabuf_free(config->ap_vendor_elements);
4134 config->ap_vendor_elements = tmp;
4136 wpa_printf(MSG_ERROR, "Cannot allocate memory for "
4137 "ap_vendor_elements");
4145 #ifdef CONFIG_CTRL_IFACE
4146 static int wpa_config_process_no_ctrl_interface(
4147 const struct global_parse_data *data,
4148 struct wpa_config *config, int line, const char *pos)
4150 wpa_printf(MSG_DEBUG, "no_ctrl_interface -> ctrl_interface=NULL");
4151 os_free(config->ctrl_interface);
4152 config->ctrl_interface = NULL;
4155 #endif /* CONFIG_CTRL_IFACE */
4158 static int wpa_config_get_int(const char *name, struct wpa_config *config,
4159 long offset, char *buf, size_t buflen,
4162 int *val = (int *) (((u8 *) config) + (long) offset);
4165 return os_snprintf(buf, buflen, "%s=%d\n", name, *val);
4166 return os_snprintf(buf, buflen, "%d", *val);
4170 static int wpa_config_get_str(const char *name, struct wpa_config *config,
4171 long offset, char *buf, size_t buflen,
4174 char **val = (char **) (((u8 *) config) + (long) offset);
4178 res = os_snprintf(buf, buflen, "%s=%s\n", name,
4179 *val ? *val : "null");
4183 res = os_snprintf(buf, buflen, "%s", *val);
4184 if (os_snprintf_error(buflen, res))
4192 static int wpa_config_get_ipv4(const char *name, struct wpa_config *config,
4193 long offset, char *buf, size_t buflen,
4196 void *val = ((u8 *) config) + (long) offset;
4198 char addr[INET_ADDRSTRLEN];
4200 if (!val || !inet_ntop(AF_INET, val, addr, sizeof(addr)))
4204 res = os_snprintf(buf, buflen, "%s=%s\n", name, addr);
4206 res = os_snprintf(buf, buflen, "%s", addr);
4208 if (os_snprintf_error(buflen, res))
4213 #endif /* CONFIG_P2P */
4219 /* OFFSET: Get offset of a variable within the wpa_config structure */
4220 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4222 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4223 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4224 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4225 #define INT(f) _INT(f), NULL, NULL
4226 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4227 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4228 #define STR(f) _STR(f), NULL, NULL
4229 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4230 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4231 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4232 OFFSET(f), NULL, NULL
4234 static const struct global_parse_data global_fields[] = {
4235 #ifdef CONFIG_CTRL_IFACE
4236 { STR(ctrl_interface), 0 },
4237 { FUNC_NO_VAR(no_ctrl_interface), 0 },
4238 { STR(ctrl_interface_group), 0 } /* deprecated */,
4239 #endif /* CONFIG_CTRL_IFACE */
4240 #ifdef CONFIG_MACSEC
4241 { INT_RANGE(eapol_version, 1, 3), 0 },
4242 #else /* CONFIG_MACSEC */
4243 { INT_RANGE(eapol_version, 1, 2), 0 },
4244 #endif /* CONFIG_MACSEC */
4245 { INT(ap_scan), 0 },
4246 { FUNC(bgscan), 0 },
4248 { INT(user_mpm), 0 },
4249 { INT_RANGE(max_peer_links, 0, 255), 0 },
4250 { INT(mesh_max_inactivity), 0 },
4251 { INT(dot11RSNASAERetransPeriod), 0 },
4252 #endif /* CONFIG_MESH */
4253 { INT(disable_scan_offload), 0 },
4254 { INT(fast_reauth), 0 },
4255 { STR(opensc_engine_path), 0 },
4256 { STR(pkcs11_engine_path), 0 },
4257 { STR(pkcs11_module_path), 0 },
4258 { STR(openssl_ciphers), 0 },
4259 { STR(pcsc_reader), 0 },
4260 { STR(pcsc_pin), 0 },
4261 { INT(external_sim), 0 },
4262 { STR(driver_param), 0 },
4263 { INT(dot11RSNAConfigPMKLifetime), 0 },
4264 { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
4265 { INT(dot11RSNAConfigSATimeout), 0 },
4266 #ifndef CONFIG_NO_CONFIG_WRITE
4267 { INT(update_config), 0 },
4268 #endif /* CONFIG_NO_CONFIG_WRITE */
4269 { FUNC_NO_VAR(load_dynamic_eap), 0 },
4271 { FUNC(uuid), CFG_CHANGED_UUID },
4272 { STR_RANGE(device_name, 0, WPS_DEV_NAME_MAX_LEN),
4273 CFG_CHANGED_DEVICE_NAME },
4274 { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
4275 { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
4276 { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
4277 { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
4278 { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
4279 { FUNC(os_version), CFG_CHANGED_OS_VERSION },
4280 { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
4281 { INT_RANGE(wps_cred_processing, 0, 2), 0 },
4282 { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
4283 #endif /* CONFIG_WPS */
4285 { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
4286 { INT(p2p_listen_reg_class), CFG_CHANGED_P2P_LISTEN_CHANNEL },
4287 { INT(p2p_listen_channel), CFG_CHANGED_P2P_LISTEN_CHANNEL },
4288 { INT(p2p_oper_reg_class), CFG_CHANGED_P2P_OPER_CHANNEL },
4289 { INT(p2p_oper_channel), CFG_CHANGED_P2P_OPER_CHANNEL },
4290 { INT_RANGE(p2p_go_intent, 0, 15), 0 },
4291 { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
4292 { INT_RANGE(persistent_reconnect, 0, 1), 0 },
4293 { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
4294 { INT(p2p_group_idle), 0 },
4295 { INT_RANGE(p2p_go_freq_change_policy, 0, P2P_GO_FREQ_MOVE_MAX), 0 },
4296 { INT_RANGE(p2p_passphrase_len, 8, 63),
4297 CFG_CHANGED_P2P_PASSPHRASE_LEN },
4298 { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
4299 { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
4300 { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
4301 { INT_RANGE(p2p_optimize_listen_chan, 0, 1), 0 },
4302 { INT(p2p_go_ht40), 0 },
4303 { INT(p2p_go_vht), 0 },
4304 { INT(p2p_disabled), 0 },
4305 { INT_RANGE(p2p_go_ctwindow, 0, 127), 0 },
4306 { INT(p2p_no_group_iface), 0 },
4307 { INT_RANGE(p2p_ignore_shared_freq, 0, 1), 0 },
4308 { IPV4(ip_addr_go), 0 },
4309 { IPV4(ip_addr_mask), 0 },
4310 { IPV4(ip_addr_start), 0 },
4311 { IPV4(ip_addr_end), 0 },
4312 { INT_RANGE(p2p_cli_probe, 0, 1), 0 },
4313 #endif /* CONFIG_P2P */
4314 { FUNC(country), CFG_CHANGED_COUNTRY },
4315 { INT(bss_max_count), 0 },
4316 { INT(bss_expiration_age), 0 },
4317 { INT(bss_expiration_scan_count), 0 },
4318 { INT_RANGE(filter_ssids, 0, 1), 0 },
4319 { INT_RANGE(filter_rssi, -100, 0), 0 },
4320 { INT(max_num_sta), 0 },
4321 { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
4323 { INT_RANGE(hs20, 0, 1), 0 },
4324 #endif /* CONFIG_HS20 */
4325 { INT_RANGE(interworking, 0, 1), 0 },
4326 { FUNC(hessid), 0 },
4327 { INT_RANGE(access_network_type, 0, 15), 0 },
4328 { INT_RANGE(pbc_in_m1, 0, 1), 0 },
4329 { STR(autoscan), 0 },
4330 { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff),
4331 CFG_CHANGED_NFC_PASSWORD_TOKEN },
4332 { BIN(wps_nfc_dh_pubkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4333 { BIN(wps_nfc_dh_privkey), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4334 { BIN(wps_nfc_dev_pw), CFG_CHANGED_NFC_PASSWORD_TOKEN },
4335 { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
4336 { INT(p2p_go_max_inactivity), 0 },
4337 { INT_RANGE(auto_interworking, 0, 1), 0 },
4340 { FUNC(sae_groups), 0 },
4341 { INT(dtim_period), 0 },
4342 { INT(beacon_int), 0 },
4343 { FUNC(ap_vendor_elements), 0 },
4344 { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
4345 { FUNC(freq_list), 0 },
4346 { INT(scan_cur_freq), 0 },
4347 { INT(sched_scan_interval), 0 },
4348 { INT(tdls_external_control), 0},
4349 { STR(osu_dir), 0 },
4350 { STR(wowlan_triggers), 0 },
4351 { INT(p2p_search_delay), 0},
4352 { INT(mac_addr), 0 },
4353 { INT(rand_addr_lifetime), 0 },
4354 { INT(preassoc_mac_addr), 0 },
4355 { INT(key_mgmt_offload), 0},
4356 { INT(passive_scan), 0 },
4357 { INT(reassoc_same_bss_optim), 0 },
4358 { INT(wps_priority), 0},
4360 { STR_RANGE(fst_group_id, 1, FST_MAX_GROUP_ID_LEN), 0 },
4361 { INT_RANGE(fst_priority, 1, FST_MAX_PRIO_VALUE), 0 },
4362 { INT_RANGE(fst_llt, 1, FST_MAX_LLT_MS), 0 },
4363 #endif /* CONFIG_FST */
4364 { INT_RANGE(wpa_rsc_relaxation, 0, 1), 0 },
4365 { STR(sched_scan_plans), CFG_CHANGED_SCHED_SCAN_PLANS },
4367 { STR(non_pref_chan), 0 },
4368 { INT_RANGE(mbo_cell_capa, MBO_CELL_CAPA_AVAILABLE,
4369 MBO_CELL_CAPA_NOT_SUPPORTED), 0 },
4370 #endif /*CONFIG_MBO */
4371 { INT(gas_address3), 0 },
4383 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4386 int wpa_config_dump_values(struct wpa_config *config, char *buf, size_t buflen)
4391 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
4392 const struct global_parse_data *field = &global_fields[i];
4398 tmp = field->get(field->name, config, (long) field->param1,
4410 int wpa_config_get_value(const char *name, struct wpa_config *config,
4411 char *buf, size_t buflen)
4415 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
4416 const struct global_parse_data *field = &global_fields[i];
4418 if (os_strcmp(name, field->name) != 0)
4422 return field->get(name, config, (long) field->param1,
4430 int wpa_config_get_num_global_field_names(void)
4432 return NUM_GLOBAL_FIELDS;
4436 const char * wpa_config_get_global_field_name(unsigned int i, int *no_var)
4438 if (i >= NUM_GLOBAL_FIELDS)
4442 *no_var = !global_fields[i].param1;
4443 return global_fields[i].name;
4447 int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
4452 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
4453 const struct global_parse_data *field = &global_fields[i];
4454 size_t flen = os_strlen(field->name);
4455 if (os_strncmp(pos, field->name, flen) != 0 ||
4459 if (field->parser(field, config, line, pos + flen + 1)) {
4460 wpa_printf(MSG_ERROR, "Line %d: failed to "
4461 "parse '%s'.", line, pos);
4464 if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN)
4465 config->wps_nfc_pw_from_config = 1;
4466 config->changed_parameters |= field->changed_flag;
4469 if (i == NUM_GLOBAL_FIELDS) {
4471 if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
4472 char *tmp = os_strchr(pos, '=');
4476 wpa_printf(MSG_ERROR, "Line %d: invalid line "
4481 if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
4483 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
4488 #endif /* CONFIG_AP */
4491 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",