2 * WPA Supplicant / Configuration parser and common functions
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/uuid.h"
13 #include "utils/ip_addr.h"
14 #include "common/ieee802_1x_defs.h"
15 #include "crypto/sha1.h"
16 #include "rsn_supp/wpa.h"
17 #include "eap_peer/eap.h"
23 #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
24 #define NO_CONFIG_WRITE
28 * Structure for network configuration parsing. This data is used to implement
29 * a generic parser for each network block variable. The table of configuration
30 * variables is defined below in this file (ssid_fields[]).
33 /* Configuration variable name */
36 /* Parser function for this variable. The parser functions return 0 or 1
37 * to indicate success. Value 0 indicates that the parameter value may
38 * have changed while value 1 means that the value did not change.
39 * Error cases (failure to parse the string) are indicated by returning
41 int (*parser
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
,
42 int line
, const char *value
);
44 #ifndef NO_CONFIG_WRITE
45 /* Writer function (i.e., to get the variable in text format from
46 * internal presentation). */
47 char * (*writer
)(const struct parse_data
*data
, struct wpa_ssid
*ssid
);
48 #endif /* NO_CONFIG_WRITE */
50 /* Variable specific parameters for the parser. */
51 void *param1
, *param2
, *param3
, *param4
;
53 /* 0 = this variable can be included in debug output and ctrl_iface
54 * 1 = this variable contains key/private data and it must not be
55 * included in debug output unless explicitly requested. In
56 * addition, this variable will not be readable through the
63 static int wpa_config_parse_str(const struct parse_data
*data
,
64 struct wpa_ssid
*ssid
,
65 int line
, const char *value
)
67 size_t res_len
, *dst_len
, prev_len
;
70 if (os_strcmp(value
, "NULL") == 0) {
71 wpa_printf(MSG_DEBUG
, "Unset configuration string '%s'",
78 tmp
= wpa_config_parse_string(value
, &res_len
);
80 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s '%s'.",
82 data
->key_data
? "[KEY DATA REMOVED]" : value
);
87 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
90 wpa_hexdump_ascii(MSG_MSGDUMP
, data
->name
,
94 if (data
->param3
&& res_len
< (size_t) data
->param3
) {
95 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
96 "min_len=%ld)", line
, data
->name
,
97 (unsigned long) res_len
, (long) data
->param3
);
102 if (data
->param4
&& res_len
> (size_t) data
->param4
) {
103 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
104 "max_len=%ld)", line
, data
->name
,
105 (unsigned long) res_len
, (long) data
->param4
);
111 dst
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
112 dst_len
= (size_t *) (((u8
*) ssid
) + (long) data
->param2
);
117 prev_len
= os_strlen(*dst
);
120 if ((*dst
== NULL
&& tmp
== NULL
) ||
121 (*dst
&& tmp
&& prev_len
== res_len
&&
122 os_memcmp(*dst
, tmp
, res_len
) == 0)) {
123 /* No change to the previously configured value */
137 #ifndef NO_CONFIG_WRITE
138 static char * wpa_config_write_string_ascii(const u8
*value
, size_t len
)
142 buf
= os_malloc(len
+ 3);
146 os_memcpy(buf
+ 1, value
, len
);
154 static char * wpa_config_write_string_hex(const u8
*value
, size_t len
)
158 buf
= os_zalloc(2 * len
+ 1);
161 wpa_snprintf_hex(buf
, 2 * len
+ 1, value
, len
);
167 static char * wpa_config_write_string(const u8
*value
, size_t len
)
172 if (is_hex(value
, len
))
173 return wpa_config_write_string_hex(value
, len
);
175 return wpa_config_write_string_ascii(value
, len
);
179 static char * wpa_config_write_str(const struct parse_data
*data
,
180 struct wpa_ssid
*ssid
)
185 src
= (char **) (((u8
*) ssid
) + (long) data
->param1
);
190 len
= *((size_t *) (((u8
*) ssid
) + (long) data
->param2
));
192 len
= os_strlen(*src
);
194 return wpa_config_write_string((const u8
*) *src
, len
);
196 #endif /* NO_CONFIG_WRITE */
199 static int wpa_config_parse_int(const struct parse_data
*data
,
200 struct wpa_ssid
*ssid
,
201 int line
, const char *value
)
206 dst
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
207 val
= strtol(value
, &end
, 0);
209 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
217 wpa_printf(MSG_MSGDUMP
, "%s=%d (0x%x)", data
->name
, *dst
, *dst
);
219 if (data
->param3
&& *dst
< (long) data
->param3
) {
220 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
221 "min_value=%ld)", line
, data
->name
, *dst
,
222 (long) data
->param3
);
223 *dst
= (long) data
->param3
;
227 if (data
->param4
&& *dst
> (long) data
->param4
) {
228 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
229 "max_value=%ld)", line
, data
->name
, *dst
,
230 (long) data
->param4
);
231 *dst
= (long) data
->param4
;
239 #ifndef NO_CONFIG_WRITE
240 static char * wpa_config_write_int(const struct parse_data
*data
,
241 struct wpa_ssid
*ssid
)
246 src
= (int *) (((u8
*) ssid
) + (long) data
->param1
);
248 value
= os_malloc(20);
251 res
= os_snprintf(value
, 20, "%d", *src
);
252 if (os_snprintf_error(20, res
)) {
256 value
[20 - 1] = '\0';
259 #endif /* NO_CONFIG_WRITE */
262 static int wpa_config_parse_addr_list(const struct parse_data
*data
,
263 int line
, const char *value
,
264 u8
**list
, size_t *num
, char *name
,
265 u8 abort_on_error
, u8 masked
)
268 u8
*buf
, *n
, addr
[2 * ETH_ALEN
];
275 while (pos
&& *pos
) {
279 if (hwaddr_masked_aton(pos
, addr
, &addr
[ETH_ALEN
], masked
)) {
280 if (abort_on_error
|| count
== 0) {
281 wpa_printf(MSG_ERROR
,
282 "Line %d: Invalid %s address '%s'",
287 /* continue anyway since this could have been from a
288 * truncated configuration file line */
290 "Line %d: Ignore likely truncated %s address '%s'",
293 n
= os_realloc_array(buf
, count
+ 1, 2 * ETH_ALEN
);
299 os_memmove(buf
+ 2 * ETH_ALEN
, buf
,
300 count
* 2 * ETH_ALEN
);
301 os_memcpy(buf
, addr
, 2 * ETH_ALEN
);
303 wpa_printf(MSG_MSGDUMP
,
304 "%s: addr=" MACSTR
" mask=" MACSTR
,
306 MAC2STR(&addr
[ETH_ALEN
]));
309 pos
= os_strchr(pos
, ' ');
320 #ifndef NO_CONFIG_WRITE
321 static char * wpa_config_write_addr_list(const struct parse_data
*data
,
322 const u8
*list
, size_t num
, char *name
)
324 char *value
, *end
, *pos
;
328 if (list
== NULL
|| num
== 0)
331 value
= os_malloc(2 * 20 * num
);
335 end
= value
+ 2 * 20 * num
;
337 for (i
= num
; i
> 0; i
--) {
338 const u8
*a
= list
+ (i
- 1) * 2 * ETH_ALEN
;
339 const u8
*m
= a
+ ETH_ALEN
;
343 res
= hwaddr_mask_txt(pos
, end
- pos
, a
, m
);
353 #endif /* NO_CONFIG_WRITE */
355 static int wpa_config_parse_bssid(const struct parse_data
*data
,
356 struct wpa_ssid
*ssid
, int line
,
359 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
360 os_strcmp(value
, "any") == 0) {
362 wpa_printf(MSG_MSGDUMP
, "BSSID any");
365 if (hwaddr_aton(value
, ssid
->bssid
)) {
366 wpa_printf(MSG_ERROR
, "Line %d: Invalid BSSID '%s'.",
371 wpa_hexdump(MSG_MSGDUMP
, "BSSID", ssid
->bssid
, ETH_ALEN
);
376 #ifndef NO_CONFIG_WRITE
377 static char * wpa_config_write_bssid(const struct parse_data
*data
,
378 struct wpa_ssid
*ssid
)
383 if (!ssid
->bssid_set
)
386 value
= os_malloc(20);
389 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->bssid
));
390 if (os_snprintf_error(20, res
)) {
394 value
[20 - 1] = '\0';
397 #endif /* NO_CONFIG_WRITE */
400 static int wpa_config_parse_bssid_blacklist(const struct parse_data
*data
,
401 struct wpa_ssid
*ssid
, int line
,
404 return wpa_config_parse_addr_list(data
, line
, value
,
405 &ssid
->bssid_blacklist
,
406 &ssid
->num_bssid_blacklist
,
407 "bssid_blacklist", 1, 1);
411 #ifndef NO_CONFIG_WRITE
412 static char * wpa_config_write_bssid_blacklist(const struct parse_data
*data
,
413 struct wpa_ssid
*ssid
)
415 return wpa_config_write_addr_list(data
, ssid
->bssid_blacklist
,
416 ssid
->num_bssid_blacklist
,
419 #endif /* NO_CONFIG_WRITE */
422 static int wpa_config_parse_bssid_whitelist(const struct parse_data
*data
,
423 struct wpa_ssid
*ssid
, int line
,
426 return wpa_config_parse_addr_list(data
, line
, value
,
427 &ssid
->bssid_whitelist
,
428 &ssid
->num_bssid_whitelist
,
429 "bssid_whitelist", 1, 1);
433 #ifndef NO_CONFIG_WRITE
434 static char * wpa_config_write_bssid_whitelist(const struct parse_data
*data
,
435 struct wpa_ssid
*ssid
)
437 return wpa_config_write_addr_list(data
, ssid
->bssid_whitelist
,
438 ssid
->num_bssid_whitelist
,
441 #endif /* NO_CONFIG_WRITE */
444 static int wpa_config_parse_psk(const struct parse_data
*data
,
445 struct wpa_ssid
*ssid
, int line
,
448 #ifdef CONFIG_EXT_PASSWORD
449 if (os_strncmp(value
, "ext:", 4) == 0) {
450 str_clear_free(ssid
->passphrase
);
451 ssid
->passphrase
= NULL
;
453 os_free(ssid
->ext_psk
);
454 ssid
->ext_psk
= os_strdup(value
+ 4);
455 if (ssid
->ext_psk
== NULL
)
457 wpa_printf(MSG_DEBUG
, "PSK: External password '%s'",
461 #endif /* CONFIG_EXT_PASSWORD */
464 #ifndef CONFIG_NO_PBKDF2
469 pos
= os_strrchr(value
, '"');
473 len
= os_strlen(value
);
474 if (len
< 8 || len
> 63) {
475 wpa_printf(MSG_ERROR
, "Line %d: Invalid passphrase "
476 "length %lu (expected: 8..63) '%s'.",
477 line
, (unsigned long) len
, value
);
480 wpa_hexdump_ascii_key(MSG_MSGDUMP
, "PSK (ASCII passphrase)",
482 if (has_ctrl_char((u8
*) value
, len
)) {
483 wpa_printf(MSG_ERROR
,
484 "Line %d: Invalid passphrase character",
488 if (ssid
->passphrase
&& os_strlen(ssid
->passphrase
) == len
&&
489 os_memcmp(ssid
->passphrase
, value
, len
) == 0) {
490 /* No change to the previously configured value */
494 str_clear_free(ssid
->passphrase
);
495 ssid
->passphrase
= dup_binstr(value
, len
);
496 if (ssid
->passphrase
== NULL
)
499 #else /* CONFIG_NO_PBKDF2 */
500 wpa_printf(MSG_ERROR
, "Line %d: ASCII passphrase not "
503 #endif /* CONFIG_NO_PBKDF2 */
506 if (hexstr2bin(value
, ssid
->psk
, PMK_LEN
) ||
507 value
[PMK_LEN
* 2] != '\0') {
508 wpa_printf(MSG_ERROR
, "Line %d: Invalid PSK '%s'.",
513 str_clear_free(ssid
->passphrase
);
514 ssid
->passphrase
= NULL
;
517 wpa_hexdump_key(MSG_MSGDUMP
, "PSK", ssid
->psk
, PMK_LEN
);
522 #ifndef NO_CONFIG_WRITE
523 static char * wpa_config_write_psk(const struct parse_data
*data
,
524 struct wpa_ssid
*ssid
)
526 #ifdef CONFIG_EXT_PASSWORD
528 size_t len
= 4 + os_strlen(ssid
->ext_psk
) + 1;
529 char *buf
= os_malloc(len
);
534 res
= os_snprintf(buf
, len
, "ext:%s", ssid
->ext_psk
);
535 if (os_snprintf_error(len
, res
)) {
541 #endif /* CONFIG_EXT_PASSWORD */
543 if (ssid
->passphrase
)
544 return wpa_config_write_string_ascii(
545 (const u8
*) ssid
->passphrase
,
546 os_strlen(ssid
->passphrase
));
549 return wpa_config_write_string_hex(ssid
->psk
, PMK_LEN
);
553 #endif /* NO_CONFIG_WRITE */
556 static int wpa_config_parse_proto(const struct parse_data
*data
,
557 struct wpa_ssid
*ssid
, int line
,
560 int val
= 0, last
, errors
= 0;
561 char *start
, *end
, *buf
;
563 buf
= os_strdup(value
);
568 while (*start
!= '\0') {
569 while (*start
== ' ' || *start
== '\t')
574 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
578 if (os_strcmp(start
, "WPA") == 0)
579 val
|= WPA_PROTO_WPA
;
580 else if (os_strcmp(start
, "RSN") == 0 ||
581 os_strcmp(start
, "WPA2") == 0)
582 val
|= WPA_PROTO_RSN
;
583 else if (os_strcmp(start
, "OSEN") == 0)
584 val
|= WPA_PROTO_OSEN
;
586 wpa_printf(MSG_ERROR
, "Line %d: invalid proto '%s'",
598 wpa_printf(MSG_ERROR
,
599 "Line %d: no proto values configured.", line
);
603 if (!errors
&& ssid
->proto
== val
)
605 wpa_printf(MSG_MSGDUMP
, "proto: 0x%x", val
);
607 return errors
? -1 : 0;
611 #ifndef NO_CONFIG_WRITE
612 static char * wpa_config_write_proto(const struct parse_data
*data
,
613 struct wpa_ssid
*ssid
)
616 char *buf
, *pos
, *end
;
618 pos
= buf
= os_zalloc(20);
623 if (ssid
->proto
& WPA_PROTO_WPA
) {
624 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
625 pos
== buf
? "" : " ");
626 if (os_snprintf_error(end
- pos
, ret
))
631 if (ssid
->proto
& WPA_PROTO_RSN
) {
632 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
633 pos
== buf
? "" : " ");
634 if (os_snprintf_error(end
- pos
, ret
))
639 if (ssid
->proto
& WPA_PROTO_OSEN
) {
640 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
641 pos
== buf
? "" : " ");
642 if (os_snprintf_error(end
- pos
, ret
))
654 #endif /* NO_CONFIG_WRITE */
657 static int wpa_config_parse_key_mgmt(const struct parse_data
*data
,
658 struct wpa_ssid
*ssid
, int line
,
661 int val
= 0, last
, errors
= 0;
662 char *start
, *end
, *buf
;
664 buf
= os_strdup(value
);
669 while (*start
!= '\0') {
670 while (*start
== ' ' || *start
== '\t')
675 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
679 if (os_strcmp(start
, "WPA-PSK") == 0)
680 val
|= WPA_KEY_MGMT_PSK
;
681 else if (os_strcmp(start
, "WPA-EAP") == 0)
682 val
|= WPA_KEY_MGMT_IEEE8021X
;
683 else if (os_strcmp(start
, "IEEE8021X") == 0)
684 val
|= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
685 else if (os_strcmp(start
, "NONE") == 0)
686 val
|= WPA_KEY_MGMT_NONE
;
687 else if (os_strcmp(start
, "WPA-NONE") == 0)
688 val
|= WPA_KEY_MGMT_WPA_NONE
;
689 #ifdef CONFIG_IEEE80211R
690 else if (os_strcmp(start
, "FT-PSK") == 0)
691 val
|= WPA_KEY_MGMT_FT_PSK
;
692 else if (os_strcmp(start
, "FT-EAP") == 0)
693 val
|= WPA_KEY_MGMT_FT_IEEE8021X
;
694 #endif /* CONFIG_IEEE80211R */
695 #ifdef CONFIG_IEEE80211W
696 else if (os_strcmp(start
, "WPA-PSK-SHA256") == 0)
697 val
|= WPA_KEY_MGMT_PSK_SHA256
;
698 else if (os_strcmp(start
, "WPA-EAP-SHA256") == 0)
699 val
|= WPA_KEY_MGMT_IEEE8021X_SHA256
;
700 #endif /* CONFIG_IEEE80211W */
702 else if (os_strcmp(start
, "WPS") == 0)
703 val
|= WPA_KEY_MGMT_WPS
;
704 #endif /* CONFIG_WPS */
706 else if (os_strcmp(start
, "SAE") == 0)
707 val
|= WPA_KEY_MGMT_SAE
;
708 else if (os_strcmp(start
, "FT-SAE") == 0)
709 val
|= WPA_KEY_MGMT_FT_SAE
;
710 #endif /* CONFIG_SAE */
712 else if (os_strcmp(start
, "OSEN") == 0)
713 val
|= WPA_KEY_MGMT_OSEN
;
714 #endif /* CONFIG_HS20 */
716 else if (os_strcmp(start
, "WPA-EAP-SUITE-B") == 0)
717 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
718 #endif /* CONFIG_SUITEB */
719 #ifdef CONFIG_SUITEB192
720 else if (os_strcmp(start
, "WPA-EAP-SUITE-B-192") == 0)
721 val
|= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
722 #endif /* CONFIG_SUITEB192 */
724 else if (os_strcmp(start
, "FILS-SHA256") == 0)
725 val
|= WPA_KEY_MGMT_FILS_SHA256
;
726 else if (os_strcmp(start
, "FILS-SHA384") == 0)
727 val
|= WPA_KEY_MGMT_FILS_SHA384
;
728 #ifdef CONFIG_IEEE80211R
729 else if (os_strcmp(start
, "FT-FILS-SHA256") == 0)
730 val
|= WPA_KEY_MGMT_FT_FILS_SHA256
;
731 else if (os_strcmp(start
, "FT-FILS-SHA384") == 0)
732 val
|= WPA_KEY_MGMT_FT_FILS_SHA384
;
733 #endif /* CONFIG_IEEE80211R */
734 #endif /* CONFIG_FILS */
736 else if (os_strcmp(start
, "OWE") == 0)
737 val
|= WPA_KEY_MGMT_OWE
;
738 #endif /* CONFIG_OWE */
740 wpa_printf(MSG_ERROR
, "Line %d: invalid key_mgmt '%s'",
752 wpa_printf(MSG_ERROR
,
753 "Line %d: no key_mgmt values configured.", line
);
757 if (!errors
&& ssid
->key_mgmt
== val
)
759 wpa_printf(MSG_MSGDUMP
, "key_mgmt: 0x%x", val
);
760 ssid
->key_mgmt
= val
;
761 return errors
? -1 : 0;
765 #ifndef NO_CONFIG_WRITE
766 static char * wpa_config_write_key_mgmt(const struct parse_data
*data
,
767 struct wpa_ssid
*ssid
)
769 char *buf
, *pos
, *end
;
772 pos
= buf
= os_zalloc(100);
777 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
) {
778 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK",
779 pos
== buf
? "" : " ");
780 if (os_snprintf_error(end
- pos
, ret
)) {
787 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
788 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP",
789 pos
== buf
? "" : " ");
790 if (os_snprintf_error(end
- pos
, ret
)) {
797 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
798 ret
= os_snprintf(pos
, end
- pos
, "%sIEEE8021X",
799 pos
== buf
? "" : " ");
800 if (os_snprintf_error(end
- pos
, ret
)) {
807 if (ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) {
808 ret
= os_snprintf(pos
, end
- pos
, "%sNONE",
809 pos
== buf
? "" : " ");
810 if (os_snprintf_error(end
- pos
, ret
)) {
817 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
818 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-NONE",
819 pos
== buf
? "" : " ");
820 if (os_snprintf_error(end
- pos
, ret
)) {
827 #ifdef CONFIG_IEEE80211R
828 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
829 ret
= os_snprintf(pos
, end
- pos
, "%sFT-PSK",
830 pos
== buf
? "" : " ");
831 if (os_snprintf_error(end
- pos
, ret
)) {
838 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
839 ret
= os_snprintf(pos
, end
- pos
, "%sFT-EAP",
840 pos
== buf
? "" : " ");
841 if (os_snprintf_error(end
- pos
, ret
)) {
847 #endif /* CONFIG_IEEE80211R */
849 #ifdef CONFIG_IEEE80211W
850 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
851 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-PSK-SHA256",
852 pos
== buf
? "" : " ");
853 if (os_snprintf_error(end
- pos
, ret
)) {
860 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
861 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SHA256",
862 pos
== buf
? "" : " ");
863 if (os_snprintf_error(end
- pos
, ret
)) {
869 #endif /* CONFIG_IEEE80211W */
872 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
873 ret
= os_snprintf(pos
, end
- pos
, "%sWPS",
874 pos
== buf
? "" : " ");
875 if (os_snprintf_error(end
- pos
, ret
)) {
881 #endif /* CONFIG_WPS */
884 if (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
) {
885 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
886 pos
== buf
? "" : " ");
887 if (os_snprintf_error(end
- pos
, ret
)) {
894 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
895 ret
= os_snprintf(pos
, end
- pos
, "%sFT-SAE",
896 pos
== buf
? "" : " ");
897 if (os_snprintf_error(end
- pos
, ret
)) {
903 #endif /* CONFIG_SAE */
906 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) {
907 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
908 pos
== buf
? "" : " ");
909 if (os_snprintf_error(end
- pos
, ret
)) {
915 #endif /* CONFIG_HS20 */
918 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
919 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B",
920 pos
== buf
? "" : " ");
921 if (os_snprintf_error(end
- pos
, ret
)) {
927 #endif /* CONFIG_SUITEB */
929 #ifdef CONFIG_SUITEB192
930 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
931 ret
= os_snprintf(pos
, end
- pos
, "%sWPA-EAP-SUITE-B-192",
932 pos
== buf
? "" : " ");
933 if (os_snprintf_error(end
- pos
, ret
)) {
939 #endif /* CONFIG_SUITEB192 */
942 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
943 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
944 pos
== buf
? "" : " ");
945 if (os_snprintf_error(end
- pos
, ret
)) {
951 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
952 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
953 pos
== buf
? "" : " ");
954 if (os_snprintf_error(end
- pos
, ret
)) {
960 #ifdef CONFIG_IEEE80211R
961 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
962 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
963 pos
== buf
? "" : " ");
964 if (os_snprintf_error(end
- pos
, ret
)) {
970 if (ssid
->key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
971 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
972 pos
== buf
? "" : " ");
973 if (os_snprintf_error(end
- pos
, ret
)) {
979 #endif /* CONFIG_IEEE80211R */
980 #endif /* CONFIG_FILS */
989 #endif /* NO_CONFIG_WRITE */
992 static int wpa_config_parse_cipher(int line
, const char *value
)
996 #else /* CONFIG_NO_WPA */
997 int val
= wpa_parse_cipher(value
);
999 wpa_printf(MSG_ERROR
, "Line %d: invalid cipher '%s'.",
1004 wpa_printf(MSG_ERROR
, "Line %d: no cipher values configured.",
1009 #endif /* CONFIG_NO_WPA */
1013 #ifndef NO_CONFIG_WRITE
1014 static char * wpa_config_write_cipher(int cipher
)
1016 #ifdef CONFIG_NO_WPA
1018 #else /* CONFIG_NO_WPA */
1019 char *buf
= os_zalloc(50);
1023 if (wpa_write_ciphers(buf
, buf
+ 50, cipher
, " ") < 0) {
1029 #endif /* CONFIG_NO_WPA */
1031 #endif /* NO_CONFIG_WRITE */
1034 static int wpa_config_parse_pairwise(const struct parse_data
*data
,
1035 struct wpa_ssid
*ssid
, int line
,
1039 val
= wpa_config_parse_cipher(line
, value
);
1042 if (val
& ~WPA_ALLOWED_PAIRWISE_CIPHERS
) {
1043 wpa_printf(MSG_ERROR
, "Line %d: not allowed pairwise cipher "
1044 "(0x%x).", line
, val
);
1048 if (ssid
->pairwise_cipher
== val
)
1050 wpa_printf(MSG_MSGDUMP
, "pairwise: 0x%x", val
);
1051 ssid
->pairwise_cipher
= val
;
1056 #ifndef NO_CONFIG_WRITE
1057 static char * wpa_config_write_pairwise(const struct parse_data
*data
,
1058 struct wpa_ssid
*ssid
)
1060 return wpa_config_write_cipher(ssid
->pairwise_cipher
);
1062 #endif /* NO_CONFIG_WRITE */
1065 static int wpa_config_parse_group(const struct parse_data
*data
,
1066 struct wpa_ssid
*ssid
, int line
,
1070 val
= wpa_config_parse_cipher(line
, value
);
1075 * Backwards compatibility - filter out WEP ciphers that were previously
1078 val
&= ~(WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
);
1080 if (val
& ~WPA_ALLOWED_GROUP_CIPHERS
) {
1081 wpa_printf(MSG_ERROR
, "Line %d: not allowed group cipher "
1082 "(0x%x).", line
, val
);
1086 if (ssid
->group_cipher
== val
)
1088 wpa_printf(MSG_MSGDUMP
, "group: 0x%x", val
);
1089 ssid
->group_cipher
= val
;
1094 #ifndef NO_CONFIG_WRITE
1095 static char * wpa_config_write_group(const struct parse_data
*data
,
1096 struct wpa_ssid
*ssid
)
1098 return wpa_config_write_cipher(ssid
->group_cipher
);
1100 #endif /* NO_CONFIG_WRITE */
1103 static int wpa_config_parse_auth_alg(const struct parse_data
*data
,
1104 struct wpa_ssid
*ssid
, int line
,
1107 int val
= 0, last
, errors
= 0;
1108 char *start
, *end
, *buf
;
1110 buf
= os_strdup(value
);
1115 while (*start
!= '\0') {
1116 while (*start
== ' ' || *start
== '\t')
1121 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1123 last
= *end
== '\0';
1125 if (os_strcmp(start
, "OPEN") == 0)
1126 val
|= WPA_AUTH_ALG_OPEN
;
1127 else if (os_strcmp(start
, "SHARED") == 0)
1128 val
|= WPA_AUTH_ALG_SHARED
;
1129 else if (os_strcmp(start
, "LEAP") == 0)
1130 val
|= WPA_AUTH_ALG_LEAP
;
1132 wpa_printf(MSG_ERROR
, "Line %d: invalid auth_alg '%s'",
1144 wpa_printf(MSG_ERROR
,
1145 "Line %d: no auth_alg values configured.", line
);
1149 if (!errors
&& ssid
->auth_alg
== val
)
1151 wpa_printf(MSG_MSGDUMP
, "auth_alg: 0x%x", val
);
1152 ssid
->auth_alg
= val
;
1153 return errors
? -1 : 0;
1157 #ifndef NO_CONFIG_WRITE
1158 static char * wpa_config_write_auth_alg(const struct parse_data
*data
,
1159 struct wpa_ssid
*ssid
)
1161 char *buf
, *pos
, *end
;
1164 pos
= buf
= os_zalloc(30);
1169 if (ssid
->auth_alg
& WPA_AUTH_ALG_OPEN
) {
1170 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
1171 pos
== buf
? "" : " ");
1172 if (os_snprintf_error(end
- pos
, ret
)) {
1179 if (ssid
->auth_alg
& WPA_AUTH_ALG_SHARED
) {
1180 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1181 pos
== buf
? "" : " ");
1182 if (os_snprintf_error(end
- pos
, ret
)) {
1189 if (ssid
->auth_alg
& WPA_AUTH_ALG_LEAP
) {
1190 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
1191 pos
== buf
? "" : " ");
1192 if (os_snprintf_error(end
- pos
, ret
)) {
1206 #endif /* NO_CONFIG_WRITE */
1209 static int * wpa_config_parse_int_array(const char *value
)
1217 freqs
= os_calloc(len
+ 1, sizeof(int));
1228 n
= os_realloc_array(freqs
, len
* 2 + 1, sizeof(int));
1233 for (i
= len
; i
<= len
* 2; i
++)
1239 freqs
[used
] = atoi(pos
);
1240 if (freqs
[used
] == 0)
1243 pos
= os_strchr(pos
+ 1, ' ');
1250 static int wpa_config_parse_scan_freq(const struct parse_data
*data
,
1251 struct wpa_ssid
*ssid
, int line
,
1256 freqs
= wpa_config_parse_int_array(value
);
1259 if (freqs
[0] == 0) {
1263 os_free(ssid
->scan_freq
);
1264 ssid
->scan_freq
= freqs
;
1270 static int wpa_config_parse_freq_list(const struct parse_data
*data
,
1271 struct wpa_ssid
*ssid
, int line
,
1276 freqs
= wpa_config_parse_int_array(value
);
1279 if (freqs
[0] == 0) {
1283 os_free(ssid
->freq_list
);
1284 ssid
->freq_list
= freqs
;
1290 #ifndef NO_CONFIG_WRITE
1291 static char * wpa_config_write_freqs(const struct parse_data
*data
,
1294 char *buf
, *pos
, *end
;
1302 for (i
= 0; freqs
[i
]; i
++)
1305 pos
= buf
= os_zalloc(10 * count
+ 1);
1308 end
= buf
+ 10 * count
+ 1;
1310 for (i
= 0; freqs
[i
]; i
++) {
1311 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
1312 i
== 0 ? "" : " ", freqs
[i
]);
1313 if (os_snprintf_error(end
- pos
, ret
)) {
1324 static char * wpa_config_write_scan_freq(const struct parse_data
*data
,
1325 struct wpa_ssid
*ssid
)
1327 return wpa_config_write_freqs(data
, ssid
->scan_freq
);
1331 static char * wpa_config_write_freq_list(const struct parse_data
*data
,
1332 struct wpa_ssid
*ssid
)
1334 return wpa_config_write_freqs(data
, ssid
->freq_list
);
1336 #endif /* NO_CONFIG_WRITE */
1339 #ifdef IEEE8021X_EAPOL
1340 static int wpa_config_parse_eap(const struct parse_data
*data
,
1341 struct wpa_ssid
*ssid
, int line
,
1344 int last
, errors
= 0;
1345 char *start
, *end
, *buf
;
1346 struct eap_method_type
*methods
= NULL
, *tmp
;
1347 size_t num_methods
= 0;
1349 buf
= os_strdup(value
);
1354 while (*start
!= '\0') {
1355 while (*start
== ' ' || *start
== '\t')
1360 while (*end
!= ' ' && *end
!= '\t' && *end
!= '\0')
1362 last
= *end
== '\0';
1365 methods
= os_realloc_array(methods
, num_methods
+ 1,
1367 if (methods
== NULL
) {
1372 methods
[num_methods
].method
= eap_peer_get_type(
1373 start
, &methods
[num_methods
].vendor
);
1374 if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1375 methods
[num_methods
].method
== EAP_TYPE_NONE
) {
1376 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP method "
1377 "'%s'", line
, start
);
1378 wpa_printf(MSG_ERROR
, "You may need to add support for"
1379 " this EAP method during wpa_supplicant\n"
1380 "build time configuration.\n"
1381 "See README for more information.");
1383 } else if (methods
[num_methods
].vendor
== EAP_VENDOR_IETF
&&
1384 methods
[num_methods
].method
== EAP_TYPE_LEAP
)
1396 methods
= os_realloc_array(methods
, num_methods
+ 1, sizeof(*methods
));
1397 if (methods
== NULL
) {
1401 methods
[num_methods
].vendor
= EAP_VENDOR_IETF
;
1402 methods
[num_methods
].method
= EAP_TYPE_NONE
;
1405 if (!errors
&& ssid
->eap
.eap_methods
) {
1406 struct eap_method_type
*prev_m
;
1407 size_t i
, j
, prev_methods
, match
= 0;
1409 prev_m
= ssid
->eap
.eap_methods
;
1410 for (i
= 0; prev_m
[i
].vendor
!= EAP_VENDOR_IETF
||
1411 prev_m
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1412 /* Count the methods */
1414 prev_methods
= i
+ 1;
1416 for (i
= 0; prev_methods
== num_methods
&& i
< prev_methods
;
1418 for (j
= 0; j
< num_methods
; j
++) {
1419 if (prev_m
[i
].vendor
== methods
[j
].vendor
&&
1420 prev_m
[i
].method
== methods
[j
].method
) {
1426 if (match
== num_methods
) {
1431 wpa_hexdump(MSG_MSGDUMP
, "eap methods",
1432 (u8
*) methods
, num_methods
* sizeof(*methods
));
1433 os_free(ssid
->eap
.eap_methods
);
1434 ssid
->eap
.eap_methods
= methods
;
1435 return errors
? -1 : 0;
1439 #ifndef NO_CONFIG_WRITE
1440 static char * wpa_config_write_eap(const struct parse_data
*data
,
1441 struct wpa_ssid
*ssid
)
1444 char *buf
, *pos
, *end
;
1445 const struct eap_method_type
*eap_methods
= ssid
->eap
.eap_methods
;
1448 if (eap_methods
== NULL
)
1451 pos
= buf
= os_zalloc(100);
1456 for (i
= 0; eap_methods
[i
].vendor
!= EAP_VENDOR_IETF
||
1457 eap_methods
[i
].method
!= EAP_TYPE_NONE
; i
++) {
1458 name
= eap_get_name(eap_methods
[i
].vendor
,
1459 eap_methods
[i
].method
);
1461 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
1462 pos
== buf
? "" : " ", name
);
1463 if (os_snprintf_error(end
- pos
, ret
))
1473 #endif /* NO_CONFIG_WRITE */
1476 static int wpa_config_parse_password(const struct parse_data
*data
,
1477 struct wpa_ssid
*ssid
, int line
,
1482 if (os_strcmp(value
, "NULL") == 0) {
1483 if (!ssid
->eap
.password
)
1484 return 1; /* Already unset */
1485 wpa_printf(MSG_DEBUG
, "Unset configuration string 'password'");
1486 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1487 ssid
->eap
.password
= NULL
;
1488 ssid
->eap
.password_len
= 0;
1492 #ifdef CONFIG_EXT_PASSWORD
1493 if (os_strncmp(value
, "ext:", 4) == 0) {
1494 char *name
= os_strdup(value
+ 4);
1497 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1498 ssid
->eap
.password
= (u8
*) name
;
1499 ssid
->eap
.password_len
= os_strlen(name
);
1500 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1501 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1504 #endif /* CONFIG_EXT_PASSWORD */
1506 if (os_strncmp(value
, "hash:", 5) != 0) {
1510 tmp
= wpa_config_parse_string(value
, &res_len
);
1512 wpa_printf(MSG_ERROR
, "Line %d: failed to parse "
1516 wpa_hexdump_ascii_key(MSG_MSGDUMP
, data
->name
,
1517 (u8
*) tmp
, res_len
);
1519 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1520 ssid
->eap
.password
= (u8
*) tmp
;
1521 ssid
->eap
.password_len
= res_len
;
1522 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1523 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1529 /* NtPasswordHash: hash:<32 hex digits> */
1530 if (os_strlen(value
+ 5) != 2 * 16) {
1531 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash length "
1532 "(expected 32 hex digits)", line
);
1536 hash
= os_malloc(16);
1540 if (hexstr2bin(value
+ 5, hash
, 16)) {
1542 wpa_printf(MSG_ERROR
, "Line %d: Invalid password hash", line
);
1546 wpa_hexdump_key(MSG_MSGDUMP
, data
->name
, hash
, 16);
1548 if (ssid
->eap
.password
&& ssid
->eap
.password_len
== 16 &&
1549 os_memcmp(ssid
->eap
.password
, hash
, 16) == 0 &&
1550 (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1551 bin_clear_free(hash
, 16);
1554 bin_clear_free(ssid
->eap
.password
, ssid
->eap
.password_len
);
1555 ssid
->eap
.password
= hash
;
1556 ssid
->eap
.password_len
= 16;
1557 ssid
->eap
.flags
|= EAP_CONFIG_FLAGS_PASSWORD_NTHASH
;
1558 ssid
->eap
.flags
&= ~EAP_CONFIG_FLAGS_EXT_PASSWORD
;
1564 #ifndef NO_CONFIG_WRITE
1565 static char * wpa_config_write_password(const struct parse_data
*data
,
1566 struct wpa_ssid
*ssid
)
1570 if (ssid
->eap
.password
== NULL
)
1573 #ifdef CONFIG_EXT_PASSWORD
1574 if (ssid
->eap
.flags
& EAP_CONFIG_FLAGS_EXT_PASSWORD
) {
1575 buf
= os_zalloc(4 + ssid
->eap
.password_len
+ 1);
1578 os_memcpy(buf
, "ext:", 4);
1579 os_memcpy(buf
+ 4, ssid
->eap
.password
, ssid
->eap
.password_len
);
1582 #endif /* CONFIG_EXT_PASSWORD */
1584 if (!(ssid
->eap
.flags
& EAP_CONFIG_FLAGS_PASSWORD_NTHASH
)) {
1585 return wpa_config_write_string(
1586 ssid
->eap
.password
, ssid
->eap
.password_len
);
1589 buf
= os_malloc(5 + 32 + 1);
1593 os_memcpy(buf
, "hash:", 5);
1594 wpa_snprintf_hex(buf
+ 5, 32 + 1, ssid
->eap
.password
, 16);
1598 #endif /* NO_CONFIG_WRITE */
1599 #endif /* IEEE8021X_EAPOL */
1602 static int wpa_config_parse_wep_key(u8
*key
, size_t *len
, int line
,
1603 const char *value
, int idx
)
1605 char *buf
, title
[20];
1608 buf
= wpa_config_parse_string(value
, len
);
1610 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key %d '%s'.",
1614 if (*len
> MAX_WEP_KEY_LEN
) {
1615 wpa_printf(MSG_ERROR
, "Line %d: Too long WEP key %d '%s'.",
1620 if (*len
&& *len
!= 5 && *len
!= 13 && *len
!= 16) {
1621 wpa_printf(MSG_ERROR
, "Line %d: Invalid WEP key length %u - "
1622 "this network block will be ignored",
1623 line
, (unsigned int) *len
);
1625 os_memcpy(key
, buf
, *len
);
1626 str_clear_free(buf
);
1627 res
= os_snprintf(title
, sizeof(title
), "wep_key%d", idx
);
1628 if (!os_snprintf_error(sizeof(title
), res
))
1629 wpa_hexdump_key(MSG_MSGDUMP
, title
, key
, *len
);
1634 static int wpa_config_parse_wep_key0(const struct parse_data
*data
,
1635 struct wpa_ssid
*ssid
, int line
,
1638 return wpa_config_parse_wep_key(ssid
->wep_key
[0],
1639 &ssid
->wep_key_len
[0], line
,
1644 static int wpa_config_parse_wep_key1(const struct parse_data
*data
,
1645 struct wpa_ssid
*ssid
, int line
,
1648 return wpa_config_parse_wep_key(ssid
->wep_key
[1],
1649 &ssid
->wep_key_len
[1], line
,
1654 static int wpa_config_parse_wep_key2(const struct parse_data
*data
,
1655 struct wpa_ssid
*ssid
, int line
,
1658 return wpa_config_parse_wep_key(ssid
->wep_key
[2],
1659 &ssid
->wep_key_len
[2], line
,
1664 static int wpa_config_parse_wep_key3(const struct parse_data
*data
,
1665 struct wpa_ssid
*ssid
, int line
,
1668 return wpa_config_parse_wep_key(ssid
->wep_key
[3],
1669 &ssid
->wep_key_len
[3], line
,
1674 #ifndef NO_CONFIG_WRITE
1675 static char * wpa_config_write_wep_key(struct wpa_ssid
*ssid
, int idx
)
1677 if (ssid
->wep_key_len
[idx
] == 0)
1679 return wpa_config_write_string(ssid
->wep_key
[idx
],
1680 ssid
->wep_key_len
[idx
]);
1684 static char * wpa_config_write_wep_key0(const struct parse_data
*data
,
1685 struct wpa_ssid
*ssid
)
1687 return wpa_config_write_wep_key(ssid
, 0);
1691 static char * wpa_config_write_wep_key1(const struct parse_data
*data
,
1692 struct wpa_ssid
*ssid
)
1694 return wpa_config_write_wep_key(ssid
, 1);
1698 static char * wpa_config_write_wep_key2(const struct parse_data
*data
,
1699 struct wpa_ssid
*ssid
)
1701 return wpa_config_write_wep_key(ssid
, 2);
1705 static char * wpa_config_write_wep_key3(const struct parse_data
*data
,
1706 struct wpa_ssid
*ssid
)
1708 return wpa_config_write_wep_key(ssid
, 3);
1710 #endif /* NO_CONFIG_WRITE */
1715 static int wpa_config_parse_go_p2p_dev_addr(const struct parse_data
*data
,
1716 struct wpa_ssid
*ssid
, int line
,
1719 if (value
[0] == '\0' || os_strcmp(value
, "\"\"") == 0 ||
1720 os_strcmp(value
, "any") == 0) {
1721 os_memset(ssid
->go_p2p_dev_addr
, 0, ETH_ALEN
);
1722 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address any");
1725 if (hwaddr_aton(value
, ssid
->go_p2p_dev_addr
)) {
1726 wpa_printf(MSG_ERROR
, "Line %d: Invalid GO P2P Device Address '%s'.",
1730 ssid
->bssid_set
= 1;
1731 wpa_printf(MSG_MSGDUMP
, "GO P2P Device Address " MACSTR
,
1732 MAC2STR(ssid
->go_p2p_dev_addr
));
1737 #ifndef NO_CONFIG_WRITE
1738 static char * wpa_config_write_go_p2p_dev_addr(const struct parse_data
*data
,
1739 struct wpa_ssid
*ssid
)
1744 if (is_zero_ether_addr(ssid
->go_p2p_dev_addr
))
1747 value
= os_malloc(20);
1750 res
= os_snprintf(value
, 20, MACSTR
, MAC2STR(ssid
->go_p2p_dev_addr
));
1751 if (os_snprintf_error(20, res
)) {
1755 value
[20 - 1] = '\0';
1758 #endif /* NO_CONFIG_WRITE */
1761 static int wpa_config_parse_p2p_client_list(const struct parse_data
*data
,
1762 struct wpa_ssid
*ssid
, int line
,
1765 return wpa_config_parse_addr_list(data
, line
, value
,
1766 &ssid
->p2p_client_list
,
1767 &ssid
->num_p2p_clients
,
1768 "p2p_client_list", 0, 0);
1772 #ifndef NO_CONFIG_WRITE
1773 static char * wpa_config_write_p2p_client_list(const struct parse_data
*data
,
1774 struct wpa_ssid
*ssid
)
1776 return wpa_config_write_addr_list(data
, ssid
->p2p_client_list
,
1777 ssid
->num_p2p_clients
,
1780 #endif /* NO_CONFIG_WRITE */
1783 static int wpa_config_parse_psk_list(const struct parse_data
*data
,
1784 struct wpa_ssid
*ssid
, int line
,
1787 struct psk_list_entry
*p
;
1790 p
= os_zalloc(sizeof(*p
));
1795 if (os_strncmp(pos
, "P2P-", 4) == 0) {
1800 if (hwaddr_aton(pos
, p
->addr
)) {
1801 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list address '%s'",
1808 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list '%s'",
1815 if (hexstr2bin(pos
, p
->psk
, PMK_LEN
) || pos
[PMK_LEN
* 2] != '\0') {
1816 wpa_printf(MSG_ERROR
, "Line %d: Invalid psk_list PSK '%s'",
1822 dl_list_add(&ssid
->psk_list
, &p
->list
);
1828 #ifndef NO_CONFIG_WRITE
1829 static char * wpa_config_write_psk_list(const struct parse_data
*data
,
1830 struct wpa_ssid
*ssid
)
1834 #endif /* NO_CONFIG_WRITE */
1836 #endif /* CONFIG_P2P */
1841 static int wpa_config_parse_mesh_basic_rates(const struct parse_data
*data
,
1842 struct wpa_ssid
*ssid
, int line
,
1845 int *rates
= wpa_config_parse_int_array(value
);
1847 if (rates
== NULL
) {
1848 wpa_printf(MSG_ERROR
, "Line %d: Invalid mesh_basic_rates '%s'",
1852 if (rates
[0] == 0) {
1857 os_free(ssid
->mesh_basic_rates
);
1858 ssid
->mesh_basic_rates
= rates
;
1864 #ifndef NO_CONFIG_WRITE
1866 static char * wpa_config_write_mesh_basic_rates(const struct parse_data
*data
,
1867 struct wpa_ssid
*ssid
)
1869 return wpa_config_write_freqs(data
, ssid
->mesh_basic_rates
);
1872 #endif /* NO_CONFIG_WRITE */
1874 #endif /* CONFIG_MESH */
1877 #ifdef CONFIG_MACSEC
1879 static int wpa_config_parse_mka_cak(const struct parse_data
*data
,
1880 struct wpa_ssid
*ssid
, int line
,
1883 if (hexstr2bin(value
, ssid
->mka_cak
, MACSEC_CAK_LEN
) ||
1884 value
[MACSEC_CAK_LEN
* 2] != '\0') {
1885 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CAK '%s'.",
1890 ssid
->mka_psk_set
|= MKA_PSK_SET_CAK
;
1892 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CAK", ssid
->mka_cak
, MACSEC_CAK_LEN
);
1897 static int wpa_config_parse_mka_ckn(const struct parse_data
*data
,
1898 struct wpa_ssid
*ssid
, int line
,
1901 if (hexstr2bin(value
, ssid
->mka_ckn
, MACSEC_CKN_LEN
) ||
1902 value
[MACSEC_CKN_LEN
* 2] != '\0') {
1903 wpa_printf(MSG_ERROR
, "Line %d: Invalid MKA-CKN '%s'.",
1908 ssid
->mka_psk_set
|= MKA_PSK_SET_CKN
;
1910 wpa_hexdump_key(MSG_MSGDUMP
, "MKA-CKN", ssid
->mka_ckn
, MACSEC_CKN_LEN
);
1915 #ifndef NO_CONFIG_WRITE
1917 static char * wpa_config_write_mka_cak(const struct parse_data
*data
,
1918 struct wpa_ssid
*ssid
)
1920 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CAK
))
1923 return wpa_config_write_string_hex(ssid
->mka_cak
, MACSEC_CAK_LEN
);
1927 static char * wpa_config_write_mka_ckn(const struct parse_data
*data
,
1928 struct wpa_ssid
*ssid
)
1930 if (!(ssid
->mka_psk_set
& MKA_PSK_SET_CKN
))
1932 return wpa_config_write_string_hex(ssid
->mka_ckn
, MACSEC_CKN_LEN
);
1935 #endif /* NO_CONFIG_WRITE */
1937 #endif /* CONFIG_MACSEC */
1940 /* Helper macros for network block parser */
1945 /* OFFSET: Get offset of a variable within the wpa_ssid structure */
1946 #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
1948 /* STR: Define a string variable for an ASCII string; f = field name */
1949 #ifdef NO_CONFIG_WRITE
1950 #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
1951 #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
1952 #else /* NO_CONFIG_WRITE */
1953 #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
1954 #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
1955 #endif /* NO_CONFIG_WRITE */
1956 #define STR(f) _STR(f), NULL, NULL, NULL, 0
1957 #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
1958 #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
1959 #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
1961 /* STR_LEN: Define a string variable with a separate variable for storing the
1962 * data length. Unlike STR(), this can be used to store arbitrary binary data
1963 * (i.e., even nul termination character). */
1964 #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
1965 #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
1966 #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
1967 #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
1968 #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
1970 /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
1971 * explicitly specified. */
1972 #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
1973 #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
1974 #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
1976 #ifdef NO_CONFIG_WRITE
1977 #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
1978 #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
1979 #else /* NO_CONFIG_WRITE */
1980 #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1981 OFFSET(f), (void *) 0
1982 #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
1983 OFFSET(eap.f), (void *) 0
1984 #endif /* NO_CONFIG_WRITE */
1986 /* INT: Define an integer variable */
1987 #define INT(f) _INT(f), NULL, NULL, 0
1988 #define INTe(f) _INTe(f), NULL, NULL, 0
1990 /* INT_RANGE: Define an integer variable with allowed value range */
1991 #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
1993 /* FUNC: Define a configuration variable that uses a custom function for
1994 * parsing and writing the value. */
1995 #ifdef NO_CONFIG_WRITE
1996 #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
1997 #else /* NO_CONFIG_WRITE */
1998 #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
1999 NULL, NULL, NULL, NULL
2000 #endif /* NO_CONFIG_WRITE */
2001 #define FUNC(f) _FUNC(f), 0
2002 #define FUNC_KEY(f) _FUNC(f), 1
2005 * Table of network configuration variables. This table is used to parse each
2006 * network configuration variable, e.g., each line in wpa_supplicant.conf file
2007 * that is inside a network block.
2009 * This table is generated using the helper macros defined above and with
2010 * generous help from the C pre-processor. The field name is stored as a string
2011 * into .name and for STR and INT types, the offset of the target buffer within
2012 * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
2013 * offset to the field containing the length of the configuration variable.
2014 * .param3 and .param4 can be used to mark the allowed range (length for STR
2015 * and value for INT).
2017 * For each configuration line in wpa_supplicant.conf, the parser goes through
2018 * this table and select the entry that matches with the field name. The parser
2019 * function (.parser) is then called to parse the actual value of the field.
2021 * This kind of mechanism makes it easy to add new configuration parameters,
2022 * since only one line needs to be added into this table and into the
2023 * struct wpa_ssid definition if the new variable is either a string or
2024 * integer. More complex types will need to use their own parser and writer
2027 static const struct parse_data ssid_fields
[] = {
2028 { STR_RANGE(ssid
, 0, SSID_MAX_LEN
) },
2029 { INT_RANGE(scan_ssid
, 0, 1) },
2031 { FUNC(bssid_blacklist
) },
2032 { FUNC(bssid_whitelist
) },
2034 { INT(mem_only_psk
) },
2037 { INT(bg_scan_period
) },
2041 { FUNC(scan_freq
) },
2042 { FUNC(freq_list
) },
2043 { INT_RANGE(ht
, 0, 1) },
2044 { INT_RANGE(vht
, 0, 1) },
2045 { INT_RANGE(ht40
, -1, 1) },
2046 { INT_RANGE(max_oper_chwidth
, VHT_CHANWIDTH_USE_HT
,
2047 VHT_CHANWIDTH_80P80MHZ
) },
2048 { INT(vht_center_freq1
) },
2049 { INT(vht_center_freq2
) },
2050 #ifdef IEEE8021X_EAPOL
2052 { STR_LENe(identity
) },
2053 { STR_LENe(anonymous_identity
) },
2054 { FUNC_KEY(password
) },
2057 { STRe(client_cert
) },
2058 { STRe(private_key
) },
2059 { STR_KEYe(private_key_passwd
) },
2061 { STRe(subject_match
) },
2062 { STRe(altsubject_match
) },
2063 { STRe(domain_suffix_match
) },
2064 { STRe(domain_match
) },
2067 { STRe(client_cert2
) },
2068 { STRe(private_key2
) },
2069 { STR_KEYe(private_key2_passwd
) },
2071 { STRe(subject_match2
) },
2072 { STRe(altsubject_match2
) },
2073 { STRe(domain_suffix_match2
) },
2074 { STRe(domain_match2
) },
2079 { STRe(engine_id
) },
2082 { STRe(ca_cert_id
) },
2084 { STRe(engine2_id
) },
2087 { STRe(ca_cert2_id
) },
2090 { INT(eapol_flags
) },
2092 { STRe(openssl_ciphers
) },
2094 #endif /* IEEE8021X_EAPOL */
2095 { FUNC_KEY(wep_key0
) },
2096 { FUNC_KEY(wep_key1
) },
2097 { FUNC_KEY(wep_key2
) },
2098 { FUNC_KEY(wep_key3
) },
2099 { INT(wep_tx_keyidx
) },
2101 #ifdef IEEE8021X_EAPOL
2102 { INT(eap_workaround
) },
2104 { INTe(fragment_size
) },
2106 #endif /* IEEE8021X_EAPOL */
2108 { INT_RANGE(mode
, 0, 5) },
2109 { INT_RANGE(no_auto_peer
, 0, 1) },
2110 #else /* CONFIG_MESH */
2111 { INT_RANGE(mode
, 0, 4) },
2112 #endif /* CONFIG_MESH */
2113 { INT_RANGE(proactive_key_caching
, 0, 1) },
2114 { INT_RANGE(disabled
, 0, 2) },
2116 #ifdef CONFIG_IEEE80211W
2117 { INT_RANGE(ieee80211w
, 0, 2) },
2118 #endif /* CONFIG_IEEE80211W */
2119 { INT_RANGE(peerkey
, 0, 1) },
2120 { INT_RANGE(mixed_cell
, 0, 1) },
2121 { INT_RANGE(frequency
, 0, 65000) },
2122 { INT_RANGE(fixed_freq
, 0, 1) },
2124 { INT_RANGE(acs
, 0, 1) },
2125 #endif /* CONFIG_ACS */
2127 { FUNC(mesh_basic_rates
) },
2128 { INT(dot11MeshMaxRetries
) },
2129 { INT(dot11MeshRetryTimeout
) },
2130 { INT(dot11MeshConfirmTimeout
) },
2131 { INT(dot11MeshHoldingTimeout
) },
2132 #endif /* CONFIG_MESH */
2133 { INT(wpa_ptk_rekey
) },
2134 { INT(group_rekey
) },
2136 { INT_RANGE(ignore_broadcast_ssid
, 0, 2) },
2138 { FUNC(go_p2p_dev_addr
) },
2139 { FUNC(p2p_client_list
) },
2141 #endif /* CONFIG_P2P */
2142 #ifdef CONFIG_HT_OVERRIDES
2143 { INT_RANGE(disable_ht
, 0, 1) },
2144 { INT_RANGE(disable_ht40
, -1, 1) },
2145 { INT_RANGE(disable_sgi
, 0, 1) },
2146 { INT_RANGE(disable_ldpc
, 0, 1) },
2147 { INT_RANGE(ht40_intolerant
, 0, 1) },
2148 { INT_RANGE(disable_max_amsdu
, -1, 1) },
2149 { INT_RANGE(ampdu_factor
, -1, 3) },
2150 { INT_RANGE(ampdu_density
, -1, 7) },
2152 #endif /* CONFIG_HT_OVERRIDES */
2153 #ifdef CONFIG_VHT_OVERRIDES
2154 { INT_RANGE(disable_vht
, 0, 1) },
2156 { INT(vht_capa_mask
) },
2157 { INT_RANGE(vht_rx_mcs_nss_1
, -1, 3) },
2158 { INT_RANGE(vht_rx_mcs_nss_2
, -1, 3) },
2159 { INT_RANGE(vht_rx_mcs_nss_3
, -1, 3) },
2160 { INT_RANGE(vht_rx_mcs_nss_4
, -1, 3) },
2161 { INT_RANGE(vht_rx_mcs_nss_5
, -1, 3) },
2162 { INT_RANGE(vht_rx_mcs_nss_6
, -1, 3) },
2163 { INT_RANGE(vht_rx_mcs_nss_7
, -1, 3) },
2164 { INT_RANGE(vht_rx_mcs_nss_8
, -1, 3) },
2165 { INT_RANGE(vht_tx_mcs_nss_1
, -1, 3) },
2166 { INT_RANGE(vht_tx_mcs_nss_2
, -1, 3) },
2167 { INT_RANGE(vht_tx_mcs_nss_3
, -1, 3) },
2168 { INT_RANGE(vht_tx_mcs_nss_4
, -1, 3) },
2169 { INT_RANGE(vht_tx_mcs_nss_5
, -1, 3) },
2170 { INT_RANGE(vht_tx_mcs_nss_6
, -1, 3) },
2171 { INT_RANGE(vht_tx_mcs_nss_7
, -1, 3) },
2172 { INT_RANGE(vht_tx_mcs_nss_8
, -1, 3) },
2173 #endif /* CONFIG_VHT_OVERRIDES */
2174 { INT(ap_max_inactivity
) },
2175 { INT(dtim_period
) },
2176 { INT(beacon_int
) },
2177 #ifdef CONFIG_MACSEC
2178 { INT_RANGE(macsec_policy
, 0, 1) },
2179 { INT_RANGE(macsec_integ_only
, 0, 1) },
2180 { INT_RANGE(macsec_port
, 1, 65534) },
2181 { INT_RANGE(mka_priority
, 0, 255) },
2182 { FUNC_KEY(mka_cak
) },
2183 { FUNC_KEY(mka_ckn
) },
2184 #endif /* CONFIG_MACSEC */
2186 { INT(update_identifier
) },
2187 #endif /* CONFIG_HS20 */
2188 { INT_RANGE(mac_addr
, 0, 2) },
2189 { INT_RANGE(pbss
, 0, 2) },
2190 { INT_RANGE(wps_disabled
, 0, 1) },
2191 { INT_RANGE(fils_dh_group
, 0, 65535) },
2203 #undef STR_RANGE_KEY
2210 #define NUM_SSID_FIELDS ARRAY_SIZE(ssid_fields)
2214 * wpa_config_add_prio_network - Add a network to priority lists
2215 * @config: Configuration data from wpa_config_read()
2216 * @ssid: Pointer to the network configuration to be added to the list
2217 * Returns: 0 on success, -1 on failure
2219 * This function is used to add a network block to the priority list of
2220 * networks. This must be called for each network when reading in the full
2221 * configuration. In addition, this can be used indirectly when updating
2222 * priorities by calling wpa_config_update_prio_list().
2224 int wpa_config_add_prio_network(struct wpa_config
*config
,
2225 struct wpa_ssid
*ssid
)
2228 struct wpa_ssid
*prev
, **nlist
;
2231 * Add to an existing priority list if one is available for the
2232 * configured priority level for this network.
2234 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2235 prev
= config
->pssid
[prio
];
2236 if (prev
->priority
== ssid
->priority
) {
2244 /* First network for this priority - add a new priority list */
2245 nlist
= os_realloc_array(config
->pssid
, config
->num_prio
+ 1,
2246 sizeof(struct wpa_ssid
*));
2250 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
2251 if (nlist
[prio
]->priority
< ssid
->priority
) {
2252 os_memmove(&nlist
[prio
+ 1], &nlist
[prio
],
2253 (config
->num_prio
- prio
) *
2254 sizeof(struct wpa_ssid
*));
2261 config
->pssid
= nlist
;
2268 * wpa_config_update_prio_list - Update network priority list
2269 * @config: Configuration data from wpa_config_read()
2270 * Returns: 0 on success, -1 on failure
2272 * This function is called to update the priority list of networks in the
2273 * configuration when a network is being added or removed. This is also called
2274 * if a priority for a network is changed.
2276 int wpa_config_update_prio_list(struct wpa_config
*config
)
2278 struct wpa_ssid
*ssid
;
2281 os_free(config
->pssid
);
2282 config
->pssid
= NULL
;
2283 config
->num_prio
= 0;
2285 ssid
= config
->ssid
;
2288 if (wpa_config_add_prio_network(config
, ssid
) < 0)
2297 #ifdef IEEE8021X_EAPOL
2298 static void eap_peer_config_free(struct eap_peer_config
*eap
)
2300 os_free(eap
->eap_methods
);
2301 bin_clear_free(eap
->identity
, eap
->identity_len
);
2302 os_free(eap
->anonymous_identity
);
2303 bin_clear_free(eap
->password
, eap
->password_len
);
2304 os_free(eap
->ca_cert
);
2305 os_free(eap
->ca_path
);
2306 os_free(eap
->client_cert
);
2307 os_free(eap
->private_key
);
2308 str_clear_free(eap
->private_key_passwd
);
2309 os_free(eap
->dh_file
);
2310 os_free(eap
->subject_match
);
2311 os_free(eap
->altsubject_match
);
2312 os_free(eap
->domain_suffix_match
);
2313 os_free(eap
->domain_match
);
2314 os_free(eap
->ca_cert2
);
2315 os_free(eap
->ca_path2
);
2316 os_free(eap
->client_cert2
);
2317 os_free(eap
->private_key2
);
2318 str_clear_free(eap
->private_key2_passwd
);
2319 os_free(eap
->dh_file2
);
2320 os_free(eap
->subject_match2
);
2321 os_free(eap
->altsubject_match2
);
2322 os_free(eap
->domain_suffix_match2
);
2323 os_free(eap
->domain_match2
);
2324 os_free(eap
->phase1
);
2325 os_free(eap
->phase2
);
2327 str_clear_free(eap
->pin
);
2328 os_free(eap
->engine_id
);
2329 os_free(eap
->key_id
);
2330 os_free(eap
->cert_id
);
2331 os_free(eap
->ca_cert_id
);
2332 os_free(eap
->key2_id
);
2333 os_free(eap
->cert2_id
);
2334 os_free(eap
->ca_cert2_id
);
2335 str_clear_free(eap
->pin2
);
2336 os_free(eap
->engine2_id
);
2338 os_free(eap
->pending_req_otp
);
2339 os_free(eap
->pac_file
);
2340 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
2341 str_clear_free(eap
->external_sim_resp
);
2342 os_free(eap
->openssl_ciphers
);
2344 #endif /* IEEE8021X_EAPOL */
2348 * wpa_config_free_ssid - Free network/ssid configuration data
2349 * @ssid: Configuration data for the network
2351 * This function frees all resources allocated for the network configuration
2354 void wpa_config_free_ssid(struct wpa_ssid
*ssid
)
2356 struct psk_list_entry
*psk
;
2358 os_free(ssid
->ssid
);
2359 str_clear_free(ssid
->passphrase
);
2360 os_free(ssid
->ext_psk
);
2361 #ifdef IEEE8021X_EAPOL
2362 eap_peer_config_free(&ssid
->eap
);
2363 #endif /* IEEE8021X_EAPOL */
2364 os_free(ssid
->id_str
);
2365 os_free(ssid
->scan_freq
);
2366 os_free(ssid
->freq_list
);
2367 os_free(ssid
->bgscan
);
2368 os_free(ssid
->p2p_client_list
);
2369 os_free(ssid
->bssid_blacklist
);
2370 os_free(ssid
->bssid_whitelist
);
2371 #ifdef CONFIG_HT_OVERRIDES
2372 os_free(ssid
->ht_mcs
);
2373 #endif /* CONFIG_HT_OVERRIDES */
2375 os_free(ssid
->mesh_basic_rates
);
2376 #endif /* CONFIG_MESH */
2377 while ((psk
= dl_list_first(&ssid
->psk_list
, struct psk_list_entry
,
2379 dl_list_del(&psk
->list
);
2380 bin_clear_free(psk
, sizeof(*psk
));
2382 bin_clear_free(ssid
, sizeof(*ssid
));
2386 void wpa_config_free_cred(struct wpa_cred
*cred
)
2390 os_free(cred
->realm
);
2391 str_clear_free(cred
->username
);
2392 str_clear_free(cred
->password
);
2393 os_free(cred
->ca_cert
);
2394 os_free(cred
->client_cert
);
2395 os_free(cred
->private_key
);
2396 str_clear_free(cred
->private_key_passwd
);
2397 os_free(cred
->imsi
);
2398 str_clear_free(cred
->milenage
);
2399 for (i
= 0; i
< cred
->num_domain
; i
++)
2400 os_free(cred
->domain
[i
]);
2401 os_free(cred
->domain
);
2402 os_free(cred
->domain_suffix_match
);
2403 os_free(cred
->eap_method
);
2404 os_free(cred
->phase1
);
2405 os_free(cred
->phase2
);
2406 os_free(cred
->excluded_ssid
);
2407 os_free(cred
->roaming_partner
);
2408 os_free(cred
->provisioning_sp
);
2409 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++)
2410 os_free(cred
->req_conn_capab_port
[i
]);
2411 os_free(cred
->req_conn_capab_port
);
2412 os_free(cred
->req_conn_capab_proto
);
2417 void wpa_config_flush_blobs(struct wpa_config
*config
)
2419 #ifndef CONFIG_NO_CONFIG_BLOBS
2420 struct wpa_config_blob
*blob
, *prev
;
2422 blob
= config
->blobs
;
2423 config
->blobs
= NULL
;
2427 wpa_config_free_blob(prev
);
2429 #endif /* CONFIG_NO_CONFIG_BLOBS */
2434 * wpa_config_free - Free configuration data
2435 * @config: Configuration data from wpa_config_read()
2437 * This function frees all resources allocated for the configuration data by
2438 * wpa_config_read().
2440 void wpa_config_free(struct wpa_config
*config
)
2442 struct wpa_ssid
*ssid
, *prev
= NULL
;
2443 struct wpa_cred
*cred
, *cprev
;
2446 ssid
= config
->ssid
;
2450 wpa_config_free_ssid(prev
);
2453 cred
= config
->cred
;
2457 wpa_config_free_cred(cprev
);
2460 wpa_config_flush_blobs(config
);
2462 wpabuf_free(config
->wps_vendor_ext_m1
);
2463 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++)
2464 wpabuf_free(config
->wps_vendor_ext
[i
]);
2465 os_free(config
->ctrl_interface
);
2466 os_free(config
->ctrl_interface_group
);
2467 os_free(config
->opensc_engine_path
);
2468 os_free(config
->pkcs11_engine_path
);
2469 os_free(config
->pkcs11_module_path
);
2470 os_free(config
->openssl_ciphers
);
2471 os_free(config
->pcsc_reader
);
2472 str_clear_free(config
->pcsc_pin
);
2473 os_free(config
->driver_param
);
2474 os_free(config
->device_name
);
2475 os_free(config
->manufacturer
);
2476 os_free(config
->model_name
);
2477 os_free(config
->model_number
);
2478 os_free(config
->serial_number
);
2479 os_free(config
->config_methods
);
2480 os_free(config
->p2p_ssid_postfix
);
2481 os_free(config
->pssid
);
2482 os_free(config
->p2p_pref_chan
);
2483 os_free(config
->p2p_no_go_freq
.range
);
2484 os_free(config
->autoscan
);
2485 os_free(config
->freq_list
);
2486 wpabuf_free(config
->wps_nfc_dh_pubkey
);
2487 wpabuf_free(config
->wps_nfc_dh_privkey
);
2488 wpabuf_free(config
->wps_nfc_dev_pw
);
2489 os_free(config
->ext_password_backend
);
2490 os_free(config
->sae_groups
);
2491 wpabuf_free(config
->ap_vendor_elements
);
2492 os_free(config
->osu_dir
);
2493 os_free(config
->bgscan
);
2494 os_free(config
->wowlan_triggers
);
2495 os_free(config
->fst_group_id
);
2496 os_free(config
->sched_scan_plans
);
2498 os_free(config
->non_pref_chan
);
2499 #endif /* CONFIG_MBO */
2506 * wpa_config_foreach_network - Iterate over each configured network
2507 * @config: Configuration data from wpa_config_read()
2508 * @func: Callback function to process each network
2509 * @arg: Opaque argument to pass to callback function
2511 * Iterate over the set of configured networks calling the specified
2512 * function for each item. We guard against callbacks removing the
2515 void wpa_config_foreach_network(struct wpa_config
*config
,
2516 void (*func
)(void *, struct wpa_ssid
*),
2519 struct wpa_ssid
*ssid
, *next
;
2521 ssid
= config
->ssid
;
2531 * wpa_config_get_network - Get configured network based on id
2532 * @config: Configuration data from wpa_config_read()
2533 * @id: Unique network id to search for
2534 * Returns: Network configuration or %NULL if not found
2536 struct wpa_ssid
* wpa_config_get_network(struct wpa_config
*config
, int id
)
2538 struct wpa_ssid
*ssid
;
2540 ssid
= config
->ssid
;
2552 * wpa_config_add_network - Add a new network with empty configuration
2553 * @config: Configuration data from wpa_config_read()
2554 * Returns: The new network configuration or %NULL if operation failed
2556 struct wpa_ssid
* wpa_config_add_network(struct wpa_config
*config
)
2559 struct wpa_ssid
*ssid
, *last
= NULL
;
2562 ssid
= config
->ssid
;
2571 ssid
= os_zalloc(sizeof(*ssid
));
2575 dl_list_init(&ssid
->psk_list
);
2579 config
->ssid
= ssid
;
2581 wpa_config_update_prio_list(config
);
2588 * wpa_config_remove_network - Remove a configured network based on id
2589 * @config: Configuration data from wpa_config_read()
2590 * @id: Unique network id to search for
2591 * Returns: 0 on success, or -1 if the network was not found
2593 int wpa_config_remove_network(struct wpa_config
*config
, int id
)
2595 struct wpa_ssid
*ssid
, *prev
= NULL
;
2597 ssid
= config
->ssid
;
2609 prev
->next
= ssid
->next
;
2611 config
->ssid
= ssid
->next
;
2613 wpa_config_update_prio_list(config
);
2614 wpa_config_free_ssid(ssid
);
2620 * wpa_config_set_network_defaults - Set network default values
2621 * @ssid: Pointer to network configuration data
2623 void wpa_config_set_network_defaults(struct wpa_ssid
*ssid
)
2625 ssid
->proto
= DEFAULT_PROTO
;
2626 ssid
->pairwise_cipher
= DEFAULT_PAIRWISE
;
2627 ssid
->group_cipher
= DEFAULT_GROUP
;
2628 ssid
->key_mgmt
= DEFAULT_KEY_MGMT
;
2629 ssid
->bg_scan_period
= DEFAULT_BG_SCAN_PERIOD
;
2631 #ifdef IEEE8021X_EAPOL
2632 ssid
->eapol_flags
= DEFAULT_EAPOL_FLAGS
;
2633 ssid
->eap_workaround
= DEFAULT_EAP_WORKAROUND
;
2634 ssid
->eap
.fragment_size
= DEFAULT_FRAGMENT_SIZE
;
2635 ssid
->eap
.sim_num
= DEFAULT_USER_SELECTED_SIM
;
2636 #endif /* IEEE8021X_EAPOL */
2638 ssid
->dot11MeshMaxRetries
= DEFAULT_MESH_MAX_RETRIES
;
2639 ssid
->dot11MeshRetryTimeout
= DEFAULT_MESH_RETRY_TIMEOUT
;
2640 ssid
->dot11MeshConfirmTimeout
= DEFAULT_MESH_CONFIRM_TIMEOUT
;
2641 ssid
->dot11MeshHoldingTimeout
= DEFAULT_MESH_HOLDING_TIMEOUT
;
2642 #endif /* CONFIG_MESH */
2643 #ifdef CONFIG_HT_OVERRIDES
2644 ssid
->disable_ht
= DEFAULT_DISABLE_HT
;
2645 ssid
->disable_ht40
= DEFAULT_DISABLE_HT40
;
2646 ssid
->disable_sgi
= DEFAULT_DISABLE_SGI
;
2647 ssid
->disable_ldpc
= DEFAULT_DISABLE_LDPC
;
2648 ssid
->disable_max_amsdu
= DEFAULT_DISABLE_MAX_AMSDU
;
2649 ssid
->ampdu_factor
= DEFAULT_AMPDU_FACTOR
;
2650 ssid
->ampdu_density
= DEFAULT_AMPDU_DENSITY
;
2651 #endif /* CONFIG_HT_OVERRIDES */
2652 #ifdef CONFIG_VHT_OVERRIDES
2653 ssid
->vht_rx_mcs_nss_1
= -1;
2654 ssid
->vht_rx_mcs_nss_2
= -1;
2655 ssid
->vht_rx_mcs_nss_3
= -1;
2656 ssid
->vht_rx_mcs_nss_4
= -1;
2657 ssid
->vht_rx_mcs_nss_5
= -1;
2658 ssid
->vht_rx_mcs_nss_6
= -1;
2659 ssid
->vht_rx_mcs_nss_7
= -1;
2660 ssid
->vht_rx_mcs_nss_8
= -1;
2661 ssid
->vht_tx_mcs_nss_1
= -1;
2662 ssid
->vht_tx_mcs_nss_2
= -1;
2663 ssid
->vht_tx_mcs_nss_3
= -1;
2664 ssid
->vht_tx_mcs_nss_4
= -1;
2665 ssid
->vht_tx_mcs_nss_5
= -1;
2666 ssid
->vht_tx_mcs_nss_6
= -1;
2667 ssid
->vht_tx_mcs_nss_7
= -1;
2668 ssid
->vht_tx_mcs_nss_8
= -1;
2669 #endif /* CONFIG_VHT_OVERRIDES */
2670 ssid
->proactive_key_caching
= -1;
2671 #ifdef CONFIG_IEEE80211W
2672 ssid
->ieee80211w
= MGMT_FRAME_PROTECTION_DEFAULT
;
2673 #endif /* CONFIG_IEEE80211W */
2674 #ifdef CONFIG_MACSEC
2675 ssid
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
2676 #endif /* CONFIG_MACSEC */
2677 ssid
->mac_addr
= -1;
2682 * wpa_config_set - Set a variable in network configuration
2683 * @ssid: Pointer to network configuration data
2684 * @var: Variable name, e.g., "ssid"
2685 * @value: Variable value
2686 * @line: Line number in configuration file or 0 if not used
2687 * Returns: 0 on success with possible change in the value, 1 on success with
2688 * no change to previously configured value, or -1 on failure
2690 * This function can be used to set network configuration variables based on
2691 * both the configuration file and management interface input. The value
2692 * parameter must be in the same format as the text-based configuration file is
2693 * using. For example, strings are using double quotation marks.
2695 int wpa_config_set(struct wpa_ssid
*ssid
, const char *var
, const char *value
,
2701 if (ssid
== NULL
|| var
== NULL
|| value
== NULL
)
2704 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2705 const struct parse_data
*field
= &ssid_fields
[i
];
2706 if (os_strcmp(var
, field
->name
) != 0)
2709 ret
= field
->parser(field
, ssid
, line
, value
);
2712 wpa_printf(MSG_ERROR
, "Line %d: failed to "
2713 "parse %s '%s'.", line
, var
, value
);
2719 if (i
== NUM_SSID_FIELDS
) {
2721 wpa_printf(MSG_ERROR
, "Line %d: unknown network field "
2722 "'%s'.", line
, var
);
2731 int wpa_config_set_quoted(struct wpa_ssid
*ssid
, const char *var
,
2738 len
= os_strlen(value
);
2739 buf
= os_malloc(len
+ 3);
2743 os_memcpy(buf
+ 1, value
, len
);
2745 buf
[len
+ 2] = '\0';
2746 ret
= wpa_config_set(ssid
, var
, buf
, 0);
2753 * wpa_config_get_all - Get all options from network configuration
2754 * @ssid: Pointer to network configuration data
2755 * @get_keys: Determines if keys/passwords will be included in returned list
2756 * (if they may be exported)
2757 * Returns: %NULL terminated list of all set keys and their values in the form
2758 * of [key1, val1, key2, val2, ... , NULL]
2760 * This function can be used to get list of all configured network properties.
2761 * The caller is responsible for freeing the returned list and all its
2764 char ** wpa_config_get_all(struct wpa_ssid
*ssid
, int get_keys
)
2766 #ifdef NO_CONFIG_WRITE
2768 #else /* NO_CONFIG_WRITE */
2769 const struct parse_data
*field
;
2775 get_keys
= get_keys
&& ssid
->export_keys
;
2777 props
= os_calloc(2 * NUM_SSID_FIELDS
+ 1, sizeof(char *));
2782 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2783 field
= &ssid_fields
[i
];
2784 if (field
->key_data
&& !get_keys
)
2786 value
= field
->writer(field
, ssid
);
2789 if (os_strlen(value
) == 0) {
2794 key
= os_strdup(field
->name
);
2800 props
[fields_num
* 2] = key
;
2801 props
[fields_num
* 2 + 1] = value
;
2809 for (i
= 0; props
[i
]; i
++)
2813 #endif /* NO_CONFIG_WRITE */
2817 #ifndef NO_CONFIG_WRITE
2819 * wpa_config_get - Get a variable in network configuration
2820 * @ssid: Pointer to network configuration data
2821 * @var: Variable name, e.g., "ssid"
2822 * Returns: Value of the variable or %NULL on failure
2824 * This function can be used to get network configuration variables. The
2825 * returned value is a copy of the configuration variable in text format, i.e,.
2826 * the same format that the text-based configuration file and wpa_config_set()
2827 * are using for the value. The caller is responsible for freeing the returned
2830 char * wpa_config_get(struct wpa_ssid
*ssid
, const char *var
)
2834 if (ssid
== NULL
|| var
== NULL
)
2837 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2838 const struct parse_data
*field
= &ssid_fields
[i
];
2839 if (os_strcmp(var
, field
->name
) == 0) {
2840 char *ret
= field
->writer(field
, ssid
);
2842 if (ret
&& has_newline(ret
)) {
2843 wpa_printf(MSG_ERROR
,
2844 "Found newline in value for %s; not returning it",
2859 * wpa_config_get_no_key - Get a variable in network configuration (no keys)
2860 * @ssid: Pointer to network configuration data
2861 * @var: Variable name, e.g., "ssid"
2862 * Returns: Value of the variable or %NULL on failure
2864 * This function can be used to get network configuration variable like
2865 * wpa_config_get(). The only difference is that this functions does not expose
2866 * key/password material from the configuration. In case a key/password field
2867 * is requested, the returned value is an empty string or %NULL if the variable
2868 * is not set or "*" if the variable is set (regardless of its value). The
2869 * returned value is a copy of the configuration variable in text format, i.e,.
2870 * the same format that the text-based configuration file and wpa_config_set()
2871 * are using for the value. The caller is responsible for freeing the returned
2874 char * wpa_config_get_no_key(struct wpa_ssid
*ssid
, const char *var
)
2878 if (ssid
== NULL
|| var
== NULL
)
2881 for (i
= 0; i
< NUM_SSID_FIELDS
; i
++) {
2882 const struct parse_data
*field
= &ssid_fields
[i
];
2883 if (os_strcmp(var
, field
->name
) == 0) {
2884 char *res
= field
->writer(field
, ssid
);
2885 if (field
->key_data
) {
2886 if (res
&& res
[0]) {
2887 wpa_printf(MSG_DEBUG
, "Do not allow "
2888 "key_data field to be "
2890 str_clear_free(res
);
2891 return os_strdup("*");
2903 #endif /* NO_CONFIG_WRITE */
2907 * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
2908 * @ssid: Pointer to network configuration data
2910 * This function must be called to update WPA PSK when either SSID or the
2911 * passphrase has changed for the network configuration.
2913 void wpa_config_update_psk(struct wpa_ssid
*ssid
)
2915 #ifndef CONFIG_NO_PBKDF2
2916 pbkdf2_sha1(ssid
->passphrase
, ssid
->ssid
, ssid
->ssid_len
, 4096,
2917 ssid
->psk
, PMK_LEN
);
2918 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
2919 ssid
->psk
, PMK_LEN
);
2921 #endif /* CONFIG_NO_PBKDF2 */
2925 static int wpa_config_set_cred_req_conn_capab(struct wpa_cred
*cred
,
2930 int *ports
, *nports
;
2932 unsigned int num_ports
;
2934 proto
= os_realloc_array(cred
->req_conn_capab_proto
,
2935 cred
->num_req_conn_capab
+ 1, sizeof(u8
));
2938 cred
->req_conn_capab_proto
= proto
;
2940 port
= os_realloc_array(cred
->req_conn_capab_port
,
2941 cred
->num_req_conn_capab
+ 1, sizeof(int *));
2944 cred
->req_conn_capab_port
= port
;
2946 proto
[cred
->num_req_conn_capab
] = atoi(value
);
2948 pos
= os_strchr(value
, ':');
2950 port
[cred
->num_req_conn_capab
] = NULL
;
2951 cred
->num_req_conn_capab
++;
2960 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
2961 if (nports
== NULL
) {
2966 ports
[num_ports
++] = atoi(pos
);
2968 pos
= os_strchr(pos
, ',');
2974 nports
= os_realloc_array(ports
, num_ports
+ 1, sizeof(int));
2975 if (nports
== NULL
) {
2980 ports
[num_ports
] = -1;
2982 port
[cred
->num_req_conn_capab
] = ports
;
2983 cred
->num_req_conn_capab
++;
2988 int wpa_config_set_cred(struct wpa_cred
*cred
, const char *var
,
2989 const char *value
, int line
)
2994 if (os_strcmp(var
, "temporary") == 0) {
2995 cred
->temporary
= atoi(value
);
2999 if (os_strcmp(var
, "priority") == 0) {
3000 cred
->priority
= atoi(value
);
3004 if (os_strcmp(var
, "sp_priority") == 0) {
3005 int prio
= atoi(value
);
3006 if (prio
< 0 || prio
> 255)
3008 cred
->sp_priority
= prio
;
3012 if (os_strcmp(var
, "pcsc") == 0) {
3013 cred
->pcsc
= atoi(value
);
3017 if (os_strcmp(var
, "eap") == 0) {
3018 struct eap_method_type method
;
3019 method
.method
= eap_peer_get_type(value
, &method
.vendor
);
3020 if (method
.vendor
== EAP_VENDOR_IETF
&&
3021 method
.method
== EAP_TYPE_NONE
) {
3022 wpa_printf(MSG_ERROR
, "Line %d: unknown EAP type '%s' "
3023 "for a credential", line
, value
);
3026 os_free(cred
->eap_method
);
3027 cred
->eap_method
= os_malloc(sizeof(*cred
->eap_method
));
3028 if (cred
->eap_method
== NULL
)
3030 os_memcpy(cred
->eap_method
, &method
, sizeof(method
));
3034 if (os_strcmp(var
, "password") == 0 &&
3035 os_strncmp(value
, "ext:", 4) == 0) {
3036 if (has_newline(value
))
3038 str_clear_free(cred
->password
);
3039 cred
->password
= os_strdup(value
);
3040 cred
->ext_password
= 1;
3044 if (os_strcmp(var
, "update_identifier") == 0) {
3045 cred
->update_identifier
= atoi(value
);
3049 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0) {
3050 cred
->min_dl_bandwidth_home
= atoi(value
);
3054 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0) {
3055 cred
->min_ul_bandwidth_home
= atoi(value
);
3059 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0) {
3060 cred
->min_dl_bandwidth_roaming
= atoi(value
);
3064 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0) {
3065 cred
->min_ul_bandwidth_roaming
= atoi(value
);
3069 if (os_strcmp(var
, "max_bss_load") == 0) {
3070 cred
->max_bss_load
= atoi(value
);
3074 if (os_strcmp(var
, "req_conn_capab") == 0)
3075 return wpa_config_set_cred_req_conn_capab(cred
, value
);
3077 if (os_strcmp(var
, "ocsp") == 0) {
3078 cred
->ocsp
= atoi(value
);
3082 if (os_strcmp(var
, "sim_num") == 0) {
3083 cred
->sim_num
= atoi(value
);
3087 val
= wpa_config_parse_string(value
, &len
);
3089 (os_strcmp(var
, "excluded_ssid") != 0 &&
3090 os_strcmp(var
, "roaming_consortium") != 0 &&
3091 os_strcmp(var
, "required_roaming_consortium") != 0 &&
3092 has_newline(val
))) {
3093 wpa_printf(MSG_ERROR
, "Line %d: invalid field '%s' string "
3094 "value '%s'.", line
, var
, value
);
3099 if (os_strcmp(var
, "realm") == 0) {
3100 os_free(cred
->realm
);
3105 if (os_strcmp(var
, "username") == 0) {
3106 str_clear_free(cred
->username
);
3107 cred
->username
= val
;
3111 if (os_strcmp(var
, "password") == 0) {
3112 str_clear_free(cred
->password
);
3113 cred
->password
= val
;
3114 cred
->ext_password
= 0;
3118 if (os_strcmp(var
, "ca_cert") == 0) {
3119 os_free(cred
->ca_cert
);
3120 cred
->ca_cert
= val
;
3124 if (os_strcmp(var
, "client_cert") == 0) {
3125 os_free(cred
->client_cert
);
3126 cred
->client_cert
= val
;
3130 if (os_strcmp(var
, "private_key") == 0) {
3131 os_free(cred
->private_key
);
3132 cred
->private_key
= val
;
3136 if (os_strcmp(var
, "private_key_passwd") == 0) {
3137 str_clear_free(cred
->private_key_passwd
);
3138 cred
->private_key_passwd
= val
;
3142 if (os_strcmp(var
, "imsi") == 0) {
3143 os_free(cred
->imsi
);
3148 if (os_strcmp(var
, "milenage") == 0) {
3149 str_clear_free(cred
->milenage
);
3150 cred
->milenage
= val
;
3154 if (os_strcmp(var
, "domain_suffix_match") == 0) {
3155 os_free(cred
->domain_suffix_match
);
3156 cred
->domain_suffix_match
= val
;
3160 if (os_strcmp(var
, "domain") == 0) {
3162 new_domain
= os_realloc_array(cred
->domain
,
3163 cred
->num_domain
+ 1,
3165 if (new_domain
== NULL
) {
3169 new_domain
[cred
->num_domain
++] = val
;
3170 cred
->domain
= new_domain
;
3174 if (os_strcmp(var
, "phase1") == 0) {
3175 os_free(cred
->phase1
);
3180 if (os_strcmp(var
, "phase2") == 0) {
3181 os_free(cred
->phase2
);
3186 if (os_strcmp(var
, "roaming_consortium") == 0) {
3187 if (len
< 3 || len
> sizeof(cred
->roaming_consortium
)) {
3188 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3189 "roaming_consortium length %d (3..15 "
3190 "expected)", line
, (int) len
);
3194 os_memcpy(cred
->roaming_consortium
, val
, len
);
3195 cred
->roaming_consortium_len
= len
;
3200 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3201 if (len
< 3 || len
> sizeof(cred
->required_roaming_consortium
))
3203 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3204 "required_roaming_consortium length %d "
3205 "(3..15 expected)", line
, (int) len
);
3209 os_memcpy(cred
->required_roaming_consortium
, val
, len
);
3210 cred
->required_roaming_consortium_len
= len
;
3215 if (os_strcmp(var
, "excluded_ssid") == 0) {
3216 struct excluded_ssid
*e
;
3218 if (len
> SSID_MAX_LEN
) {
3219 wpa_printf(MSG_ERROR
, "Line %d: invalid "
3220 "excluded_ssid length %d", line
, (int) len
);
3225 e
= os_realloc_array(cred
->excluded_ssid
,
3226 cred
->num_excluded_ssid
+ 1,
3227 sizeof(struct excluded_ssid
));
3232 cred
->excluded_ssid
= e
;
3234 e
= &cred
->excluded_ssid
[cred
->num_excluded_ssid
++];
3235 os_memcpy(e
->ssid
, val
, len
);
3243 if (os_strcmp(var
, "roaming_partner") == 0) {
3244 struct roaming_partner
*p
;
3247 p
= os_realloc_array(cred
->roaming_partner
,
3248 cred
->num_roaming_partner
+ 1,
3249 sizeof(struct roaming_partner
));
3254 cred
->roaming_partner
= p
;
3256 p
= &cred
->roaming_partner
[cred
->num_roaming_partner
];
3258 pos
= os_strchr(val
, ',');
3264 if (pos
- val
- 1 >= (int) sizeof(p
->fqdn
)) {
3268 os_memcpy(p
->fqdn
, val
, pos
- val
);
3270 p
->exact_match
= atoi(pos
);
3272 pos
= os_strchr(pos
, ',');
3279 p
->priority
= atoi(pos
);
3281 pos
= os_strchr(pos
, ',');
3288 if (os_strlen(pos
) >= sizeof(p
->country
)) {
3292 os_memcpy(p
->country
, pos
, os_strlen(pos
) + 1);
3294 cred
->num_roaming_partner
++;
3300 if (os_strcmp(var
, "provisioning_sp") == 0) {
3301 os_free(cred
->provisioning_sp
);
3302 cred
->provisioning_sp
= val
;
3307 wpa_printf(MSG_ERROR
, "Line %d: unknown cred field '%s'.",
3317 static char * alloc_int_str(int val
)
3319 const unsigned int bufsize
= 20;
3323 buf
= os_malloc(bufsize
);
3326 res
= os_snprintf(buf
, bufsize
, "%d", val
);
3327 if (os_snprintf_error(bufsize
, res
)) {
3335 static char * alloc_strdup(const char *str
)
3339 return os_strdup(str
);
3343 char * wpa_config_get_cred_no_key(struct wpa_cred
*cred
, const char *var
)
3345 if (os_strcmp(var
, "temporary") == 0)
3346 return alloc_int_str(cred
->temporary
);
3348 if (os_strcmp(var
, "priority") == 0)
3349 return alloc_int_str(cred
->priority
);
3351 if (os_strcmp(var
, "sp_priority") == 0)
3352 return alloc_int_str(cred
->sp_priority
);
3354 if (os_strcmp(var
, "pcsc") == 0)
3355 return alloc_int_str(cred
->pcsc
);
3357 if (os_strcmp(var
, "eap") == 0) {
3358 if (!cred
->eap_method
)
3360 return alloc_strdup(eap_get_name(cred
->eap_method
[0].vendor
,
3361 cred
->eap_method
[0].method
));
3364 if (os_strcmp(var
, "update_identifier") == 0)
3365 return alloc_int_str(cred
->update_identifier
);
3367 if (os_strcmp(var
, "min_dl_bandwidth_home") == 0)
3368 return alloc_int_str(cred
->min_dl_bandwidth_home
);
3370 if (os_strcmp(var
, "min_ul_bandwidth_home") == 0)
3371 return alloc_int_str(cred
->min_ul_bandwidth_home
);
3373 if (os_strcmp(var
, "min_dl_bandwidth_roaming") == 0)
3374 return alloc_int_str(cred
->min_dl_bandwidth_roaming
);
3376 if (os_strcmp(var
, "min_ul_bandwidth_roaming") == 0)
3377 return alloc_int_str(cred
->min_ul_bandwidth_roaming
);
3379 if (os_strcmp(var
, "max_bss_load") == 0)
3380 return alloc_int_str(cred
->max_bss_load
);
3382 if (os_strcmp(var
, "req_conn_capab") == 0) {
3384 char *buf
, *end
, *pos
;
3387 if (!cred
->num_req_conn_capab
)
3390 buf
= os_malloc(4000);
3395 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
3398 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
3400 cred
->req_conn_capab_proto
[i
]);
3401 if (os_snprintf_error(end
- pos
, ret
))
3405 ports
= cred
->req_conn_capab_port
[i
];
3408 for (j
= 0; ports
[j
] != -1; j
++) {
3409 ret
= os_snprintf(pos
, end
- pos
,
3413 if (os_snprintf_error(end
- pos
, ret
))
3423 if (os_strcmp(var
, "ocsp") == 0)
3424 return alloc_int_str(cred
->ocsp
);
3426 if (os_strcmp(var
, "realm") == 0)
3427 return alloc_strdup(cred
->realm
);
3429 if (os_strcmp(var
, "username") == 0)
3430 return alloc_strdup(cred
->username
);
3432 if (os_strcmp(var
, "password") == 0) {
3433 if (!cred
->password
)
3435 return alloc_strdup("*");
3438 if (os_strcmp(var
, "ca_cert") == 0)
3439 return alloc_strdup(cred
->ca_cert
);
3441 if (os_strcmp(var
, "client_cert") == 0)
3442 return alloc_strdup(cred
->client_cert
);
3444 if (os_strcmp(var
, "private_key") == 0)
3445 return alloc_strdup(cred
->private_key
);
3447 if (os_strcmp(var
, "private_key_passwd") == 0) {
3448 if (!cred
->private_key_passwd
)
3450 return alloc_strdup("*");
3453 if (os_strcmp(var
, "imsi") == 0)
3454 return alloc_strdup(cred
->imsi
);
3456 if (os_strcmp(var
, "milenage") == 0) {
3457 if (!(cred
->milenage
))
3459 return alloc_strdup("*");
3462 if (os_strcmp(var
, "domain_suffix_match") == 0)
3463 return alloc_strdup(cred
->domain_suffix_match
);
3465 if (os_strcmp(var
, "domain") == 0) {
3467 char *buf
, *end
, *pos
;
3470 if (!cred
->num_domain
)
3473 buf
= os_malloc(4000);
3479 for (i
= 0; i
< cred
->num_domain
; i
++) {
3480 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3481 i
> 0 ? "\n" : "", cred
->domain
[i
]);
3482 if (os_snprintf_error(end
- pos
, ret
))
3490 if (os_strcmp(var
, "phase1") == 0)
3491 return alloc_strdup(cred
->phase1
);
3493 if (os_strcmp(var
, "phase2") == 0)
3494 return alloc_strdup(cred
->phase2
);
3496 if (os_strcmp(var
, "roaming_consortium") == 0) {
3500 if (!cred
->roaming_consortium_len
)
3502 buflen
= cred
->roaming_consortium_len
* 2 + 1;
3503 buf
= os_malloc(buflen
);
3506 wpa_snprintf_hex(buf
, buflen
, cred
->roaming_consortium
,
3507 cred
->roaming_consortium_len
);
3511 if (os_strcmp(var
, "required_roaming_consortium") == 0) {
3515 if (!cred
->required_roaming_consortium_len
)
3517 buflen
= cred
->required_roaming_consortium_len
* 2 + 1;
3518 buf
= os_malloc(buflen
);
3521 wpa_snprintf_hex(buf
, buflen
, cred
->required_roaming_consortium
,
3522 cred
->required_roaming_consortium_len
);
3526 if (os_strcmp(var
, "excluded_ssid") == 0) {
3528 char *buf
, *end
, *pos
;
3530 if (!cred
->num_excluded_ssid
)
3533 buf
= os_malloc(4000);
3539 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
3540 struct excluded_ssid
*e
;
3543 e
= &cred
->excluded_ssid
[i
];
3544 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3546 wpa_ssid_txt(e
->ssid
, e
->ssid_len
));
3547 if (os_snprintf_error(end
- pos
, ret
))
3555 if (os_strcmp(var
, "roaming_partner") == 0) {
3557 char *buf
, *end
, *pos
;
3559 if (!cred
->num_roaming_partner
)
3562 buf
= os_malloc(4000);
3568 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
3569 struct roaming_partner
*p
;
3572 p
= &cred
->roaming_partner
[i
];
3573 ret
= os_snprintf(pos
, end
- pos
, "%s%s,%d,%u,%s",
3575 p
->fqdn
, p
->exact_match
, p
->priority
,
3577 if (os_snprintf_error(end
- pos
, ret
))
3585 if (os_strcmp(var
, "provisioning_sp") == 0)
3586 return alloc_strdup(cred
->provisioning_sp
);
3592 struct wpa_cred
* wpa_config_get_cred(struct wpa_config
*config
, int id
)
3594 struct wpa_cred
*cred
;
3596 cred
= config
->cred
;
3607 struct wpa_cred
* wpa_config_add_cred(struct wpa_config
*config
)
3610 struct wpa_cred
*cred
, *last
= NULL
;
3613 cred
= config
->cred
;
3622 cred
= os_zalloc(sizeof(*cred
));
3626 cred
->sim_num
= DEFAULT_USER_SELECTED_SIM
;
3630 config
->cred
= cred
;
3636 int wpa_config_remove_cred(struct wpa_config
*config
, int id
)
3638 struct wpa_cred
*cred
, *prev
= NULL
;
3640 cred
= config
->cred
;
3652 prev
->next
= cred
->next
;
3654 config
->cred
= cred
->next
;
3656 wpa_config_free_cred(cred
);
3661 #ifndef CONFIG_NO_CONFIG_BLOBS
3663 * wpa_config_get_blob - Get a named configuration blob
3664 * @config: Configuration data from wpa_config_read()
3665 * @name: Name of the blob
3666 * Returns: Pointer to blob data or %NULL if not found
3668 const struct wpa_config_blob
* wpa_config_get_blob(struct wpa_config
*config
,
3671 struct wpa_config_blob
*blob
= config
->blobs
;
3674 if (os_strcmp(blob
->name
, name
) == 0)
3683 * wpa_config_set_blob - Set or add a named configuration blob
3684 * @config: Configuration data from wpa_config_read()
3685 * @blob: New value for the blob
3687 * Adds a new configuration blob or replaces the current value of an existing
3690 void wpa_config_set_blob(struct wpa_config
*config
,
3691 struct wpa_config_blob
*blob
)
3693 wpa_config_remove_blob(config
, blob
->name
);
3694 blob
->next
= config
->blobs
;
3695 config
->blobs
= blob
;
3700 * wpa_config_free_blob - Free blob data
3701 * @blob: Pointer to blob to be freed
3703 void wpa_config_free_blob(struct wpa_config_blob
*blob
)
3706 os_free(blob
->name
);
3707 bin_clear_free(blob
->data
, blob
->len
);
3714 * wpa_config_remove_blob - Remove a named configuration blob
3715 * @config: Configuration data from wpa_config_read()
3716 * @name: Name of the blob to remove
3717 * Returns: 0 if blob was removed or -1 if blob was not found
3719 int wpa_config_remove_blob(struct wpa_config
*config
, const char *name
)
3721 struct wpa_config_blob
*pos
= config
->blobs
, *prev
= NULL
;
3724 if (os_strcmp(pos
->name
, name
) == 0) {
3726 prev
->next
= pos
->next
;
3728 config
->blobs
= pos
->next
;
3729 wpa_config_free_blob(pos
);
3738 #endif /* CONFIG_NO_CONFIG_BLOBS */
3742 * wpa_config_alloc_empty - Allocate an empty configuration
3743 * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
3745 * @driver_param: Driver parameters
3746 * Returns: Pointer to allocated configuration data or %NULL on failure
3748 struct wpa_config
* wpa_config_alloc_empty(const char *ctrl_interface
,
3749 const char *driver_param
)
3751 struct wpa_config
*config
;
3752 const int aCWmin
= 4, aCWmax
= 10;
3753 const struct hostapd_wmm_ac_params ac_bk
=
3754 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
3755 const struct hostapd_wmm_ac_params ac_be
=
3756 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
3757 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
3758 { aCWmin
- 1, aCWmin
, 2, 3000 / 32, 0 };
3759 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
3760 { aCWmin
- 2, aCWmin
- 1, 2, 1500 / 32, 0 };
3762 config
= os_zalloc(sizeof(*config
));
3765 config
->eapol_version
= DEFAULT_EAPOL_VERSION
;
3766 config
->ap_scan
= DEFAULT_AP_SCAN
;
3767 config
->user_mpm
= DEFAULT_USER_MPM
;
3768 config
->max_peer_links
= DEFAULT_MAX_PEER_LINKS
;
3769 config
->mesh_max_inactivity
= DEFAULT_MESH_MAX_INACTIVITY
;
3770 config
->dot11RSNASAERetransPeriod
=
3771 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD
;
3772 config
->fast_reauth
= DEFAULT_FAST_REAUTH
;
3773 config
->p2p_go_intent
= DEFAULT_P2P_GO_INTENT
;
3774 config
->p2p_intra_bss
= DEFAULT_P2P_INTRA_BSS
;
3775 config
->p2p_go_freq_change_policy
= DEFAULT_P2P_GO_FREQ_MOVE
;
3776 config
->p2p_go_max_inactivity
= DEFAULT_P2P_GO_MAX_INACTIVITY
;
3777 config
->p2p_optimize_listen_chan
= DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN
;
3778 config
->p2p_go_ctwindow
= DEFAULT_P2P_GO_CTWINDOW
;
3779 config
->bss_max_count
= DEFAULT_BSS_MAX_COUNT
;
3780 config
->bss_expiration_age
= DEFAULT_BSS_EXPIRATION_AGE
;
3781 config
->bss_expiration_scan_count
= DEFAULT_BSS_EXPIRATION_SCAN_COUNT
;
3782 config
->max_num_sta
= DEFAULT_MAX_NUM_STA
;
3783 config
->access_network_type
= DEFAULT_ACCESS_NETWORK_TYPE
;
3784 config
->scan_cur_freq
= DEFAULT_SCAN_CUR_FREQ
;
3785 config
->wmm_ac_params
[0] = ac_be
;
3786 config
->wmm_ac_params
[1] = ac_bk
;
3787 config
->wmm_ac_params
[2] = ac_vi
;
3788 config
->wmm_ac_params
[3] = ac_vo
;
3789 config
->p2p_search_delay
= DEFAULT_P2P_SEARCH_DELAY
;
3790 config
->rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
3791 config
->key_mgmt_offload
= DEFAULT_KEY_MGMT_OFFLOAD
;
3792 config
->cert_in_cb
= DEFAULT_CERT_IN_CB
;
3793 config
->wpa_rsc_relaxation
= DEFAULT_WPA_RSC_RELAXATION
;
3796 config
->mbo_cell_capa
= DEFAULT_MBO_CELL_CAPA
;
3797 config
->disassoc_imminent_rssi_threshold
=
3798 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD
;
3799 #endif /* CONFIG_MBO */
3802 config
->ctrl_interface
= os_strdup(ctrl_interface
);
3804 config
->driver_param
= os_strdup(driver_param
);
3805 config
->gas_rand_addr_lifetime
= DEFAULT_RAND_ADDR_LIFETIME
;
3811 #ifndef CONFIG_NO_STDOUT_DEBUG
3813 * wpa_config_debug_dump_networks - Debug dump of configured networks
3814 * @config: Configuration data from wpa_config_read()
3816 void wpa_config_debug_dump_networks(struct wpa_config
*config
)
3819 struct wpa_ssid
*ssid
;
3821 for (prio
= 0; prio
< config
->num_prio
; prio
++) {
3822 ssid
= config
->pssid
[prio
];
3823 wpa_printf(MSG_DEBUG
, "Priority group %d",
3826 wpa_printf(MSG_DEBUG
, " id=%d ssid='%s'",
3828 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
3833 #endif /* CONFIG_NO_STDOUT_DEBUG */
3836 struct global_parse_data
{
3838 int (*parser
)(const struct global_parse_data
*data
,
3839 struct wpa_config
*config
, int line
, const char *value
);
3840 int (*get
)(const char *name
, struct wpa_config
*config
, long offset
,
3841 char *buf
, size_t buflen
, int pretty_print
);
3842 void *param1
, *param2
, *param3
;
3843 unsigned int changed_flag
;
3847 static int wpa_global_config_parse_int(const struct global_parse_data
*data
,
3848 struct wpa_config
*config
, int line
,
3854 dst
= (int *) (((u8
*) config
) + (long) data
->param1
);
3855 val
= strtol(pos
, &end
, 0);
3857 wpa_printf(MSG_ERROR
, "Line %d: invalid number \"%s\"",
3863 wpa_printf(MSG_DEBUG
, "%s=%d", data
->name
, *dst
);
3865 if (data
->param2
&& *dst
< (long) data
->param2
) {
3866 wpa_printf(MSG_ERROR
, "Line %d: too small %s (value=%d "
3867 "min_value=%ld)", line
, data
->name
, *dst
,
3868 (long) data
->param2
);
3869 *dst
= (long) data
->param2
;
3873 if (data
->param3
&& *dst
> (long) data
->param3
) {
3874 wpa_printf(MSG_ERROR
, "Line %d: too large %s (value=%d "
3875 "max_value=%ld)", line
, data
->name
, *dst
,
3876 (long) data
->param3
);
3877 *dst
= (long) data
->param3
;
3885 static int wpa_global_config_parse_str(const struct global_parse_data
*data
,
3886 struct wpa_config
*config
, int line
,
3892 len
= os_strlen(pos
);
3893 if (data
->param2
&& len
< (size_t) data
->param2
) {
3894 wpa_printf(MSG_ERROR
, "Line %d: too short %s (len=%lu "
3895 "min_len=%ld)", line
, data
->name
,
3896 (unsigned long) len
, (long) data
->param2
);
3900 if (data
->param3
&& len
> (size_t) data
->param3
) {
3901 wpa_printf(MSG_ERROR
, "Line %d: too long %s (len=%lu "
3902 "max_len=%ld)", line
, data
->name
,
3903 (unsigned long) len
, (long) data
->param3
);
3907 if (has_newline(pos
)) {
3908 wpa_printf(MSG_ERROR
, "Line %d: invalid %s value with newline",
3913 tmp
= os_strdup(pos
);
3917 dst
= (char **) (((u8
*) config
) + (long) data
->param1
);
3920 wpa_printf(MSG_DEBUG
, "%s='%s'", data
->name
, *dst
);
3926 static int wpa_config_process_bgscan(const struct global_parse_data
*data
,
3927 struct wpa_config
*config
, int line
,
3934 tmp
= wpa_config_parse_string(pos
, &len
);
3936 wpa_printf(MSG_ERROR
, "Line %d: failed to parse %s",
3941 res
= wpa_global_config_parse_str(data
, config
, line
, tmp
);
3947 static int wpa_global_config_parse_bin(const struct global_parse_data
*data
,
3948 struct wpa_config
*config
, int line
,
3951 struct wpabuf
**dst
, *tmp
;
3953 tmp
= wpabuf_parse_bin(pos
);
3957 dst
= (struct wpabuf
**) (((u8
*) config
) + (long) data
->param1
);
3960 wpa_printf(MSG_DEBUG
, "%s", data
->name
);
3966 static int wpa_config_process_freq_list(const struct global_parse_data
*data
,
3967 struct wpa_config
*config
, int line
,
3972 freqs
= wpa_config_parse_int_array(value
);
3975 if (freqs
[0] == 0) {
3979 os_free(config
->freq_list
);
3980 config
->freq_list
= freqs
;
3986 static int wpa_global_config_parse_ipv4(const struct global_parse_data
*data
,
3987 struct wpa_config
*config
, int line
,
3991 struct hostapd_ip_addr addr
;
3993 if (hostapd_parse_ip_addr(pos
, &addr
) < 0)
3995 if (addr
.af
!= AF_INET
)
3998 dst
= (u32
*) (((u8
*) config
) + (long) data
->param1
);
3999 os_memcpy(dst
, &addr
.u
.v4
.s_addr
, 4);
4000 wpa_printf(MSG_DEBUG
, "%s = 0x%x", data
->name
,
4001 WPA_GET_BE32((u8
*) dst
));
4005 #endif /* CONFIG_P2P */
4008 static int wpa_config_process_country(const struct global_parse_data
*data
,
4009 struct wpa_config
*config
, int line
,
4012 if (!pos
[0] || !pos
[1]) {
4013 wpa_printf(MSG_DEBUG
, "Invalid country set");
4016 config
->country
[0] = pos
[0];
4017 config
->country
[1] = pos
[1];
4018 wpa_printf(MSG_DEBUG
, "country='%c%c'",
4019 config
->country
[0], config
->country
[1]);
4024 static int wpa_config_process_load_dynamic_eap(
4025 const struct global_parse_data
*data
, struct wpa_config
*config
,
4026 int line
, const char *so
)
4029 wpa_printf(MSG_DEBUG
, "load_dynamic_eap=%s", so
);
4030 ret
= eap_peer_method_load(so
);
4032 wpa_printf(MSG_DEBUG
, "This EAP type was already loaded - not "
4035 wpa_printf(MSG_ERROR
, "Line %d: Failed to load dynamic EAP "
4036 "method '%s'.", line
, so
);
4046 static int wpa_config_process_uuid(const struct global_parse_data
*data
,
4047 struct wpa_config
*config
, int line
,
4051 if (uuid_str2bin(pos
, config
->uuid
)) {
4052 wpa_printf(MSG_ERROR
, "Line %d: invalid UUID", line
);
4055 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
4056 wpa_printf(MSG_DEBUG
, "uuid=%s", buf
);
4061 static int wpa_config_process_device_type(
4062 const struct global_parse_data
*data
,
4063 struct wpa_config
*config
, int line
, const char *pos
)
4065 return wps_dev_type_str2bin(pos
, config
->device_type
);
4069 static int wpa_config_process_os_version(const struct global_parse_data
*data
,
4070 struct wpa_config
*config
, int line
,
4073 if (hexstr2bin(pos
, config
->os_version
, 4)) {
4074 wpa_printf(MSG_ERROR
, "Line %d: invalid os_version", line
);
4077 wpa_printf(MSG_DEBUG
, "os_version=%08x",
4078 WPA_GET_BE32(config
->os_version
));
4083 static int wpa_config_process_wps_vendor_ext_m1(
4084 const struct global_parse_data
*data
,
4085 struct wpa_config
*config
, int line
, const char *pos
)
4088 int len
= os_strlen(pos
) / 2;
4092 wpa_printf(MSG_ERROR
, "Line %d: "
4093 "invalid wps_vendor_ext_m1", line
);
4097 tmp
= wpabuf_alloc(len
);
4099 p
= wpabuf_put(tmp
, len
);
4101 if (hexstr2bin(pos
, p
, len
)) {
4102 wpa_printf(MSG_ERROR
, "Line %d: "
4103 "invalid wps_vendor_ext_m1", line
);
4108 wpabuf_free(config
->wps_vendor_ext_m1
);
4109 config
->wps_vendor_ext_m1
= tmp
;
4111 wpa_printf(MSG_ERROR
, "Can not allocate "
4112 "memory for wps_vendor_ext_m1");
4119 #endif /* CONFIG_WPS */
4122 static int wpa_config_process_sec_device_type(
4123 const struct global_parse_data
*data
,
4124 struct wpa_config
*config
, int line
, const char *pos
)
4128 if (config
->num_sec_device_types
>= MAX_SEC_DEVICE_TYPES
) {
4129 wpa_printf(MSG_ERROR
, "Line %d: too many sec_device_type "
4134 idx
= config
->num_sec_device_types
;
4136 if (wps_dev_type_str2bin(pos
, config
->sec_device_type
[idx
]))
4139 config
->num_sec_device_types
++;
4144 static int wpa_config_process_p2p_pref_chan(
4145 const struct global_parse_data
*data
,
4146 struct wpa_config
*config
, int line
, const char *pos
)
4148 struct p2p_channel
*pref
= NULL
, *n
;
4149 unsigned int num
= 0;
4153 /* format: class:chan,class:chan,... */
4156 op_class
= atoi(pos
);
4157 pos2
= os_strchr(pos
, ':');
4163 n
= os_realloc_array(pref
, num
+ 1,
4164 sizeof(struct p2p_channel
));
4168 pref
[num
].op_class
= op_class
;
4169 pref
[num
].chan
= chan
;
4172 pos
= os_strchr(pos2
, ',');
4178 os_free(config
->p2p_pref_chan
);
4179 config
->p2p_pref_chan
= pref
;
4180 config
->num_p2p_pref_chan
= num
;
4181 wpa_hexdump(MSG_DEBUG
, "P2P: Preferred class/channel pairs",
4182 (u8
*) config
->p2p_pref_chan
,
4183 config
->num_p2p_pref_chan
* sizeof(struct p2p_channel
));
4189 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_pref_chan list", line
);
4194 static int wpa_config_process_p2p_no_go_freq(
4195 const struct global_parse_data
*data
,
4196 struct wpa_config
*config
, int line
, const char *pos
)
4200 ret
= freq_range_list_parse(&config
->p2p_no_go_freq
, pos
);
4202 wpa_printf(MSG_ERROR
, "Line %d: Invalid p2p_no_go_freq", line
);
4206 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_go_freq with %u items",
4207 config
->p2p_no_go_freq
.num
);
4212 #endif /* CONFIG_P2P */
4215 static int wpa_config_process_hessid(
4216 const struct global_parse_data
*data
,
4217 struct wpa_config
*config
, int line
, const char *pos
)
4219 if (hwaddr_aton2(pos
, config
->hessid
) < 0) {
4220 wpa_printf(MSG_ERROR
, "Line %d: Invalid hessid '%s'",
4229 static int wpa_config_process_sae_groups(
4230 const struct global_parse_data
*data
,
4231 struct wpa_config
*config
, int line
, const char *pos
)
4233 int *groups
= wpa_config_parse_int_array(pos
);
4234 if (groups
== NULL
) {
4235 wpa_printf(MSG_ERROR
, "Line %d: Invalid sae_groups '%s'",
4240 os_free(config
->sae_groups
);
4241 config
->sae_groups
= groups
;
4247 static int wpa_config_process_ap_vendor_elements(
4248 const struct global_parse_data
*data
,
4249 struct wpa_config
*config
, int line
, const char *pos
)
4252 int len
= os_strlen(pos
) / 2;
4256 wpa_printf(MSG_ERROR
, "Line %d: invalid ap_vendor_elements",
4261 tmp
= wpabuf_alloc(len
);
4263 p
= wpabuf_put(tmp
, len
);
4265 if (hexstr2bin(pos
, p
, len
)) {
4266 wpa_printf(MSG_ERROR
, "Line %d: invalid "
4267 "ap_vendor_elements", line
);
4272 wpabuf_free(config
->ap_vendor_elements
);
4273 config
->ap_vendor_elements
= tmp
;
4275 wpa_printf(MSG_ERROR
, "Cannot allocate memory for "
4276 "ap_vendor_elements");
4284 #ifdef CONFIG_CTRL_IFACE
4285 static int wpa_config_process_no_ctrl_interface(
4286 const struct global_parse_data
*data
,
4287 struct wpa_config
*config
, int line
, const char *pos
)
4289 wpa_printf(MSG_DEBUG
, "no_ctrl_interface -> ctrl_interface=NULL");
4290 os_free(config
->ctrl_interface
);
4291 config
->ctrl_interface
= NULL
;
4294 #endif /* CONFIG_CTRL_IFACE */
4297 static int wpa_config_get_int(const char *name
, struct wpa_config
*config
,
4298 long offset
, char *buf
, size_t buflen
,
4301 int *val
= (int *) (((u8
*) config
) + (long) offset
);
4304 return os_snprintf(buf
, buflen
, "%s=%d\n", name
, *val
);
4305 return os_snprintf(buf
, buflen
, "%d", *val
);
4309 static int wpa_config_get_str(const char *name
, struct wpa_config
*config
,
4310 long offset
, char *buf
, size_t buflen
,
4313 char **val
= (char **) (((u8
*) config
) + (long) offset
);
4317 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
,
4318 *val
? *val
: "null");
4322 res
= os_snprintf(buf
, buflen
, "%s", *val
);
4323 if (os_snprintf_error(buflen
, res
))
4331 static int wpa_config_get_ipv4(const char *name
, struct wpa_config
*config
,
4332 long offset
, char *buf
, size_t buflen
,
4335 void *val
= ((u8
*) config
) + (long) offset
;
4337 char addr
[INET_ADDRSTRLEN
];
4339 if (!val
|| !inet_ntop(AF_INET
, val
, addr
, sizeof(addr
)))
4343 res
= os_snprintf(buf
, buflen
, "%s=%s\n", name
, addr
);
4345 res
= os_snprintf(buf
, buflen
, "%s", addr
);
4347 if (os_snprintf_error(buflen
, res
))
4352 #endif /* CONFIG_P2P */
4358 /* OFFSET: Get offset of a variable within the wpa_config structure */
4359 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
4361 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
4362 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
4363 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
4364 #define INT(f) _INT(f), NULL, NULL
4365 #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
4366 #define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
4367 #define STR(f) _STR(f), NULL, NULL
4368 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
4369 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
4370 #define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4, \
4371 OFFSET(f), NULL, NULL
4373 static const struct global_parse_data global_fields
[] = {
4374 #ifdef CONFIG_CTRL_IFACE
4375 { STR(ctrl_interface
), 0 },
4376 { FUNC_NO_VAR(no_ctrl_interface
), 0 },
4377 { STR(ctrl_interface_group
), 0 } /* deprecated */,
4378 #endif /* CONFIG_CTRL_IFACE */
4379 #ifdef CONFIG_MACSEC
4380 { INT_RANGE(eapol_version
, 1, 3), 0 },
4381 #else /* CONFIG_MACSEC */
4382 { INT_RANGE(eapol_version
, 1, 2), 0 },
4383 #endif /* CONFIG_MACSEC */
4384 { INT(ap_scan
), 0 },
4385 { FUNC(bgscan
), 0 },
4387 { INT(user_mpm
), 0 },
4388 { INT_RANGE(max_peer_links
, 0, 255), 0 },
4389 { INT(mesh_max_inactivity
), 0 },
4390 { INT(dot11RSNASAERetransPeriod
), 0 },
4391 #endif /* CONFIG_MESH */
4392 { INT(disable_scan_offload
), 0 },
4393 { INT(fast_reauth
), 0 },
4394 { STR(opensc_engine_path
), 0 },
4395 { STR(pkcs11_engine_path
), 0 },
4396 { STR(pkcs11_module_path
), 0 },
4397 { STR(openssl_ciphers
), 0 },
4398 { STR(pcsc_reader
), 0 },
4399 { STR(pcsc_pin
), 0 },
4400 { INT(external_sim
), 0 },
4401 { STR(driver_param
), 0 },
4402 { INT(dot11RSNAConfigPMKLifetime
), 0 },
4403 { INT(dot11RSNAConfigPMKReauthThreshold
), 0 },
4404 { INT(dot11RSNAConfigSATimeout
), 0 },
4405 #ifndef CONFIG_NO_CONFIG_WRITE
4406 { INT(update_config
), 0 },
4407 #endif /* CONFIG_NO_CONFIG_WRITE */
4408 { FUNC_NO_VAR(load_dynamic_eap
), 0 },
4410 { FUNC(uuid
), CFG_CHANGED_UUID
},
4411 { INT_RANGE(auto_uuid
, 0, 1), 0 },
4412 { STR_RANGE(device_name
, 0, WPS_DEV_NAME_MAX_LEN
),
4413 CFG_CHANGED_DEVICE_NAME
},
4414 { STR_RANGE(manufacturer
, 0, 64), CFG_CHANGED_WPS_STRING
},
4415 { STR_RANGE(model_name
, 0, 32), CFG_CHANGED_WPS_STRING
},
4416 { STR_RANGE(model_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4417 { STR_RANGE(serial_number
, 0, 32), CFG_CHANGED_WPS_STRING
},
4418 { FUNC(device_type
), CFG_CHANGED_DEVICE_TYPE
},
4419 { FUNC(os_version
), CFG_CHANGED_OS_VERSION
},
4420 { STR(config_methods
), CFG_CHANGED_CONFIG_METHODS
},
4421 { INT_RANGE(wps_cred_processing
, 0, 2), 0 },
4422 { FUNC(wps_vendor_ext_m1
), CFG_CHANGED_VENDOR_EXTENSION
},
4423 #endif /* CONFIG_WPS */
4425 { FUNC(sec_device_type
), CFG_CHANGED_SEC_DEVICE_TYPE
},
4426 { INT(p2p_listen_reg_class
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4427 { INT(p2p_listen_channel
), CFG_CHANGED_P2P_LISTEN_CHANNEL
},
4428 { INT(p2p_oper_reg_class
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4429 { INT(p2p_oper_channel
), CFG_CHANGED_P2P_OPER_CHANNEL
},
4430 { INT_RANGE(p2p_go_intent
, 0, 15), 0 },
4431 { STR(p2p_ssid_postfix
), CFG_CHANGED_P2P_SSID_POSTFIX
},
4432 { INT_RANGE(persistent_reconnect
, 0, 1), 0 },
4433 { INT_RANGE(p2p_intra_bss
, 0, 1), CFG_CHANGED_P2P_INTRA_BSS
},
4434 { INT(p2p_group_idle
), 0 },
4435 { INT_RANGE(p2p_go_freq_change_policy
, 0, P2P_GO_FREQ_MOVE_MAX
), 0 },
4436 { INT_RANGE(p2p_passphrase_len
, 8, 63),
4437 CFG_CHANGED_P2P_PASSPHRASE_LEN
},
4438 { FUNC(p2p_pref_chan
), CFG_CHANGED_P2P_PREF_CHAN
},
4439 { FUNC(p2p_no_go_freq
), CFG_CHANGED_P2P_PREF_CHAN
},
4440 { INT_RANGE(p2p_add_cli_chan
, 0, 1), 0 },
4441 { INT_RANGE(p2p_optimize_listen_chan
, 0, 1), 0 },
4442 { INT(p2p_go_ht40
), 0 },
4443 { INT(p2p_go_vht
), 0 },
4444 { INT(p2p_disabled
), 0 },
4445 { INT_RANGE(p2p_go_ctwindow
, 0, 127), 0 },
4446 { INT(p2p_no_group_iface
), 0 },
4447 { INT_RANGE(p2p_ignore_shared_freq
, 0, 1), 0 },
4448 { IPV4(ip_addr_go
), 0 },
4449 { IPV4(ip_addr_mask
), 0 },
4450 { IPV4(ip_addr_start
), 0 },
4451 { IPV4(ip_addr_end
), 0 },
4452 { INT_RANGE(p2p_cli_probe
, 0, 1), 0 },
4453 #endif /* CONFIG_P2P */
4454 { FUNC(country
), CFG_CHANGED_COUNTRY
},
4455 { INT(bss_max_count
), 0 },
4456 { INT(bss_expiration_age
), 0 },
4457 { INT(bss_expiration_scan_count
), 0 },
4458 { INT_RANGE(filter_ssids
, 0, 1), 0 },
4459 { INT_RANGE(filter_rssi
, -100, 0), 0 },
4460 { INT(max_num_sta
), 0 },
4461 { INT_RANGE(disassoc_low_ack
, 0, 1), 0 },
4463 { INT_RANGE(hs20
, 0, 1), 0 },
4464 #endif /* CONFIG_HS20 */
4465 { INT_RANGE(interworking
, 0, 1), 0 },
4466 { FUNC(hessid
), 0 },
4467 { INT_RANGE(access_network_type
, 0, 15), 0 },
4468 { INT_RANGE(pbc_in_m1
, 0, 1), 0 },
4469 { STR(autoscan
), 0 },
4470 { INT_RANGE(wps_nfc_dev_pw_id
, 0x10, 0xffff),
4471 CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4472 { BIN(wps_nfc_dh_pubkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4473 { BIN(wps_nfc_dh_privkey
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4474 { BIN(wps_nfc_dev_pw
), CFG_CHANGED_NFC_PASSWORD_TOKEN
},
4475 { STR(ext_password_backend
), CFG_CHANGED_EXT_PW_BACKEND
},
4476 { INT(p2p_go_max_inactivity
), 0 },
4477 { INT_RANGE(auto_interworking
, 0, 1), 0 },
4480 { FUNC(sae_groups
), 0 },
4481 { INT(dtim_period
), 0 },
4482 { INT(beacon_int
), 0 },
4483 { FUNC(ap_vendor_elements
), 0 },
4484 { INT_RANGE(ignore_old_scan_res
, 0, 1), 0 },
4485 { FUNC(freq_list
), 0 },
4486 { INT(scan_cur_freq
), 0 },
4487 { INT(sched_scan_interval
), 0 },
4488 { INT(sched_scan_start_delay
), 0 },
4489 { INT(tdls_external_control
), 0},
4490 { STR(osu_dir
), 0 },
4491 { STR(wowlan_triggers
), 0 },
4492 { INT(p2p_search_delay
), 0},
4493 { INT(mac_addr
), 0 },
4494 { INT(rand_addr_lifetime
), 0 },
4495 { INT(preassoc_mac_addr
), 0 },
4496 { INT(key_mgmt_offload
), 0},
4497 { INT(passive_scan
), 0 },
4498 { INT(reassoc_same_bss_optim
), 0 },
4499 { INT(wps_priority
), 0},
4501 { STR_RANGE(fst_group_id
, 1, FST_MAX_GROUP_ID_LEN
), 0 },
4502 { INT_RANGE(fst_priority
, 1, FST_MAX_PRIO_VALUE
), 0 },
4503 { INT_RANGE(fst_llt
, 1, FST_MAX_LLT_MS
), 0 },
4504 #endif /* CONFIG_FST */
4505 { INT_RANGE(cert_in_cb
, 0, 1), 0 },
4506 { INT_RANGE(wpa_rsc_relaxation
, 0, 1), 0 },
4507 { STR(sched_scan_plans
), CFG_CHANGED_SCHED_SCAN_PLANS
},
4509 { STR(non_pref_chan
), 0 },
4510 { INT_RANGE(mbo_cell_capa
, MBO_CELL_CAPA_AVAILABLE
,
4511 MBO_CELL_CAPA_NOT_SUPPORTED
), 0 },
4512 { INT_RANGE(disassoc_imminent_rssi_threshold
, -120, 0), 0 },
4513 #endif /*CONFIG_MBO */
4514 { INT(gas_address3
), 0 },
4515 { INT_RANGE(ftm_responder
, 0, 1), 0 },
4516 { INT_RANGE(ftm_initiator
, 0, 1), 0 },
4517 { INT(gas_rand_addr_lifetime
), 0 },
4518 { INT_RANGE(gas_rand_mac_addr
, 0, 2), 0 },
4530 #define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
4533 int wpa_config_dump_values(struct wpa_config
*config
, char *buf
, size_t buflen
)
4538 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4539 const struct global_parse_data
*field
= &global_fields
[i
];
4545 tmp
= field
->get(field
->name
, config
, (long) field
->param1
,
4557 int wpa_config_get_value(const char *name
, struct wpa_config
*config
,
4558 char *buf
, size_t buflen
)
4562 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4563 const struct global_parse_data
*field
= &global_fields
[i
];
4565 if (os_strcmp(name
, field
->name
) != 0)
4569 return field
->get(name
, config
, (long) field
->param1
,
4577 int wpa_config_get_num_global_field_names(void)
4579 return NUM_GLOBAL_FIELDS
;
4583 const char * wpa_config_get_global_field_name(unsigned int i
, int *no_var
)
4585 if (i
>= NUM_GLOBAL_FIELDS
)
4589 *no_var
= !global_fields
[i
].param1
;
4590 return global_fields
[i
].name
;
4594 int wpa_config_process_global(struct wpa_config
*config
, char *pos
, int line
)
4599 for (i
= 0; i
< NUM_GLOBAL_FIELDS
; i
++) {
4600 const struct global_parse_data
*field
= &global_fields
[i
];
4601 size_t flen
= os_strlen(field
->name
);
4602 if (os_strncmp(pos
, field
->name
, flen
) != 0 ||
4606 if (field
->parser(field
, config
, line
, pos
+ flen
+ 1)) {
4607 wpa_printf(MSG_ERROR
, "Line %d: failed to "
4608 "parse '%s'.", line
, pos
);
4611 if (field
->changed_flag
== CFG_CHANGED_NFC_PASSWORD_TOKEN
)
4612 config
->wps_nfc_pw_from_config
= 1;
4613 config
->changed_parameters
|= field
->changed_flag
;
4616 if (i
== NUM_GLOBAL_FIELDS
) {
4618 if (os_strncmp(pos
, "wmm_ac_", 7) == 0) {
4619 char *tmp
= os_strchr(pos
, '=');
4623 wpa_printf(MSG_ERROR
, "Line %d: invalid line "
4628 if (hostapd_config_wmm_ac(config
->wmm_ac_params
, pos
,
4630 wpa_printf(MSG_ERROR
, "Line %d: invalid WMM "
4635 #endif /* CONFIG_AP */
4638 wpa_printf(MSG_ERROR
, "Line %d: unknown global field '%s'.",