2 * WPA Supplicant / Configuration backend: Windows registry
3 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This file implements a configuration backend for Windows registry. All the
9 * configuration information is stored in the registry and the format for
10 * network configuration fields is same as described in the sample
11 * configuration file, wpa_supplicant.conf.
13 * Configuration data is in
14 * \a HKEY_LOCAL_MACHINE\\SOFTWARE\\%wpa_supplicant\\configs
15 * key. Each configuration profile has its own key under this. In terms of text
16 * files, each profile would map to a separate text file with possibly multiple
17 * networks. Under each profile, there is a networks key that lists all
18 * networks as a subkey. Each network has set of values in the same way as
19 * network block in the configuration file. In addition, blobs subkey has
20 * possible blobs as values.
22 * Example network configuration block:
24 HKEY_LOCAL_MACHINE\SOFTWARE\wpa_supplicant\configs\test\networks\0000
37 #define WPA_KEY_ROOT HKEY_LOCAL_MACHINE
39 #ifndef WPA_KEY_PREFIX
40 #define WPA_KEY_PREFIX TEXT("SOFTWARE\\wpa_supplicant")
50 static int wpa_config_read_blobs(struct wpa_config
*config
, HKEY hk
)
52 struct wpa_config_blob
*blob
;
58 ret
= RegOpenKeyEx(hk
, TEXT("blobs"), 0, KEY_QUERY_VALUE
, &bhk
);
59 if (ret
!= ERROR_SUCCESS
) {
60 wpa_printf(MSG_DEBUG
, "Could not open wpa_supplicant config "
62 return 0; /* assume no blobs */
69 DWORD namelen
, datalen
, type
;
72 datalen
= sizeof(data
);
73 ret
= RegEnumValue(bhk
, i
, name
, &namelen
, NULL
, &type
,
74 (LPBYTE
) data
, &datalen
);
76 if (ret
== ERROR_NO_MORE_ITEMS
)
79 if (ret
!= ERROR_SUCCESS
) {
80 wpa_printf(MSG_DEBUG
, "RegEnumValue failed: 0x%x",
85 if (namelen
>= TNAMELEN
)
86 namelen
= TNAMELEN
- 1;
87 name
[namelen
] = TEXT('\0');
88 wpa_unicode2ascii_inplace(name
);
90 if (datalen
>= sizeof(data
))
91 datalen
= sizeof(data
) - 1;
93 wpa_printf(MSG_MSGDUMP
, "blob %d: field='%s' len %d",
94 (int) i
, name
, (int) datalen
);
96 blob
= os_zalloc(sizeof(*blob
));
101 blob
->name
= os_strdup((char *) name
);
102 blob
->data
= os_memdup(data
, datalen
);
103 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
104 wpa_config_free_blob(blob
);
110 wpa_config_set_blob(config
, blob
);
115 return errors
? -1 : 0;
119 static int wpa_config_read_reg_dword(HKEY hk
, const TCHAR
*name
, int *_val
)
124 buflen
= sizeof(val
);
125 ret
= RegQueryValueEx(hk
, name
, NULL
, NULL
, (LPBYTE
) &val
, &buflen
);
126 if (ret
== ERROR_SUCCESS
&& buflen
== sizeof(val
)) {
127 wpa_printf(MSG_DEBUG
, TSTR
"=%d", name
, (int) val
);
136 static char * wpa_config_read_reg_string(HKEY hk
, const TCHAR
*name
)
143 ret
= RegQueryValueEx(hk
, name
, NULL
, NULL
, NULL
, &buflen
);
144 if (ret
!= ERROR_SUCCESS
)
146 val
= os_malloc(buflen
);
150 ret
= RegQueryValueEx(hk
, name
, NULL
, NULL
, (LPBYTE
) val
, &buflen
);
151 if (ret
!= ERROR_SUCCESS
) {
156 wpa_unicode2ascii_inplace(val
);
157 wpa_printf(MSG_DEBUG
, TSTR
"=%s", name
, (char *) val
);
163 static int wpa_config_read_global_uuid(struct wpa_config
*config
, HKEY hk
)
168 str
= wpa_config_read_reg_string(hk
, TEXT("uuid"));
172 if (uuid_str2bin(str
, config
->uuid
))
181 static int wpa_config_read_global_os_version(struct wpa_config
*config
,
187 str
= wpa_config_read_reg_string(hk
, TEXT("os_version"));
191 if (hexstr2bin(str
, config
->os_version
, 4))
198 #endif /* CONFIG_WPS */
201 static int wpa_config_read_global(struct wpa_config
*config
, HKEY hk
)
206 wpa_config_read_reg_dword(hk
, TEXT("ap_scan"), &config
->ap_scan
);
207 wpa_config_read_reg_dword(hk
, TEXT("fast_reauth"),
208 &config
->fast_reauth
);
209 wpa_config_read_reg_dword(hk
, TEXT("dot11RSNAConfigPMKLifetime"),
210 (int *) &config
->dot11RSNAConfigPMKLifetime
);
211 wpa_config_read_reg_dword(hk
,
212 TEXT("dot11RSNAConfigPMKReauthThreshold"),
214 &config
->dot11RSNAConfigPMKReauthThreshold
);
215 wpa_config_read_reg_dword(hk
, TEXT("dot11RSNAConfigSATimeout"),
216 (int *) &config
->dot11RSNAConfigSATimeout
);
217 wpa_config_read_reg_dword(hk
, TEXT("update_config"),
218 &config
->update_config
);
220 if (wpa_config_read_reg_dword(hk
, TEXT("eapol_version"),
221 &config
->eapol_version
) == 0) {
222 if (config
->eapol_version
< 1 ||
223 config
->eapol_version
> 2) {
224 wpa_printf(MSG_ERROR
, "Invalid EAPOL version (%d)",
225 config
->eapol_version
);
230 config
->ctrl_interface
= wpa_config_read_reg_string(
231 hk
, TEXT("ctrl_interface"));
234 if (wpa_config_read_global_uuid(config
, hk
))
236 wpa_config_read_reg_dword(hk
, TEXT("auto_uuid"), &config
->auto_uuid
);
237 config
->device_name
= wpa_config_read_reg_string(
238 hk
, TEXT("device_name"));
239 config
->manufacturer
= wpa_config_read_reg_string(
240 hk
, TEXT("manufacturer"));
241 config
->model_name
= wpa_config_read_reg_string(
242 hk
, TEXT("model_name"));
243 config
->serial_number
= wpa_config_read_reg_string(
244 hk
, TEXT("serial_number"));
246 char *t
= wpa_config_read_reg_string(
247 hk
, TEXT("device_type"));
248 if (t
&& wps_dev_type_str2bin(t
, config
->device_type
))
252 config
->config_methods
= wpa_config_read_reg_string(
253 hk
, TEXT("config_methods"));
254 if (wpa_config_read_global_os_version(config
, hk
))
256 wpa_config_read_reg_dword(hk
, TEXT("wps_cred_processing"),
257 &config
->wps_cred_processing
);
258 wpa_config_read_reg_dword(hk
, TEXT("wps_cred_add_sae"),
259 &config
->wps_cred_add_sae
);
260 #endif /* CONFIG_WPS */
262 config
->p2p_ssid_postfix
= wpa_config_read_reg_string(
263 hk
, TEXT("p2p_ssid_postfix"));
264 wpa_config_read_reg_dword(hk
, TEXT("p2p_group_idle"),
265 (int *) &config
->p2p_group_idle
);
266 #endif /* CONFIG_P2P */
268 wpa_config_read_reg_dword(hk
, TEXT("bss_max_count"),
269 (int *) &config
->bss_max_count
);
270 wpa_config_read_reg_dword(hk
, TEXT("filter_ssids"),
271 &config
->filter_ssids
);
272 wpa_config_read_reg_dword(hk
, TEXT("max_num_sta"),
273 (int *) &config
->max_num_sta
);
274 wpa_config_read_reg_dword(hk
, TEXT("disassoc_low_ack"),
275 (int *) &config
->disassoc_low_ack
);
277 wpa_config_read_reg_dword(hk
, TEXT("okc"), &config
->okc
);
278 wpa_config_read_reg_dword(hk
, TEXT("pmf"), &val
);
280 if (wpa_config_read_reg_dword(hk
, TEXT("extended_key_id"),
282 if (val
< 0 || val
> 1) {
283 wpa_printf(MSG_ERROR
,
284 "Invalid Extended Key ID setting (%d)", val
);
287 config
->extended_key_id
= val
;
290 return errors
? -1 : 0;
294 static struct wpa_ssid
* wpa_config_read_network(HKEY hk
, const TCHAR
*netw
,
300 struct wpa_ssid
*ssid
;
303 ret
= RegOpenKeyEx(hk
, netw
, 0, KEY_QUERY_VALUE
, &nhk
);
304 if (ret
!= ERROR_SUCCESS
) {
305 wpa_printf(MSG_DEBUG
, "Could not open wpa_supplicant config "
306 "network '" TSTR
"'", netw
);
310 wpa_printf(MSG_MSGDUMP
, "Start of a new network '" TSTR
"'", netw
);
311 ssid
= os_zalloc(sizeof(*ssid
));
316 dl_list_init(&ssid
->psk_list
);
319 wpa_config_set_network_defaults(ssid
);
322 TCHAR name
[255], data
[1024];
323 DWORD namelen
, datalen
, type
;
326 datalen
= sizeof(data
);
327 ret
= RegEnumValue(nhk
, i
, name
, &namelen
, NULL
, &type
,
328 (LPBYTE
) data
, &datalen
);
330 if (ret
== ERROR_NO_MORE_ITEMS
)
333 if (ret
!= ERROR_SUCCESS
) {
334 wpa_printf(MSG_ERROR
, "RegEnumValue failed: 0x%x",
341 name
[namelen
] = TEXT('\0');
345 data
[datalen
] = TEXT('\0');
347 wpa_unicode2ascii_inplace(name
);
348 wpa_unicode2ascii_inplace(data
);
349 if (wpa_config_set(ssid
, (char *) name
, (char *) data
, 0) < 0)
355 if (ssid
->passphrase
) {
357 wpa_printf(MSG_ERROR
, "Both PSK and passphrase "
358 "configured for network '" TSTR
"'.", netw
);
361 wpa_config_update_psk(ssid
);
364 if ((ssid
->group_cipher
& WPA_CIPHER_CCMP
) &&
365 !(ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
) &&
366 !(ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)) {
367 /* Group cipher cannot be stronger than the pairwise cipher. */
368 wpa_printf(MSG_DEBUG
, "Removed CCMP from group cipher "
369 "list since it was not allowed for pairwise "
370 "cipher for network '" TSTR
"'.", netw
);
371 ssid
->group_cipher
&= ~WPA_CIPHER_CCMP
;
375 wpa_config_free_ssid(ssid
);
383 static int wpa_config_read_networks(struct wpa_config
*config
, HKEY hk
)
386 struct wpa_ssid
*ssid
, *tail
= NULL
, *head
= NULL
;
391 ret
= RegOpenKeyEx(hk
, TEXT("networks"), 0, KEY_ENUMERATE_SUB_KEYS
,
393 if (ret
!= ERROR_SUCCESS
) {
394 wpa_printf(MSG_ERROR
, "Could not open wpa_supplicant networks "
404 ret
= RegEnumKeyEx(nhk
, i
, name
, &namelen
, NULL
, NULL
, NULL
,
407 if (ret
== ERROR_NO_MORE_ITEMS
)
410 if (ret
!= ERROR_SUCCESS
) {
411 wpa_printf(MSG_DEBUG
, "RegEnumKeyEx failed: 0x%x",
418 name
[namelen
] = '\0';
420 ssid
= wpa_config_read_network(nhk
, name
, i
);
422 wpa_printf(MSG_ERROR
, "Failed to parse network "
423 "profile '%s'.", name
);
433 if (wpa_config_add_prio_network(config
, ssid
)) {
434 wpa_printf(MSG_ERROR
, "Failed to add network profile "
435 "'%s' to priority list.", name
);
445 return errors
? -1 : 0;
449 struct wpa_config
* wpa_config_read(const char *name
, struct wpa_config
*cfgp
)
453 struct wpa_config
*config
;
462 config
= wpa_config_alloc_empty(NULL
, NULL
);
465 wpa_printf(MSG_DEBUG
, "Reading configuration profile '%s'", name
);
468 _snwprintf(buf
, 256, WPA_KEY_PREFIX
TEXT("\\configs\\%S"), name
);
470 os_snprintf(buf
, 256, WPA_KEY_PREFIX
TEXT("\\configs\\%s"), name
);
473 ret
= RegOpenKeyEx(WPA_KEY_ROOT
, buf
, 0, KEY_QUERY_VALUE
, &hk
);
474 if (ret
!= ERROR_SUCCESS
) {
475 wpa_printf(MSG_ERROR
, "Could not open wpa_supplicant "
476 "configuration registry HKLM\\" TSTR
, buf
);
481 if (wpa_config_read_global(config
, hk
))
484 if (wpa_config_read_networks(config
, hk
))
487 if (wpa_config_read_blobs(config
, hk
))
490 wpa_config_debug_dump_networks(config
);
495 wpa_config_free(config
);
503 static int wpa_config_write_reg_dword(HKEY hk
, const TCHAR
*name
, int val
,
510 RegDeleteValue(hk
, name
);
514 ret
= RegSetValueEx(hk
, name
, 0, REG_DWORD
, (LPBYTE
) &_val
,
516 if (ret
!= ERROR_SUCCESS
) {
517 wpa_printf(MSG_ERROR
, "WINREG: Failed to set %s=%d: error %d",
518 name
, val
, (int) GetLastError());
526 static int wpa_config_write_reg_string(HKEY hk
, const char *name
,
532 _name
= wpa_strdup_tchar(name
);
537 RegDeleteValue(hk
, _name
);
542 _val
= wpa_strdup_tchar(val
);
547 ret
= RegSetValueEx(hk
, _name
, 0, REG_SZ
, (BYTE
*) _val
,
548 (os_strlen(val
) + 1) * sizeof(TCHAR
));
549 if (ret
!= ERROR_SUCCESS
) {
550 wpa_printf(MSG_ERROR
, "WINREG: Failed to set %s='%s': "
551 "error %d", name
, val
, (int) GetLastError());
563 static int wpa_config_write_global(struct wpa_config
*config
, HKEY hk
)
565 #ifdef CONFIG_CTRL_IFACE
566 wpa_config_write_reg_string(hk
, "ctrl_interface",
567 config
->ctrl_interface
);
568 #endif /* CONFIG_CTRL_IFACE */
570 wpa_config_write_reg_dword(hk
, TEXT("eapol_version"),
571 config
->eapol_version
,
572 DEFAULT_EAPOL_VERSION
);
573 wpa_config_write_reg_dword(hk
, TEXT("ap_scan"), config
->ap_scan
,
575 wpa_config_write_reg_dword(hk
, TEXT("fast_reauth"),
576 config
->fast_reauth
, DEFAULT_FAST_REAUTH
);
577 wpa_config_write_reg_dword(hk
, TEXT("dot11RSNAConfigPMKLifetime"),
578 config
->dot11RSNAConfigPMKLifetime
, 0);
579 wpa_config_write_reg_dword(hk
,
580 TEXT("dot11RSNAConfigPMKReauthThreshold"),
581 config
->dot11RSNAConfigPMKReauthThreshold
,
583 wpa_config_write_reg_dword(hk
, TEXT("dot11RSNAConfigSATimeout"),
584 config
->dot11RSNAConfigSATimeout
, 0);
585 wpa_config_write_reg_dword(hk
, TEXT("update_config"),
586 config
->update_config
,
589 if (!is_nil_uuid(config
->uuid
)) {
591 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
592 wpa_config_write_reg_string(hk
, "uuid", buf
);
594 wpa_config_write_reg_dword(hk
, TEXT("auto_uuid"), config
->auto_uuid
,
596 wpa_config_write_reg_string(hk
, "device_name", config
->device_name
);
597 wpa_config_write_reg_string(hk
, "manufacturer", config
->manufacturer
);
598 wpa_config_write_reg_string(hk
, "model_name", config
->model_name
);
599 wpa_config_write_reg_string(hk
, "model_number", config
->model_number
);
600 wpa_config_write_reg_string(hk
, "serial_number",
601 config
->serial_number
);
603 char _buf
[WPS_DEV_TYPE_BUFSIZE
], *buf
;
604 buf
= wps_dev_type_bin2str(config
->device_type
,
606 wpa_config_write_reg_string(hk
, "device_type", buf
);
608 wpa_config_write_reg_string(hk
, "config_methods",
609 config
->config_methods
);
610 if (WPA_GET_BE32(config
->os_version
)) {
612 os_snprintf(vbuf
, sizeof(vbuf
), "%08x",
613 WPA_GET_BE32(config
->os_version
));
614 wpa_config_write_reg_string(hk
, "os_version", vbuf
);
616 wpa_config_write_reg_dword(hk
, TEXT("wps_cred_processing"),
617 config
->wps_cred_processing
, 0);
618 wpa_config_write_reg_dword(hk
, TEXT("wps_cred_add_sae"),
619 config
->wps_cred_add_sae
, 0);
620 #endif /* CONFIG_WPS */
622 wpa_config_write_reg_string(hk
, "p2p_ssid_postfix",
623 config
->p2p_ssid_postfix
);
624 wpa_config_write_reg_dword(hk
, TEXT("p2p_group_idle"),
625 config
->p2p_group_idle
, 0);
626 #endif /* CONFIG_P2P */
628 wpa_config_write_reg_dword(hk
, TEXT("bss_max_count"),
629 config
->bss_max_count
,
630 DEFAULT_BSS_MAX_COUNT
);
631 wpa_config_write_reg_dword(hk
, TEXT("filter_ssids"),
632 config
->filter_ssids
, 0);
633 wpa_config_write_reg_dword(hk
, TEXT("max_num_sta"),
634 config
->max_num_sta
, DEFAULT_MAX_NUM_STA
);
635 wpa_config_write_reg_dword(hk
, TEXT("ap_isolate"),
636 config
->ap_isolate
, DEFAULT_AP_ISOLATE
);
637 wpa_config_write_reg_dword(hk
, TEXT("disassoc_low_ack"),
638 config
->disassoc_low_ack
, 0);
640 wpa_config_write_reg_dword(hk
, TEXT("okc"), config
->okc
, 0);
641 wpa_config_write_reg_dword(hk
, TEXT("pmf"), config
->pmf
, 0);
643 wpa_config_write_reg_dword(hk
, TEXT("external_sim"),
644 config
->external_sim
, 0);
650 static int wpa_config_delete_subkeys(HKEY hk
, const TCHAR
*key
)
656 ret
= RegOpenKeyEx(hk
, key
, 0, KEY_ENUMERATE_SUB_KEYS
| DELETE
, &nhk
);
657 if (ret
!= ERROR_SUCCESS
) {
658 wpa_printf(MSG_DEBUG
, "WINREG: Could not open key '" TSTR
659 "' for subkey deletion: error 0x%x (%d)", key
,
660 (unsigned int) ret
, (int) GetLastError());
669 ret
= RegEnumKeyEx(nhk
, i
, name
, &namelen
, NULL
, NULL
, NULL
,
672 if (ret
== ERROR_NO_MORE_ITEMS
)
675 if (ret
!= ERROR_SUCCESS
) {
676 wpa_printf(MSG_DEBUG
, "RegEnumKeyEx failed: 0x%x (%d)",
677 (unsigned int) ret
, (int) GetLastError());
683 name
[namelen
] = TEXT('\0');
685 ret
= RegDeleteKey(nhk
, name
);
686 if (ret
!= ERROR_SUCCESS
) {
687 wpa_printf(MSG_DEBUG
, "RegDeleteKey failed: 0x%x (%d)",
688 (unsigned int) ret
, (int) GetLastError());
695 return errors
? -1 : 0;
699 static void write_str(HKEY hk
, const char *field
, struct wpa_ssid
*ssid
)
701 char *value
= wpa_config_get(ssid
, field
);
704 wpa_config_write_reg_string(hk
, field
, value
);
709 static void write_int(HKEY hk
, const char *field
, int value
, int def
)
714 os_snprintf(val
, sizeof(val
), "%d", value
);
715 wpa_config_write_reg_string(hk
, field
, val
);
719 static void write_bssid(HKEY hk
, struct wpa_ssid
*ssid
)
721 char *value
= wpa_config_get(ssid
, "bssid");
724 wpa_config_write_reg_string(hk
, "bssid", value
);
729 static void write_psk(HKEY hk
, struct wpa_ssid
*ssid
)
731 char *value
= wpa_config_get(ssid
, "psk");
734 wpa_config_write_reg_string(hk
, "psk", value
);
739 static void write_proto(HKEY hk
, struct wpa_ssid
*ssid
)
743 if (ssid
->proto
== DEFAULT_PROTO
)
746 value
= wpa_config_get(ssid
, "proto");
750 wpa_config_write_reg_string(hk
, "proto", value
);
755 static void write_key_mgmt(HKEY hk
, struct wpa_ssid
*ssid
)
759 if (ssid
->key_mgmt
== DEFAULT_KEY_MGMT
)
762 value
= wpa_config_get(ssid
, "key_mgmt");
766 wpa_config_write_reg_string(hk
, "key_mgmt", value
);
771 static void write_pairwise(HKEY hk
, struct wpa_ssid
*ssid
)
775 if (ssid
->pairwise_cipher
== DEFAULT_PAIRWISE
)
778 value
= wpa_config_get(ssid
, "pairwise");
782 wpa_config_write_reg_string(hk
, "pairwise", value
);
787 static void write_group(HKEY hk
, struct wpa_ssid
*ssid
)
791 if (ssid
->group_cipher
== DEFAULT_GROUP
)
794 value
= wpa_config_get(ssid
, "group");
798 wpa_config_write_reg_string(hk
, "group", value
);
803 static void write_auth_alg(HKEY hk
, struct wpa_ssid
*ssid
)
807 if (ssid
->auth_alg
== 0)
810 value
= wpa_config_get(ssid
, "auth_alg");
814 wpa_config_write_reg_string(hk
, "auth_alg", value
);
819 #ifdef IEEE8021X_EAPOL
820 static void write_eap(HKEY hk
, struct wpa_ssid
*ssid
)
824 value
= wpa_config_get(ssid
, "eap");
829 wpa_config_write_reg_string(hk
, "eap", value
);
832 #endif /* IEEE8021X_EAPOL */
836 static void write_wep_key(HKEY hk
, int idx
, struct wpa_ssid
*ssid
)
838 char field
[20], *value
;
840 os_snprintf(field
, sizeof(field
), "wep_key%d", idx
);
841 value
= wpa_config_get(ssid
, field
);
843 wpa_config_write_reg_string(hk
, field
, value
);
847 #endif /* CONFIG_WEP */
850 static int wpa_config_write_network(HKEY hk
, struct wpa_ssid
*ssid
, int id
)
857 ret
= RegOpenKeyEx(hk
, TEXT("networks"), 0, KEY_CREATE_SUB_KEY
, &nhk
);
858 if (ret
!= ERROR_SUCCESS
) {
859 wpa_printf(MSG_DEBUG
, "WINREG: Could not open networks key "
860 "for subkey addition: error 0x%x (%d)",
861 (unsigned int) ret
, (int) GetLastError());
866 wsprintf(name
, L
"%04d", id
);
868 os_snprintf(name
, sizeof(name
), "%04d", id
);
870 ret
= RegCreateKeyEx(nhk
, name
, 0, NULL
, 0, KEY_WRITE
, NULL
, &netw
,
873 if (ret
!= ERROR_SUCCESS
) {
874 wpa_printf(MSG_DEBUG
, "WINREG: Could not add network key '%s':"
876 name
, (unsigned int) ret
, (int) GetLastError());
880 #define STR(t) write_str(netw, #t, ssid)
881 #define INT(t) write_int(netw, #t, ssid->t, 0)
882 #define INTe(t, m) write_int(netw, #t, ssid->eap.m, 0)
883 #define INT_DEF(t, def) write_int(netw, #t, ssid->t, def)
884 #define INT_DEFe(t, m, def) write_int(netw, #t, ssid->eap.m, def)
888 write_bssid(netw
, ssid
);
889 write_psk(netw
, ssid
);
891 STR(sae_password_id
);
892 write_proto(netw
, ssid
);
893 write_key_mgmt(netw
, ssid
);
894 write_pairwise(netw
, ssid
);
895 write_group(netw
, ssid
);
896 write_auth_alg(netw
, ssid
);
897 #ifdef IEEE8021X_EAPOL
898 write_eap(netw
, ssid
);
900 STR(anonymous_identity
);
907 STR(private_key_passwd
);
910 STR(check_cert_subject
);
911 STR(altsubject_match
);
916 STR(private_key2_passwd
);
919 STR(check_cert_subject2
);
920 STR(altsubject_match2
);
934 INTe(engine
, cert
.engine
);
935 INTe(engine2
, phase2_cert
.engine
);
936 INT_DEF(eapol_flags
, DEFAULT_EAPOL_FLAGS
);
937 #endif /* IEEE8021X_EAPOL */
942 for (i
= 0; i
< 4; i
++)
943 write_wep_key(netw
, i
, ssid
);
946 #endif /* CONFIG_WEP */
948 #ifdef IEEE8021X_EAPOL
949 INT_DEF(eap_workaround
, DEFAULT_EAP_WORKAROUND
);
951 INT_DEFe(fragment_size
, fragment_size
, DEFAULT_FRAGMENT_SIZE
);
952 #endif /* IEEE8021X_EAPOL */
954 write_int(netw
, "proactive_key_caching", ssid
->proactive_key_caching
,
957 write_int(netw
, "ieee80211w", ssid
->ieee80211w
,
958 MGMT_FRAME_PROTECTION_DEFAULT
);
961 INT(update_identifier
);
962 #endif /* CONFIG_HS20 */
964 INT(ft_eap_pmksa_caching
);
972 return errors
? -1 : 0;
976 static int wpa_config_write_blob(HKEY hk
, struct wpa_config_blob
*blob
)
982 ret
= RegCreateKeyEx(hk
, TEXT("blobs"), 0, NULL
, 0, KEY_WRITE
, NULL
,
984 if (ret
!= ERROR_SUCCESS
) {
985 wpa_printf(MSG_DEBUG
, "WINREG: Could not add blobs key: "
987 (unsigned int) ret
, (int) GetLastError());
991 name
= wpa_strdup_tchar(blob
->name
);
992 ret
= RegSetValueEx(bhk
, name
, 0, REG_BINARY
, blob
->data
,
994 if (ret
!= ERROR_SUCCESS
) {
995 wpa_printf(MSG_ERROR
, "WINREG: Failed to set blob %s': "
996 "error 0x%x (%d)", blob
->name
, (unsigned int) ret
,
997 (int) GetLastError());
1010 int wpa_config_write(const char *name
, struct wpa_config
*config
)
1016 struct wpa_ssid
*ssid
;
1017 struct wpa_config_blob
*blob
;
1020 wpa_printf(MSG_DEBUG
, "Writing configuration file '%s'", name
);
1023 _snwprintf(buf
, 256, WPA_KEY_PREFIX
TEXT("\\configs\\%S"), name
);
1025 os_snprintf(buf
, 256, WPA_KEY_PREFIX
TEXT("\\configs\\%s"), name
);
1026 #endif /* UNICODE */
1028 ret
= RegOpenKeyEx(WPA_KEY_ROOT
, buf
, 0, KEY_SET_VALUE
| DELETE
, &hk
);
1029 if (ret
!= ERROR_SUCCESS
) {
1030 wpa_printf(MSG_ERROR
, "Could not open wpa_supplicant "
1031 "configuration registry %s: error %d", buf
,
1032 (int) GetLastError());
1036 if (wpa_config_write_global(config
, hk
)) {
1037 wpa_printf(MSG_ERROR
, "Failed to write global configuration "
1042 wpa_config_delete_subkeys(hk
, TEXT("networks"));
1043 for (ssid
= config
->ssid
, id
= 0; ssid
; ssid
= ssid
->next
, id
++) {
1044 if (ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1045 continue; /* do not save temporary WPS networks */
1046 if (wpa_config_write_network(hk
, ssid
, id
))
1050 RegDeleteKey(hk
, TEXT("blobs"));
1051 for (blob
= config
->blobs
; blob
; blob
= blob
->next
) {
1052 if (wpa_config_write_blob(hk
, blob
))
1058 wpa_printf(MSG_DEBUG
, "Configuration '%s' written %ssuccessfully",
1059 name
, errors
? "un" : "");
1060 return errors
? -1 : 0;