2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/uuid.h"
13 #include "utils/ip_addr.h"
14 #include "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
;
738 #endif /* CONFIG_IEEE80211R */
739 #ifdef CONFIG_IEEE80211W
740 else if (os_strcmp(start
, "WPA-PSK-SHA256") == 0)
741 val
|= WPA_KEY_MGMT_PSK_SHA256
;
742 else if (os_strcmp(start
, "WPA-EAP-SHA256") == 0)
743 val
|= WPA_KEY_MGMT_IEEE8021X_SHA256
;
744 #endif /* CONFIG_IEEE80211W */
746 else if (os_strcmp(start
, "WPS") == 0)
747 val
|= WPA_KEY_MGMT_WPS
;
748 #endif /* CONFIG_WPS */
750 else if (os_strcmp(start
, "SAE") == 0)
751 val
|= WPA_KEY_MGMT_SAE
;
752 else if (os_strcmp(start
, "FT-SAE") == 0)
753 val
|= WPA_KEY_MGMT_FT_SAE
;
754 #endif /* CONFIG_SAE */
756 else if (os_strcmp(start
, "OSEN") == 0)
757 val
|= WPA_KEY_MGMT_OSEN
;
758 #endif /* CONFIG_HS20 */
760 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
761 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
762 #endif /* CONFIG_SUITEB */
763 #ifdef CONFIG_SUITEB192
764 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
765 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
766 #endif /* CONFIG_SUITEB192 */
768 else if (os_strcmp(start
, "FILS-SHA256") == 0)
769 val
|= WPA_KEY_MGMT_FILS_SHA256
;
770 else if (os_strcmp(start
, "FILS-SHA384") == 0)
771 val
|= WPA_KEY_MGMT_FILS_SHA384
;
772 #ifdef CONFIG_IEEE80211R
773 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
774 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
775 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
776 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
777 #endif /* CONFIG_IEEE80211R */
778 #endif /* CONFIG_FILS */
780 else if (os_strcmp(start
, "OWE") == 0)
781 val
|= WPA_KEY_MGMT_OWE
;
782 #endif /* CONFIG_OWE */
784 else if (os_strcmp(start
, "DPP") == 0)
785 val
|= WPA_KEY_MGMT_DPP
;
786 #endif /* CONFIG_DPP */
788 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
800 wpa_printf(MSG_ERROR
,
801 "Line %d: no key_mgmt values configured.", line
);
805 if (!errors
&& ssid
->key_mgmt
== val
)
807 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
808 ssid
->key_mgmt
= val
;
809 return errors
? -1 : 0;
813 #ifndef NO_CONFIG_WRITE
814 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
815 struct wpa_ssid
*ssid
)
817 char *buf
, *pos
, *end
;
820 pos
= buf
= os_zalloc(100);
825 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
826 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
827 pos
== buf
? "" : " ");
828 if (os_snprintf_error(end
- pos
, ret
)) {
835 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
836 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
837 pos
== buf
? "" : " ");
838 if (os_snprintf_error(end
- pos
, ret
)) {
845 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
846 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
847 pos
== buf
? "" : " ");
848 if (os_snprintf_error(end
- pos
, ret
)) {
855 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
856 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
857 pos
== buf
? "" : " ");
858 if (os_snprintf_error(end
- pos
, ret
)) {
865 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
866 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
867 pos
== buf
? "" : " ");
868 if (os_snprintf_error(end
- pos
, ret
)) {
875 #ifdef CONFIG_IEEE80211R
876 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
877 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
878 pos
== buf
? "" : " ");
879 if (os_snprintf_error(end
- pos
, ret
)) {
886 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
887 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
888 pos
== buf
? "" : " ");
889 if (os_snprintf_error(end
- pos
, ret
)) {
895 #endif /* CONFIG_IEEE80211R */
897 #ifdef CONFIG_IEEE80211W
898 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
899 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
900 pos
== buf
? "" : " ");
901 if (os_snprintf_error(end
- pos
, ret
)) {
908 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
909 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
910 pos
== buf
? "" : " ");
911 if (os_snprintf_error(end
- pos
, ret
)) {
917 #endif /* CONFIG_IEEE80211W */
920 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
921 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
922 pos
== buf
? "" : " ");
923 if (os_snprintf_error(end
- pos
, ret
)) {
929 #endif /* CONFIG_WPS */
932 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
933 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
934 pos
== buf
? "" : " ");
935 if (os_snprintf_error(end
- pos
, ret
)) {
942 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
943 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
944 pos
== buf
? "" : " ");
945 if (os_snprintf_error(end
- pos
, ret
)) {
951 #endif /* CONFIG_SAE */
954 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
955 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
956 pos
== buf
? "" : " ");
957 if (os_snprintf_error(end
- pos
, ret
)) {
963 #endif /* CONFIG_HS20 */
966 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
967 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
968 pos
== buf
? "" : " ");
969 if (os_snprintf_error(end
- pos
, ret
)) {
975 #endif /* CONFIG_SUITEB */
977 #ifdef CONFIG_SUITEB192
978 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
979 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
980 pos
== buf
? "" : " ");
981 if (os_snprintf_error(end
- pos
, ret
)) {
987 #endif /* CONFIG_SUITEB192 */
990 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
991 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
992 pos
== buf
? "" : " ");
993 if (os_snprintf_error(end
- pos
, ret
)) {
999 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1000 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
1001 pos
== buf
? "" : " ");
1002 if (os_snprintf_error(end
- pos
, ret
)) {
1008 #ifdef CONFIG_IEEE80211R
1009 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1010 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
1011 pos
== buf
? "" : " ");
1012 if (os_snprintf_error(end
- pos
, ret
)) {
1018 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1019 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
1020 pos
== buf
? "" : " ");
1021 if (os_snprintf_error(end
- pos
, ret
)) {
1027 #endif /* CONFIG_IEEE80211R */
1028 #endif /* CONFIG_FILS */
1037 #endif /* NO_CONFIG_WRITE */
1040 static int wpa_config_parse_cipher(int line
, const char *value
)
1042 #ifdef CONFIG_NO_WPA
1044 #else /* CONFIG_NO_WPA */
1045 int val
= wpa_parse_cipher(value
);
1047 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1052 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1057 #endif /* CONFIG_NO_WPA */
1061 #ifndef NO_CONFIG_WRITE
1062 static char * wpa_config_write_cipher(int cipher
)
1064 #ifdef CONFIG_NO_WPA
1066 #else /* CONFIG_NO_WPA */
1067 char *buf
= os_zalloc(50);
1071 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1077 #endif /* CONFIG_NO_WPA */
1079 #endif /* NO_CONFIG_WRITE */
1082 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1083 struct wpa_ssid
*ssid
, int line
,
1087 val
= wpa_config_parse_cipher(line
, value
);
1090 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1091 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1092 "(0x%x).", line
, val
);
1096 if (ssid
->pairwise_cipher
== val
)
1098 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1099 ssid
->pairwise_cipher
= val
;
1104 #ifndef NO_CONFIG_WRITE
1105 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1106 struct wpa_ssid
*ssid
)
1108 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1110 #endif /* NO_CONFIG_WRITE */
1113 static int wpa_config_parse_group(const struct parse_data
*data
,
1114 struct wpa_ssid
*ssid
, int line
,
1118 val
= wpa_config_parse_cipher(line
, value
);
1123 * Backwards compatibility - filter out WEP ciphers that were previously
1126 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1128 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1129 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1130 "(0x%x).", line
, val
);
1134 if (ssid
->group_cipher
== val
)
1136 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1137 ssid
->group_cipher
= val
;
1142 #ifndef NO_CONFIG_WRITE
1143 static char * wpa_config_write_group(const struct parse_data
*data
,
1144 struct wpa_ssid
*ssid
)
1146 return wpa_config_write_cipher(ssid
->group_cipher
);
1148 #endif /* NO_CONFIG_WRITE */
1151 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1152 struct wpa_ssid
*ssid
, int line
,
1155 int val
= 0, last
, errors
= 0;
1156 char *start
, *end
, *buf
;
1158 buf
= os_strdup(value
);
1163 while (*start
!= '\0') {
1164 while (*start
== ' ' || *start
== '\t')
1169 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1171 last
= *end
== '\0';
1173 if (os_strcmp(start
, "OPEN") == 0)
1174 val
|= WPA_AUTH_ALG_OPEN
;
1175 else if (os_strcmp(start
, "SHARED") == 0)
1176 val
|= WPA_AUTH_ALG_SHARED
;
1177 else if (os_strcmp(start
, "LEAP") == 0)
1178 val
|= WPA_AUTH_ALG_LEAP
;
1180 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1192 wpa_printf(MSG_ERROR
,
1193 "Line %d: no auth_alg values configured.", line
);
1197 if (!errors
&& ssid
->auth_alg
== val
)
1199 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1200 ssid
->auth_alg
= val
;
1201 return errors
? -1 : 0;
1205 #ifndef NO_CONFIG_WRITE
1206 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1207 struct wpa_ssid
*ssid
)
1209 char *buf
, *pos
, *end
;
1212 pos
= buf
= os_zalloc(30);
1217 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1218 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1219 pos
== buf
? "" : " ");
1220 if (os_snprintf_error(end
- pos
, ret
)) {
1227 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1228 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1229 pos
== buf
? "" : " ");
1230 if (os_snprintf_error(end
- pos
, ret
)) {
1237 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1238 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1239 pos
== buf
? "" : " ");
1240 if (os_snprintf_error(end
- pos
, ret
)) {
1254 #endif /* NO_CONFIG_WRITE */
1257 static int * wpa_config_parse_int_array(const char *value
)
1265 freqs
= os_calloc(len
+ 1, sizeof(int));
1276 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1281 for (i
= len
; i
<= len
* 2; i
++)
1287 freqs
[used
] = atoi(pos
);
1288 if (freqs
[used
] == 0)
1291 pos
= os_strchr(pos
+ 1, ' ');
1298 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1299 struct wpa_ssid
*ssid
, int line
,
1304 freqs
= wpa_config_parse_int_array(value
);
1307 if (freqs
[0] == 0) {
1311 os_free(ssid
->scan_freq
);
1312 ssid
->scan_freq
= freqs
;
1318 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1319 struct wpa_ssid
*ssid
, int line
,
1324 freqs
= wpa_config_parse_int_array(value
);
1327 if (freqs
[0] == 0) {
1331 os_free(ssid
->freq_list
);
1332 ssid
->freq_list
= freqs
;
1338 #ifndef NO_CONFIG_WRITE
1339 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1342 char *buf
, *pos
, *end
;
1350 for (i
= 0; freqs
[i
]; i
++)
1353 pos
= buf
= os_zalloc(10 * count
+ 1);
1356 end
= buf
+ 10 * count
+ 1;
1358 for (i
= 0; freqs
[i
]; i
++) {
1359 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1360 i
== 0 ? "" : " ", freqs
[i
]);
1361 if (os_snprintf_error(end
- pos
, ret
)) {
1372 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1373 struct wpa_ssid
*ssid
)
1375 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1379 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1380 struct wpa_ssid
*ssid
)
1382 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1384 #endif /* NO_CONFIG_WRITE */
1387 #ifdef IEEE8021X_EAPOL
1388 static int wpa_config_parse_eap(const struct parse_data
*data
,
1389 struct wpa_ssid
*ssid
, int line
,
1392 int last
, errors
= 0;
1393 char *start
, *end
, *buf
;
1394 struct eap_method_type
*methods
= NULL
, *tmp
;
1395 size_t num_methods
= 0;
1397 buf
= os_strdup(value
);
1402 while (*start
!= '\0') {
1403 while (*start
== ' ' || *start
== '\t')
1408 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1410 last
= *end
== '\0';
1413 methods
= os_realloc_array(methods
, num_methods
+ 1,
1415 if (methods
== NULL
) {
1420 methods
[num_methods
].method
= eap_peer_get_type(
1421 start
, &methods
[num_methods
].vendor
);
1422 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1423 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1424 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1425 "'%s'", line
, start
);
1426 wpa_printf(MSG_ERROR
, "You may need to add support for"
1427 " this EAP method during wpa_supplicant\n"
1428 "build time configuration.\n"
1429 "See README for more information.");
1431 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1432 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1444 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1445 if (methods
== NULL
) {
1449 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1450 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1453 if (!errors
&& ssid
->eap
.eap_methods
) {
1454 struct eap_method_type
*prev_m
;
1455 size_t i
, j
, prev_methods
, match
= 0;
1457 prev_m
= ssid
->eap
.eap_methods
;
1458 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1459 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1460 /* Count the methods */
1462 prev_methods
= i
+ 1;
1464 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1466 for (j
= 0; j
< num_methods
; j
++) {
1467 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1468 prev_m
[i
].method
== methods
[j
].method
) {
1474 if (match
== num_methods
) {
1479 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1480 (u8
*) methods
, num_methods
* sizeof(*methods
));
1481 os_free(ssid
->eap
.eap_methods
);
1482 ssid
->eap
.eap_methods
= methods
;
1483 return errors
? -1 : 0;
1487 #ifndef NO_CONFIG_WRITE
1488 static char * wpa_config_write_eap(const struct parse_data
*data
,
1489 struct wpa_ssid
*ssid
)
1492 char *buf
, *pos
, *end
;
1493 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1496 if (eap_methods
== NULL
)
1499 pos
= buf
= os_zalloc(100);
1504 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1505 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1506 name
= eap_get_name(eap_methods
[i
].vendor
,
1507 eap_methods
[i
].method
);
1509 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1510 pos
== buf
? "" : " ", name
);
1511 if (os_snprintf_error(end
- pos
, ret
))
1521 #endif /* NO_CONFIG_WRITE */
1524 static int wpa_config_parse_password(const struct parse_data
*data
,
1525 struct wpa_ssid
*ssid
, int line
,
1530 if (os_strcmp(value
, "NULL") == 0) {
1531 if (!ssid
->eap
.password
)
1532 return 1; /* Already unset */
1533 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1534 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1535 ssid
->eap
.password
= NULL
;
1536 ssid
->eap
.password_len
= 0;
1540 #ifdef CONFIG_EXT_PASSWORD
1541 if (os_strncmp(value
, "ext:", 4) == 0) {
1542 char *name
= os_strdup(value
+ 4);
1545 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1546 ssid
->eap
.password
= (u8
*) name
;
1547 ssid
->eap
.password_len
= os_strlen(name
);
1548 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1549 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1552 #endif /* CONFIG_EXT_PASSWORD */
1554 if (os_strncmp(value
, "hash:", 5) != 0) {
1558 tmp
= wpa_config_parse_string(value
, &res_len
);
1560 wpa_printf(MSG_ERROR
, "Line %d: failed to parse "
1564 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1565 (u8
*) tmp
, res_len
);
1567 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1568 ssid
->eap
.password
= (u8
*) tmp
;
1569 ssid
->eap
.password_len
= res_len
;
1570 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1571 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1577 /* NtPasswordHash: hash:<32 hex digits> */
1578 if (os_strlen(value
+ 5) != 2 * 16) {
1579 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash length "
1580 "(expected 32 hex digits)", line
);
1584 hash
= os_malloc(16);
1588 if (hexstr2bin(value
+ 5, hash
, 16)) {
1590 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1594 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1596 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1597 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1598 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1599 bin_clear_free(hash
, 16);
1602 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1603 ssid
->eap
.password
= hash
;
1604 ssid
->eap
.password_len
= 16;
1605 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1606 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1612 #ifndef NO_CONFIG_WRITE
1613 static char * wpa_config_write_password(const struct parse_data
*data
,
1614 struct wpa_ssid
*ssid
)
1618 if (ssid
->eap
.password
== NULL
)
1621 #ifdef CONFIG_EXT_PASSWORD
1622 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1623 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1626 os_memcpy(buf
, "ext:", 4);
1627 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1630 #endif /* CONFIG_EXT_PASSWORD */
1632 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1633 return wpa_config_write_string(
1634 ssid
->eap
.password
, ssid
->eap
.password_len
);
1637 buf
= os_malloc(5 + 32 + 1);
1641 os_memcpy(buf
, "hash:", 5);
1642 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1646 #endif /* NO_CONFIG_WRITE */
1647 #endif /* IEEE8021X_EAPOL */
1650 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1651 const char *value
, int idx
)
1653 char *buf
, title
[20];
1656 buf
= wpa_config_parse_string(value
, len
);
1658 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1662 if (*len
> MAX_WEP_KEY_LEN
) {
1663 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1668 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1669 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1670 "this network block will be ignored",
1671 line
, (unsigned int) *len
);
1673 os_memcpy(key
, buf
, *len
);
1674 str_clear_free(buf
);
1675 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1676 if (!os_snprintf_error(sizeof(title
), res
))
1677 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1682 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1683 struct wpa_ssid
*ssid
, int line
,
1686 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1687 &ssid
->wep_key_len
[0], line
,
1692 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1693 struct wpa_ssid
*ssid
, int line
,
1696 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1697 &ssid
->wep_key_len
[1], line
,
1702 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1703 struct wpa_ssid
*ssid
, int line
,
1706 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1707 &ssid
->wep_key_len
[2], line
,
1712 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1713 struct wpa_ssid
*ssid
, int line
,
1716 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1717 &ssid
->wep_key_len
[3], line
,
1722 #ifndef NO_CONFIG_WRITE
1723 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1725 if (ssid
->wep_key_len
[idx
] == 0)
1727 return wpa_config_write_string(ssid
->wep_key
[idx
],
1728 ssid
->wep_key_len
[idx
]);
1732 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1733 struct wpa_ssid
*ssid
)
1735 return wpa_config_write_wep_key(ssid
, 0);
1739 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1740 struct wpa_ssid
*ssid
)
1742 return wpa_config_write_wep_key(ssid
, 1);
1746 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1747 struct wpa_ssid
*ssid
)
1749 return wpa_config_write_wep_key(ssid
, 2);
1753 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1754 struct wpa_ssid
*ssid
)
1756 return wpa_config_write_wep_key(ssid
, 3);
1758 #endif /* NO_CONFIG_WRITE */
1763 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1764 struct wpa_ssid
*ssid
, int line
,
1767 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1768 os_strcmp(value
, "any") == 0) {
1769 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1770 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1773 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1774 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1778 ssid
->bssid_set
= 1;
1779 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1780 MAC2STR(ssid
->go_p2p_dev_addr
));
1785 #ifndef NO_CONFIG_WRITE
1786 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
1787 struct wpa_ssid
*ssid
)
1792 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
1795 value
= os_malloc(20);
1798 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
1799 if (os_snprintf_error(20, res
)) {
1803 value
[20 - 1] = '\0';
1806 #endif /* NO_CONFIG_WRITE */
1809 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
1810 struct wpa_ssid
*ssid
, int line
,
1813 return wpa_config_parse_addr_list(data
, line
, value
,
1814 &ssid
->p2p_client_list
,
1815 &ssid
->num_p2p_clients
,
1816 "p2p_client_list", 0, 0);
1820 #ifndef NO_CONFIG_WRITE
1821 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
1822 struct wpa_ssid
*ssid
)
1824 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
1825 ssid
->num_p2p_clients
,
1828 #endif /* NO_CONFIG_WRITE */
1831 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
1832 struct wpa_ssid
*ssid
, int line
,
1835 struct psk_list_entry
*p
;
1838 p
= os_zalloc(sizeof(*p
));
1843 if (os_strncmp(pos
, "P2P-", 4) == 0) {
1848 if (hwaddr_aton(pos
, p
->addr
)) {
1849 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
1856 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
1863 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
1864 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
1870 dl_list_add(&ssid
->psk_list
, &p
->list
);
1876 #ifndef NO_CONFIG_WRITE
1877 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
1878 struct wpa_ssid
*ssid
)
1882 #endif /* NO_CONFIG_WRITE */
1884 #endif /* CONFIG_P2P */
1889 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
1890 struct wpa_ssid
*ssid
, int line
,
1893 int *rates
= wpa_config_parse_int_array(value
);
1895 if (rates
== NULL
) {
1896 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
1900 if (rates
[0] == 0) {
1905 os_free(ssid
->mesh_basic_rates
);
1906 ssid
->mesh_basic_rates
= rates
;
1912 #ifndef NO_CONFIG_WRITE
1914 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
1915 struct wpa_ssid
*ssid
)
1917 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
1920 #endif /* NO_CONFIG_WRITE */
1922 #endif /* CONFIG_MESH */
1925 #ifdef CONFIG_MACSEC
1927 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
1928 struct wpa_ssid
*ssid
, int line
,
1931 if (hexstr2bin(value
, ssid
->mka_cak
, MACSEC_CAK_LEN
) ||
1932 value
[MACSEC_CAK_LEN
* 2] != '\0') {
1933 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
1938 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
1940 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
, MACSEC_CAK_LEN
);
1945 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
1946 struct wpa_ssid
*ssid
, int line
,
1949 if (hexstr2bin(value
, ssid
->mka_ckn
, MACSEC_CKN_LEN
) ||
1950 value
[MACSEC_CKN_LEN
* 2] != '\0') {
1951 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
1956 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
1958 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
, MACSEC_CKN_LEN
);
1963 #ifndef NO_CONFIG_WRITE
1965 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
1966 struct wpa_ssid
*ssid
)
1968 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
1971 return wpa_config_write_string_hex(ssid
->mka_cak
, MACSEC_CAK_LEN
);
1975 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
1976 struct wpa_ssid
*ssid
)
1978 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
1980 return wpa_config_write_string_hex(ssid
->mka_ckn
, MACSEC_CKN_LEN
);
1983 #endif /* NO_CONFIG_WRITE */
1985 #endif /* CONFIG_MACSEC */
1988 /* Helper macros for network block parser */
1993 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1994 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1996 /* STR: Define a string variable for an ASCII string; f = field name */
1997 #ifdef NO_CONFIG_WRITE
1998 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1999 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
2000 #else /* NO_CONFIG_WRITE */
2001 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
2002 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
2003 #endif /* NO_CONFIG_WRITE */
2004 #define STR(f) _STR(f), NULL, NULL, NULL, 0
2005 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
2006 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
2007 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
2009 /* STR_LEN: Define a string variable with a separate variable for storing the
2010 * data length. Unlike STR(), this can be used to store arbitrary binary data
2011 * (i.e., even nul termination character). */
2012 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
2013 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
2014 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
2015 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
2016 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
2018 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
2019 * explicitly specified. */
2020 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
2021 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
2022 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
2024 #ifdef NO_CONFIG_WRITE
2025 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
2026 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
2027 #else /* NO_CONFIG_WRITE */
2028 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2029 OFFSET(f), (void *) 0
2030 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2031 OFFSET(eap.f), (void *) 0
2032 #endif /* NO_CONFIG_WRITE */
2034 /* INT: Define an integer variable */
2035 #define INT(f) _INT(f), NULL, NULL, 0
2036 #define INTe(f) _INTe(f), NULL, NULL, 0
2038 /* INT_RANGE: Define an integer variable with allowed value range */
2039 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
2041 /* FUNC: Define a configuration variable that uses a custom function for
2042 * parsing and writing the value. */
2043 #ifdef NO_CONFIG_WRITE
2044 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
2045 #else /* NO_CONFIG_WRITE */
2046 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
2047 NULL, NULL, NULL, NULL
2048 #endif /* NO_CONFIG_WRITE */
2049 #define FUNC(f) _FUNC(f), 0
2050 #define FUNC_KEY(f) _FUNC(f), 1
2053 * Table of network configuration variables. This table is used to parse each
2054 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2055 * that is inside a network block.
2057 * This table is generated using the helper macros defined above and with
2058 * generous help from the C pre-processor. The field name is stored as a string
2059 * into .name and for STR and INT types, the offset of the target buffer within
2060 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2061 * offset to the field containing the length of the configuration variable.
2062 * .param3 and .param4 can be used to mark the allowed range (length for STR
2063 * and value for INT).
2065 * For each configuration line in wpa_supplicant.conf, the parser goes through
2066 * this table and select the entry that matches with the field name. The parser
2067 * function (.parser) is then called to parse the actual value of the field.
2069 * This kind of mechanism makes it easy to add new configuration parameters,
2070 * since only one line needs to be added into this table and into the
2071 * struct wpa_ssid definition if the new variable is either a string or
2072 * integer. More complex types will need to use their own parser and writer
2075 static const struct parse_data ssid_fields
[] = {
2076 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2077 { INT_RANGE(scan_ssid
, 0, 1) },
2079 { FUNC(bssid_hint
) },
2080 { FUNC(bssid_blacklist
) },
2081 { FUNC(bssid_whitelist
) },
2083 { INT(mem_only_psk
) },
2086 { INT(bg_scan_period
) },
2090 { FUNC(scan_freq
) },
2091 { FUNC(freq_list
) },
2092 { INT_RANGE(ht
, 0, 1) },
2093 { INT_RANGE(vht
, 0, 1) },
2094 { INT_RANGE(ht40
, -1, 1) },
2095 { INT_RANGE(max_oper_chwidth
, VHT_CHANWIDTH_USE_HT
,
2096 VHT_CHANWIDTH_80P80MHZ
) },
2097 { INT(vht_center_freq1
) },
2098 { INT(vht_center_freq2
) },
2099 #ifdef IEEE8021X_EAPOL
2101 { STR_LENe(identity
) },
2102 { STR_LENe(anonymous_identity
) },
2103 { FUNC_KEY(password
) },
2106 { STRe(client_cert
) },
2107 { STRe(private_key
) },
2108 { STR_KEYe(private_key_passwd
) },
2110 { STRe(subject_match
) },
2111 { STRe(altsubject_match
) },
2112 { STRe(domain_suffix_match
) },
2113 { STRe(domain_match
) },
2116 { STRe(client_cert2
) },
2117 { STRe(private_key2
) },
2118 { STR_KEYe(private_key2_passwd
) },
2120 { STRe(subject_match2
) },
2121 { STRe(altsubject_match2
) },
2122 { STRe(domain_suffix_match2
) },
2123 { STRe(domain_match2
) },
2128 { STRe(engine_id
) },
2131 { STRe(ca_cert_id
) },
2133 { STRe(engine2_id
) },
2136 { STRe(ca_cert2_id
) },
2139 { INT(eapol_flags
) },
2141 { STRe(openssl_ciphers
) },
2143 #endif /* IEEE8021X_EAPOL */
2144 { FUNC_KEY(wep_key0
) },
2145 { FUNC_KEY(wep_key1
) },
2146 { FUNC_KEY(wep_key2
) },
2147 { FUNC_KEY(wep_key3
) },
2148 { INT(wep_tx_keyidx
) },
2150 #ifdef IEEE8021X_EAPOL
2151 { INT(eap_workaround
) },
2153 { INTe(fragment_size
) },
2155 #endif /* IEEE8021X_EAPOL */
2157 { INT_RANGE(mode
, 0, 5) },
2158 { INT_RANGE(no_auto_peer
, 0, 1) },
2159 { INT_RANGE(mesh_rssi_threshold
, -255, 1) },
2160 #else /* CONFIG_MESH */
2161 { INT_RANGE(mode
, 0, 4) },
2162 #endif /* CONFIG_MESH */
2163 { INT_RANGE(proactive_key_caching
, 0, 1) },
2164 { INT_RANGE(disabled
, 0, 2) },
2166 #ifdef CONFIG_IEEE80211W
2167 { INT_RANGE(ieee80211w
, 0, 2) },
2168 #endif /* CONFIG_IEEE80211W */
2169 { INT_RANGE(peerkey
, 0, 1) },
2170 { INT_RANGE(mixed_cell
, 0, 1) },
2171 { INT_RANGE(frequency
, 0, 65000) },
2172 { INT_RANGE(fixed_freq
, 0, 1) },
2174 { INT_RANGE(acs
, 0, 1) },
2175 #endif /* CONFIG_ACS */
2177 { FUNC(mesh_basic_rates
) },
2178 { INT(dot11MeshMaxRetries
) },
2179 { INT(dot11MeshRetryTimeout
) },
2180 { INT(dot11MeshConfirmTimeout
) },
2181 { INT(dot11MeshHoldingTimeout
) },
2182 #endif /* CONFIG_MESH */
2183 { INT(wpa_ptk_rekey
) },
2184 { INT(group_rekey
) },
2186 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2188 { FUNC(go_p2p_dev_addr
) },
2189 { FUNC(p2p_client_list
) },
2191 #endif /* CONFIG_P2P */
2192 #ifdef CONFIG_HT_OVERRIDES
2193 { INT_RANGE(disable_ht
, 0, 1) },
2194 { INT_RANGE(disable_ht40
, -1, 1) },
2195 { INT_RANGE(disable_sgi
, 0, 1) },
2196 { INT_RANGE(disable_ldpc
, 0, 1) },
2197 { INT_RANGE(ht40_intolerant
, 0, 1) },
2198 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2199 { INT_RANGE(ampdu_factor
, -1, 3) },
2200 { INT_RANGE(ampdu_density
, -1, 7) },
2202 #endif /* CONFIG_HT_OVERRIDES */
2203 #ifdef CONFIG_VHT_OVERRIDES
2204 { INT_RANGE(disable_vht
, 0, 1) },
2206 { INT(vht_capa_mask
) },
2207 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2208 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2209 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2210 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2211 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2212 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2213 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2214 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2215 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2216 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2217 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2218 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2219 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2220 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2221 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2222 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2223 #endif /* CONFIG_VHT_OVERRIDES */
2224 { INT(ap_max_inactivity
) },
2225 { INT(dtim_period
) },
2226 { INT(beacon_int
) },
2227 #ifdef CONFIG_MACSEC
2228 { INT_RANGE(macsec_policy
, 0, 1) },
2229 { INT_RANGE(macsec_integ_only
, 0, 1) },
2230 { INT_RANGE(macsec_port
, 1, 65534) },
2231 { INT_RANGE(mka_priority
, 0, 255) },
2232 { FUNC_KEY(mka_cak
) },
2233 { FUNC_KEY(mka_ckn
) },
2234 #endif /* CONFIG_MACSEC */
2236 { INT(update_identifier
) },
2237 #endif /* CONFIG_HS20 */
2238 { INT_RANGE(mac_addr
, 0, 2) },
2239 { INT_RANGE(pbss
, 0, 2) },
2240 { INT_RANGE(wps_disabled
, 0, 1) },
2241 { INT_RANGE(fils_dh_group
, 0, 65535) },
2243 { STR(dpp_connector
) },
2244 { STR_LEN(dpp_netaccesskey
) },
2245 { INT(dpp_netaccesskey_expiry
) },
2246 { STR_LEN(dpp_csign
) },
2247 { INT(dpp_csign_expiry
) },
2248 #endif /* CONFIG_DPP */
2260 #undef STR_RANGE_KEY
2267 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2271 * wpa_config_add_prio_network - Add a network to priority lists
2272 * @config: Configuration data from wpa_config_read()
2273 * @ssid: Pointer to the network configuration to be added to the list
2274 * Returns: 0 on success, -1 on failure
2276 * This function is used to add a network block to the priority list of
2277 * networks. This must be called for each network when reading in the full
2278 * configuration. In addition, this can be used indirectly when updating
2279 * priorities by calling wpa_config_update_prio_list().
2281 int wpa_config_add_prio_network(struct wpa_config
*config
,
2282 struct wpa_ssid
*ssid
)
2285 struct wpa_ssid
*prev
, **nlist
;
2288 * Add to an existing priority list if one is available for the
2289 * configured priority level for this network.
2291 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2292 prev
= config
->pssid
[prio
];
2293 if (prev
->priority
== ssid
->priority
) {
2301 /* First network for this priority - add a new priority list */
2302 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2303 sizeof(struct wpa_ssid
*));
2307 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2308 if (nlist
[prio
]->priority
< ssid
->priority
) {
2309 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2310 (config
->num_prio
- prio
) *
2311 sizeof(struct wpa_ssid
*));
2318 config
->pssid
= nlist
;
2325 * wpa_config_update_prio_list - Update network priority list
2326 * @config: Configuration data from wpa_config_read()
2327 * Returns: 0 on success, -1 on failure
2329 * This function is called to update the priority list of networks in the
2330 * configuration when a network is being added or removed. This is also called
2331 * if a priority for a network is changed.
2333 int wpa_config_update_prio_list(struct wpa_config
*config
)
2335 struct wpa_ssid
*ssid
;
2338 os_free(config
->pssid
);
2339 config
->pssid
= NULL
;
2340 config
->num_prio
= 0;
2342 ssid
= config
->ssid
;
2345 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2354 #ifdef IEEE8021X_EAPOL
2355 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2357 os_free(eap
->eap_methods
);
2358 bin_clear_free(eap
->identity
, eap
->identity_len
);
2359 os_free(eap
->anonymous_identity
);
2360 bin_clear_free(eap
->password
, eap
->password_len
);
2361 os_free(eap
->ca_cert
);
2362 os_free(eap
->ca_path
);
2363 os_free(eap
->client_cert
);
2364 os_free(eap
->private_key
);
2365 str_clear_free(eap
->private_key_passwd
);
2366 os_free(eap
->dh_file
);
2367 os_free(eap
->subject_match
);
2368 os_free(eap
->altsubject_match
);
2369 os_free(eap
->domain_suffix_match
);
2370 os_free(eap
->domain_match
);
2371 os_free(eap
->ca_cert2
);
2372 os_free(eap
->ca_path2
);
2373 os_free(eap
->client_cert2
);
2374 os_free(eap
->private_key2
);
2375 str_clear_free(eap
->private_key2_passwd
);
2376 os_free(eap
->dh_file2
);
2377 os_free(eap
->subject_match2
);
2378 os_free(eap
->altsubject_match2
);
2379 os_free(eap
->domain_suffix_match2
);
2380 os_free(eap
->domain_match2
);
2381 os_free(eap
->phase1
);
2382 os_free(eap
->phase2
);
2384 str_clear_free(eap
->pin
);
2385 os_free(eap
->engine_id
);
2386 os_free(eap
->key_id
);
2387 os_free(eap
->cert_id
);
2388 os_free(eap
->ca_cert_id
);
2389 os_free(eap
->key2_id
);
2390 os_free(eap
->cert2_id
);
2391 os_free(eap
->ca_cert2_id
);
2392 str_clear_free(eap
->pin2
);
2393 os_free(eap
->engine2_id
);
2395 os_free(eap
->pending_req_otp
);
2396 os_free(eap
->pac_file
);
2397 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2398 str_clear_free(eap
->external_sim_resp
);
2399 os_free(eap
->openssl_ciphers
);
2401 #endif /* IEEE8021X_EAPOL */
2405 * wpa_config_free_ssid - Free network/ssid configuration data
2406 * @ssid: Configuration data for the network
2408 * This function frees all resources allocated for the network configuration
2411 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2413 struct psk_list_entry
*psk
;
2415 os_free(ssid
->ssid
);
2416 str_clear_free(ssid
->passphrase
);
2417 os_free(ssid
->ext_psk
);
2418 #ifdef IEEE8021X_EAPOL
2419 eap_peer_config_free(&ssid
->eap
);
2420 #endif /* IEEE8021X_EAPOL */
2421 os_free(ssid
->id_str
);
2422 os_free(ssid
->scan_freq
);
2423 os_free(ssid
->freq_list
);
2424 os_free(ssid
->bgscan
);
2425 os_free(ssid
->p2p_client_list
);
2426 os_free(ssid
->bssid_blacklist
);
2427 os_free(ssid
->bssid_whitelist
);
2428 #ifdef CONFIG_HT_OVERRIDES
2429 os_free(ssid
->ht_mcs
);
2430 #endif /* CONFIG_HT_OVERRIDES */
2432 os_free(ssid
->mesh_basic_rates
);
2433 #endif /* CONFIG_MESH */
2434 os_free(ssid
->dpp_connector
);
2435 bin_clear_free(ssid
->dpp_netaccesskey
, ssid
->dpp_netaccesskey_len
);
2436 os_free(ssid
->dpp_csign
);
2437 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2439 dl_list_del(&psk
->list
);
2440 bin_clear_free(psk
, sizeof(*psk
));
2442 bin_clear_free(ssid
, sizeof(*ssid
));
2446 void wpa_config_free_cred(struct wpa_cred
*cred
)
2450 os_free(cred
->realm
);
2451 str_clear_free(cred
->username
);
2452 str_clear_free(cred
->password
);
2453 os_free(cred
->ca_cert
);
2454 os_free(cred
->client_cert
);
2455 os_free(cred
->private_key
);
2456 str_clear_free(cred
->private_key_passwd
);
2457 os_free(cred
->imsi
);
2458 str_clear_free(cred
->milenage
);
2459 for (i
= 0; i
< cred
->num_domain
; i
++)
2460 os_free(cred
->domain
[i
]);
2461 os_free(cred
->domain
);
2462 os_free(cred
->domain_suffix_match
);
2463 os_free(cred
->eap_method
);
2464 os_free(cred
->phase1
);
2465 os_free(cred
->phase2
);
2466 os_free(cred
->excluded_ssid
);
2467 os_free(cred
->roaming_partner
);
2468 os_free(cred
->provisioning_sp
);
2469 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2470 os_free(cred
->req_conn_capab_port
[i
]);
2471 os_free(cred
->req_conn_capab_port
);
2472 os_free(cred
->req_conn_capab_proto
);
2477 void wpa_config_flush_blobs(struct wpa_config
*config
)
2479 #ifndef CONFIG_NO_CONFIG_BLOBS
2480 struct wpa_config_blob
*blob
, *prev
;
2482 blob
= config
->blobs
;
2483 config
->blobs
= NULL
;
2487 wpa_config_free_blob(prev
);
2489 #endif /* CONFIG_NO_CONFIG_BLOBS */
2494 * wpa_config_free - Free configuration data
2495 * @config: Configuration data from wpa_config_read()
2497 * This function frees all resources allocated for the configuration data by
2498 * wpa_config_read().
2500 void wpa_config_free(struct wpa_config
*config
)
2502 struct wpa_ssid
*ssid
, *prev
= NULL
;
2503 struct wpa_cred
*cred
, *cprev
;
2506 ssid
= config
->ssid
;
2510 wpa_config_free_ssid(prev
);
2513 cred
= config
->cred
;
2517 wpa_config_free_cred(cprev
);
2520 wpa_config_flush_blobs(config
);
2522 wpabuf_free(config
->wps_vendor_ext_m1
);
2523 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2524 wpabuf_free(config
->wps_vendor_ext
[i
]);
2525 os_free(config
->ctrl_interface
);
2526 os_free(config
->ctrl_interface_group
);
2527 os_free(config
->opensc_engine_path
);
2528 os_free(config
->pkcs11_engine_path
);
2529 os_free(config
->pkcs11_module_path
);
2530 os_free(config
->openssl_ciphers
);
2531 os_free(config
->pcsc_reader
);
2532 str_clear_free(config
->pcsc_pin
);
2533 os_free(config
->driver_param
);
2534 os_free(config
->device_name
);
2535 os_free(config
->manufacturer
);
2536 os_free(config
->model_name
);
2537 os_free(config
->model_number
);
2538 os_free(config
->serial_number
);
2539 os_free(config
->config_methods
);
2540 os_free(config
->p2p_ssid_postfix
);
2541 os_free(config
->pssid
);
2542 os_free(config
->p2p_pref_chan
);
2543 os_free(config
->p2p_no_go_freq
.range
);
2544 os_free(config
->autoscan
);
2545 os_free(config
->freq_list
);
2546 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2547 wpabuf_free(config
->wps_nfc_dh_privkey
);
2548 wpabuf_free(config
->wps_nfc_dev_pw
);
2549 os_free(config
->ext_password_backend
);
2550 os_free(config
->sae_groups
);
2551 wpabuf_free(config
->ap_vendor_elements
);
2552 os_free(config
->osu_dir
);
2553 os_free(config
->bgscan
);
2554 os_free(config
->wowlan_triggers
);
2555 os_free(config
->fst_group_id
);
2556 os_free(config
->sched_scan_plans
);
2558 os_free(config
->non_pref_chan
);
2559 #endif /* CONFIG_MBO */
2566 * wpa_config_foreach_network - Iterate over each configured network
2567 * @config: Configuration data from wpa_config_read()
2568 * @func: Callback function to process each network
2569 * @arg: Opaque argument to pass to callback function
2571 * Iterate over the set of configured networks calling the specified
2572 * function for each item. We guard against callbacks removing the
2575 void wpa_config_foreach_network(struct wpa_config
*config
,
2576 void (*func
)(void *, struct wpa_ssid
*),
2579 struct wpa_ssid
*ssid
, *next
;
2581 ssid
= config
->ssid
;
2591 * wpa_config_get_network - Get configured network based on id
2592 * @config: Configuration data from wpa_config_read()
2593 * @id: Unique network id to search for
2594 * Returns: Network configuration or %NULL if not found
2596 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2598 struct wpa_ssid
*ssid
;
2600 ssid
= config
->ssid
;
2612 * wpa_config_add_network - Add a new network with empty configuration
2613 * @config: Configuration data from wpa_config_read()
2614 * Returns: The new network configuration or %NULL if operation failed
2616 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2619 struct wpa_ssid
*ssid
, *last
= NULL
;
2622 ssid
= config
->ssid
;
2631 ssid
= os_zalloc(sizeof(*ssid
));
2635 dl_list_init(&ssid
->psk_list
);
2639 config
->ssid
= ssid
;
2641 wpa_config_update_prio_list(config
);
2648 * wpa_config_remove_network - Remove a configured network based on id
2649 * @config: Configuration data from wpa_config_read()
2650 * @id: Unique network id to search for
2651 * Returns: 0 on success, or -1 if the network was not found
2653 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2655 struct wpa_ssid
*ssid
, *prev
= NULL
;
2657 ssid
= config
->ssid
;
2669 prev
->next
= ssid
->next
;
2671 config
->ssid
= ssid
->next
;
2673 wpa_config_update_prio_list(config
);
2674 wpa_config_free_ssid(ssid
);
2680 * wpa_config_set_network_defaults - Set network default values
2681 * @ssid: Pointer to network configuration data
2683 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
2685 ssid
->proto
= DEFAULT_PROTO
;
2686 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
2687 ssid
->group_cipher
= DEFAULT_GROUP
;
2688 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
2689 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
2691 #ifdef IEEE8021X_EAPOL
2692 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
2693 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
2694 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
2695 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
2696 #endif /* IEEE8021X_EAPOL */
2698 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
2699 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
2700 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
2701 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
2702 ssid
->mesh_rssi_threshold
= DEFAULT_MESH_RSSI_THRESHOLD
;
2703 #endif /* CONFIG_MESH */
2704 #ifdef CONFIG_HT_OVERRIDES
2705 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
2706 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
2707 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
2708 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
2709 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
2710 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
2711 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
2712 #endif /* CONFIG_HT_OVERRIDES */
2713 #ifdef CONFIG_VHT_OVERRIDES
2714 ssid
->vht_rx_mcs_nss_1
= -1;
2715 ssid
->vht_rx_mcs_nss_2
= -1;
2716 ssid
->vht_rx_mcs_nss_3
= -1;
2717 ssid
->vht_rx_mcs_nss_4
= -1;
2718 ssid
->vht_rx_mcs_nss_5
= -1;
2719 ssid
->vht_rx_mcs_nss_6
= -1;
2720 ssid
->vht_rx_mcs_nss_7
= -1;
2721 ssid
->vht_rx_mcs_nss_8
= -1;
2722 ssid
->vht_tx_mcs_nss_1
= -1;
2723 ssid
->vht_tx_mcs_nss_2
= -1;
2724 ssid
->vht_tx_mcs_nss_3
= -1;
2725 ssid
->vht_tx_mcs_nss_4
= -1;
2726 ssid
->vht_tx_mcs_nss_5
= -1;
2727 ssid
->vht_tx_mcs_nss_6
= -1;
2728 ssid
->vht_tx_mcs_nss_7
= -1;
2729 ssid
->vht_tx_mcs_nss_8
= -1;
2730 #endif /* CONFIG_VHT_OVERRIDES */
2731 ssid
->proactive_key_caching
= -1;
2732 #ifdef CONFIG_IEEE80211W
2733 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
2734 #endif /* CONFIG_IEEE80211W */
2735 #ifdef CONFIG_MACSEC
2736 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
2737 #endif /* CONFIG_MACSEC */
2738 ssid
->mac_addr
= -1;
2743 * wpa_config_set - Set a variable in network configuration
2744 * @ssid: Pointer to network configuration data
2745 * @var: Variable name, e.g., "ssid"
2746 * @value: Variable value
2747 * @line: Line number in configuration file or 0 if not used
2748 * Returns: 0 on success with possible change in the value, 1 on success with
2749 * no change to previously configured value, or -1 on failure
2751 * This function can be used to set network configuration variables based on
2752 * both the configuration file and management interface input. The value
2753 * parameter must be in the same format as the text-based configuration file is
2754 * using. For example, strings are using double quotation marks.
2756 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
2762 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
2765 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2766 const struct parse_data
*field
= &ssid_fields
[i
];
2767 if (os_strcmp(var
, field
->name
) != 0)
2770 ret
= field
->parser(field
, ssid
, line
, value
);
2773 wpa_printf(MSG_ERROR
, "Line %d: failed to "
2774 "parse %s '%s'.", line
, var
, value
);
2780 if (i
== NUM_SSID_FIELDS
) {
2782 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
2783 "'%s'.", line
, var
);
2792 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
2799 len
= os_strlen(value
);
2800 buf
= os_malloc(len
+ 3);
2804 os_memcpy(buf
+ 1, value
, len
);
2806 buf
[len
+ 2] = '\0';
2807 ret
= wpa_config_set(ssid
, var
, buf
, 0);
2814 * wpa_config_get_all - Get all options from network configuration
2815 * @ssid: Pointer to network configuration data
2816 * @get_keys: Determines if keys/passwords will be included in returned list
2817 * (if they may be exported)
2818 * Returns: %NULL terminated list of all set keys and their values in the form
2819 * of [key1, val1, key2, val2, ... , NULL]
2821 * This function can be used to get list of all configured network properties.
2822 * The caller is responsible for freeing the returned list and all its
2825 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
2827 #ifdef NO_CONFIG_WRITE
2829 #else /* NO_CONFIG_WRITE */
2830 const struct parse_data
*field
;
2836 get_keys
= get_keys
&& ssid
->export_keys
;
2838 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
2843 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2844 field
= &ssid_fields
[i
];
2845 if (field
->key_data
&& !get_keys
)
2847 value
= field
->writer(field
, ssid
);
2850 if (os_strlen(value
) == 0) {
2855 key
= os_strdup(field
->name
);
2861 props
[fields_num
* 2] = key
;
2862 props
[fields_num
* 2 + 1] = value
;
2870 for (i
= 0; props
[i
]; i
++)
2874 #endif /* NO_CONFIG_WRITE */
2878 #ifndef NO_CONFIG_WRITE
2880 * wpa_config_get - Get a variable in network configuration
2881 * @ssid: Pointer to network configuration data
2882 * @var: Variable name, e.g., "ssid"
2883 * Returns: Value of the variable or %NULL on failure
2885 * This function can be used to get network configuration variables. The
2886 * returned value is a copy of the configuration variable in text format, i.e,.
2887 * the same format that the text-based configuration file and wpa_config_set()
2888 * are using for the value. The caller is responsible for freeing the returned
2891 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
2895 if (ssid
== NULL
|| var
== NULL
)
2898 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2899 const struct parse_data
*field
= &ssid_fields
[i
];
2900 if (os_strcmp(var
, field
->name
) == 0) {
2901 char *ret
= field
->writer(field
, ssid
);
2903 if (ret
&& has_newline(ret
)) {
2904 wpa_printf(MSG_ERROR
,
2905 "Found newline in value for %s; not returning it",
2920 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2921 * @ssid: Pointer to network configuration data
2922 * @var: Variable name, e.g., "ssid"
2923 * Returns: Value of the variable or %NULL on failure
2925 * This function can be used to get network configuration variable like
2926 * wpa_config_get(). The only difference is that this functions does not expose
2927 * key/password material from the configuration. In case a key/password field
2928 * is requested, the returned value is an empty string or %NULL if the variable
2929 * is not set or "*" if the variable is set (regardless of its value). The
2930 * returned value is a copy of the configuration variable in text format, i.e,.
2931 * the same format that the text-based configuration file and wpa_config_set()
2932 * are using for the value. The caller is responsible for freeing the returned
2935 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
2939 if (ssid
== NULL
|| var
== NULL
)
2942 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2943 const struct parse_data
*field
= &ssid_fields
[i
];
2944 if (os_strcmp(var
, field
->name
) == 0) {
2945 char *res
= field
->writer(field
, ssid
);
2946 if (field
->key_data
) {
2947 if (res
&& res
[0]) {
2948 wpa_printf(MSG_DEBUG
, "Do not allow "
2949 "key_data field to be "
2951 str_clear_free(res
);
2952 return os_strdup("*");
2964 #endif /* NO_CONFIG_WRITE */
2968 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2969 * @ssid: Pointer to network configuration data
2971 * This function must be called to update WPA PSK when either SSID or the
2972 * passphrase has changed for the network configuration.
2974 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
2976 #ifndef CONFIG_NO_PBKDF2
2977 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
2978 ssid
->psk
, PMK_LEN
);
2979 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
2980 ssid
->psk
, PMK_LEN
);
2982 #endif /* CONFIG_NO_PBKDF2 */
2986 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
2991 int *ports
, *nports
;
2993 unsigned int num_ports
;
2995 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
2996 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
2999 cred
->req_conn_capab_proto
= proto
;
3001 port
= os_realloc_array(cred
->req_conn_capab_port
,
3002 cred
->num_req_conn_capab
+ 1, sizeof(int *));
3005 cred
->req_conn_capab_port
= port
;
3007 proto
[cred
->num_req_conn_capab
] = atoi(value
);
3009 pos
= os_strchr(value
, ':');
3011 port
[cred
->num_req_conn_capab
] = NULL
;
3012 cred
->num_req_conn_capab
++;
3021 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3022 if (nports
== NULL
) {
3027 ports
[num_ports
++] = atoi(pos
);
3029 pos
= os_strchr(pos
, ',');
3035 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3036 if (nports
== NULL
) {
3041 ports
[num_ports
] = -1;
3043 port
[cred
->num_req_conn_capab
] = ports
;
3044 cred
->num_req_conn_capab
++;
3049 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
3050 const char *value
, int line
)
3055 if (os_strcmp(var
, "temporary") == 0) {
3056 cred
->temporary
= atoi(value
);
3060 if (os_strcmp(var
, "priority") == 0) {
3061 cred
->priority
= atoi(value
);
3065 if (os_strcmp(var
, "sp_priority") == 0) {
3066 int prio
= atoi(value
);
3067 if (prio
< 0 || prio
> 255)
3069 cred
->sp_priority
= prio
;
3073 if (os_strcmp(var
, "pcsc") == 0) {
3074 cred
->pcsc
= atoi(value
);
3078 if (os_strcmp(var
, "eap") == 0) {
3079 struct eap_method_type method
;
3080 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3081 if (method
.vendor
== EAP_VENDOR_IETF
&&
3082 method
.method
== EAP_TYPE_NONE
) {
3083 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3084 "for a credential", line
, value
);
3087 os_free(cred
->eap_method
);
3088 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3089 if (cred
->eap_method
== NULL
)
3091 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3095 if (os_strcmp(var
, "password") == 0 &&
3096 os_strncmp(value
, "ext:", 4) == 0) {
3097 if (has_newline(value
))
3099 str_clear_free(cred
->password
);
3100 cred
->password
= os_strdup(value
);
3101 cred
->ext_password
= 1;
3105 if (os_strcmp(var
, "update_identifier") == 0) {
3106 cred
->update_identifier
= atoi(value
);
3110 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3111 cred
->min_dl_bandwidth_home
= atoi(value
);
3115 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3116 cred
->min_ul_bandwidth_home
= atoi(value
);
3120 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3121 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3125 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3126 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3130 if (os_strcmp(var
, "max_bss_load") == 0) {
3131 cred
->max_bss_load
= atoi(value
);
3135 if (os_strcmp(var
, "req_conn_capab") == 0)
3136 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3138 if (os_strcmp(var
, "ocsp") == 0) {
3139 cred
->ocsp
= atoi(value
);
3143 if (os_strcmp(var
, "sim_num") == 0) {
3144 cred
->sim_num
= atoi(value
);
3148 val
= wpa_config_parse_string(value
, &len
);
3150 (os_strcmp(var
, "excluded_ssid") != 0 &&
3151 os_strcmp(var
, "roaming_consortium") != 0 &&
3152 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3153 has_newline(val
))) {
3154 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3155 "value '%s'.", line
, var
, value
);
3160 if (os_strcmp(var
, "realm") == 0) {
3161 os_free(cred
->realm
);
3166 if (os_strcmp(var
, "username") == 0) {
3167 str_clear_free(cred
->username
);
3168 cred
->username
= val
;
3172 if (os_strcmp(var
, "password") == 0) {
3173 str_clear_free(cred
->password
);
3174 cred
->password
= val
;
3175 cred
->ext_password
= 0;
3179 if (os_strcmp(var
, "ca_cert") == 0) {
3180 os_free(cred
->ca_cert
);
3181 cred
->ca_cert
= val
;
3185 if (os_strcmp(var
, "client_cert") == 0) {
3186 os_free(cred
->client_cert
);
3187 cred
->client_cert
= val
;
3191 if (os_strcmp(var
, "private_key") == 0) {
3192 os_free(cred
->private_key
);
3193 cred
->private_key
= val
;
3197 if (os_strcmp(var
, "private_key_passwd") == 0) {
3198 str_clear_free(cred
->private_key_passwd
);
3199 cred
->private_key_passwd
= val
;
3203 if (os_strcmp(var
, "imsi") == 0) {
3204 os_free(cred
->imsi
);
3209 if (os_strcmp(var
, "milenage") == 0) {
3210 str_clear_free(cred
->milenage
);
3211 cred
->milenage
= val
;
3215 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3216 os_free(cred
->domain_suffix_match
);
3217 cred
->domain_suffix_match
= val
;
3221 if (os_strcmp(var
, "domain") == 0) {
3223 new_domain
= os_realloc_array(cred
->domain
,
3224 cred
->num_domain
+ 1,
3226 if (new_domain
== NULL
) {
3230 new_domain
[cred
->num_domain
++] = val
;
3231 cred
->domain
= new_domain
;
3235 if (os_strcmp(var
, "phase1") == 0) {
3236 os_free(cred
->phase1
);
3241 if (os_strcmp(var
, "phase2") == 0) {
3242 os_free(cred
->phase2
);
3247 if (os_strcmp(var
, "roaming_consortium") == 0) {
3248 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3249 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3250 "roaming_consortium length %d (3..15 "
3251 "expected)", line
, (int) len
);
3255 os_memcpy(cred
->roaming_consortium
, val
, len
);
3256 cred
->roaming_consortium_len
= len
;
3261 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3262 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3264 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3265 "required_roaming_consortium length %d "
3266 "(3..15 expected)", line
, (int) len
);
3270 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3271 cred
->required_roaming_consortium_len
= len
;
3276 if (os_strcmp(var
, "excluded_ssid") == 0) {
3277 struct excluded_ssid
*e
;
3279 if (len
> SSID_MAX_LEN
) {
3280 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3281 "excluded_ssid length %d", line
, (int) len
);
3286 e
= os_realloc_array(cred
->excluded_ssid
,
3287 cred
->num_excluded_ssid
+ 1,
3288 sizeof(struct excluded_ssid
));
3293 cred
->excluded_ssid
= e
;
3295 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3296 os_memcpy(e
->ssid
, val
, len
);
3304 if (os_strcmp(var
, "roaming_partner") == 0) {
3305 struct roaming_partner
*p
;
3308 p
= os_realloc_array(cred
->roaming_partner
,
3309 cred
->num_roaming_partner
+ 1,
3310 sizeof(struct roaming_partner
));
3315 cred
->roaming_partner
= p
;
3317 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3319 pos
= os_strchr(val
, ',');
3325 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3329 os_memcpy(p
->fqdn
, val
, pos
- val
);
3331 p
->exact_match
= atoi(pos
);
3333 pos
= os_strchr(pos
, ',');
3340 p
->priority
= atoi(pos
);
3342 pos
= os_strchr(pos
, ',');
3349 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3353 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3355 cred
->num_roaming_partner
++;
3361 if (os_strcmp(var
, "provisioning_sp") == 0) {
3362 os_free(cred
->provisioning_sp
);
3363 cred
->provisioning_sp
= val
;
3368 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3378 static char * alloc_int_str(int val
)
3380 const unsigned int bufsize
= 20;
3384 buf
= os_malloc(bufsize
);
3387 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3388 if (os_snprintf_error(bufsize
, res
)) {
3396 static char * alloc_strdup(const char *str
)
3400 return os_strdup(str
);
3404 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3406 if (os_strcmp(var
, "temporary") == 0)
3407 return alloc_int_str(cred
->temporary
);
3409 if (os_strcmp(var
, "priority") == 0)
3410 return alloc_int_str(cred
->priority
);
3412 if (os_strcmp(var
, "sp_priority") == 0)
3413 return alloc_int_str(cred
->sp_priority
);
3415 if (os_strcmp(var
, "pcsc") == 0)
3416 return alloc_int_str(cred
->pcsc
);
3418 if (os_strcmp(var
, "eap") == 0) {
3419 if (!cred
->eap_method
)
3421 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3422 cred
->eap_method
[0].method
));
3425 if (os_strcmp(var
, "update_identifier") == 0)
3426 return alloc_int_str(cred
->update_identifier
);
3428 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3429 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3431 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3432 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3434 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3435 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3437 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3438 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3440 if (os_strcmp(var
, "max_bss_load") == 0)
3441 return alloc_int_str(cred
->max_bss_load
);
3443 if (os_strcmp(var
, "req_conn_capab") == 0) {
3445 char *buf
, *end
, *pos
;
3448 if (!cred
->num_req_conn_capab
)
3451 buf
= os_malloc(4000);
3456 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3459 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3461 cred
->req_conn_capab_proto
[i
]);
3462 if (os_snprintf_error(end
- pos
, ret
))
3466 ports
= cred
->req_conn_capab_port
[i
];
3469 for (j
= 0; ports
[j
] != -1; j
++) {
3470 ret
= os_snprintf(pos
, end
- pos
,
3474 if (os_snprintf_error(end
- pos
, ret
))
3484 if (os_strcmp(var
, "ocsp") == 0)
3485 return alloc_int_str(cred
->ocsp
);
3487 if (os_strcmp(var
, "realm") == 0)
3488 return alloc_strdup(cred
->realm
);
3490 if (os_strcmp(var
, "username") == 0)
3491 return alloc_strdup(cred
->username
);
3493 if (os_strcmp(var
, "password") == 0) {
3494 if (!cred
->password
)
3496 return alloc_strdup("*");
3499 if (os_strcmp(var
, "ca_cert") == 0)
3500 return alloc_strdup(cred
->ca_cert
);
3502 if (os_strcmp(var
, "client_cert") == 0)
3503 return alloc_strdup(cred
->client_cert
);
3505 if (os_strcmp(var
, "private_key") == 0)
3506 return alloc_strdup(cred
->private_key
);
3508 if (os_strcmp(var
, "private_key_passwd") == 0) {
3509 if (!cred
->private_key_passwd
)
3511 return alloc_strdup("*");
3514 if (os_strcmp(var
, "imsi") == 0)
3515 return alloc_strdup(cred
->imsi
);
3517 if (os_strcmp(var
, "milenage") == 0) {
3518 if (!(cred
->milenage
))
3520 return alloc_strdup("*");
3523 if (os_strcmp(var
, "domain_suffix_match") == 0)
3524 return alloc_strdup(cred
->domain_suffix_match
);
3526 if (os_strcmp(var
, "domain") == 0) {
3528 char *buf
, *end
, *pos
;
3531 if (!cred
->num_domain
)
3534 buf
= os_malloc(4000);
3540 for (i
= 0; i
< cred
->num_domain
; i
++) {
3541 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3542 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3543 if (os_snprintf_error(end
- pos
, ret
))
3551 if (os_strcmp(var
, "phase1") == 0)
3552 return alloc_strdup(cred
->phase1
);
3554 if (os_strcmp(var
, "phase2") == 0)
3555 return alloc_strdup(cred
->phase2
);
3557 if (os_strcmp(var
, "roaming_consortium") == 0) {
3561 if (!cred
->roaming_consortium_len
)
3563 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3564 buf
= os_malloc(buflen
);
3567 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3568 cred
->roaming_consortium_len
);
3572 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3576 if (!cred
->required_roaming_consortium_len
)
3578 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3579 buf
= os_malloc(buflen
);
3582 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
3583 cred
->required_roaming_consortium_len
);
3587 if (os_strcmp(var
, "excluded_ssid") == 0) {
3589 char *buf
, *end
, *pos
;
3591 if (!cred
->num_excluded_ssid
)
3594 buf
= os_malloc(4000);
3600 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
3601 struct excluded_ssid
*e
;
3604 e
= &cred
->excluded_ssid
[i
];
3605 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3607 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
3608 if (os_snprintf_error(end
- pos
, ret
))
3616 if (os_strcmp(var
, "roaming_partner") == 0) {
3618 char *buf
, *end
, *pos
;
3620 if (!cred
->num_roaming_partner
)
3623 buf
= os_malloc(4000);
3629 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
3630 struct roaming_partner
*p
;
3633 p
= &cred
->roaming_partner
[i
];
3634 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
3636 p
->fqdn
, p
->exact_match
, p
->priority
,
3638 if (os_snprintf_error(end
- pos
, ret
))
3646 if (os_strcmp(var
, "provisioning_sp") == 0)
3647 return alloc_strdup(cred
->provisioning_sp
);
3653 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
3655 struct wpa_cred
*cred
;
3657 cred
= config
->cred
;
3668 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
3671 struct wpa_cred
*cred
, *last
= NULL
;
3674 cred
= config
->cred
;
3683 cred
= os_zalloc(sizeof(*cred
));
3687 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
3691 config
->cred
= cred
;
3697 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
3699 struct wpa_cred
*cred
, *prev
= NULL
;
3701 cred
= config
->cred
;
3713 prev
->next
= cred
->next
;
3715 config
->cred
= cred
->next
;
3717 wpa_config_free_cred(cred
);
3722 #ifndef CONFIG_NO_CONFIG_BLOBS
3724 * wpa_config_get_blob - Get a named configuration blob
3725 * @config: Configuration data from wpa_config_read()
3726 * @name: Name of the blob
3727 * Returns: Pointer to blob data or %NULL if not found
3729 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
3732 struct wpa_config_blob
*blob
= config
->blobs
;
3735 if (os_strcmp(blob
->name
, name
) == 0)
3744 * wpa_config_set_blob - Set or add a named configuration blob
3745 * @config: Configuration data from wpa_config_read()
3746 * @blob: New value for the blob
3748 * Adds a new configuration blob or replaces the current value of an existing
3751 void wpa_config_set_blob(struct wpa_config
*config
,
3752 struct wpa_config_blob
*blob
)
3754 wpa_config_remove_blob(config
, blob
->name
);
3755 blob
->next
= config
->blobs
;
3756 config
->blobs
= blob
;
3761 * wpa_config_free_blob - Free blob data
3762 * @blob: Pointer to blob to be freed
3764 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
3767 os_free(blob
->name
);
3768 bin_clear_free(blob
->data
, blob
->len
);
3775 * wpa_config_remove_blob - Remove a named configuration blob
3776 * @config: Configuration data from wpa_config_read()
3777 * @name: Name of the blob to remove
3778 * Returns: 0 if blob was removed or -1 if blob was not found
3780 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
3782 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
3785 if (os_strcmp(pos
->name
, name
) == 0) {
3787 prev
->next
= pos
->next
;
3789 config
->blobs
= pos
->next
;
3790 wpa_config_free_blob(pos
);
3799 #endif /* CONFIG_NO_CONFIG_BLOBS */
3803 * wpa_config_alloc_empty - Allocate an empty configuration
3804 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3806 * @driver_param: Driver parameters
3807 * Returns: Pointer to allocated configuration data or %NULL on failure
3809 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
3810 const char *driver_param
)
3812 struct wpa_config
*config
;
3813 const int aCWmin
= 4, aCWmax
= 10;
3814 const struct hostapd_wmm_ac_params ac_bk
=
3815 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
3816 const struct hostapd_wmm_ac_params ac_be
=
3817 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
3818 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
3819 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
3820 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
3821 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
3823 config
= os_zalloc(sizeof(*config
));
3826 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
3827 config
->ap_scan
= DEFAULT_AP_SCAN
;
3828 config
->user_mpm
= DEFAULT_USER_MPM
;
3829 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
3830 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
3831 config
->dot11RSNASAERetransPeriod
=
3832 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
3833 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
3834 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
3835 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
3836 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
3837 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
3838 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
3839 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
3840 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
3841 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
3842 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
3843 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
3844 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
3845 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
3846 config
->wmm_ac_params
[0] = ac_be
;
3847 config
->wmm_ac_params
[1] = ac_bk
;
3848 config
->wmm_ac_params
[2] = ac_vi
;
3849 config
->wmm_ac_params
[3] = ac_vo
;
3850 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
3851 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
3852 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
3853 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
3854 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
3857 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
3858 config
->disassoc_imminent_rssi_threshold
=
3859 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
3860 #endif /* CONFIG_MBO */
3863 config
->ctrl_interface
= os_strdup(ctrl_interface
);
3865 config
->driver_param
= os_strdup(driver_param
);
3866 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
3872 #ifndef CONFIG_NO_STDOUT_DEBUG
3874 * wpa_config_debug_dump_networks - Debug dump of configured networks
3875 * @config: Configuration data from wpa_config_read()
3877 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
3880 struct wpa_ssid
*ssid
;
3882 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
3883 ssid
= config
->pssid
[prio
];
3884 wpa_printf(MSG_DEBUG
, "Priority group %d",
3887 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
3889 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
3894 #endif /* CONFIG_NO_STDOUT_DEBUG */
3897 struct global_parse_data
{
3899 int (*parser
)(const struct global_parse_data
*data
,
3900 struct wpa_config
*config
, int line
, const char *value
);
3901 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
3902 char *buf
, size_t buflen
, int pretty_print
);
3903 void *param1
, *param2
, *param3
;
3904 unsigned int changed_flag
;
3908 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
3909 struct wpa_config
*config
, int line
,
3915 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
3916 val
= strtol(pos
, &end
, 0);
3918 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
3924 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
3926 if (data
->param2
&& *dst
< (long) data
->param2
) {
3927 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
3928 "min_value=%ld)", line
, data
->name
, *dst
,
3929 (long) data
->param2
);
3930 *dst
= (long) data
->param2
;
3934 if (data
->param3
&& *dst
> (long) data
->param3
) {
3935 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
3936 "max_value=%ld)", line
, data
->name
, *dst
,
3937 (long) data
->param3
);
3938 *dst
= (long) data
->param3
;
3946 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
3947 struct wpa_config
*config
, int line
,
3953 len
= os_strlen(pos
);
3954 if (data
->param2
&& len
< (size_t) data
->param2
) {
3955 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
3956 "min_len=%ld)", line
, data
->name
,
3957 (unsigned long) len
, (long) data
->param2
);
3961 if (data
->param3
&& len
> (size_t) data
->param3
) {
3962 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
3963 "max_len=%ld)", line
, data
->name
,
3964 (unsigned long) len
, (long) data
->param3
);
3968 if (has_newline(pos
)) {
3969 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
3974 tmp
= os_strdup(pos
);
3978 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
3981 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
3987 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
3988 struct wpa_config
*config
, int line
,
3995 tmp
= wpa_config_parse_string(pos
, &len
);
3997 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
4002 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
4008 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
4009 struct wpa_config
*config
, int line
,
4012 struct wpabuf
**dst
, *tmp
;
4014 tmp
= wpabuf_parse_bin(pos
);
4018 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
4021 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
4027 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
4028 struct wpa_config
*config
, int line
,
4033 freqs
= wpa_config_parse_int_array(value
);
4036 if (freqs
[0] == 0) {
4040 os_free(config
->freq_list
);
4041 config
->freq_list
= freqs
;
4047 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
4048 struct wpa_config
*config
, int line
,
4052 struct hostapd_ip_addr addr
;
4054 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
4056 if (addr
.af
!= AF_INET
)
4059 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
4060 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4061 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4062 WPA_GET_BE32((u8
*) dst
));
4066 #endif /* CONFIG_P2P */
4069 static int wpa_config_process_country(const struct global_parse_data
*data
,
4070 struct wpa_config
*config
, int line
,
4073 if (!pos
[0] || !pos
[1]) {
4074 wpa_printf(MSG_DEBUG
, "Invalid country set");
4077 config
->country
[0] = pos
[0];
4078 config
->country
[1] = pos
[1];
4079 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4080 config
->country
[0], config
->country
[1]);
4085 static int wpa_config_process_load_dynamic_eap(
4086 const struct global_parse_data
*data
, struct wpa_config
*config
,
4087 int line
, const char *so
)
4090 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4091 ret
= eap_peer_method_load(so
);
4093 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4096 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4097 "method '%s'.", line
, so
);
4107 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4108 struct wpa_config
*config
, int line
,
4112 if (uuid_str2bin(pos
, config
->uuid
)) {
4113 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4116 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4117 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4122 static int wpa_config_process_device_type(
4123 const struct global_parse_data
*data
,
4124 struct wpa_config
*config
, int line
, const char *pos
)
4126 return wps_dev_type_str2bin(pos
, config
->device_type
);
4130 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4131 struct wpa_config
*config
, int line
,
4134 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4135 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4138 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4139 WPA_GET_BE32(config
->os_version
));
4144 static int wpa_config_process_wps_vendor_ext_m1(
4145 const struct global_parse_data
*data
,
4146 struct wpa_config
*config
, int line
, const char *pos
)
4149 int len
= os_strlen(pos
) / 2;
4153 wpa_printf(MSG_ERROR
, "Line %d: "
4154 "invalid wps_vendor_ext_m1", line
);
4158 tmp
= wpabuf_alloc(len
);
4160 p
= wpabuf_put(tmp
, len
);
4162 if (hexstr2bin(pos
, p
, len
)) {
4163 wpa_printf(MSG_ERROR
, "Line %d: "
4164 "invalid wps_vendor_ext_m1", line
);
4169 wpabuf_free(config
->wps_vendor_ext_m1
);
4170 config
->wps_vendor_ext_m1
= tmp
;
4172 wpa_printf(MSG_ERROR
, "Can not allocate "
4173 "memory for wps_vendor_ext_m1");
4180 #endif /* CONFIG_WPS */
4183 static int wpa_config_process_sec_device_type(
4184 const struct global_parse_data
*data
,
4185 struct wpa_config
*config
, int line
, const char *pos
)
4189 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4190 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4195 idx
= config
->num_sec_device_types
;
4197 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4200 config
->num_sec_device_types
++;
4205 static int wpa_config_process_p2p_pref_chan(
4206 const struct global_parse_data
*data
,
4207 struct wpa_config
*config
, int line
, const char *pos
)
4209 struct p2p_channel
*pref
= NULL
, *n
;
4210 unsigned int num
= 0;
4214 /* format: class:chan,class:chan,... */
4217 op_class
= atoi(pos
);
4218 pos2
= os_strchr(pos
, ':');
4224 n
= os_realloc_array(pref
, num
+ 1,
4225 sizeof(struct p2p_channel
));
4229 pref
[num
].op_class
= op_class
;
4230 pref
[num
].chan
= chan
;
4233 pos
= os_strchr(pos2
, ',');
4239 os_free(config
->p2p_pref_chan
);
4240 config
->p2p_pref_chan
= pref
;
4241 config
->num_p2p_pref_chan
= num
;
4242 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4243 (u8
*) config
->p2p_pref_chan
,
4244 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4250 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4255 static int wpa_config_process_p2p_no_go_freq(
4256 const struct global_parse_data
*data
,
4257 struct wpa_config
*config
, int line
, const char *pos
)
4261 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4263 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4267 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4268 config
->p2p_no_go_freq
.num
);
4273 #endif /* CONFIG_P2P */
4276 static int wpa_config_process_hessid(
4277 const struct global_parse_data
*data
,
4278 struct wpa_config
*config
, int line
, const char *pos
)
4280 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4281 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4290 static int wpa_config_process_sae_groups(
4291 const struct global_parse_data
*data
,
4292 struct wpa_config
*config
, int line
, const char *pos
)
4294 int *groups
= wpa_config_parse_int_array(pos
);
4295 if (groups
== NULL
) {
4296 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4301 os_free(config
->sae_groups
);
4302 config
->sae_groups
= groups
;
4308 static int wpa_config_process_ap_vendor_elements(
4309 const struct global_parse_data
*data
,
4310 struct wpa_config
*config
, int line
, const char *pos
)
4313 int len
= os_strlen(pos
) / 2;
4317 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4322 tmp
= wpabuf_alloc(len
);
4324 p
= wpabuf_put(tmp
, len
);
4326 if (hexstr2bin(pos
, p
, len
)) {
4327 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4328 "ap_vendor_elements", line
);
4333 wpabuf_free(config
->ap_vendor_elements
);
4334 config
->ap_vendor_elements
= tmp
;
4336 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4337 "ap_vendor_elements");
4345 #ifdef CONFIG_CTRL_IFACE
4346 static int wpa_config_process_no_ctrl_interface(
4347 const struct global_parse_data
*data
,
4348 struct wpa_config
*config
, int line
, const char *pos
)
4350 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4351 os_free(config
->ctrl_interface
);
4352 config
->ctrl_interface
= NULL
;
4355 #endif /* CONFIG_CTRL_IFACE */
4358 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4359 long offset
, char *buf
, size_t buflen
,
4362 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4365 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4366 return os_snprintf(buf
, buflen
, "%d", *val
);
4370 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4371 long offset
, char *buf
, size_t buflen
,
4374 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4378 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4379 *val
? *val
: "null");
4383 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4384 if (os_snprintf_error(buflen
, res
))
4392 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4393 long offset
, char *buf
, size_t buflen
,
4396 void *val
= ((u8
*) config
) + (long) offset
;
4398 char addr
[INET_ADDRSTRLEN
];
4400 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4404 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4406 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4408 if (os_snprintf_error(buflen
, res
))
4413 #endif /* CONFIG_P2P */
4419 /* OFFSET: Get offset of a variable within the wpa_config structure */
4420 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4422 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4423 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4424 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4425 #define INT(f) _INT(f), NULL, NULL
4426 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4427 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4428 #define STR(f) _STR(f), NULL, NULL
4429 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4430 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4431 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4432 OFFSET(f), NULL, NULL
4434 static const struct global_parse_data global_fields
[] = {
4435 #ifdef CONFIG_CTRL_IFACE
4436 { STR(ctrl_interface
), 0 },
4437 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4438 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4439 #endif /* CONFIG_CTRL_IFACE */
4440 #ifdef CONFIG_MACSEC
4441 { INT_RANGE(eapol_version
, 1, 3), 0 },
4442 #else /* CONFIG_MACSEC */
4443 { INT_RANGE(eapol_version
, 1, 2), 0 },
4444 #endif /* CONFIG_MACSEC */
4445 { INT(ap_scan
), 0 },
4446 { FUNC(bgscan
), 0 },
4448 { INT(user_mpm
), 0 },
4449 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4450 { INT(mesh_max_inactivity
), 0 },
4451 { INT(dot11RSNASAERetransPeriod
), 0 },
4452 #endif /* CONFIG_MESH */
4453 { INT(disable_scan_offload
), 0 },
4454 { INT(fast_reauth
), 0 },
4455 { STR(opensc_engine_path
), 0 },
4456 { STR(pkcs11_engine_path
), 0 },
4457 { STR(pkcs11_module_path
), 0 },
4458 { STR(openssl_ciphers
), 0 },
4459 { STR(pcsc_reader
), 0 },
4460 { STR(pcsc_pin
), 0 },
4461 { INT(external_sim
), 0 },
4462 { STR(driver_param
), 0 },
4463 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4464 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4465 { INT(dot11RSNAConfigSATimeout
), 0 },
4466 #ifndef CONFIG_NO_CONFIG_WRITE
4467 { INT(update_config
), 0 },
4468 #endif /* CONFIG_NO_CONFIG_WRITE */
4469 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4471 { FUNC(uuid
), CFG_CHANGED_UUID
},
4472 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4473 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4474 CFG_CHANGED_DEVICE_NAME
},
4475 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4476 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4477 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4478 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4479 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4480 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4481 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4482 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4483 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4484 #endif /* CONFIG_WPS */
4486 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4487 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4488 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4489 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4490 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4491 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4492 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4493 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4494 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4495 { INT(p2p_group_idle
), 0 },
4496 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4497 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4498 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4499 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4500 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4501 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4502 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4503 { INT(p2p_go_ht40
), 0 },
4504 { INT(p2p_go_vht
), 0 },
4505 { INT(p2p_disabled
), 0 },
4506 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4507 { INT(p2p_no_group_iface
), 0 },
4508 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4509 { IPV4(ip_addr_go
), 0 },
4510 { IPV4(ip_addr_mask
), 0 },
4511 { IPV4(ip_addr_start
), 0 },
4512 { IPV4(ip_addr_end
), 0 },
4513 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4514 #endif /* CONFIG_P2P */
4515 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4516 { INT(bss_max_count
), 0 },
4517 { INT(bss_expiration_age
), 0 },
4518 { INT(bss_expiration_scan_count
), 0 },
4519 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4520 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4521 { INT(max_num_sta
), 0 },
4522 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4524 { INT_RANGE(hs20
, 0, 1), 0 },
4525 #endif /* CONFIG_HS20 */
4526 { INT_RANGE(interworking
, 0, 1), 0 },
4527 { FUNC(hessid
), 0 },
4528 { INT_RANGE(access_network_type
, 0, 15), 0 },
4529 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
4530 { STR(autoscan
), 0 },
4531 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
4532 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4533 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4534 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4535 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4536 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
4537 { INT(p2p_go_max_inactivity
), 0 },
4538 { INT_RANGE(auto_interworking
, 0, 1), 0 },
4541 { FUNC(sae_groups
), 0 },
4542 { INT(dtim_period
), 0 },
4543 { INT(beacon_int
), 0 },
4544 { FUNC(ap_vendor_elements
), 0 },
4545 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
4546 { FUNC(freq_list
), 0 },
4547 { INT(scan_cur_freq
), 0 },
4548 { INT(sched_scan_interval
), 0 },
4549 { INT(sched_scan_start_delay
), 0 },
4550 { INT(tdls_external_control
), 0},
4551 { STR(osu_dir
), 0 },
4552 { STR(wowlan_triggers
), 0 },
4553 { INT(p2p_search_delay
), 0},
4554 { INT(mac_addr
), 0 },
4555 { INT(rand_addr_lifetime
), 0 },
4556 { INT(preassoc_mac_addr
), 0 },
4557 { INT(key_mgmt_offload
), 0},
4558 { INT(passive_scan
), 0 },
4559 { INT(reassoc_same_bss_optim
), 0 },
4560 { INT(wps_priority
), 0},
4562 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
4563 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
4564 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
4565 #endif /* CONFIG_FST */
4566 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
4567 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
4568 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
4570 { STR(non_pref_chan
), 0 },
4571 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
4572 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
4573 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
4574 #endif /* CONFIG_MBO */
4575 { INT(gas_address3
), 0 },
4576 { INT_RANGE(ftm_responder
, 0, 1), 0 },
4577 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
4578 { INT(gas_rand_addr_lifetime
), 0 },
4579 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
4580 { INT_RANGE(dpp_config_processing
, 0, 2), 0 },
4592 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4595 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
4600 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4601 const struct global_parse_data
*field
= &global_fields
[i
];
4607 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
4619 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
4620 char *buf
, size_t buflen
)
4624 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4625 const struct global_parse_data
*field
= &global_fields
[i
];
4627 if (os_strcmp(name
, field
->name
) != 0)
4631 return field
->get(name
, config
, (long) field
->param1
,
4639 int wpa_config_get_num_global_field_names(void)
4641 return NUM_GLOBAL_FIELDS
;
4645 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
4647 if (i
>= NUM_GLOBAL_FIELDS
)
4651 *no_var
= !global_fields
[i
].param1
;
4652 return global_fields
[i
].name
;
4656 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
4661 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4662 const struct global_parse_data
*field
= &global_fields
[i
];
4663 size_t flen
= os_strlen(field
->name
);
4664 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
4668 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
4669 wpa_printf(MSG_ERROR
, "Line %d: failed to "
4670 "parse '%s'.", line
, pos
);
4673 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
4674 config
->wps_nfc_pw_from_config
= 1;
4675 config
->changed_parameters
|= field
->changed_flag
;
4678 if (i
== NUM_GLOBAL_FIELDS
) {
4680 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
4681 char *tmp
= os_strchr(pos
, '=');
4685 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
4690 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
4692 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
4697 #endif /* CONFIG_AP */
4700 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",