2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2018, 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 "crypto/sha1.h"
16 #include "rsn_supp/wpa.h"
17 #include "eap_peer/eap.h"
23 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
24 #define NO_CONFIG_WRITE
28 * Structure for network configuration parsing. This data is used to implement
29 * a generic parser for each network block variable. The table of configuration
30 * variables is defined below in this file (ssid_fields[]).
33 /* Configuration variable name */
36 /* Parser function for this variable. The parser functions return 0 or 1
37 * to indicate success. Value 0 indicates that the parameter value may
38 * have changed while value 1 means that the value did not change.
39 * Error cases (failure to parse the string) are indicated by returning
41 int (*parser
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
,
42 int line
, const char *value
);
44 #ifndef NO_CONFIG_WRITE
45 /* Writer function (i.e., to get the variable in text format from
46 * internal presentation). */
47 char * (*writer
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
);
48 #endif /* NO_CONFIG_WRITE */
50 /* Variable specific parameters for the parser. */
51 void *param1
, *param2
, *param3
, *param4
;
53 /* 0 = this variable can be included in debug output and ctrl_iface
54 * 1 = this variable contains key/private data and it must not be
55 * included in debug output unless explicitly requested. In
56 * addition, this variable will not be readable through the
63 static int wpa_config_parse_str(const struct parse_data
*data
,
64 struct wpa_ssid
*ssid
,
65 int line
, const char *value
)
67 size_t res_len
, *dst_len
, prev_len
;
70 if (os_strcmp(value
, "NULL") == 0) {
71 wpa_printf(MSG_DEBUG
, "Unset configuration string '%s'",
78 tmp
= wpa_config_parse_string(value
, &res_len
);
80 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s '%s'.",
82 data
->key_data
? "[KEY DATA REMOVED]" : value
);
87 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
90 wpa_hexdump_ascii(MSG_MSGDUMP
, data
->name
,
94 if (data
->param3
&& res_len
< (size_t) data
->param3
) {
95 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
96 "min_len=%ld)", line
, data
->name
,
97 (unsigned long) res_len
, (long) data
->param3
);
102 if (data
->param4
&& res_len
> (size_t) data
->param4
) {
103 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
104 "max_len=%ld)", line
, data
->name
,
105 (unsigned long) res_len
, (long) data
->param4
);
111 dst
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
112 dst_len
= (size_t *) (((u8
*) ssid
) + (long) data
->param2
);
117 prev_len
= os_strlen(*dst
);
120 if ((*dst
== NULL
&& tmp
== NULL
) ||
121 (*dst
&& tmp
&& prev_len
== res_len
&&
122 os_memcmp(*dst
, tmp
, res_len
) == 0)) {
123 /* No change to the previously configured value */
137 #ifndef NO_CONFIG_WRITE
138 static char * wpa_config_write_string_ascii(const u8
*value
, size_t len
)
142 buf
= os_malloc(len
+ 3);
146 os_memcpy(buf
+ 1, value
, len
);
154 static char * wpa_config_write_string_hex(const u8
*value
, size_t len
)
158 buf
= os_zalloc(2 * len
+ 1);
161 wpa_snprintf_hex(buf
, 2 * len
+ 1, value
, len
);
167 static char * wpa_config_write_string(const u8
*value
, size_t len
)
172 if (is_hex(value
, len
))
173 return wpa_config_write_string_hex(value
, len
);
175 return wpa_config_write_string_ascii(value
, len
);
179 static char * wpa_config_write_str(const struct parse_data
*data
,
180 struct wpa_ssid
*ssid
)
185 src
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
190 len
= *((size_t *) (((u8
*) ssid
) + (long) data
->param2
));
192 len
= os_strlen(*src
);
194 return wpa_config_write_string((const u8
*) *src
, len
);
196 #endif /* NO_CONFIG_WRITE */
199 static int wpa_config_parse_int(const struct parse_data
*data
,
200 struct wpa_ssid
*ssid
,
201 int line
, const char *value
)
206 dst
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
207 val
= strtol(value
, &end
, 0);
209 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
217 wpa_printf(MSG_MSGDUMP
, "%s=%d (0x%x)", data
->name
, *dst
, *dst
);
219 if (data
->param3
&& *dst
< (long) data
->param3
) {
220 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
221 "min_value=%ld)", line
, data
->name
, *dst
,
222 (long) data
->param3
);
223 *dst
= (long) data
->param3
;
227 if (data
->param4
&& *dst
> (long) data
->param4
) {
228 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
229 "max_value=%ld)", line
, data
->name
, *dst
,
230 (long) data
->param4
);
231 *dst
= (long) data
->param4
;
239 #ifndef NO_CONFIG_WRITE
240 static char * wpa_config_write_int(const struct parse_data
*data
,
241 struct wpa_ssid
*ssid
)
246 src
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
248 value
= os_malloc(20);
251 res
= os_snprintf(value
, 20, "%d", *src
);
252 if (os_snprintf_error(20, res
)) {
256 value
[20 - 1] = '\0';
259 #endif /* NO_CONFIG_WRITE */
262 static int wpa_config_parse_addr_list(const struct parse_data
*data
,
263 int line
, const char *value
,
264 u8
**list
, size_t *num
, char *name
,
265 u8 abort_on_error
, u8 masked
)
268 u8
*buf
, *n
, addr
[2 * ETH_ALEN
];
275 while (pos
&& *pos
) {
279 if (hwaddr_masked_aton(pos
, addr
, &addr
[ETH_ALEN
], masked
)) {
280 if (abort_on_error
|| count
== 0) {
281 wpa_printf(MSG_ERROR
,
282 "Line %d: Invalid %s address '%s'",
287 /* continue anyway since this could have been from a
288 * truncated configuration file line */
290 "Line %d: Ignore likely truncated %s address '%s'",
293 n
= os_realloc_array(buf
, count
+ 1, 2 * ETH_ALEN
);
299 os_memmove(buf
+ 2 * ETH_ALEN
, buf
,
300 count
* 2 * ETH_ALEN
);
301 os_memcpy(buf
, addr
, 2 * ETH_ALEN
);
303 wpa_printf(MSG_MSGDUMP
,
304 "%s: addr=" MACSTR
" mask=" MACSTR
,
306 MAC2STR(&addr
[ETH_ALEN
]));
309 pos
= os_strchr(pos
, ' ');
320 #ifndef NO_CONFIG_WRITE
321 static char * wpa_config_write_addr_list(const struct parse_data
*data
,
322 const u8
*list
, size_t num
, char *name
)
324 char *value
, *end
, *pos
;
328 if (list
== NULL
|| num
== 0)
331 value
= os_malloc(2 * 20 * num
);
335 end
= value
+ 2 * 20 * num
;
337 for (i
= num
; i
> 0; i
--) {
338 const u8
*a
= list
+ (i
- 1) * 2 * ETH_ALEN
;
339 const u8
*m
= a
+ ETH_ALEN
;
343 res
= hwaddr_mask_txt(pos
, end
- pos
, a
, m
);
353 #endif /* NO_CONFIG_WRITE */
355 static int wpa_config_parse_bssid(const struct parse_data
*data
,
356 struct wpa_ssid
*ssid
, int line
,
359 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
360 os_strcmp(value
, "any") == 0) {
362 wpa_printf(MSG_MSGDUMP
, "BSSID any");
365 if (hwaddr_aton(value
, ssid
->bssid
)) {
366 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID '%s'.",
371 wpa_hexdump(MSG_MSGDUMP
, "BSSID", ssid
->bssid
, ETH_ALEN
);
376 #ifndef NO_CONFIG_WRITE
377 static char * wpa_config_write_bssid(const struct parse_data
*data
,
378 struct wpa_ssid
*ssid
)
383 if (!ssid
->bssid_set
)
386 value
= os_malloc(20);
389 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid
));
390 if (os_snprintf_error(20, res
)) {
394 value
[20 - 1] = '\0';
397 #endif /* NO_CONFIG_WRITE */
400 static int wpa_config_parse_bssid_hint(const struct parse_data
*data
,
401 struct wpa_ssid
*ssid
, int line
,
404 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
405 os_strcmp(value
, "any") == 0) {
406 ssid
->bssid_hint_set
= 0;
407 wpa_printf(MSG_MSGDUMP
, "BSSID hint any");
410 if (hwaddr_aton(value
, ssid
->bssid_hint
)) {
411 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID hint '%s'.",
415 ssid
->bssid_hint_set
= 1;
416 wpa_hexdump(MSG_MSGDUMP
, "BSSID hint", ssid
->bssid_hint
, ETH_ALEN
);
421 #ifndef NO_CONFIG_WRITE
422 static char * wpa_config_write_bssid_hint(const struct parse_data
*data
,
423 struct wpa_ssid
*ssid
)
428 if (!ssid
->bssid_hint_set
)
431 value
= os_malloc(20);
434 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid_hint
));
435 if (os_snprintf_error(20, res
)) {
441 #endif /* NO_CONFIG_WRITE */
444 static int wpa_config_parse_bssid_blacklist(const struct parse_data
*data
,
445 struct wpa_ssid
*ssid
, int line
,
448 return wpa_config_parse_addr_list(data
, line
, value
,
449 &ssid
->bssid_blacklist
,
450 &ssid
->num_bssid_blacklist
,
451 "bssid_blacklist", 1, 1);
455 #ifndef NO_CONFIG_WRITE
456 static char * wpa_config_write_bssid_blacklist(const struct parse_data
*data
,
457 struct wpa_ssid
*ssid
)
459 return wpa_config_write_addr_list(data
, ssid
->bssid_blacklist
,
460 ssid
->num_bssid_blacklist
,
463 #endif /* NO_CONFIG_WRITE */
466 static int wpa_config_parse_bssid_whitelist(const struct parse_data
*data
,
467 struct wpa_ssid
*ssid
, int line
,
470 return wpa_config_parse_addr_list(data
, line
, value
,
471 &ssid
->bssid_whitelist
,
472 &ssid
->num_bssid_whitelist
,
473 "bssid_whitelist", 1, 1);
477 #ifndef NO_CONFIG_WRITE
478 static char * wpa_config_write_bssid_whitelist(const struct parse_data
*data
,
479 struct wpa_ssid
*ssid
)
481 return wpa_config_write_addr_list(data
, ssid
->bssid_whitelist
,
482 ssid
->num_bssid_whitelist
,
485 #endif /* NO_CONFIG_WRITE */
488 static int wpa_config_parse_psk(const struct parse_data
*data
,
489 struct wpa_ssid
*ssid
, int line
,
492 #ifdef CONFIG_EXT_PASSWORD
493 if (os_strncmp(value
, "ext:", 4) == 0) {
494 str_clear_free(ssid
->passphrase
);
495 ssid
->passphrase
= NULL
;
497 os_free(ssid
->ext_psk
);
498 ssid
->ext_psk
= os_strdup(value
+ 4);
499 if (ssid
->ext_psk
== NULL
)
501 wpa_printf(MSG_DEBUG
, "PSK: External password '%s'",
505 #endif /* CONFIG_EXT_PASSWORD */
508 #ifndef CONFIG_NO_PBKDF2
513 pos
= os_strrchr(value
, '"');
517 len
= os_strlen(value
);
518 if (len
< 8 || len
> 63) {
519 wpa_printf(MSG_ERROR
, "Line %d: Invalid passphrase "
520 "length %lu (expected: 8..63) '%s'.",
521 line
, (unsigned long) len
, value
);
524 wpa_hexdump_ascii_key(MSG_MSGDUMP
, "PSK (ASCII passphrase)",
526 if (has_ctrl_char((u8
*) value
, len
)) {
527 wpa_printf(MSG_ERROR
,
528 "Line %d: Invalid passphrase character",
532 if (ssid
->passphrase
&& os_strlen(ssid
->passphrase
) == len
&&
533 os_memcmp(ssid
->passphrase
, value
, len
) == 0) {
534 /* No change to the previously configured value */
538 str_clear_free(ssid
->passphrase
);
539 ssid
->passphrase
= dup_binstr(value
, len
);
540 if (ssid
->passphrase
== NULL
)
543 #else /* CONFIG_NO_PBKDF2 */
544 wpa_printf(MSG_ERROR
, "Line %d: ASCII passphrase not "
547 #endif /* CONFIG_NO_PBKDF2 */
550 if (hexstr2bin(value
, ssid
->psk
, PMK_LEN
) ||
551 value
[PMK_LEN
* 2] != '\0') {
552 wpa_printf(MSG_ERROR
, "Line %d: Invalid PSK '%s'.",
557 str_clear_free(ssid
->passphrase
);
558 ssid
->passphrase
= NULL
;
561 wpa_hexdump_key(MSG_MSGDUMP
, "PSK", ssid
->psk
, PMK_LEN
);
566 #ifndef NO_CONFIG_WRITE
567 static char * wpa_config_write_psk(const struct parse_data
*data
,
568 struct wpa_ssid
*ssid
)
570 #ifdef CONFIG_EXT_PASSWORD
572 size_t len
= 4 + os_strlen(ssid
->ext_psk
) + 1;
573 char *buf
= os_malloc(len
);
578 res
= os_snprintf(buf
, len
, "ext:%s", ssid
->ext_psk
);
579 if (os_snprintf_error(len
, res
)) {
585 #endif /* CONFIG_EXT_PASSWORD */
587 if (ssid
->passphrase
)
588 return wpa_config_write_string_ascii(
589 (const u8
*) ssid
->passphrase
,
590 os_strlen(ssid
->passphrase
));
593 return wpa_config_write_string_hex(ssid
->psk
, PMK_LEN
);
597 #endif /* NO_CONFIG_WRITE */
600 static int wpa_config_parse_proto(const struct parse_data
*data
,
601 struct wpa_ssid
*ssid
, int line
,
604 int val
= 0, last
, errors
= 0;
605 char *start
, *end
, *buf
;
607 buf
= os_strdup(value
);
612 while (*start
!= '\0') {
613 while (*start
== ' ' || *start
== '\t')
618 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
622 if (os_strcmp(start
, "WPA") == 0)
623 val
|= WPA_PROTO_WPA
;
624 else if (os_strcmp(start
, "RSN") == 0 ||
625 os_strcmp(start
, "WPA2") == 0)
626 val
|= WPA_PROTO_RSN
;
627 else if (os_strcmp(start
, "OSEN") == 0)
628 val
|= WPA_PROTO_OSEN
;
630 wpa_printf(MSG_ERROR
, "Line %d: invalid proto '%s'",
642 wpa_printf(MSG_ERROR
,
643 "Line %d: no proto values configured.", line
);
647 if (!errors
&& ssid
->proto
== val
)
649 wpa_printf(MSG_MSGDUMP
, "proto: 0x%x", val
);
651 return errors
? -1 : 0;
655 #ifndef NO_CONFIG_WRITE
656 static char * wpa_config_write_proto(const struct parse_data
*data
,
657 struct wpa_ssid
*ssid
)
660 char *buf
, *pos
, *end
;
662 pos
= buf
= os_zalloc(20);
667 if (ssid
->proto
& WPA_PROTO_WPA
) {
668 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
669 pos
== buf
? "" : " ");
670 if (os_snprintf_error(end
- pos
, ret
))
675 if (ssid
->proto
& WPA_PROTO_RSN
) {
676 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
677 pos
== buf
? "" : " ");
678 if (os_snprintf_error(end
- pos
, ret
))
683 if (ssid
->proto
& WPA_PROTO_OSEN
) {
684 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
685 pos
== buf
? "" : " ");
686 if (os_snprintf_error(end
- pos
, ret
))
698 #endif /* NO_CONFIG_WRITE */
701 static int wpa_config_parse_key_mgmt(const struct parse_data
*data
,
702 struct wpa_ssid
*ssid
, int line
,
705 int val
= 0, last
, errors
= 0;
706 char *start
, *end
, *buf
;
708 buf
= os_strdup(value
);
713 while (*start
!= '\0') {
714 while (*start
== ' ' || *start
== '\t')
719 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
723 if (os_strcmp(start
, "WPA-PSK") == 0)
724 val
|= WPA_KEY_MGMT_PSK
;
725 else if (os_strcmp(start
, "WPA-EAP") == 0)
726 val
|= WPA_KEY_MGMT_IEEE8021X
;
727 else if (os_strcmp(start
, "IEEE8021X") == 0)
728 val
|= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
729 else if (os_strcmp(start
, "NONE") == 0)
730 val
|= WPA_KEY_MGMT_NONE
;
731 else if (os_strcmp(start
, "WPA-NONE") == 0)
732 val
|= WPA_KEY_MGMT_WPA_NONE
;
733 #ifdef CONFIG_IEEE80211R
734 else if (os_strcmp(start
, "FT-PSK") == 0)
735 val
|= WPA_KEY_MGMT_FT_PSK
;
736 else if (os_strcmp(start
, "FT-EAP") == 0)
737 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
739 else if (os_strcmp(start
, "FT-EAP-SHA384") == 0)
740 val
|= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
741 #endif /* CONFIG_SHA384 */
742 #endif /* CONFIG_IEEE80211R */
743 #ifdef CONFIG_IEEE80211W
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
;
748 #endif /* CONFIG_IEEE80211W */
750 else if (os_strcmp(start
, "WPS") == 0)
751 val
|= WPA_KEY_MGMT_WPS
;
752 #endif /* CONFIG_WPS */
754 else if (os_strcmp(start
, "SAE") == 0)
755 val
|= WPA_KEY_MGMT_SAE
;
756 else if (os_strcmp(start
, "FT-SAE") == 0)
757 val
|= WPA_KEY_MGMT_FT_SAE
;
758 #endif /* CONFIG_SAE */
760 else if (os_strcmp(start
, "OSEN") == 0)
761 val
|= WPA_KEY_MGMT_OSEN
;
762 #endif /* CONFIG_HS20 */
764 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
765 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
766 #endif /* CONFIG_SUITEB */
767 #ifdef CONFIG_SUITEB192
768 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
769 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
770 #endif /* CONFIG_SUITEB192 */
772 else if (os_strcmp(start
, "FILS-SHA256") == 0)
773 val
|= WPA_KEY_MGMT_FILS_SHA256
;
774 else if (os_strcmp(start
, "FILS-SHA384") == 0)
775 val
|= WPA_KEY_MGMT_FILS_SHA384
;
776 #ifdef CONFIG_IEEE80211R
777 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
778 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
779 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
780 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
781 #endif /* CONFIG_IEEE80211R */
782 #endif /* CONFIG_FILS */
784 else if (os_strcmp(start
, "OWE") == 0)
785 val
|= WPA_KEY_MGMT_OWE
;
786 #endif /* CONFIG_OWE */
788 else if (os_strcmp(start
, "DPP") == 0)
789 val
|= WPA_KEY_MGMT_DPP
;
790 #endif /* CONFIG_DPP */
792 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
804 wpa_printf(MSG_ERROR
,
805 "Line %d: no key_mgmt values configured.", line
);
809 if (!errors
&& ssid
->key_mgmt
== val
)
811 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
812 ssid
->key_mgmt
= val
;
813 return errors
? -1 : 0;
817 #ifndef NO_CONFIG_WRITE
818 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
819 struct wpa_ssid
*ssid
)
821 char *buf
, *pos
, *end
;
824 pos
= buf
= os_zalloc(100);
829 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
830 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
831 pos
== buf
? "" : " ");
832 if (os_snprintf_error(end
- pos
, ret
)) {
839 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
840 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
841 pos
== buf
? "" : " ");
842 if (os_snprintf_error(end
- pos
, ret
)) {
849 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
850 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
851 pos
== buf
? "" : " ");
852 if (os_snprintf_error(end
- pos
, ret
)) {
859 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
860 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
861 pos
== buf
? "" : " ");
862 if (os_snprintf_error(end
- pos
, ret
)) {
869 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
870 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
871 pos
== buf
? "" : " ");
872 if (os_snprintf_error(end
- pos
, ret
)) {
879 #ifdef CONFIG_IEEE80211R
880 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
881 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
882 pos
== buf
? "" : " ");
883 if (os_snprintf_error(end
- pos
, ret
)) {
890 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
891 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
892 pos
== buf
? "" : " ");
893 if (os_snprintf_error(end
- pos
, ret
)) {
901 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
902 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP-SHA384",
903 pos
== buf
? "" : " ");
904 if (os_snprintf_error(end
- pos
, ret
)) {
910 #endif /* CONFIG_SHA384 */
911 #endif /* CONFIG_IEEE80211R */
913 #ifdef CONFIG_IEEE80211W
914 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
915 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
916 pos
== buf
? "" : " ");
917 if (os_snprintf_error(end
- pos
, ret
)) {
924 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
925 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
926 pos
== buf
? "" : " ");
927 if (os_snprintf_error(end
- pos
, ret
)) {
933 #endif /* CONFIG_IEEE80211W */
936 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
937 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
938 pos
== buf
? "" : " ");
939 if (os_snprintf_error(end
- pos
, ret
)) {
945 #endif /* CONFIG_WPS */
948 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
949 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
950 pos
== buf
? "" : " ");
951 if (os_snprintf_error(end
- pos
, ret
)) {
958 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
959 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
960 pos
== buf
? "" : " ");
961 if (os_snprintf_error(end
- pos
, ret
)) {
967 #endif /* CONFIG_SAE */
970 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
971 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
972 pos
== buf
? "" : " ");
973 if (os_snprintf_error(end
- pos
, ret
)) {
979 #endif /* CONFIG_HS20 */
982 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
983 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
984 pos
== buf
? "" : " ");
985 if (os_snprintf_error(end
- pos
, ret
)) {
991 #endif /* CONFIG_SUITEB */
993 #ifdef CONFIG_SUITEB192
994 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
995 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
996 pos
== buf
? "" : " ");
997 if (os_snprintf_error(end
- pos
, ret
)) {
1003 #endif /* CONFIG_SUITEB192 */
1006 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1007 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
1008 pos
== buf
? "" : " ");
1009 if (os_snprintf_error(end
- pos
, ret
)) {
1015 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1016 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
1017 pos
== buf
? "" : " ");
1018 if (os_snprintf_error(end
- pos
, ret
)) {
1024 #ifdef CONFIG_IEEE80211R
1025 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1026 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
1027 pos
== buf
? "" : " ");
1028 if (os_snprintf_error(end
- pos
, ret
)) {
1034 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1035 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
1036 pos
== buf
? "" : " ");
1037 if (os_snprintf_error(end
- pos
, ret
)) {
1043 #endif /* CONFIG_IEEE80211R */
1044 #endif /* CONFIG_FILS */
1053 #endif /* NO_CONFIG_WRITE */
1056 static int wpa_config_parse_cipher(int line
, const char *value
)
1058 #ifdef CONFIG_NO_WPA
1060 #else /* CONFIG_NO_WPA */
1061 int val
= wpa_parse_cipher(value
);
1063 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1068 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1073 #endif /* CONFIG_NO_WPA */
1077 #ifndef NO_CONFIG_WRITE
1078 static char * wpa_config_write_cipher(int cipher
)
1080 #ifdef CONFIG_NO_WPA
1082 #else /* CONFIG_NO_WPA */
1083 char *buf
= os_zalloc(50);
1087 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1093 #endif /* CONFIG_NO_WPA */
1095 #endif /* NO_CONFIG_WRITE */
1098 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1099 struct wpa_ssid
*ssid
, int line
,
1103 val
= wpa_config_parse_cipher(line
, value
);
1106 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1107 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1108 "(0x%x).", line
, val
);
1112 if (ssid
->pairwise_cipher
== val
)
1114 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1115 ssid
->pairwise_cipher
= val
;
1120 #ifndef NO_CONFIG_WRITE
1121 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1122 struct wpa_ssid
*ssid
)
1124 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1126 #endif /* NO_CONFIG_WRITE */
1129 static int wpa_config_parse_group(const struct parse_data
*data
,
1130 struct wpa_ssid
*ssid
, int line
,
1134 val
= wpa_config_parse_cipher(line
, value
);
1139 * Backwards compatibility - filter out WEP ciphers that were previously
1142 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1144 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1145 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1146 "(0x%x).", line
, val
);
1150 if (ssid
->group_cipher
== val
)
1152 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1153 ssid
->group_cipher
= val
;
1158 #ifndef NO_CONFIG_WRITE
1159 static char * wpa_config_write_group(const struct parse_data
*data
,
1160 struct wpa_ssid
*ssid
)
1162 return wpa_config_write_cipher(ssid
->group_cipher
);
1164 #endif /* NO_CONFIG_WRITE */
1167 static int wpa_config_parse_group_mgmt(const struct parse_data
*data
,
1168 struct wpa_ssid
*ssid
, int line
,
1173 val
= wpa_config_parse_cipher(line
, value
);
1177 if (val
& ~WPA_ALLOWED_GROUP_MGMT_CIPHERS
) {
1178 wpa_printf(MSG_ERROR
,
1179 "Line %d: not allowed group management cipher (0x%x).",
1184 if (ssid
->group_mgmt_cipher
== val
)
1186 wpa_printf(MSG_MSGDUMP
, "group_mgmt: 0x%x", val
);
1187 ssid
->group_mgmt_cipher
= val
;
1192 #ifndef NO_CONFIG_WRITE
1193 static char * wpa_config_write_group_mgmt(const struct parse_data
*data
,
1194 struct wpa_ssid
*ssid
)
1196 return wpa_config_write_cipher(ssid
->group_mgmt_cipher
);
1198 #endif /* NO_CONFIG_WRITE */
1201 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1202 struct wpa_ssid
*ssid
, int line
,
1205 int val
= 0, last
, errors
= 0;
1206 char *start
, *end
, *buf
;
1208 buf
= os_strdup(value
);
1213 while (*start
!= '\0') {
1214 while (*start
== ' ' || *start
== '\t')
1219 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1221 last
= *end
== '\0';
1223 if (os_strcmp(start
, "OPEN") == 0)
1224 val
|= WPA_AUTH_ALG_OPEN
;
1225 else if (os_strcmp(start
, "SHARED") == 0)
1226 val
|= WPA_AUTH_ALG_SHARED
;
1227 else if (os_strcmp(start
, "LEAP") == 0)
1228 val
|= WPA_AUTH_ALG_LEAP
;
1230 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1242 wpa_printf(MSG_ERROR
,
1243 "Line %d: no auth_alg values configured.", line
);
1247 if (!errors
&& ssid
->auth_alg
== val
)
1249 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1250 ssid
->auth_alg
= val
;
1251 return errors
? -1 : 0;
1255 #ifndef NO_CONFIG_WRITE
1256 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1257 struct wpa_ssid
*ssid
)
1259 char *buf
, *pos
, *end
;
1262 pos
= buf
= os_zalloc(30);
1267 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1268 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1269 pos
== buf
? "" : " ");
1270 if (os_snprintf_error(end
- pos
, ret
)) {
1277 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1278 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1279 pos
== buf
? "" : " ");
1280 if (os_snprintf_error(end
- pos
, ret
)) {
1287 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1288 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1289 pos
== buf
? "" : " ");
1290 if (os_snprintf_error(end
- pos
, ret
)) {
1304 #endif /* NO_CONFIG_WRITE */
1307 static int * wpa_config_parse_int_array(const char *value
)
1315 freqs
= os_calloc(len
+ 1, sizeof(int));
1326 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1331 for (i
= len
; i
<= len
* 2; i
++)
1337 freqs
[used
] = atoi(pos
);
1338 if (freqs
[used
] == 0)
1341 pos
= os_strchr(pos
+ 1, ' ');
1348 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1349 struct wpa_ssid
*ssid
, int line
,
1354 freqs
= wpa_config_parse_int_array(value
);
1357 if (freqs
[0] == 0) {
1361 os_free(ssid
->scan_freq
);
1362 ssid
->scan_freq
= freqs
;
1368 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1369 struct wpa_ssid
*ssid
, int line
,
1374 freqs
= wpa_config_parse_int_array(value
);
1377 if (freqs
[0] == 0) {
1381 os_free(ssid
->freq_list
);
1382 ssid
->freq_list
= freqs
;
1388 #ifndef NO_CONFIG_WRITE
1389 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1392 char *buf
, *pos
, *end
;
1400 for (i
= 0; freqs
[i
]; i
++)
1403 pos
= buf
= os_zalloc(10 * count
+ 1);
1406 end
= buf
+ 10 * count
+ 1;
1408 for (i
= 0; freqs
[i
]; i
++) {
1409 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1410 i
== 0 ? "" : " ", freqs
[i
]);
1411 if (os_snprintf_error(end
- pos
, ret
)) {
1422 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1423 struct wpa_ssid
*ssid
)
1425 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1429 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1430 struct wpa_ssid
*ssid
)
1432 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1434 #endif /* NO_CONFIG_WRITE */
1437 #ifdef IEEE8021X_EAPOL
1438 static int wpa_config_parse_eap(const struct parse_data
*data
,
1439 struct wpa_ssid
*ssid
, int line
,
1442 int last
, errors
= 0;
1443 char *start
, *end
, *buf
;
1444 struct eap_method_type
*methods
= NULL
, *tmp
;
1445 size_t num_methods
= 0;
1447 buf
= os_strdup(value
);
1452 while (*start
!= '\0') {
1453 while (*start
== ' ' || *start
== '\t')
1458 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1460 last
= *end
== '\0';
1463 methods
= os_realloc_array(methods
, num_methods
+ 1,
1465 if (methods
== NULL
) {
1470 methods
[num_methods
].method
= eap_peer_get_type(
1471 start
, &methods
[num_methods
].vendor
);
1472 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1473 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1474 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1475 "'%s'", line
, start
);
1476 wpa_printf(MSG_ERROR
, "You may need to add support for"
1477 " this EAP method during wpa_supplicant\n"
1478 "build time configuration.\n"
1479 "See README for more information.");
1481 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1482 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1494 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1495 if (methods
== NULL
) {
1499 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1500 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1503 if (!errors
&& ssid
->eap
.eap_methods
) {
1504 struct eap_method_type
*prev_m
;
1505 size_t i
, j
, prev_methods
, match
= 0;
1507 prev_m
= ssid
->eap
.eap_methods
;
1508 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1509 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1510 /* Count the methods */
1512 prev_methods
= i
+ 1;
1514 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1516 for (j
= 0; j
< num_methods
; j
++) {
1517 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1518 prev_m
[i
].method
== methods
[j
].method
) {
1524 if (match
== num_methods
) {
1529 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1530 (u8
*) methods
, num_methods
* sizeof(*methods
));
1531 os_free(ssid
->eap
.eap_methods
);
1532 ssid
->eap
.eap_methods
= methods
;
1533 return errors
? -1 : 0;
1537 #ifndef NO_CONFIG_WRITE
1538 static char * wpa_config_write_eap(const struct parse_data
*data
,
1539 struct wpa_ssid
*ssid
)
1542 char *buf
, *pos
, *end
;
1543 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1546 if (eap_methods
== NULL
)
1549 pos
= buf
= os_zalloc(100);
1554 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1555 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1556 name
= eap_get_name(eap_methods
[i
].vendor
,
1557 eap_methods
[i
].method
);
1559 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1560 pos
== buf
? "" : " ", name
);
1561 if (os_snprintf_error(end
- pos
, ret
))
1571 #endif /* NO_CONFIG_WRITE */
1574 static int wpa_config_parse_password(const struct parse_data
*data
,
1575 struct wpa_ssid
*ssid
, int line
,
1580 if (os_strcmp(value
, "NULL") == 0) {
1581 if (!ssid
->eap
.password
)
1582 return 1; /* Already unset */
1583 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1584 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1585 ssid
->eap
.password
= NULL
;
1586 ssid
->eap
.password_len
= 0;
1590 #ifdef CONFIG_EXT_PASSWORD
1591 if (os_strncmp(value
, "ext:", 4) == 0) {
1592 char *name
= os_strdup(value
+ 4);
1595 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1596 ssid
->eap
.password
= (u8
*) name
;
1597 ssid
->eap
.password_len
= os_strlen(name
);
1598 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1599 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1602 #endif /* CONFIG_EXT_PASSWORD */
1604 if (os_strncmp(value
, "hash:", 5) != 0) {
1608 tmp
= wpa_config_parse_string(value
, &res_len
);
1610 wpa_printf(MSG_ERROR
, "Line %d: failed to parse "
1614 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1615 (u8
*) tmp
, res_len
);
1617 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1618 ssid
->eap
.password
= (u8
*) tmp
;
1619 ssid
->eap
.password_len
= res_len
;
1620 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1621 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1627 /* NtPasswordHash: hash:<32 hex digits> */
1628 if (os_strlen(value
+ 5) != 2 * 16) {
1629 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash length "
1630 "(expected 32 hex digits)", line
);
1634 hash
= os_malloc(16);
1638 if (hexstr2bin(value
+ 5, hash
, 16)) {
1640 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1644 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1646 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1647 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1648 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1649 bin_clear_free(hash
, 16);
1652 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1653 ssid
->eap
.password
= hash
;
1654 ssid
->eap
.password_len
= 16;
1655 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1656 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1662 #ifndef NO_CONFIG_WRITE
1663 static char * wpa_config_write_password(const struct parse_data
*data
,
1664 struct wpa_ssid
*ssid
)
1668 if (ssid
->eap
.password
== NULL
)
1671 #ifdef CONFIG_EXT_PASSWORD
1672 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1673 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1676 os_memcpy(buf
, "ext:", 4);
1677 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1680 #endif /* CONFIG_EXT_PASSWORD */
1682 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1683 return wpa_config_write_string(
1684 ssid
->eap
.password
, ssid
->eap
.password_len
);
1687 buf
= os_malloc(5 + 32 + 1);
1691 os_memcpy(buf
, "hash:", 5);
1692 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1696 #endif /* NO_CONFIG_WRITE */
1697 #endif /* IEEE8021X_EAPOL */
1700 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1701 const char *value
, int idx
)
1703 char *buf
, title
[20];
1706 buf
= wpa_config_parse_string(value
, len
);
1708 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1712 if (*len
> MAX_WEP_KEY_LEN
) {
1713 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1718 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1719 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1720 "this network block will be ignored",
1721 line
, (unsigned int) *len
);
1723 os_memcpy(key
, buf
, *len
);
1724 str_clear_free(buf
);
1725 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1726 if (!os_snprintf_error(sizeof(title
), res
))
1727 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1732 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1733 struct wpa_ssid
*ssid
, int line
,
1736 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1737 &ssid
->wep_key_len
[0], line
,
1742 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1743 struct wpa_ssid
*ssid
, int line
,
1746 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1747 &ssid
->wep_key_len
[1], line
,
1752 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1753 struct wpa_ssid
*ssid
, int line
,
1756 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1757 &ssid
->wep_key_len
[2], line
,
1762 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1763 struct wpa_ssid
*ssid
, int line
,
1766 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1767 &ssid
->wep_key_len
[3], line
,
1772 #ifndef NO_CONFIG_WRITE
1773 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1775 if (ssid
->wep_key_len
[idx
] == 0)
1777 return wpa_config_write_string(ssid
->wep_key
[idx
],
1778 ssid
->wep_key_len
[idx
]);
1782 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1783 struct wpa_ssid
*ssid
)
1785 return wpa_config_write_wep_key(ssid
, 0);
1789 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1790 struct wpa_ssid
*ssid
)
1792 return wpa_config_write_wep_key(ssid
, 1);
1796 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1797 struct wpa_ssid
*ssid
)
1799 return wpa_config_write_wep_key(ssid
, 2);
1803 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1804 struct wpa_ssid
*ssid
)
1806 return wpa_config_write_wep_key(ssid
, 3);
1808 #endif /* NO_CONFIG_WRITE */
1813 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1814 struct wpa_ssid
*ssid
, int line
,
1817 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1818 os_strcmp(value
, "any") == 0) {
1819 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1820 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1823 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1824 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1828 ssid
->bssid_set
= 1;
1829 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1830 MAC2STR(ssid
->go_p2p_dev_addr
));
1835 #ifndef NO_CONFIG_WRITE
1836 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
1837 struct wpa_ssid
*ssid
)
1842 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
1845 value
= os_malloc(20);
1848 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
1849 if (os_snprintf_error(20, res
)) {
1853 value
[20 - 1] = '\0';
1856 #endif /* NO_CONFIG_WRITE */
1859 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
1860 struct wpa_ssid
*ssid
, int line
,
1863 return wpa_config_parse_addr_list(data
, line
, value
,
1864 &ssid
->p2p_client_list
,
1865 &ssid
->num_p2p_clients
,
1866 "p2p_client_list", 0, 0);
1870 #ifndef NO_CONFIG_WRITE
1871 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
1872 struct wpa_ssid
*ssid
)
1874 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
1875 ssid
->num_p2p_clients
,
1878 #endif /* NO_CONFIG_WRITE */
1881 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
1882 struct wpa_ssid
*ssid
, int line
,
1885 struct psk_list_entry
*p
;
1888 p
= os_zalloc(sizeof(*p
));
1893 if (os_strncmp(pos
, "P2P-", 4) == 0) {
1898 if (hwaddr_aton(pos
, p
->addr
)) {
1899 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
1906 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
1913 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
1914 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
1920 dl_list_add(&ssid
->psk_list
, &p
->list
);
1926 #ifndef NO_CONFIG_WRITE
1927 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
1928 struct wpa_ssid
*ssid
)
1932 #endif /* NO_CONFIG_WRITE */
1934 #endif /* CONFIG_P2P */
1939 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
1940 struct wpa_ssid
*ssid
, int line
,
1943 int *rates
= wpa_config_parse_int_array(value
);
1945 if (rates
== NULL
) {
1946 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
1950 if (rates
[0] == 0) {
1955 os_free(ssid
->mesh_basic_rates
);
1956 ssid
->mesh_basic_rates
= rates
;
1962 #ifndef NO_CONFIG_WRITE
1964 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
1965 struct wpa_ssid
*ssid
)
1967 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
1970 #endif /* NO_CONFIG_WRITE */
1972 #endif /* CONFIG_MESH */
1975 #ifdef CONFIG_MACSEC
1977 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
1978 struct wpa_ssid
*ssid
, int line
,
1981 if (hexstr2bin(value
, ssid
->mka_cak
, MACSEC_CAK_LEN
) ||
1982 value
[MACSEC_CAK_LEN
* 2] != '\0') {
1983 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
1988 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
1990 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
, MACSEC_CAK_LEN
);
1995 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
1996 struct wpa_ssid
*ssid
, int line
,
1999 if (hexstr2bin(value
, ssid
->mka_ckn
, MACSEC_CKN_LEN
) ||
2000 value
[MACSEC_CKN_LEN
* 2] != '\0') {
2001 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2006 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
2008 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
, MACSEC_CKN_LEN
);
2013 #ifndef NO_CONFIG_WRITE
2015 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
2016 struct wpa_ssid
*ssid
)
2018 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
2021 return wpa_config_write_string_hex(ssid
->mka_cak
, MACSEC_CAK_LEN
);
2025 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
2026 struct wpa_ssid
*ssid
)
2028 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
2030 return wpa_config_write_string_hex(ssid
->mka_ckn
, MACSEC_CKN_LEN
);
2033 #endif /* NO_CONFIG_WRITE */
2035 #endif /* CONFIG_MACSEC */
2038 static int wpa_config_parse_peerkey(const struct parse_data
*data
,
2039 struct wpa_ssid
*ssid
, int line
,
2042 wpa_printf(MSG_INFO
, "NOTE: Obsolete peerkey parameter ignored");
2047 #ifndef NO_CONFIG_WRITE
2048 static char * wpa_config_write_peerkey(const struct parse_data
*data
,
2049 struct wpa_ssid
*ssid
)
2053 #endif /* NO_CONFIG_WRITE */
2056 /* Helper macros for network block parser */
2061 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
2062 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
2064 /* STR: Define a string variable for an ASCII string; f = field name */
2065 #ifdef NO_CONFIG_WRITE
2066 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
2067 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
2068 #else /* NO_CONFIG_WRITE */
2069 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
2070 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
2071 #endif /* NO_CONFIG_WRITE */
2072 #define STR(f) _STR(f), NULL, NULL, NULL, 0
2073 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
2074 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
2075 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
2077 /* STR_LEN: Define a string variable with a separate variable for storing the
2078 * data length. Unlike STR(), this can be used to store arbitrary binary data
2079 * (i.e., even nul termination character). */
2080 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
2081 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
2082 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
2083 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
2084 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
2086 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
2087 * explicitly specified. */
2088 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
2089 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
2090 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
2092 #ifdef NO_CONFIG_WRITE
2093 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
2094 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
2095 #else /* NO_CONFIG_WRITE */
2096 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2097 OFFSET(f), (void *) 0
2098 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2099 OFFSET(eap.f), (void *) 0
2100 #endif /* NO_CONFIG_WRITE */
2102 /* INT: Define an integer variable */
2103 #define INT(f) _INT(f), NULL, NULL, 0
2104 #define INTe(f) _INTe(f), NULL, NULL, 0
2106 /* INT_RANGE: Define an integer variable with allowed value range */
2107 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
2109 /* FUNC: Define a configuration variable that uses a custom function for
2110 * parsing and writing the value. */
2111 #ifdef NO_CONFIG_WRITE
2112 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
2113 #else /* NO_CONFIG_WRITE */
2114 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
2115 NULL, NULL, NULL, NULL
2116 #endif /* NO_CONFIG_WRITE */
2117 #define FUNC(f) _FUNC(f), 0
2118 #define FUNC_KEY(f) _FUNC(f), 1
2121 * Table of network configuration variables. This table is used to parse each
2122 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2123 * that is inside a network block.
2125 * This table is generated using the helper macros defined above and with
2126 * generous help from the C pre-processor. The field name is stored as a string
2127 * into .name and for STR and INT types, the offset of the target buffer within
2128 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2129 * offset to the field containing the length of the configuration variable.
2130 * .param3 and .param4 can be used to mark the allowed range (length for STR
2131 * and value for INT).
2133 * For each configuration line in wpa_supplicant.conf, the parser goes through
2134 * this table and select the entry that matches with the field name. The parser
2135 * function (.parser) is then called to parse the actual value of the field.
2137 * This kind of mechanism makes it easy to add new configuration parameters,
2138 * since only one line needs to be added into this table and into the
2139 * struct wpa_ssid definition if the new variable is either a string or
2140 * integer. More complex types will need to use their own parser and writer
2143 static const struct parse_data ssid_fields
[] = {
2144 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2145 { INT_RANGE(scan_ssid
, 0, 1) },
2147 { FUNC(bssid_hint
) },
2148 { FUNC(bssid_blacklist
) },
2149 { FUNC(bssid_whitelist
) },
2151 { INT(mem_only_psk
) },
2152 { STR_KEY(sae_password
) },
2153 { STR(sae_password_id
) },
2156 { INT(bg_scan_period
) },
2159 { FUNC(group_mgmt
) },
2161 { FUNC(scan_freq
) },
2162 { FUNC(freq_list
) },
2163 { INT_RANGE(ht
, 0, 1) },
2164 { INT_RANGE(vht
, 0, 1) },
2165 { INT_RANGE(ht40
, -1, 1) },
2166 { INT_RANGE(max_oper_chwidth
, VHT_CHANWIDTH_USE_HT
,
2167 VHT_CHANWIDTH_80P80MHZ
) },
2168 { INT(vht_center_freq1
) },
2169 { INT(vht_center_freq2
) },
2170 #ifdef IEEE8021X_EAPOL
2172 { STR_LENe(identity
) },
2173 { STR_LENe(anonymous_identity
) },
2174 { STR_LENe(imsi_identity
) },
2175 { FUNC_KEY(password
) },
2178 { STRe(client_cert
) },
2179 { STRe(private_key
) },
2180 { STR_KEYe(private_key_passwd
) },
2182 { STRe(subject_match
) },
2183 { STRe(altsubject_match
) },
2184 { STRe(domain_suffix_match
) },
2185 { STRe(domain_match
) },
2188 { STRe(client_cert2
) },
2189 { STRe(private_key2
) },
2190 { STR_KEYe(private_key2_passwd
) },
2192 { STRe(subject_match2
) },
2193 { STRe(altsubject_match2
) },
2194 { STRe(domain_suffix_match2
) },
2195 { STRe(domain_match2
) },
2200 { STRe(engine_id
) },
2203 { STRe(ca_cert_id
) },
2205 { STRe(engine2_id
) },
2208 { STRe(ca_cert2_id
) },
2211 { INT(eapol_flags
) },
2213 { STRe(openssl_ciphers
) },
2215 #endif /* IEEE8021X_EAPOL */
2216 { FUNC_KEY(wep_key0
) },
2217 { FUNC_KEY(wep_key1
) },
2218 { FUNC_KEY(wep_key2
) },
2219 { FUNC_KEY(wep_key3
) },
2220 { INT(wep_tx_keyidx
) },
2222 #ifdef IEEE8021X_EAPOL
2223 { INT(eap_workaround
) },
2225 { INTe(fragment_size
) },
2227 #endif /* IEEE8021X_EAPOL */
2229 { INT_RANGE(mode
, 0, 5) },
2230 { INT_RANGE(no_auto_peer
, 0, 1) },
2231 { INT_RANGE(mesh_rssi_threshold
, -255, 1) },
2232 #else /* CONFIG_MESH */
2233 { INT_RANGE(mode
, 0, 4) },
2234 #endif /* CONFIG_MESH */
2235 { INT_RANGE(proactive_key_caching
, 0, 1) },
2236 { INT_RANGE(disabled
, 0, 2) },
2238 #ifdef CONFIG_IEEE80211W
2239 { INT_RANGE(ieee80211w
, 0, 2) },
2240 #endif /* CONFIG_IEEE80211W */
2241 { FUNC(peerkey
) /* obsolete - removed */ },
2242 { INT_RANGE(mixed_cell
, 0, 1) },
2243 { INT_RANGE(frequency
, 0, 65000) },
2244 { INT_RANGE(fixed_freq
, 0, 1) },
2246 { INT_RANGE(acs
, 0, 1) },
2247 #endif /* CONFIG_ACS */
2249 { FUNC(mesh_basic_rates
) },
2250 { INT(dot11MeshMaxRetries
) },
2251 { INT(dot11MeshRetryTimeout
) },
2252 { INT(dot11MeshConfirmTimeout
) },
2253 { INT(dot11MeshHoldingTimeout
) },
2254 #endif /* CONFIG_MESH */
2255 { INT(wpa_ptk_rekey
) },
2256 { INT(group_rekey
) },
2258 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2260 { FUNC(go_p2p_dev_addr
) },
2261 { FUNC(p2p_client_list
) },
2263 #endif /* CONFIG_P2P */
2264 #ifdef CONFIG_HT_OVERRIDES
2265 { INT_RANGE(disable_ht
, 0, 1) },
2266 { INT_RANGE(disable_ht40
, -1, 1) },
2267 { INT_RANGE(disable_sgi
, 0, 1) },
2268 { INT_RANGE(disable_ldpc
, 0, 1) },
2269 { INT_RANGE(ht40_intolerant
, 0, 1) },
2270 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2271 { INT_RANGE(ampdu_factor
, -1, 3) },
2272 { INT_RANGE(ampdu_density
, -1, 7) },
2274 #endif /* CONFIG_HT_OVERRIDES */
2275 #ifdef CONFIG_VHT_OVERRIDES
2276 { INT_RANGE(disable_vht
, 0, 1) },
2278 { INT(vht_capa_mask
) },
2279 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2280 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2281 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2282 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2283 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2284 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2285 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2286 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2287 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2288 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2289 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2290 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2291 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2292 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2293 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2294 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2295 #endif /* CONFIG_VHT_OVERRIDES */
2296 { INT(ap_max_inactivity
) },
2297 { INT(dtim_period
) },
2298 { INT(beacon_int
) },
2299 #ifdef CONFIG_MACSEC
2300 { INT_RANGE(macsec_policy
, 0, 1) },
2301 { INT_RANGE(macsec_integ_only
, 0, 1) },
2302 { INT_RANGE(macsec_port
, 1, 65534) },
2303 { INT_RANGE(mka_priority
, 0, 255) },
2304 { FUNC_KEY(mka_cak
) },
2305 { FUNC_KEY(mka_ckn
) },
2306 #endif /* CONFIG_MACSEC */
2308 { INT(update_identifier
) },
2309 { STR_RANGE(roaming_consortium_selection
, 0, MAX_ROAMING_CONS_OI_LEN
) },
2310 #endif /* CONFIG_HS20 */
2311 { INT_RANGE(mac_addr
, 0, 2) },
2312 { INT_RANGE(pbss
, 0, 2) },
2313 { INT_RANGE(wps_disabled
, 0, 1) },
2314 { INT_RANGE(fils_dh_group
, 0, 65535) },
2316 { STR(dpp_connector
) },
2317 { STR_LEN(dpp_netaccesskey
) },
2318 { INT(dpp_netaccesskey_expiry
) },
2319 { STR_LEN(dpp_csign
) },
2320 #endif /* CONFIG_DPP */
2321 { INT_RANGE(owe_group
, 0, 65535) },
2322 { INT_RANGE(owe_only
, 0, 1) },
2334 #undef STR_RANGE_KEY
2341 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2345 * wpa_config_add_prio_network - Add a network to priority lists
2346 * @config: Configuration data from wpa_config_read()
2347 * @ssid: Pointer to the network configuration to be added to the list
2348 * Returns: 0 on success, -1 on failure
2350 * This function is used to add a network block to the priority list of
2351 * networks. This must be called for each network when reading in the full
2352 * configuration. In addition, this can be used indirectly when updating
2353 * priorities by calling wpa_config_update_prio_list().
2355 int wpa_config_add_prio_network(struct wpa_config
*config
,
2356 struct wpa_ssid
*ssid
)
2359 struct wpa_ssid
*prev
, **nlist
;
2362 * Add to an existing priority list if one is available for the
2363 * configured priority level for this network.
2365 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2366 prev
= config
->pssid
[prio
];
2367 if (prev
->priority
== ssid
->priority
) {
2375 /* First network for this priority - add a new priority list */
2376 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2377 sizeof(struct wpa_ssid
*));
2381 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2382 if (nlist
[prio
]->priority
< ssid
->priority
) {
2383 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2384 (config
->num_prio
- prio
) *
2385 sizeof(struct wpa_ssid
*));
2392 config
->pssid
= nlist
;
2399 * wpa_config_update_prio_list - Update network priority list
2400 * @config: Configuration data from wpa_config_read()
2401 * Returns: 0 on success, -1 on failure
2403 * This function is called to update the priority list of networks in the
2404 * configuration when a network is being added or removed. This is also called
2405 * if a priority for a network is changed.
2407 int wpa_config_update_prio_list(struct wpa_config
*config
)
2409 struct wpa_ssid
*ssid
;
2412 os_free(config
->pssid
);
2413 config
->pssid
= NULL
;
2414 config
->num_prio
= 0;
2416 ssid
= config
->ssid
;
2419 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2428 #ifdef IEEE8021X_EAPOL
2429 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2431 os_free(eap
->eap_methods
);
2432 bin_clear_free(eap
->identity
, eap
->identity_len
);
2433 os_free(eap
->anonymous_identity
);
2434 os_free(eap
->imsi_identity
);
2435 bin_clear_free(eap
->password
, eap
->password_len
);
2436 os_free(eap
->ca_cert
);
2437 os_free(eap
->ca_path
);
2438 os_free(eap
->client_cert
);
2439 os_free(eap
->private_key
);
2440 str_clear_free(eap
->private_key_passwd
);
2441 os_free(eap
->dh_file
);
2442 os_free(eap
->subject_match
);
2443 os_free(eap
->altsubject_match
);
2444 os_free(eap
->domain_suffix_match
);
2445 os_free(eap
->domain_match
);
2446 os_free(eap
->ca_cert2
);
2447 os_free(eap
->ca_path2
);
2448 os_free(eap
->client_cert2
);
2449 os_free(eap
->private_key2
);
2450 str_clear_free(eap
->private_key2_passwd
);
2451 os_free(eap
->dh_file2
);
2452 os_free(eap
->subject_match2
);
2453 os_free(eap
->altsubject_match2
);
2454 os_free(eap
->domain_suffix_match2
);
2455 os_free(eap
->domain_match2
);
2456 os_free(eap
->phase1
);
2457 os_free(eap
->phase2
);
2459 str_clear_free(eap
->pin
);
2460 os_free(eap
->engine_id
);
2461 os_free(eap
->key_id
);
2462 os_free(eap
->cert_id
);
2463 os_free(eap
->ca_cert_id
);
2464 os_free(eap
->key2_id
);
2465 os_free(eap
->cert2_id
);
2466 os_free(eap
->ca_cert2_id
);
2467 str_clear_free(eap
->pin2
);
2468 os_free(eap
->engine2_id
);
2470 os_free(eap
->pending_req_otp
);
2471 os_free(eap
->pac_file
);
2472 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2473 str_clear_free(eap
->external_sim_resp
);
2474 os_free(eap
->openssl_ciphers
);
2476 #endif /* IEEE8021X_EAPOL */
2480 * wpa_config_free_ssid - Free network/ssid configuration data
2481 * @ssid: Configuration data for the network
2483 * This function frees all resources allocated for the network configuration
2486 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2488 struct psk_list_entry
*psk
;
2490 os_free(ssid
->ssid
);
2491 str_clear_free(ssid
->passphrase
);
2492 os_free(ssid
->ext_psk
);
2493 str_clear_free(ssid
->sae_password
);
2494 os_free(ssid
->sae_password_id
);
2495 #ifdef IEEE8021X_EAPOL
2496 eap_peer_config_free(&ssid
->eap
);
2497 #endif /* IEEE8021X_EAPOL */
2498 os_free(ssid
->id_str
);
2499 os_free(ssid
->scan_freq
);
2500 os_free(ssid
->freq_list
);
2501 os_free(ssid
->bgscan
);
2502 os_free(ssid
->p2p_client_list
);
2503 os_free(ssid
->bssid_blacklist
);
2504 os_free(ssid
->bssid_whitelist
);
2505 #ifdef CONFIG_HT_OVERRIDES
2506 os_free(ssid
->ht_mcs
);
2507 #endif /* CONFIG_HT_OVERRIDES */
2509 os_free(ssid
->mesh_basic_rates
);
2510 #endif /* CONFIG_MESH */
2512 os_free(ssid
->roaming_consortium_selection
);
2513 #endif /* CONFIG_HS20 */
2514 os_free(ssid
->dpp_connector
);
2515 bin_clear_free(ssid
->dpp_netaccesskey
, ssid
->dpp_netaccesskey_len
);
2516 os_free(ssid
->dpp_csign
);
2517 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2519 dl_list_del(&psk
->list
);
2520 bin_clear_free(psk
, sizeof(*psk
));
2522 bin_clear_free(ssid
, sizeof(*ssid
));
2526 void wpa_config_free_cred(struct wpa_cred
*cred
)
2530 os_free(cred
->realm
);
2531 str_clear_free(cred
->username
);
2532 str_clear_free(cred
->password
);
2533 os_free(cred
->ca_cert
);
2534 os_free(cred
->client_cert
);
2535 os_free(cred
->private_key
);
2536 str_clear_free(cred
->private_key_passwd
);
2537 os_free(cred
->imsi
);
2538 str_clear_free(cred
->milenage
);
2539 for (i
= 0; i
< cred
->num_domain
; i
++)
2540 os_free(cred
->domain
[i
]);
2541 os_free(cred
->domain
);
2542 os_free(cred
->domain_suffix_match
);
2543 os_free(cred
->eap_method
);
2544 os_free(cred
->phase1
);
2545 os_free(cred
->phase2
);
2546 os_free(cred
->excluded_ssid
);
2547 os_free(cred
->roaming_partner
);
2548 os_free(cred
->provisioning_sp
);
2549 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2550 os_free(cred
->req_conn_capab_port
[i
]);
2551 os_free(cred
->req_conn_capab_port
);
2552 os_free(cred
->req_conn_capab_proto
);
2557 void wpa_config_flush_blobs(struct wpa_config
*config
)
2559 #ifndef CONFIG_NO_CONFIG_BLOBS
2560 struct wpa_config_blob
*blob
, *prev
;
2562 blob
= config
->blobs
;
2563 config
->blobs
= NULL
;
2567 wpa_config_free_blob(prev
);
2569 #endif /* CONFIG_NO_CONFIG_BLOBS */
2574 * wpa_config_free - Free configuration data
2575 * @config: Configuration data from wpa_config_read()
2577 * This function frees all resources allocated for the configuration data by
2578 * wpa_config_read().
2580 void wpa_config_free(struct wpa_config
*config
)
2582 struct wpa_ssid
*ssid
, *prev
= NULL
;
2583 struct wpa_cred
*cred
, *cprev
;
2586 ssid
= config
->ssid
;
2590 wpa_config_free_ssid(prev
);
2593 cred
= config
->cred
;
2597 wpa_config_free_cred(cprev
);
2600 wpa_config_flush_blobs(config
);
2602 wpabuf_free(config
->wps_vendor_ext_m1
);
2603 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2604 wpabuf_free(config
->wps_vendor_ext
[i
]);
2605 os_free(config
->ctrl_interface
);
2606 os_free(config
->ctrl_interface_group
);
2607 os_free(config
->opensc_engine_path
);
2608 os_free(config
->pkcs11_engine_path
);
2609 os_free(config
->pkcs11_module_path
);
2610 os_free(config
->openssl_ciphers
);
2611 os_free(config
->pcsc_reader
);
2612 str_clear_free(config
->pcsc_pin
);
2613 os_free(config
->driver_param
);
2614 os_free(config
->device_name
);
2615 os_free(config
->manufacturer
);
2616 os_free(config
->model_name
);
2617 os_free(config
->model_number
);
2618 os_free(config
->serial_number
);
2619 os_free(config
->config_methods
);
2620 os_free(config
->p2p_ssid_postfix
);
2621 os_free(config
->pssid
);
2622 os_free(config
->p2p_pref_chan
);
2623 os_free(config
->p2p_no_go_freq
.range
);
2624 os_free(config
->autoscan
);
2625 os_free(config
->freq_list
);
2626 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2627 wpabuf_free(config
->wps_nfc_dh_privkey
);
2628 wpabuf_free(config
->wps_nfc_dev_pw
);
2629 os_free(config
->ext_password_backend
);
2630 os_free(config
->sae_groups
);
2631 wpabuf_free(config
->ap_vendor_elements
);
2632 os_free(config
->osu_dir
);
2633 os_free(config
->bgscan
);
2634 os_free(config
->wowlan_triggers
);
2635 os_free(config
->fst_group_id
);
2636 os_free(config
->sched_scan_plans
);
2638 os_free(config
->non_pref_chan
);
2639 #endif /* CONFIG_MBO */
2646 * wpa_config_foreach_network - Iterate over each configured network
2647 * @config: Configuration data from wpa_config_read()
2648 * @func: Callback function to process each network
2649 * @arg: Opaque argument to pass to callback function
2651 * Iterate over the set of configured networks calling the specified
2652 * function for each item. We guard against callbacks removing the
2655 void wpa_config_foreach_network(struct wpa_config
*config
,
2656 void (*func
)(void *, struct wpa_ssid
*),
2659 struct wpa_ssid
*ssid
, *next
;
2661 ssid
= config
->ssid
;
2671 * wpa_config_get_network - Get configured network based on id
2672 * @config: Configuration data from wpa_config_read()
2673 * @id: Unique network id to search for
2674 * Returns: Network configuration or %NULL if not found
2676 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2678 struct wpa_ssid
*ssid
;
2680 ssid
= config
->ssid
;
2692 * wpa_config_add_network - Add a new network with empty configuration
2693 * @config: Configuration data from wpa_config_read()
2694 * Returns: The new network configuration or %NULL if operation failed
2696 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2699 struct wpa_ssid
*ssid
, *last
= NULL
;
2702 ssid
= config
->ssid
;
2711 ssid
= os_zalloc(sizeof(*ssid
));
2715 dl_list_init(&ssid
->psk_list
);
2719 config
->ssid
= ssid
;
2721 wpa_config_update_prio_list(config
);
2728 * wpa_config_remove_network - Remove a configured network based on id
2729 * @config: Configuration data from wpa_config_read()
2730 * @id: Unique network id to search for
2731 * Returns: 0 on success, or -1 if the network was not found
2733 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2735 struct wpa_ssid
*ssid
, *prev
= NULL
;
2737 ssid
= config
->ssid
;
2749 prev
->next
= ssid
->next
;
2751 config
->ssid
= ssid
->next
;
2753 wpa_config_update_prio_list(config
);
2754 wpa_config_free_ssid(ssid
);
2760 * wpa_config_set_network_defaults - Set network default values
2761 * @ssid: Pointer to network configuration data
2763 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
2765 ssid
->proto
= DEFAULT_PROTO
;
2766 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
2767 ssid
->group_cipher
= DEFAULT_GROUP
;
2768 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
2769 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
2771 #ifdef IEEE8021X_EAPOL
2772 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
2773 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
2774 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
2775 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
2776 #endif /* IEEE8021X_EAPOL */
2778 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
2779 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
2780 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
2781 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
2782 ssid
->mesh_rssi_threshold
= DEFAULT_MESH_RSSI_THRESHOLD
;
2783 #endif /* CONFIG_MESH */
2784 #ifdef CONFIG_HT_OVERRIDES
2785 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
2786 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
2787 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
2788 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
2789 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
2790 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
2791 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
2792 #endif /* CONFIG_HT_OVERRIDES */
2793 #ifdef CONFIG_VHT_OVERRIDES
2794 ssid
->vht_rx_mcs_nss_1
= -1;
2795 ssid
->vht_rx_mcs_nss_2
= -1;
2796 ssid
->vht_rx_mcs_nss_3
= -1;
2797 ssid
->vht_rx_mcs_nss_4
= -1;
2798 ssid
->vht_rx_mcs_nss_5
= -1;
2799 ssid
->vht_rx_mcs_nss_6
= -1;
2800 ssid
->vht_rx_mcs_nss_7
= -1;
2801 ssid
->vht_rx_mcs_nss_8
= -1;
2802 ssid
->vht_tx_mcs_nss_1
= -1;
2803 ssid
->vht_tx_mcs_nss_2
= -1;
2804 ssid
->vht_tx_mcs_nss_3
= -1;
2805 ssid
->vht_tx_mcs_nss_4
= -1;
2806 ssid
->vht_tx_mcs_nss_5
= -1;
2807 ssid
->vht_tx_mcs_nss_6
= -1;
2808 ssid
->vht_tx_mcs_nss_7
= -1;
2809 ssid
->vht_tx_mcs_nss_8
= -1;
2810 #endif /* CONFIG_VHT_OVERRIDES */
2811 ssid
->proactive_key_caching
= -1;
2812 #ifdef CONFIG_IEEE80211W
2813 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
2814 #endif /* CONFIG_IEEE80211W */
2815 #ifdef CONFIG_MACSEC
2816 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
2817 #endif /* CONFIG_MACSEC */
2818 ssid
->mac_addr
= -1;
2823 * wpa_config_set - Set a variable in network configuration
2824 * @ssid: Pointer to network configuration data
2825 * @var: Variable name, e.g., "ssid"
2826 * @value: Variable value
2827 * @line: Line number in configuration file or 0 if not used
2828 * Returns: 0 on success with possible change in the value, 1 on success with
2829 * no change to previously configured value, or -1 on failure
2831 * This function can be used to set network configuration variables based on
2832 * both the configuration file and management interface input. The value
2833 * parameter must be in the same format as the text-based configuration file is
2834 * using. For example, strings are using double quotation marks.
2836 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
2842 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
2845 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2846 const struct parse_data
*field
= &ssid_fields
[i
];
2847 if (os_strcmp(var
, field
->name
) != 0)
2850 ret
= field
->parser(field
, ssid
, line
, value
);
2853 wpa_printf(MSG_ERROR
, "Line %d: failed to "
2854 "parse %s '%s'.", line
, var
, value
);
2860 if (i
== NUM_SSID_FIELDS
) {
2862 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
2863 "'%s'.", line
, var
);
2872 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
2879 len
= os_strlen(value
);
2880 buf
= os_malloc(len
+ 3);
2884 os_memcpy(buf
+ 1, value
, len
);
2886 buf
[len
+ 2] = '\0';
2887 ret
= wpa_config_set(ssid
, var
, buf
, 0);
2894 * wpa_config_get_all - Get all options from network configuration
2895 * @ssid: Pointer to network configuration data
2896 * @get_keys: Determines if keys/passwords will be included in returned list
2897 * (if they may be exported)
2898 * Returns: %NULL terminated list of all set keys and their values in the form
2899 * of [key1, val1, key2, val2, ... , NULL]
2901 * This function can be used to get list of all configured network properties.
2902 * The caller is responsible for freeing the returned list and all its
2905 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
2907 #ifdef NO_CONFIG_WRITE
2909 #else /* NO_CONFIG_WRITE */
2910 const struct parse_data
*field
;
2916 get_keys
= get_keys
&& ssid
->export_keys
;
2918 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
2923 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2924 field
= &ssid_fields
[i
];
2925 if (field
->key_data
&& !get_keys
)
2927 value
= field
->writer(field
, ssid
);
2930 if (os_strlen(value
) == 0) {
2935 key
= os_strdup(field
->name
);
2941 props
[fields_num
* 2] = key
;
2942 props
[fields_num
* 2 + 1] = value
;
2950 for (i
= 0; props
[i
]; i
++)
2954 #endif /* NO_CONFIG_WRITE */
2958 #ifndef NO_CONFIG_WRITE
2960 * wpa_config_get - Get a variable in network configuration
2961 * @ssid: Pointer to network configuration data
2962 * @var: Variable name, e.g., "ssid"
2963 * Returns: Value of the variable or %NULL on failure
2965 * This function can be used to get network configuration variables. The
2966 * returned value is a copy of the configuration variable in text format, i.e,.
2967 * the same format that the text-based configuration file and wpa_config_set()
2968 * are using for the value. The caller is responsible for freeing the returned
2971 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
2975 if (ssid
== NULL
|| var
== NULL
)
2978 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2979 const struct parse_data
*field
= &ssid_fields
[i
];
2980 if (os_strcmp(var
, field
->name
) == 0) {
2981 char *ret
= field
->writer(field
, ssid
);
2983 if (ret
&& has_newline(ret
)) {
2984 wpa_printf(MSG_ERROR
,
2985 "Found newline in value for %s; not returning it",
3000 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
3001 * @ssid: Pointer to network configuration data
3002 * @var: Variable name, e.g., "ssid"
3003 * Returns: Value of the variable or %NULL on failure
3005 * This function can be used to get network configuration variable like
3006 * wpa_config_get(). The only difference is that this functions does not expose
3007 * key/password material from the configuration. In case a key/password field
3008 * is requested, the returned value is an empty string or %NULL if the variable
3009 * is not set or "*" if the variable is set (regardless of its value). The
3010 * returned value is a copy of the configuration variable in text format, i.e,.
3011 * the same format that the text-based configuration file and wpa_config_set()
3012 * are using for the value. The caller is responsible for freeing the returned
3015 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
3019 if (ssid
== NULL
|| var
== NULL
)
3022 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3023 const struct parse_data
*field
= &ssid_fields
[i
];
3024 if (os_strcmp(var
, field
->name
) == 0) {
3025 char *res
= field
->writer(field
, ssid
);
3026 if (field
->key_data
) {
3027 if (res
&& res
[0]) {
3028 wpa_printf(MSG_DEBUG
, "Do not allow "
3029 "key_data field to be "
3031 str_clear_free(res
);
3032 return os_strdup("*");
3044 #endif /* NO_CONFIG_WRITE */
3048 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
3049 * @ssid: Pointer to network configuration data
3051 * This function must be called to update WPA PSK when either SSID or the
3052 * passphrase has changed for the network configuration.
3054 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
3056 #ifndef CONFIG_NO_PBKDF2
3057 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
3058 ssid
->psk
, PMK_LEN
);
3059 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
3060 ssid
->psk
, PMK_LEN
);
3062 #endif /* CONFIG_NO_PBKDF2 */
3066 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
3071 int *ports
, *nports
;
3073 unsigned int num_ports
;
3075 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
3076 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
3079 cred
->req_conn_capab_proto
= proto
;
3081 port
= os_realloc_array(cred
->req_conn_capab_port
,
3082 cred
->num_req_conn_capab
+ 1, sizeof(int *));
3085 cred
->req_conn_capab_port
= port
;
3087 proto
[cred
->num_req_conn_capab
] = atoi(value
);
3089 pos
= os_strchr(value
, ':');
3091 port
[cred
->num_req_conn_capab
] = NULL
;
3092 cred
->num_req_conn_capab
++;
3101 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3102 if (nports
== NULL
) {
3107 ports
[num_ports
++] = atoi(pos
);
3109 pos
= os_strchr(pos
, ',');
3115 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3116 if (nports
== NULL
) {
3121 ports
[num_ports
] = -1;
3123 port
[cred
->num_req_conn_capab
] = ports
;
3124 cred
->num_req_conn_capab
++;
3129 static int wpa_config_set_cred_roaming_consortiums(struct wpa_cred
*cred
,
3132 u8 roaming_consortiums
[MAX_ROAMING_CONS
][MAX_ROAMING_CONS_OI_LEN
];
3133 size_t roaming_consortiums_len
[MAX_ROAMING_CONS
];
3134 unsigned int num_roaming_consortiums
= 0;
3135 const char *pos
, *end
;
3138 os_memset(roaming_consortiums
, 0, sizeof(roaming_consortiums
));
3139 os_memset(roaming_consortiums_len
, 0, sizeof(roaming_consortiums_len
));
3141 for (pos
= value
;;) {
3142 end
= os_strchr(pos
, ',');
3143 len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
3144 if (!end
&& len
== 0)
3146 if (len
== 0 || (len
& 1) != 0 ||
3147 len
/ 2 > MAX_ROAMING_CONS_OI_LEN
||
3149 roaming_consortiums
[num_roaming_consortiums
],
3151 wpa_printf(MSG_INFO
,
3152 "Invalid roaming_consortiums entry: %s",
3156 roaming_consortiums_len
[num_roaming_consortiums
] = len
/ 2;
3157 num_roaming_consortiums
++;
3162 if (num_roaming_consortiums
>= MAX_ROAMING_CONS
) {
3163 wpa_printf(MSG_INFO
,
3164 "Too many roaming_consortiums OIs");
3171 os_memcpy(cred
->roaming_consortiums
, roaming_consortiums
,
3172 sizeof(roaming_consortiums
));
3173 os_memcpy(cred
->roaming_consortiums_len
, roaming_consortiums_len
,
3174 sizeof(roaming_consortiums_len
));
3175 cred
->num_roaming_consortiums
= num_roaming_consortiums
;
3181 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
3182 const char *value
, int line
)
3188 if (os_strcmp(var
, "temporary") == 0) {
3189 cred
->temporary
= atoi(value
);
3193 if (os_strcmp(var
, "priority") == 0) {
3194 cred
->priority
= atoi(value
);
3198 if (os_strcmp(var
, "sp_priority") == 0) {
3199 int prio
= atoi(value
);
3200 if (prio
< 0 || prio
> 255)
3202 cred
->sp_priority
= prio
;
3206 if (os_strcmp(var
, "pcsc") == 0) {
3207 cred
->pcsc
= atoi(value
);
3211 if (os_strcmp(var
, "eap") == 0) {
3212 struct eap_method_type method
;
3213 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3214 if (method
.vendor
== EAP_VENDOR_IETF
&&
3215 method
.method
== EAP_TYPE_NONE
) {
3216 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3217 "for a credential", line
, value
);
3220 os_free(cred
->eap_method
);
3221 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3222 if (cred
->eap_method
== NULL
)
3224 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3228 if (os_strcmp(var
, "password") == 0 &&
3229 os_strncmp(value
, "ext:", 4) == 0) {
3230 if (has_newline(value
))
3232 str_clear_free(cred
->password
);
3233 cred
->password
= os_strdup(value
);
3234 cred
->ext_password
= 1;
3238 if (os_strcmp(var
, "update_identifier") == 0) {
3239 cred
->update_identifier
= atoi(value
);
3243 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3244 cred
->min_dl_bandwidth_home
= atoi(value
);
3248 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3249 cred
->min_ul_bandwidth_home
= atoi(value
);
3253 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3254 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3258 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3259 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3263 if (os_strcmp(var
, "max_bss_load") == 0) {
3264 cred
->max_bss_load
= atoi(value
);
3268 if (os_strcmp(var
, "req_conn_capab") == 0)
3269 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3271 if (os_strcmp(var
, "ocsp") == 0) {
3272 cred
->ocsp
= atoi(value
);
3276 if (os_strcmp(var
, "sim_num") == 0) {
3277 cred
->sim_num
= atoi(value
);
3281 val
= wpa_config_parse_string(value
, &len
);
3283 (os_strcmp(var
, "excluded_ssid") != 0 &&
3284 os_strcmp(var
, "roaming_consortium") != 0 &&
3285 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3286 has_newline(val
))) {
3287 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3288 "value '%s'.", line
, var
, value
);
3293 if (os_strcmp(var
, "realm") == 0) {
3294 os_free(cred
->realm
);
3299 if (os_strcmp(var
, "username") == 0) {
3300 str_clear_free(cred
->username
);
3301 cred
->username
= val
;
3305 if (os_strcmp(var
, "password") == 0) {
3306 str_clear_free(cred
->password
);
3307 cred
->password
= val
;
3308 cred
->ext_password
= 0;
3312 if (os_strcmp(var
, "ca_cert") == 0) {
3313 os_free(cred
->ca_cert
);
3314 cred
->ca_cert
= val
;
3318 if (os_strcmp(var
, "client_cert") == 0) {
3319 os_free(cred
->client_cert
);
3320 cred
->client_cert
= val
;
3324 if (os_strcmp(var
, "private_key") == 0) {
3325 os_free(cred
->private_key
);
3326 cred
->private_key
= val
;
3330 if (os_strcmp(var
, "private_key_passwd") == 0) {
3331 str_clear_free(cred
->private_key_passwd
);
3332 cred
->private_key_passwd
= val
;
3336 if (os_strcmp(var
, "imsi") == 0) {
3337 os_free(cred
->imsi
);
3342 if (os_strcmp(var
, "milenage") == 0) {
3343 str_clear_free(cred
->milenage
);
3344 cred
->milenage
= val
;
3348 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3349 os_free(cred
->domain_suffix_match
);
3350 cred
->domain_suffix_match
= val
;
3354 if (os_strcmp(var
, "domain") == 0) {
3356 new_domain
= os_realloc_array(cred
->domain
,
3357 cred
->num_domain
+ 1,
3359 if (new_domain
== NULL
) {
3363 new_domain
[cred
->num_domain
++] = val
;
3364 cred
->domain
= new_domain
;
3368 if (os_strcmp(var
, "phase1") == 0) {
3369 os_free(cred
->phase1
);
3374 if (os_strcmp(var
, "phase2") == 0) {
3375 os_free(cred
->phase2
);
3380 if (os_strcmp(var
, "roaming_consortium") == 0) {
3381 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3382 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3383 "roaming_consortium length %d (3..15 "
3384 "expected)", line
, (int) len
);
3388 os_memcpy(cred
->roaming_consortium
, val
, len
);
3389 cred
->roaming_consortium_len
= len
;
3394 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3395 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3397 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3398 "required_roaming_consortium length %d "
3399 "(3..15 expected)", line
, (int) len
);
3403 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3404 cred
->required_roaming_consortium_len
= len
;
3409 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3410 res
= wpa_config_set_cred_roaming_consortiums(cred
, val
);
3412 wpa_printf(MSG_ERROR
,
3413 "Line %d: invalid roaming_consortiums",
3419 if (os_strcmp(var
, "excluded_ssid") == 0) {
3420 struct excluded_ssid
*e
;
3422 if (len
> SSID_MAX_LEN
) {
3423 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3424 "excluded_ssid length %d", line
, (int) len
);
3429 e
= os_realloc_array(cred
->excluded_ssid
,
3430 cred
->num_excluded_ssid
+ 1,
3431 sizeof(struct excluded_ssid
));
3436 cred
->excluded_ssid
= e
;
3438 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3439 os_memcpy(e
->ssid
, val
, len
);
3447 if (os_strcmp(var
, "roaming_partner") == 0) {
3448 struct roaming_partner
*p
;
3451 p
= os_realloc_array(cred
->roaming_partner
,
3452 cred
->num_roaming_partner
+ 1,
3453 sizeof(struct roaming_partner
));
3458 cred
->roaming_partner
= p
;
3460 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3462 pos
= os_strchr(val
, ',');
3468 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3472 os_memcpy(p
->fqdn
, val
, pos
- val
);
3474 p
->exact_match
= atoi(pos
);
3476 pos
= os_strchr(pos
, ',');
3483 p
->priority
= atoi(pos
);
3485 pos
= os_strchr(pos
, ',');
3492 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3496 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3498 cred
->num_roaming_partner
++;
3504 if (os_strcmp(var
, "provisioning_sp") == 0) {
3505 os_free(cred
->provisioning_sp
);
3506 cred
->provisioning_sp
= val
;
3511 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3521 static char * alloc_int_str(int val
)
3523 const unsigned int bufsize
= 20;
3527 buf
= os_malloc(bufsize
);
3530 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3531 if (os_snprintf_error(bufsize
, res
)) {
3539 static char * alloc_strdup(const char *str
)
3543 return os_strdup(str
);
3547 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3549 if (os_strcmp(var
, "temporary") == 0)
3550 return alloc_int_str(cred
->temporary
);
3552 if (os_strcmp(var
, "priority") == 0)
3553 return alloc_int_str(cred
->priority
);
3555 if (os_strcmp(var
, "sp_priority") == 0)
3556 return alloc_int_str(cred
->sp_priority
);
3558 if (os_strcmp(var
, "pcsc") == 0)
3559 return alloc_int_str(cred
->pcsc
);
3561 if (os_strcmp(var
, "eap") == 0) {
3562 if (!cred
->eap_method
)
3564 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3565 cred
->eap_method
[0].method
));
3568 if (os_strcmp(var
, "update_identifier") == 0)
3569 return alloc_int_str(cred
->update_identifier
);
3571 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3572 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3574 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3575 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3577 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3578 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3580 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3581 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3583 if (os_strcmp(var
, "max_bss_load") == 0)
3584 return alloc_int_str(cred
->max_bss_load
);
3586 if (os_strcmp(var
, "req_conn_capab") == 0) {
3588 char *buf
, *end
, *pos
;
3591 if (!cred
->num_req_conn_capab
)
3594 buf
= os_malloc(4000);
3599 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3602 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3604 cred
->req_conn_capab_proto
[i
]);
3605 if (os_snprintf_error(end
- pos
, ret
))
3609 ports
= cred
->req_conn_capab_port
[i
];
3612 for (j
= 0; ports
[j
] != -1; j
++) {
3613 ret
= os_snprintf(pos
, end
- pos
,
3617 if (os_snprintf_error(end
- pos
, ret
))
3627 if (os_strcmp(var
, "ocsp") == 0)
3628 return alloc_int_str(cred
->ocsp
);
3630 if (os_strcmp(var
, "realm") == 0)
3631 return alloc_strdup(cred
->realm
);
3633 if (os_strcmp(var
, "username") == 0)
3634 return alloc_strdup(cred
->username
);
3636 if (os_strcmp(var
, "password") == 0) {
3637 if (!cred
->password
)
3639 return alloc_strdup("*");
3642 if (os_strcmp(var
, "ca_cert") == 0)
3643 return alloc_strdup(cred
->ca_cert
);
3645 if (os_strcmp(var
, "client_cert") == 0)
3646 return alloc_strdup(cred
->client_cert
);
3648 if (os_strcmp(var
, "private_key") == 0)
3649 return alloc_strdup(cred
->private_key
);
3651 if (os_strcmp(var
, "private_key_passwd") == 0) {
3652 if (!cred
->private_key_passwd
)
3654 return alloc_strdup("*");
3657 if (os_strcmp(var
, "imsi") == 0)
3658 return alloc_strdup(cred
->imsi
);
3660 if (os_strcmp(var
, "milenage") == 0) {
3661 if (!(cred
->milenage
))
3663 return alloc_strdup("*");
3666 if (os_strcmp(var
, "domain_suffix_match") == 0)
3667 return alloc_strdup(cred
->domain_suffix_match
);
3669 if (os_strcmp(var
, "domain") == 0) {
3671 char *buf
, *end
, *pos
;
3674 if (!cred
->num_domain
)
3677 buf
= os_malloc(4000);
3683 for (i
= 0; i
< cred
->num_domain
; i
++) {
3684 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3685 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3686 if (os_snprintf_error(end
- pos
, ret
))
3694 if (os_strcmp(var
, "phase1") == 0)
3695 return alloc_strdup(cred
->phase1
);
3697 if (os_strcmp(var
, "phase2") == 0)
3698 return alloc_strdup(cred
->phase2
);
3700 if (os_strcmp(var
, "roaming_consortium") == 0) {
3704 if (!cred
->roaming_consortium_len
)
3706 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3707 buf
= os_malloc(buflen
);
3710 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3711 cred
->roaming_consortium_len
);
3715 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3719 if (!cred
->required_roaming_consortium_len
)
3721 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3722 buf
= os_malloc(buflen
);
3725 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
3726 cred
->required_roaming_consortium_len
);
3730 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3735 if (!cred
->num_roaming_consortiums
)
3737 buflen
= cred
->num_roaming_consortiums
*
3738 MAX_ROAMING_CONS_OI_LEN
* 2 + 1;
3739 buf
= os_malloc(buflen
);
3743 for (i
= 0; i
< cred
->num_roaming_consortiums
; i
++) {
3746 pos
+= wpa_snprintf_hex(
3747 pos
, buf
+ buflen
- pos
,
3748 cred
->roaming_consortiums
[i
],
3749 cred
->roaming_consortiums_len
[i
]);
3755 if (os_strcmp(var
, "excluded_ssid") == 0) {
3757 char *buf
, *end
, *pos
;
3759 if (!cred
->num_excluded_ssid
)
3762 buf
= os_malloc(4000);
3768 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
3769 struct excluded_ssid
*e
;
3772 e
= &cred
->excluded_ssid
[i
];
3773 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3775 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
3776 if (os_snprintf_error(end
- pos
, ret
))
3784 if (os_strcmp(var
, "roaming_partner") == 0) {
3786 char *buf
, *end
, *pos
;
3788 if (!cred
->num_roaming_partner
)
3791 buf
= os_malloc(4000);
3797 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
3798 struct roaming_partner
*p
;
3801 p
= &cred
->roaming_partner
[i
];
3802 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
3804 p
->fqdn
, p
->exact_match
, p
->priority
,
3806 if (os_snprintf_error(end
- pos
, ret
))
3814 if (os_strcmp(var
, "provisioning_sp") == 0)
3815 return alloc_strdup(cred
->provisioning_sp
);
3821 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
3823 struct wpa_cred
*cred
;
3825 cred
= config
->cred
;
3836 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
3839 struct wpa_cred
*cred
, *last
= NULL
;
3842 cred
= config
->cred
;
3851 cred
= os_zalloc(sizeof(*cred
));
3855 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
3859 config
->cred
= cred
;
3865 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
3867 struct wpa_cred
*cred
, *prev
= NULL
;
3869 cred
= config
->cred
;
3881 prev
->next
= cred
->next
;
3883 config
->cred
= cred
->next
;
3885 wpa_config_free_cred(cred
);
3890 #ifndef CONFIG_NO_CONFIG_BLOBS
3892 * wpa_config_get_blob - Get a named configuration blob
3893 * @config: Configuration data from wpa_config_read()
3894 * @name: Name of the blob
3895 * Returns: Pointer to blob data or %NULL if not found
3897 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
3900 struct wpa_config_blob
*blob
= config
->blobs
;
3903 if (os_strcmp(blob
->name
, name
) == 0)
3912 * wpa_config_set_blob - Set or add a named configuration blob
3913 * @config: Configuration data from wpa_config_read()
3914 * @blob: New value for the blob
3916 * Adds a new configuration blob or replaces the current value of an existing
3919 void wpa_config_set_blob(struct wpa_config
*config
,
3920 struct wpa_config_blob
*blob
)
3922 wpa_config_remove_blob(config
, blob
->name
);
3923 blob
->next
= config
->blobs
;
3924 config
->blobs
= blob
;
3929 * wpa_config_free_blob - Free blob data
3930 * @blob: Pointer to blob to be freed
3932 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
3935 os_free(blob
->name
);
3936 bin_clear_free(blob
->data
, blob
->len
);
3943 * wpa_config_remove_blob - Remove a named configuration blob
3944 * @config: Configuration data from wpa_config_read()
3945 * @name: Name of the blob to remove
3946 * Returns: 0 if blob was removed or -1 if blob was not found
3948 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
3950 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
3953 if (os_strcmp(pos
->name
, name
) == 0) {
3955 prev
->next
= pos
->next
;
3957 config
->blobs
= pos
->next
;
3958 wpa_config_free_blob(pos
);
3967 #endif /* CONFIG_NO_CONFIG_BLOBS */
3971 * wpa_config_alloc_empty - Allocate an empty configuration
3972 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3974 * @driver_param: Driver parameters
3975 * Returns: Pointer to allocated configuration data or %NULL on failure
3977 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
3978 const char *driver_param
)
3980 struct wpa_config
*config
;
3981 const int aCWmin
= 4, aCWmax
= 10;
3982 const struct hostapd_wmm_ac_params ac_bk
=
3983 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
3984 const struct hostapd_wmm_ac_params ac_be
=
3985 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
3986 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
3987 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
3988 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
3989 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
3991 config
= os_zalloc(sizeof(*config
));
3994 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
3995 config
->ap_scan
= DEFAULT_AP_SCAN
;
3996 config
->user_mpm
= DEFAULT_USER_MPM
;
3997 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
3998 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
3999 config
->dot11RSNASAERetransPeriod
=
4000 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
4001 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
4002 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
4003 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
4004 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
4005 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
4006 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
4007 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
4008 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
4009 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
4010 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
4011 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
4012 config
->ap_isolate
= DEFAULT_AP_ISOLATE
;
4013 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
4014 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
4015 config
->wmm_ac_params
[0] = ac_be
;
4016 config
->wmm_ac_params
[1] = ac_bk
;
4017 config
->wmm_ac_params
[2] = ac_vi
;
4018 config
->wmm_ac_params
[3] = ac_vo
;
4019 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
4020 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4021 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
4022 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
4023 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
4026 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
4027 config
->disassoc_imminent_rssi_threshold
=
4028 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
4029 config
->oce
= DEFAULT_OCE_SUPPORT
;
4030 #endif /* CONFIG_MBO */
4033 config
->ctrl_interface
= os_strdup(ctrl_interface
);
4035 config
->driver_param
= os_strdup(driver_param
);
4036 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4042 #ifndef CONFIG_NO_STDOUT_DEBUG
4044 * wpa_config_debug_dump_networks - Debug dump of configured networks
4045 * @config: Configuration data from wpa_config_read()
4047 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
4050 struct wpa_ssid
*ssid
;
4052 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
4053 ssid
= config
->pssid
[prio
];
4054 wpa_printf(MSG_DEBUG
, "Priority group %d",
4057 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
4059 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
4064 #endif /* CONFIG_NO_STDOUT_DEBUG */
4067 struct global_parse_data
{
4069 int (*parser
)(const struct global_parse_data
*data
,
4070 struct wpa_config
*config
, int line
, const char *value
);
4071 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
4072 char *buf
, size_t buflen
, int pretty_print
);
4073 void *param1
, *param2
, *param3
;
4074 unsigned int changed_flag
;
4078 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
4079 struct wpa_config
*config
, int line
,
4085 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
4086 val
= strtol(pos
, &end
, 0);
4088 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
4094 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
4096 if (data
->param2
&& *dst
< (long) data
->param2
) {
4097 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
4098 "min_value=%ld)", line
, data
->name
, *dst
,
4099 (long) data
->param2
);
4100 *dst
= (long) data
->param2
;
4104 if (data
->param3
&& *dst
> (long) data
->param3
) {
4105 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
4106 "max_value=%ld)", line
, data
->name
, *dst
,
4107 (long) data
->param3
);
4108 *dst
= (long) data
->param3
;
4116 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
4117 struct wpa_config
*config
, int line
,
4123 len
= os_strlen(pos
);
4124 if (data
->param2
&& len
< (size_t) data
->param2
) {
4125 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
4126 "min_len=%ld)", line
, data
->name
,
4127 (unsigned long) len
, (long) data
->param2
);
4131 if (data
->param3
&& len
> (size_t) data
->param3
) {
4132 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
4133 "max_len=%ld)", line
, data
->name
,
4134 (unsigned long) len
, (long) data
->param3
);
4138 if (has_newline(pos
)) {
4139 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
4144 tmp
= os_strdup(pos
);
4148 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
4151 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
4157 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
4158 struct wpa_config
*config
, int line
,
4165 tmp
= wpa_config_parse_string(pos
, &len
);
4167 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
4172 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
4178 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
4179 struct wpa_config
*config
, int line
,
4182 struct wpabuf
**dst
, *tmp
;
4184 tmp
= wpabuf_parse_bin(pos
);
4188 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
4191 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
4197 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
4198 struct wpa_config
*config
, int line
,
4203 freqs
= wpa_config_parse_int_array(value
);
4206 if (freqs
[0] == 0) {
4210 os_free(config
->freq_list
);
4211 config
->freq_list
= freqs
;
4217 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
4218 struct wpa_config
*config
, int line
,
4222 struct hostapd_ip_addr addr
;
4224 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
4226 if (addr
.af
!= AF_INET
)
4229 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
4230 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4231 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4232 WPA_GET_BE32((u8
*) dst
));
4236 #endif /* CONFIG_P2P */
4239 static int wpa_config_process_country(const struct global_parse_data
*data
,
4240 struct wpa_config
*config
, int line
,
4243 if (!pos
[0] || !pos
[1]) {
4244 wpa_printf(MSG_DEBUG
, "Invalid country set");
4247 config
->country
[0] = pos
[0];
4248 config
->country
[1] = pos
[1];
4249 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4250 config
->country
[0], config
->country
[1]);
4255 static int wpa_config_process_load_dynamic_eap(
4256 const struct global_parse_data
*data
, struct wpa_config
*config
,
4257 int line
, const char *so
)
4260 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4261 ret
= eap_peer_method_load(so
);
4263 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4266 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4267 "method '%s'.", line
, so
);
4277 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4278 struct wpa_config
*config
, int line
,
4282 if (uuid_str2bin(pos
, config
->uuid
)) {
4283 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4286 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4287 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4292 static int wpa_config_process_device_type(
4293 const struct global_parse_data
*data
,
4294 struct wpa_config
*config
, int line
, const char *pos
)
4296 return wps_dev_type_str2bin(pos
, config
->device_type
);
4300 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4301 struct wpa_config
*config
, int line
,
4304 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4305 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4308 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4309 WPA_GET_BE32(config
->os_version
));
4314 static int wpa_config_process_wps_vendor_ext_m1(
4315 const struct global_parse_data
*data
,
4316 struct wpa_config
*config
, int line
, const char *pos
)
4319 int len
= os_strlen(pos
) / 2;
4323 wpa_printf(MSG_ERROR
, "Line %d: "
4324 "invalid wps_vendor_ext_m1", line
);
4328 tmp
= wpabuf_alloc(len
);
4330 p
= wpabuf_put(tmp
, len
);
4332 if (hexstr2bin(pos
, p
, len
)) {
4333 wpa_printf(MSG_ERROR
, "Line %d: "
4334 "invalid wps_vendor_ext_m1", line
);
4339 wpabuf_free(config
->wps_vendor_ext_m1
);
4340 config
->wps_vendor_ext_m1
= tmp
;
4342 wpa_printf(MSG_ERROR
, "Can not allocate "
4343 "memory for wps_vendor_ext_m1");
4350 #endif /* CONFIG_WPS */
4353 static int wpa_config_process_sec_device_type(
4354 const struct global_parse_data
*data
,
4355 struct wpa_config
*config
, int line
, const char *pos
)
4359 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4360 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4365 idx
= config
->num_sec_device_types
;
4367 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4370 config
->num_sec_device_types
++;
4375 static int wpa_config_process_p2p_pref_chan(
4376 const struct global_parse_data
*data
,
4377 struct wpa_config
*config
, int line
, const char *pos
)
4379 struct p2p_channel
*pref
= NULL
, *n
;
4380 unsigned int num
= 0;
4384 /* format: class:chan,class:chan,... */
4387 op_class
= atoi(pos
);
4388 pos2
= os_strchr(pos
, ':');
4394 n
= os_realloc_array(pref
, num
+ 1,
4395 sizeof(struct p2p_channel
));
4399 pref
[num
].op_class
= op_class
;
4400 pref
[num
].chan
= chan
;
4403 pos
= os_strchr(pos2
, ',');
4409 os_free(config
->p2p_pref_chan
);
4410 config
->p2p_pref_chan
= pref
;
4411 config
->num_p2p_pref_chan
= num
;
4412 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4413 (u8
*) config
->p2p_pref_chan
,
4414 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4420 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4425 static int wpa_config_process_p2p_no_go_freq(
4426 const struct global_parse_data
*data
,
4427 struct wpa_config
*config
, int line
, const char *pos
)
4431 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4433 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4437 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4438 config
->p2p_no_go_freq
.num
);
4443 #endif /* CONFIG_P2P */
4446 static int wpa_config_process_hessid(
4447 const struct global_parse_data
*data
,
4448 struct wpa_config
*config
, int line
, const char *pos
)
4450 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4451 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4460 static int wpa_config_process_sae_groups(
4461 const struct global_parse_data
*data
,
4462 struct wpa_config
*config
, int line
, const char *pos
)
4464 int *groups
= wpa_config_parse_int_array(pos
);
4465 if (groups
== NULL
) {
4466 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4471 os_free(config
->sae_groups
);
4472 config
->sae_groups
= groups
;
4478 static int wpa_config_process_ap_vendor_elements(
4479 const struct global_parse_data
*data
,
4480 struct wpa_config
*config
, int line
, const char *pos
)
4483 int len
= os_strlen(pos
) / 2;
4487 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4492 tmp
= wpabuf_alloc(len
);
4494 p
= wpabuf_put(tmp
, len
);
4496 if (hexstr2bin(pos
, p
, len
)) {
4497 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4498 "ap_vendor_elements", line
);
4503 wpabuf_free(config
->ap_vendor_elements
);
4504 config
->ap_vendor_elements
= tmp
;
4506 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4507 "ap_vendor_elements");
4515 #ifdef CONFIG_CTRL_IFACE
4516 static int wpa_config_process_no_ctrl_interface(
4517 const struct global_parse_data
*data
,
4518 struct wpa_config
*config
, int line
, const char *pos
)
4520 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4521 os_free(config
->ctrl_interface
);
4522 config
->ctrl_interface
= NULL
;
4525 #endif /* CONFIG_CTRL_IFACE */
4528 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4529 long offset
, char *buf
, size_t buflen
,
4532 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4535 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4536 return os_snprintf(buf
, buflen
, "%d", *val
);
4540 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4541 long offset
, char *buf
, size_t buflen
,
4544 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4548 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4549 *val
? *val
: "null");
4553 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4554 if (os_snprintf_error(buflen
, res
))
4562 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4563 long offset
, char *buf
, size_t buflen
,
4566 void *val
= ((u8
*) config
) + (long) offset
;
4568 char addr
[INET_ADDRSTRLEN
];
4570 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4574 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4576 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4578 if (os_snprintf_error(buflen
, res
))
4583 #endif /* CONFIG_P2P */
4589 /* OFFSET: Get offset of a variable within the wpa_config structure */
4590 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4592 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4593 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4594 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4595 #define INT(f) _INT(f), NULL, NULL
4596 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4597 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4598 #define STR(f) _STR(f), NULL, NULL
4599 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4600 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4601 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4602 OFFSET(f), NULL, NULL
4604 static const struct global_parse_data global_fields
[] = {
4605 #ifdef CONFIG_CTRL_IFACE
4606 { STR(ctrl_interface
), 0 },
4607 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4608 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4609 #endif /* CONFIG_CTRL_IFACE */
4610 #ifdef CONFIG_MACSEC
4611 { INT_RANGE(eapol_version
, 1, 3), 0 },
4612 #else /* CONFIG_MACSEC */
4613 { INT_RANGE(eapol_version
, 1, 2), 0 },
4614 #endif /* CONFIG_MACSEC */
4615 { INT(ap_scan
), 0 },
4616 { FUNC(bgscan
), 0 },
4618 { INT(user_mpm
), 0 },
4619 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4620 { INT(mesh_max_inactivity
), 0 },
4621 { INT(dot11RSNASAERetransPeriod
), 0 },
4622 #endif /* CONFIG_MESH */
4623 { INT(disable_scan_offload
), 0 },
4624 { INT(fast_reauth
), 0 },
4625 { STR(opensc_engine_path
), 0 },
4626 { STR(pkcs11_engine_path
), 0 },
4627 { STR(pkcs11_module_path
), 0 },
4628 { STR(openssl_ciphers
), 0 },
4629 { STR(pcsc_reader
), 0 },
4630 { STR(pcsc_pin
), 0 },
4631 { INT(external_sim
), 0 },
4632 { STR(driver_param
), 0 },
4633 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4634 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4635 { INT(dot11RSNAConfigSATimeout
), 0 },
4636 #ifndef CONFIG_NO_CONFIG_WRITE
4637 { INT(update_config
), 0 },
4638 #endif /* CONFIG_NO_CONFIG_WRITE */
4639 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4641 { FUNC(uuid
), CFG_CHANGED_UUID
},
4642 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4643 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4644 CFG_CHANGED_DEVICE_NAME
},
4645 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4646 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4647 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4648 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4649 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4650 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4651 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4652 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4653 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4654 #endif /* CONFIG_WPS */
4656 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4657 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4658 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4659 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4660 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4661 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4662 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4663 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4664 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4665 { INT(p2p_group_idle
), 0 },
4666 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4667 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4668 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4669 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4670 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4671 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4672 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4673 { INT(p2p_go_ht40
), 0 },
4674 { INT(p2p_go_vht
), 0 },
4675 { INT(p2p_disabled
), 0 },
4676 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4677 { INT(p2p_no_group_iface
), 0 },
4678 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4679 { IPV4(ip_addr_go
), 0 },
4680 { IPV4(ip_addr_mask
), 0 },
4681 { IPV4(ip_addr_start
), 0 },
4682 { IPV4(ip_addr_end
), 0 },
4683 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4684 #endif /* CONFIG_P2P */
4685 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4686 { INT(bss_max_count
), 0 },
4687 { INT(bss_expiration_age
), 0 },
4688 { INT(bss_expiration_scan_count
), 0 },
4689 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4690 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4691 { INT(max_num_sta
), 0 },
4692 { INT_RANGE(ap_isolate
, 0, 1), 0 },
4693 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4695 { INT_RANGE(hs20
, 0, 1), 0 },
4696 #endif /* CONFIG_HS20 */
4697 { INT_RANGE(interworking
, 0, 1), 0 },
4698 { FUNC(hessid
), 0 },
4699 { INT_RANGE(access_network_type
, 0, 15), 0 },
4700 { INT_RANGE(go_interworking
, 0, 1), 0 },
4701 { INT_RANGE(go_access_network_type
, 0, 15), 0 },
4702 { INT_RANGE(go_internet
, 0, 1), 0 },
4703 { INT_RANGE(go_venue_group
, 0, 255), 0 },
4704 { INT_RANGE(go_venue_type
, 0, 255), 0 },
4705 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
4706 { STR(autoscan
), 0 },
4707 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
4708 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4709 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4710 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4711 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4712 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
4713 { INT(p2p_go_max_inactivity
), 0 },
4714 { INT_RANGE(auto_interworking
, 0, 1), 0 },
4717 { FUNC(sae_groups
), 0 },
4718 { INT(dtim_period
), 0 },
4719 { INT(beacon_int
), 0 },
4720 { FUNC(ap_vendor_elements
), 0 },
4721 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
4722 { FUNC(freq_list
), 0 },
4723 { INT(scan_cur_freq
), 0 },
4724 { INT(sched_scan_interval
), 0 },
4725 { INT(sched_scan_start_delay
), 0 },
4726 { INT(tdls_external_control
), 0},
4727 { STR(osu_dir
), 0 },
4728 { STR(wowlan_triggers
), CFG_CHANGED_WOWLAN_TRIGGERS
},
4729 { INT(p2p_search_delay
), 0},
4730 { INT(mac_addr
), 0 },
4731 { INT(rand_addr_lifetime
), 0 },
4732 { INT(preassoc_mac_addr
), 0 },
4733 { INT(key_mgmt_offload
), 0},
4734 { INT(passive_scan
), 0 },
4735 { INT(reassoc_same_bss_optim
), 0 },
4736 { INT(wps_priority
), 0},
4738 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
4739 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
4740 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
4741 #endif /* CONFIG_FST */
4742 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
4743 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
4744 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
4746 { STR(non_pref_chan
), 0 },
4747 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
4748 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
4749 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
4750 { INT_RANGE(oce
, 0, 3), 0 },
4751 #endif /* CONFIG_MBO */
4752 { INT(gas_address3
), 0 },
4753 { INT_RANGE(ftm_responder
, 0, 1), 0 },
4754 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
4755 { INT(gas_rand_addr_lifetime
), 0 },
4756 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
4757 { INT_RANGE(dpp_config_processing
, 0, 2), 0 },
4758 { INT_RANGE(coloc_intf_reporting
, 0, 1), 0 },
4770 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4773 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
4778 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4779 const struct global_parse_data
*field
= &global_fields
[i
];
4785 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
4797 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
4798 char *buf
, size_t buflen
)
4802 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4803 const struct global_parse_data
*field
= &global_fields
[i
];
4805 if (os_strcmp(name
, field
->name
) != 0)
4809 return field
->get(name
, config
, (long) field
->param1
,
4817 int wpa_config_get_num_global_field_names(void)
4819 return NUM_GLOBAL_FIELDS
;
4823 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
4825 if (i
>= NUM_GLOBAL_FIELDS
)
4829 *no_var
= !global_fields
[i
].param1
;
4830 return global_fields
[i
].name
;
4834 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
4839 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4840 const struct global_parse_data
*field
= &global_fields
[i
];
4841 size_t flen
= os_strlen(field
->name
);
4842 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
4846 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
4847 wpa_printf(MSG_ERROR
, "Line %d: failed to "
4848 "parse '%s'.", line
, pos
);
4851 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
4852 config
->wps_nfc_pw_from_config
= 1;
4853 config
->changed_parameters
|= field
->changed_flag
;
4856 if (i
== NUM_GLOBAL_FIELDS
) {
4858 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
4859 char *tmp
= os_strchr(pos
, '=');
4863 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
4868 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
4870 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
4875 #endif /* CONFIG_AP */
4878 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",