2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/uuid.h"
13 #include "utils/ip_addr.h"
14 #include "common/ieee802_1x_defs.h"
15 #include "crypto/sha1.h"
16 #include "rsn_supp/wpa.h"
17 #include "eap_peer/eap.h"
23 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
24 #define NO_CONFIG_WRITE
28 * Structure for network configuration parsing. This data is used to implement
29 * a generic parser for each network block variable. The table of configuration
30 * variables is defined below in this file (ssid_fields[]).
33 /* Configuration variable name */
36 /* Parser function for this variable. The parser functions return 0 or 1
37 * to indicate success. Value 0 indicates that the parameter value may
38 * have changed while value 1 means that the value did not change.
39 * Error cases (failure to parse the string) are indicated by returning
41 int (*parser
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
,
42 int line
, const char *value
);
44 #ifndef NO_CONFIG_WRITE
45 /* Writer function (i.e., to get the variable in text format from
46 * internal presentation). */
47 char * (*writer
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
);
48 #endif /* NO_CONFIG_WRITE */
50 /* Variable specific parameters for the parser. */
51 void *param1
, *param2
, *param3
, *param4
;
53 /* 0 = this variable can be included in debug output and ctrl_iface
54 * 1 = this variable contains key/private data and it must not be
55 * included in debug output unless explicitly requested. In
56 * addition, this variable will not be readable through the
63 static int wpa_config_parse_str(const struct parse_data
*data
,
64 struct wpa_ssid
*ssid
,
65 int line
, const char *value
)
67 size_t res_len
, *dst_len
, prev_len
;
70 if (os_strcmp(value
, "NULL") == 0) {
71 wpa_printf(MSG_DEBUG
, "Unset configuration string '%s'",
78 tmp
= wpa_config_parse_string(value
, &res_len
);
80 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s '%s'.",
82 data
->key_data
? "[KEY DATA REMOVED]" : value
);
87 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
90 wpa_hexdump_ascii(MSG_MSGDUMP
, data
->name
,
94 if (data
->param3
&& res_len
< (size_t) data
->param3
) {
95 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
96 "min_len=%ld)", line
, data
->name
,
97 (unsigned long) res_len
, (long) data
->param3
);
102 if (data
->param4
&& res_len
> (size_t) data
->param4
) {
103 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
104 "max_len=%ld)", line
, data
->name
,
105 (unsigned long) res_len
, (long) data
->param4
);
111 dst
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
112 dst_len
= (size_t *) (((u8
*) ssid
) + (long) data
->param2
);
117 prev_len
= os_strlen(*dst
);
120 if ((*dst
== NULL
&& tmp
== NULL
) ||
121 (*dst
&& tmp
&& prev_len
== res_len
&&
122 os_memcmp(*dst
, tmp
, res_len
) == 0)) {
123 /* No change to the previously configured value */
137 #ifndef NO_CONFIG_WRITE
138 static char * wpa_config_write_string_ascii(const u8
*value
, size_t len
)
142 buf
= os_malloc(len
+ 3);
146 os_memcpy(buf
+ 1, value
, len
);
154 static char * wpa_config_write_string_hex(const u8
*value
, size_t len
)
158 buf
= os_zalloc(2 * len
+ 1);
161 wpa_snprintf_hex(buf
, 2 * len
+ 1, value
, len
);
167 static char * wpa_config_write_string(const u8
*value
, size_t len
)
172 if (is_hex(value
, len
))
173 return wpa_config_write_string_hex(value
, len
);
175 return wpa_config_write_string_ascii(value
, len
);
179 static char * wpa_config_write_str(const struct parse_data
*data
,
180 struct wpa_ssid
*ssid
)
185 src
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
190 len
= *((size_t *) (((u8
*) ssid
) + (long) data
->param2
));
192 len
= os_strlen(*src
);
194 return wpa_config_write_string((const u8
*) *src
, len
);
196 #endif /* NO_CONFIG_WRITE */
199 static int wpa_config_parse_int(const struct parse_data
*data
,
200 struct wpa_ssid
*ssid
,
201 int line
, const char *value
)
206 dst
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
207 val
= strtol(value
, &end
, 0);
209 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
217 wpa_printf(MSG_MSGDUMP
, "%s=%d (0x%x)", data
->name
, *dst
, *dst
);
219 if (data
->param3
&& *dst
< (long) data
->param3
) {
220 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
221 "min_value=%ld)", line
, data
->name
, *dst
,
222 (long) data
->param3
);
223 *dst
= (long) data
->param3
;
227 if (data
->param4
&& *dst
> (long) data
->param4
) {
228 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
229 "max_value=%ld)", line
, data
->name
, *dst
,
230 (long) data
->param4
);
231 *dst
= (long) data
->param4
;
239 #ifndef NO_CONFIG_WRITE
240 static char * wpa_config_write_int(const struct parse_data
*data
,
241 struct wpa_ssid
*ssid
)
246 src
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
248 value
= os_malloc(20);
251 res
= os_snprintf(value
, 20, "%d", *src
);
252 if (os_snprintf_error(20, res
)) {
256 value
[20 - 1] = '\0';
259 #endif /* NO_CONFIG_WRITE */
262 static int wpa_config_parse_addr_list(const struct parse_data
*data
,
263 int line
, const char *value
,
264 u8
**list
, size_t *num
, char *name
,
265 u8 abort_on_error
, u8 masked
)
268 u8
*buf
, *n
, addr
[2 * ETH_ALEN
];
275 while (pos
&& *pos
) {
279 if (hwaddr_masked_aton(pos
, addr
, &addr
[ETH_ALEN
], masked
)) {
280 if (abort_on_error
|| count
== 0) {
281 wpa_printf(MSG_ERROR
,
282 "Line %d: Invalid %s address '%s'",
287 /* continue anyway since this could have been from a
288 * truncated configuration file line */
290 "Line %d: Ignore likely truncated %s address '%s'",
293 n
= os_realloc_array(buf
, count
+ 1, 2 * ETH_ALEN
);
299 os_memmove(buf
+ 2 * ETH_ALEN
, buf
,
300 count
* 2 * ETH_ALEN
);
301 os_memcpy(buf
, addr
, 2 * ETH_ALEN
);
303 wpa_printf(MSG_MSGDUMP
,
304 "%s: addr=" MACSTR
" mask=" MACSTR
,
306 MAC2STR(&addr
[ETH_ALEN
]));
309 pos
= os_strchr(pos
, ' ');
320 #ifndef NO_CONFIG_WRITE
321 static char * wpa_config_write_addr_list(const struct parse_data
*data
,
322 const u8
*list
, size_t num
, char *name
)
324 char *value
, *end
, *pos
;
328 if (list
== NULL
|| num
== 0)
331 value
= os_malloc(2 * 20 * num
);
335 end
= value
+ 2 * 20 * num
;
337 for (i
= num
; i
> 0; i
--) {
338 const u8
*a
= list
+ (i
- 1) * 2 * ETH_ALEN
;
339 const u8
*m
= a
+ ETH_ALEN
;
343 res
= hwaddr_mask_txt(pos
, end
- pos
, a
, m
);
353 #endif /* NO_CONFIG_WRITE */
355 static int wpa_config_parse_bssid(const struct parse_data
*data
,
356 struct wpa_ssid
*ssid
, int line
,
359 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
360 os_strcmp(value
, "any") == 0) {
362 wpa_printf(MSG_MSGDUMP
, "BSSID any");
365 if (hwaddr_aton(value
, ssid
->bssid
)) {
366 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID '%s'.",
371 wpa_hexdump(MSG_MSGDUMP
, "BSSID", ssid
->bssid
, ETH_ALEN
);
376 #ifndef NO_CONFIG_WRITE
377 static char * wpa_config_write_bssid(const struct parse_data
*data
,
378 struct wpa_ssid
*ssid
)
383 if (!ssid
->bssid_set
)
386 value
= os_malloc(20);
389 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid
));
390 if (os_snprintf_error(20, res
)) {
394 value
[20 - 1] = '\0';
397 #endif /* NO_CONFIG_WRITE */
400 static int wpa_config_parse_bssid_hint(const struct parse_data
*data
,
401 struct wpa_ssid
*ssid
, int line
,
404 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
405 os_strcmp(value
, "any") == 0) {
406 ssid
->bssid_hint_set
= 0;
407 wpa_printf(MSG_MSGDUMP
, "BSSID hint any");
410 if (hwaddr_aton(value
, ssid
->bssid_hint
)) {
411 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID hint '%s'.",
415 ssid
->bssid_hint_set
= 1;
416 wpa_hexdump(MSG_MSGDUMP
, "BSSID hint", ssid
->bssid_hint
, ETH_ALEN
);
421 #ifndef NO_CONFIG_WRITE
422 static char * wpa_config_write_bssid_hint(const struct parse_data
*data
,
423 struct wpa_ssid
*ssid
)
428 if (!ssid
->bssid_hint_set
)
431 value
= os_malloc(20);
434 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid_hint
));
435 if (os_snprintf_error(20, res
)) {
441 #endif /* NO_CONFIG_WRITE */
444 static int wpa_config_parse_bssid_blacklist(const struct parse_data
*data
,
445 struct wpa_ssid
*ssid
, int line
,
448 return wpa_config_parse_addr_list(data
, line
, value
,
449 &ssid
->bssid_blacklist
,
450 &ssid
->num_bssid_blacklist
,
451 "bssid_blacklist", 1, 1);
455 #ifndef NO_CONFIG_WRITE
456 static char * wpa_config_write_bssid_blacklist(const struct parse_data
*data
,
457 struct wpa_ssid
*ssid
)
459 return wpa_config_write_addr_list(data
, ssid
->bssid_blacklist
,
460 ssid
->num_bssid_blacklist
,
463 #endif /* NO_CONFIG_WRITE */
466 static int wpa_config_parse_bssid_whitelist(const struct parse_data
*data
,
467 struct wpa_ssid
*ssid
, int line
,
470 return wpa_config_parse_addr_list(data
, line
, value
,
471 &ssid
->bssid_whitelist
,
472 &ssid
->num_bssid_whitelist
,
473 "bssid_whitelist", 1, 1);
477 #ifndef NO_CONFIG_WRITE
478 static char * wpa_config_write_bssid_whitelist(const struct parse_data
*data
,
479 struct wpa_ssid
*ssid
)
481 return wpa_config_write_addr_list(data
, ssid
->bssid_whitelist
,
482 ssid
->num_bssid_whitelist
,
485 #endif /* NO_CONFIG_WRITE */
488 static int wpa_config_parse_psk(const struct parse_data
*data
,
489 struct wpa_ssid
*ssid
, int line
,
492 #ifdef CONFIG_EXT_PASSWORD
493 if (os_strncmp(value
, "ext:", 4) == 0) {
494 str_clear_free(ssid
->passphrase
);
495 ssid
->passphrase
= NULL
;
497 os_free(ssid
->ext_psk
);
498 ssid
->ext_psk
= os_strdup(value
+ 4);
499 if (ssid
->ext_psk
== NULL
)
501 wpa_printf(MSG_DEBUG
, "PSK: External password '%s'",
505 #endif /* CONFIG_EXT_PASSWORD */
508 #ifndef CONFIG_NO_PBKDF2
513 pos
= os_strrchr(value
, '"');
517 len
= os_strlen(value
);
518 if (len
< 8 || len
> 63) {
519 wpa_printf(MSG_ERROR
, "Line %d: Invalid passphrase "
520 "length %lu (expected: 8..63) '%s'.",
521 line
, (unsigned long) len
, value
);
524 wpa_hexdump_ascii_key(MSG_MSGDUMP
, "PSK (ASCII passphrase)",
526 if (has_ctrl_char((u8
*) value
, len
)) {
527 wpa_printf(MSG_ERROR
,
528 "Line %d: Invalid passphrase character",
532 if (ssid
->passphrase
&& os_strlen(ssid
->passphrase
) == len
&&
533 os_memcmp(ssid
->passphrase
, value
, len
) == 0) {
534 /* No change to the previously configured value */
538 str_clear_free(ssid
->passphrase
);
539 ssid
->passphrase
= dup_binstr(value
, len
);
540 if (ssid
->passphrase
== NULL
)
543 #else /* CONFIG_NO_PBKDF2 */
544 wpa_printf(MSG_ERROR
, "Line %d: ASCII passphrase not "
547 #endif /* CONFIG_NO_PBKDF2 */
550 if (hexstr2bin(value
, ssid
->psk
, PMK_LEN
) ||
551 value
[PMK_LEN
* 2] != '\0') {
552 wpa_printf(MSG_ERROR
, "Line %d: Invalid PSK '%s'.",
557 str_clear_free(ssid
->passphrase
);
558 ssid
->passphrase
= NULL
;
561 wpa_hexdump_key(MSG_MSGDUMP
, "PSK", ssid
->psk
, PMK_LEN
);
566 #ifndef NO_CONFIG_WRITE
567 static char * wpa_config_write_psk(const struct parse_data
*data
,
568 struct wpa_ssid
*ssid
)
570 #ifdef CONFIG_EXT_PASSWORD
572 size_t len
= 4 + os_strlen(ssid
->ext_psk
) + 1;
573 char *buf
= os_malloc(len
);
578 res
= os_snprintf(buf
, len
, "ext:%s", ssid
->ext_psk
);
579 if (os_snprintf_error(len
, res
)) {
585 #endif /* CONFIG_EXT_PASSWORD */
587 if (ssid
->passphrase
)
588 return wpa_config_write_string_ascii(
589 (const u8
*) ssid
->passphrase
,
590 os_strlen(ssid
->passphrase
));
593 return wpa_config_write_string_hex(ssid
->psk
, PMK_LEN
);
597 #endif /* NO_CONFIG_WRITE */
600 static int wpa_config_parse_proto(const struct parse_data
*data
,
601 struct wpa_ssid
*ssid
, int line
,
604 int val
= 0, last
, errors
= 0;
605 char *start
, *end
, *buf
;
607 buf
= os_strdup(value
);
612 while (*start
!= '\0') {
613 while (*start
== ' ' || *start
== '\t')
618 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
622 if (os_strcmp(start
, "WPA") == 0)
623 val
|= WPA_PROTO_WPA
;
624 else if (os_strcmp(start
, "RSN") == 0 ||
625 os_strcmp(start
, "WPA2") == 0)
626 val
|= WPA_PROTO_RSN
;
627 else if (os_strcmp(start
, "OSEN") == 0)
628 val
|= WPA_PROTO_OSEN
;
630 wpa_printf(MSG_ERROR
, "Line %d: invalid proto '%s'",
642 wpa_printf(MSG_ERROR
,
643 "Line %d: no proto values configured.", line
);
647 if (!errors
&& ssid
->proto
== val
)
649 wpa_printf(MSG_MSGDUMP
, "proto: 0x%x", val
);
651 return errors
? -1 : 0;
655 #ifndef NO_CONFIG_WRITE
656 static char * wpa_config_write_proto(const struct parse_data
*data
,
657 struct wpa_ssid
*ssid
)
660 char *buf
, *pos
, *end
;
662 pos
= buf
= os_zalloc(20);
667 if (ssid
->proto
& WPA_PROTO_WPA
) {
668 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
669 pos
== buf
? "" : " ");
670 if (os_snprintf_error(end
- pos
, ret
))
675 if (ssid
->proto
& WPA_PROTO_RSN
) {
676 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
677 pos
== buf
? "" : " ");
678 if (os_snprintf_error(end
- pos
, ret
))
683 if (ssid
->proto
& WPA_PROTO_OSEN
) {
684 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
685 pos
== buf
? "" : " ");
686 if (os_snprintf_error(end
- pos
, ret
))
698 #endif /* NO_CONFIG_WRITE */
701 static int wpa_config_parse_key_mgmt(const struct parse_data
*data
,
702 struct wpa_ssid
*ssid
, int line
,
705 int val
= 0, last
, errors
= 0;
706 char *start
, *end
, *buf
;
708 buf
= os_strdup(value
);
713 while (*start
!= '\0') {
714 while (*start
== ' ' || *start
== '\t')
719 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
723 if (os_strcmp(start
, "WPA-PSK") == 0)
724 val
|= WPA_KEY_MGMT_PSK
;
725 else if (os_strcmp(start
, "WPA-EAP") == 0)
726 val
|= WPA_KEY_MGMT_IEEE8021X
;
727 else if (os_strcmp(start
, "IEEE8021X") == 0)
728 val
|= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
729 else if (os_strcmp(start
, "NONE") == 0)
730 val
|= WPA_KEY_MGMT_NONE
;
731 else if (os_strcmp(start
, "WPA-NONE") == 0)
732 val
|= WPA_KEY_MGMT_WPA_NONE
;
733 #ifdef CONFIG_IEEE80211R
734 else if (os_strcmp(start
, "FT-PSK") == 0)
735 val
|= WPA_KEY_MGMT_FT_PSK
;
736 else if (os_strcmp(start
, "FT-EAP") == 0)
737 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
739 else if (os_strcmp(start
, "FT-EAP-SHA384") == 0)
740 val
|= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
741 #endif /* CONFIG_SHA384 */
742 #endif /* CONFIG_IEEE80211R */
743 else if (os_strcmp(start
, "WPA-PSK-SHA256") == 0)
744 val
|= WPA_KEY_MGMT_PSK_SHA256
;
745 else if (os_strcmp(start
, "WPA-EAP-SHA256") == 0)
746 val
|= WPA_KEY_MGMT_IEEE8021X_SHA256
;
748 else if (os_strcmp(start
, "WPS") == 0)
749 val
|= WPA_KEY_MGMT_WPS
;
750 #endif /* CONFIG_WPS */
752 else if (os_strcmp(start
, "SAE") == 0)
753 val
|= WPA_KEY_MGMT_SAE
;
754 else if (os_strcmp(start
, "FT-SAE") == 0)
755 val
|= WPA_KEY_MGMT_FT_SAE
;
756 #endif /* CONFIG_SAE */
758 else if (os_strcmp(start
, "OSEN") == 0)
759 val
|= WPA_KEY_MGMT_OSEN
;
760 #endif /* CONFIG_HS20 */
762 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
763 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
764 #endif /* CONFIG_SUITEB */
765 #ifdef CONFIG_SUITEB192
766 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
767 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
768 #endif /* CONFIG_SUITEB192 */
770 else if (os_strcmp(start
, "FILS-SHA256") == 0)
771 val
|= WPA_KEY_MGMT_FILS_SHA256
;
772 else if (os_strcmp(start
, "FILS-SHA384") == 0)
773 val
|= WPA_KEY_MGMT_FILS_SHA384
;
774 #ifdef CONFIG_IEEE80211R
775 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
776 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
777 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
778 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
779 #endif /* CONFIG_IEEE80211R */
780 #endif /* CONFIG_FILS */
782 else if (os_strcmp(start
, "OWE") == 0)
783 val
|= WPA_KEY_MGMT_OWE
;
784 #endif /* CONFIG_OWE */
786 else if (os_strcmp(start
, "DPP") == 0)
787 val
|= WPA_KEY_MGMT_DPP
;
788 #endif /* CONFIG_DPP */
790 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
802 wpa_printf(MSG_ERROR
,
803 "Line %d: no key_mgmt values configured.", line
);
807 if (!errors
&& ssid
->key_mgmt
== val
)
809 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
810 ssid
->key_mgmt
= val
;
811 return errors
? -1 : 0;
815 #ifndef NO_CONFIG_WRITE
816 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
817 struct wpa_ssid
*ssid
)
819 char *buf
, *pos
, *end
;
822 pos
= buf
= os_zalloc(100);
827 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
828 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
829 pos
== buf
? "" : " ");
830 if (os_snprintf_error(end
- pos
, ret
)) {
837 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
838 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
839 pos
== buf
? "" : " ");
840 if (os_snprintf_error(end
- pos
, ret
)) {
847 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
848 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
849 pos
== buf
? "" : " ");
850 if (os_snprintf_error(end
- pos
, ret
)) {
857 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
858 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
859 pos
== buf
? "" : " ");
860 if (os_snprintf_error(end
- pos
, ret
)) {
867 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
868 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
869 pos
== buf
? "" : " ");
870 if (os_snprintf_error(end
- pos
, ret
)) {
877 #ifdef CONFIG_IEEE80211R
878 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
879 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
880 pos
== buf
? "" : " ");
881 if (os_snprintf_error(end
- pos
, ret
)) {
888 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
889 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
890 pos
== buf
? "" : " ");
891 if (os_snprintf_error(end
- pos
, ret
)) {
899 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
900 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP-SHA384",
901 pos
== buf
? "" : " ");
902 if (os_snprintf_error(end
- pos
, ret
)) {
908 #endif /* CONFIG_SHA384 */
909 #endif /* CONFIG_IEEE80211R */
911 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
912 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
913 pos
== buf
? "" : " ");
914 if (os_snprintf_error(end
- pos
, ret
)) {
921 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
922 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
923 pos
== buf
? "" : " ");
924 if (os_snprintf_error(end
- pos
, ret
)) {
932 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
933 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
934 pos
== buf
? "" : " ");
935 if (os_snprintf_error(end
- pos
, ret
)) {
941 #endif /* CONFIG_WPS */
944 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
945 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
946 pos
== buf
? "" : " ");
947 if (os_snprintf_error(end
- pos
, ret
)) {
954 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
955 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
956 pos
== buf
? "" : " ");
957 if (os_snprintf_error(end
- pos
, ret
)) {
963 #endif /* CONFIG_SAE */
966 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
967 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
968 pos
== buf
? "" : " ");
969 if (os_snprintf_error(end
- pos
, ret
)) {
975 #endif /* CONFIG_HS20 */
978 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
979 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
980 pos
== buf
? "" : " ");
981 if (os_snprintf_error(end
- pos
, ret
)) {
987 #endif /* CONFIG_SUITEB */
989 #ifdef CONFIG_SUITEB192
990 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
991 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
992 pos
== buf
? "" : " ");
993 if (os_snprintf_error(end
- pos
, ret
)) {
999 #endif /* CONFIG_SUITEB192 */
1002 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1003 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
1004 pos
== buf
? "" : " ");
1005 if (os_snprintf_error(end
- pos
, ret
)) {
1011 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1012 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
1013 pos
== buf
? "" : " ");
1014 if (os_snprintf_error(end
- pos
, ret
)) {
1020 #ifdef CONFIG_IEEE80211R
1021 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1022 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
1023 pos
== buf
? "" : " ");
1024 if (os_snprintf_error(end
- pos
, ret
)) {
1030 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1031 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
1032 pos
== buf
? "" : " ");
1033 if (os_snprintf_error(end
- pos
, ret
)) {
1039 #endif /* CONFIG_IEEE80211R */
1040 #endif /* CONFIG_FILS */
1043 if (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) {
1044 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
1045 pos
== buf
? "" : " ");
1046 if (os_snprintf_error(end
- pos
, ret
)) {
1052 #endif /* CONFIG_DPP */
1055 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) {
1056 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
1057 pos
== buf
? "" : " ");
1058 if (os_snprintf_error(end
- pos
, ret
)) {
1064 #endif /* CONFIG_OWE */
1073 #endif /* NO_CONFIG_WRITE */
1076 static int wpa_config_parse_cipher(int line
, const char *value
)
1078 #ifdef CONFIG_NO_WPA
1080 #else /* CONFIG_NO_WPA */
1081 int val
= wpa_parse_cipher(value
);
1083 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1088 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1093 #endif /* CONFIG_NO_WPA */
1097 #ifndef NO_CONFIG_WRITE
1098 static char * wpa_config_write_cipher(int cipher
)
1100 #ifdef CONFIG_NO_WPA
1102 #else /* CONFIG_NO_WPA */
1103 char *buf
= os_zalloc(50);
1107 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1113 #endif /* CONFIG_NO_WPA */
1115 #endif /* NO_CONFIG_WRITE */
1118 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1119 struct wpa_ssid
*ssid
, int line
,
1123 val
= wpa_config_parse_cipher(line
, value
);
1126 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1127 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1128 "(0x%x).", line
, val
);
1132 if (ssid
->pairwise_cipher
== val
)
1134 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1135 ssid
->pairwise_cipher
= val
;
1140 #ifndef NO_CONFIG_WRITE
1141 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1142 struct wpa_ssid
*ssid
)
1144 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1146 #endif /* NO_CONFIG_WRITE */
1149 static int wpa_config_parse_group(const struct parse_data
*data
,
1150 struct wpa_ssid
*ssid
, int line
,
1154 val
= wpa_config_parse_cipher(line
, value
);
1159 * Backwards compatibility - filter out WEP ciphers that were previously
1162 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1164 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1165 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1166 "(0x%x).", line
, val
);
1170 if (ssid
->group_cipher
== val
)
1172 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1173 ssid
->group_cipher
= val
;
1178 #ifndef NO_CONFIG_WRITE
1179 static char * wpa_config_write_group(const struct parse_data
*data
,
1180 struct wpa_ssid
*ssid
)
1182 return wpa_config_write_cipher(ssid
->group_cipher
);
1184 #endif /* NO_CONFIG_WRITE */
1187 static int wpa_config_parse_group_mgmt(const struct parse_data
*data
,
1188 struct wpa_ssid
*ssid
, int line
,
1193 val
= wpa_config_parse_cipher(line
, value
);
1197 if (val
& ~WPA_ALLOWED_GROUP_MGMT_CIPHERS
) {
1198 wpa_printf(MSG_ERROR
,
1199 "Line %d: not allowed group management cipher (0x%x).",
1204 if (ssid
->group_mgmt_cipher
== val
)
1206 wpa_printf(MSG_MSGDUMP
, "group_mgmt: 0x%x", val
);
1207 ssid
->group_mgmt_cipher
= val
;
1212 #ifndef NO_CONFIG_WRITE
1213 static char * wpa_config_write_group_mgmt(const struct parse_data
*data
,
1214 struct wpa_ssid
*ssid
)
1216 return wpa_config_write_cipher(ssid
->group_mgmt_cipher
);
1218 #endif /* NO_CONFIG_WRITE */
1221 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1222 struct wpa_ssid
*ssid
, int line
,
1225 int val
= 0, last
, errors
= 0;
1226 char *start
, *end
, *buf
;
1228 buf
= os_strdup(value
);
1233 while (*start
!= '\0') {
1234 while (*start
== ' ' || *start
== '\t')
1239 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1241 last
= *end
== '\0';
1243 if (os_strcmp(start
, "OPEN") == 0)
1244 val
|= WPA_AUTH_ALG_OPEN
;
1245 else if (os_strcmp(start
, "SHARED") == 0)
1246 val
|= WPA_AUTH_ALG_SHARED
;
1247 else if (os_strcmp(start
, "LEAP") == 0)
1248 val
|= WPA_AUTH_ALG_LEAP
;
1250 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1262 wpa_printf(MSG_ERROR
,
1263 "Line %d: no auth_alg values configured.", line
);
1267 if (!errors
&& ssid
->auth_alg
== val
)
1269 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1270 ssid
->auth_alg
= val
;
1271 return errors
? -1 : 0;
1275 #ifndef NO_CONFIG_WRITE
1276 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1277 struct wpa_ssid
*ssid
)
1279 char *buf
, *pos
, *end
;
1282 pos
= buf
= os_zalloc(30);
1287 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1288 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1289 pos
== buf
? "" : " ");
1290 if (os_snprintf_error(end
- pos
, ret
)) {
1297 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1298 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1299 pos
== buf
? "" : " ");
1300 if (os_snprintf_error(end
- pos
, ret
)) {
1307 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1308 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1309 pos
== buf
? "" : " ");
1310 if (os_snprintf_error(end
- pos
, ret
)) {
1324 #endif /* NO_CONFIG_WRITE */
1327 static int * wpa_config_parse_int_array(const char *value
)
1335 freqs
= os_calloc(len
+ 1, sizeof(int));
1346 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1351 for (i
= len
; i
<= len
* 2; i
++)
1357 freqs
[used
] = atoi(pos
);
1358 if (freqs
[used
] == 0)
1361 pos
= os_strchr(pos
+ 1, ' ');
1368 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1369 struct wpa_ssid
*ssid
, int line
,
1374 freqs
= wpa_config_parse_int_array(value
);
1377 if (freqs
[0] == 0) {
1381 os_free(ssid
->scan_freq
);
1382 ssid
->scan_freq
= freqs
;
1388 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1389 struct wpa_ssid
*ssid
, int line
,
1394 freqs
= wpa_config_parse_int_array(value
);
1397 if (freqs
[0] == 0) {
1401 os_free(ssid
->freq_list
);
1402 ssid
->freq_list
= freqs
;
1408 #ifndef NO_CONFIG_WRITE
1409 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1412 char *buf
, *pos
, *end
;
1420 for (i
= 0; freqs
[i
]; i
++)
1423 pos
= buf
= os_zalloc(10 * count
+ 1);
1426 end
= buf
+ 10 * count
+ 1;
1428 for (i
= 0; freqs
[i
]; i
++) {
1429 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1430 i
== 0 ? "" : " ", freqs
[i
]);
1431 if (os_snprintf_error(end
- pos
, ret
)) {
1442 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1443 struct wpa_ssid
*ssid
)
1445 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1449 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1450 struct wpa_ssid
*ssid
)
1452 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1454 #endif /* NO_CONFIG_WRITE */
1457 #ifdef IEEE8021X_EAPOL
1458 static int wpa_config_parse_eap(const struct parse_data
*data
,
1459 struct wpa_ssid
*ssid
, int line
,
1462 int last
, errors
= 0;
1463 char *start
, *end
, *buf
;
1464 struct eap_method_type
*methods
= NULL
, *tmp
;
1465 size_t num_methods
= 0;
1467 buf
= os_strdup(value
);
1472 while (*start
!= '\0') {
1473 while (*start
== ' ' || *start
== '\t')
1478 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1480 last
= *end
== '\0';
1483 methods
= os_realloc_array(methods
, num_methods
+ 1,
1485 if (methods
== NULL
) {
1490 methods
[num_methods
].method
= eap_peer_get_type(
1491 start
, &methods
[num_methods
].vendor
);
1492 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1493 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1494 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1495 "'%s'", line
, start
);
1496 wpa_printf(MSG_ERROR
, "You may need to add support for"
1497 " this EAP method during wpa_supplicant\n"
1498 "build time configuration.\n"
1499 "See README for more information.");
1501 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1502 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1514 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1515 if (methods
== NULL
) {
1519 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1520 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1523 if (!errors
&& ssid
->eap
.eap_methods
) {
1524 struct eap_method_type
*prev_m
;
1525 size_t i
, j
, prev_methods
, match
= 0;
1527 prev_m
= ssid
->eap
.eap_methods
;
1528 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1529 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1530 /* Count the methods */
1532 prev_methods
= i
+ 1;
1534 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1536 for (j
= 0; j
< num_methods
; j
++) {
1537 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1538 prev_m
[i
].method
== methods
[j
].method
) {
1544 if (match
== num_methods
) {
1549 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1550 (u8
*) methods
, num_methods
* sizeof(*methods
));
1551 os_free(ssid
->eap
.eap_methods
);
1552 ssid
->eap
.eap_methods
= methods
;
1553 return errors
? -1 : 0;
1557 #ifndef NO_CONFIG_WRITE
1558 static char * wpa_config_write_eap(const struct parse_data
*data
,
1559 struct wpa_ssid
*ssid
)
1562 char *buf
, *pos
, *end
;
1563 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1566 if (eap_methods
== NULL
)
1569 pos
= buf
= os_zalloc(100);
1574 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1575 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1576 name
= eap_get_name(eap_methods
[i
].vendor
,
1577 eap_methods
[i
].method
);
1579 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1580 pos
== buf
? "" : " ", name
);
1581 if (os_snprintf_error(end
- pos
, ret
))
1591 #endif /* NO_CONFIG_WRITE */
1594 static int wpa_config_parse_password(const struct parse_data
*data
,
1595 struct wpa_ssid
*ssid
, int line
,
1600 if (os_strcmp(value
, "NULL") == 0) {
1601 if (!ssid
->eap
.password
)
1602 return 1; /* Already unset */
1603 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1604 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1605 ssid
->eap
.password
= NULL
;
1606 ssid
->eap
.password_len
= 0;
1610 #ifdef CONFIG_EXT_PASSWORD
1611 if (os_strncmp(value
, "ext:", 4) == 0) {
1612 char *name
= os_strdup(value
+ 4);
1615 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1616 ssid
->eap
.password
= (u8
*) name
;
1617 ssid
->eap
.password_len
= os_strlen(name
);
1618 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1619 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1622 #endif /* CONFIG_EXT_PASSWORD */
1624 if (os_strncmp(value
, "hash:", 5) != 0) {
1628 tmp
= wpa_config_parse_string(value
, &res_len
);
1630 wpa_printf(MSG_ERROR
,
1631 "Line %d: failed to parse password.", line
);
1634 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1635 (u8
*) tmp
, res_len
);
1637 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1638 ssid
->eap
.password
= (u8
*) tmp
;
1639 ssid
->eap
.password_len
= res_len
;
1640 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1641 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1647 /* NtPasswordHash: hash:<32 hex digits> */
1648 if (os_strlen(value
+ 5) != 2 * 16) {
1649 wpa_printf(MSG_ERROR
,
1650 "Line %d: Invalid password hash length (expected 32 hex digits)",
1655 hash
= os_malloc(16);
1659 if (hexstr2bin(value
+ 5, hash
, 16)) {
1661 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1665 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1667 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1668 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1669 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1670 bin_clear_free(hash
, 16);
1673 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1674 ssid
->eap
.password
= hash
;
1675 ssid
->eap
.password_len
= 16;
1676 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1677 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1683 static int wpa_config_parse_machine_password(const struct parse_data
*data
,
1684 struct wpa_ssid
*ssid
, int line
,
1689 if (os_strcmp(value
, "NULL") == 0) {
1690 if (!ssid
->eap
.machine_password
)
1691 return 1; /* Already unset */
1692 wpa_printf(MSG_DEBUG
,
1693 "Unset configuration string 'machine_password'");
1694 bin_clear_free(ssid
->eap
.machine_password
,
1695 ssid
->eap
.machine_password_len
);
1696 ssid
->eap
.machine_password
= NULL
;
1697 ssid
->eap
.machine_password_len
= 0;
1701 #ifdef CONFIG_EXT_PASSWORD
1702 if (os_strncmp(value
, "ext:", 4) == 0) {
1703 char *name
= os_strdup(value
+ 4);
1707 bin_clear_free(ssid
->eap
.machine_password
,
1708 ssid
->eap
.machine_password_len
);
1709 ssid
->eap
.machine_password
= (u8
*) name
;
1710 ssid
->eap
.machine_password_len
= os_strlen(name
);
1711 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1712 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1715 #endif /* CONFIG_EXT_PASSWORD */
1717 if (os_strncmp(value
, "hash:", 5) != 0) {
1721 tmp
= wpa_config_parse_string(value
, &res_len
);
1723 wpa_printf(MSG_ERROR
,
1724 "Line %d: failed to parse machine_password.",
1728 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1729 (u8
*) tmp
, res_len
);
1731 bin_clear_free(ssid
->eap
.machine_password
,
1732 ssid
->eap
.machine_password_len
);
1733 ssid
->eap
.machine_password
= (u8
*) tmp
;
1734 ssid
->eap
.machine_password_len
= res_len
;
1735 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1736 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1742 /* NtPasswordHash: hash:<32 hex digits> */
1743 if (os_strlen(value
+ 5) != 2 * 16) {
1744 wpa_printf(MSG_ERROR
,
1745 "Line %d: Invalid machine_password hash length (expected 32 hex digits)",
1750 hash
= os_malloc(16);
1754 if (hexstr2bin(value
+ 5, hash
, 16)) {
1756 wpa_printf(MSG_ERROR
, "Line %d: Invalid machine_password hash",
1761 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1763 if (ssid
->eap
.machine_password
&&
1764 ssid
->eap
.machine_password_len
== 16 &&
1765 os_memcmp(ssid
->eap
.machine_password
, hash
, 16) == 0 &&
1766 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
)) {
1767 bin_clear_free(hash
, 16);
1770 bin_clear_free(ssid
->eap
.machine_password
,
1771 ssid
->eap
.machine_password_len
);
1772 ssid
->eap
.machine_password
= hash
;
1773 ssid
->eap
.machine_password_len
= 16;
1774 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
;
1775 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
;
1781 #ifndef NO_CONFIG_WRITE
1783 static char * wpa_config_write_password(const struct parse_data
*data
,
1784 struct wpa_ssid
*ssid
)
1788 if (!ssid
->eap
.password
)
1791 #ifdef CONFIG_EXT_PASSWORD
1792 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1793 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1796 os_memcpy(buf
, "ext:", 4);
1797 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1800 #endif /* CONFIG_EXT_PASSWORD */
1802 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1803 return wpa_config_write_string(
1804 ssid
->eap
.password
, ssid
->eap
.password_len
);
1807 buf
= os_malloc(5 + 32 + 1);
1811 os_memcpy(buf
, "hash:", 5);
1812 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1818 static char * wpa_config_write_machine_password(const struct parse_data
*data
,
1819 struct wpa_ssid
*ssid
)
1823 if (!ssid
->eap
.machine_password
)
1826 #ifdef CONFIG_EXT_PASSWORD
1827 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_MACHINE_PASSWORD
) {
1828 buf
= os_zalloc(4 + ssid
->eap
.machine_password_len
+ 1);
1831 os_memcpy(buf
, "ext:", 4);
1832 os_memcpy(buf
+ 4, ssid
->eap
.machine_password
,
1833 ssid
->eap
.machine_password_len
);
1836 #endif /* CONFIG_EXT_PASSWORD */
1838 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_MACHINE_PASSWORD_NTHASH
)) {
1839 return wpa_config_write_string(
1840 ssid
->eap
.machine_password
,
1841 ssid
->eap
.machine_password_len
);
1844 buf
= os_malloc(5 + 32 + 1);
1848 os_memcpy(buf
, "hash:", 5);
1849 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.machine_password
, 16);
1854 #endif /* NO_CONFIG_WRITE */
1855 #endif /* IEEE8021X_EAPOL */
1858 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1859 const char *value
, int idx
)
1861 char *buf
, title
[20];
1864 buf
= wpa_config_parse_string(value
, len
);
1866 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1870 if (*len
> MAX_WEP_KEY_LEN
) {
1871 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1876 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1877 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1878 "this network block will be ignored",
1879 line
, (unsigned int) *len
);
1881 os_memcpy(key
, buf
, *len
);
1882 str_clear_free(buf
);
1883 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1884 if (!os_snprintf_error(sizeof(title
), res
))
1885 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1890 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1891 struct wpa_ssid
*ssid
, int line
,
1894 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1895 &ssid
->wep_key_len
[0], line
,
1900 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1901 struct wpa_ssid
*ssid
, int line
,
1904 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1905 &ssid
->wep_key_len
[1], line
,
1910 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1911 struct wpa_ssid
*ssid
, int line
,
1914 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1915 &ssid
->wep_key_len
[2], line
,
1920 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1921 struct wpa_ssid
*ssid
, int line
,
1924 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1925 &ssid
->wep_key_len
[3], line
,
1930 #ifndef NO_CONFIG_WRITE
1931 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1933 if (ssid
->wep_key_len
[idx
] == 0)
1935 return wpa_config_write_string(ssid
->wep_key
[idx
],
1936 ssid
->wep_key_len
[idx
]);
1940 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1941 struct wpa_ssid
*ssid
)
1943 return wpa_config_write_wep_key(ssid
, 0);
1947 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1948 struct wpa_ssid
*ssid
)
1950 return wpa_config_write_wep_key(ssid
, 1);
1954 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1955 struct wpa_ssid
*ssid
)
1957 return wpa_config_write_wep_key(ssid
, 2);
1961 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1962 struct wpa_ssid
*ssid
)
1964 return wpa_config_write_wep_key(ssid
, 3);
1966 #endif /* NO_CONFIG_WRITE */
1971 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1972 struct wpa_ssid
*ssid
, int line
,
1975 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1976 os_strcmp(value
, "any") == 0) {
1977 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1978 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1981 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1982 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1986 ssid
->bssid_set
= 1;
1987 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1988 MAC2STR(ssid
->go_p2p_dev_addr
));
1993 #ifndef NO_CONFIG_WRITE
1994 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
1995 struct wpa_ssid
*ssid
)
2000 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
2003 value
= os_malloc(20);
2006 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
2007 if (os_snprintf_error(20, res
)) {
2011 value
[20 - 1] = '\0';
2014 #endif /* NO_CONFIG_WRITE */
2017 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
2018 struct wpa_ssid
*ssid
, int line
,
2021 return wpa_config_parse_addr_list(data
, line
, value
,
2022 &ssid
->p2p_client_list
,
2023 &ssid
->num_p2p_clients
,
2024 "p2p_client_list", 0, 0);
2028 #ifndef NO_CONFIG_WRITE
2029 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
2030 struct wpa_ssid
*ssid
)
2032 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
2033 ssid
->num_p2p_clients
,
2036 #endif /* NO_CONFIG_WRITE */
2039 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
2040 struct wpa_ssid
*ssid
, int line
,
2043 struct psk_list_entry
*p
;
2046 p
= os_zalloc(sizeof(*p
));
2051 if (os_strncmp(pos
, "P2P-", 4) == 0) {
2056 if (hwaddr_aton(pos
, p
->addr
)) {
2057 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
2064 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
2071 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
2072 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
2078 dl_list_add(&ssid
->psk_list
, &p
->list
);
2084 #ifndef NO_CONFIG_WRITE
2085 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
2086 struct wpa_ssid
*ssid
)
2090 #endif /* NO_CONFIG_WRITE */
2092 #endif /* CONFIG_P2P */
2097 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
2098 struct wpa_ssid
*ssid
, int line
,
2101 int *rates
= wpa_config_parse_int_array(value
);
2103 if (rates
== NULL
) {
2104 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
2108 if (rates
[0] == 0) {
2113 os_free(ssid
->mesh_basic_rates
);
2114 ssid
->mesh_basic_rates
= rates
;
2120 #ifndef NO_CONFIG_WRITE
2122 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
2123 struct wpa_ssid
*ssid
)
2125 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
2128 #endif /* NO_CONFIG_WRITE */
2130 #endif /* CONFIG_MESH */
2133 #ifdef CONFIG_MACSEC
2135 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
2136 struct wpa_ssid
*ssid
, int line
,
2141 len
= os_strlen(value
);
2142 if (len
> 2 * MACSEC_CAK_MAX_LEN
||
2143 (len
!= 2 * 16 && len
!= 2 * 32) ||
2144 hexstr2bin(value
, ssid
->mka_cak
, len
/ 2)) {
2145 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
2149 ssid
->mka_cak_len
= len
/ 2;
2150 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
2152 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
,
2158 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
2159 struct wpa_ssid
*ssid
, int line
,
2164 len
= os_strlen(value
);
2165 if (len
> 2 * MACSEC_CKN_MAX_LEN
|| /* too long */
2166 len
< 2 || /* too short */
2167 len
% 2 != 0 /* not an integral number of bytes */) {
2168 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2172 ssid
->mka_ckn_len
= len
/ 2;
2173 if (hexstr2bin(value
, ssid
->mka_ckn
, ssid
->mka_ckn_len
)) {
2174 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2179 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
2181 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
,
2187 #ifndef NO_CONFIG_WRITE
2189 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
2190 struct wpa_ssid
*ssid
)
2192 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
2195 return wpa_config_write_string_hex(ssid
->mka_cak
, ssid
->mka_cak_len
);
2199 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
2200 struct wpa_ssid
*ssid
)
2202 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
2204 return wpa_config_write_string_hex(ssid
->mka_ckn
, ssid
->mka_ckn_len
);
2207 #endif /* NO_CONFIG_WRITE */
2209 #endif /* CONFIG_MACSEC */
2214 static int wpa_config_parse_ocv(const struct parse_data
*data
,
2215 struct wpa_ssid
*ssid
, int line
,
2220 ssid
->ocv
= strtol(value
, &end
, 0);
2221 if (*end
|| ssid
->ocv
< 0 || ssid
->ocv
> 1) {
2222 wpa_printf(MSG_ERROR
, "Line %d: Invalid ocv value '%s'.",
2226 if (ssid
->ocv
&& ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
)
2227 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_OPTIONAL
;
2232 #ifndef NO_CONFIG_WRITE
2233 static char * wpa_config_write_ocv(const struct parse_data
*data
,
2234 struct wpa_ssid
*ssid
)
2236 char *value
= os_malloc(20);
2240 os_snprintf(value
, 20, "%d", ssid
->ocv
);
2241 value
[20 - 1] = '\0';
2244 #endif /* NO_CONFIG_WRITE */
2246 #endif /* CONFIG_OCV */
2249 static int wpa_config_parse_peerkey(const struct parse_data
*data
,
2250 struct wpa_ssid
*ssid
, int line
,
2253 wpa_printf(MSG_INFO
, "NOTE: Obsolete peerkey parameter ignored");
2258 #ifndef NO_CONFIG_WRITE
2259 static char * wpa_config_write_peerkey(const struct parse_data
*data
,
2260 struct wpa_ssid
*ssid
)
2264 #endif /* NO_CONFIG_WRITE */
2267 /* Helper macros for network block parser */
2272 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
2273 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
2275 /* STR: Define a string variable for an ASCII string; f = field name */
2276 #ifdef NO_CONFIG_WRITE
2277 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
2278 #define _STRe(f, m) #f, wpa_config_parse_str, OFFSET(eap.m)
2279 #else /* NO_CONFIG_WRITE */
2280 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
2281 #define _STRe(f, m) #f, wpa_config_parse_str, wpa_config_write_str, \
2283 #endif /* NO_CONFIG_WRITE */
2284 #define STR(f) _STR(f), NULL, NULL, NULL, 0
2285 #define STRe(f, m) _STRe(f, m), NULL, NULL, NULL, 0
2286 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
2287 #define STR_KEYe(f, m) _STRe(f, m), NULL, NULL, NULL, 1
2289 /* STR_LEN: Define a string variable with a separate variable for storing the
2290 * data length. Unlike STR(), this can be used to store arbitrary binary data
2291 * (i.e., even nul termination character). */
2292 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
2293 #define _STR_LENe(f, m) _STRe(f, m), OFFSET(eap.m ## _len)
2294 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
2295 #define STR_LENe(f, m) _STR_LENe(f, m), NULL, NULL, 0
2296 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
2298 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
2299 * explicitly specified. */
2300 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
2301 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
2302 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
2304 #ifdef NO_CONFIG_WRITE
2305 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
2306 #define _INTe(f, m) #f, wpa_config_parse_int, OFFSET(eap.m), (void *) 0
2307 #else /* NO_CONFIG_WRITE */
2308 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2309 OFFSET(f), (void *) 0
2310 #define _INTe(f, m) #f, wpa_config_parse_int, wpa_config_write_int, \
2311 OFFSET(eap.m), (void *) 0
2312 #endif /* NO_CONFIG_WRITE */
2314 /* INT: Define an integer variable */
2315 #define INT(f) _INT(f), NULL, NULL, 0
2316 #define INTe(f, m) _INTe(f, m), NULL, NULL, 0
2318 /* INT_RANGE: Define an integer variable with allowed value range */
2319 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
2321 /* FUNC: Define a configuration variable that uses a custom function for
2322 * parsing and writing the value. */
2323 #ifdef NO_CONFIG_WRITE
2324 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
2325 #else /* NO_CONFIG_WRITE */
2326 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
2327 NULL, NULL, NULL, NULL
2328 #endif /* NO_CONFIG_WRITE */
2329 #define FUNC(f) _FUNC(f), 0
2330 #define FUNC_KEY(f) _FUNC(f), 1
2333 * Table of network configuration variables. This table is used to parse each
2334 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2335 * that is inside a network block.
2337 * This table is generated using the helper macros defined above and with
2338 * generous help from the C pre-processor. The field name is stored as a string
2339 * into .name and for STR and INT types, the offset of the target buffer within
2340 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2341 * offset to the field containing the length of the configuration variable.
2342 * .param3 and .param4 can be used to mark the allowed range (length for STR
2343 * and value for INT).
2345 * For each configuration line in wpa_supplicant.conf, the parser goes through
2346 * this table and select the entry that matches with the field name. The parser
2347 * function (.parser) is then called to parse the actual value of the field.
2349 * This kind of mechanism makes it easy to add new configuration parameters,
2350 * since only one line needs to be added into this table and into the
2351 * struct wpa_ssid definition if the new variable is either a string or
2352 * integer. More complex types will need to use their own parser and writer
2355 static const struct parse_data ssid_fields
[] = {
2356 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2357 { INT_RANGE(scan_ssid
, 0, 1) },
2359 { FUNC(bssid_hint
) },
2360 { FUNC(bssid_blacklist
) },
2361 { FUNC(bssid_whitelist
) },
2363 { INT(mem_only_psk
) },
2364 { STR_KEY(sae_password
) },
2365 { STR(sae_password_id
) },
2368 { INT(bg_scan_period
) },
2371 { FUNC(group_mgmt
) },
2373 { FUNC(scan_freq
) },
2374 { FUNC(freq_list
) },
2375 { INT_RANGE(ht
, 0, 1) },
2376 { INT_RANGE(vht
, 0, 1) },
2377 { INT_RANGE(ht40
, -1, 1) },
2378 { INT_RANGE(max_oper_chwidth
, CHANWIDTH_USE_HT
,
2379 CHANWIDTH_80P80MHZ
) },
2380 { INT(vht_center_freq1
) },
2381 { INT(vht_center_freq2
) },
2382 #ifdef IEEE8021X_EAPOL
2384 { STR_LENe(identity
, identity
) },
2385 { STR_LENe(anonymous_identity
, anonymous_identity
) },
2386 { STR_LENe(imsi_identity
, imsi_identity
) },
2387 { STR_LENe(machine_identity
, machine_identity
) },
2388 { FUNC_KEY(password
) },
2389 { FUNC_KEY(machine_password
) },
2390 { STRe(ca_cert
, cert
.ca_cert
) },
2391 { STRe(ca_path
, cert
.ca_path
) },
2392 { STRe(client_cert
, cert
.client_cert
) },
2393 { STRe(private_key
, cert
.private_key
) },
2394 { STR_KEYe(private_key_passwd
, cert
.private_key_passwd
) },
2395 { STRe(dh_file
, cert
.dh_file
) },
2396 { STRe(subject_match
, cert
.subject_match
) },
2397 { STRe(check_cert_subject
, cert
.check_cert_subject
) },
2398 { STRe(altsubject_match
, cert
.altsubject_match
) },
2399 { STRe(domain_suffix_match
, cert
.domain_suffix_match
) },
2400 { STRe(domain_match
, cert
.domain_match
) },
2401 { STRe(ca_cert2
, phase2_cert
.ca_cert
) },
2402 { STRe(ca_path2
, phase2_cert
.ca_path
) },
2403 { STRe(client_cert2
, phase2_cert
.client_cert
) },
2404 { STRe(private_key2
, phase2_cert
.private_key
) },
2405 { STR_KEYe(private_key2_passwd
, phase2_cert
.private_key_passwd
) },
2406 { STRe(dh_file2
, phase2_cert
.dh_file
) },
2407 { STRe(subject_match2
, phase2_cert
.subject_match
) },
2408 { STRe(check_cert_subject2
, phase2_cert
.check_cert_subject
) },
2409 { STRe(altsubject_match2
, phase2_cert
.altsubject_match
) },
2410 { STRe(domain_suffix_match2
, phase2_cert
.domain_suffix_match
) },
2411 { STRe(domain_match2
, phase2_cert
.domain_match
) },
2412 { STRe(phase1
, phase1
) },
2413 { STRe(phase2
, phase2
) },
2414 { STRe(machine_phase2
, machine_phase2
) },
2415 { STRe(pcsc
, pcsc
) },
2416 { STR_KEYe(pin
, cert
.pin
) },
2417 { STRe(engine_id
, cert
.engine_id
) },
2418 { STRe(key_id
, cert
.key_id
) },
2419 { STRe(cert_id
, cert
.cert_id
) },
2420 { STRe(ca_cert_id
, cert
.ca_cert_id
) },
2421 { STR_KEYe(pin2
, phase2_cert
.pin
) },
2422 { STRe(engine_id2
, phase2_cert
.engine_id
) },
2423 { STRe(key_id2
, phase2_cert
.key_id
) },
2424 { STRe(cert_id2
, phase2_cert
.cert_id
) },
2425 { STRe(ca_cert_id2
, phase2_cert
.ca_cert_id
) },
2426 { INTe(engine
, cert
.engine
) },
2427 { INTe(engine2
, phase2_cert
.engine
) },
2428 { STRe(machine_ca_cert
, machine_cert
.ca_cert
) },
2429 { STRe(machine_ca_path
, machine_cert
.ca_path
) },
2430 { STRe(machine_client_cert
, machine_cert
.client_cert
) },
2431 { STRe(machine_private_key
, machine_cert
.private_key
) },
2432 { STR_KEYe(machine_private_key_passwd
,
2433 machine_cert
.private_key_passwd
) },
2434 { STRe(machine_dh_file
, machine_cert
.dh_file
) },
2435 { STRe(machine_subject_match
, machine_cert
.subject_match
) },
2436 { STRe(machine_check_cert_subject
, machine_cert
.check_cert_subject
) },
2437 { STRe(machine_altsubject_match
, machine_cert
.altsubject_match
) },
2438 { STRe(machine_domain_suffix_match
,
2439 machine_cert
.domain_suffix_match
) },
2440 { STRe(machine_domain_match
, machine_cert
.domain_match
) },
2441 { STR_KEYe(machine_pin
, machine_cert
.pin
) },
2442 { STRe(machine_engine_id
, machine_cert
.engine_id
) },
2443 { STRe(machine_key_id
, machine_cert
.key_id
) },
2444 { STRe(machine_cert_id
, machine_cert
.cert_id
) },
2445 { STRe(machine_ca_cert_id
, machine_cert
.ca_cert_id
) },
2446 { INTe(machine_engine
, machine_cert
.engine
) },
2447 { INTe(machine_ocsp
, machine_cert
.ocsp
) },
2448 { INT(eapol_flags
) },
2449 { INTe(sim_num
, sim_num
) },
2450 { STRe(openssl_ciphers
, openssl_ciphers
) },
2452 #endif /* IEEE8021X_EAPOL */
2453 { FUNC_KEY(wep_key0
) },
2454 { FUNC_KEY(wep_key1
) },
2455 { FUNC_KEY(wep_key2
) },
2456 { FUNC_KEY(wep_key3
) },
2457 { INT(wep_tx_keyidx
) },
2459 #ifdef IEEE8021X_EAPOL
2460 { INT(eap_workaround
) },
2461 { STRe(pac_file
, pac_file
) },
2462 { INTe(fragment_size
, fragment_size
) },
2463 { INTe(ocsp
, cert
.ocsp
) },
2464 { INTe(ocsp2
, phase2_cert
.ocsp
) },
2465 #endif /* IEEE8021X_EAPOL */
2467 { INT_RANGE(mode
, 0, 5) },
2468 { INT_RANGE(no_auto_peer
, 0, 1) },
2469 { INT_RANGE(mesh_rssi_threshold
, -255, 1) },
2470 #else /* CONFIG_MESH */
2471 { INT_RANGE(mode
, 0, 4) },
2472 #endif /* CONFIG_MESH */
2473 { INT_RANGE(proactive_key_caching
, 0, 1) },
2474 { INT_RANGE(disabled
, 0, 2) },
2476 { INT_RANGE(ieee80211w
, 0, 2) },
2479 #endif /* CONFIG_OCV */
2480 { FUNC(peerkey
) /* obsolete - removed */ },
2481 { INT_RANGE(mixed_cell
, 0, 1) },
2482 { INT_RANGE(frequency
, 0, 70200) },
2483 { INT_RANGE(fixed_freq
, 0, 1) },
2485 { INT_RANGE(acs
, 0, 1) },
2486 #endif /* CONFIG_ACS */
2488 { FUNC(mesh_basic_rates
) },
2489 { INT(dot11MeshMaxRetries
) },
2490 { INT(dot11MeshRetryTimeout
) },
2491 { INT(dot11MeshConfirmTimeout
) },
2492 { INT(dot11MeshHoldingTimeout
) },
2493 #endif /* CONFIG_MESH */
2494 { INT(wpa_ptk_rekey
) },
2495 { INT(group_rekey
) },
2497 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2499 { FUNC(go_p2p_dev_addr
) },
2500 { FUNC(p2p_client_list
) },
2502 #endif /* CONFIG_P2P */
2503 #ifdef CONFIG_HT_OVERRIDES
2504 { INT_RANGE(disable_ht
, 0, 1) },
2505 { INT_RANGE(disable_ht40
, -1, 1) },
2506 { INT_RANGE(disable_sgi
, 0, 1) },
2507 { INT_RANGE(disable_ldpc
, 0, 1) },
2508 { INT_RANGE(ht40_intolerant
, 0, 1) },
2509 { INT_RANGE(tx_stbc
, -1, 1) },
2510 { INT_RANGE(rx_stbc
, -1, 3) },
2511 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2512 { INT_RANGE(ampdu_factor
, -1, 3) },
2513 { INT_RANGE(ampdu_density
, -1, 7) },
2515 #endif /* CONFIG_HT_OVERRIDES */
2516 #ifdef CONFIG_VHT_OVERRIDES
2517 { INT_RANGE(disable_vht
, 0, 1) },
2519 { INT(vht_capa_mask
) },
2520 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2521 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2522 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2523 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2524 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2525 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2526 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2527 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2528 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2529 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2530 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2531 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2532 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2533 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2534 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2535 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2536 #endif /* CONFIG_VHT_OVERRIDES */
2537 { INT(ap_max_inactivity
) },
2538 { INT(dtim_period
) },
2539 { INT(beacon_int
) },
2540 #ifdef CONFIG_MACSEC
2541 { INT_RANGE(macsec_policy
, 0, 1) },
2542 { INT_RANGE(macsec_integ_only
, 0, 1) },
2543 { INT_RANGE(macsec_replay_protect
, 0, 1) },
2544 { INT(macsec_replay_window
) },
2545 { INT_RANGE(macsec_port
, 1, 65534) },
2546 { INT_RANGE(mka_priority
, 0, 255) },
2547 { FUNC_KEY(mka_cak
) },
2548 { FUNC_KEY(mka_ckn
) },
2549 #endif /* CONFIG_MACSEC */
2551 { INT(update_identifier
) },
2552 { STR_RANGE(roaming_consortium_selection
, 0, MAX_ROAMING_CONS_OI_LEN
) },
2553 #endif /* CONFIG_HS20 */
2554 { INT_RANGE(mac_addr
, 0, 2) },
2555 { INT_RANGE(pbss
, 0, 2) },
2556 { INT_RANGE(wps_disabled
, 0, 1) },
2557 { INT_RANGE(fils_dh_group
, 0, 65535) },
2559 { STR(dpp_connector
) },
2560 { STR_LEN(dpp_netaccesskey
) },
2561 { INT(dpp_netaccesskey_expiry
) },
2562 { STR_LEN(dpp_csign
) },
2563 #endif /* CONFIG_DPP */
2564 { INT_RANGE(owe_group
, 0, 65535) },
2565 { INT_RANGE(owe_only
, 0, 1) },
2566 { INT_RANGE(multi_ap_backhaul_sta
, 0, 1) },
2567 { INT_RANGE(ft_eap_pmksa_caching
, 0, 1) },
2579 #undef STR_RANGE_KEY
2586 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2590 * wpa_config_add_prio_network - Add a network to priority lists
2591 * @config: Configuration data from wpa_config_read()
2592 * @ssid: Pointer to the network configuration to be added to the list
2593 * Returns: 0 on success, -1 on failure
2595 * This function is used to add a network block to the priority list of
2596 * networks. This must be called for each network when reading in the full
2597 * configuration. In addition, this can be used indirectly when updating
2598 * priorities by calling wpa_config_update_prio_list().
2600 int wpa_config_add_prio_network(struct wpa_config
*config
,
2601 struct wpa_ssid
*ssid
)
2604 struct wpa_ssid
*prev
, **nlist
;
2607 * Add to an existing priority list if one is available for the
2608 * configured priority level for this network.
2610 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2611 prev
= config
->pssid
[prio
];
2612 if (prev
->priority
== ssid
->priority
) {
2620 /* First network for this priority - add a new priority list */
2621 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2622 sizeof(struct wpa_ssid
*));
2626 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2627 if (nlist
[prio
]->priority
< ssid
->priority
) {
2628 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2629 (config
->num_prio
- prio
) *
2630 sizeof(struct wpa_ssid
*));
2637 config
->pssid
= nlist
;
2644 * wpa_config_update_prio_list - Update network priority list
2645 * @config: Configuration data from wpa_config_read()
2646 * Returns: 0 on success, -1 on failure
2648 * This function is called to update the priority list of networks in the
2649 * configuration when a network is being added or removed. This is also called
2650 * if a priority for a network is changed.
2652 int wpa_config_update_prio_list(struct wpa_config
*config
)
2654 struct wpa_ssid
*ssid
;
2657 os_free(config
->pssid
);
2658 config
->pssid
= NULL
;
2659 config
->num_prio
= 0;
2661 ssid
= config
->ssid
;
2664 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2673 #ifdef IEEE8021X_EAPOL
2675 static void eap_peer_config_free_cert(struct eap_peer_cert_config
*cert
)
2677 os_free(cert
->ca_cert
);
2678 os_free(cert
->ca_path
);
2679 os_free(cert
->client_cert
);
2680 os_free(cert
->private_key
);
2681 str_clear_free(cert
->private_key_passwd
);
2682 os_free(cert
->dh_file
);
2683 os_free(cert
->subject_match
);
2684 os_free(cert
->check_cert_subject
);
2685 os_free(cert
->altsubject_match
);
2686 os_free(cert
->domain_suffix_match
);
2687 os_free(cert
->domain_match
);
2688 str_clear_free(cert
->pin
);
2689 os_free(cert
->engine_id
);
2690 os_free(cert
->key_id
);
2691 os_free(cert
->cert_id
);
2692 os_free(cert
->ca_cert_id
);
2696 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2698 os_free(eap
->eap_methods
);
2699 bin_clear_free(eap
->identity
, eap
->identity_len
);
2700 os_free(eap
->anonymous_identity
);
2701 os_free(eap
->imsi_identity
);
2702 os_free(eap
->machine_identity
);
2703 bin_clear_free(eap
->password
, eap
->password_len
);
2704 bin_clear_free(eap
->machine_password
, eap
->machine_password_len
);
2705 eap_peer_config_free_cert(&eap
->cert
);
2706 eap_peer_config_free_cert(&eap
->phase2_cert
);
2707 eap_peer_config_free_cert(&eap
->machine_cert
);
2708 os_free(eap
->phase1
);
2709 os_free(eap
->phase2
);
2710 os_free(eap
->machine_phase2
);
2713 os_free(eap
->pending_req_otp
);
2714 os_free(eap
->pac_file
);
2715 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2716 str_clear_free(eap
->external_sim_resp
);
2717 os_free(eap
->openssl_ciphers
);
2720 #endif /* IEEE8021X_EAPOL */
2724 * wpa_config_free_ssid - Free network/ssid configuration data
2725 * @ssid: Configuration data for the network
2727 * This function frees all resources allocated for the network configuration
2730 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2732 struct psk_list_entry
*psk
;
2734 os_free(ssid
->ssid
);
2735 str_clear_free(ssid
->passphrase
);
2736 os_free(ssid
->ext_psk
);
2737 str_clear_free(ssid
->sae_password
);
2738 os_free(ssid
->sae_password_id
);
2739 #ifdef IEEE8021X_EAPOL
2740 eap_peer_config_free(&ssid
->eap
);
2741 #endif /* IEEE8021X_EAPOL */
2742 os_free(ssid
->id_str
);
2743 os_free(ssid
->scan_freq
);
2744 os_free(ssid
->freq_list
);
2745 os_free(ssid
->bgscan
);
2746 os_free(ssid
->p2p_client_list
);
2747 os_free(ssid
->bssid_blacklist
);
2748 os_free(ssid
->bssid_whitelist
);
2749 #ifdef CONFIG_HT_OVERRIDES
2750 os_free(ssid
->ht_mcs
);
2751 #endif /* CONFIG_HT_OVERRIDES */
2753 os_free(ssid
->mesh_basic_rates
);
2754 #endif /* CONFIG_MESH */
2756 os_free(ssid
->roaming_consortium_selection
);
2757 #endif /* CONFIG_HS20 */
2758 os_free(ssid
->dpp_connector
);
2759 bin_clear_free(ssid
->dpp_netaccesskey
, ssid
->dpp_netaccesskey_len
);
2760 os_free(ssid
->dpp_csign
);
2761 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2763 dl_list_del(&psk
->list
);
2764 bin_clear_free(psk
, sizeof(*psk
));
2766 bin_clear_free(ssid
, sizeof(*ssid
));
2770 void wpa_config_free_cred(struct wpa_cred
*cred
)
2774 os_free(cred
->realm
);
2775 str_clear_free(cred
->username
);
2776 str_clear_free(cred
->password
);
2777 os_free(cred
->ca_cert
);
2778 os_free(cred
->client_cert
);
2779 os_free(cred
->private_key
);
2780 str_clear_free(cred
->private_key_passwd
);
2781 os_free(cred
->imsi
);
2782 str_clear_free(cred
->milenage
);
2783 for (i
= 0; i
< cred
->num_domain
; i
++)
2784 os_free(cred
->domain
[i
]);
2785 os_free(cred
->domain
);
2786 os_free(cred
->domain_suffix_match
);
2787 os_free(cred
->eap_method
);
2788 os_free(cred
->phase1
);
2789 os_free(cred
->phase2
);
2790 os_free(cred
->excluded_ssid
);
2791 os_free(cred
->roaming_partner
);
2792 os_free(cred
->provisioning_sp
);
2793 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2794 os_free(cred
->req_conn_capab_port
[i
]);
2795 os_free(cred
->req_conn_capab_port
);
2796 os_free(cred
->req_conn_capab_proto
);
2801 void wpa_config_flush_blobs(struct wpa_config
*config
)
2803 #ifndef CONFIG_NO_CONFIG_BLOBS
2804 struct wpa_config_blob
*blob
, *prev
;
2806 blob
= config
->blobs
;
2807 config
->blobs
= NULL
;
2811 wpa_config_free_blob(prev
);
2813 #endif /* CONFIG_NO_CONFIG_BLOBS */
2818 * wpa_config_free - Free configuration data
2819 * @config: Configuration data from wpa_config_read()
2821 * This function frees all resources allocated for the configuration data by
2822 * wpa_config_read().
2824 void wpa_config_free(struct wpa_config
*config
)
2826 struct wpa_ssid
*ssid
, *prev
= NULL
;
2827 struct wpa_cred
*cred
, *cprev
;
2830 ssid
= config
->ssid
;
2834 wpa_config_free_ssid(prev
);
2837 cred
= config
->cred
;
2841 wpa_config_free_cred(cprev
);
2844 wpa_config_flush_blobs(config
);
2846 wpabuf_free(config
->wps_vendor_ext_m1
);
2847 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2848 wpabuf_free(config
->wps_vendor_ext
[i
]);
2849 os_free(config
->ctrl_interface
);
2850 os_free(config
->ctrl_interface_group
);
2851 os_free(config
->opensc_engine_path
);
2852 os_free(config
->pkcs11_engine_path
);
2853 os_free(config
->pkcs11_module_path
);
2854 os_free(config
->openssl_ciphers
);
2855 os_free(config
->pcsc_reader
);
2856 str_clear_free(config
->pcsc_pin
);
2857 os_free(config
->driver_param
);
2858 os_free(config
->device_name
);
2859 os_free(config
->manufacturer
);
2860 os_free(config
->model_name
);
2861 os_free(config
->model_number
);
2862 os_free(config
->serial_number
);
2863 os_free(config
->config_methods
);
2864 os_free(config
->p2p_ssid_postfix
);
2865 os_free(config
->pssid
);
2866 os_free(config
->p2p_pref_chan
);
2867 os_free(config
->p2p_no_go_freq
.range
);
2868 os_free(config
->autoscan
);
2869 os_free(config
->freq_list
);
2870 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2871 wpabuf_free(config
->wps_nfc_dh_privkey
);
2872 wpabuf_free(config
->wps_nfc_dev_pw
);
2873 os_free(config
->ext_password_backend
);
2874 os_free(config
->sae_groups
);
2875 wpabuf_free(config
->ap_vendor_elements
);
2876 os_free(config
->osu_dir
);
2877 os_free(config
->bgscan
);
2878 os_free(config
->wowlan_triggers
);
2879 os_free(config
->fst_group_id
);
2880 os_free(config
->sched_scan_plans
);
2882 os_free(config
->non_pref_chan
);
2883 #endif /* CONFIG_MBO */
2890 * wpa_config_foreach_network - Iterate over each configured network
2891 * @config: Configuration data from wpa_config_read()
2892 * @func: Callback function to process each network
2893 * @arg: Opaque argument to pass to callback function
2895 * Iterate over the set of configured networks calling the specified
2896 * function for each item. We guard against callbacks removing the
2899 void wpa_config_foreach_network(struct wpa_config
*config
,
2900 void (*func
)(void *, struct wpa_ssid
*),
2903 struct wpa_ssid
*ssid
, *next
;
2905 ssid
= config
->ssid
;
2915 * wpa_config_get_network - Get configured network based on id
2916 * @config: Configuration data from wpa_config_read()
2917 * @id: Unique network id to search for
2918 * Returns: Network configuration or %NULL if not found
2920 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2922 struct wpa_ssid
*ssid
;
2924 ssid
= config
->ssid
;
2936 * wpa_config_add_network - Add a new network with empty configuration
2937 * @config: Configuration data from wpa_config_read()
2938 * Returns: The new network configuration or %NULL if operation failed
2940 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2943 struct wpa_ssid
*ssid
, *last
= NULL
;
2946 ssid
= config
->ssid
;
2955 ssid
= os_zalloc(sizeof(*ssid
));
2959 dl_list_init(&ssid
->psk_list
);
2963 config
->ssid
= ssid
;
2965 wpa_config_update_prio_list(config
);
2972 * wpa_config_remove_network - Remove a configured network based on id
2973 * @config: Configuration data from wpa_config_read()
2974 * @id: Unique network id to search for
2975 * Returns: 0 on success, or -1 if the network was not found
2977 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2979 struct wpa_ssid
*ssid
, *prev
= NULL
;
2981 ssid
= config
->ssid
;
2993 prev
->next
= ssid
->next
;
2995 config
->ssid
= ssid
->next
;
2997 wpa_config_update_prio_list(config
);
2998 wpa_config_free_ssid(ssid
);
3004 * wpa_config_set_network_defaults - Set network default values
3005 * @ssid: Pointer to network configuration data
3007 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
3009 ssid
->proto
= DEFAULT_PROTO
;
3010 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
3011 ssid
->group_cipher
= DEFAULT_GROUP
;
3012 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
3013 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
3015 #ifdef IEEE8021X_EAPOL
3016 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
3017 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
3018 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
3019 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
3020 #endif /* IEEE8021X_EAPOL */
3022 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
3023 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
3024 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
3025 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
3026 ssid
->mesh_rssi_threshold
= DEFAULT_MESH_RSSI_THRESHOLD
;
3027 #endif /* CONFIG_MESH */
3028 #ifdef CONFIG_HT_OVERRIDES
3029 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
3030 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
3031 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
3032 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
3033 ssid
->tx_stbc
= DEFAULT_TX_STBC
;
3034 ssid
->rx_stbc
= DEFAULT_RX_STBC
;
3035 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
3036 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
3037 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
3038 #endif /* CONFIG_HT_OVERRIDES */
3039 #ifdef CONFIG_VHT_OVERRIDES
3040 ssid
->vht_rx_mcs_nss_1
= -1;
3041 ssid
->vht_rx_mcs_nss_2
= -1;
3042 ssid
->vht_rx_mcs_nss_3
= -1;
3043 ssid
->vht_rx_mcs_nss_4
= -1;
3044 ssid
->vht_rx_mcs_nss_5
= -1;
3045 ssid
->vht_rx_mcs_nss_6
= -1;
3046 ssid
->vht_rx_mcs_nss_7
= -1;
3047 ssid
->vht_rx_mcs_nss_8
= -1;
3048 ssid
->vht_tx_mcs_nss_1
= -1;
3049 ssid
->vht_tx_mcs_nss_2
= -1;
3050 ssid
->vht_tx_mcs_nss_3
= -1;
3051 ssid
->vht_tx_mcs_nss_4
= -1;
3052 ssid
->vht_tx_mcs_nss_5
= -1;
3053 ssid
->vht_tx_mcs_nss_6
= -1;
3054 ssid
->vht_tx_mcs_nss_7
= -1;
3055 ssid
->vht_tx_mcs_nss_8
= -1;
3056 #endif /* CONFIG_VHT_OVERRIDES */
3057 ssid
->proactive_key_caching
= -1;
3058 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
3059 #ifdef CONFIG_MACSEC
3060 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
3061 #endif /* CONFIG_MACSEC */
3062 ssid
->mac_addr
= -1;
3063 ssid
->max_oper_chwidth
= DEFAULT_MAX_OPER_CHWIDTH
;
3068 * wpa_config_set - Set a variable in network configuration
3069 * @ssid: Pointer to network configuration data
3070 * @var: Variable name, e.g., "ssid"
3071 * @value: Variable value
3072 * @line: Line number in configuration file or 0 if not used
3073 * Returns: 0 on success with possible change in the value, 1 on success with
3074 * no change to previously configured value, or -1 on failure
3076 * This function can be used to set network configuration variables based on
3077 * both the configuration file and management interface input. The value
3078 * parameter must be in the same format as the text-based configuration file is
3079 * using. For example, strings are using double quotation marks.
3081 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
3087 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
3090 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3091 const struct parse_data
*field
= &ssid_fields
[i
];
3092 if (os_strcmp(var
, field
->name
) != 0)
3095 ret
= field
->parser(field
, ssid
, line
, value
);
3098 wpa_printf(MSG_ERROR
, "Line %d: failed to "
3099 "parse %s '%s'.", line
, var
, value
);
3105 if (i
== NUM_SSID_FIELDS
) {
3107 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
3108 "'%s'.", line
, var
);
3117 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
3124 len
= os_strlen(value
);
3125 buf
= os_malloc(len
+ 3);
3129 os_memcpy(buf
+ 1, value
, len
);
3131 buf
[len
+ 2] = '\0';
3132 ret
= wpa_config_set(ssid
, var
, buf
, 0);
3139 * wpa_config_get_all - Get all options from network configuration
3140 * @ssid: Pointer to network configuration data
3141 * @get_keys: Determines if keys/passwords will be included in returned list
3142 * (if they may be exported)
3143 * Returns: %NULL terminated list of all set keys and their values in the form
3144 * of [key1, val1, key2, val2, ... , NULL]
3146 * This function can be used to get list of all configured network properties.
3147 * The caller is responsible for freeing the returned list and all its
3150 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
3152 #ifdef NO_CONFIG_WRITE
3154 #else /* NO_CONFIG_WRITE */
3155 const struct parse_data
*field
;
3161 get_keys
= get_keys
&& ssid
->export_keys
;
3163 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
3168 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3169 field
= &ssid_fields
[i
];
3170 if (field
->key_data
&& !get_keys
)
3172 value
= field
->writer(field
, ssid
);
3175 if (os_strlen(value
) == 0) {
3180 key
= os_strdup(field
->name
);
3186 props
[fields_num
* 2] = key
;
3187 props
[fields_num
* 2 + 1] = value
;
3195 for (i
= 0; props
[i
]; i
++)
3199 #endif /* NO_CONFIG_WRITE */
3203 #ifndef NO_CONFIG_WRITE
3205 * wpa_config_get - Get a variable in network configuration
3206 * @ssid: Pointer to network configuration data
3207 * @var: Variable name, e.g., "ssid"
3208 * Returns: Value of the variable or %NULL on failure
3210 * This function can be used to get network configuration variables. The
3211 * returned value is a copy of the configuration variable in text format, i.e,.
3212 * the same format that the text-based configuration file and wpa_config_set()
3213 * are using for the value. The caller is responsible for freeing the returned
3216 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
3220 if (ssid
== NULL
|| var
== NULL
)
3223 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3224 const struct parse_data
*field
= &ssid_fields
[i
];
3225 if (os_strcmp(var
, field
->name
) == 0) {
3226 char *ret
= field
->writer(field
, ssid
);
3228 if (ret
&& has_newline(ret
)) {
3229 wpa_printf(MSG_ERROR
,
3230 "Found newline in value for %s; not returning it",
3245 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
3246 * @ssid: Pointer to network configuration data
3247 * @var: Variable name, e.g., "ssid"
3248 * Returns: Value of the variable or %NULL on failure
3250 * This function can be used to get network configuration variable like
3251 * wpa_config_get(). The only difference is that this functions does not expose
3252 * key/password material from the configuration. In case a key/password field
3253 * is requested, the returned value is an empty string or %NULL if the variable
3254 * is not set or "*" if the variable is set (regardless of its value). The
3255 * returned value is a copy of the configuration variable in text format, i.e,.
3256 * the same format that the text-based configuration file and wpa_config_set()
3257 * are using for the value. The caller is responsible for freeing the returned
3260 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
3264 if (ssid
== NULL
|| var
== NULL
)
3267 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3268 const struct parse_data
*field
= &ssid_fields
[i
];
3269 if (os_strcmp(var
, field
->name
) == 0) {
3270 char *res
= field
->writer(field
, ssid
);
3271 if (field
->key_data
) {
3272 if (res
&& res
[0]) {
3273 wpa_printf(MSG_DEBUG
, "Do not allow "
3274 "key_data field to be "
3276 str_clear_free(res
);
3277 return os_strdup("*");
3289 #endif /* NO_CONFIG_WRITE */
3293 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
3294 * @ssid: Pointer to network configuration data
3296 * This function must be called to update WPA PSK when either SSID or the
3297 * passphrase has changed for the network configuration.
3299 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
3301 #ifndef CONFIG_NO_PBKDF2
3302 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
3303 ssid
->psk
, PMK_LEN
);
3304 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
3305 ssid
->psk
, PMK_LEN
);
3307 #endif /* CONFIG_NO_PBKDF2 */
3311 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
3316 int *ports
, *nports
;
3318 unsigned int num_ports
;
3320 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
3321 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
3324 cred
->req_conn_capab_proto
= proto
;
3326 port
= os_realloc_array(cred
->req_conn_capab_port
,
3327 cred
->num_req_conn_capab
+ 1, sizeof(int *));
3330 cred
->req_conn_capab_port
= port
;
3332 proto
[cred
->num_req_conn_capab
] = atoi(value
);
3334 pos
= os_strchr(value
, ':');
3336 port
[cred
->num_req_conn_capab
] = NULL
;
3337 cred
->num_req_conn_capab
++;
3346 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3347 if (nports
== NULL
) {
3352 ports
[num_ports
++] = atoi(pos
);
3354 pos
= os_strchr(pos
, ',');
3360 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3361 if (nports
== NULL
) {
3366 ports
[num_ports
] = -1;
3368 port
[cred
->num_req_conn_capab
] = ports
;
3369 cred
->num_req_conn_capab
++;
3374 static int wpa_config_set_cred_roaming_consortiums(struct wpa_cred
*cred
,
3377 u8 roaming_consortiums
[MAX_ROAMING_CONS
][MAX_ROAMING_CONS_OI_LEN
];
3378 size_t roaming_consortiums_len
[MAX_ROAMING_CONS
];
3379 unsigned int num_roaming_consortiums
= 0;
3380 const char *pos
, *end
;
3383 os_memset(roaming_consortiums
, 0, sizeof(roaming_consortiums
));
3384 os_memset(roaming_consortiums_len
, 0, sizeof(roaming_consortiums_len
));
3386 for (pos
= value
;;) {
3387 end
= os_strchr(pos
, ',');
3388 len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
3389 if (!end
&& len
== 0)
3391 if (len
== 0 || (len
& 1) != 0 ||
3392 len
/ 2 > MAX_ROAMING_CONS_OI_LEN
||
3394 roaming_consortiums
[num_roaming_consortiums
],
3396 wpa_printf(MSG_INFO
,
3397 "Invalid roaming_consortiums entry: %s",
3401 roaming_consortiums_len
[num_roaming_consortiums
] = len
/ 2;
3402 num_roaming_consortiums
++;
3407 if (num_roaming_consortiums
>= MAX_ROAMING_CONS
) {
3408 wpa_printf(MSG_INFO
,
3409 "Too many roaming_consortiums OIs");
3416 os_memcpy(cred
->roaming_consortiums
, roaming_consortiums
,
3417 sizeof(roaming_consortiums
));
3418 os_memcpy(cred
->roaming_consortiums_len
, roaming_consortiums_len
,
3419 sizeof(roaming_consortiums_len
));
3420 cred
->num_roaming_consortiums
= num_roaming_consortiums
;
3426 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
3427 const char *value
, int line
)
3433 if (os_strcmp(var
, "temporary") == 0) {
3434 cred
->temporary
= atoi(value
);
3438 if (os_strcmp(var
, "priority") == 0) {
3439 cred
->priority
= atoi(value
);
3443 if (os_strcmp(var
, "sp_priority") == 0) {
3444 int prio
= atoi(value
);
3445 if (prio
< 0 || prio
> 255)
3447 cred
->sp_priority
= prio
;
3451 if (os_strcmp(var
, "pcsc") == 0) {
3452 cred
->pcsc
= atoi(value
);
3456 if (os_strcmp(var
, "eap") == 0) {
3457 struct eap_method_type method
;
3458 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3459 if (method
.vendor
== EAP_VENDOR_IETF
&&
3460 method
.method
== EAP_TYPE_NONE
) {
3461 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3462 "for a credential", line
, value
);
3465 os_free(cred
->eap_method
);
3466 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3467 if (cred
->eap_method
== NULL
)
3469 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3473 if (os_strcmp(var
, "password") == 0 &&
3474 os_strncmp(value
, "ext:", 4) == 0) {
3475 if (has_newline(value
))
3477 str_clear_free(cred
->password
);
3478 cred
->password
= os_strdup(value
);
3479 cred
->ext_password
= 1;
3483 if (os_strcmp(var
, "update_identifier") == 0) {
3484 cred
->update_identifier
= atoi(value
);
3488 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3489 cred
->min_dl_bandwidth_home
= atoi(value
);
3493 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3494 cred
->min_ul_bandwidth_home
= atoi(value
);
3498 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3499 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3503 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3504 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3508 if (os_strcmp(var
, "max_bss_load") == 0) {
3509 cred
->max_bss_load
= atoi(value
);
3513 if (os_strcmp(var
, "req_conn_capab") == 0)
3514 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3516 if (os_strcmp(var
, "ocsp") == 0) {
3517 cred
->ocsp
= atoi(value
);
3521 if (os_strcmp(var
, "sim_num") == 0) {
3522 cred
->sim_num
= atoi(value
);
3526 val
= wpa_config_parse_string(value
, &len
);
3528 (os_strcmp(var
, "excluded_ssid") != 0 &&
3529 os_strcmp(var
, "roaming_consortium") != 0 &&
3530 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3531 has_newline(val
))) {
3532 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3533 "value '%s'.", line
, var
, value
);
3538 if (os_strcmp(var
, "realm") == 0) {
3539 os_free(cred
->realm
);
3544 if (os_strcmp(var
, "username") == 0) {
3545 str_clear_free(cred
->username
);
3546 cred
->username
= val
;
3550 if (os_strcmp(var
, "password") == 0) {
3551 str_clear_free(cred
->password
);
3552 cred
->password
= val
;
3553 cred
->ext_password
= 0;
3557 if (os_strcmp(var
, "ca_cert") == 0) {
3558 os_free(cred
->ca_cert
);
3559 cred
->ca_cert
= val
;
3563 if (os_strcmp(var
, "client_cert") == 0) {
3564 os_free(cred
->client_cert
);
3565 cred
->client_cert
= val
;
3569 if (os_strcmp(var
, "private_key") == 0) {
3570 os_free(cred
->private_key
);
3571 cred
->private_key
= val
;
3575 if (os_strcmp(var
, "private_key_passwd") == 0) {
3576 str_clear_free(cred
->private_key_passwd
);
3577 cred
->private_key_passwd
= val
;
3581 if (os_strcmp(var
, "imsi") == 0) {
3582 os_free(cred
->imsi
);
3587 if (os_strcmp(var
, "milenage") == 0) {
3588 str_clear_free(cred
->milenage
);
3589 cred
->milenage
= val
;
3593 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3594 os_free(cred
->domain_suffix_match
);
3595 cred
->domain_suffix_match
= val
;
3599 if (os_strcmp(var
, "domain") == 0) {
3601 new_domain
= os_realloc_array(cred
->domain
,
3602 cred
->num_domain
+ 1,
3604 if (new_domain
== NULL
) {
3608 new_domain
[cred
->num_domain
++] = val
;
3609 cred
->domain
= new_domain
;
3613 if (os_strcmp(var
, "phase1") == 0) {
3614 os_free(cred
->phase1
);
3619 if (os_strcmp(var
, "phase2") == 0) {
3620 os_free(cred
->phase2
);
3625 if (os_strcmp(var
, "roaming_consortium") == 0) {
3626 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3627 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3628 "roaming_consortium length %d (3..15 "
3629 "expected)", line
, (int) len
);
3633 os_memcpy(cred
->roaming_consortium
, val
, len
);
3634 cred
->roaming_consortium_len
= len
;
3639 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3640 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3642 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3643 "required_roaming_consortium length %d "
3644 "(3..15 expected)", line
, (int) len
);
3648 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3649 cred
->required_roaming_consortium_len
= len
;
3654 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3655 res
= wpa_config_set_cred_roaming_consortiums(cred
, val
);
3657 wpa_printf(MSG_ERROR
,
3658 "Line %d: invalid roaming_consortiums",
3664 if (os_strcmp(var
, "excluded_ssid") == 0) {
3665 struct excluded_ssid
*e
;
3667 if (len
> SSID_MAX_LEN
) {
3668 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3669 "excluded_ssid length %d", line
, (int) len
);
3674 e
= os_realloc_array(cred
->excluded_ssid
,
3675 cred
->num_excluded_ssid
+ 1,
3676 sizeof(struct excluded_ssid
));
3681 cred
->excluded_ssid
= e
;
3683 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3684 os_memcpy(e
->ssid
, val
, len
);
3692 if (os_strcmp(var
, "roaming_partner") == 0) {
3693 struct roaming_partner
*p
;
3696 p
= os_realloc_array(cred
->roaming_partner
,
3697 cred
->num_roaming_partner
+ 1,
3698 sizeof(struct roaming_partner
));
3703 cred
->roaming_partner
= p
;
3705 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3707 pos
= os_strchr(val
, ',');
3713 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3717 os_memcpy(p
->fqdn
, val
, pos
- val
);
3719 p
->exact_match
= atoi(pos
);
3721 pos
= os_strchr(pos
, ',');
3728 p
->priority
= atoi(pos
);
3730 pos
= os_strchr(pos
, ',');
3737 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3741 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3743 cred
->num_roaming_partner
++;
3749 if (os_strcmp(var
, "provisioning_sp") == 0) {
3750 os_free(cred
->provisioning_sp
);
3751 cred
->provisioning_sp
= val
;
3756 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3766 static char * alloc_int_str(int val
)
3768 const unsigned int bufsize
= 20;
3772 buf
= os_malloc(bufsize
);
3775 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3776 if (os_snprintf_error(bufsize
, res
)) {
3784 static char * alloc_strdup(const char *str
)
3788 return os_strdup(str
);
3792 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3794 if (os_strcmp(var
, "temporary") == 0)
3795 return alloc_int_str(cred
->temporary
);
3797 if (os_strcmp(var
, "priority") == 0)
3798 return alloc_int_str(cred
->priority
);
3800 if (os_strcmp(var
, "sp_priority") == 0)
3801 return alloc_int_str(cred
->sp_priority
);
3803 if (os_strcmp(var
, "pcsc") == 0)
3804 return alloc_int_str(cred
->pcsc
);
3806 if (os_strcmp(var
, "eap") == 0) {
3807 if (!cred
->eap_method
)
3809 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3810 cred
->eap_method
[0].method
));
3813 if (os_strcmp(var
, "update_identifier") == 0)
3814 return alloc_int_str(cred
->update_identifier
);
3816 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3817 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3819 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3820 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3822 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3823 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3825 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3826 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3828 if (os_strcmp(var
, "max_bss_load") == 0)
3829 return alloc_int_str(cred
->max_bss_load
);
3831 if (os_strcmp(var
, "req_conn_capab") == 0) {
3833 char *buf
, *end
, *pos
;
3836 if (!cred
->num_req_conn_capab
)
3839 buf
= os_malloc(4000);
3844 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3847 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3849 cred
->req_conn_capab_proto
[i
]);
3850 if (os_snprintf_error(end
- pos
, ret
))
3854 ports
= cred
->req_conn_capab_port
[i
];
3857 for (j
= 0; ports
[j
] != -1; j
++) {
3858 ret
= os_snprintf(pos
, end
- pos
,
3862 if (os_snprintf_error(end
- pos
, ret
))
3872 if (os_strcmp(var
, "ocsp") == 0)
3873 return alloc_int_str(cred
->ocsp
);
3875 if (os_strcmp(var
, "realm") == 0)
3876 return alloc_strdup(cred
->realm
);
3878 if (os_strcmp(var
, "username") == 0)
3879 return alloc_strdup(cred
->username
);
3881 if (os_strcmp(var
, "password") == 0) {
3882 if (!cred
->password
)
3884 return alloc_strdup("*");
3887 if (os_strcmp(var
, "ca_cert") == 0)
3888 return alloc_strdup(cred
->ca_cert
);
3890 if (os_strcmp(var
, "client_cert") == 0)
3891 return alloc_strdup(cred
->client_cert
);
3893 if (os_strcmp(var
, "private_key") == 0)
3894 return alloc_strdup(cred
->private_key
);
3896 if (os_strcmp(var
, "private_key_passwd") == 0) {
3897 if (!cred
->private_key_passwd
)
3899 return alloc_strdup("*");
3902 if (os_strcmp(var
, "imsi") == 0)
3903 return alloc_strdup(cred
->imsi
);
3905 if (os_strcmp(var
, "milenage") == 0) {
3906 if (!(cred
->milenage
))
3908 return alloc_strdup("*");
3911 if (os_strcmp(var
, "domain_suffix_match") == 0)
3912 return alloc_strdup(cred
->domain_suffix_match
);
3914 if (os_strcmp(var
, "domain") == 0) {
3916 char *buf
, *end
, *pos
;
3919 if (!cred
->num_domain
)
3922 buf
= os_malloc(4000);
3928 for (i
= 0; i
< cred
->num_domain
; i
++) {
3929 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3930 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3931 if (os_snprintf_error(end
- pos
, ret
))
3939 if (os_strcmp(var
, "phase1") == 0)
3940 return alloc_strdup(cred
->phase1
);
3942 if (os_strcmp(var
, "phase2") == 0)
3943 return alloc_strdup(cred
->phase2
);
3945 if (os_strcmp(var
, "roaming_consortium") == 0) {
3949 if (!cred
->roaming_consortium_len
)
3951 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3952 buf
= os_malloc(buflen
);
3955 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3956 cred
->roaming_consortium_len
);
3960 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3964 if (!cred
->required_roaming_consortium_len
)
3966 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3967 buf
= os_malloc(buflen
);
3970 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
3971 cred
->required_roaming_consortium_len
);
3975 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3980 if (!cred
->num_roaming_consortiums
)
3982 buflen
= cred
->num_roaming_consortiums
*
3983 MAX_ROAMING_CONS_OI_LEN
* 2 + 1;
3984 buf
= os_malloc(buflen
);
3988 for (i
= 0; i
< cred
->num_roaming_consortiums
; i
++) {
3991 pos
+= wpa_snprintf_hex(
3992 pos
, buf
+ buflen
- pos
,
3993 cred
->roaming_consortiums
[i
],
3994 cred
->roaming_consortiums_len
[i
]);
4000 if (os_strcmp(var
, "excluded_ssid") == 0) {
4002 char *buf
, *end
, *pos
;
4004 if (!cred
->num_excluded_ssid
)
4007 buf
= os_malloc(4000);
4013 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
4014 struct excluded_ssid
*e
;
4017 e
= &cred
->excluded_ssid
[i
];
4018 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4020 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
4021 if (os_snprintf_error(end
- pos
, ret
))
4029 if (os_strcmp(var
, "roaming_partner") == 0) {
4031 char *buf
, *end
, *pos
;
4033 if (!cred
->num_roaming_partner
)
4036 buf
= os_malloc(4000);
4042 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
4043 struct roaming_partner
*p
;
4046 p
= &cred
->roaming_partner
[i
];
4047 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
4049 p
->fqdn
, p
->exact_match
, p
->priority
,
4051 if (os_snprintf_error(end
- pos
, ret
))
4059 if (os_strcmp(var
, "provisioning_sp") == 0)
4060 return alloc_strdup(cred
->provisioning_sp
);
4066 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
4068 struct wpa_cred
*cred
;
4070 cred
= config
->cred
;
4081 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
4084 struct wpa_cred
*cred
, *last
= NULL
;
4087 cred
= config
->cred
;
4096 cred
= os_zalloc(sizeof(*cred
));
4100 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
4104 config
->cred
= cred
;
4110 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
4112 struct wpa_cred
*cred
, *prev
= NULL
;
4114 cred
= config
->cred
;
4126 prev
->next
= cred
->next
;
4128 config
->cred
= cred
->next
;
4130 wpa_config_free_cred(cred
);
4135 #ifndef CONFIG_NO_CONFIG_BLOBS
4137 * wpa_config_get_blob - Get a named configuration blob
4138 * @config: Configuration data from wpa_config_read()
4139 * @name: Name of the blob
4140 * Returns: Pointer to blob data or %NULL if not found
4142 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
4145 struct wpa_config_blob
*blob
= config
->blobs
;
4148 if (os_strcmp(blob
->name
, name
) == 0)
4157 * wpa_config_set_blob - Set or add a named configuration blob
4158 * @config: Configuration data from wpa_config_read()
4159 * @blob: New value for the blob
4161 * Adds a new configuration blob or replaces the current value of an existing
4164 void wpa_config_set_blob(struct wpa_config
*config
,
4165 struct wpa_config_blob
*blob
)
4167 wpa_config_remove_blob(config
, blob
->name
);
4168 blob
->next
= config
->blobs
;
4169 config
->blobs
= blob
;
4174 * wpa_config_free_blob - Free blob data
4175 * @blob: Pointer to blob to be freed
4177 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
4180 os_free(blob
->name
);
4181 bin_clear_free(blob
->data
, blob
->len
);
4188 * wpa_config_remove_blob - Remove a named configuration blob
4189 * @config: Configuration data from wpa_config_read()
4190 * @name: Name of the blob to remove
4191 * Returns: 0 if blob was removed or -1 if blob was not found
4193 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
4195 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
4198 if (os_strcmp(pos
->name
, name
) == 0) {
4200 prev
->next
= pos
->next
;
4202 config
->blobs
= pos
->next
;
4203 wpa_config_free_blob(pos
);
4212 #endif /* CONFIG_NO_CONFIG_BLOBS */
4216 * wpa_config_alloc_empty - Allocate an empty configuration
4217 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
4219 * @driver_param: Driver parameters
4220 * Returns: Pointer to allocated configuration data or %NULL on failure
4222 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
4223 const char *driver_param
)
4225 struct wpa_config
*config
;
4226 const int aCWmin
= 4, aCWmax
= 10;
4227 const struct hostapd_wmm_ac_params ac_bk
=
4228 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
4229 const struct hostapd_wmm_ac_params ac_be
=
4230 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
4231 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
4232 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
4233 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
4234 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
4236 config
= os_zalloc(sizeof(*config
));
4239 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
4240 config
->ap_scan
= DEFAULT_AP_SCAN
;
4241 config
->user_mpm
= DEFAULT_USER_MPM
;
4242 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
4243 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
4244 config
->dot11RSNASAERetransPeriod
=
4245 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
4246 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
4247 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
4248 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
4249 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
4250 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
4251 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
4252 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
4253 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
4254 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
4255 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
4256 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
4257 config
->ap_isolate
= DEFAULT_AP_ISOLATE
;
4258 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
4259 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
4260 config
->wmm_ac_params
[0] = ac_be
;
4261 config
->wmm_ac_params
[1] = ac_bk
;
4262 config
->wmm_ac_params
[2] = ac_vi
;
4263 config
->wmm_ac_params
[3] = ac_vo
;
4264 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
4265 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4266 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
4267 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
4268 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
4271 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
4272 config
->disassoc_imminent_rssi_threshold
=
4273 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
4274 config
->oce
= DEFAULT_OCE_SUPPORT
;
4275 #endif /* CONFIG_MBO */
4278 config
->ctrl_interface
= os_strdup(ctrl_interface
);
4280 config
->driver_param
= os_strdup(driver_param
);
4281 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4287 #ifndef CONFIG_NO_STDOUT_DEBUG
4289 * wpa_config_debug_dump_networks - Debug dump of configured networks
4290 * @config: Configuration data from wpa_config_read()
4292 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
4295 struct wpa_ssid
*ssid
;
4297 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
4298 ssid
= config
->pssid
[prio
];
4299 wpa_printf(MSG_DEBUG
, "Priority group %d",
4302 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
4304 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
4309 #endif /* CONFIG_NO_STDOUT_DEBUG */
4312 struct global_parse_data
{
4314 int (*parser
)(const struct global_parse_data
*data
,
4315 struct wpa_config
*config
, int line
, const char *value
);
4316 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
4317 char *buf
, size_t buflen
, int pretty_print
);
4318 void *param1
, *param2
, *param3
;
4319 unsigned int changed_flag
;
4323 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
4324 struct wpa_config
*config
, int line
,
4330 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
4331 val
= strtol(pos
, &end
, 0);
4333 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
4339 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
4341 if (data
->param2
&& *dst
< (long) data
->param2
) {
4342 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
4343 "min_value=%ld)", line
, data
->name
, *dst
,
4344 (long) data
->param2
);
4345 *dst
= (long) data
->param2
;
4349 if (data
->param3
&& *dst
> (long) data
->param3
) {
4350 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
4351 "max_value=%ld)", line
, data
->name
, *dst
,
4352 (long) data
->param3
);
4353 *dst
= (long) data
->param3
;
4361 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
4362 struct wpa_config
*config
, int line
,
4368 len
= os_strlen(pos
);
4369 if (data
->param2
&& len
< (size_t) data
->param2
) {
4370 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
4371 "min_len=%ld)", line
, data
->name
,
4372 (unsigned long) len
, (long) data
->param2
);
4376 if (data
->param3
&& len
> (size_t) data
->param3
) {
4377 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
4378 "max_len=%ld)", line
, data
->name
,
4379 (unsigned long) len
, (long) data
->param3
);
4383 if (has_newline(pos
)) {
4384 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
4389 tmp
= os_strdup(pos
);
4393 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
4396 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
4402 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
4403 struct wpa_config
*config
, int line
,
4410 tmp
= wpa_config_parse_string(pos
, &len
);
4412 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
4417 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
4423 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
4424 struct wpa_config
*config
, int line
,
4427 struct wpabuf
**dst
, *tmp
;
4429 tmp
= wpabuf_parse_bin(pos
);
4433 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
4436 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
4442 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
4443 struct wpa_config
*config
, int line
,
4448 freqs
= wpa_config_parse_int_array(value
);
4451 if (freqs
[0] == 0) {
4455 os_free(config
->freq_list
);
4456 config
->freq_list
= freqs
;
4462 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
4463 struct wpa_config
*config
, int line
,
4467 struct hostapd_ip_addr addr
;
4469 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
4471 if (addr
.af
!= AF_INET
)
4474 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
4475 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4476 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4477 WPA_GET_BE32((u8
*) dst
));
4481 #endif /* CONFIG_P2P */
4484 static int wpa_config_process_country(const struct global_parse_data
*data
,
4485 struct wpa_config
*config
, int line
,
4488 if (!pos
[0] || !pos
[1]) {
4489 wpa_printf(MSG_DEBUG
, "Invalid country set");
4492 config
->country
[0] = pos
[0];
4493 config
->country
[1] = pos
[1];
4494 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4495 config
->country
[0], config
->country
[1]);
4500 static int wpa_config_process_load_dynamic_eap(
4501 const struct global_parse_data
*data
, struct wpa_config
*config
,
4502 int line
, const char *so
)
4505 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4506 ret
= eap_peer_method_load(so
);
4508 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4511 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4512 "method '%s'.", line
, so
);
4522 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4523 struct wpa_config
*config
, int line
,
4527 if (uuid_str2bin(pos
, config
->uuid
)) {
4528 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4531 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4532 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4537 static int wpa_config_process_device_type(
4538 const struct global_parse_data
*data
,
4539 struct wpa_config
*config
, int line
, const char *pos
)
4541 return wps_dev_type_str2bin(pos
, config
->device_type
);
4545 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4546 struct wpa_config
*config
, int line
,
4549 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4550 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4553 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4554 WPA_GET_BE32(config
->os_version
));
4559 static int wpa_config_process_wps_vendor_ext_m1(
4560 const struct global_parse_data
*data
,
4561 struct wpa_config
*config
, int line
, const char *pos
)
4564 int len
= os_strlen(pos
) / 2;
4568 wpa_printf(MSG_ERROR
, "Line %d: "
4569 "invalid wps_vendor_ext_m1", line
);
4573 tmp
= wpabuf_alloc(len
);
4575 p
= wpabuf_put(tmp
, len
);
4577 if (hexstr2bin(pos
, p
, len
)) {
4578 wpa_printf(MSG_ERROR
, "Line %d: "
4579 "invalid wps_vendor_ext_m1", line
);
4584 wpabuf_free(config
->wps_vendor_ext_m1
);
4585 config
->wps_vendor_ext_m1
= tmp
;
4587 wpa_printf(MSG_ERROR
, "Can not allocate "
4588 "memory for wps_vendor_ext_m1");
4595 #endif /* CONFIG_WPS */
4598 static int wpa_config_process_sec_device_type(
4599 const struct global_parse_data
*data
,
4600 struct wpa_config
*config
, int line
, const char *pos
)
4604 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4605 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4610 idx
= config
->num_sec_device_types
;
4612 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4615 config
->num_sec_device_types
++;
4620 static int wpa_config_process_p2p_pref_chan(
4621 const struct global_parse_data
*data
,
4622 struct wpa_config
*config
, int line
, const char *pos
)
4624 struct p2p_channel
*pref
= NULL
, *n
;
4625 unsigned int num
= 0;
4629 /* format: class:chan,class:chan,... */
4632 op_class
= atoi(pos
);
4633 pos2
= os_strchr(pos
, ':');
4639 n
= os_realloc_array(pref
, num
+ 1,
4640 sizeof(struct p2p_channel
));
4644 pref
[num
].op_class
= op_class
;
4645 pref
[num
].chan
= chan
;
4648 pos
= os_strchr(pos2
, ',');
4654 os_free(config
->p2p_pref_chan
);
4655 config
->p2p_pref_chan
= pref
;
4656 config
->num_p2p_pref_chan
= num
;
4657 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4658 (u8
*) config
->p2p_pref_chan
,
4659 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4665 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4670 static int wpa_config_process_p2p_no_go_freq(
4671 const struct global_parse_data
*data
,
4672 struct wpa_config
*config
, int line
, const char *pos
)
4676 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4678 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4682 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4683 config
->p2p_no_go_freq
.num
);
4689 static int wpa_config_process_p2p_device_persistent_mac_addr(
4690 const struct global_parse_data
*data
,
4691 struct wpa_config
*config
, int line
, const char *pos
)
4693 if (hwaddr_aton2(pos
, config
->p2p_device_persistent_mac_addr
) < 0) {
4694 wpa_printf(MSG_ERROR
,
4695 "Line %d: Invalid p2p_device_persistent_mac_addr '%s'",
4703 #endif /* CONFIG_P2P */
4706 static int wpa_config_process_hessid(
4707 const struct global_parse_data
*data
,
4708 struct wpa_config
*config
, int line
, const char *pos
)
4710 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4711 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4720 static int wpa_config_process_sae_groups(
4721 const struct global_parse_data
*data
,
4722 struct wpa_config
*config
, int line
, const char *pos
)
4724 int *groups
= wpa_config_parse_int_array(pos
);
4725 if (groups
== NULL
) {
4726 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4731 os_free(config
->sae_groups
);
4732 config
->sae_groups
= groups
;
4738 static int wpa_config_process_ap_vendor_elements(
4739 const struct global_parse_data
*data
,
4740 struct wpa_config
*config
, int line
, const char *pos
)
4743 int len
= os_strlen(pos
) / 2;
4747 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4752 tmp
= wpabuf_alloc(len
);
4754 p
= wpabuf_put(tmp
, len
);
4756 if (hexstr2bin(pos
, p
, len
)) {
4757 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4758 "ap_vendor_elements", line
);
4763 wpabuf_free(config
->ap_vendor_elements
);
4764 config
->ap_vendor_elements
= tmp
;
4766 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4767 "ap_vendor_elements");
4775 #ifdef CONFIG_CTRL_IFACE
4776 static int wpa_config_process_no_ctrl_interface(
4777 const struct global_parse_data
*data
,
4778 struct wpa_config
*config
, int line
, const char *pos
)
4780 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4781 os_free(config
->ctrl_interface
);
4782 config
->ctrl_interface
= NULL
;
4785 #endif /* CONFIG_CTRL_IFACE */
4788 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4789 long offset
, char *buf
, size_t buflen
,
4792 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4795 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4796 return os_snprintf(buf
, buflen
, "%d", *val
);
4800 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4801 long offset
, char *buf
, size_t buflen
,
4804 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4808 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4809 *val
? *val
: "null");
4813 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4814 if (os_snprintf_error(buflen
, res
))
4822 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4823 long offset
, char *buf
, size_t buflen
,
4826 void *val
= ((u8
*) config
) + (long) offset
;
4828 char addr
[INET_ADDRSTRLEN
];
4830 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4834 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4836 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4838 if (os_snprintf_error(buflen
, res
))
4843 #endif /* CONFIG_P2P */
4849 /* OFFSET: Get offset of a variable within the wpa_config structure */
4850 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4852 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4853 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4854 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4855 #define INT(f) _INT(f), NULL, NULL
4856 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4857 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4858 #define STR(f) _STR(f), NULL, NULL
4859 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4860 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4861 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4862 OFFSET(f), NULL, NULL
4864 static const struct global_parse_data global_fields
[] = {
4865 #ifdef CONFIG_CTRL_IFACE
4866 { STR(ctrl_interface
), 0 },
4867 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4868 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4869 #endif /* CONFIG_CTRL_IFACE */
4870 #ifdef CONFIG_MACSEC
4871 { INT_RANGE(eapol_version
, 1, 3), 0 },
4872 #else /* CONFIG_MACSEC */
4873 { INT_RANGE(eapol_version
, 1, 2), 0 },
4874 #endif /* CONFIG_MACSEC */
4875 { INT(ap_scan
), 0 },
4876 { FUNC(bgscan
), 0 },
4878 { INT(user_mpm
), 0 },
4879 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4880 { INT(mesh_max_inactivity
), 0 },
4881 { INT(dot11RSNASAERetransPeriod
), 0 },
4882 #endif /* CONFIG_MESH */
4883 { INT(disable_scan_offload
), 0 },
4884 { INT(fast_reauth
), 0 },
4885 { STR(opensc_engine_path
), 0 },
4886 { STR(pkcs11_engine_path
), 0 },
4887 { STR(pkcs11_module_path
), 0 },
4888 { STR(openssl_ciphers
), 0 },
4889 { STR(pcsc_reader
), 0 },
4890 { STR(pcsc_pin
), 0 },
4891 { INT(external_sim
), 0 },
4892 { STR(driver_param
), 0 },
4893 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4894 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4895 { INT(dot11RSNAConfigSATimeout
), 0 },
4896 #ifndef CONFIG_NO_CONFIG_WRITE
4897 { INT(update_config
), 0 },
4898 #endif /* CONFIG_NO_CONFIG_WRITE */
4899 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4901 { FUNC(uuid
), CFG_CHANGED_UUID
},
4902 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4903 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4904 CFG_CHANGED_DEVICE_NAME
},
4905 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4906 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4907 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4908 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4909 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4910 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4911 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4912 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4913 { INT_RANGE(wps_cred_add_sae
, 0, 1), 0 },
4914 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4915 #endif /* CONFIG_WPS */
4917 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4918 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4919 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4920 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4921 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4922 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4923 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4924 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4925 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4926 { INT(p2p_group_idle
), 0 },
4927 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4928 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4929 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4930 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4931 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4932 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4933 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4934 { INT(p2p_go_ht40
), 0 },
4935 { INT(p2p_go_vht
), 0 },
4936 { INT(p2p_go_he
), 0 },
4937 { INT(p2p_disabled
), 0 },
4938 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4939 { INT(p2p_no_group_iface
), 0 },
4940 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4941 { IPV4(ip_addr_go
), 0 },
4942 { IPV4(ip_addr_mask
), 0 },
4943 { IPV4(ip_addr_start
), 0 },
4944 { IPV4(ip_addr_end
), 0 },
4945 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4946 { INT(p2p_device_random_mac_addr
), 0 },
4947 { FUNC(p2p_device_persistent_mac_addr
), 0 },
4948 { INT(p2p_interface_random_mac_addr
), 0 },
4949 #endif /* CONFIG_P2P */
4950 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4951 { INT(bss_max_count
), 0 },
4952 { INT(bss_expiration_age
), 0 },
4953 { INT(bss_expiration_scan_count
), 0 },
4954 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4955 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4956 { INT(max_num_sta
), 0 },
4957 { INT_RANGE(ap_isolate
, 0, 1), 0 },
4958 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4960 { INT_RANGE(hs20
, 0, 1), 0 },
4961 #endif /* CONFIG_HS20 */
4962 { INT_RANGE(interworking
, 0, 1), 0 },
4963 { FUNC(hessid
), 0 },
4964 { INT_RANGE(access_network_type
, 0, 15), 0 },
4965 { INT_RANGE(go_interworking
, 0, 1), 0 },
4966 { INT_RANGE(go_access_network_type
, 0, 15), 0 },
4967 { INT_RANGE(go_internet
, 0, 1), 0 },
4968 { INT_RANGE(go_venue_group
, 0, 255), 0 },
4969 { INT_RANGE(go_venue_type
, 0, 255), 0 },
4970 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
4971 { STR(autoscan
), 0 },
4972 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
4973 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4974 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4975 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4976 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4977 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
4978 { INT(p2p_go_max_inactivity
), 0 },
4979 { INT_RANGE(auto_interworking
, 0, 1), 0 },
4982 { FUNC(sae_groups
), 0 },
4983 { INT_RANGE(sae_pmkid_in_assoc
, 0, 1), 0 },
4984 { INT(dtim_period
), 0 },
4985 { INT(beacon_int
), 0 },
4986 { FUNC(ap_vendor_elements
), 0 },
4987 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
4988 { FUNC(freq_list
), 0 },
4989 { INT(scan_cur_freq
), 0 },
4990 { INT(sched_scan_interval
), 0 },
4991 { INT(sched_scan_start_delay
), 0 },
4992 { INT(tdls_external_control
), 0},
4993 { STR(osu_dir
), 0 },
4994 { STR(wowlan_triggers
), CFG_CHANGED_WOWLAN_TRIGGERS
},
4995 { INT(p2p_search_delay
), 0},
4996 { INT(mac_addr
), 0 },
4997 { INT(rand_addr_lifetime
), 0 },
4998 { INT(preassoc_mac_addr
), 0 },
4999 { INT(key_mgmt_offload
), 0},
5000 { INT(passive_scan
), 0 },
5001 { INT(reassoc_same_bss_optim
), 0 },
5002 { INT(wps_priority
), 0},
5004 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
5005 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
5006 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
5007 #endif /* CONFIG_FST */
5008 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
5009 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
5010 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
5012 { STR(non_pref_chan
), 0 },
5013 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
5014 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
5015 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
5016 { INT_RANGE(oce
, 0, 3), 0 },
5017 #endif /* CONFIG_MBO */
5018 { INT(gas_address3
), 0 },
5019 { INT_RANGE(ftm_responder
, 0, 1), 0 },
5020 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
5021 { INT(gas_rand_addr_lifetime
), 0 },
5022 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
5023 { INT_RANGE(dpp_config_processing
, 0, 2), 0 },
5024 { INT_RANGE(coloc_intf_reporting
, 0, 1), 0 },
5026 { INT_RANGE(disable_btm
, 0, 1), CFG_CHANGED_DISABLE_BTM
},
5027 #endif /* CONFIG_WNM */
5039 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
5042 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
5047 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5048 const struct global_parse_data
*field
= &global_fields
[i
];
5054 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
5066 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
5067 char *buf
, size_t buflen
)
5071 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5072 const struct global_parse_data
*field
= &global_fields
[i
];
5074 if (os_strcmp(name
, field
->name
) != 0)
5078 return field
->get(name
, config
, (long) field
->param1
,
5086 int wpa_config_get_num_global_field_names(void)
5088 return NUM_GLOBAL_FIELDS
;
5092 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
5094 if (i
>= NUM_GLOBAL_FIELDS
)
5098 *no_var
= !global_fields
[i
].param1
;
5099 return global_fields
[i
].name
;
5103 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
5108 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
5109 const struct global_parse_data
*field
= &global_fields
[i
];
5110 size_t flen
= os_strlen(field
->name
);
5111 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
5115 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
5116 wpa_printf(MSG_ERROR
, "Line %d: failed to "
5117 "parse '%s'.", line
, pos
);
5120 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
5121 config
->wps_nfc_pw_from_config
= 1;
5122 config
->changed_parameters
|= field
->changed_flag
;
5125 if (i
== NUM_GLOBAL_FIELDS
) {
5127 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
5128 char *tmp
= os_strchr(pos
, '=');
5132 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
5137 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
5139 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
5144 #endif /* CONFIG_AP */
5147 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",