2 * WPA Supplicant / Configuration backend: Windows registry
3 * Copyright (c) 2003-2008, 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);
281 return errors ? -1 : 0;
285 static struct wpa_ssid * wpa_config_read_network(HKEY hk, const TCHAR *netw,
291 struct wpa_ssid *ssid;
294 ret = RegOpenKeyEx(hk, netw, 0, KEY_QUERY_VALUE, &nhk);
295 if (ret != ERROR_SUCCESS) {
296 wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config "
297 "network '" TSTR "'", netw);
301 wpa_printf(MSG_MSGDUMP, "Start of a new network '" TSTR "'", netw);
302 ssid = os_zalloc(sizeof(*ssid));
307 dl_list_init(&ssid->psk_list);
310 wpa_config_set_network_defaults(ssid);
313 TCHAR name[255], data[1024];
314 DWORD namelen, datalen, type;
317 datalen = sizeof(data);
318 ret = RegEnumValue(nhk, i, name, &namelen, NULL, &type,
319 (LPBYTE) data, &datalen);
321 if (ret == ERROR_NO_MORE_ITEMS)
324 if (ret != ERROR_SUCCESS) {
325 wpa_printf(MSG_ERROR, "RegEnumValue failed: 0x%x",
332 name[namelen] = TEXT('\0');
336 data[datalen] = TEXT('\0');
338 wpa_unicode2ascii_inplace(name);
339 wpa_unicode2ascii_inplace(data);
340 if (wpa_config_set(ssid, (char *) name, (char *) data, 0) < 0)
346 if (ssid->passphrase) {
348 wpa_printf(MSG_ERROR, "Both PSK and passphrase "
349 "configured for network '" TSTR "'.", netw);
352 wpa_config_update_psk(ssid);
355 if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
356 !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
357 !(ssid->pairwise_cipher & WPA_CIPHER_NONE)) {
358 /* Group cipher cannot be stronger than the pairwise cipher. */
359 wpa_printf(MSG_DEBUG, "Removed CCMP from group cipher "
360 "list since it was not allowed for pairwise "
361 "cipher for network '" TSTR "'.", netw);
362 ssid->group_cipher &= ~WPA_CIPHER_CCMP;
366 wpa_config_free_ssid(ssid);
374 static int wpa_config_read_networks(struct wpa_config *config, HKEY hk)
377 struct wpa_ssid *ssid, *tail = NULL, *head = NULL;
382 ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_ENUMERATE_SUB_KEYS,
384 if (ret != ERROR_SUCCESS) {
385 wpa_printf(MSG_ERROR, "Could not open wpa_supplicant networks "
395 ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL,
398 if (ret == ERROR_NO_MORE_ITEMS)
401 if (ret != ERROR_SUCCESS) {
402 wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x",
409 name[namelen] = '\0';
411 ssid = wpa_config_read_network(nhk, name, i);
413 wpa_printf(MSG_ERROR, "Failed to parse network "
414 "profile '%s'.", name);
424 if (wpa_config_add_prio_network(config, ssid)) {
425 wpa_printf(MSG_ERROR, "Failed to add network profile "
426 "'%s' to priority list.", name);
436 return errors ? -1 : 0;
440 struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp)
444 struct wpa_config *config;
453 config = wpa_config_alloc_empty(NULL, NULL);
456 wpa_printf(MSG_DEBUG, "Reading configuration profile '%s'", name);
459 _snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name);
461 os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name);
464 ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_QUERY_VALUE, &hk);
465 if (ret != ERROR_SUCCESS) {
466 wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
467 "configuration registry HKLM\\" TSTR, buf);
472 if (wpa_config_read_global(config, hk))
475 if (wpa_config_read_networks(config, hk))
478 if (wpa_config_read_blobs(config, hk))
481 wpa_config_debug_dump_networks(config);
486 wpa_config_free(config);
494 static int wpa_config_write_reg_dword(HKEY hk, const TCHAR *name, int val,
501 RegDeleteValue(hk, name);
505 ret = RegSetValueEx(hk, name, 0, REG_DWORD, (LPBYTE) &_val,
507 if (ret != ERROR_SUCCESS) {
508 wpa_printf(MSG_ERROR, "WINREG: Failed to set %s=%d: error %d",
509 name, val, (int) GetLastError());
517 static int wpa_config_write_reg_string(HKEY hk, const char *name,
523 _name = wpa_strdup_tchar(name);
528 RegDeleteValue(hk, _name);
533 _val = wpa_strdup_tchar(val);
538 ret = RegSetValueEx(hk, _name, 0, REG_SZ, (BYTE *) _val,
539 (os_strlen(val) + 1) * sizeof(TCHAR));
540 if (ret != ERROR_SUCCESS) {
541 wpa_printf(MSG_ERROR, "WINREG: Failed to set %s='%s': "
542 "error %d", name, val, (int) GetLastError());
554 static int wpa_config_write_global(struct wpa_config *config, HKEY hk)
556 #ifdef CONFIG_CTRL_IFACE
557 wpa_config_write_reg_string(hk, "ctrl_interface",
558 config->ctrl_interface);
559 #endif /* CONFIG_CTRL_IFACE */
561 wpa_config_write_reg_dword(hk, TEXT("eapol_version"),
562 config->eapol_version,
563 DEFAULT_EAPOL_VERSION);
564 wpa_config_write_reg_dword(hk, TEXT("ap_scan"), config->ap_scan,
566 wpa_config_write_reg_dword(hk, TEXT("fast_reauth"),
567 config->fast_reauth, DEFAULT_FAST_REAUTH);
568 wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"),
569 config->dot11RSNAConfigPMKLifetime, 0);
570 wpa_config_write_reg_dword(hk,
571 TEXT("dot11RSNAConfigPMKReauthThreshold"),
572 config->dot11RSNAConfigPMKReauthThreshold,
574 wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"),
575 config->dot11RSNAConfigSATimeout, 0);
576 wpa_config_write_reg_dword(hk, TEXT("update_config"),
577 config->update_config,
580 if (!is_nil_uuid(config->uuid)) {
582 uuid_bin2str(config->uuid, buf, sizeof(buf));
583 wpa_config_write_reg_string(hk, "uuid", buf);
585 wpa_config_write_reg_dword(hk, TEXT("auto_uuid"), config->auto_uuid,
587 wpa_config_write_reg_string(hk, "device_name", config->device_name);
588 wpa_config_write_reg_string(hk, "manufacturer", config->manufacturer);
589 wpa_config_write_reg_string(hk, "model_name", config->model_name);
590 wpa_config_write_reg_string(hk, "model_number", config->model_number);
591 wpa_config_write_reg_string(hk, "serial_number",
592 config->serial_number);
594 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
595 buf = wps_dev_type_bin2str(config->device_type,
597 wpa_config_write_reg_string(hk, "device_type", buf);
599 wpa_config_write_reg_string(hk, "config_methods",
600 config->config_methods);
601 if (WPA_GET_BE32(config->os_version)) {
603 os_snprintf(vbuf, sizeof(vbuf), "%08x",
604 WPA_GET_BE32(config->os_version));
605 wpa_config_write_reg_string(hk, "os_version", vbuf);
607 wpa_config_write_reg_dword(hk, TEXT("wps_cred_processing"),
608 config->wps_cred_processing, 0);
609 wpa_config_write_reg_dword(hk, TEXT("wps_cred_add_sae"),
610 config->wps_cred_add_sae, 0);
611 #endif /* CONFIG_WPS */
613 wpa_config_write_reg_string(hk, "p2p_ssid_postfix",
614 config->p2p_ssid_postfix);
615 wpa_config_write_reg_dword(hk, TEXT("p2p_group_idle"),
616 config->p2p_group_idle, 0);
617 #endif /* CONFIG_P2P */
619 wpa_config_write_reg_dword(hk, TEXT("bss_max_count"),
620 config->bss_max_count,
621 DEFAULT_BSS_MAX_COUNT);
622 wpa_config_write_reg_dword(hk, TEXT("filter_ssids"),
623 config->filter_ssids, 0);
624 wpa_config_write_reg_dword(hk, TEXT("max_num_sta"),
625 config->max_num_sta, DEFAULT_MAX_NUM_STA);
626 wpa_config_write_reg_dword(hk, TEXT("ap_isolate"),
627 config->ap_isolate, DEFAULT_AP_ISOLATE);
628 wpa_config_write_reg_dword(hk, TEXT("disassoc_low_ack"),
629 config->disassoc_low_ack, 0);
631 wpa_config_write_reg_dword(hk, TEXT("okc"), config->okc, 0);
632 wpa_config_write_reg_dword(hk, TEXT("pmf"), config->pmf, 0);
634 wpa_config_write_reg_dword(hk, TEXT("external_sim"),
635 config->external_sim, 0);
641 static int wpa_config_delete_subkeys(HKEY hk, const TCHAR *key)
647 ret = RegOpenKeyEx(hk, key, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &nhk);
648 if (ret != ERROR_SUCCESS) {
649 wpa_printf(MSG_DEBUG, "WINREG: Could not open key '" TSTR
650 "' for subkey deletion: error 0x%x (%d)", key,
651 (unsigned int) ret, (int) GetLastError());
660 ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL,
663 if (ret == ERROR_NO_MORE_ITEMS)
666 if (ret != ERROR_SUCCESS) {
667 wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x (%d)",
668 (unsigned int) ret, (int) GetLastError());
674 name[namelen] = TEXT('\0');
676 ret = RegDeleteKey(nhk, name);
677 if (ret != ERROR_SUCCESS) {
678 wpa_printf(MSG_DEBUG, "RegDeleteKey failed: 0x%x (%d)",
679 (unsigned int) ret, (int) GetLastError());
686 return errors ? -1 : 0;
690 static void write_str(HKEY hk, const char *field, struct wpa_ssid *ssid)
692 char *value = wpa_config_get(ssid, field);
695 wpa_config_write_reg_string(hk, field, value);
700 static void write_int(HKEY hk, const char *field, int value, int def)
705 os_snprintf(val, sizeof(val), "%d", value);
706 wpa_config_write_reg_string(hk, field, val);
710 static void write_bssid(HKEY hk, struct wpa_ssid *ssid)
712 char *value = wpa_config_get(ssid, "bssid");
715 wpa_config_write_reg_string(hk, "bssid", value);
720 static void write_psk(HKEY hk, struct wpa_ssid *ssid)
722 char *value = wpa_config_get(ssid, "psk");
725 wpa_config_write_reg_string(hk, "psk", value);
730 static void write_proto(HKEY hk, struct wpa_ssid *ssid)
734 if (ssid->proto == DEFAULT_PROTO)
737 value = wpa_config_get(ssid, "proto");
741 wpa_config_write_reg_string(hk, "proto", value);
746 static void write_key_mgmt(HKEY hk, struct wpa_ssid *ssid)
750 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
753 value = wpa_config_get(ssid, "key_mgmt");
757 wpa_config_write_reg_string(hk, "key_mgmt", value);
762 static void write_pairwise(HKEY hk, struct wpa_ssid *ssid)
766 if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
769 value = wpa_config_get(ssid, "pairwise");
773 wpa_config_write_reg_string(hk, "pairwise", value);
778 static void write_group(HKEY hk, struct wpa_ssid *ssid)
782 if (ssid->group_cipher == DEFAULT_GROUP)
785 value = wpa_config_get(ssid, "group");
789 wpa_config_write_reg_string(hk, "group", value);
794 static void write_auth_alg(HKEY hk, struct wpa_ssid *ssid)
798 if (ssid->auth_alg == 0)
801 value = wpa_config_get(ssid, "auth_alg");
805 wpa_config_write_reg_string(hk, "auth_alg", value);
810 #ifdef IEEE8021X_EAPOL
811 static void write_eap(HKEY hk, struct wpa_ssid *ssid)
815 value = wpa_config_get(ssid, "eap");
820 wpa_config_write_reg_string(hk, "eap", value);
823 #endif /* IEEE8021X_EAPOL */
826 static void write_wep_key(HKEY hk, int idx, struct wpa_ssid *ssid)
828 char field[20], *value;
830 os_snprintf(field, sizeof(field), "wep_key%d", idx);
831 value = wpa_config_get(ssid, field);
833 wpa_config_write_reg_string(hk, field, value);
839 static int wpa_config_write_network(HKEY hk, struct wpa_ssid *ssid, int id)
846 ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_CREATE_SUB_KEY, &nhk);
847 if (ret != ERROR_SUCCESS) {
848 wpa_printf(MSG_DEBUG, "WINREG: Could not open networks key "
849 "for subkey addition: error 0x%x (%d)",
850 (unsigned int) ret, (int) GetLastError());
855 wsprintf(name, L"%04d", id);
857 os_snprintf(name, sizeof(name), "%04d", id);
859 ret = RegCreateKeyEx(nhk, name, 0, NULL, 0, KEY_WRITE, NULL, &netw,
862 if (ret != ERROR_SUCCESS) {
863 wpa_printf(MSG_DEBUG, "WINREG: Could not add network key '%s':"
865 name, (unsigned int) ret, (int) GetLastError());
869 #define STR(t) write_str(netw, #t, ssid)
870 #define INT(t) write_int(netw, #t, ssid->t, 0)
871 #define INTe(t) write_int(netw, #t, ssid->eap.t, 0)
872 #define INT_DEF(t, def) write_int(netw, #t, ssid->t, def)
873 #define INT_DEFe(t, def) write_int(netw, #t, ssid->eap.t, def)
877 write_bssid(netw, ssid);
878 write_psk(netw, ssid);
880 STR(sae_password_id);
881 write_proto(netw, ssid);
882 write_key_mgmt(netw, ssid);
883 write_pairwise(netw, ssid);
884 write_group(netw, ssid);
885 write_auth_alg(netw, ssid);
886 #ifdef IEEE8021X_EAPOL
887 write_eap(netw, ssid);
889 STR(anonymous_identity);
896 STR(private_key_passwd);
899 STR(check_cert_subject);
900 STR(altsubject_match);
905 STR(private_key2_passwd);
908 STR(check_cert_subject2);
909 STR(altsubject_match2);
925 INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
926 #endif /* IEEE8021X_EAPOL */
927 for (i = 0; i < 4; i++)
928 write_wep_key(netw, i, ssid);
931 #ifdef IEEE8021X_EAPOL
932 INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
934 INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE);
935 #endif /* IEEE8021X_EAPOL */
937 write_int(netw, "proactive_key_caching", ssid->proactive_key_caching,
940 #ifdef CONFIG_IEEE80211W
941 write_int(netw, "ieee80211w", ssid->ieee80211w,
942 MGMT_FRAME_PROTECTION_DEFAULT);
943 #endif /* CONFIG_IEEE80211W */
946 INT(update_identifier);
947 #endif /* CONFIG_HS20 */
949 INT(ft_eap_pmksa_caching);
957 return errors ? -1 : 0;
961 static int wpa_config_write_blob(HKEY hk, struct wpa_config_blob *blob)
967 ret = RegCreateKeyEx(hk, TEXT("blobs"), 0, NULL, 0, KEY_WRITE, NULL,
969 if (ret != ERROR_SUCCESS) {
970 wpa_printf(MSG_DEBUG, "WINREG: Could not add blobs key: "
972 (unsigned int) ret, (int) GetLastError());
976 name = wpa_strdup_tchar(blob->name);
977 ret = RegSetValueEx(bhk, name, 0, REG_BINARY, blob->data,
979 if (ret != ERROR_SUCCESS) {
980 wpa_printf(MSG_ERROR, "WINREG: Failed to set blob %s': "
981 "error 0x%x (%d)", blob->name, (unsigned int) ret,
982 (int) GetLastError());
995 int wpa_config_write(const char *name, struct wpa_config *config)
1001 struct wpa_ssid *ssid;
1002 struct wpa_config_blob *blob;
1005 wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
1008 _snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name);
1010 os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name);
1011 #endif /* UNICODE */
1013 ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_SET_VALUE | DELETE, &hk);
1014 if (ret != ERROR_SUCCESS) {
1015 wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
1016 "configuration registry %s: error %d", buf,
1017 (int) GetLastError());
1021 if (wpa_config_write_global(config, hk)) {
1022 wpa_printf(MSG_ERROR, "Failed to write global configuration "
1027 wpa_config_delete_subkeys(hk, TEXT("networks"));
1028 for (ssid = config->ssid, id = 0; ssid; ssid = ssid->next, id++) {
1029 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS)
1030 continue; /* do not save temporary WPS networks */
1031 if (wpa_config_write_network(hk, ssid, id))
1035 RegDeleteKey(hk, TEXT("blobs"));
1036 for (blob = config->blobs; blob; blob = blob->next) {
1037 if (wpa_config_write_blob(hk, blob))
1043 wpa_printf(MSG_DEBUG, "Configuration '%s' written %ssuccessfully",
1044 name, errors ? "un" : "");
1045 return errors ? -1 : 0;