2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2019, 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 "common/ieee802_1x_defs.h"
15 #include "common/sae.h"
16 #include "crypto/sha1.h"
17 #include "rsn_supp/wpa.h"
18 #include "eap_peer/eap.h"
24 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
25 #define NO_CONFIG_WRITE
29 * Structure for network configuration parsing. This data is used to implement
30 * a generic parser for each network block variable. The table of configuration
31 * variables is defined below in this file (ssid_fields[]).
34 /* Configuration variable name */
37 /* Parser function for this variable. The parser functions return 0 or 1
38 * to indicate success. Value 0 indicates that the parameter value may
39 * have changed while value 1 means that the value did not change.
40 * Error cases (failure to parse the string) are indicated by returning
42 int (*parser
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
,
43 int line
, const char *value
);
45 #ifndef NO_CONFIG_WRITE
46 /* Writer function (i.e., to get the variable in text format from
47 * internal presentation). */
48 char * (*writer
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
);
49 #endif /* NO_CONFIG_WRITE */
51 /* Variable specific parameters for the parser. */
52 void *param1
, *param2
, *param3
, *param4
;
54 /* 0 = this variable can be included in debug output and ctrl_iface
55 * 1 = this variable contains key/private data and it must not be
56 * included in debug output unless explicitly requested. In
57 * addition, this variable will not be readable through the
64 static int wpa_config_parse_str(const struct parse_data
*data
,
65 struct wpa_ssid
*ssid
,
66 int line
, const char *value
)
68 size_t res_len
, *dst_len
, prev_len
;
71 if (os_strcmp(value
, "NULL") == 0) {
72 wpa_printf(MSG_DEBUG
, "Unset configuration string '%s'",
79 tmp
= wpa_config_parse_string(value
, &res_len
);
81 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s '%s'.",
83 data
->key_data
? "[KEY DATA REMOVED]" : value
);
88 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
91 wpa_hexdump_ascii(MSG_MSGDUMP
, data
->name
,
95 if (data
->param3
&& res_len
< (size_t) data
->param3
) {
96 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
97 "min_len=%ld)", line
, data
->name
,
98 (unsigned long) res_len
, (long) data
->param3
);
103 if (data
->param4
&& res_len
> (size_t) data
->param4
) {
104 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
105 "max_len=%ld)", line
, data
->name
,
106 (unsigned long) res_len
, (long) data
->param4
);
112 dst
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
113 dst_len
= (size_t *) (((u8
*) ssid
) + (long) data
->param2
);
118 prev_len
= os_strlen(*dst
);
121 if ((*dst
== NULL
&& tmp
== NULL
) ||
122 (*dst
&& tmp
&& prev_len
== res_len
&&
123 os_memcmp(*dst
, tmp
, res_len
) == 0)) {
124 /* No change to the previously configured value */
138 #ifndef NO_CONFIG_WRITE
139 static char * wpa_config_write_string_ascii(const u8
*value
, size_t len
)
143 buf
= os_malloc(len
+ 3);
147 os_memcpy(buf
+ 1, value
, len
);
155 static char * wpa_config_write_string_hex(const u8
*value
, size_t len
)
159 buf
= os_zalloc(2 * len
+ 1);
162 wpa_snprintf_hex(buf
, 2 * len
+ 1, value
, len
);
168 static char * wpa_config_write_string(const u8
*value
, size_t len
)
173 if (is_hex(value
, len
))
174 return wpa_config_write_string_hex(value
, len
);
176 return wpa_config_write_string_ascii(value
, len
);
180 static char * wpa_config_write_str(const struct parse_data
*data
,
181 struct wpa_ssid
*ssid
)
186 src
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
191 len
= *((size_t *) (((u8
*) ssid
) + (long) data
->param2
));
193 len
= os_strlen(*src
);
195 return wpa_config_write_string((const u8
*) *src
, len
);
197 #endif /* NO_CONFIG_WRITE */
200 static int wpa_config_parse_int(const struct parse_data
*data
,
201 struct wpa_ssid
*ssid
,
202 int line
, const char *value
)
207 dst
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
208 val
= strtol(value
, &end
, 0);
210 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
218 wpa_printf(MSG_MSGDUMP
, "%s=%d (0x%x)", data
->name
, *dst
, *dst
);
220 if (data
->param3
&& *dst
< (long) data
->param3
) {
221 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
222 "min_value=%ld)", line
, data
->name
, *dst
,
223 (long) data
->param3
);
224 *dst
= (long) data
->param3
;
228 if (data
->param4
&& *dst
> (long) data
->param4
) {
229 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
230 "max_value=%ld)", line
, data
->name
, *dst
,
231 (long) data
->param4
);
232 *dst
= (long) data
->param4
;
240 #ifndef NO_CONFIG_WRITE
241 static char * wpa_config_write_int(const struct parse_data
*data
,
242 struct wpa_ssid
*ssid
)
247 src
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
249 value
= os_malloc(20);
252 res
= os_snprintf(value
, 20, "%d", *src
);
253 if (os_snprintf_error(20, res
)) {
257 value
[20 - 1] = '\0';
260 #endif /* NO_CONFIG_WRITE */
263 static int wpa_config_parse_addr_list(const struct parse_data
*data
,
264 int line
, const char *value
,
265 u8
**list
, size_t *num
, char *name
,
266 u8 abort_on_error
, u8 masked
)
269 u8
*buf
, *n
, addr
[2 * ETH_ALEN
];
276 while (pos
&& *pos
) {
280 if (hwaddr_masked_aton(pos
, addr
, &addr
[ETH_ALEN
], masked
)) {
281 if (abort_on_error
|| count
== 0) {
282 wpa_printf(MSG_ERROR
,
283 "Line %d: Invalid %s address '%s'",
288 /* continue anyway since this could have been from a
289 * truncated configuration file line */
291 "Line %d: Ignore likely truncated %s address '%s'",
294 n
= os_realloc_array(buf
, count
+ 1, 2 * ETH_ALEN
);
300 os_memmove(buf
+ 2 * ETH_ALEN
, buf
,
301 count
* 2 * ETH_ALEN
);
302 os_memcpy(buf
, addr
, 2 * ETH_ALEN
);
304 wpa_printf(MSG_MSGDUMP
,
305 "%s: addr=" MACSTR
" mask=" MACSTR
,
307 MAC2STR(&addr
[ETH_ALEN
]));
310 pos
= os_strchr(pos
, ' ');
321 #ifndef NO_CONFIG_WRITE
322 static char * wpa_config_write_addr_list(const struct parse_data
*data
,
323 const u8
*list
, size_t num
, char *name
)
325 char *value
, *end
, *pos
;
329 if (list
== NULL
|| num
== 0)
332 value
= os_malloc(2 * 20 * num
);
336 end
= value
+ 2 * 20 * num
;
338 for (i
= num
; i
> 0; i
--) {
339 const u8
*a
= list
+ (i
- 1) * 2 * ETH_ALEN
;
340 const u8
*m
= a
+ ETH_ALEN
;
344 res
= hwaddr_mask_txt(pos
, end
- pos
, a
, m
);
354 #endif /* NO_CONFIG_WRITE */
356 static int wpa_config_parse_bssid(const struct parse_data
*data
,
357 struct wpa_ssid
*ssid
, int line
,
360 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
361 os_strcmp(value
, "any") == 0) {
363 wpa_printf(MSG_MSGDUMP
, "BSSID any");
366 if (hwaddr_aton(value
, ssid
->bssid
)) {
367 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID '%s'.",
372 wpa_hexdump(MSG_MSGDUMP
, "BSSID", ssid
->bssid
, ETH_ALEN
);
377 #ifndef NO_CONFIG_WRITE
378 static char * wpa_config_write_bssid(const struct parse_data
*data
,
379 struct wpa_ssid
*ssid
)
384 if (!ssid
->bssid_set
)
387 value
= os_malloc(20);
390 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid
));
391 if (os_snprintf_error(20, res
)) {
395 value
[20 - 1] = '\0';
398 #endif /* NO_CONFIG_WRITE */
401 static int wpa_config_parse_bssid_hint(const struct parse_data
*data
,
402 struct wpa_ssid
*ssid
, int line
,
405 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
406 os_strcmp(value
, "any") == 0) {
407 ssid
->bssid_hint_set
= 0;
408 wpa_printf(MSG_MSGDUMP
, "BSSID hint any");
411 if (hwaddr_aton(value
, ssid
->bssid_hint
)) {
412 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID hint '%s'.",
416 ssid
->bssid_hint_set
= 1;
417 wpa_hexdump(MSG_MSGDUMP
, "BSSID hint", ssid
->bssid_hint
, ETH_ALEN
);
422 #ifndef NO_CONFIG_WRITE
423 static char * wpa_config_write_bssid_hint(const struct parse_data
*data
,
424 struct wpa_ssid
*ssid
)
429 if (!ssid
->bssid_hint_set
)
432 value
= os_malloc(20);
435 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid_hint
));
436 if (os_snprintf_error(20, res
)) {
442 #endif /* NO_CONFIG_WRITE */
445 static int wpa_config_parse_bssid_blacklist(const struct parse_data
*data
,
446 struct wpa_ssid
*ssid
, int line
,
449 return wpa_config_parse_addr_list(data
, line
, value
,
450 &ssid
->bssid_blacklist
,
451 &ssid
->num_bssid_blacklist
,
452 "bssid_blacklist", 1, 1);
456 #ifndef NO_CONFIG_WRITE
457 static char * wpa_config_write_bssid_blacklist(const struct parse_data
*data
,
458 struct wpa_ssid
*ssid
)
460 return wpa_config_write_addr_list(data
, ssid
->bssid_blacklist
,
461 ssid
->num_bssid_blacklist
,
464 #endif /* NO_CONFIG_WRITE */
467 static int wpa_config_parse_bssid_whitelist(const struct parse_data
*data
,
468 struct wpa_ssid
*ssid
, int line
,
471 return wpa_config_parse_addr_list(data
, line
, value
,
472 &ssid
->bssid_whitelist
,
473 &ssid
->num_bssid_whitelist
,
474 "bssid_whitelist", 1, 1);
478 #ifndef NO_CONFIG_WRITE
479 static char * wpa_config_write_bssid_whitelist(const struct parse_data
*data
,
480 struct wpa_ssid
*ssid
)
482 return wpa_config_write_addr_list(data
, ssid
->bssid_whitelist
,
483 ssid
->num_bssid_whitelist
,
486 #endif /* NO_CONFIG_WRITE */
489 static int wpa_config_parse_psk(const struct parse_data
*data
,
490 struct wpa_ssid
*ssid
, int line
,
493 #ifdef CONFIG_EXT_PASSWORD
494 if (os_strncmp(value
, "ext:", 4) == 0) {
495 str_clear_free(ssid
->passphrase
);
496 ssid
->passphrase
= NULL
;
498 os_free(ssid
->ext_psk
);
499 ssid
->ext_psk
= os_strdup(value
+ 4);
500 if (ssid
->ext_psk
== NULL
)
502 wpa_printf(MSG_DEBUG
, "PSK: External password '%s'",
506 #endif /* CONFIG_EXT_PASSWORD */
509 #ifndef CONFIG_NO_PBKDF2
514 pos
= os_strrchr(value
, '"');
518 len
= os_strlen(value
);
519 if (len
< 8 || len
> 63) {
520 wpa_printf(MSG_ERROR
, "Line %d: Invalid passphrase "
521 "length %lu (expected: 8..63) '%s'.",
522 line
, (unsigned long) len
, value
);
525 wpa_hexdump_ascii_key(MSG_MSGDUMP
, "PSK (ASCII passphrase)",
527 if (has_ctrl_char((u8
*) value
, len
)) {
528 wpa_printf(MSG_ERROR
,
529 "Line %d: Invalid passphrase character",
533 if (ssid
->passphrase
&& os_strlen(ssid
->passphrase
) == len
&&
534 os_memcmp(ssid
->passphrase
, value
, len
) == 0) {
535 /* No change to the previously configured value */
539 str_clear_free(ssid
->passphrase
);
540 ssid
->passphrase
= dup_binstr(value
, len
);
541 if (ssid
->passphrase
== NULL
)
544 #else /* CONFIG_NO_PBKDF2 */
545 wpa_printf(MSG_ERROR
, "Line %d: ASCII passphrase not "
548 #endif /* CONFIG_NO_PBKDF2 */
551 if (hexstr2bin(value
, ssid
->psk
, PMK_LEN
) ||
552 value
[PMK_LEN
* 2] != '\0') {
553 wpa_printf(MSG_ERROR
, "Line %d: Invalid PSK '%s'.",
558 str_clear_free(ssid
->passphrase
);
559 ssid
->passphrase
= NULL
;
562 wpa_hexdump_key(MSG_MSGDUMP
, "PSK", ssid
->psk
, PMK_LEN
);
567 #ifndef NO_CONFIG_WRITE
568 static char * wpa_config_write_psk(const struct parse_data
*data
,
569 struct wpa_ssid
*ssid
)
571 #ifdef CONFIG_EXT_PASSWORD
573 size_t len
= 4 + os_strlen(ssid
->ext_psk
) + 1;
574 char *buf
= os_malloc(len
);
579 res
= os_snprintf(buf
, len
, "ext:%s", ssid
->ext_psk
);
580 if (os_snprintf_error(len
, res
)) {
586 #endif /* CONFIG_EXT_PASSWORD */
588 if (ssid
->passphrase
)
589 return wpa_config_write_string_ascii(
590 (const u8
*) ssid
->passphrase
,
591 os_strlen(ssid
->passphrase
));
594 return wpa_config_write_string_hex(ssid
->psk
, PMK_LEN
);
598 #endif /* NO_CONFIG_WRITE */
601 static int wpa_config_parse_proto(const struct parse_data
*data
,
602 struct wpa_ssid
*ssid
, int line
,
605 int val
= 0, last
, errors
= 0;
606 char *start
, *end
, *buf
;
608 buf
= os_strdup(value
);
613 while (*start
!= '\0') {
614 while (*start
== ' ' || *start
== '\t')
619 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
623 if (os_strcmp(start
, "WPA") == 0)
624 val
|= WPA_PROTO_WPA
;
625 else if (os_strcmp(start
, "RSN") == 0 ||
626 os_strcmp(start
, "WPA2") == 0)
627 val
|= WPA_PROTO_RSN
;
628 else if (os_strcmp(start
, "OSEN") == 0)
629 val
|= WPA_PROTO_OSEN
;
631 wpa_printf(MSG_ERROR
, "Line %d: invalid proto '%s'",
643 wpa_printf(MSG_ERROR
,
644 "Line %d: no proto values configured.", line
);
648 if (!errors
&& ssid
->proto
== val
)
650 wpa_printf(MSG_MSGDUMP
, "proto: 0x%x", val
);
652 return errors
? -1 : 0;
656 #ifndef NO_CONFIG_WRITE
657 static char * wpa_config_write_proto(const struct parse_data
*data
,
658 struct wpa_ssid
*ssid
)
661 char *buf
, *pos
, *end
;
663 pos
= buf
= os_zalloc(20);
668 if (ssid
->proto
& WPA_PROTO_WPA
) {
669 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
670 pos
== buf
? "" : " ");
671 if (os_snprintf_error(end
- pos
, ret
))
676 if (ssid
->proto
& WPA_PROTO_RSN
) {
677 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
678 pos
== buf
? "" : " ");
679 if (os_snprintf_error(end
- pos
, ret
))
684 if (ssid
->proto
& WPA_PROTO_OSEN
) {
685 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
686 pos
== buf
? "" : " ");
687 if (os_snprintf_error(end
- pos
, ret
))
699 #endif /* NO_CONFIG_WRITE */
702 static int wpa_config_parse_key_mgmt(const struct parse_data
*data
,
703 struct wpa_ssid
*ssid
, int line
,
706 int val
= 0, last
, errors
= 0;
707 char *start
, *end
, *buf
;
709 buf
= os_strdup(value
);
714 while (*start
!= '\0') {
715 while (*start
== ' ' || *start
== '\t')
720 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
724 if (os_strcmp(start
, "WPA-PSK") == 0)
725 val
|= WPA_KEY_MGMT_PSK
;
726 else if (os_strcmp(start
, "WPA-EAP") == 0)
727 val
|= WPA_KEY_MGMT_IEEE8021X
;
728 else if (os_strcmp(start
, "IEEE8021X") == 0)
729 val
|= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
730 else if (os_strcmp(start
, "NONE") == 0)
731 val
|= WPA_KEY_MGMT_NONE
;
732 else if (os_strcmp(start
, "WPA-NONE") == 0)
733 val
|= WPA_KEY_MGMT_WPA_NONE
;
734 #ifdef CONFIG_IEEE80211R
735 else if (os_strcmp(start
, "FT-PSK") == 0)
736 val
|= WPA_KEY_MGMT_FT_PSK
;
737 else if (os_strcmp(start
, "FT-EAP") == 0)
738 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
740 else if (os_strcmp(start
, "FT-EAP-SHA384") == 0)
741 val
|= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
742 #endif /* CONFIG_SHA384 */
743 #endif /* CONFIG_IEEE80211R */
744 else if (os_strcmp(start
, "WPA-PSK-SHA256") == 0)
745 val
|= WPA_KEY_MGMT_PSK_SHA256
;
746 else if (os_strcmp(start
, "WPA-EAP-SHA256") == 0)
747 val
|= WPA_KEY_MGMT_IEEE8021X_SHA256
;
749 else if (os_strcmp(start
, "WPS") == 0)
750 val
|= WPA_KEY_MGMT_WPS
;
751 #endif /* CONFIG_WPS */
753 else if (os_strcmp(start
, "SAE") == 0)
754 val
|= WPA_KEY_MGMT_SAE
;
755 else if (os_strcmp(start
, "FT-SAE") == 0)
756 val
|= WPA_KEY_MGMT_FT_SAE
;
757 #endif /* CONFIG_SAE */
759 else if (os_strcmp(start
, "OSEN") == 0)
760 val
|= WPA_KEY_MGMT_OSEN
;
761 #endif /* CONFIG_HS20 */
763 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
764 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
765 #endif /* CONFIG_SUITEB */
766 #ifdef CONFIG_SUITEB192
767 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
768 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
769 #endif /* CONFIG_SUITEB192 */
771 else if (os_strcmp(start
, "FILS-SHA256") == 0)
772 val
|= WPA_KEY_MGMT_FILS_SHA256
;
773 else if (os_strcmp(start
, "FILS-SHA384") == 0)
774 val
|= WPA_KEY_MGMT_FILS_SHA384
;
775 #ifdef CONFIG_IEEE80211R
776 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
777 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
778 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
779 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
780 #endif /* CONFIG_IEEE80211R */
781 #endif /* CONFIG_FILS */
783 else if (os_strcmp(start
, "OWE") == 0)
784 val
|= WPA_KEY_MGMT_OWE
;
785 #endif /* CONFIG_OWE */
787 else if (os_strcmp(start
, "DPP") == 0)
788 val
|= WPA_KEY_MGMT_DPP
;
789 #endif /* CONFIG_DPP */
791 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
803 wpa_printf(MSG_ERROR
,
804 "Line %d: no key_mgmt values configured.", line
);
808 if (!errors
&& ssid
->key_mgmt
== val
)
810 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
811 ssid
->key_mgmt
= val
;
812 return errors
? -1 : 0;
816 #ifndef NO_CONFIG_WRITE
817 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
818 struct wpa_ssid
*ssid
)
820 char *buf
, *pos
, *end
;
823 pos
= buf
= os_zalloc(100);
828 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
829 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
830 pos
== buf
? "" : " ");
831 if (os_snprintf_error(end
- pos
, ret
)) {
838 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
839 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
840 pos
== buf
? "" : " ");
841 if (os_snprintf_error(end
- pos
, ret
)) {
848 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
849 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
850 pos
== buf
? "" : " ");
851 if (os_snprintf_error(end
- pos
, ret
)) {
858 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
859 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
860 pos
== buf
? "" : " ");
861 if (os_snprintf_error(end
- pos
, ret
)) {
868 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
869 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
870 pos
== buf
? "" : " ");
871 if (os_snprintf_error(end
- pos
, ret
)) {
878 #ifdef CONFIG_IEEE80211R
879 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
880 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
881 pos
== buf
? "" : " ");
882 if (os_snprintf_error(end
- pos
, ret
)) {
889 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
890 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
891 pos
== buf
? "" : " ");
892 if (os_snprintf_error(end
- pos
, ret
)) {
900 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
901 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP-SHA384",
902 pos
== buf
? "" : " ");
903 if (os_snprintf_error(end
- pos
, ret
)) {
909 #endif /* CONFIG_SHA384 */
910 #endif /* CONFIG_IEEE80211R */
912 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
913 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
914 pos
== buf
? "" : " ");
915 if (os_snprintf_error(end
- pos
, ret
)) {
922 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
923 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
924 pos
== buf
? "" : " ");
925 if (os_snprintf_error(end
- pos
, ret
)) {
933 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
934 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
935 pos
== buf
? "" : " ");
936 if (os_snprintf_error(end
- pos
, ret
)) {
942 #endif /* CONFIG_WPS */
945 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
946 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
947 pos
== buf
? "" : " ");
948 if (os_snprintf_error(end
- pos
, ret
)) {
955 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
956 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
957 pos
== buf
? "" : " ");
958 if (os_snprintf_error(end
- pos
, ret
)) {
964 #endif /* CONFIG_SAE */
967 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
968 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
969 pos
== buf
? "" : " ");
970 if (os_snprintf_error(end
- pos
, ret
)) {
976 #endif /* CONFIG_HS20 */
979 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
980 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
981 pos
== buf
? "" : " ");
982 if (os_snprintf_error(end
- pos
, ret
)) {
988 #endif /* CONFIG_SUITEB */
990 #ifdef CONFIG_SUITEB192
991 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
992 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
993 pos
== buf
? "" : " ");
994 if (os_snprintf_error(end
- pos
, ret
)) {
1000 #endif /* CONFIG_SUITEB192 */
1003 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1004 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
1005 pos
== buf
? "" : " ");
1006 if (os_snprintf_error(end
- pos
, ret
)) {
1012 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1013 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
1014 pos
== buf
? "" : " ");
1015 if (os_snprintf_error(end
- pos
, ret
)) {
1021 #ifdef CONFIG_IEEE80211R
1022 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1023 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
1024 pos
== buf
? "" : " ");
1025 if (os_snprintf_error(end
- pos
, ret
)) {
1031 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1032 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
1033 pos
== buf
? "" : " ");
1034 if (os_snprintf_error(end
- pos
, ret
)) {
1040 #endif /* CONFIG_IEEE80211R */
1041 #endif /* CONFIG_FILS */
1044 if (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) {
1045 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
1046 pos
== buf
? "" : " ");
1047 if (os_snprintf_error(end
- pos
, ret
)) {
1053 #endif /* CONFIG_DPP */
1056 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) {
1057 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
1058 pos
== buf
? "" : " ");
1059 if (os_snprintf_error(end
- pos
, ret
)) {
1065 #endif /* CONFIG_OWE */
1074 #endif /* NO_CONFIG_WRITE */
1077 static int wpa_config_parse_cipher(int line
, const char *value
)
1079 #ifdef CONFIG_NO_WPA
1081 #else /* CONFIG_NO_WPA */
1082 int val
= wpa_parse_cipher(value
);
1084 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1089 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1094 #endif /* CONFIG_NO_WPA */
1098 #ifndef NO_CONFIG_WRITE
1099 static char * wpa_config_write_cipher(int cipher
)
1101 #ifdef CONFIG_NO_WPA
1103 #else /* CONFIG_NO_WPA */
1104 char *buf
= os_zalloc(50);
1108 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1114 #endif /* CONFIG_NO_WPA */
1116 #endif /* NO_CONFIG_WRITE */
1119 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1120 struct wpa_ssid
*ssid
, int line
,
1124 val
= wpa_config_parse_cipher(line
, value
);
1127 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1128 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1129 "(0x%x).", line
, val
);
1133 if (ssid
->pairwise_cipher
== val
)
1135 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1136 ssid
->pairwise_cipher
= val
;
1141 #ifndef NO_CONFIG_WRITE
1142 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1143 struct wpa_ssid
*ssid
)
1145 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1147 #endif /* NO_CONFIG_WRITE */
1150 static int wpa_config_parse_group(const struct parse_data
*data
,
1151 struct wpa_ssid
*ssid
, int line
,
1155 val
= wpa_config_parse_cipher(line
, value
);
1160 * Backwards compatibility - filter out WEP ciphers that were previously
1163 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1165 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1166 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1167 "(0x%x).", line
, val
);
1171 if (ssid
->group_cipher
== val
)
1173 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1174 ssid
->group_cipher
= val
;
1179 #ifndef NO_CONFIG_WRITE
1180 static char * wpa_config_write_group(const struct parse_data
*data
,
1181 struct wpa_ssid
*ssid
)
1183 return wpa_config_write_cipher(ssid
->group_cipher
);
1185 #endif /* NO_CONFIG_WRITE */
1188 static int wpa_config_parse_group_mgmt(const struct parse_data
*data
,
1189 struct wpa_ssid
*ssid
, int line
,
1194 val
= wpa_config_parse_cipher(line
, value
);
1198 if (val
& ~WPA_ALLOWED_GROUP_MGMT_CIPHERS
) {
1199 wpa_printf(MSG_ERROR
,
1200 "Line %d: not allowed group management cipher (0x%x).",
1205 if (ssid
->group_mgmt_cipher
== val
)
1207 wpa_printf(MSG_MSGDUMP
, "group_mgmt: 0x%x", val
);
1208 ssid
->group_mgmt_cipher
= val
;
1213 #ifndef NO_CONFIG_WRITE
1214 static char * wpa_config_write_group_mgmt(const struct parse_data
*data
,
1215 struct wpa_ssid
*ssid
)
1217 return wpa_config_write_cipher(ssid
->group_mgmt_cipher
);
1219 #endif /* NO_CONFIG_WRITE */
1222 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1223 struct wpa_ssid
*ssid
, int line
,
1226 int val
= 0, last
, errors
= 0;
1227 char *start
, *end
, *buf
;
1229 buf
= os_strdup(value
);
1234 while (*start
!= '\0') {
1235 while (*start
== ' ' || *start
== '\t')
1240 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1242 last
= *end
== '\0';
1244 if (os_strcmp(start
, "OPEN") == 0)
1245 val
|= WPA_AUTH_ALG_OPEN
;
1246 else if (os_strcmp(start
, "SHARED") == 0)
1247 val
|= WPA_AUTH_ALG_SHARED
;
1248 else if (os_strcmp(start
, "LEAP") == 0)
1249 val
|= WPA_AUTH_ALG_LEAP
;
1251 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1263 wpa_printf(MSG_ERROR
,
1264 "Line %d: no auth_alg values configured.", line
);
1268 if (!errors
&& ssid
->auth_alg
== val
)
1270 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1271 ssid
->auth_alg
= val
;
1272 return errors
? -1 : 0;
1276 #ifndef NO_CONFIG_WRITE
1277 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1278 struct wpa_ssid
*ssid
)
1280 char *buf
, *pos
, *end
;
1283 pos
= buf
= os_zalloc(30);
1288 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1289 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1290 pos
== buf
? "" : " ");
1291 if (os_snprintf_error(end
- pos
, ret
)) {
1298 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1299 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1300 pos
== buf
? "" : " ");
1301 if (os_snprintf_error(end
- pos
, ret
)) {
1308 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1309 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1310 pos
== buf
? "" : " ");
1311 if (os_snprintf_error(end
- pos
, ret
)) {
1325 #endif /* NO_CONFIG_WRITE */
1328 static int * wpa_config_parse_int_array(const char *value
)
1336 freqs
= os_calloc(len
+ 1, sizeof(int));
1347 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1352 for (i
= len
; i
<= len
* 2; i
++)
1358 freqs
[used
] = atoi(pos
);
1359 if (freqs
[used
] == 0)
1362 pos
= os_strchr(pos
+ 1, ' ');
1369 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1370 struct wpa_ssid
*ssid
, int line
,
1375 freqs
= wpa_config_parse_int_array(value
);
1378 if (freqs
[0] == 0) {
1382 os_free(ssid
->scan_freq
);
1383 ssid
->scan_freq
= freqs
;
1389 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1390 struct wpa_ssid
*ssid
, int line
,
1395 freqs
= wpa_config_parse_int_array(value
);
1398 if (freqs
[0] == 0) {
1402 os_free(ssid
->freq_list
);
1403 ssid
->freq_list
= freqs
;
1409 #ifndef NO_CONFIG_WRITE
1410 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1413 char *buf
, *pos
, *end
;
1421 for (i
= 0; freqs
[i
]; i
++)
1424 pos
= buf
= os_zalloc(10 * count
+ 1);
1427 end
= buf
+ 10 * count
+ 1;
1429 for (i
= 0; freqs
[i
]; i
++) {
1430 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1431 i
== 0 ? "" : " ", freqs
[i
]);
1432 if (os_snprintf_error(end
- pos
, ret
)) {
1443 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1444 struct wpa_ssid
*ssid
)
1446 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1450 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1451 struct wpa_ssid
*ssid
)
1453 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1455 #endif /* NO_CONFIG_WRITE */
1458 #ifdef IEEE8021X_EAPOL
1459 static int wpa_config_parse_eap(const struct parse_data
*data
,
1460 struct wpa_ssid
*ssid
, int line
,
1463 int last
, errors
= 0;
1464 char *start
, *end
, *buf
;
1465 struct eap_method_type
*methods
= NULL
, *tmp
;
1466 size_t num_methods
= 0;
1468 buf
= os_strdup(value
);
1473 while (*start
!= '\0') {
1474 while (*start
== ' ' || *start
== '\t')
1479 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1481 last
= *end
== '\0';
1484 methods
= os_realloc_array(methods
, num_methods
+ 1,
1486 if (methods
== NULL
) {
1491 methods
[num_methods
].method
= eap_peer_get_type(
1492 start
, &methods
[num_methods
].vendor
);
1493 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1494 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1495 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1496 "'%s'", line
, start
);
1497 wpa_printf(MSG_ERROR
, "You may need to add support for"
1498 " this EAP method during wpa_supplicant\n"
1499 "build time configuration.\n"
1500 "See README for more information.");
1502 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1503 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1515 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1516 if (methods
== NULL
) {
1520 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1521 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1524 if (!errors
&& ssid
->eap
.eap_methods
) {
1525 struct eap_method_type
*prev_m
;
1526 size_t i
, j
, prev_methods
, match
= 0;
1528 prev_m
= ssid
->eap
.eap_methods
;
1529 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1530 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1531 /* Count the methods */
1533 prev_methods
= i
+ 1;
1535 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1537 for (j
= 0; j
< num_methods
; j
++) {
1538 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1539 prev_m
[i
].method
== methods
[j
].method
) {
1545 if (match
== num_methods
) {
1550 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1551 (u8
*) methods
, num_methods
* sizeof(*methods
));
1552 os_free(ssid
->eap
.eap_methods
);
1553 ssid
->eap
.eap_methods
= methods
;
1554 return errors
? -1 : 0;
1558 #ifndef NO_CONFIG_WRITE
1559 static char * wpa_config_write_eap(const struct parse_data
*data
,
1560 struct wpa_ssid
*ssid
)
1563 char *buf
, *pos
, *end
;
1564 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1567 if (eap_methods
== NULL
)
1570 pos
= buf
= os_zalloc(100);
1575 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1576 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1577 name
= eap_get_name(eap_methods
[i
].vendor
,
1578 eap_methods
[i
].method
);
1580 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1581 pos
== buf
? "" : " ", name
);
1582 if (os_snprintf_error(end
- pos
, ret
))
1592 #endif /* NO_CONFIG_WRITE */
1595 static int wpa_config_parse_password(const struct parse_data
*data
,
1596 struct wpa_ssid
*ssid
, int line
,
1601 if (os_strcmp(value
, "NULL") == 0) {
1602 if (!ssid
->eap
.password
)
1603 return 1; /* Already unset */
1604 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1605 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1606 ssid
->eap
.password
= NULL
;
1607 ssid
->eap
.password_len
= 0;
1611 #ifdef CONFIG_EXT_PASSWORD
1612 if (os_strncmp(value
, "ext:", 4) == 0) {
1613 char *name
= os_strdup(value
+ 4);
1616 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1617 ssid
->eap
.password
= (u8
*) name
;
1618 ssid
->eap
.password_len
= os_strlen(name
);
1619 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1620 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1623 #endif /* CONFIG_EXT_PASSWORD */
1625 if (os_strncmp(value
, "hash:", 5) != 0) {
1629 tmp
= wpa_config_parse_string(value
, &res_len
);
1631 wpa_printf(MSG_ERROR
,
1632 "Line %d: failed to parse password.", line
);
1635 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1636 (u8
*) tmp
, res_len
);
1638 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1639 ssid
->eap
.password
= (u8
*) tmp
;
1640 ssid
->eap
.password_len
= res_len
;
1641 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1642 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1648 /* NtPasswordHash: hash:<32 hex digits> */
1649 if (os_strlen(value
+ 5) != 2 * 16) {
1650 wpa_printf(MSG_ERROR
,
1651 "Line %d: Invalid password hash length (expected 32 hex digits)",
1656 hash
= os_malloc(16);
1660 if (hexstr2bin(value
+ 5, hash
, 16)) {
1662 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1666 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1668 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1669 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1670 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1671 bin_clear_free(hash
, 16);
1674 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1675 ssid
->eap
.password
= hash
;
1676 ssid
->eap
.password_len
= 16;
1677 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1678 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1684 static int wpa_config_parse_machine_password(const struct parse_data
*data
,
1685 struct wpa_ssid
*ssid
, int line
,
1690 if (os_strcmp(value
, "NULL") == 0) {
1691 if (!ssid
->eap
.machine_password
)
1692 return 1; /* Already unset */
1693 wpa_printf(MSG_DEBUG
,
1694 "Unset configuration string 'machine_password'");
1695 bin_clear_free(ssid
->eap
.machine_password
,
1696 ssid
->eap
.machine_password_len
);
1697 ssid
->eap
.machine_password
= NULL
;
1698 ssid
->eap
.machine_password_len
= 0;
1702 #ifdef CONFIG_EXT_PASSWORD
1703 if (os_strncmp(value
, "ext:", 4) == 0) {
1704 char *name
= os_strdup(value
+ 4);
1708 bin_clear_free(ssid
->eap
.machine_password
,
1709 ssid
->eap
.machine_password_len
);
1710 ssid
->eap
.machine_password
= (u8
*) name
;
1711 ssid
->eap
.machine_password_len
= os_strlen(name
);
1712 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1713 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1716 #endif /* CONFIG_EXT_PASSWORD */
1718 if (os_strncmp(value
, "hash:", 5) != 0) {
1722 tmp
= wpa_config_parse_string(value
, &res_len
);
1724 wpa_printf(MSG_ERROR
,
1725 "Line %d: failed to parse machine_password.",
1729 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1730 (u8
*) tmp
, res_len
);
1732 bin_clear_free(ssid
->eap
.machine_password
,
1733 ssid
->eap
.machine_password_len
);
1734 ssid
->eap
.machine_password
= (u8
*) tmp
;
1735 ssid
->eap
.machine_password_len
= res_len
;
1736 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1737 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1743 /* NtPasswordHash: hash:<32 hex digits> */
1744 if (os_strlen(value
+ 5) != 2 * 16) {
1745 wpa_printf(MSG_ERROR
,
1746 "Line %d: Invalid machine_password hash length (expected 32 hex digits)",
1751 hash
= os_malloc(16);
1755 if (hexstr2bin(value
+ 5, hash
, 16)) {
1757 wpa_printf(MSG_ERROR
, "Line %d: Invalid machine_password hash",
1762 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1764 if (ssid
->eap
.machine_password
&&
1765 ssid
->eap
.machine_password_len
== 16 &&
1766 os_memcmp(ssid
->eap
.machine_password
, hash
, 16) == 0 &&
1767 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
)) {
1768 bin_clear_free(hash
, 16);
1771 bin_clear_free(ssid
->eap
.machine_password
,
1772 ssid
->eap
.machine_password_len
);
1773 ssid
->eap
.machine_password
= hash
;
1774 ssid
->eap
.machine_password_len
= 16;
1775 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1776 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1782 #ifndef NO_CONFIG_WRITE
1784 static char * wpa_config_write_password(const struct parse_data
*data
,
1785 struct wpa_ssid
*ssid
)
1789 if (!ssid
->eap
.password
)
1792 #ifdef CONFIG_EXT_PASSWORD
1793 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1794 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1797 os_memcpy(buf
, "ext:", 4);
1798 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1801 #endif /* CONFIG_EXT_PASSWORD */
1803 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1804 return wpa_config_write_string(
1805 ssid
->eap
.password
, ssid
->eap
.password_len
);
1808 buf
= os_malloc(5 + 32 + 1);
1812 os_memcpy(buf
, "hash:", 5);
1813 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1819 static char * wpa_config_write_machine_password(const struct parse_data
*data
,
1820 struct wpa_ssid
*ssid
)
1824 if (!ssid
->eap
.machine_password
)
1827 #ifdef CONFIG_EXT_PASSWORD
1828 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
) {
1829 buf
= os_zalloc(4 + ssid
->eap
.machine_password_len
+ 1);
1832 os_memcpy(buf
, "ext:", 4);
1833 os_memcpy(buf
+ 4, ssid
->eap
.machine_password
,
1834 ssid
->eap
.machine_password_len
);
1837 #endif /* CONFIG_EXT_PASSWORD */
1839 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
)) {
1840 return wpa_config_write_string(
1841 ssid
->eap
.machine_password
,
1842 ssid
->eap
.machine_password_len
);
1845 buf
= os_malloc(5 + 32 + 1);
1849 os_memcpy(buf
, "hash:", 5);
1850 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.machine_password
, 16);
1855 #endif /* NO_CONFIG_WRITE */
1856 #endif /* IEEE8021X_EAPOL */
1861 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1862 const char *value
, int idx
)
1864 char *buf
, title
[20];
1867 buf
= wpa_config_parse_string(value
, len
);
1869 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1873 if (*len
> MAX_WEP_KEY_LEN
) {
1874 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1879 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1880 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1881 "this network block will be ignored",
1882 line
, (unsigned int) *len
);
1884 os_memcpy(key
, buf
, *len
);
1885 str_clear_free(buf
);
1886 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1887 if (!os_snprintf_error(sizeof(title
), res
))
1888 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1893 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1894 struct wpa_ssid
*ssid
, int line
,
1897 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1898 &ssid
->wep_key_len
[0], line
,
1903 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1904 struct wpa_ssid
*ssid
, int line
,
1907 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1908 &ssid
->wep_key_len
[1], line
,
1913 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1914 struct wpa_ssid
*ssid
, int line
,
1917 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1918 &ssid
->wep_key_len
[2], line
,
1923 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1924 struct wpa_ssid
*ssid
, int line
,
1927 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1928 &ssid
->wep_key_len
[3], line
,
1933 #ifndef NO_CONFIG_WRITE
1934 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1936 if (ssid
->wep_key_len
[idx
] == 0)
1938 return wpa_config_write_string(ssid
->wep_key
[idx
],
1939 ssid
->wep_key_len
[idx
]);
1943 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1944 struct wpa_ssid
*ssid
)
1946 return wpa_config_write_wep_key(ssid
, 0);
1950 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1951 struct wpa_ssid
*ssid
)
1953 return wpa_config_write_wep_key(ssid
, 1);
1957 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1958 struct wpa_ssid
*ssid
)
1960 return wpa_config_write_wep_key(ssid
, 2);
1964 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1965 struct wpa_ssid
*ssid
)
1967 return wpa_config_write_wep_key(ssid
, 3);
1969 #endif /* NO_CONFIG_WRITE */
1971 #endif /* CONFIG_WEP */
1976 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1977 struct wpa_ssid
*ssid
, int line
,
1980 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1981 os_strcmp(value
, "any") == 0) {
1982 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1983 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1986 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1987 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1991 ssid
->bssid_set
= 1;
1992 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1993 MAC2STR(ssid
->go_p2p_dev_addr
));
1998 #ifndef NO_CONFIG_WRITE
1999 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
2000 struct wpa_ssid
*ssid
)
2005 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
2008 value
= os_malloc(20);
2011 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
2012 if (os_snprintf_error(20, res
)) {
2016 value
[20 - 1] = '\0';
2019 #endif /* NO_CONFIG_WRITE */
2022 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
2023 struct wpa_ssid
*ssid
, int line
,
2026 return wpa_config_parse_addr_list(data
, line
, value
,
2027 &ssid
->p2p_client_list
,
2028 &ssid
->num_p2p_clients
,
2029 "p2p_client_list", 0, 0);
2033 #ifndef NO_CONFIG_WRITE
2034 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
2035 struct wpa_ssid
*ssid
)
2037 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
2038 ssid
->num_p2p_clients
,
2041 #endif /* NO_CONFIG_WRITE */
2044 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
2045 struct wpa_ssid
*ssid
, int line
,
2048 struct psk_list_entry
*p
;
2051 p
= os_zalloc(sizeof(*p
));
2056 if (os_strncmp(pos
, "P2P-", 4) == 0) {
2061 if (hwaddr_aton(pos
, p
->addr
)) {
2062 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
2069 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
2076 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
2077 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
2083 dl_list_add(&ssid
->psk_list
, &p
->list
);
2089 #ifndef NO_CONFIG_WRITE
2090 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
2091 struct wpa_ssid
*ssid
)
2095 #endif /* NO_CONFIG_WRITE */
2097 #endif /* CONFIG_P2P */
2102 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
2103 struct wpa_ssid
*ssid
, int line
,
2106 int *rates
= wpa_config_parse_int_array(value
);
2108 if (rates
== NULL
) {
2109 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
2113 if (rates
[0] == 0) {
2118 os_free(ssid
->mesh_basic_rates
);
2119 ssid
->mesh_basic_rates
= rates
;
2125 #ifndef NO_CONFIG_WRITE
2127 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
2128 struct wpa_ssid
*ssid
)
2130 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
2133 #endif /* NO_CONFIG_WRITE */
2135 #endif /* CONFIG_MESH */
2138 #ifdef CONFIG_MACSEC
2140 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
2141 struct wpa_ssid
*ssid
, int line
,
2146 len
= os_strlen(value
);
2147 if (len
> 2 * MACSEC_CAK_MAX_LEN
||
2148 (len
!= 2 * 16 && len
!= 2 * 32) ||
2149 hexstr2bin(value
, ssid
->mka_cak
, len
/ 2)) {
2150 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
2154 ssid
->mka_cak_len
= len
/ 2;
2155 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
2157 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
,
2163 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
2164 struct wpa_ssid
*ssid
, int line
,
2169 len
= os_strlen(value
);
2170 if (len
> 2 * MACSEC_CKN_MAX_LEN
|| /* too long */
2171 len
< 2 || /* too short */
2172 len
% 2 != 0 /* not an integral number of bytes */) {
2173 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2177 ssid
->mka_ckn_len
= len
/ 2;
2178 if (hexstr2bin(value
, ssid
->mka_ckn
, ssid
->mka_ckn_len
)) {
2179 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2184 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
2186 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
,
2192 #ifndef NO_CONFIG_WRITE
2194 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
2195 struct wpa_ssid
*ssid
)
2197 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
2200 return wpa_config_write_string_hex(ssid
->mka_cak
, ssid
->mka_cak_len
);
2204 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
2205 struct wpa_ssid
*ssid
)
2207 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
2209 return wpa_config_write_string_hex(ssid
->mka_ckn
, ssid
->mka_ckn_len
);
2212 #endif /* NO_CONFIG_WRITE */
2214 #endif /* CONFIG_MACSEC */
2219 static int wpa_config_parse_ocv(const struct parse_data
*data
,
2220 struct wpa_ssid
*ssid
, int line
,
2225 ssid
->ocv
= strtol(value
, &end
, 0);
2226 if (*end
|| ssid
->ocv
< 0 || ssid
->ocv
> 1) {
2227 wpa_printf(MSG_ERROR
, "Line %d: Invalid ocv value '%s'.",
2231 if (ssid
->ocv
&& ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
)
2232 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_OPTIONAL
;
2237 #ifndef NO_CONFIG_WRITE
2238 static char * wpa_config_write_ocv(const struct parse_data
*data
,
2239 struct wpa_ssid
*ssid
)
2241 char *value
= os_malloc(20);
2245 os_snprintf(value
, 20, "%d", ssid
->ocv
);
2246 value
[20 - 1] = '\0';
2249 #endif /* NO_CONFIG_WRITE */
2251 #endif /* CONFIG_OCV */
2254 static int wpa_config_parse_peerkey(const struct parse_data
*data
,
2255 struct wpa_ssid
*ssid
, int line
,
2258 wpa_printf(MSG_INFO
, "NOTE: Obsolete peerkey parameter ignored");
2263 #ifndef NO_CONFIG_WRITE
2264 static char * wpa_config_write_peerkey(const struct parse_data
*data
,
2265 struct wpa_ssid
*ssid
)
2269 #endif /* NO_CONFIG_WRITE */
2272 /* Helper macros for network block parser */
2277 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
2278 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
2280 /* STR: Define a string variable for an ASCII string; f = field name */
2281 #ifdef NO_CONFIG_WRITE
2282 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
2283 #define _STRe(f, m) #f, wpa_config_parse_str, OFFSET(eap.m)
2284 #else /* NO_CONFIG_WRITE */
2285 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
2286 #define _STRe(f, m) #f, wpa_config_parse_str, wpa_config_write_str, \
2288 #endif /* NO_CONFIG_WRITE */
2289 #define STR(f) _STR(f), NULL, NULL, NULL, 0
2290 #define STRe(f, m) _STRe(f, m), NULL, NULL, NULL, 0
2291 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
2292 #define STR_KEYe(f, m) _STRe(f, m), NULL, NULL, NULL, 1
2294 /* STR_LEN: Define a string variable with a separate variable for storing the
2295 * data length. Unlike STR(), this can be used to store arbitrary binary data
2296 * (i.e., even nul termination character). */
2297 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
2298 #define _STR_LENe(f, m) _STRe(f, m), OFFSET(eap.m ## _len)
2299 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
2300 #define STR_LENe(f, m) _STR_LENe(f, m), NULL, NULL, 0
2301 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
2303 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
2304 * explicitly specified. */
2305 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
2306 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
2307 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
2309 #ifdef NO_CONFIG_WRITE
2310 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
2311 #define _INTe(f, m) #f, wpa_config_parse_int, OFFSET(eap.m), (void *) 0
2312 #else /* NO_CONFIG_WRITE */
2313 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2314 OFFSET(f), (void *) 0
2315 #define _INTe(f, m) #f, wpa_config_parse_int, wpa_config_write_int, \
2316 OFFSET(eap.m), (void *) 0
2317 #endif /* NO_CONFIG_WRITE */
2319 /* INT: Define an integer variable */
2320 #define INT(f) _INT(f), NULL, NULL, 0
2321 #define INTe(f, m) _INTe(f, m), NULL, NULL, 0
2323 /* INT_RANGE: Define an integer variable with allowed value range */
2324 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
2326 /* FUNC: Define a configuration variable that uses a custom function for
2327 * parsing and writing the value. */
2328 #ifdef NO_CONFIG_WRITE
2329 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
2330 #else /* NO_CONFIG_WRITE */
2331 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
2332 NULL, NULL, NULL, NULL
2333 #endif /* NO_CONFIG_WRITE */
2334 #define FUNC(f) _FUNC(f), 0
2335 #define FUNC_KEY(f) _FUNC(f), 1
2338 * Table of network configuration variables. This table is used to parse each
2339 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2340 * that is inside a network block.
2342 * This table is generated using the helper macros defined above and with
2343 * generous help from the C pre-processor. The field name is stored as a string
2344 * into .name and for STR and INT types, the offset of the target buffer within
2345 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2346 * offset to the field containing the length of the configuration variable.
2347 * .param3 and .param4 can be used to mark the allowed range (length for STR
2348 * and value for INT).
2350 * For each configuration line in wpa_supplicant.conf, the parser goes through
2351 * this table and select the entry that matches with the field name. The parser
2352 * function (.parser) is then called to parse the actual value of the field.
2354 * This kind of mechanism makes it easy to add new configuration parameters,
2355 * since only one line needs to be added into this table and into the
2356 * struct wpa_ssid definition if the new variable is either a string or
2357 * integer. More complex types will need to use their own parser and writer
2360 static const struct parse_data ssid_fields
[] = {
2361 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2362 { INT_RANGE(scan_ssid
, 0, 1) },
2364 { FUNC(bssid_hint
) },
2365 { FUNC(bssid_blacklist
) },
2366 { FUNC(bssid_whitelist
) },
2368 { INT(mem_only_psk
) },
2369 { STR_KEY(sae_password
) },
2370 { STR(sae_password_id
) },
2373 { INT(bg_scan_period
) },
2376 { FUNC(group_mgmt
) },
2378 { FUNC(scan_freq
) },
2379 { FUNC(freq_list
) },
2380 { INT_RANGE(ht
, 0, 1) },
2381 { INT_RANGE(vht
, 0, 1) },
2382 { INT_RANGE(ht40
, -1, 1) },
2383 { INT_RANGE(max_oper_chwidth
, CHANWIDTH_USE_HT
,
2384 CHANWIDTH_80P80MHZ
) },
2385 { INT(vht_center_freq1
) },
2386 { INT(vht_center_freq2
) },
2387 #ifdef IEEE8021X_EAPOL
2389 { STR_LENe(identity
, identity
) },
2390 { STR_LENe(anonymous_identity
, anonymous_identity
) },
2391 { STR_LENe(imsi_identity
, imsi_identity
) },
2392 { STR_LENe(machine_identity
, machine_identity
) },
2393 { FUNC_KEY(password
) },
2394 { FUNC_KEY(machine_password
) },
2395 { STRe(ca_cert
, cert
.ca_cert
) },
2396 { STRe(ca_path
, cert
.ca_path
) },
2397 { STRe(client_cert
, cert
.client_cert
) },
2398 { STRe(private_key
, cert
.private_key
) },
2399 { STR_KEYe(private_key_passwd
, cert
.private_key_passwd
) },
2400 { STRe(dh_file
, cert
.dh_file
) },
2401 { STRe(subject_match
, cert
.subject_match
) },
2402 { STRe(check_cert_subject
, cert
.check_cert_subject
) },
2403 { STRe(altsubject_match
, cert
.altsubject_match
) },
2404 { STRe(domain_suffix_match
, cert
.domain_suffix_match
) },
2405 { STRe(domain_match
, cert
.domain_match
) },
2406 { STRe(ca_cert2
, phase2_cert
.ca_cert
) },
2407 { STRe(ca_path2
, phase2_cert
.ca_path
) },
2408 { STRe(client_cert2
, phase2_cert
.client_cert
) },
2409 { STRe(private_key2
, phase2_cert
.private_key
) },
2410 { STR_KEYe(private_key2_passwd
, phase2_cert
.private_key_passwd
) },
2411 { STRe(dh_file2
, phase2_cert
.dh_file
) },
2412 { STRe(subject_match2
, phase2_cert
.subject_match
) },
2413 { STRe(check_cert_subject2
, phase2_cert
.check_cert_subject
) },
2414 { STRe(altsubject_match2
, phase2_cert
.altsubject_match
) },
2415 { STRe(domain_suffix_match2
, phase2_cert
.domain_suffix_match
) },
2416 { STRe(domain_match2
, phase2_cert
.domain_match
) },
2417 { STRe(phase1
, phase1
) },
2418 { STRe(phase2
, phase2
) },
2419 { STRe(machine_phase2
, machine_phase2
) },
2420 { STRe(pcsc
, pcsc
) },
2421 { STR_KEYe(pin
, cert
.pin
) },
2422 { STRe(engine_id
, cert
.engine_id
) },
2423 { STRe(key_id
, cert
.key_id
) },
2424 { STRe(cert_id
, cert
.cert_id
) },
2425 { STRe(ca_cert_id
, cert
.ca_cert_id
) },
2426 { STR_KEYe(pin2
, phase2_cert
.pin
) },
2427 { STRe(engine_id2
, phase2_cert
.engine_id
) },
2428 { STRe(key_id2
, phase2_cert
.key_id
) },
2429 { STRe(cert_id2
, phase2_cert
.cert_id
) },
2430 { STRe(ca_cert_id2
, phase2_cert
.ca_cert_id
) },
2431 { INTe(engine
, cert
.engine
) },
2432 { INTe(engine2
, phase2_cert
.engine
) },
2433 { STRe(machine_ca_cert
, machine_cert
.ca_cert
) },
2434 { STRe(machine_ca_path
, machine_cert
.ca_path
) },
2435 { STRe(machine_client_cert
, machine_cert
.client_cert
) },
2436 { STRe(machine_private_key
, machine_cert
.private_key
) },
2437 { STR_KEYe(machine_private_key_passwd
,
2438 machine_cert
.private_key_passwd
) },
2439 { STRe(machine_dh_file
, machine_cert
.dh_file
) },
2440 { STRe(machine_subject_match
, machine_cert
.subject_match
) },
2441 { STRe(machine_check_cert_subject
, machine_cert
.check_cert_subject
) },
2442 { STRe(machine_altsubject_match
, machine_cert
.altsubject_match
) },
2443 { STRe(machine_domain_suffix_match
,
2444 machine_cert
.domain_suffix_match
) },
2445 { STRe(machine_domain_match
, machine_cert
.domain_match
) },
2446 { STR_KEYe(machine_pin
, machine_cert
.pin
) },
2447 { STRe(machine_engine_id
, machine_cert
.engine_id
) },
2448 { STRe(machine_key_id
, machine_cert
.key_id
) },
2449 { STRe(machine_cert_id
, machine_cert
.cert_id
) },
2450 { STRe(machine_ca_cert_id
, machine_cert
.ca_cert_id
) },
2451 { INTe(machine_engine
, machine_cert
.engine
) },
2452 { INTe(machine_ocsp
, machine_cert
.ocsp
) },
2453 { INT(eapol_flags
) },
2454 { INTe(sim_num
, sim_num
) },
2455 { STRe(openssl_ciphers
, openssl_ciphers
) },
2457 #endif /* IEEE8021X_EAPOL */
2459 { FUNC_KEY(wep_key0
) },
2460 { FUNC_KEY(wep_key1
) },
2461 { FUNC_KEY(wep_key2
) },
2462 { FUNC_KEY(wep_key3
) },
2463 { INT(wep_tx_keyidx
) },
2464 #endif /* CONFIG_WEP */
2466 #ifdef IEEE8021X_EAPOL
2467 { INT(eap_workaround
) },
2468 { STRe(pac_file
, pac_file
) },
2469 { INTe(fragment_size
, fragment_size
) },
2470 { INTe(ocsp
, cert
.ocsp
) },
2471 { INTe(ocsp2
, phase2_cert
.ocsp
) },
2472 #endif /* IEEE8021X_EAPOL */
2474 { INT_RANGE(mode
, 0, 5) },
2475 { INT_RANGE(no_auto_peer
, 0, 1) },
2476 { INT_RANGE(mesh_rssi_threshold
, -255, 1) },
2477 #else /* CONFIG_MESH */
2478 { INT_RANGE(mode
, 0, 4) },
2479 #endif /* CONFIG_MESH */
2480 { INT_RANGE(proactive_key_caching
, 0, 1) },
2481 { INT_RANGE(disabled
, 0, 2) },
2483 { INT_RANGE(ieee80211w
, 0, 2) },
2486 #endif /* CONFIG_OCV */
2487 { FUNC(peerkey
) /* obsolete - removed */ },
2488 { INT_RANGE(mixed_cell
, 0, 1) },
2489 { INT_RANGE(frequency
, 0, 70200) },
2490 { INT_RANGE(fixed_freq
, 0, 1) },
2491 { INT_RANGE(enable_edmg
, 0, 1) },
2492 { INT_RANGE(edmg_channel
, 9, 13) },
2494 { INT_RANGE(acs
, 0, 1) },
2495 #endif /* CONFIG_ACS */
2497 { FUNC(mesh_basic_rates
) },
2498 { INT(dot11MeshMaxRetries
) },
2499 { INT(dot11MeshRetryTimeout
) },
2500 { INT(dot11MeshConfirmTimeout
) },
2501 { INT(dot11MeshHoldingTimeout
) },
2502 #endif /* CONFIG_MESH */
2503 { INT(wpa_ptk_rekey
) },
2504 { INT_RANGE(wpa_deny_ptk0_rekey
, 0, 2) },
2505 { INT(group_rekey
) },
2507 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2509 { FUNC(go_p2p_dev_addr
) },
2510 { FUNC(p2p_client_list
) },
2512 #endif /* CONFIG_P2P */
2513 #ifdef CONFIG_HT_OVERRIDES
2514 { INT_RANGE(disable_ht
, 0, 1) },
2515 { INT_RANGE(disable_ht40
, -1, 1) },
2516 { INT_RANGE(disable_sgi
, 0, 1) },
2517 { INT_RANGE(disable_ldpc
, 0, 1) },
2518 { INT_RANGE(ht40_intolerant
, 0, 1) },
2519 { INT_RANGE(tx_stbc
, -1, 1) },
2520 { INT_RANGE(rx_stbc
, -1, 3) },
2521 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2522 { INT_RANGE(ampdu_factor
, -1, 3) },
2523 { INT_RANGE(ampdu_density
, -1, 7) },
2525 #endif /* CONFIG_HT_OVERRIDES */
2526 #ifdef CONFIG_VHT_OVERRIDES
2527 { INT_RANGE(disable_vht
, 0, 1) },
2529 { INT(vht_capa_mask
) },
2530 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2531 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2532 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2533 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2534 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2535 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2536 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2537 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2538 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2539 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2540 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2541 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2542 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2543 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2544 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2545 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2546 #endif /* CONFIG_VHT_OVERRIDES */
2547 { INT(ap_max_inactivity
) },
2548 { INT(dtim_period
) },
2549 { INT(beacon_int
) },
2550 #ifdef CONFIG_MACSEC
2551 { INT_RANGE(macsec_policy
, 0, 1) },
2552 { INT_RANGE(macsec_integ_only
, 0, 1) },
2553 { INT_RANGE(macsec_replay_protect
, 0, 1) },
2554 { INT(macsec_replay_window
) },
2555 { INT_RANGE(macsec_port
, 1, 65534) },
2556 { INT_RANGE(mka_priority
, 0, 255) },
2557 { FUNC_KEY(mka_cak
) },
2558 { FUNC_KEY(mka_ckn
) },
2559 #endif /* CONFIG_MACSEC */
2561 { INT(update_identifier
) },
2562 { STR_RANGE(roaming_consortium_selection
, 0, MAX_ROAMING_CONS_OI_LEN
) },
2563 #endif /* CONFIG_HS20 */
2564 { INT_RANGE(mac_addr
, 0, 2) },
2565 { INT_RANGE(pbss
, 0, 2) },
2566 { INT_RANGE(wps_disabled
, 0, 1) },
2567 { INT_RANGE(fils_dh_group
, 0, 65535) },
2569 { STR(dpp_connector
) },
2570 { STR_LEN(dpp_netaccesskey
) },
2571 { INT(dpp_netaccesskey_expiry
) },
2572 { STR_LEN(dpp_csign
) },
2573 { INT_RANGE(dpp_pfs
, 0, 2) },
2574 #endif /* CONFIG_DPP */
2575 { INT_RANGE(owe_group
, 0, 65535) },
2576 { INT_RANGE(owe_only
, 0, 1) },
2577 { INT_RANGE(owe_ptk_workaround
, 0, 1) },
2578 { INT_RANGE(multi_ap_backhaul_sta
, 0, 1) },
2579 { INT_RANGE(ft_eap_pmksa_caching
, 0, 1) },
2580 { INT_RANGE(beacon_prot
, 0, 1) },
2581 { INT_RANGE(transition_disable
, 0, 255) },
2593 #undef STR_RANGE_KEY
2600 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2604 * wpa_config_add_prio_network - Add a network to priority lists
2605 * @config: Configuration data from wpa_config_read()
2606 * @ssid: Pointer to the network configuration to be added to the list
2607 * Returns: 0 on success, -1 on failure
2609 * This function is used to add a network block to the priority list of
2610 * networks. This must be called for each network when reading in the full
2611 * configuration. In addition, this can be used indirectly when updating
2612 * priorities by calling wpa_config_update_prio_list().
2614 int wpa_config_add_prio_network(struct wpa_config
*config
,
2615 struct wpa_ssid
*ssid
)
2618 struct wpa_ssid
*prev
, **nlist
;
2621 * Add to an existing priority list if one is available for the
2622 * configured priority level for this network.
2624 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2625 prev
= config
->pssid
[prio
];
2626 if (prev
->priority
== ssid
->priority
) {
2634 /* First network for this priority - add a new priority list */
2635 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2636 sizeof(struct wpa_ssid
*));
2640 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2641 if (nlist
[prio
]->priority
< ssid
->priority
) {
2642 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2643 (config
->num_prio
- prio
) *
2644 sizeof(struct wpa_ssid
*));
2651 config
->pssid
= nlist
;
2658 * wpa_config_update_prio_list - Update network priority list
2659 * @config: Configuration data from wpa_config_read()
2660 * Returns: 0 on success, -1 on failure
2662 * This function is called to update the priority list of networks in the
2663 * configuration when a network is being added or removed. This is also called
2664 * if a priority for a network is changed.
2666 int wpa_config_update_prio_list(struct wpa_config
*config
)
2668 struct wpa_ssid
*ssid
;
2671 os_free(config
->pssid
);
2672 config
->pssid
= NULL
;
2673 config
->num_prio
= 0;
2675 ssid
= config
->ssid
;
2678 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2687 #ifdef IEEE8021X_EAPOL
2689 static void eap_peer_config_free_cert(struct eap_peer_cert_config
*cert
)
2691 os_free(cert
->ca_cert
);
2692 os_free(cert
->ca_path
);
2693 os_free(cert
->client_cert
);
2694 os_free(cert
->private_key
);
2695 str_clear_free(cert
->private_key_passwd
);
2696 os_free(cert
->dh_file
);
2697 os_free(cert
->subject_match
);
2698 os_free(cert
->check_cert_subject
);
2699 os_free(cert
->altsubject_match
);
2700 os_free(cert
->domain_suffix_match
);
2701 os_free(cert
->domain_match
);
2702 str_clear_free(cert
->pin
);
2703 os_free(cert
->engine_id
);
2704 os_free(cert
->key_id
);
2705 os_free(cert
->cert_id
);
2706 os_free(cert
->ca_cert_id
);
2710 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2712 os_free(eap
->eap_methods
);
2713 bin_clear_free(eap
->identity
, eap
->identity_len
);
2714 os_free(eap
->anonymous_identity
);
2715 os_free(eap
->imsi_identity
);
2716 os_free(eap
->machine_identity
);
2717 bin_clear_free(eap
->password
, eap
->password_len
);
2718 bin_clear_free(eap
->machine_password
, eap
->machine_password_len
);
2719 eap_peer_config_free_cert(&eap
->cert
);
2720 eap_peer_config_free_cert(&eap
->phase2_cert
);
2721 eap_peer_config_free_cert(&eap
->machine_cert
);
2722 os_free(eap
->phase1
);
2723 os_free(eap
->phase2
);
2724 os_free(eap
->machine_phase2
);
2727 os_free(eap
->pending_req_otp
);
2728 os_free(eap
->pac_file
);
2729 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2730 str_clear_free(eap
->external_sim_resp
);
2731 os_free(eap
->openssl_ciphers
);
2734 #endif /* IEEE8021X_EAPOL */
2738 * wpa_config_free_ssid - Free network/ssid configuration data
2739 * @ssid: Configuration data for the network
2741 * This function frees all resources allocated for the network configuration
2744 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2746 struct psk_list_entry
*psk
;
2748 os_free(ssid
->ssid
);
2749 str_clear_free(ssid
->passphrase
);
2750 os_free(ssid
->ext_psk
);
2751 str_clear_free(ssid
->sae_password
);
2752 os_free(ssid
->sae_password_id
);
2753 #ifdef IEEE8021X_EAPOL
2754 eap_peer_config_free(&ssid
->eap
);
2755 #endif /* IEEE8021X_EAPOL */
2756 os_free(ssid
->id_str
);
2757 os_free(ssid
->scan_freq
);
2758 os_free(ssid
->freq_list
);
2759 os_free(ssid
->bgscan
);
2760 os_free(ssid
->p2p_client_list
);
2761 os_free(ssid
->bssid_blacklist
);
2762 os_free(ssid
->bssid_whitelist
);
2763 #ifdef CONFIG_HT_OVERRIDES
2764 os_free(ssid
->ht_mcs
);
2765 #endif /* CONFIG_HT_OVERRIDES */
2767 os_free(ssid
->mesh_basic_rates
);
2768 #endif /* CONFIG_MESH */
2770 os_free(ssid
->roaming_consortium_selection
);
2771 #endif /* CONFIG_HS20 */
2772 os_free(ssid
->dpp_connector
);
2773 bin_clear_free(ssid
->dpp_netaccesskey
, ssid
->dpp_netaccesskey_len
);
2774 os_free(ssid
->dpp_csign
);
2775 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2777 dl_list_del(&psk
->list
);
2778 bin_clear_free(psk
, sizeof(*psk
));
2781 sae_deinit_pt(ssid
->pt
);
2782 #endif /* CONFIG_SAE */
2783 bin_clear_free(ssid
, sizeof(*ssid
));
2787 void wpa_config_free_cred(struct wpa_cred
*cred
)
2791 os_free(cred
->realm
);
2792 str_clear_free(cred
->username
);
2793 str_clear_free(cred
->password
);
2794 os_free(cred
->ca_cert
);
2795 os_free(cred
->client_cert
);
2796 os_free(cred
->private_key
);
2797 str_clear_free(cred
->private_key_passwd
);
2798 os_free(cred
->imsi
);
2799 str_clear_free(cred
->milenage
);
2800 for (i
= 0; i
< cred
->num_domain
; i
++)
2801 os_free(cred
->domain
[i
]);
2802 os_free(cred
->domain
);
2803 os_free(cred
->domain_suffix_match
);
2804 os_free(cred
->eap_method
);
2805 os_free(cred
->phase1
);
2806 os_free(cred
->phase2
);
2807 os_free(cred
->excluded_ssid
);
2808 os_free(cred
->roaming_partner
);
2809 os_free(cred
->provisioning_sp
);
2810 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2811 os_free(cred
->req_conn_capab_port
[i
]);
2812 os_free(cred
->req_conn_capab_port
);
2813 os_free(cred
->req_conn_capab_proto
);
2818 void wpa_config_flush_blobs(struct wpa_config
*config
)
2820 #ifndef CONFIG_NO_CONFIG_BLOBS
2821 struct wpa_config_blob
*blob
, *prev
;
2823 blob
= config
->blobs
;
2824 config
->blobs
= NULL
;
2828 wpa_config_free_blob(prev
);
2830 #endif /* CONFIG_NO_CONFIG_BLOBS */
2835 * wpa_config_free - Free configuration data
2836 * @config: Configuration data from wpa_config_read()
2838 * This function frees all resources allocated for the configuration data by
2839 * wpa_config_read().
2841 void wpa_config_free(struct wpa_config
*config
)
2843 struct wpa_ssid
*ssid
, *prev
= NULL
;
2844 struct wpa_cred
*cred
, *cprev
;
2847 ssid
= config
->ssid
;
2851 wpa_config_free_ssid(prev
);
2854 cred
= config
->cred
;
2858 wpa_config_free_cred(cprev
);
2861 wpa_config_flush_blobs(config
);
2863 wpabuf_free(config
->wps_vendor_ext_m1
);
2864 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2865 wpabuf_free(config
->wps_vendor_ext
[i
]);
2866 os_free(config
->ctrl_interface
);
2867 os_free(config
->ctrl_interface_group
);
2868 os_free(config
->opensc_engine_path
);
2869 os_free(config
->pkcs11_engine_path
);
2870 os_free(config
->pkcs11_module_path
);
2871 os_free(config
->openssl_ciphers
);
2872 os_free(config
->pcsc_reader
);
2873 str_clear_free(config
->pcsc_pin
);
2874 os_free(config
->driver_param
);
2875 os_free(config
->device_name
);
2876 os_free(config
->manufacturer
);
2877 os_free(config
->model_name
);
2878 os_free(config
->model_number
);
2879 os_free(config
->serial_number
);
2880 os_free(config
->config_methods
);
2881 os_free(config
->p2p_ssid_postfix
);
2882 os_free(config
->pssid
);
2883 os_free(config
->p2p_pref_chan
);
2884 os_free(config
->p2p_no_go_freq
.range
);
2885 os_free(config
->autoscan
);
2886 os_free(config
->freq_list
);
2887 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2888 wpabuf_free(config
->wps_nfc_dh_privkey
);
2889 wpabuf_free(config
->wps_nfc_dev_pw
);
2890 os_free(config
->ext_password_backend
);
2891 os_free(config
->sae_groups
);
2892 wpabuf_free(config
->ap_vendor_elements
);
2893 os_free(config
->osu_dir
);
2894 os_free(config
->bgscan
);
2895 os_free(config
->wowlan_triggers
);
2896 os_free(config
->fst_group_id
);
2897 os_free(config
->sched_scan_plans
);
2899 os_free(config
->non_pref_chan
);
2900 #endif /* CONFIG_MBO */
2901 os_free(config
->dpp_name
);
2902 os_free(config
->dpp_mud_url
);
2909 * wpa_config_foreach_network - Iterate over each configured network
2910 * @config: Configuration data from wpa_config_read()
2911 * @func: Callback function to process each network
2912 * @arg: Opaque argument to pass to callback function
2914 * Iterate over the set of configured networks calling the specified
2915 * function for each item. We guard against callbacks removing the
2918 void wpa_config_foreach_network(struct wpa_config
*config
,
2919 void (*func
)(void *, struct wpa_ssid
*),
2922 struct wpa_ssid
*ssid
, *next
;
2924 ssid
= config
->ssid
;
2934 * wpa_config_get_network - Get configured network based on id
2935 * @config: Configuration data from wpa_config_read()
2936 * @id: Unique network id to search for
2937 * Returns: Network configuration or %NULL if not found
2939 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2941 struct wpa_ssid
*ssid
;
2943 ssid
= config
->ssid
;
2955 * wpa_config_add_network - Add a new network with empty configuration
2956 * @config: Configuration data from wpa_config_read()
2957 * Returns: The new network configuration or %NULL if operation failed
2959 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2962 struct wpa_ssid
*ssid
, *last
= NULL
;
2965 ssid
= config
->ssid
;
2974 ssid
= os_zalloc(sizeof(*ssid
));
2978 dl_list_init(&ssid
->psk_list
);
2982 config
->ssid
= ssid
;
2984 wpa_config_update_prio_list(config
);
2991 * wpa_config_remove_network - Remove a configured network based on id
2992 * @config: Configuration data from wpa_config_read()
2993 * @id: Unique network id to search for
2994 * Returns: 0 on success, or -1 if the network was not found
2996 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2998 struct wpa_ssid
*ssid
, *prev
= NULL
;
3000 ssid
= config
->ssid
;
3012 prev
->next
= ssid
->next
;
3014 config
->ssid
= ssid
->next
;
3016 wpa_config_update_prio_list(config
);
3017 wpa_config_free_ssid(ssid
);
3023 * wpa_config_set_network_defaults - Set network default values
3024 * @ssid: Pointer to network configuration data
3026 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
3028 ssid
->proto
= DEFAULT_PROTO
;
3029 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
3030 ssid
->group_cipher
= DEFAULT_GROUP
;
3031 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
3032 ssid
->wpa_deny_ptk0_rekey
= PTK0_REKEY_ALLOW_ALWAYS
;
3033 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
3035 #ifdef IEEE8021X_EAPOL
3036 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
3037 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
3038 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
3039 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
3040 #endif /* IEEE8021X_EAPOL */
3042 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
3043 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
3044 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
3045 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
3046 ssid
->mesh_rssi_threshold
= DEFAULT_MESH_RSSI_THRESHOLD
;
3047 #endif /* CONFIG_MESH */
3048 #ifdef CONFIG_HT_OVERRIDES
3049 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
3050 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
3051 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
3052 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
3053 ssid
->tx_stbc
= DEFAULT_TX_STBC
;
3054 ssid
->rx_stbc
= DEFAULT_RX_STBC
;
3055 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
3056 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
3057 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
3058 #endif /* CONFIG_HT_OVERRIDES */
3059 #ifdef CONFIG_VHT_OVERRIDES
3060 ssid
->vht_rx_mcs_nss_1
= -1;
3061 ssid
->vht_rx_mcs_nss_2
= -1;
3062 ssid
->vht_rx_mcs_nss_3
= -1;
3063 ssid
->vht_rx_mcs_nss_4
= -1;
3064 ssid
->vht_rx_mcs_nss_5
= -1;
3065 ssid
->vht_rx_mcs_nss_6
= -1;
3066 ssid
->vht_rx_mcs_nss_7
= -1;
3067 ssid
->vht_rx_mcs_nss_8
= -1;
3068 ssid
->vht_tx_mcs_nss_1
= -1;
3069 ssid
->vht_tx_mcs_nss_2
= -1;
3070 ssid
->vht_tx_mcs_nss_3
= -1;
3071 ssid
->vht_tx_mcs_nss_4
= -1;
3072 ssid
->vht_tx_mcs_nss_5
= -1;
3073 ssid
->vht_tx_mcs_nss_6
= -1;
3074 ssid
->vht_tx_mcs_nss_7
= -1;
3075 ssid
->vht_tx_mcs_nss_8
= -1;
3076 #endif /* CONFIG_VHT_OVERRIDES */
3077 ssid
->proactive_key_caching
= -1;
3078 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
3079 #ifdef CONFIG_MACSEC
3080 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
3081 #endif /* CONFIG_MACSEC */
3082 ssid
->mac_addr
= -1;
3083 ssid
->max_oper_chwidth
= DEFAULT_MAX_OPER_CHWIDTH
;
3088 * wpa_config_set - Set a variable in network configuration
3089 * @ssid: Pointer to network configuration data
3090 * @var: Variable name, e.g., "ssid"
3091 * @value: Variable value
3092 * @line: Line number in configuration file or 0 if not used
3093 * Returns: 0 on success with possible change in the value, 1 on success with
3094 * no change to previously configured value, or -1 on failure
3096 * This function can be used to set network configuration variables based on
3097 * both the configuration file and management interface input. The value
3098 * parameter must be in the same format as the text-based configuration file is
3099 * using. For example, strings are using double quotation marks.
3101 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
3107 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
3110 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3111 const struct parse_data
*field
= &ssid_fields
[i
];
3112 if (os_strcmp(var
, field
->name
) != 0)
3115 ret
= field
->parser(field
, ssid
, line
, value
);
3118 wpa_printf(MSG_ERROR
, "Line %d: failed to "
3119 "parse %s '%s'.", line
, var
, value
);
3124 if (os_strcmp(var
, "ssid") == 0 ||
3125 os_strcmp(var
, "psk") == 0 ||
3126 os_strcmp(var
, "sae_password") == 0 ||
3127 os_strcmp(var
, "sae_password_id") == 0) {
3128 sae_deinit_pt(ssid
->pt
);
3131 #endif /* CONFIG_SAE */
3134 if (i
== NUM_SSID_FIELDS
) {
3136 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
3137 "'%s'.", line
, var
);
3146 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
3153 len
= os_strlen(value
);
3154 buf
= os_malloc(len
+ 3);
3158 os_memcpy(buf
+ 1, value
, len
);
3160 buf
[len
+ 2] = '\0';
3161 ret
= wpa_config_set(ssid
, var
, buf
, 0);
3168 * wpa_config_get_all - Get all options from network configuration
3169 * @ssid: Pointer to network configuration data
3170 * @get_keys: Determines if keys/passwords will be included in returned list
3171 * (if they may be exported)
3172 * Returns: %NULL terminated list of all set keys and their values in the form
3173 * of [key1, val1, key2, val2, ... , NULL]
3175 * This function can be used to get list of all configured network properties.
3176 * The caller is responsible for freeing the returned list and all its
3179 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
3181 #ifdef NO_CONFIG_WRITE
3183 #else /* NO_CONFIG_WRITE */
3184 const struct parse_data
*field
;
3190 get_keys
= get_keys
&& ssid
->export_keys
;
3192 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
3197 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3198 field
= &ssid_fields
[i
];
3199 if (field
->key_data
&& !get_keys
)
3201 value
= field
->writer(field
, ssid
);
3204 if (os_strlen(value
) == 0) {
3209 key
= os_strdup(field
->name
);
3215 props
[fields_num
* 2] = key
;
3216 props
[fields_num
* 2 + 1] = value
;
3224 for (i
= 0; props
[i
]; i
++)
3228 #endif /* NO_CONFIG_WRITE */
3232 #ifndef NO_CONFIG_WRITE
3234 * wpa_config_get - Get a variable in network configuration
3235 * @ssid: Pointer to network configuration data
3236 * @var: Variable name, e.g., "ssid"
3237 * Returns: Value of the variable or %NULL on failure
3239 * This function can be used to get network configuration variables. The
3240 * returned value is a copy of the configuration variable in text format, i.e,.
3241 * the same format that the text-based configuration file and wpa_config_set()
3242 * are using for the value. The caller is responsible for freeing the returned
3245 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
3249 if (ssid
== NULL
|| var
== NULL
)
3252 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3253 const struct parse_data
*field
= &ssid_fields
[i
];
3254 if (os_strcmp(var
, field
->name
) == 0) {
3255 char *ret
= field
->writer(field
, ssid
);
3257 if (ret
&& has_newline(ret
)) {
3258 wpa_printf(MSG_ERROR
,
3259 "Found newline in value for %s; not returning it",
3274 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
3275 * @ssid: Pointer to network configuration data
3276 * @var: Variable name, e.g., "ssid"
3277 * Returns: Value of the variable or %NULL on failure
3279 * This function can be used to get network configuration variable like
3280 * wpa_config_get(). The only difference is that this functions does not expose
3281 * key/password material from the configuration. In case a key/password field
3282 * is requested, the returned value is an empty string or %NULL if the variable
3283 * is not set or "*" if the variable is set (regardless of its value). The
3284 * returned value is a copy of the configuration variable in text format, i.e,.
3285 * the same format that the text-based configuration file and wpa_config_set()
3286 * are using for the value. The caller is responsible for freeing the returned
3289 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
3293 if (ssid
== NULL
|| var
== NULL
)
3296 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3297 const struct parse_data
*field
= &ssid_fields
[i
];
3298 if (os_strcmp(var
, field
->name
) == 0) {
3299 char *res
= field
->writer(field
, ssid
);
3300 if (field
->key_data
) {
3301 if (res
&& res
[0]) {
3302 wpa_printf(MSG_DEBUG
, "Do not allow "
3303 "key_data field to be "
3305 str_clear_free(res
);
3306 return os_strdup("*");
3318 #endif /* NO_CONFIG_WRITE */
3322 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
3323 * @ssid: Pointer to network configuration data
3325 * This function must be called to update WPA PSK when either SSID or the
3326 * passphrase has changed for the network configuration.
3328 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
3330 #ifndef CONFIG_NO_PBKDF2
3331 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
3332 ssid
->psk
, PMK_LEN
);
3333 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
3334 ssid
->psk
, PMK_LEN
);
3336 #endif /* CONFIG_NO_PBKDF2 */
3340 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
3345 int *ports
, *nports
;
3347 unsigned int num_ports
;
3349 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
3350 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
3353 cred
->req_conn_capab_proto
= proto
;
3355 port
= os_realloc_array(cred
->req_conn_capab_port
,
3356 cred
->num_req_conn_capab
+ 1, sizeof(int *));
3359 cred
->req_conn_capab_port
= port
;
3361 proto
[cred
->num_req_conn_capab
] = atoi(value
);
3363 pos
= os_strchr(value
, ':');
3365 port
[cred
->num_req_conn_capab
] = NULL
;
3366 cred
->num_req_conn_capab
++;
3375 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3376 if (nports
== NULL
) {
3381 ports
[num_ports
++] = atoi(pos
);
3383 pos
= os_strchr(pos
, ',');
3389 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3390 if (nports
== NULL
) {
3395 ports
[num_ports
] = -1;
3397 port
[cred
->num_req_conn_capab
] = ports
;
3398 cred
->num_req_conn_capab
++;
3403 static int wpa_config_set_cred_roaming_consortiums(struct wpa_cred
*cred
,
3406 u8 roaming_consortiums
[MAX_ROAMING_CONS
][MAX_ROAMING_CONS_OI_LEN
];
3407 size_t roaming_consortiums_len
[MAX_ROAMING_CONS
];
3408 unsigned int num_roaming_consortiums
= 0;
3409 const char *pos
, *end
;
3412 os_memset(roaming_consortiums
, 0, sizeof(roaming_consortiums
));
3413 os_memset(roaming_consortiums_len
, 0, sizeof(roaming_consortiums_len
));
3415 for (pos
= value
;;) {
3416 end
= os_strchr(pos
, ',');
3417 len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
3418 if (!end
&& len
== 0)
3420 if (len
== 0 || (len
& 1) != 0 ||
3421 len
/ 2 > MAX_ROAMING_CONS_OI_LEN
||
3423 roaming_consortiums
[num_roaming_consortiums
],
3425 wpa_printf(MSG_INFO
,
3426 "Invalid roaming_consortiums entry: %s",
3430 roaming_consortiums_len
[num_roaming_consortiums
] = len
/ 2;
3431 num_roaming_consortiums
++;
3436 if (num_roaming_consortiums
>= MAX_ROAMING_CONS
) {
3437 wpa_printf(MSG_INFO
,
3438 "Too many roaming_consortiums OIs");
3445 os_memcpy(cred
->roaming_consortiums
, roaming_consortiums
,
3446 sizeof(roaming_consortiums
));
3447 os_memcpy(cred
->roaming_consortiums_len
, roaming_consortiums_len
,
3448 sizeof(roaming_consortiums_len
));
3449 cred
->num_roaming_consortiums
= num_roaming_consortiums
;
3455 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
3456 const char *value
, int line
)
3462 if (os_strcmp(var
, "temporary") == 0) {
3463 cred
->temporary
= atoi(value
);
3467 if (os_strcmp(var
, "priority") == 0) {
3468 cred
->priority
= atoi(value
);
3472 if (os_strcmp(var
, "sp_priority") == 0) {
3473 int prio
= atoi(value
);
3474 if (prio
< 0 || prio
> 255)
3476 cred
->sp_priority
= prio
;
3480 if (os_strcmp(var
, "pcsc") == 0) {
3481 cred
->pcsc
= atoi(value
);
3485 if (os_strcmp(var
, "eap") == 0) {
3486 struct eap_method_type method
;
3487 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3488 if (method
.vendor
== EAP_VENDOR_IETF
&&
3489 method
.method
== EAP_TYPE_NONE
) {
3490 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3491 "for a credential", line
, value
);
3494 os_free(cred
->eap_method
);
3495 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3496 if (cred
->eap_method
== NULL
)
3498 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3502 if (os_strcmp(var
, "password") == 0 &&
3503 os_strncmp(value
, "ext:", 4) == 0) {
3504 if (has_newline(value
))
3506 str_clear_free(cred
->password
);
3507 cred
->password
= os_strdup(value
);
3508 cred
->ext_password
= 1;
3512 if (os_strcmp(var
, "update_identifier") == 0) {
3513 cred
->update_identifier
= atoi(value
);
3517 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3518 cred
->min_dl_bandwidth_home
= atoi(value
);
3522 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3523 cred
->min_ul_bandwidth_home
= atoi(value
);
3527 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3528 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3532 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3533 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3537 if (os_strcmp(var
, "max_bss_load") == 0) {
3538 cred
->max_bss_load
= atoi(value
);
3542 if (os_strcmp(var
, "req_conn_capab") == 0)
3543 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3545 if (os_strcmp(var
, "ocsp") == 0) {
3546 cred
->ocsp
= atoi(value
);
3550 if (os_strcmp(var
, "sim_num") == 0) {
3551 cred
->sim_num
= atoi(value
);
3555 val
= wpa_config_parse_string(value
, &len
);
3557 (os_strcmp(var
, "excluded_ssid") != 0 &&
3558 os_strcmp(var
, "roaming_consortium") != 0 &&
3559 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3560 has_newline(val
))) {
3561 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3562 "value '%s'.", line
, var
, value
);
3567 if (os_strcmp(var
, "realm") == 0) {
3568 os_free(cred
->realm
);
3573 if (os_strcmp(var
, "username") == 0) {
3574 str_clear_free(cred
->username
);
3575 cred
->username
= val
;
3579 if (os_strcmp(var
, "password") == 0) {
3580 str_clear_free(cred
->password
);
3581 cred
->password
= val
;
3582 cred
->ext_password
= 0;
3586 if (os_strcmp(var
, "ca_cert") == 0) {
3587 os_free(cred
->ca_cert
);
3588 cred
->ca_cert
= val
;
3592 if (os_strcmp(var
, "client_cert") == 0) {
3593 os_free(cred
->client_cert
);
3594 cred
->client_cert
= val
;
3598 if (os_strcmp(var
, "private_key") == 0) {
3599 os_free(cred
->private_key
);
3600 cred
->private_key
= val
;
3604 if (os_strcmp(var
, "private_key_passwd") == 0) {
3605 str_clear_free(cred
->private_key_passwd
);
3606 cred
->private_key_passwd
= val
;
3610 if (os_strcmp(var
, "imsi") == 0) {
3611 os_free(cred
->imsi
);
3616 if (os_strcmp(var
, "milenage") == 0) {
3617 str_clear_free(cred
->milenage
);
3618 cred
->milenage
= val
;
3622 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3623 os_free(cred
->domain_suffix_match
);
3624 cred
->domain_suffix_match
= val
;
3628 if (os_strcmp(var
, "domain") == 0) {
3630 new_domain
= os_realloc_array(cred
->domain
,
3631 cred
->num_domain
+ 1,
3633 if (new_domain
== NULL
) {
3637 new_domain
[cred
->num_domain
++] = val
;
3638 cred
->domain
= new_domain
;
3642 if (os_strcmp(var
, "phase1") == 0) {
3643 os_free(cred
->phase1
);
3648 if (os_strcmp(var
, "phase2") == 0) {
3649 os_free(cred
->phase2
);
3654 if (os_strcmp(var
, "roaming_consortium") == 0) {
3655 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3656 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3657 "roaming_consortium length %d (3..15 "
3658 "expected)", line
, (int) len
);
3662 os_memcpy(cred
->roaming_consortium
, val
, len
);
3663 cred
->roaming_consortium_len
= len
;
3668 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3669 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3671 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3672 "required_roaming_consortium length %d "
3673 "(3..15 expected)", line
, (int) len
);
3677 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3678 cred
->required_roaming_consortium_len
= len
;
3683 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3684 res
= wpa_config_set_cred_roaming_consortiums(cred
, val
);
3686 wpa_printf(MSG_ERROR
,
3687 "Line %d: invalid roaming_consortiums",
3693 if (os_strcmp(var
, "excluded_ssid") == 0) {
3694 struct excluded_ssid
*e
;
3696 if (len
> SSID_MAX_LEN
) {
3697 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3698 "excluded_ssid length %d", line
, (int) len
);
3703 e
= os_realloc_array(cred
->excluded_ssid
,
3704 cred
->num_excluded_ssid
+ 1,
3705 sizeof(struct excluded_ssid
));
3710 cred
->excluded_ssid
= e
;
3712 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3713 os_memcpy(e
->ssid
, val
, len
);
3721 if (os_strcmp(var
, "roaming_partner") == 0) {
3722 struct roaming_partner
*p
;
3725 p
= os_realloc_array(cred
->roaming_partner
,
3726 cred
->num_roaming_partner
+ 1,
3727 sizeof(struct roaming_partner
));
3732 cred
->roaming_partner
= p
;
3734 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3736 pos
= os_strchr(val
, ',');
3742 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3746 os_memcpy(p
->fqdn
, val
, pos
- val
);
3748 p
->exact_match
= atoi(pos
);
3750 pos
= os_strchr(pos
, ',');
3757 p
->priority
= atoi(pos
);
3759 pos
= os_strchr(pos
, ',');
3766 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3770 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3772 cred
->num_roaming_partner
++;
3778 if (os_strcmp(var
, "provisioning_sp") == 0) {
3779 os_free(cred
->provisioning_sp
);
3780 cred
->provisioning_sp
= val
;
3785 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3795 static char * alloc_int_str(int val
)
3797 const unsigned int bufsize
= 20;
3801 buf
= os_malloc(bufsize
);
3804 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3805 if (os_snprintf_error(bufsize
, res
)) {
3813 static char * alloc_strdup(const char *str
)
3817 return os_strdup(str
);
3821 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3823 if (os_strcmp(var
, "temporary") == 0)
3824 return alloc_int_str(cred
->temporary
);
3826 if (os_strcmp(var
, "priority") == 0)
3827 return alloc_int_str(cred
->priority
);
3829 if (os_strcmp(var
, "sp_priority") == 0)
3830 return alloc_int_str(cred
->sp_priority
);
3832 if (os_strcmp(var
, "pcsc") == 0)
3833 return alloc_int_str(cred
->pcsc
);
3835 if (os_strcmp(var
, "eap") == 0) {
3836 if (!cred
->eap_method
)
3838 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3839 cred
->eap_method
[0].method
));
3842 if (os_strcmp(var
, "update_identifier") == 0)
3843 return alloc_int_str(cred
->update_identifier
);
3845 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3846 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3848 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3849 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3851 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3852 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3854 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3855 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3857 if (os_strcmp(var
, "max_bss_load") == 0)
3858 return alloc_int_str(cred
->max_bss_load
);
3860 if (os_strcmp(var
, "req_conn_capab") == 0) {
3862 char *buf
, *end
, *pos
;
3865 if (!cred
->num_req_conn_capab
)
3868 buf
= os_malloc(4000);
3873 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3876 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3878 cred
->req_conn_capab_proto
[i
]);
3879 if (os_snprintf_error(end
- pos
, ret
))
3883 ports
= cred
->req_conn_capab_port
[i
];
3886 for (j
= 0; ports
[j
] != -1; j
++) {
3887 ret
= os_snprintf(pos
, end
- pos
,
3891 if (os_snprintf_error(end
- pos
, ret
))
3901 if (os_strcmp(var
, "ocsp") == 0)
3902 return alloc_int_str(cred
->ocsp
);
3904 if (os_strcmp(var
, "realm") == 0)
3905 return alloc_strdup(cred
->realm
);
3907 if (os_strcmp(var
, "username") == 0)
3908 return alloc_strdup(cred
->username
);
3910 if (os_strcmp(var
, "password") == 0) {
3911 if (!cred
->password
)
3913 return alloc_strdup("*");
3916 if (os_strcmp(var
, "ca_cert") == 0)
3917 return alloc_strdup(cred
->ca_cert
);
3919 if (os_strcmp(var
, "client_cert") == 0)
3920 return alloc_strdup(cred
->client_cert
);
3922 if (os_strcmp(var
, "private_key") == 0)
3923 return alloc_strdup(cred
->private_key
);
3925 if (os_strcmp(var
, "private_key_passwd") == 0) {
3926 if (!cred
->private_key_passwd
)
3928 return alloc_strdup("*");
3931 if (os_strcmp(var
, "imsi") == 0)
3932 return alloc_strdup(cred
->imsi
);
3934 if (os_strcmp(var
, "milenage") == 0) {
3935 if (!(cred
->milenage
))
3937 return alloc_strdup("*");
3940 if (os_strcmp(var
, "domain_suffix_match") == 0)
3941 return alloc_strdup(cred
->domain_suffix_match
);
3943 if (os_strcmp(var
, "domain") == 0) {
3945 char *buf
, *end
, *pos
;
3948 if (!cred
->num_domain
)
3951 buf
= os_malloc(4000);
3957 for (i
= 0; i
< cred
->num_domain
; i
++) {
3958 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3959 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3960 if (os_snprintf_error(end
- pos
, ret
))
3968 if (os_strcmp(var
, "phase1") == 0)
3969 return alloc_strdup(cred
->phase1
);
3971 if (os_strcmp(var
, "phase2") == 0)
3972 return alloc_strdup(cred
->phase2
);
3974 if (os_strcmp(var
, "roaming_consortium") == 0) {
3978 if (!cred
->roaming_consortium_len
)
3980 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3981 buf
= os_malloc(buflen
);
3984 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3985 cred
->roaming_consortium_len
);
3989 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3993 if (!cred
->required_roaming_consortium_len
)
3995 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3996 buf
= os_malloc(buflen
);
3999 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
4000 cred
->required_roaming_consortium_len
);
4004 if (os_strcmp(var
, "roaming_consortiums") == 0) {
4009 if (!cred
->num_roaming_consortiums
)
4011 buflen
= cred
->num_roaming_consortiums
*
4012 MAX_ROAMING_CONS_OI_LEN
* 2 + 1;
4013 buf
= os_malloc(buflen
);
4017 for (i
= 0; i
< cred
->num_roaming_consortiums
; i
++) {
4020 pos
+= wpa_snprintf_hex(
4021 pos
, buf
+ buflen
- pos
,
4022 cred
->roaming_consortiums
[i
],
4023 cred
->roaming_consortiums_len
[i
]);
4029 if (os_strcmp(var
, "excluded_ssid") == 0) {
4031 char *buf
, *end
, *pos
;
4033 if (!cred
->num_excluded_ssid
)
4036 buf
= os_malloc(4000);
4042 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
4043 struct excluded_ssid
*e
;
4046 e
= &cred
->excluded_ssid
[i
];
4047 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4049 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
4050 if (os_snprintf_error(end
- pos
, ret
))
4058 if (os_strcmp(var
, "roaming_partner") == 0) {
4060 char *buf
, *end
, *pos
;
4062 if (!cred
->num_roaming_partner
)
4065 buf
= os_malloc(4000);
4071 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
4072 struct roaming_partner
*p
;
4075 p
= &cred
->roaming_partner
[i
];
4076 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
4078 p
->fqdn
, p
->exact_match
, p
->priority
,
4080 if (os_snprintf_error(end
- pos
, ret
))
4088 if (os_strcmp(var
, "provisioning_sp") == 0)
4089 return alloc_strdup(cred
->provisioning_sp
);
4095 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
4097 struct wpa_cred
*cred
;
4099 cred
= config
->cred
;
4110 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
4113 struct wpa_cred
*cred
, *last
= NULL
;
4116 cred
= config
->cred
;
4125 cred
= os_zalloc(sizeof(*cred
));
4129 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
4133 config
->cred
= cred
;
4139 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
4141 struct wpa_cred
*cred
, *prev
= NULL
;
4143 cred
= config
->cred
;
4155 prev
->next
= cred
->next
;
4157 config
->cred
= cred
->next
;
4159 wpa_config_free_cred(cred
);
4164 #ifndef CONFIG_NO_CONFIG_BLOBS
4166 * wpa_config_get_blob - Get a named configuration blob
4167 * @config: Configuration data from wpa_config_read()
4168 * @name: Name of the blob
4169 * Returns: Pointer to blob data or %NULL if not found
4171 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
4174 struct wpa_config_blob
*blob
= config
->blobs
;
4177 if (os_strcmp(blob
->name
, name
) == 0)
4186 * wpa_config_set_blob - Set or add a named configuration blob
4187 * @config: Configuration data from wpa_config_read()
4188 * @blob: New value for the blob
4190 * Adds a new configuration blob or replaces the current value of an existing
4193 void wpa_config_set_blob(struct wpa_config
*config
,
4194 struct wpa_config_blob
*blob
)
4196 wpa_config_remove_blob(config
, blob
->name
);
4197 blob
->next
= config
->blobs
;
4198 config
->blobs
= blob
;
4203 * wpa_config_free_blob - Free blob data
4204 * @blob: Pointer to blob to be freed
4206 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
4209 os_free(blob
->name
);
4210 bin_clear_free(blob
->data
, blob
->len
);
4217 * wpa_config_remove_blob - Remove a named configuration blob
4218 * @config: Configuration data from wpa_config_read()
4219 * @name: Name of the blob to remove
4220 * Returns: 0 if blob was removed or -1 if blob was not found
4222 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
4224 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
4227 if (os_strcmp(pos
->name
, name
) == 0) {
4229 prev
->next
= pos
->next
;
4231 config
->blobs
= pos
->next
;
4232 wpa_config_free_blob(pos
);
4241 #endif /* CONFIG_NO_CONFIG_BLOBS */
4245 * wpa_config_alloc_empty - Allocate an empty configuration
4246 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
4248 * @driver_param: Driver parameters
4249 * Returns: Pointer to allocated configuration data or %NULL on failure
4251 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
4252 const char *driver_param
)
4254 struct wpa_config
*config
;
4255 const int aCWmin
= 4, aCWmax
= 10;
4256 const struct hostapd_wmm_ac_params ac_bk
=
4257 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
4258 const struct hostapd_wmm_ac_params ac_be
=
4259 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
4260 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
4261 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
4262 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
4263 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
4265 config
= os_zalloc(sizeof(*config
));
4268 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
4269 config
->ap_scan
= DEFAULT_AP_SCAN
;
4270 config
->user_mpm
= DEFAULT_USER_MPM
;
4271 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
4272 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
4273 config
->dot11RSNASAERetransPeriod
=
4274 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
4275 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
4276 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
4277 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
4278 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
4279 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
4280 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
4281 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
4282 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
4283 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
4284 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
4285 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
4286 config
->ap_isolate
= DEFAULT_AP_ISOLATE
;
4287 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
4288 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
4289 config
->wmm_ac_params
[0] = ac_be
;
4290 config
->wmm_ac_params
[1] = ac_bk
;
4291 config
->wmm_ac_params
[2] = ac_vi
;
4292 config
->wmm_ac_params
[3] = ac_vo
;
4293 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
4294 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4295 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
4296 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
4297 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
4298 config
->extended_key_id
= DEFAULT_EXTENDED_KEY_ID
;
4301 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
4302 config
->disassoc_imminent_rssi_threshold
=
4303 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
4304 config
->oce
= DEFAULT_OCE_SUPPORT
;
4305 #endif /* CONFIG_MBO */
4308 config
->ctrl_interface
= os_strdup(ctrl_interface
);
4310 config
->driver_param
= os_strdup(driver_param
);
4311 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4317 #ifndef CONFIG_NO_STDOUT_DEBUG
4319 * wpa_config_debug_dump_networks - Debug dump of configured networks
4320 * @config: Configuration data from wpa_config_read()
4322 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
4325 struct wpa_ssid
*ssid
;
4327 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
4328 ssid
= config
->pssid
[prio
];
4329 wpa_printf(MSG_DEBUG
, "Priority group %d",
4332 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
4334 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
4339 #endif /* CONFIG_NO_STDOUT_DEBUG */
4342 struct global_parse_data
{
4344 int (*parser
)(const struct global_parse_data
*data
,
4345 struct wpa_config
*config
, int line
, const char *value
);
4346 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
4347 char *buf
, size_t buflen
, int pretty_print
);
4348 void *param1
, *param2
, *param3
;
4349 unsigned int changed_flag
;
4353 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
4354 struct wpa_config
*config
, int line
,
4360 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
4361 val
= strtol(pos
, &end
, 0);
4363 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
4369 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
4371 if (data
->param2
&& *dst
< (long) data
->param2
) {
4372 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
4373 "min_value=%ld)", line
, data
->name
, *dst
,
4374 (long) data
->param2
);
4375 *dst
= (long) data
->param2
;
4379 if (data
->param3
&& *dst
> (long) data
->param3
) {
4380 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
4381 "max_value=%ld)", line
, data
->name
, *dst
,
4382 (long) data
->param3
);
4383 *dst
= (long) data
->param3
;
4391 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
4392 struct wpa_config
*config
, int line
,
4398 len
= os_strlen(pos
);
4399 if (data
->param2
&& len
< (size_t) data
->param2
) {
4400 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
4401 "min_len=%ld)", line
, data
->name
,
4402 (unsigned long) len
, (long) data
->param2
);
4406 if (data
->param3
&& len
> (size_t) data
->param3
) {
4407 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
4408 "max_len=%ld)", line
, data
->name
,
4409 (unsigned long) len
, (long) data
->param3
);
4413 if (has_newline(pos
)) {
4414 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
4419 tmp
= os_strdup(pos
);
4423 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
4426 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
4432 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
4433 struct wpa_config
*config
, int line
,
4440 tmp
= wpa_config_parse_string(pos
, &len
);
4442 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
4447 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
4453 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
4454 struct wpa_config
*config
, int line
,
4457 struct wpabuf
**dst
, *tmp
;
4459 tmp
= wpabuf_parse_bin(pos
);
4463 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
4466 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
4472 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
4473 struct wpa_config
*config
, int line
,
4478 freqs
= wpa_config_parse_int_array(value
);
4481 if (freqs
[0] == 0) {
4485 os_free(config
->freq_list
);
4486 config
->freq_list
= freqs
;
4492 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
4493 struct wpa_config
*config
, int line
,
4497 struct hostapd_ip_addr addr
;
4499 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
4501 if (addr
.af
!= AF_INET
)
4504 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
4505 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4506 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4507 WPA_GET_BE32((u8
*) dst
));
4511 #endif /* CONFIG_P2P */
4514 static int wpa_config_process_country(const struct global_parse_data
*data
,
4515 struct wpa_config
*config
, int line
,
4518 if (!pos
[0] || !pos
[1]) {
4519 wpa_printf(MSG_DEBUG
, "Invalid country set");
4522 config
->country
[0] = pos
[0];
4523 config
->country
[1] = pos
[1];
4524 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4525 config
->country
[0], config
->country
[1]);
4530 static int wpa_config_process_load_dynamic_eap(
4531 const struct global_parse_data
*data
, struct wpa_config
*config
,
4532 int line
, const char *so
)
4535 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4536 ret
= eap_peer_method_load(so
);
4538 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4541 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4542 "method '%s'.", line
, so
);
4552 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4553 struct wpa_config
*config
, int line
,
4557 if (uuid_str2bin(pos
, config
->uuid
)) {
4558 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4561 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4562 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4567 static int wpa_config_process_device_type(
4568 const struct global_parse_data
*data
,
4569 struct wpa_config
*config
, int line
, const char *pos
)
4571 return wps_dev_type_str2bin(pos
, config
->device_type
);
4575 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4576 struct wpa_config
*config
, int line
,
4579 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4580 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4583 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4584 WPA_GET_BE32(config
->os_version
));
4589 static int wpa_config_process_wps_vendor_ext_m1(
4590 const struct global_parse_data
*data
,
4591 struct wpa_config
*config
, int line
, const char *pos
)
4594 int len
= os_strlen(pos
) / 2;
4598 wpa_printf(MSG_ERROR
, "Line %d: "
4599 "invalid wps_vendor_ext_m1", line
);
4603 tmp
= wpabuf_alloc(len
);
4605 p
= wpabuf_put(tmp
, len
);
4607 if (hexstr2bin(pos
, p
, len
)) {
4608 wpa_printf(MSG_ERROR
, "Line %d: "
4609 "invalid wps_vendor_ext_m1", line
);
4614 wpabuf_free(config
->wps_vendor_ext_m1
);
4615 config
->wps_vendor_ext_m1
= tmp
;
4617 wpa_printf(MSG_ERROR
, "Can not allocate "
4618 "memory for wps_vendor_ext_m1");
4625 #endif /* CONFIG_WPS */
4628 static int wpa_config_process_sec_device_type(
4629 const struct global_parse_data
*data
,
4630 struct wpa_config
*config
, int line
, const char *pos
)
4634 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4635 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4640 idx
= config
->num_sec_device_types
;
4642 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4645 config
->num_sec_device_types
++;
4650 static int wpa_config_process_p2p_pref_chan(
4651 const struct global_parse_data
*data
,
4652 struct wpa_config
*config
, int line
, const char *pos
)
4654 struct p2p_channel
*pref
= NULL
, *n
;
4659 /* format: class:chan,class:chan,... */
4662 op_class
= atoi(pos
);
4663 pos2
= os_strchr(pos
, ':');
4669 n
= os_realloc_array(pref
, num
+ 1,
4670 sizeof(struct p2p_channel
));
4674 pref
[num
].op_class
= op_class
;
4675 pref
[num
].chan
= chan
;
4678 pos
= os_strchr(pos2
, ',');
4684 os_free(config
->p2p_pref_chan
);
4685 config
->p2p_pref_chan
= pref
;
4686 config
->num_p2p_pref_chan
= num
;
4687 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4688 (u8
*) config
->p2p_pref_chan
,
4689 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4695 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4700 static int wpa_config_process_p2p_no_go_freq(
4701 const struct global_parse_data
*data
,
4702 struct wpa_config
*config
, int line
, const char *pos
)
4706 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4708 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4712 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4713 config
->p2p_no_go_freq
.num
);
4719 static int wpa_config_process_p2p_device_persistent_mac_addr(
4720 const struct global_parse_data
*data
,
4721 struct wpa_config
*config
, int line
, const char *pos
)
4723 if (hwaddr_aton2(pos
, config
->p2p_device_persistent_mac_addr
) < 0) {
4724 wpa_printf(MSG_ERROR
,
4725 "Line %d: Invalid p2p_device_persistent_mac_addr '%s'",
4733 #endif /* CONFIG_P2P */
4736 static int wpa_config_process_hessid(
4737 const struct global_parse_data
*data
,
4738 struct wpa_config
*config
, int line
, const char *pos
)
4740 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4741 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4750 static int wpa_config_process_sae_groups(
4751 const struct global_parse_data
*data
,
4752 struct wpa_config
*config
, int line
, const char *pos
)
4754 int *groups
= wpa_config_parse_int_array(pos
);
4755 if (groups
== NULL
) {
4756 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4761 os_free(config
->sae_groups
);
4762 config
->sae_groups
= groups
;
4768 static int wpa_config_process_ap_vendor_elements(
4769 const struct global_parse_data
*data
,
4770 struct wpa_config
*config
, int line
, const char *pos
)
4773 int len
= os_strlen(pos
) / 2;
4777 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4782 tmp
= wpabuf_alloc(len
);
4784 p
= wpabuf_put(tmp
, len
);
4786 if (hexstr2bin(pos
, p
, len
)) {
4787 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4788 "ap_vendor_elements", line
);
4793 wpabuf_free(config
->ap_vendor_elements
);
4794 config
->ap_vendor_elements
= tmp
;
4796 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4797 "ap_vendor_elements");
4805 #ifdef CONFIG_CTRL_IFACE
4806 static int wpa_config_process_no_ctrl_interface(
4807 const struct global_parse_data
*data
,
4808 struct wpa_config
*config
, int line
, const char *pos
)
4810 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4811 os_free(config
->ctrl_interface
);
4812 config
->ctrl_interface
= NULL
;
4815 #endif /* CONFIG_CTRL_IFACE */
4818 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4819 long offset
, char *buf
, size_t buflen
,
4822 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4825 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4826 return os_snprintf(buf
, buflen
, "%d", *val
);
4830 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4831 long offset
, char *buf
, size_t buflen
,
4834 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4838 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4839 *val
? *val
: "null");
4843 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4844 if (os_snprintf_error(buflen
, res
))
4852 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4853 long offset
, char *buf
, size_t buflen
,
4856 void *val
= ((u8
*) config
) + (long) offset
;
4858 char addr
[INET_ADDRSTRLEN
];
4860 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4864 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4866 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4868 if (os_snprintf_error(buflen
, res
))
4873 #endif /* CONFIG_P2P */
4879 /* OFFSET: Get offset of a variable within the wpa_config structure */
4880 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4882 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4883 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4884 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4885 #define INT(f) _INT(f), NULL, NULL
4886 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4887 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4888 #define STR(f) _STR(f), NULL, NULL
4889 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4890 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4891 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4892 OFFSET(f), NULL, NULL
4894 static const struct global_parse_data global_fields
[] = {
4895 #ifdef CONFIG_CTRL_IFACE
4896 { STR(ctrl_interface
), 0 },
4897 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4898 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4899 #endif /* CONFIG_CTRL_IFACE */
4900 #ifdef CONFIG_MACSEC
4901 { INT_RANGE(eapol_version
, 1, 3), 0 },
4902 #else /* CONFIG_MACSEC */
4903 { INT_RANGE(eapol_version
, 1, 2), 0 },
4904 #endif /* CONFIG_MACSEC */
4905 { INT(ap_scan
), 0 },
4906 { FUNC(bgscan
), 0 },
4908 { INT(user_mpm
), 0 },
4909 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4910 { INT(mesh_max_inactivity
), 0 },
4911 { INT(dot11RSNASAERetransPeriod
), 0 },
4912 #endif /* CONFIG_MESH */
4913 { INT(disable_scan_offload
), 0 },
4914 { INT(fast_reauth
), 0 },
4915 { STR(opensc_engine_path
), 0 },
4916 { STR(pkcs11_engine_path
), 0 },
4917 { STR(pkcs11_module_path
), 0 },
4918 { STR(openssl_ciphers
), 0 },
4919 { STR(pcsc_reader
), 0 },
4920 { STR(pcsc_pin
), 0 },
4921 { INT(external_sim
), 0 },
4922 { STR(driver_param
), 0 },
4923 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4924 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4925 { INT(dot11RSNAConfigSATimeout
), 0 },
4926 #ifndef CONFIG_NO_CONFIG_WRITE
4927 { INT(update_config
), 0 },
4928 #endif /* CONFIG_NO_CONFIG_WRITE */
4929 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4931 { FUNC(uuid
), CFG_CHANGED_UUID
},
4932 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4933 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4934 CFG_CHANGED_DEVICE_NAME
},
4935 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4936 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4937 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4938 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4939 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4940 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4941 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4942 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4943 { INT_RANGE(wps_cred_add_sae
, 0, 1), 0 },
4944 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4945 #endif /* CONFIG_WPS */
4947 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4948 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4949 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4950 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4951 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4952 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4953 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4954 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4955 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4956 { INT(p2p_group_idle
), 0 },
4957 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4958 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4959 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4960 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4961 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4962 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4963 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4964 { INT(p2p_go_ht40
), 0 },
4965 { INT(p2p_go_vht
), 0 },
4966 { INT(p2p_go_he
), 0 },
4967 { INT(p2p_go_edmg
), 0 },
4968 { INT(p2p_disabled
), 0 },
4969 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4970 { INT(p2p_no_group_iface
), 0 },
4971 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4972 { IPV4(ip_addr_go
), 0 },
4973 { IPV4(ip_addr_mask
), 0 },
4974 { IPV4(ip_addr_start
), 0 },
4975 { IPV4(ip_addr_end
), 0 },
4976 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4977 { INT(p2p_device_random_mac_addr
), 0 },
4978 { FUNC(p2p_device_persistent_mac_addr
), 0 },
4979 { INT(p2p_interface_random_mac_addr
), 0 },
4980 #endif /* CONFIG_P2P */
4981 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4982 { INT(bss_max_count
), 0 },
4983 { INT(bss_expiration_age
), 0 },
4984 { INT(bss_expiration_scan_count
), 0 },
4985 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4986 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4987 { INT(max_num_sta
), 0 },
4988 { INT_RANGE(ap_isolate
, 0, 1), 0 },
4989 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4991 { INT_RANGE(hs20
, 0, 1), 0 },
4992 #endif /* CONFIG_HS20 */
4993 { INT_RANGE(interworking
, 0, 1), 0 },
4994 { FUNC(hessid
), 0 },
4995 { INT_RANGE(access_network_type
, 0, 15), 0 },
4996 { INT_RANGE(go_interworking
, 0, 1), 0 },
4997 { INT_RANGE(go_access_network_type
, 0, 15), 0 },
4998 { INT_RANGE(go_internet
, 0, 1), 0 },
4999 { INT_RANGE(go_venue_group
, 0, 255), 0 },
5000 { INT_RANGE(go_venue_type
, 0, 255), 0 },
5001 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
5002 { STR(autoscan
), 0 },
5003 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
5004 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
5005 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
5006 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
5007 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
5008 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
5009 { INT(p2p_go_max_inactivity
), 0 },
5010 { INT_RANGE(auto_interworking
, 0, 1), 0 },
5013 { FUNC(sae_groups
), 0 },
5014 { INT_RANGE(sae_pwe
, 0, 3), 0 },
5015 { INT_RANGE(sae_pmkid_in_assoc
, 0, 1), 0 },
5016 { INT(dtim_period
), 0 },
5017 { INT(beacon_int
), 0 },
5018 { FUNC(ap_vendor_elements
), 0 },
5019 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
5020 { FUNC(freq_list
), 0 },
5021 { INT(scan_cur_freq
), 0 },
5022 { INT(sched_scan_interval
), 0 },
5023 { INT(sched_scan_start_delay
), 0 },
5024 { INT(tdls_external_control
), 0},
5025 { STR(osu_dir
), 0 },
5026 { STR(wowlan_triggers
), CFG_CHANGED_WOWLAN_TRIGGERS
},
5027 { INT(p2p_search_delay
), 0},
5028 { INT(mac_addr
), 0 },
5029 { INT(rand_addr_lifetime
), 0 },
5030 { INT(preassoc_mac_addr
), 0 },
5031 { INT(key_mgmt_offload
), 0},
5032 { INT(passive_scan
), 0 },
5033 { INT(reassoc_same_bss_optim
), 0 },
5034 { INT(wps_priority
), 0},
5036 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
5037 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
5038 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
5039 #endif /* CONFIG_FST */
5040 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
5041 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
5042 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
5044 { STR(non_pref_chan
), 0 },
5045 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
5046 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
5047 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
5048 { INT_RANGE(oce
, 0, 3), 0 },
5049 #endif /* CONFIG_MBO */
5050 { INT(gas_address3
), 0 },
5051 { INT_RANGE(ftm_responder
, 0, 1), 0 },
5052 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
5053 { INT(gas_rand_addr_lifetime
), 0 },
5054 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
5056 { INT_RANGE(dpp_config_processing
, 0, 2), 0 },
5057 { STR(dpp_name
), 0 },
5058 { STR(dpp_mud_url
), 0 },
5059 #endif /* CONFIG_DPP */
5060 { INT_RANGE(coloc_intf_reporting
, 0, 1), 0 },
5062 { INT_RANGE(disable_btm
, 0, 1), CFG_CHANGED_DISABLE_BTM
},
5063 { INT_RANGE(extended_key_id
, 0, 1), 0 },
5064 #endif /* CONFIG_WNM */
5076 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
5079 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
5084 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5085 const struct global_parse_data
*field
= &global_fields
[i
];
5091 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
5103 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
5104 char *buf
, size_t buflen
)
5108 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5109 const struct global_parse_data
*field
= &global_fields
[i
];
5111 if (os_strcmp(name
, field
->name
) != 0)
5115 return field
->get(name
, config
, (long) field
->param1
,
5123 int wpa_config_get_num_global_field_names(void)
5125 return NUM_GLOBAL_FIELDS
;
5129 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
5131 if (i
>= NUM_GLOBAL_FIELDS
)
5135 *no_var
= !global_fields
[i
].param1
;
5136 return global_fields
[i
].name
;
5140 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
5145 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5146 const struct global_parse_data
*field
= &global_fields
[i
];
5147 size_t flen
= os_strlen(field
->name
);
5148 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
5152 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
5153 wpa_printf(MSG_ERROR
, "Line %d: failed to "
5154 "parse '%s'.", line
, pos
);
5157 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
5158 config
->wps_nfc_pw_from_config
= 1;
5159 config
->changed_parameters
|= field
->changed_flag
;
5162 if (i
== NUM_GLOBAL_FIELDS
) {
5164 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
5165 char *tmp
= os_strchr(pos
, '=');
5169 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
5174 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
5176 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
5182 #endif /* CONFIG_AP */
5185 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",