2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/uuid.h"
13 #include "utils/ip_addr.h"
14 #include "common/ieee802_1x_defs.h"
15 #include "crypto/sha1.h"
16 #include "rsn_supp/wpa.h"
17 #include "eap_peer/eap.h"
23 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
24 #define NO_CONFIG_WRITE
28 * Structure for network configuration parsing. This data is used to implement
29 * a generic parser for each network block variable. The table of configuration
30 * variables is defined below in this file (ssid_fields[]).
33 /* Configuration variable name */
36 /* Parser function for this variable. The parser functions return 0 or 1
37 * to indicate success. Value 0 indicates that the parameter value may
38 * have changed while value 1 means that the value did not change.
39 * Error cases (failure to parse the string) are indicated by returning
41 int (*parser
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
,
42 int line
, const char *value
);
44 #ifndef NO_CONFIG_WRITE
45 /* Writer function (i.e., to get the variable in text format from
46 * internal presentation). */
47 char * (*writer
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
);
48 #endif /* NO_CONFIG_WRITE */
50 /* Variable specific parameters for the parser. */
51 void *param1
, *param2
, *param3
, *param4
;
53 /* 0 = this variable can be included in debug output and ctrl_iface
54 * 1 = this variable contains key/private data and it must not be
55 * included in debug output unless explicitly requested. In
56 * addition, this variable will not be readable through the
63 static int wpa_config_parse_str(const struct parse_data
*data
,
64 struct wpa_ssid
*ssid
,
65 int line
, const char *value
)
67 size_t res_len
, *dst_len
, prev_len
;
70 if (os_strcmp(value
, "NULL") == 0) {
71 wpa_printf(MSG_DEBUG
, "Unset configuration string '%s'",
78 tmp
= wpa_config_parse_string(value
, &res_len
);
80 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s '%s'.",
82 data
->key_data
? "[KEY DATA REMOVED]" : value
);
87 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
90 wpa_hexdump_ascii(MSG_MSGDUMP
, data
->name
,
94 if (data
->param3
&& res_len
< (size_t) data
->param3
) {
95 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
96 "min_len=%ld)", line
, data
->name
,
97 (unsigned long) res_len
, (long) data
->param3
);
102 if (data
->param4
&& res_len
> (size_t) data
->param4
) {
103 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
104 "max_len=%ld)", line
, data
->name
,
105 (unsigned long) res_len
, (long) data
->param4
);
111 dst
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
112 dst_len
= (size_t *) (((u8
*) ssid
) + (long) data
->param2
);
117 prev_len
= os_strlen(*dst
);
120 if ((*dst
== NULL
&& tmp
== NULL
) ||
121 (*dst
&& tmp
&& prev_len
== res_len
&&
122 os_memcmp(*dst
, tmp
, res_len
) == 0)) {
123 /* No change to the previously configured value */
137 #ifndef NO_CONFIG_WRITE
138 static char * wpa_config_write_string_ascii(const u8
*value
, size_t len
)
142 buf
= os_malloc(len
+ 3);
146 os_memcpy(buf
+ 1, value
, len
);
154 static char * wpa_config_write_string_hex(const u8
*value
, size_t len
)
158 buf
= os_zalloc(2 * len
+ 1);
161 wpa_snprintf_hex(buf
, 2 * len
+ 1, value
, len
);
167 static char * wpa_config_write_string(const u8
*value
, size_t len
)
172 if (is_hex(value
, len
))
173 return wpa_config_write_string_hex(value
, len
);
175 return wpa_config_write_string_ascii(value
, len
);
179 static char * wpa_config_write_str(const struct parse_data
*data
,
180 struct wpa_ssid
*ssid
)
185 src
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
190 len
= *((size_t *) (((u8
*) ssid
) + (long) data
->param2
));
192 len
= os_strlen(*src
);
194 return wpa_config_write_string((const u8
*) *src
, len
);
196 #endif /* NO_CONFIG_WRITE */
199 static int wpa_config_parse_int(const struct parse_data
*data
,
200 struct wpa_ssid
*ssid
,
201 int line
, const char *value
)
206 dst
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
207 val
= strtol(value
, &end
, 0);
209 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
217 wpa_printf(MSG_MSGDUMP
, "%s=%d (0x%x)", data
->name
, *dst
, *dst
);
219 if (data
->param3
&& *dst
< (long) data
->param3
) {
220 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
221 "min_value=%ld)", line
, data
->name
, *dst
,
222 (long) data
->param3
);
223 *dst
= (long) data
->param3
;
227 if (data
->param4
&& *dst
> (long) data
->param4
) {
228 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
229 "max_value=%ld)", line
, data
->name
, *dst
,
230 (long) data
->param4
);
231 *dst
= (long) data
->param4
;
239 #ifndef NO_CONFIG_WRITE
240 static char * wpa_config_write_int(const struct parse_data
*data
,
241 struct wpa_ssid
*ssid
)
246 src
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
248 value
= os_malloc(20);
251 res
= os_snprintf(value
, 20, "%d", *src
);
252 if (os_snprintf_error(20, res
)) {
256 value
[20 - 1] = '\0';
259 #endif /* NO_CONFIG_WRITE */
262 static int wpa_config_parse_addr_list(const struct parse_data
*data
,
263 int line
, const char *value
,
264 u8
**list
, size_t *num
, char *name
,
265 u8 abort_on_error
, u8 masked
)
268 u8
*buf
, *n
, addr
[2 * ETH_ALEN
];
275 while (pos
&& *pos
) {
279 if (hwaddr_masked_aton(pos
, addr
, &addr
[ETH_ALEN
], masked
)) {
280 if (abort_on_error
|| count
== 0) {
281 wpa_printf(MSG_ERROR
,
282 "Line %d: Invalid %s address '%s'",
287 /* continue anyway since this could have been from a
288 * truncated configuration file line */
290 "Line %d: Ignore likely truncated %s address '%s'",
293 n
= os_realloc_array(buf
, count
+ 1, 2 * ETH_ALEN
);
299 os_memmove(buf
+ 2 * ETH_ALEN
, buf
,
300 count
* 2 * ETH_ALEN
);
301 os_memcpy(buf
, addr
, 2 * ETH_ALEN
);
303 wpa_printf(MSG_MSGDUMP
,
304 "%s: addr=" MACSTR
" mask=" MACSTR
,
306 MAC2STR(&addr
[ETH_ALEN
]));
309 pos
= os_strchr(pos
, ' ');
320 #ifndef NO_CONFIG_WRITE
321 static char * wpa_config_write_addr_list(const struct parse_data
*data
,
322 const u8
*list
, size_t num
, char *name
)
324 char *value
, *end
, *pos
;
328 if (list
== NULL
|| num
== 0)
331 value
= os_malloc(2 * 20 * num
);
335 end
= value
+ 2 * 20 * num
;
337 for (i
= num
; i
> 0; i
--) {
338 const u8
*a
= list
+ (i
- 1) * 2 * ETH_ALEN
;
339 const u8
*m
= a
+ ETH_ALEN
;
343 res
= hwaddr_mask_txt(pos
, end
- pos
, a
, m
);
353 #endif /* NO_CONFIG_WRITE */
355 static int wpa_config_parse_bssid(const struct parse_data
*data
,
356 struct wpa_ssid
*ssid
, int line
,
359 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
360 os_strcmp(value
, "any") == 0) {
362 wpa_printf(MSG_MSGDUMP
, "BSSID any");
365 if (hwaddr_aton(value
, ssid
->bssid
)) {
366 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID '%s'.",
371 wpa_hexdump(MSG_MSGDUMP
, "BSSID", ssid
->bssid
, ETH_ALEN
);
376 #ifndef NO_CONFIG_WRITE
377 static char * wpa_config_write_bssid(const struct parse_data
*data
,
378 struct wpa_ssid
*ssid
)
383 if (!ssid
->bssid_set
)
386 value
= os_malloc(20);
389 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid
));
390 if (os_snprintf_error(20, res
)) {
394 value
[20 - 1] = '\0';
397 #endif /* NO_CONFIG_WRITE */
400 static int wpa_config_parse_bssid_hint(const struct parse_data
*data
,
401 struct wpa_ssid
*ssid
, int line
,
404 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
405 os_strcmp(value
, "any") == 0) {
406 ssid
->bssid_hint_set
= 0;
407 wpa_printf(MSG_MSGDUMP
, "BSSID hint any");
410 if (hwaddr_aton(value
, ssid
->bssid_hint
)) {
411 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID hint '%s'.",
415 ssid
->bssid_hint_set
= 1;
416 wpa_hexdump(MSG_MSGDUMP
, "BSSID hint", ssid
->bssid_hint
, ETH_ALEN
);
421 #ifndef NO_CONFIG_WRITE
422 static char * wpa_config_write_bssid_hint(const struct parse_data
*data
,
423 struct wpa_ssid
*ssid
)
428 if (!ssid
->bssid_hint_set
)
431 value
= os_malloc(20);
434 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid_hint
));
435 if (os_snprintf_error(20, res
)) {
441 #endif /* NO_CONFIG_WRITE */
444 static int wpa_config_parse_bssid_blacklist(const struct parse_data
*data
,
445 struct wpa_ssid
*ssid
, int line
,
448 return wpa_config_parse_addr_list(data
, line
, value
,
449 &ssid
->bssid_blacklist
,
450 &ssid
->num_bssid_blacklist
,
451 "bssid_blacklist", 1, 1);
455 #ifndef NO_CONFIG_WRITE
456 static char * wpa_config_write_bssid_blacklist(const struct parse_data
*data
,
457 struct wpa_ssid
*ssid
)
459 return wpa_config_write_addr_list(data
, ssid
->bssid_blacklist
,
460 ssid
->num_bssid_blacklist
,
463 #endif /* NO_CONFIG_WRITE */
466 static int wpa_config_parse_bssid_whitelist(const struct parse_data
*data
,
467 struct wpa_ssid
*ssid
, int line
,
470 return wpa_config_parse_addr_list(data
, line
, value
,
471 &ssid
->bssid_whitelist
,
472 &ssid
->num_bssid_whitelist
,
473 "bssid_whitelist", 1, 1);
477 #ifndef NO_CONFIG_WRITE
478 static char * wpa_config_write_bssid_whitelist(const struct parse_data
*data
,
479 struct wpa_ssid
*ssid
)
481 return wpa_config_write_addr_list(data
, ssid
->bssid_whitelist
,
482 ssid
->num_bssid_whitelist
,
485 #endif /* NO_CONFIG_WRITE */
488 static int wpa_config_parse_psk(const struct parse_data
*data
,
489 struct wpa_ssid
*ssid
, int line
,
492 #ifdef CONFIG_EXT_PASSWORD
493 if (os_strncmp(value
, "ext:", 4) == 0) {
494 str_clear_free(ssid
->passphrase
);
495 ssid
->passphrase
= NULL
;
497 os_free(ssid
->ext_psk
);
498 ssid
->ext_psk
= os_strdup(value
+ 4);
499 if (ssid
->ext_psk
== NULL
)
501 wpa_printf(MSG_DEBUG
, "PSK: External password '%s'",
505 #endif /* CONFIG_EXT_PASSWORD */
508 #ifndef CONFIG_NO_PBKDF2
513 pos
= os_strrchr(value
, '"');
517 len
= os_strlen(value
);
518 if (len
< 8 || len
> 63) {
519 wpa_printf(MSG_ERROR
, "Line %d: Invalid passphrase "
520 "length %lu (expected: 8..63) '%s'.",
521 line
, (unsigned long) len
, value
);
524 wpa_hexdump_ascii_key(MSG_MSGDUMP
, "PSK (ASCII passphrase)",
526 if (has_ctrl_char((u8
*) value
, len
)) {
527 wpa_printf(MSG_ERROR
,
528 "Line %d: Invalid passphrase character",
532 if (ssid
->passphrase
&& os_strlen(ssid
->passphrase
) == len
&&
533 os_memcmp(ssid
->passphrase
, value
, len
) == 0) {
534 /* No change to the previously configured value */
538 str_clear_free(ssid
->passphrase
);
539 ssid
->passphrase
= dup_binstr(value
, len
);
540 if (ssid
->passphrase
== NULL
)
543 #else /* CONFIG_NO_PBKDF2 */
544 wpa_printf(MSG_ERROR
, "Line %d: ASCII passphrase not "
547 #endif /* CONFIG_NO_PBKDF2 */
550 if (hexstr2bin(value
, ssid
->psk
, PMK_LEN
) ||
551 value
[PMK_LEN
* 2] != '\0') {
552 wpa_printf(MSG_ERROR
, "Line %d: Invalid PSK '%s'.",
557 str_clear_free(ssid
->passphrase
);
558 ssid
->passphrase
= NULL
;
561 wpa_hexdump_key(MSG_MSGDUMP
, "PSK", ssid
->psk
, PMK_LEN
);
566 #ifndef NO_CONFIG_WRITE
567 static char * wpa_config_write_psk(const struct parse_data
*data
,
568 struct wpa_ssid
*ssid
)
570 #ifdef CONFIG_EXT_PASSWORD
572 size_t len
= 4 + os_strlen(ssid
->ext_psk
) + 1;
573 char *buf
= os_malloc(len
);
578 res
= os_snprintf(buf
, len
, "ext:%s", ssid
->ext_psk
);
579 if (os_snprintf_error(len
, res
)) {
585 #endif /* CONFIG_EXT_PASSWORD */
587 if (ssid
->passphrase
)
588 return wpa_config_write_string_ascii(
589 (const u8
*) ssid
->passphrase
,
590 os_strlen(ssid
->passphrase
));
593 return wpa_config_write_string_hex(ssid
->psk
, PMK_LEN
);
597 #endif /* NO_CONFIG_WRITE */
600 static int wpa_config_parse_proto(const struct parse_data
*data
,
601 struct wpa_ssid
*ssid
, int line
,
604 int val
= 0, last
, errors
= 0;
605 char *start
, *end
, *buf
;
607 buf
= os_strdup(value
);
612 while (*start
!= '\0') {
613 while (*start
== ' ' || *start
== '\t')
618 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
622 if (os_strcmp(start
, "WPA") == 0)
623 val
|= WPA_PROTO_WPA
;
624 else if (os_strcmp(start
, "RSN") == 0 ||
625 os_strcmp(start
, "WPA2") == 0)
626 val
|= WPA_PROTO_RSN
;
627 else if (os_strcmp(start
, "OSEN") == 0)
628 val
|= WPA_PROTO_OSEN
;
630 wpa_printf(MSG_ERROR
, "Line %d: invalid proto '%s'",
642 wpa_printf(MSG_ERROR
,
643 "Line %d: no proto values configured.", line
);
647 if (!errors
&& ssid
->proto
== val
)
649 wpa_printf(MSG_MSGDUMP
, "proto: 0x%x", val
);
651 return errors
? -1 : 0;
655 #ifndef NO_CONFIG_WRITE
656 static char * wpa_config_write_proto(const struct parse_data
*data
,
657 struct wpa_ssid
*ssid
)
660 char *buf
, *pos
, *end
;
662 pos
= buf
= os_zalloc(20);
667 if (ssid
->proto
& WPA_PROTO_WPA
) {
668 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
669 pos
== buf
? "" : " ");
670 if (os_snprintf_error(end
- pos
, ret
))
675 if (ssid
->proto
& WPA_PROTO_RSN
) {
676 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
677 pos
== buf
? "" : " ");
678 if (os_snprintf_error(end
- pos
, ret
))
683 if (ssid
->proto
& WPA_PROTO_OSEN
) {
684 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
685 pos
== buf
? "" : " ");
686 if (os_snprintf_error(end
- pos
, ret
))
698 #endif /* NO_CONFIG_WRITE */
701 static int wpa_config_parse_key_mgmt(const struct parse_data
*data
,
702 struct wpa_ssid
*ssid
, int line
,
705 int val
= 0, last
, errors
= 0;
706 char *start
, *end
, *buf
;
708 buf
= os_strdup(value
);
713 while (*start
!= '\0') {
714 while (*start
== ' ' || *start
== '\t')
719 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
723 if (os_strcmp(start
, "WPA-PSK") == 0)
724 val
|= WPA_KEY_MGMT_PSK
;
725 else if (os_strcmp(start
, "WPA-EAP") == 0)
726 val
|= WPA_KEY_MGMT_IEEE8021X
;
727 else if (os_strcmp(start
, "IEEE8021X") == 0)
728 val
|= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
729 else if (os_strcmp(start
, "NONE") == 0)
730 val
|= WPA_KEY_MGMT_NONE
;
731 else if (os_strcmp(start
, "WPA-NONE") == 0)
732 val
|= WPA_KEY_MGMT_WPA_NONE
;
733 #ifdef CONFIG_IEEE80211R
734 else if (os_strcmp(start
, "FT-PSK") == 0)
735 val
|= WPA_KEY_MGMT_FT_PSK
;
736 else if (os_strcmp(start
, "FT-EAP") == 0)
737 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
739 else if (os_strcmp(start
, "FT-EAP-SHA384") == 0)
740 val
|= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
741 #endif /* CONFIG_SHA384 */
742 #endif /* CONFIG_IEEE80211R */
743 #ifdef CONFIG_IEEE80211W
744 else if (os_strcmp(start
, "WPA-PSK-SHA256") == 0)
745 val
|= WPA_KEY_MGMT_PSK_SHA256
;
746 else if (os_strcmp(start
, "WPA-EAP-SHA256") == 0)
747 val
|= WPA_KEY_MGMT_IEEE8021X_SHA256
;
748 #endif /* CONFIG_IEEE80211W */
750 else if (os_strcmp(start
, "WPS") == 0)
751 val
|= WPA_KEY_MGMT_WPS
;
752 #endif /* CONFIG_WPS */
754 else if (os_strcmp(start
, "SAE") == 0)
755 val
|= WPA_KEY_MGMT_SAE
;
756 else if (os_strcmp(start
, "FT-SAE") == 0)
757 val
|= WPA_KEY_MGMT_FT_SAE
;
758 #endif /* CONFIG_SAE */
760 else if (os_strcmp(start
, "OSEN") == 0)
761 val
|= WPA_KEY_MGMT_OSEN
;
762 #endif /* CONFIG_HS20 */
764 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
765 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
766 #endif /* CONFIG_SUITEB */
767 #ifdef CONFIG_SUITEB192
768 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
769 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
770 #endif /* CONFIG_SUITEB192 */
772 else if (os_strcmp(start
, "FILS-SHA256") == 0)
773 val
|= WPA_KEY_MGMT_FILS_SHA256
;
774 else if (os_strcmp(start
, "FILS-SHA384") == 0)
775 val
|= WPA_KEY_MGMT_FILS_SHA384
;
776 #ifdef CONFIG_IEEE80211R
777 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
778 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
779 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
780 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
781 #endif /* CONFIG_IEEE80211R */
782 #endif /* CONFIG_FILS */
784 else if (os_strcmp(start
, "OWE") == 0)
785 val
|= WPA_KEY_MGMT_OWE
;
786 #endif /* CONFIG_OWE */
788 else if (os_strcmp(start
, "DPP") == 0)
789 val
|= WPA_KEY_MGMT_DPP
;
790 #endif /* CONFIG_DPP */
792 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
804 wpa_printf(MSG_ERROR
,
805 "Line %d: no key_mgmt values configured.", line
);
809 if (!errors
&& ssid
->key_mgmt
== val
)
811 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
812 ssid
->key_mgmt
= val
;
813 return errors
? -1 : 0;
817 #ifndef NO_CONFIG_WRITE
818 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
819 struct wpa_ssid
*ssid
)
821 char *buf
, *pos
, *end
;
824 pos
= buf
= os_zalloc(100);
829 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
830 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
831 pos
== buf
? "" : " ");
832 if (os_snprintf_error(end
- pos
, ret
)) {
839 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
840 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
841 pos
== buf
? "" : " ");
842 if (os_snprintf_error(end
- pos
, ret
)) {
849 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
850 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
851 pos
== buf
? "" : " ");
852 if (os_snprintf_error(end
- pos
, ret
)) {
859 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
860 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
861 pos
== buf
? "" : " ");
862 if (os_snprintf_error(end
- pos
, ret
)) {
869 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
870 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
871 pos
== buf
? "" : " ");
872 if (os_snprintf_error(end
- pos
, ret
)) {
879 #ifdef CONFIG_IEEE80211R
880 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
881 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
882 pos
== buf
? "" : " ");
883 if (os_snprintf_error(end
- pos
, ret
)) {
890 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
891 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
892 pos
== buf
? "" : " ");
893 if (os_snprintf_error(end
- pos
, ret
)) {
901 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
902 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP-SHA384",
903 pos
== buf
? "" : " ");
904 if (os_snprintf_error(end
- pos
, ret
)) {
910 #endif /* CONFIG_SHA384 */
911 #endif /* CONFIG_IEEE80211R */
913 #ifdef CONFIG_IEEE80211W
914 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
915 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
916 pos
== buf
? "" : " ");
917 if (os_snprintf_error(end
- pos
, ret
)) {
924 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
925 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
926 pos
== buf
? "" : " ");
927 if (os_snprintf_error(end
- pos
, ret
)) {
933 #endif /* CONFIG_IEEE80211W */
936 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
937 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
938 pos
== buf
? "" : " ");
939 if (os_snprintf_error(end
- pos
, ret
)) {
945 #endif /* CONFIG_WPS */
948 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
949 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
950 pos
== buf
? "" : " ");
951 if (os_snprintf_error(end
- pos
, ret
)) {
958 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
959 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
960 pos
== buf
? "" : " ");
961 if (os_snprintf_error(end
- pos
, ret
)) {
967 #endif /* CONFIG_SAE */
970 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
971 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
972 pos
== buf
? "" : " ");
973 if (os_snprintf_error(end
- pos
, ret
)) {
979 #endif /* CONFIG_HS20 */
982 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
983 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
984 pos
== buf
? "" : " ");
985 if (os_snprintf_error(end
- pos
, ret
)) {
991 #endif /* CONFIG_SUITEB */
993 #ifdef CONFIG_SUITEB192
994 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
995 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
996 pos
== buf
? "" : " ");
997 if (os_snprintf_error(end
- pos
, ret
)) {
1003 #endif /* CONFIG_SUITEB192 */
1006 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1007 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
1008 pos
== buf
? "" : " ");
1009 if (os_snprintf_error(end
- pos
, ret
)) {
1015 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1016 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
1017 pos
== buf
? "" : " ");
1018 if (os_snprintf_error(end
- pos
, ret
)) {
1024 #ifdef CONFIG_IEEE80211R
1025 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1026 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
1027 pos
== buf
? "" : " ");
1028 if (os_snprintf_error(end
- pos
, ret
)) {
1034 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1035 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
1036 pos
== buf
? "" : " ");
1037 if (os_snprintf_error(end
- pos
, ret
)) {
1043 #endif /* CONFIG_IEEE80211R */
1044 #endif /* CONFIG_FILS */
1047 if (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) {
1048 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
1049 pos
== buf
? "" : " ");
1050 if (os_snprintf_error(end
- pos
, ret
)) {
1056 #endif /* CONFIG_DPP */
1059 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) {
1060 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
1061 pos
== buf
? "" : " ");
1062 if (os_snprintf_error(end
- pos
, ret
)) {
1068 #endif /* CONFIG_OWE */
1077 #endif /* NO_CONFIG_WRITE */
1080 static int wpa_config_parse_cipher(int line
, const char *value
)
1082 #ifdef CONFIG_NO_WPA
1084 #else /* CONFIG_NO_WPA */
1085 int val
= wpa_parse_cipher(value
);
1087 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1092 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1097 #endif /* CONFIG_NO_WPA */
1101 #ifndef NO_CONFIG_WRITE
1102 static char * wpa_config_write_cipher(int cipher
)
1104 #ifdef CONFIG_NO_WPA
1106 #else /* CONFIG_NO_WPA */
1107 char *buf
= os_zalloc(50);
1111 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1117 #endif /* CONFIG_NO_WPA */
1119 #endif /* NO_CONFIG_WRITE */
1122 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1123 struct wpa_ssid
*ssid
, int line
,
1127 val
= wpa_config_parse_cipher(line
, value
);
1130 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1131 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1132 "(0x%x).", line
, val
);
1136 if (ssid
->pairwise_cipher
== val
)
1138 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1139 ssid
->pairwise_cipher
= val
;
1144 #ifndef NO_CONFIG_WRITE
1145 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1146 struct wpa_ssid
*ssid
)
1148 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1150 #endif /* NO_CONFIG_WRITE */
1153 static int wpa_config_parse_group(const struct parse_data
*data
,
1154 struct wpa_ssid
*ssid
, int line
,
1158 val
= wpa_config_parse_cipher(line
, value
);
1163 * Backwards compatibility - filter out WEP ciphers that were previously
1166 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1168 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1169 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1170 "(0x%x).", line
, val
);
1174 if (ssid
->group_cipher
== val
)
1176 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1177 ssid
->group_cipher
= val
;
1182 #ifndef NO_CONFIG_WRITE
1183 static char * wpa_config_write_group(const struct parse_data
*data
,
1184 struct wpa_ssid
*ssid
)
1186 return wpa_config_write_cipher(ssid
->group_cipher
);
1188 #endif /* NO_CONFIG_WRITE */
1191 static int wpa_config_parse_group_mgmt(const struct parse_data
*data
,
1192 struct wpa_ssid
*ssid
, int line
,
1197 val
= wpa_config_parse_cipher(line
, value
);
1201 if (val
& ~WPA_ALLOWED_GROUP_MGMT_CIPHERS
) {
1202 wpa_printf(MSG_ERROR
,
1203 "Line %d: not allowed group management cipher (0x%x).",
1208 if (ssid
->group_mgmt_cipher
== val
)
1210 wpa_printf(MSG_MSGDUMP
, "group_mgmt: 0x%x", val
);
1211 ssid
->group_mgmt_cipher
= val
;
1216 #ifndef NO_CONFIG_WRITE
1217 static char * wpa_config_write_group_mgmt(const struct parse_data
*data
,
1218 struct wpa_ssid
*ssid
)
1220 return wpa_config_write_cipher(ssid
->group_mgmt_cipher
);
1222 #endif /* NO_CONFIG_WRITE */
1225 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1226 struct wpa_ssid
*ssid
, int line
,
1229 int val
= 0, last
, errors
= 0;
1230 char *start
, *end
, *buf
;
1232 buf
= os_strdup(value
);
1237 while (*start
!= '\0') {
1238 while (*start
== ' ' || *start
== '\t')
1243 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1245 last
= *end
== '\0';
1247 if (os_strcmp(start
, "OPEN") == 0)
1248 val
|= WPA_AUTH_ALG_OPEN
;
1249 else if (os_strcmp(start
, "SHARED") == 0)
1250 val
|= WPA_AUTH_ALG_SHARED
;
1251 else if (os_strcmp(start
, "LEAP") == 0)
1252 val
|= WPA_AUTH_ALG_LEAP
;
1254 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1266 wpa_printf(MSG_ERROR
,
1267 "Line %d: no auth_alg values configured.", line
);
1271 if (!errors
&& ssid
->auth_alg
== val
)
1273 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1274 ssid
->auth_alg
= val
;
1275 return errors
? -1 : 0;
1279 #ifndef NO_CONFIG_WRITE
1280 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1281 struct wpa_ssid
*ssid
)
1283 char *buf
, *pos
, *end
;
1286 pos
= buf
= os_zalloc(30);
1291 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1292 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1293 pos
== buf
? "" : " ");
1294 if (os_snprintf_error(end
- pos
, ret
)) {
1301 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1302 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1303 pos
== buf
? "" : " ");
1304 if (os_snprintf_error(end
- pos
, ret
)) {
1311 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1312 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1313 pos
== buf
? "" : " ");
1314 if (os_snprintf_error(end
- pos
, ret
)) {
1328 #endif /* NO_CONFIG_WRITE */
1331 static int * wpa_config_parse_int_array(const char *value
)
1339 freqs
= os_calloc(len
+ 1, sizeof(int));
1350 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1355 for (i
= len
; i
<= len
* 2; i
++)
1361 freqs
[used
] = atoi(pos
);
1362 if (freqs
[used
] == 0)
1365 pos
= os_strchr(pos
+ 1, ' ');
1372 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1373 struct wpa_ssid
*ssid
, int line
,
1378 freqs
= wpa_config_parse_int_array(value
);
1381 if (freqs
[0] == 0) {
1385 os_free(ssid
->scan_freq
);
1386 ssid
->scan_freq
= freqs
;
1392 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1393 struct wpa_ssid
*ssid
, int line
,
1398 freqs
= wpa_config_parse_int_array(value
);
1401 if (freqs
[0] == 0) {
1405 os_free(ssid
->freq_list
);
1406 ssid
->freq_list
= freqs
;
1412 #ifndef NO_CONFIG_WRITE
1413 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1416 char *buf
, *pos
, *end
;
1424 for (i
= 0; freqs
[i
]; i
++)
1427 pos
= buf
= os_zalloc(10 * count
+ 1);
1430 end
= buf
+ 10 * count
+ 1;
1432 for (i
= 0; freqs
[i
]; i
++) {
1433 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1434 i
== 0 ? "" : " ", freqs
[i
]);
1435 if (os_snprintf_error(end
- pos
, ret
)) {
1446 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1447 struct wpa_ssid
*ssid
)
1449 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1453 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1454 struct wpa_ssid
*ssid
)
1456 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1458 #endif /* NO_CONFIG_WRITE */
1461 #ifdef IEEE8021X_EAPOL
1462 static int wpa_config_parse_eap(const struct parse_data
*data
,
1463 struct wpa_ssid
*ssid
, int line
,
1466 int last
, errors
= 0;
1467 char *start
, *end
, *buf
;
1468 struct eap_method_type
*methods
= NULL
, *tmp
;
1469 size_t num_methods
= 0;
1471 buf
= os_strdup(value
);
1476 while (*start
!= '\0') {
1477 while (*start
== ' ' || *start
== '\t')
1482 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1484 last
= *end
== '\0';
1487 methods
= os_realloc_array(methods
, num_methods
+ 1,
1489 if (methods
== NULL
) {
1494 methods
[num_methods
].method
= eap_peer_get_type(
1495 start
, &methods
[num_methods
].vendor
);
1496 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1497 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1498 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1499 "'%s'", line
, start
);
1500 wpa_printf(MSG_ERROR
, "You may need to add support for"
1501 " this EAP method during wpa_supplicant\n"
1502 "build time configuration.\n"
1503 "See README for more information.");
1505 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1506 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1518 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1519 if (methods
== NULL
) {
1523 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1524 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1527 if (!errors
&& ssid
->eap
.eap_methods
) {
1528 struct eap_method_type
*prev_m
;
1529 size_t i
, j
, prev_methods
, match
= 0;
1531 prev_m
= ssid
->eap
.eap_methods
;
1532 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1533 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1534 /* Count the methods */
1536 prev_methods
= i
+ 1;
1538 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1540 for (j
= 0; j
< num_methods
; j
++) {
1541 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1542 prev_m
[i
].method
== methods
[j
].method
) {
1548 if (match
== num_methods
) {
1553 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1554 (u8
*) methods
, num_methods
* sizeof(*methods
));
1555 os_free(ssid
->eap
.eap_methods
);
1556 ssid
->eap
.eap_methods
= methods
;
1557 return errors
? -1 : 0;
1561 #ifndef NO_CONFIG_WRITE
1562 static char * wpa_config_write_eap(const struct parse_data
*data
,
1563 struct wpa_ssid
*ssid
)
1566 char *buf
, *pos
, *end
;
1567 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1570 if (eap_methods
== NULL
)
1573 pos
= buf
= os_zalloc(100);
1578 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1579 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1580 name
= eap_get_name(eap_methods
[i
].vendor
,
1581 eap_methods
[i
].method
);
1583 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1584 pos
== buf
? "" : " ", name
);
1585 if (os_snprintf_error(end
- pos
, ret
))
1595 #endif /* NO_CONFIG_WRITE */
1598 static int wpa_config_parse_password(const struct parse_data
*data
,
1599 struct wpa_ssid
*ssid
, int line
,
1604 if (os_strcmp(value
, "NULL") == 0) {
1605 if (!ssid
->eap
.password
)
1606 return 1; /* Already unset */
1607 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1608 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1609 ssid
->eap
.password
= NULL
;
1610 ssid
->eap
.password_len
= 0;
1614 #ifdef CONFIG_EXT_PASSWORD
1615 if (os_strncmp(value
, "ext:", 4) == 0) {
1616 char *name
= os_strdup(value
+ 4);
1619 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1620 ssid
->eap
.password
= (u8
*) name
;
1621 ssid
->eap
.password_len
= os_strlen(name
);
1622 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1623 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1626 #endif /* CONFIG_EXT_PASSWORD */
1628 if (os_strncmp(value
, "hash:", 5) != 0) {
1632 tmp
= wpa_config_parse_string(value
, &res_len
);
1634 wpa_printf(MSG_ERROR
, "Line %d: failed to parse "
1638 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1639 (u8
*) tmp
, res_len
);
1641 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1642 ssid
->eap
.password
= (u8
*) tmp
;
1643 ssid
->eap
.password_len
= res_len
;
1644 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1645 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1651 /* NtPasswordHash: hash:<32 hex digits> */
1652 if (os_strlen(value
+ 5) != 2 * 16) {
1653 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash length "
1654 "(expected 32 hex digits)", line
);
1658 hash
= os_malloc(16);
1662 if (hexstr2bin(value
+ 5, hash
, 16)) {
1664 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1668 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1670 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1671 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1672 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1673 bin_clear_free(hash
, 16);
1676 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1677 ssid
->eap
.password
= hash
;
1678 ssid
->eap
.password_len
= 16;
1679 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1680 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1686 #ifndef NO_CONFIG_WRITE
1687 static char * wpa_config_write_password(const struct parse_data
*data
,
1688 struct wpa_ssid
*ssid
)
1692 if (ssid
->eap
.password
== NULL
)
1695 #ifdef CONFIG_EXT_PASSWORD
1696 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1697 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1700 os_memcpy(buf
, "ext:", 4);
1701 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1704 #endif /* CONFIG_EXT_PASSWORD */
1706 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1707 return wpa_config_write_string(
1708 ssid
->eap
.password
, ssid
->eap
.password_len
);
1711 buf
= os_malloc(5 + 32 + 1);
1715 os_memcpy(buf
, "hash:", 5);
1716 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1720 #endif /* NO_CONFIG_WRITE */
1721 #endif /* IEEE8021X_EAPOL */
1724 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1725 const char *value
, int idx
)
1727 char *buf
, title
[20];
1730 buf
= wpa_config_parse_string(value
, len
);
1732 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1736 if (*len
> MAX_WEP_KEY_LEN
) {
1737 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1742 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1743 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1744 "this network block will be ignored",
1745 line
, (unsigned int) *len
);
1747 os_memcpy(key
, buf
, *len
);
1748 str_clear_free(buf
);
1749 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1750 if (!os_snprintf_error(sizeof(title
), res
))
1751 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1756 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1757 struct wpa_ssid
*ssid
, int line
,
1760 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1761 &ssid
->wep_key_len
[0], line
,
1766 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1767 struct wpa_ssid
*ssid
, int line
,
1770 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1771 &ssid
->wep_key_len
[1], line
,
1776 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1777 struct wpa_ssid
*ssid
, int line
,
1780 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1781 &ssid
->wep_key_len
[2], line
,
1786 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1787 struct wpa_ssid
*ssid
, int line
,
1790 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1791 &ssid
->wep_key_len
[3], line
,
1796 #ifndef NO_CONFIG_WRITE
1797 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1799 if (ssid
->wep_key_len
[idx
] == 0)
1801 return wpa_config_write_string(ssid
->wep_key
[idx
],
1802 ssid
->wep_key_len
[idx
]);
1806 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1807 struct wpa_ssid
*ssid
)
1809 return wpa_config_write_wep_key(ssid
, 0);
1813 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1814 struct wpa_ssid
*ssid
)
1816 return wpa_config_write_wep_key(ssid
, 1);
1820 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1821 struct wpa_ssid
*ssid
)
1823 return wpa_config_write_wep_key(ssid
, 2);
1827 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1828 struct wpa_ssid
*ssid
)
1830 return wpa_config_write_wep_key(ssid
, 3);
1832 #endif /* NO_CONFIG_WRITE */
1837 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1838 struct wpa_ssid
*ssid
, int line
,
1841 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1842 os_strcmp(value
, "any") == 0) {
1843 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1844 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1847 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1848 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1852 ssid
->bssid_set
= 1;
1853 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1854 MAC2STR(ssid
->go_p2p_dev_addr
));
1859 #ifndef NO_CONFIG_WRITE
1860 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
1861 struct wpa_ssid
*ssid
)
1866 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
1869 value
= os_malloc(20);
1872 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
1873 if (os_snprintf_error(20, res
)) {
1877 value
[20 - 1] = '\0';
1880 #endif /* NO_CONFIG_WRITE */
1883 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
1884 struct wpa_ssid
*ssid
, int line
,
1887 return wpa_config_parse_addr_list(data
, line
, value
,
1888 &ssid
->p2p_client_list
,
1889 &ssid
->num_p2p_clients
,
1890 "p2p_client_list", 0, 0);
1894 #ifndef NO_CONFIG_WRITE
1895 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
1896 struct wpa_ssid
*ssid
)
1898 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
1899 ssid
->num_p2p_clients
,
1902 #endif /* NO_CONFIG_WRITE */
1905 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
1906 struct wpa_ssid
*ssid
, int line
,
1909 struct psk_list_entry
*p
;
1912 p
= os_zalloc(sizeof(*p
));
1917 if (os_strncmp(pos
, "P2P-", 4) == 0) {
1922 if (hwaddr_aton(pos
, p
->addr
)) {
1923 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
1930 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
1937 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
1938 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
1944 dl_list_add(&ssid
->psk_list
, &p
->list
);
1950 #ifndef NO_CONFIG_WRITE
1951 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
1952 struct wpa_ssid
*ssid
)
1956 #endif /* NO_CONFIG_WRITE */
1958 #endif /* CONFIG_P2P */
1963 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
1964 struct wpa_ssid
*ssid
, int line
,
1967 int *rates
= wpa_config_parse_int_array(value
);
1969 if (rates
== NULL
) {
1970 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
1974 if (rates
[0] == 0) {
1979 os_free(ssid
->mesh_basic_rates
);
1980 ssid
->mesh_basic_rates
= rates
;
1986 #ifndef NO_CONFIG_WRITE
1988 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
1989 struct wpa_ssid
*ssid
)
1991 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
1994 #endif /* NO_CONFIG_WRITE */
1996 #endif /* CONFIG_MESH */
1999 #ifdef CONFIG_MACSEC
2001 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
2002 struct wpa_ssid
*ssid
, int line
,
2007 len
= os_strlen(value
);
2008 if (len
> 2 * MACSEC_CAK_MAX_LEN
||
2009 (len
!= 2 * 16 && len
!= 2 * 32) ||
2010 hexstr2bin(value
, ssid
->mka_cak
, len
/ 2)) {
2011 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
2015 ssid
->mka_cak_len
= len
/ 2;
2016 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
2018 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
,
2024 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
2025 struct wpa_ssid
*ssid
, int line
,
2030 len
= os_strlen(value
);
2031 if (len
> 2 * MACSEC_CKN_MAX_LEN
|| /* too long */
2032 len
< 2 || /* too short */
2033 len
% 2 != 0 /* not an integral number of bytes */) {
2034 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2038 ssid
->mka_ckn_len
= len
/ 2;
2039 if (hexstr2bin(value
, ssid
->mka_ckn
, ssid
->mka_ckn_len
)) {
2040 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
2045 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
2047 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
,
2053 #ifndef NO_CONFIG_WRITE
2055 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
2056 struct wpa_ssid
*ssid
)
2058 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
2061 return wpa_config_write_string_hex(ssid
->mka_cak
, ssid
->mka_cak_len
);
2065 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
2066 struct wpa_ssid
*ssid
)
2068 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
2070 return wpa_config_write_string_hex(ssid
->mka_ckn
, ssid
->mka_ckn_len
);
2073 #endif /* NO_CONFIG_WRITE */
2075 #endif /* CONFIG_MACSEC */
2080 static int wpa_config_parse_ocv(const struct parse_data
*data
,
2081 struct wpa_ssid
*ssid
, int line
,
2086 ssid
->ocv
= strtol(value
, &end
, 0);
2087 if (*end
|| ssid
->ocv
< 0 || ssid
->ocv
> 1) {
2088 wpa_printf(MSG_ERROR
, "Line %d: Invalid ocv value '%s'.",
2092 if (ssid
->ocv
&& ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
)
2093 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_OPTIONAL
;
2098 #ifndef NO_CONFIG_WRITE
2099 static char * wpa_config_write_ocv(const struct parse_data
*data
,
2100 struct wpa_ssid
*ssid
)
2102 char *value
= os_malloc(20);
2106 os_snprintf(value
, 20, "%d", ssid
->ocv
);
2107 value
[20 - 1] = '\0';
2110 #endif /* NO_CONFIG_WRITE */
2112 #endif /* CONFIG_OCV */
2115 static int wpa_config_parse_peerkey(const struct parse_data
*data
,
2116 struct wpa_ssid
*ssid
, int line
,
2119 wpa_printf(MSG_INFO
, "NOTE: Obsolete peerkey parameter ignored");
2124 #ifndef NO_CONFIG_WRITE
2125 static char * wpa_config_write_peerkey(const struct parse_data
*data
,
2126 struct wpa_ssid
*ssid
)
2130 #endif /* NO_CONFIG_WRITE */
2133 /* Helper macros for network block parser */
2138 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
2139 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
2141 /* STR: Define a string variable for an ASCII string; f = field name */
2142 #ifdef NO_CONFIG_WRITE
2143 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
2144 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
2145 #else /* NO_CONFIG_WRITE */
2146 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
2147 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
2148 #endif /* NO_CONFIG_WRITE */
2149 #define STR(f) _STR(f), NULL, NULL, NULL, 0
2150 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
2151 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
2152 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
2154 /* STR_LEN: Define a string variable with a separate variable for storing the
2155 * data length. Unlike STR(), this can be used to store arbitrary binary data
2156 * (i.e., even nul termination character). */
2157 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
2158 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
2159 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
2160 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
2161 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
2163 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
2164 * explicitly specified. */
2165 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
2166 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
2167 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
2169 #ifdef NO_CONFIG_WRITE
2170 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
2171 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
2172 #else /* NO_CONFIG_WRITE */
2173 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2174 OFFSET(f), (void *) 0
2175 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
2176 OFFSET(eap.f), (void *) 0
2177 #endif /* NO_CONFIG_WRITE */
2179 /* INT: Define an integer variable */
2180 #define INT(f) _INT(f), NULL, NULL, 0
2181 #define INTe(f) _INTe(f), NULL, NULL, 0
2183 /* INT_RANGE: Define an integer variable with allowed value range */
2184 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
2186 /* FUNC: Define a configuration variable that uses a custom function for
2187 * parsing and writing the value. */
2188 #ifdef NO_CONFIG_WRITE
2189 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
2190 #else /* NO_CONFIG_WRITE */
2191 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
2192 NULL, NULL, NULL, NULL
2193 #endif /* NO_CONFIG_WRITE */
2194 #define FUNC(f) _FUNC(f), 0
2195 #define FUNC_KEY(f) _FUNC(f), 1
2198 * Table of network configuration variables. This table is used to parse each
2199 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2200 * that is inside a network block.
2202 * This table is generated using the helper macros defined above and with
2203 * generous help from the C pre-processor. The field name is stored as a string
2204 * into .name and for STR and INT types, the offset of the target buffer within
2205 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2206 * offset to the field containing the length of the configuration variable.
2207 * .param3 and .param4 can be used to mark the allowed range (length for STR
2208 * and value for INT).
2210 * For each configuration line in wpa_supplicant.conf, the parser goes through
2211 * this table and select the entry that matches with the field name. The parser
2212 * function (.parser) is then called to parse the actual value of the field.
2214 * This kind of mechanism makes it easy to add new configuration parameters,
2215 * since only one line needs to be added into this table and into the
2216 * struct wpa_ssid definition if the new variable is either a string or
2217 * integer. More complex types will need to use their own parser and writer
2220 static const struct parse_data ssid_fields
[] = {
2221 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2222 { INT_RANGE(scan_ssid
, 0, 1) },
2224 { FUNC(bssid_hint
) },
2225 { FUNC(bssid_blacklist
) },
2226 { FUNC(bssid_whitelist
) },
2228 { INT(mem_only_psk
) },
2229 { STR_KEY(sae_password
) },
2230 { STR(sae_password_id
) },
2233 { INT(bg_scan_period
) },
2236 { FUNC(group_mgmt
) },
2238 { FUNC(scan_freq
) },
2239 { FUNC(freq_list
) },
2240 { INT_RANGE(ht
, 0, 1) },
2241 { INT_RANGE(vht
, 0, 1) },
2242 { INT_RANGE(ht40
, -1, 1) },
2243 { INT_RANGE(max_oper_chwidth
, CHANWIDTH_USE_HT
,
2244 CHANWIDTH_80P80MHZ
) },
2245 { INT(vht_center_freq1
) },
2246 { INT(vht_center_freq2
) },
2247 #ifdef IEEE8021X_EAPOL
2249 { STR_LENe(identity
) },
2250 { STR_LENe(anonymous_identity
) },
2251 { STR_LENe(imsi_identity
) },
2252 { FUNC_KEY(password
) },
2255 { STRe(client_cert
) },
2256 { STRe(private_key
) },
2257 { STR_KEYe(private_key_passwd
) },
2259 { STRe(subject_match
) },
2260 { STRe(check_cert_subject
) },
2261 { STRe(altsubject_match
) },
2262 { STRe(domain_suffix_match
) },
2263 { STRe(domain_match
) },
2266 { STRe(client_cert2
) },
2267 { STRe(private_key2
) },
2268 { STR_KEYe(private_key2_passwd
) },
2270 { STRe(subject_match2
) },
2271 { STRe(check_cert_subject2
) },
2272 { STRe(altsubject_match2
) },
2273 { STRe(domain_suffix_match2
) },
2274 { STRe(domain_match2
) },
2279 { STRe(engine_id
) },
2282 { STRe(ca_cert_id
) },
2284 { STRe(engine2_id
) },
2287 { STRe(ca_cert2_id
) },
2290 { INT(eapol_flags
) },
2292 { STRe(openssl_ciphers
) },
2294 #endif /* IEEE8021X_EAPOL */
2295 { FUNC_KEY(wep_key0
) },
2296 { FUNC_KEY(wep_key1
) },
2297 { FUNC_KEY(wep_key2
) },
2298 { FUNC_KEY(wep_key3
) },
2299 { INT(wep_tx_keyidx
) },
2301 #ifdef IEEE8021X_EAPOL
2302 { INT(eap_workaround
) },
2304 { INTe(fragment_size
) },
2306 #endif /* IEEE8021X_EAPOL */
2308 { INT_RANGE(mode
, 0, 5) },
2309 { INT_RANGE(no_auto_peer
, 0, 1) },
2310 { INT_RANGE(mesh_rssi_threshold
, -255, 1) },
2311 #else /* CONFIG_MESH */
2312 { INT_RANGE(mode
, 0, 4) },
2313 #endif /* CONFIG_MESH */
2314 { INT_RANGE(proactive_key_caching
, 0, 1) },
2315 { INT_RANGE(disabled
, 0, 2) },
2317 #ifdef CONFIG_IEEE80211W
2318 { INT_RANGE(ieee80211w
, 0, 2) },
2319 #endif /* CONFIG_IEEE80211W */
2322 #endif /* CONFIG_OCV */
2323 { FUNC(peerkey
) /* obsolete - removed */ },
2324 { INT_RANGE(mixed_cell
, 0, 1) },
2325 { INT_RANGE(frequency
, 0, 65000) },
2326 { INT_RANGE(fixed_freq
, 0, 1) },
2328 { INT_RANGE(acs
, 0, 1) },
2329 #endif /* CONFIG_ACS */
2331 { FUNC(mesh_basic_rates
) },
2332 { INT(dot11MeshMaxRetries
) },
2333 { INT(dot11MeshRetryTimeout
) },
2334 { INT(dot11MeshConfirmTimeout
) },
2335 { INT(dot11MeshHoldingTimeout
) },
2336 #endif /* CONFIG_MESH */
2337 { INT(wpa_ptk_rekey
) },
2338 { INT(group_rekey
) },
2340 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2342 { FUNC(go_p2p_dev_addr
) },
2343 { FUNC(p2p_client_list
) },
2345 #endif /* CONFIG_P2P */
2346 #ifdef CONFIG_HT_OVERRIDES
2347 { INT_RANGE(disable_ht
, 0, 1) },
2348 { INT_RANGE(disable_ht40
, -1, 1) },
2349 { INT_RANGE(disable_sgi
, 0, 1) },
2350 { INT_RANGE(disable_ldpc
, 0, 1) },
2351 { INT_RANGE(ht40_intolerant
, 0, 1) },
2352 { INT_RANGE(tx_stbc
, -1, 1) },
2353 { INT_RANGE(rx_stbc
, -1, 3) },
2354 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2355 { INT_RANGE(ampdu_factor
, -1, 3) },
2356 { INT_RANGE(ampdu_density
, -1, 7) },
2358 #endif /* CONFIG_HT_OVERRIDES */
2359 #ifdef CONFIG_VHT_OVERRIDES
2360 { INT_RANGE(disable_vht
, 0, 1) },
2362 { INT(vht_capa_mask
) },
2363 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2364 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2365 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2366 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2367 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2368 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2369 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2370 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2371 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2372 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2373 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2374 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2375 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2376 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2377 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2378 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2379 #endif /* CONFIG_VHT_OVERRIDES */
2380 { INT(ap_max_inactivity
) },
2381 { INT(dtim_period
) },
2382 { INT(beacon_int
) },
2383 #ifdef CONFIG_MACSEC
2384 { INT_RANGE(macsec_policy
, 0, 1) },
2385 { INT_RANGE(macsec_integ_only
, 0, 1) },
2386 { INT_RANGE(macsec_replay_protect
, 0, 1) },
2387 { INT(macsec_replay_window
) },
2388 { INT_RANGE(macsec_port
, 1, 65534) },
2389 { INT_RANGE(mka_priority
, 0, 255) },
2390 { FUNC_KEY(mka_cak
) },
2391 { FUNC_KEY(mka_ckn
) },
2392 #endif /* CONFIG_MACSEC */
2394 { INT(update_identifier
) },
2395 { STR_RANGE(roaming_consortium_selection
, 0, MAX_ROAMING_CONS_OI_LEN
) },
2396 #endif /* CONFIG_HS20 */
2397 { INT_RANGE(mac_addr
, 0, 2) },
2398 { INT_RANGE(pbss
, 0, 2) },
2399 { INT_RANGE(wps_disabled
, 0, 1) },
2400 { INT_RANGE(fils_dh_group
, 0, 65535) },
2402 { STR(dpp_connector
) },
2403 { STR_LEN(dpp_netaccesskey
) },
2404 { INT(dpp_netaccesskey_expiry
) },
2405 { STR_LEN(dpp_csign
) },
2406 #endif /* CONFIG_DPP */
2407 { INT_RANGE(owe_group
, 0, 65535) },
2408 { INT_RANGE(owe_only
, 0, 1) },
2409 { INT_RANGE(multi_ap_backhaul_sta
, 0, 1) },
2410 { INT_RANGE(ft_eap_pmksa_caching
, 0, 1) },
2422 #undef STR_RANGE_KEY
2429 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2433 * wpa_config_add_prio_network - Add a network to priority lists
2434 * @config: Configuration data from wpa_config_read()
2435 * @ssid: Pointer to the network configuration to be added to the list
2436 * Returns: 0 on success, -1 on failure
2438 * This function is used to add a network block to the priority list of
2439 * networks. This must be called for each network when reading in the full
2440 * configuration. In addition, this can be used indirectly when updating
2441 * priorities by calling wpa_config_update_prio_list().
2443 int wpa_config_add_prio_network(struct wpa_config
*config
,
2444 struct wpa_ssid
*ssid
)
2447 struct wpa_ssid
*prev
, **nlist
;
2450 * Add to an existing priority list if one is available for the
2451 * configured priority level for this network.
2453 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2454 prev
= config
->pssid
[prio
];
2455 if (prev
->priority
== ssid
->priority
) {
2463 /* First network for this priority - add a new priority list */
2464 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2465 sizeof(struct wpa_ssid
*));
2469 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2470 if (nlist
[prio
]->priority
< ssid
->priority
) {
2471 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2472 (config
->num_prio
- prio
) *
2473 sizeof(struct wpa_ssid
*));
2480 config
->pssid
= nlist
;
2487 * wpa_config_update_prio_list - Update network priority list
2488 * @config: Configuration data from wpa_config_read()
2489 * Returns: 0 on success, -1 on failure
2491 * This function is called to update the priority list of networks in the
2492 * configuration when a network is being added or removed. This is also called
2493 * if a priority for a network is changed.
2495 int wpa_config_update_prio_list(struct wpa_config
*config
)
2497 struct wpa_ssid
*ssid
;
2500 os_free(config
->pssid
);
2501 config
->pssid
= NULL
;
2502 config
->num_prio
= 0;
2504 ssid
= config
->ssid
;
2507 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2516 #ifdef IEEE8021X_EAPOL
2517 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2519 os_free(eap
->eap_methods
);
2520 bin_clear_free(eap
->identity
, eap
->identity_len
);
2521 os_free(eap
->anonymous_identity
);
2522 os_free(eap
->imsi_identity
);
2523 bin_clear_free(eap
->password
, eap
->password_len
);
2524 os_free(eap
->ca_cert
);
2525 os_free(eap
->ca_path
);
2526 os_free(eap
->client_cert
);
2527 os_free(eap
->private_key
);
2528 str_clear_free(eap
->private_key_passwd
);
2529 os_free(eap
->dh_file
);
2530 os_free(eap
->subject_match
);
2531 os_free(eap
->check_cert_subject
);
2532 os_free(eap
->altsubject_match
);
2533 os_free(eap
->domain_suffix_match
);
2534 os_free(eap
->domain_match
);
2535 os_free(eap
->ca_cert2
);
2536 os_free(eap
->ca_path2
);
2537 os_free(eap
->client_cert2
);
2538 os_free(eap
->private_key2
);
2539 str_clear_free(eap
->private_key2_passwd
);
2540 os_free(eap
->dh_file2
);
2541 os_free(eap
->subject_match2
);
2542 os_free(eap
->check_cert_subject2
);
2543 os_free(eap
->altsubject_match2
);
2544 os_free(eap
->domain_suffix_match2
);
2545 os_free(eap
->domain_match2
);
2546 os_free(eap
->phase1
);
2547 os_free(eap
->phase2
);
2549 str_clear_free(eap
->pin
);
2550 os_free(eap
->engine_id
);
2551 os_free(eap
->key_id
);
2552 os_free(eap
->cert_id
);
2553 os_free(eap
->ca_cert_id
);
2554 os_free(eap
->key2_id
);
2555 os_free(eap
->cert2_id
);
2556 os_free(eap
->ca_cert2_id
);
2557 str_clear_free(eap
->pin2
);
2558 os_free(eap
->engine2_id
);
2560 os_free(eap
->pending_req_otp
);
2561 os_free(eap
->pac_file
);
2562 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2563 str_clear_free(eap
->external_sim_resp
);
2564 os_free(eap
->openssl_ciphers
);
2566 #endif /* IEEE8021X_EAPOL */
2570 * wpa_config_free_ssid - Free network/ssid configuration data
2571 * @ssid: Configuration data for the network
2573 * This function frees all resources allocated for the network configuration
2576 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2578 struct psk_list_entry
*psk
;
2580 os_free(ssid
->ssid
);
2581 str_clear_free(ssid
->passphrase
);
2582 os_free(ssid
->ext_psk
);
2583 str_clear_free(ssid
->sae_password
);
2584 os_free(ssid
->sae_password_id
);
2585 #ifdef IEEE8021X_EAPOL
2586 eap_peer_config_free(&ssid
->eap
);
2587 #endif /* IEEE8021X_EAPOL */
2588 os_free(ssid
->id_str
);
2589 os_free(ssid
->scan_freq
);
2590 os_free(ssid
->freq_list
);
2591 os_free(ssid
->bgscan
);
2592 os_free(ssid
->p2p_client_list
);
2593 os_free(ssid
->bssid_blacklist
);
2594 os_free(ssid
->bssid_whitelist
);
2595 #ifdef CONFIG_HT_OVERRIDES
2596 os_free(ssid
->ht_mcs
);
2597 #endif /* CONFIG_HT_OVERRIDES */
2599 os_free(ssid
->mesh_basic_rates
);
2600 #endif /* CONFIG_MESH */
2602 os_free(ssid
->roaming_consortium_selection
);
2603 #endif /* CONFIG_HS20 */
2604 os_free(ssid
->dpp_connector
);
2605 bin_clear_free(ssid
->dpp_netaccesskey
, ssid
->dpp_netaccesskey_len
);
2606 os_free(ssid
->dpp_csign
);
2607 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2609 dl_list_del(&psk
->list
);
2610 bin_clear_free(psk
, sizeof(*psk
));
2612 bin_clear_free(ssid
, sizeof(*ssid
));
2616 void wpa_config_free_cred(struct wpa_cred
*cred
)
2620 os_free(cred
->realm
);
2621 str_clear_free(cred
->username
);
2622 str_clear_free(cred
->password
);
2623 os_free(cred
->ca_cert
);
2624 os_free(cred
->client_cert
);
2625 os_free(cred
->private_key
);
2626 str_clear_free(cred
->private_key_passwd
);
2627 os_free(cred
->imsi
);
2628 str_clear_free(cred
->milenage
);
2629 for (i
= 0; i
< cred
->num_domain
; i
++)
2630 os_free(cred
->domain
[i
]);
2631 os_free(cred
->domain
);
2632 os_free(cred
->domain_suffix_match
);
2633 os_free(cred
->eap_method
);
2634 os_free(cred
->phase1
);
2635 os_free(cred
->phase2
);
2636 os_free(cred
->excluded_ssid
);
2637 os_free(cred
->roaming_partner
);
2638 os_free(cred
->provisioning_sp
);
2639 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2640 os_free(cred
->req_conn_capab_port
[i
]);
2641 os_free(cred
->req_conn_capab_port
);
2642 os_free(cred
->req_conn_capab_proto
);
2647 void wpa_config_flush_blobs(struct wpa_config
*config
)
2649 #ifndef CONFIG_NO_CONFIG_BLOBS
2650 struct wpa_config_blob
*blob
, *prev
;
2652 blob
= config
->blobs
;
2653 config
->blobs
= NULL
;
2657 wpa_config_free_blob(prev
);
2659 #endif /* CONFIG_NO_CONFIG_BLOBS */
2664 * wpa_config_free - Free configuration data
2665 * @config: Configuration data from wpa_config_read()
2667 * This function frees all resources allocated for the configuration data by
2668 * wpa_config_read().
2670 void wpa_config_free(struct wpa_config
*config
)
2672 struct wpa_ssid
*ssid
, *prev
= NULL
;
2673 struct wpa_cred
*cred
, *cprev
;
2676 ssid
= config
->ssid
;
2680 wpa_config_free_ssid(prev
);
2683 cred
= config
->cred
;
2687 wpa_config_free_cred(cprev
);
2690 wpa_config_flush_blobs(config
);
2692 wpabuf_free(config
->wps_vendor_ext_m1
);
2693 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2694 wpabuf_free(config
->wps_vendor_ext
[i
]);
2695 os_free(config
->ctrl_interface
);
2696 os_free(config
->ctrl_interface_group
);
2697 os_free(config
->opensc_engine_path
);
2698 os_free(config
->pkcs11_engine_path
);
2699 os_free(config
->pkcs11_module_path
);
2700 os_free(config
->openssl_ciphers
);
2701 os_free(config
->pcsc_reader
);
2702 str_clear_free(config
->pcsc_pin
);
2703 os_free(config
->driver_param
);
2704 os_free(config
->device_name
);
2705 os_free(config
->manufacturer
);
2706 os_free(config
->model_name
);
2707 os_free(config
->model_number
);
2708 os_free(config
->serial_number
);
2709 os_free(config
->config_methods
);
2710 os_free(config
->p2p_ssid_postfix
);
2711 os_free(config
->pssid
);
2712 os_free(config
->p2p_pref_chan
);
2713 os_free(config
->p2p_no_go_freq
.range
);
2714 os_free(config
->autoscan
);
2715 os_free(config
->freq_list
);
2716 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2717 wpabuf_free(config
->wps_nfc_dh_privkey
);
2718 wpabuf_free(config
->wps_nfc_dev_pw
);
2719 os_free(config
->ext_password_backend
);
2720 os_free(config
->sae_groups
);
2721 wpabuf_free(config
->ap_vendor_elements
);
2722 os_free(config
->osu_dir
);
2723 os_free(config
->bgscan
);
2724 os_free(config
->wowlan_triggers
);
2725 os_free(config
->fst_group_id
);
2726 os_free(config
->sched_scan_plans
);
2728 os_free(config
->non_pref_chan
);
2729 #endif /* CONFIG_MBO */
2736 * wpa_config_foreach_network - Iterate over each configured network
2737 * @config: Configuration data from wpa_config_read()
2738 * @func: Callback function to process each network
2739 * @arg: Opaque argument to pass to callback function
2741 * Iterate over the set of configured networks calling the specified
2742 * function for each item. We guard against callbacks removing the
2745 void wpa_config_foreach_network(struct wpa_config
*config
,
2746 void (*func
)(void *, struct wpa_ssid
*),
2749 struct wpa_ssid
*ssid
, *next
;
2751 ssid
= config
->ssid
;
2761 * wpa_config_get_network - Get configured network based on id
2762 * @config: Configuration data from wpa_config_read()
2763 * @id: Unique network id to search for
2764 * Returns: Network configuration or %NULL if not found
2766 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2768 struct wpa_ssid
*ssid
;
2770 ssid
= config
->ssid
;
2782 * wpa_config_add_network - Add a new network with empty configuration
2783 * @config: Configuration data from wpa_config_read()
2784 * Returns: The new network configuration or %NULL if operation failed
2786 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2789 struct wpa_ssid
*ssid
, *last
= NULL
;
2792 ssid
= config
->ssid
;
2801 ssid
= os_zalloc(sizeof(*ssid
));
2805 dl_list_init(&ssid
->psk_list
);
2809 config
->ssid
= ssid
;
2811 wpa_config_update_prio_list(config
);
2818 * wpa_config_remove_network - Remove a configured network based on id
2819 * @config: Configuration data from wpa_config_read()
2820 * @id: Unique network id to search for
2821 * Returns: 0 on success, or -1 if the network was not found
2823 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2825 struct wpa_ssid
*ssid
, *prev
= NULL
;
2827 ssid
= config
->ssid
;
2839 prev
->next
= ssid
->next
;
2841 config
->ssid
= ssid
->next
;
2843 wpa_config_update_prio_list(config
);
2844 wpa_config_free_ssid(ssid
);
2850 * wpa_config_set_network_defaults - Set network default values
2851 * @ssid: Pointer to network configuration data
2853 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
2855 ssid
->proto
= DEFAULT_PROTO
;
2856 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
2857 ssid
->group_cipher
= DEFAULT_GROUP
;
2858 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
2859 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
2861 #ifdef IEEE8021X_EAPOL
2862 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
2863 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
2864 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
2865 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
2866 #endif /* IEEE8021X_EAPOL */
2868 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
2869 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
2870 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
2871 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
2872 ssid
->mesh_rssi_threshold
= DEFAULT_MESH_RSSI_THRESHOLD
;
2873 #endif /* CONFIG_MESH */
2874 #ifdef CONFIG_HT_OVERRIDES
2875 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
2876 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
2877 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
2878 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
2879 ssid
->tx_stbc
= DEFAULT_TX_STBC
;
2880 ssid
->rx_stbc
= DEFAULT_RX_STBC
;
2881 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
2882 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
2883 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
2884 #endif /* CONFIG_HT_OVERRIDES */
2885 #ifdef CONFIG_VHT_OVERRIDES
2886 ssid
->vht_rx_mcs_nss_1
= -1;
2887 ssid
->vht_rx_mcs_nss_2
= -1;
2888 ssid
->vht_rx_mcs_nss_3
= -1;
2889 ssid
->vht_rx_mcs_nss_4
= -1;
2890 ssid
->vht_rx_mcs_nss_5
= -1;
2891 ssid
->vht_rx_mcs_nss_6
= -1;
2892 ssid
->vht_rx_mcs_nss_7
= -1;
2893 ssid
->vht_rx_mcs_nss_8
= -1;
2894 ssid
->vht_tx_mcs_nss_1
= -1;
2895 ssid
->vht_tx_mcs_nss_2
= -1;
2896 ssid
->vht_tx_mcs_nss_3
= -1;
2897 ssid
->vht_tx_mcs_nss_4
= -1;
2898 ssid
->vht_tx_mcs_nss_5
= -1;
2899 ssid
->vht_tx_mcs_nss_6
= -1;
2900 ssid
->vht_tx_mcs_nss_7
= -1;
2901 ssid
->vht_tx_mcs_nss_8
= -1;
2902 #endif /* CONFIG_VHT_OVERRIDES */
2903 ssid
->proactive_key_caching
= -1;
2904 #ifdef CONFIG_IEEE80211W
2905 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
2906 #endif /* CONFIG_IEEE80211W */
2907 #ifdef CONFIG_MACSEC
2908 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
2909 #endif /* CONFIG_MACSEC */
2910 ssid
->mac_addr
= -1;
2911 ssid
->max_oper_chwidth
= DEFAULT_MAX_OPER_CHWIDTH
;
2916 * wpa_config_set - Set a variable in network configuration
2917 * @ssid: Pointer to network configuration data
2918 * @var: Variable name, e.g., "ssid"
2919 * @value: Variable value
2920 * @line: Line number in configuration file or 0 if not used
2921 * Returns: 0 on success with possible change in the value, 1 on success with
2922 * no change to previously configured value, or -1 on failure
2924 * This function can be used to set network configuration variables based on
2925 * both the configuration file and management interface input. The value
2926 * parameter must be in the same format as the text-based configuration file is
2927 * using. For example, strings are using double quotation marks.
2929 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
2935 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
2938 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2939 const struct parse_data
*field
= &ssid_fields
[i
];
2940 if (os_strcmp(var
, field
->name
) != 0)
2943 ret
= field
->parser(field
, ssid
, line
, value
);
2946 wpa_printf(MSG_ERROR
, "Line %d: failed to "
2947 "parse %s '%s'.", line
, var
, value
);
2953 if (i
== NUM_SSID_FIELDS
) {
2955 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
2956 "'%s'.", line
, var
);
2965 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
2972 len
= os_strlen(value
);
2973 buf
= os_malloc(len
+ 3);
2977 os_memcpy(buf
+ 1, value
, len
);
2979 buf
[len
+ 2] = '\0';
2980 ret
= wpa_config_set(ssid
, var
, buf
, 0);
2987 * wpa_config_get_all - Get all options from network configuration
2988 * @ssid: Pointer to network configuration data
2989 * @get_keys: Determines if keys/passwords will be included in returned list
2990 * (if they may be exported)
2991 * Returns: %NULL terminated list of all set keys and their values in the form
2992 * of [key1, val1, key2, val2, ... , NULL]
2994 * This function can be used to get list of all configured network properties.
2995 * The caller is responsible for freeing the returned list and all its
2998 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
3000 #ifdef NO_CONFIG_WRITE
3002 #else /* NO_CONFIG_WRITE */
3003 const struct parse_data
*field
;
3009 get_keys
= get_keys
&& ssid
->export_keys
;
3011 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
3016 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3017 field
= &ssid_fields
[i
];
3018 if (field
->key_data
&& !get_keys
)
3020 value
= field
->writer(field
, ssid
);
3023 if (os_strlen(value
) == 0) {
3028 key
= os_strdup(field
->name
);
3034 props
[fields_num
* 2] = key
;
3035 props
[fields_num
* 2 + 1] = value
;
3043 for (i
= 0; props
[i
]; i
++)
3047 #endif /* NO_CONFIG_WRITE */
3051 #ifndef NO_CONFIG_WRITE
3053 * wpa_config_get - Get a variable in network configuration
3054 * @ssid: Pointer to network configuration data
3055 * @var: Variable name, e.g., "ssid"
3056 * Returns: Value of the variable or %NULL on failure
3058 * This function can be used to get network configuration variables. The
3059 * returned value is a copy of the configuration variable in text format, i.e,.
3060 * the same format that the text-based configuration file and wpa_config_set()
3061 * are using for the value. The caller is responsible for freeing the returned
3064 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
3068 if (ssid
== NULL
|| var
== NULL
)
3071 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3072 const struct parse_data
*field
= &ssid_fields
[i
];
3073 if (os_strcmp(var
, field
->name
) == 0) {
3074 char *ret
= field
->writer(field
, ssid
);
3076 if (ret
&& has_newline(ret
)) {
3077 wpa_printf(MSG_ERROR
,
3078 "Found newline in value for %s; not returning it",
3093 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
3094 * @ssid: Pointer to network configuration data
3095 * @var: Variable name, e.g., "ssid"
3096 * Returns: Value of the variable or %NULL on failure
3098 * This function can be used to get network configuration variable like
3099 * wpa_config_get(). The only difference is that this functions does not expose
3100 * key/password material from the configuration. In case a key/password field
3101 * is requested, the returned value is an empty string or %NULL if the variable
3102 * is not set or "*" if the variable is set (regardless of its value). The
3103 * returned value is a copy of the configuration variable in text format, i.e,.
3104 * the same format that the text-based configuration file and wpa_config_set()
3105 * are using for the value. The caller is responsible for freeing the returned
3108 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
3112 if (ssid
== NULL
|| var
== NULL
)
3115 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
3116 const struct parse_data
*field
= &ssid_fields
[i
];
3117 if (os_strcmp(var
, field
->name
) == 0) {
3118 char *res
= field
->writer(field
, ssid
);
3119 if (field
->key_data
) {
3120 if (res
&& res
[0]) {
3121 wpa_printf(MSG_DEBUG
, "Do not allow "
3122 "key_data field to be "
3124 str_clear_free(res
);
3125 return os_strdup("*");
3137 #endif /* NO_CONFIG_WRITE */
3141 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
3142 * @ssid: Pointer to network configuration data
3144 * This function must be called to update WPA PSK when either SSID or the
3145 * passphrase has changed for the network configuration.
3147 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
3149 #ifndef CONFIG_NO_PBKDF2
3150 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
3151 ssid
->psk
, PMK_LEN
);
3152 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
3153 ssid
->psk
, PMK_LEN
);
3155 #endif /* CONFIG_NO_PBKDF2 */
3159 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
3164 int *ports
, *nports
;
3166 unsigned int num_ports
;
3168 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
3169 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
3172 cred
->req_conn_capab_proto
= proto
;
3174 port
= os_realloc_array(cred
->req_conn_capab_port
,
3175 cred
->num_req_conn_capab
+ 1, sizeof(int *));
3178 cred
->req_conn_capab_port
= port
;
3180 proto
[cred
->num_req_conn_capab
] = atoi(value
);
3182 pos
= os_strchr(value
, ':');
3184 port
[cred
->num_req_conn_capab
] = NULL
;
3185 cred
->num_req_conn_capab
++;
3194 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3195 if (nports
== NULL
) {
3200 ports
[num_ports
++] = atoi(pos
);
3202 pos
= os_strchr(pos
, ',');
3208 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
3209 if (nports
== NULL
) {
3214 ports
[num_ports
] = -1;
3216 port
[cred
->num_req_conn_capab
] = ports
;
3217 cred
->num_req_conn_capab
++;
3222 static int wpa_config_set_cred_roaming_consortiums(struct wpa_cred
*cred
,
3225 u8 roaming_consortiums
[MAX_ROAMING_CONS
][MAX_ROAMING_CONS_OI_LEN
];
3226 size_t roaming_consortiums_len
[MAX_ROAMING_CONS
];
3227 unsigned int num_roaming_consortiums
= 0;
3228 const char *pos
, *end
;
3231 os_memset(roaming_consortiums
, 0, sizeof(roaming_consortiums
));
3232 os_memset(roaming_consortiums_len
, 0, sizeof(roaming_consortiums_len
));
3234 for (pos
= value
;;) {
3235 end
= os_strchr(pos
, ',');
3236 len
= end
? (size_t) (end
- pos
) : os_strlen(pos
);
3237 if (!end
&& len
== 0)
3239 if (len
== 0 || (len
& 1) != 0 ||
3240 len
/ 2 > MAX_ROAMING_CONS_OI_LEN
||
3242 roaming_consortiums
[num_roaming_consortiums
],
3244 wpa_printf(MSG_INFO
,
3245 "Invalid roaming_consortiums entry: %s",
3249 roaming_consortiums_len
[num_roaming_consortiums
] = len
/ 2;
3250 num_roaming_consortiums
++;
3255 if (num_roaming_consortiums
>= MAX_ROAMING_CONS
) {
3256 wpa_printf(MSG_INFO
,
3257 "Too many roaming_consortiums OIs");
3264 os_memcpy(cred
->roaming_consortiums
, roaming_consortiums
,
3265 sizeof(roaming_consortiums
));
3266 os_memcpy(cred
->roaming_consortiums_len
, roaming_consortiums_len
,
3267 sizeof(roaming_consortiums_len
));
3268 cred
->num_roaming_consortiums
= num_roaming_consortiums
;
3274 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
3275 const char *value
, int line
)
3281 if (os_strcmp(var
, "temporary") == 0) {
3282 cred
->temporary
= atoi(value
);
3286 if (os_strcmp(var
, "priority") == 0) {
3287 cred
->priority
= atoi(value
);
3291 if (os_strcmp(var
, "sp_priority") == 0) {
3292 int prio
= atoi(value
);
3293 if (prio
< 0 || prio
> 255)
3295 cred
->sp_priority
= prio
;
3299 if (os_strcmp(var
, "pcsc") == 0) {
3300 cred
->pcsc
= atoi(value
);
3304 if (os_strcmp(var
, "eap") == 0) {
3305 struct eap_method_type method
;
3306 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3307 if (method
.vendor
== EAP_VENDOR_IETF
&&
3308 method
.method
== EAP_TYPE_NONE
) {
3309 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3310 "for a credential", line
, value
);
3313 os_free(cred
->eap_method
);
3314 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3315 if (cred
->eap_method
== NULL
)
3317 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3321 if (os_strcmp(var
, "password") == 0 &&
3322 os_strncmp(value
, "ext:", 4) == 0) {
3323 if (has_newline(value
))
3325 str_clear_free(cred
->password
);
3326 cred
->password
= os_strdup(value
);
3327 cred
->ext_password
= 1;
3331 if (os_strcmp(var
, "update_identifier") == 0) {
3332 cred
->update_identifier
= atoi(value
);
3336 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3337 cred
->min_dl_bandwidth_home
= atoi(value
);
3341 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3342 cred
->min_ul_bandwidth_home
= atoi(value
);
3346 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3347 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3351 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3352 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3356 if (os_strcmp(var
, "max_bss_load") == 0) {
3357 cred
->max_bss_load
= atoi(value
);
3361 if (os_strcmp(var
, "req_conn_capab") == 0)
3362 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3364 if (os_strcmp(var
, "ocsp") == 0) {
3365 cred
->ocsp
= atoi(value
);
3369 if (os_strcmp(var
, "sim_num") == 0) {
3370 cred
->sim_num
= atoi(value
);
3374 val
= wpa_config_parse_string(value
, &len
);
3376 (os_strcmp(var
, "excluded_ssid") != 0 &&
3377 os_strcmp(var
, "roaming_consortium") != 0 &&
3378 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3379 has_newline(val
))) {
3380 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3381 "value '%s'.", line
, var
, value
);
3386 if (os_strcmp(var
, "realm") == 0) {
3387 os_free(cred
->realm
);
3392 if (os_strcmp(var
, "username") == 0) {
3393 str_clear_free(cred
->username
);
3394 cred
->username
= val
;
3398 if (os_strcmp(var
, "password") == 0) {
3399 str_clear_free(cred
->password
);
3400 cred
->password
= val
;
3401 cred
->ext_password
= 0;
3405 if (os_strcmp(var
, "ca_cert") == 0) {
3406 os_free(cred
->ca_cert
);
3407 cred
->ca_cert
= val
;
3411 if (os_strcmp(var
, "client_cert") == 0) {
3412 os_free(cred
->client_cert
);
3413 cred
->client_cert
= val
;
3417 if (os_strcmp(var
, "private_key") == 0) {
3418 os_free(cred
->private_key
);
3419 cred
->private_key
= val
;
3423 if (os_strcmp(var
, "private_key_passwd") == 0) {
3424 str_clear_free(cred
->private_key_passwd
);
3425 cred
->private_key_passwd
= val
;
3429 if (os_strcmp(var
, "imsi") == 0) {
3430 os_free(cred
->imsi
);
3435 if (os_strcmp(var
, "milenage") == 0) {
3436 str_clear_free(cred
->milenage
);
3437 cred
->milenage
= val
;
3441 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3442 os_free(cred
->domain_suffix_match
);
3443 cred
->domain_suffix_match
= val
;
3447 if (os_strcmp(var
, "domain") == 0) {
3449 new_domain
= os_realloc_array(cred
->domain
,
3450 cred
->num_domain
+ 1,
3452 if (new_domain
== NULL
) {
3456 new_domain
[cred
->num_domain
++] = val
;
3457 cred
->domain
= new_domain
;
3461 if (os_strcmp(var
, "phase1") == 0) {
3462 os_free(cred
->phase1
);
3467 if (os_strcmp(var
, "phase2") == 0) {
3468 os_free(cred
->phase2
);
3473 if (os_strcmp(var
, "roaming_consortium") == 0) {
3474 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3475 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3476 "roaming_consortium length %d (3..15 "
3477 "expected)", line
, (int) len
);
3481 os_memcpy(cred
->roaming_consortium
, val
, len
);
3482 cred
->roaming_consortium_len
= len
;
3487 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3488 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3490 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3491 "required_roaming_consortium length %d "
3492 "(3..15 expected)", line
, (int) len
);
3496 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3497 cred
->required_roaming_consortium_len
= len
;
3502 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3503 res
= wpa_config_set_cred_roaming_consortiums(cred
, val
);
3505 wpa_printf(MSG_ERROR
,
3506 "Line %d: invalid roaming_consortiums",
3512 if (os_strcmp(var
, "excluded_ssid") == 0) {
3513 struct excluded_ssid
*e
;
3515 if (len
> SSID_MAX_LEN
) {
3516 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3517 "excluded_ssid length %d", line
, (int) len
);
3522 e
= os_realloc_array(cred
->excluded_ssid
,
3523 cred
->num_excluded_ssid
+ 1,
3524 sizeof(struct excluded_ssid
));
3529 cred
->excluded_ssid
= e
;
3531 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3532 os_memcpy(e
->ssid
, val
, len
);
3540 if (os_strcmp(var
, "roaming_partner") == 0) {
3541 struct roaming_partner
*p
;
3544 p
= os_realloc_array(cred
->roaming_partner
,
3545 cred
->num_roaming_partner
+ 1,
3546 sizeof(struct roaming_partner
));
3551 cred
->roaming_partner
= p
;
3553 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3555 pos
= os_strchr(val
, ',');
3561 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3565 os_memcpy(p
->fqdn
, val
, pos
- val
);
3567 p
->exact_match
= atoi(pos
);
3569 pos
= os_strchr(pos
, ',');
3576 p
->priority
= atoi(pos
);
3578 pos
= os_strchr(pos
, ',');
3585 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3589 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3591 cred
->num_roaming_partner
++;
3597 if (os_strcmp(var
, "provisioning_sp") == 0) {
3598 os_free(cred
->provisioning_sp
);
3599 cred
->provisioning_sp
= val
;
3604 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3614 static char * alloc_int_str(int val
)
3616 const unsigned int bufsize
= 20;
3620 buf
= os_malloc(bufsize
);
3623 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3624 if (os_snprintf_error(bufsize
, res
)) {
3632 static char * alloc_strdup(const char *str
)
3636 return os_strdup(str
);
3640 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3642 if (os_strcmp(var
, "temporary") == 0)
3643 return alloc_int_str(cred
->temporary
);
3645 if (os_strcmp(var
, "priority") == 0)
3646 return alloc_int_str(cred
->priority
);
3648 if (os_strcmp(var
, "sp_priority") == 0)
3649 return alloc_int_str(cred
->sp_priority
);
3651 if (os_strcmp(var
, "pcsc") == 0)
3652 return alloc_int_str(cred
->pcsc
);
3654 if (os_strcmp(var
, "eap") == 0) {
3655 if (!cred
->eap_method
)
3657 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3658 cred
->eap_method
[0].method
));
3661 if (os_strcmp(var
, "update_identifier") == 0)
3662 return alloc_int_str(cred
->update_identifier
);
3664 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3665 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3667 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3668 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3670 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3671 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3673 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3674 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3676 if (os_strcmp(var
, "max_bss_load") == 0)
3677 return alloc_int_str(cred
->max_bss_load
);
3679 if (os_strcmp(var
, "req_conn_capab") == 0) {
3681 char *buf
, *end
, *pos
;
3684 if (!cred
->num_req_conn_capab
)
3687 buf
= os_malloc(4000);
3692 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3695 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3697 cred
->req_conn_capab_proto
[i
]);
3698 if (os_snprintf_error(end
- pos
, ret
))
3702 ports
= cred
->req_conn_capab_port
[i
];
3705 for (j
= 0; ports
[j
] != -1; j
++) {
3706 ret
= os_snprintf(pos
, end
- pos
,
3710 if (os_snprintf_error(end
- pos
, ret
))
3720 if (os_strcmp(var
, "ocsp") == 0)
3721 return alloc_int_str(cred
->ocsp
);
3723 if (os_strcmp(var
, "realm") == 0)
3724 return alloc_strdup(cred
->realm
);
3726 if (os_strcmp(var
, "username") == 0)
3727 return alloc_strdup(cred
->username
);
3729 if (os_strcmp(var
, "password") == 0) {
3730 if (!cred
->password
)
3732 return alloc_strdup("*");
3735 if (os_strcmp(var
, "ca_cert") == 0)
3736 return alloc_strdup(cred
->ca_cert
);
3738 if (os_strcmp(var
, "client_cert") == 0)
3739 return alloc_strdup(cred
->client_cert
);
3741 if (os_strcmp(var
, "private_key") == 0)
3742 return alloc_strdup(cred
->private_key
);
3744 if (os_strcmp(var
, "private_key_passwd") == 0) {
3745 if (!cred
->private_key_passwd
)
3747 return alloc_strdup("*");
3750 if (os_strcmp(var
, "imsi") == 0)
3751 return alloc_strdup(cred
->imsi
);
3753 if (os_strcmp(var
, "milenage") == 0) {
3754 if (!(cred
->milenage
))
3756 return alloc_strdup("*");
3759 if (os_strcmp(var
, "domain_suffix_match") == 0)
3760 return alloc_strdup(cred
->domain_suffix_match
);
3762 if (os_strcmp(var
, "domain") == 0) {
3764 char *buf
, *end
, *pos
;
3767 if (!cred
->num_domain
)
3770 buf
= os_malloc(4000);
3776 for (i
= 0; i
< cred
->num_domain
; i
++) {
3777 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3778 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3779 if (os_snprintf_error(end
- pos
, ret
))
3787 if (os_strcmp(var
, "phase1") == 0)
3788 return alloc_strdup(cred
->phase1
);
3790 if (os_strcmp(var
, "phase2") == 0)
3791 return alloc_strdup(cred
->phase2
);
3793 if (os_strcmp(var
, "roaming_consortium") == 0) {
3797 if (!cred
->roaming_consortium_len
)
3799 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3800 buf
= os_malloc(buflen
);
3803 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3804 cred
->roaming_consortium_len
);
3808 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3812 if (!cred
->required_roaming_consortium_len
)
3814 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3815 buf
= os_malloc(buflen
);
3818 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
3819 cred
->required_roaming_consortium_len
);
3823 if (os_strcmp(var
, "roaming_consortiums") == 0) {
3828 if (!cred
->num_roaming_consortiums
)
3830 buflen
= cred
->num_roaming_consortiums
*
3831 MAX_ROAMING_CONS_OI_LEN
* 2 + 1;
3832 buf
= os_malloc(buflen
);
3836 for (i
= 0; i
< cred
->num_roaming_consortiums
; i
++) {
3839 pos
+= wpa_snprintf_hex(
3840 pos
, buf
+ buflen
- pos
,
3841 cred
->roaming_consortiums
[i
],
3842 cred
->roaming_consortiums_len
[i
]);
3848 if (os_strcmp(var
, "excluded_ssid") == 0) {
3850 char *buf
, *end
, *pos
;
3852 if (!cred
->num_excluded_ssid
)
3855 buf
= os_malloc(4000);
3861 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
3862 struct excluded_ssid
*e
;
3865 e
= &cred
->excluded_ssid
[i
];
3866 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3868 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
3869 if (os_snprintf_error(end
- pos
, ret
))
3877 if (os_strcmp(var
, "roaming_partner") == 0) {
3879 char *buf
, *end
, *pos
;
3881 if (!cred
->num_roaming_partner
)
3884 buf
= os_malloc(4000);
3890 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
3891 struct roaming_partner
*p
;
3894 p
= &cred
->roaming_partner
[i
];
3895 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
3897 p
->fqdn
, p
->exact_match
, p
->priority
,
3899 if (os_snprintf_error(end
- pos
, ret
))
3907 if (os_strcmp(var
, "provisioning_sp") == 0)
3908 return alloc_strdup(cred
->provisioning_sp
);
3914 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
3916 struct wpa_cred
*cred
;
3918 cred
= config
->cred
;
3929 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
3932 struct wpa_cred
*cred
, *last
= NULL
;
3935 cred
= config
->cred
;
3944 cred
= os_zalloc(sizeof(*cred
));
3948 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
3952 config
->cred
= cred
;
3958 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
3960 struct wpa_cred
*cred
, *prev
= NULL
;
3962 cred
= config
->cred
;
3974 prev
->next
= cred
->next
;
3976 config
->cred
= cred
->next
;
3978 wpa_config_free_cred(cred
);
3983 #ifndef CONFIG_NO_CONFIG_BLOBS
3985 * wpa_config_get_blob - Get a named configuration blob
3986 * @config: Configuration data from wpa_config_read()
3987 * @name: Name of the blob
3988 * Returns: Pointer to blob data or %NULL if not found
3990 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
3993 struct wpa_config_blob
*blob
= config
->blobs
;
3996 if (os_strcmp(blob
->name
, name
) == 0)
4005 * wpa_config_set_blob - Set or add a named configuration blob
4006 * @config: Configuration data from wpa_config_read()
4007 * @blob: New value for the blob
4009 * Adds a new configuration blob or replaces the current value of an existing
4012 void wpa_config_set_blob(struct wpa_config
*config
,
4013 struct wpa_config_blob
*blob
)
4015 wpa_config_remove_blob(config
, blob
->name
);
4016 blob
->next
= config
->blobs
;
4017 config
->blobs
= blob
;
4022 * wpa_config_free_blob - Free blob data
4023 * @blob: Pointer to blob to be freed
4025 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
4028 os_free(blob
->name
);
4029 bin_clear_free(blob
->data
, blob
->len
);
4036 * wpa_config_remove_blob - Remove a named configuration blob
4037 * @config: Configuration data from wpa_config_read()
4038 * @name: Name of the blob to remove
4039 * Returns: 0 if blob was removed or -1 if blob was not found
4041 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
4043 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
4046 if (os_strcmp(pos
->name
, name
) == 0) {
4048 prev
->next
= pos
->next
;
4050 config
->blobs
= pos
->next
;
4051 wpa_config_free_blob(pos
);
4060 #endif /* CONFIG_NO_CONFIG_BLOBS */
4064 * wpa_config_alloc_empty - Allocate an empty configuration
4065 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
4067 * @driver_param: Driver parameters
4068 * Returns: Pointer to allocated configuration data or %NULL on failure
4070 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
4071 const char *driver_param
)
4073 struct wpa_config
*config
;
4074 const int aCWmin
= 4, aCWmax
= 10;
4075 const struct hostapd_wmm_ac_params ac_bk
=
4076 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
4077 const struct hostapd_wmm_ac_params ac_be
=
4078 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
4079 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
4080 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
4081 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
4082 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
4084 config
= os_zalloc(sizeof(*config
));
4087 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
4088 config
->ap_scan
= DEFAULT_AP_SCAN
;
4089 config
->user_mpm
= DEFAULT_USER_MPM
;
4090 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
4091 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
4092 config
->dot11RSNASAERetransPeriod
=
4093 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
4094 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
4095 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
4096 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
4097 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
4098 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
4099 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
4100 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
4101 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
4102 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
4103 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
4104 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
4105 config
->ap_isolate
= DEFAULT_AP_ISOLATE
;
4106 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
4107 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
4108 config
->wmm_ac_params
[0] = ac_be
;
4109 config
->wmm_ac_params
[1] = ac_bk
;
4110 config
->wmm_ac_params
[2] = ac_vi
;
4111 config
->wmm_ac_params
[3] = ac_vo
;
4112 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
4113 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4114 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
4115 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
4116 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
4119 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
4120 config
->disassoc_imminent_rssi_threshold
=
4121 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
4122 config
->oce
= DEFAULT_OCE_SUPPORT
;
4123 #endif /* CONFIG_MBO */
4126 config
->ctrl_interface
= os_strdup(ctrl_interface
);
4128 config
->driver_param
= os_strdup(driver_param
);
4129 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
4135 #ifndef CONFIG_NO_STDOUT_DEBUG
4137 * wpa_config_debug_dump_networks - Debug dump of configured networks
4138 * @config: Configuration data from wpa_config_read()
4140 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
4143 struct wpa_ssid
*ssid
;
4145 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
4146 ssid
= config
->pssid
[prio
];
4147 wpa_printf(MSG_DEBUG
, "Priority group %d",
4150 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
4152 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
4157 #endif /* CONFIG_NO_STDOUT_DEBUG */
4160 struct global_parse_data
{
4162 int (*parser
)(const struct global_parse_data
*data
,
4163 struct wpa_config
*config
, int line
, const char *value
);
4164 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
4165 char *buf
, size_t buflen
, int pretty_print
);
4166 void *param1
, *param2
, *param3
;
4167 unsigned int changed_flag
;
4171 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
4172 struct wpa_config
*config
, int line
,
4178 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
4179 val
= strtol(pos
, &end
, 0);
4181 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
4187 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
4189 if (data
->param2
&& *dst
< (long) data
->param2
) {
4190 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
4191 "min_value=%ld)", line
, data
->name
, *dst
,
4192 (long) data
->param2
);
4193 *dst
= (long) data
->param2
;
4197 if (data
->param3
&& *dst
> (long) data
->param3
) {
4198 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
4199 "max_value=%ld)", line
, data
->name
, *dst
,
4200 (long) data
->param3
);
4201 *dst
= (long) data
->param3
;
4209 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
4210 struct wpa_config
*config
, int line
,
4216 len
= os_strlen(pos
);
4217 if (data
->param2
&& len
< (size_t) data
->param2
) {
4218 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
4219 "min_len=%ld)", line
, data
->name
,
4220 (unsigned long) len
, (long) data
->param2
);
4224 if (data
->param3
&& len
> (size_t) data
->param3
) {
4225 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
4226 "max_len=%ld)", line
, data
->name
,
4227 (unsigned long) len
, (long) data
->param3
);
4231 if (has_newline(pos
)) {
4232 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
4237 tmp
= os_strdup(pos
);
4241 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
4244 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
4250 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
4251 struct wpa_config
*config
, int line
,
4258 tmp
= wpa_config_parse_string(pos
, &len
);
4260 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
4265 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
4271 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
4272 struct wpa_config
*config
, int line
,
4275 struct wpabuf
**dst
, *tmp
;
4277 tmp
= wpabuf_parse_bin(pos
);
4281 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
4284 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
4290 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
4291 struct wpa_config
*config
, int line
,
4296 freqs
= wpa_config_parse_int_array(value
);
4299 if (freqs
[0] == 0) {
4303 os_free(config
->freq_list
);
4304 config
->freq_list
= freqs
;
4310 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
4311 struct wpa_config
*config
, int line
,
4315 struct hostapd_ip_addr addr
;
4317 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
4319 if (addr
.af
!= AF_INET
)
4322 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
4323 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4324 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4325 WPA_GET_BE32((u8
*) dst
));
4329 #endif /* CONFIG_P2P */
4332 static int wpa_config_process_country(const struct global_parse_data
*data
,
4333 struct wpa_config
*config
, int line
,
4336 if (!pos
[0] || !pos
[1]) {
4337 wpa_printf(MSG_DEBUG
, "Invalid country set");
4340 config
->country
[0] = pos
[0];
4341 config
->country
[1] = pos
[1];
4342 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4343 config
->country
[0], config
->country
[1]);
4348 static int wpa_config_process_load_dynamic_eap(
4349 const struct global_parse_data
*data
, struct wpa_config
*config
,
4350 int line
, const char *so
)
4353 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4354 ret
= eap_peer_method_load(so
);
4356 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4359 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4360 "method '%s'.", line
, so
);
4370 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4371 struct wpa_config
*config
, int line
,
4375 if (uuid_str2bin(pos
, config
->uuid
)) {
4376 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4379 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4380 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4385 static int wpa_config_process_device_type(
4386 const struct global_parse_data
*data
,
4387 struct wpa_config
*config
, int line
, const char *pos
)
4389 return wps_dev_type_str2bin(pos
, config
->device_type
);
4393 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4394 struct wpa_config
*config
, int line
,
4397 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4398 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4401 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4402 WPA_GET_BE32(config
->os_version
));
4407 static int wpa_config_process_wps_vendor_ext_m1(
4408 const struct global_parse_data
*data
,
4409 struct wpa_config
*config
, int line
, const char *pos
)
4412 int len
= os_strlen(pos
) / 2;
4416 wpa_printf(MSG_ERROR
, "Line %d: "
4417 "invalid wps_vendor_ext_m1", line
);
4421 tmp
= wpabuf_alloc(len
);
4423 p
= wpabuf_put(tmp
, len
);
4425 if (hexstr2bin(pos
, p
, len
)) {
4426 wpa_printf(MSG_ERROR
, "Line %d: "
4427 "invalid wps_vendor_ext_m1", line
);
4432 wpabuf_free(config
->wps_vendor_ext_m1
);
4433 config
->wps_vendor_ext_m1
= tmp
;
4435 wpa_printf(MSG_ERROR
, "Can not allocate "
4436 "memory for wps_vendor_ext_m1");
4443 #endif /* CONFIG_WPS */
4446 static int wpa_config_process_sec_device_type(
4447 const struct global_parse_data
*data
,
4448 struct wpa_config
*config
, int line
, const char *pos
)
4452 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4453 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4458 idx
= config
->num_sec_device_types
;
4460 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4463 config
->num_sec_device_types
++;
4468 static int wpa_config_process_p2p_pref_chan(
4469 const struct global_parse_data
*data
,
4470 struct wpa_config
*config
, int line
, const char *pos
)
4472 struct p2p_channel
*pref
= NULL
, *n
;
4473 unsigned int num
= 0;
4477 /* format: class:chan,class:chan,... */
4480 op_class
= atoi(pos
);
4481 pos2
= os_strchr(pos
, ':');
4487 n
= os_realloc_array(pref
, num
+ 1,
4488 sizeof(struct p2p_channel
));
4492 pref
[num
].op_class
= op_class
;
4493 pref
[num
].chan
= chan
;
4496 pos
= os_strchr(pos2
, ',');
4502 os_free(config
->p2p_pref_chan
);
4503 config
->p2p_pref_chan
= pref
;
4504 config
->num_p2p_pref_chan
= num
;
4505 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4506 (u8
*) config
->p2p_pref_chan
,
4507 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4513 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4518 static int wpa_config_process_p2p_no_go_freq(
4519 const struct global_parse_data
*data
,
4520 struct wpa_config
*config
, int line
, const char *pos
)
4524 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4526 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4530 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4531 config
->p2p_no_go_freq
.num
);
4537 static int wpa_config_process_p2p_device_persistent_mac_addr(
4538 const struct global_parse_data
*data
,
4539 struct wpa_config
*config
, int line
, const char *pos
)
4541 if (hwaddr_aton2(pos
, config
->p2p_device_persistent_mac_addr
) < 0) {
4542 wpa_printf(MSG_ERROR
,
4543 "Line %d: Invalid p2p_device_persistent_mac_addr '%s'",
4551 #endif /* CONFIG_P2P */
4554 static int wpa_config_process_hessid(
4555 const struct global_parse_data
*data
,
4556 struct wpa_config
*config
, int line
, const char *pos
)
4558 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4559 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4568 static int wpa_config_process_sae_groups(
4569 const struct global_parse_data
*data
,
4570 struct wpa_config
*config
, int line
, const char *pos
)
4572 int *groups
= wpa_config_parse_int_array(pos
);
4573 if (groups
== NULL
) {
4574 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4579 os_free(config
->sae_groups
);
4580 config
->sae_groups
= groups
;
4586 static int wpa_config_process_ap_vendor_elements(
4587 const struct global_parse_data
*data
,
4588 struct wpa_config
*config
, int line
, const char *pos
)
4591 int len
= os_strlen(pos
) / 2;
4595 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4600 tmp
= wpabuf_alloc(len
);
4602 p
= wpabuf_put(tmp
, len
);
4604 if (hexstr2bin(pos
, p
, len
)) {
4605 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4606 "ap_vendor_elements", line
);
4611 wpabuf_free(config
->ap_vendor_elements
);
4612 config
->ap_vendor_elements
= tmp
;
4614 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4615 "ap_vendor_elements");
4623 #ifdef CONFIG_CTRL_IFACE
4624 static int wpa_config_process_no_ctrl_interface(
4625 const struct global_parse_data
*data
,
4626 struct wpa_config
*config
, int line
, const char *pos
)
4628 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4629 os_free(config
->ctrl_interface
);
4630 config
->ctrl_interface
= NULL
;
4633 #endif /* CONFIG_CTRL_IFACE */
4636 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4637 long offset
, char *buf
, size_t buflen
,
4640 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4643 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4644 return os_snprintf(buf
, buflen
, "%d", *val
);
4648 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4649 long offset
, char *buf
, size_t buflen
,
4652 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4656 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4657 *val
? *val
: "null");
4661 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4662 if (os_snprintf_error(buflen
, res
))
4670 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4671 long offset
, char *buf
, size_t buflen
,
4674 void *val
= ((u8
*) config
) + (long) offset
;
4676 char addr
[INET_ADDRSTRLEN
];
4678 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4682 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4684 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4686 if (os_snprintf_error(buflen
, res
))
4691 #endif /* CONFIG_P2P */
4697 /* OFFSET: Get offset of a variable within the wpa_config structure */
4698 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4700 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4701 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4702 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4703 #define INT(f) _INT(f), NULL, NULL
4704 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4705 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4706 #define STR(f) _STR(f), NULL, NULL
4707 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4708 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4709 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4710 OFFSET(f), NULL, NULL
4712 static const struct global_parse_data global_fields
[] = {
4713 #ifdef CONFIG_CTRL_IFACE
4714 { STR(ctrl_interface
), 0 },
4715 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4716 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4717 #endif /* CONFIG_CTRL_IFACE */
4718 #ifdef CONFIG_MACSEC
4719 { INT_RANGE(eapol_version
, 1, 3), 0 },
4720 #else /* CONFIG_MACSEC */
4721 { INT_RANGE(eapol_version
, 1, 2), 0 },
4722 #endif /* CONFIG_MACSEC */
4723 { INT(ap_scan
), 0 },
4724 { FUNC(bgscan
), 0 },
4726 { INT(user_mpm
), 0 },
4727 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4728 { INT(mesh_max_inactivity
), 0 },
4729 { INT(dot11RSNASAERetransPeriod
), 0 },
4730 #endif /* CONFIG_MESH */
4731 { INT(disable_scan_offload
), 0 },
4732 { INT(fast_reauth
), 0 },
4733 { STR(opensc_engine_path
), 0 },
4734 { STR(pkcs11_engine_path
), 0 },
4735 { STR(pkcs11_module_path
), 0 },
4736 { STR(openssl_ciphers
), 0 },
4737 { STR(pcsc_reader
), 0 },
4738 { STR(pcsc_pin
), 0 },
4739 { INT(external_sim
), 0 },
4740 { STR(driver_param
), 0 },
4741 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4742 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4743 { INT(dot11RSNAConfigSATimeout
), 0 },
4744 #ifndef CONFIG_NO_CONFIG_WRITE
4745 { INT(update_config
), 0 },
4746 #endif /* CONFIG_NO_CONFIG_WRITE */
4747 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4749 { FUNC(uuid
), CFG_CHANGED_UUID
},
4750 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4751 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4752 CFG_CHANGED_DEVICE_NAME
},
4753 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4754 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4755 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4756 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4757 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4758 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4759 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4760 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4761 { INT_RANGE(wps_cred_add_sae
, 0, 1), 0 },
4762 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4763 #endif /* CONFIG_WPS */
4765 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4766 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4767 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4768 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4769 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4770 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4771 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4772 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4773 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4774 { INT(p2p_group_idle
), 0 },
4775 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4776 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4777 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4778 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4779 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4780 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4781 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4782 { INT(p2p_go_ht40
), 0 },
4783 { INT(p2p_go_vht
), 0 },
4784 { INT(p2p_go_he
), 0 },
4785 { INT(p2p_disabled
), 0 },
4786 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4787 { INT(p2p_no_group_iface
), 0 },
4788 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4789 { IPV4(ip_addr_go
), 0 },
4790 { IPV4(ip_addr_mask
), 0 },
4791 { IPV4(ip_addr_start
), 0 },
4792 { IPV4(ip_addr_end
), 0 },
4793 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4794 { INT(p2p_device_random_mac_addr
), 0 },
4795 { FUNC(p2p_device_persistent_mac_addr
), 0 },
4796 { INT(p2p_interface_random_mac_addr
), 0 },
4797 #endif /* CONFIG_P2P */
4798 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4799 { INT(bss_max_count
), 0 },
4800 { INT(bss_expiration_age
), 0 },
4801 { INT(bss_expiration_scan_count
), 0 },
4802 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4803 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4804 { INT(max_num_sta
), 0 },
4805 { INT_RANGE(ap_isolate
, 0, 1), 0 },
4806 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4808 { INT_RANGE(hs20
, 0, 1), 0 },
4809 #endif /* CONFIG_HS20 */
4810 { INT_RANGE(interworking
, 0, 1), 0 },
4811 { FUNC(hessid
), 0 },
4812 { INT_RANGE(access_network_type
, 0, 15), 0 },
4813 { INT_RANGE(go_interworking
, 0, 1), 0 },
4814 { INT_RANGE(go_access_network_type
, 0, 15), 0 },
4815 { INT_RANGE(go_internet
, 0, 1), 0 },
4816 { INT_RANGE(go_venue_group
, 0, 255), 0 },
4817 { INT_RANGE(go_venue_type
, 0, 255), 0 },
4818 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
4819 { STR(autoscan
), 0 },
4820 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
4821 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4822 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4823 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4824 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4825 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
4826 { INT(p2p_go_max_inactivity
), 0 },
4827 { INT_RANGE(auto_interworking
, 0, 1), 0 },
4830 { FUNC(sae_groups
), 0 },
4831 { INT_RANGE(sae_pmkid_in_assoc
, 0, 1), 0 },
4832 { INT(dtim_period
), 0 },
4833 { INT(beacon_int
), 0 },
4834 { FUNC(ap_vendor_elements
), 0 },
4835 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
4836 { FUNC(freq_list
), 0 },
4837 { INT(scan_cur_freq
), 0 },
4838 { INT(sched_scan_interval
), 0 },
4839 { INT(sched_scan_start_delay
), 0 },
4840 { INT(tdls_external_control
), 0},
4841 { STR(osu_dir
), 0 },
4842 { STR(wowlan_triggers
), CFG_CHANGED_WOWLAN_TRIGGERS
},
4843 { INT(p2p_search_delay
), 0},
4844 { INT(mac_addr
), 0 },
4845 { INT(rand_addr_lifetime
), 0 },
4846 { INT(preassoc_mac_addr
), 0 },
4847 { INT(key_mgmt_offload
), 0},
4848 { INT(passive_scan
), 0 },
4849 { INT(reassoc_same_bss_optim
), 0 },
4850 { INT(wps_priority
), 0},
4852 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
4853 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
4854 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
4855 #endif /* CONFIG_FST */
4856 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
4857 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
4858 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
4860 { STR(non_pref_chan
), 0 },
4861 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
4862 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
4863 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
4864 { INT_RANGE(oce
, 0, 3), 0 },
4865 #endif /* CONFIG_MBO */
4866 { INT(gas_address3
), 0 },
4867 { INT_RANGE(ftm_responder
, 0, 1), 0 },
4868 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
4869 { INT(gas_rand_addr_lifetime
), 0 },
4870 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
4871 { INT_RANGE(dpp_config_processing
, 0, 2), 0 },
4872 { INT_RANGE(coloc_intf_reporting
, 0, 1), 0 },
4874 { INT_RANGE(disable_btm
, 0, 1), CFG_CHANGED_DISABLE_BTM
},
4875 #endif /* CONFIG_WNM */
4887 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4890 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
4895 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4896 const struct global_parse_data
*field
= &global_fields
[i
];
4902 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
4914 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
4915 char *buf
, size_t buflen
)
4919 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4920 const struct global_parse_data
*field
= &global_fields
[i
];
4922 if (os_strcmp(name
, field
->name
) != 0)
4926 return field
->get(name
, config
, (long) field
->param1
,
4934 int wpa_config_get_num_global_field_names(void)
4936 return NUM_GLOBAL_FIELDS
;
4940 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
4942 if (i
>= NUM_GLOBAL_FIELDS
)
4946 *no_var
= !global_fields
[i
].param1
;
4947 return global_fields
[i
].name
;
4951 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
4956 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4957 const struct global_parse_data
*field
= &global_fields
[i
];
4958 size_t flen
= os_strlen(field
->name
);
4959 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
4963 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
4964 wpa_printf(MSG_ERROR
, "Line %d: failed to "
4965 "parse '%s'.", line
, pos
);
4968 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
4969 config
->wps_nfc_pw_from_config
= 1;
4970 config
->changed_parameters
|= field
->changed_flag
;
4973 if (i
== NUM_GLOBAL_FIELDS
) {
4975 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
4976 char *tmp
= os_strchr(pos
, '=');
4980 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
4985 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
4987 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
4992 #endif /* CONFIG_AP */
4995 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",