2 * WPA Supplicant / Configuration backend: text file
3 * Copyright (c) 2003-2012, 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 text files. All the
9 * configuration information is stored in a text file that uses a format
10 * described in the sample configuration file, wpa_supplicant.conf.
23 * wpa_config_get_line - Read the next configuration file line
24 * @s: Buffer for the line
25 * @size: The buffer length
26 * @stream: File stream to read from
27 * @line: Pointer to a variable storing the file line number
28 * @_pos: Buffer for the pointer to the beginning of data on the text line or
29 * %NULL if not needed (returned value used instead)
30 * Returns: Pointer to the beginning of data on the text line or %NULL if no
31 * more text lines are available.
33 * This function reads the next non-empty line from the configuration file and
34 * removes comments. The returned string is guaranteed to be null-terminated.
36 static char * wpa_config_get_line(char *s
, int size
, FILE *stream
, int *line
,
39 char *pos
, *end
, *sstart
;
41 while (fgets(s
, size
, stream
)) {
46 /* Skip white space from the beginning of line. */
47 while (*pos
== ' ' || *pos
== '\t' || *pos
== '\r')
50 /* Skip comment lines and empty lines */
51 if (*pos
== '#' || *pos
== '\n' || *pos
== '\0')
55 * Remove # comments unless they are within a double quoted
58 sstart
= os_strchr(pos
, '"');
60 sstart
= os_strrchr(sstart
+ 1, '"');
63 end
= os_strchr(sstart
, '#');
67 end
= pos
+ os_strlen(pos
) - 1;
69 /* Remove trailing white space. */
71 (*end
== '\n' || *end
== ' ' || *end
== '\t' ||
89 static int wpa_config_validate_network(struct wpa_ssid
*ssid
, int line
)
93 if (ssid
->passphrase
) {
95 wpa_printf(MSG_ERROR
, "Line %d: both PSK and "
96 "passphrase configured.", line
);
99 wpa_config_update_psk(ssid
);
102 if ((ssid
->group_cipher
& WPA_CIPHER_CCMP
) &&
103 !(ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
) &&
104 !(ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)) {
105 /* Group cipher cannot be stronger than the pairwise cipher. */
106 wpa_printf(MSG_DEBUG
, "Line %d: removed CCMP from group cipher"
107 " list since it was not allowed for pairwise "
109 ssid
->group_cipher
&= ~WPA_CIPHER_CCMP
;
116 static struct wpa_ssid
* wpa_config_read_network(FILE *f
, int *line
, int id
)
118 struct wpa_ssid
*ssid
;
119 int errors
= 0, end
= 0;
120 char buf
[256], *pos
, *pos2
;
122 wpa_printf(MSG_MSGDUMP
, "Line: %d - start of a new network block",
124 ssid
= os_zalloc(sizeof(*ssid
));
129 wpa_config_set_network_defaults(ssid
);
131 while (wpa_config_get_line(buf
, sizeof(buf
), f
, line
, &pos
)) {
132 if (os_strcmp(pos
, "}") == 0) {
137 pos2
= os_strchr(pos
, '=');
139 wpa_printf(MSG_ERROR
, "Line %d: Invalid SSID line "
140 "'%s'.", *line
, pos
);
147 if (os_strchr(pos2
+ 1, '"') == NULL
) {
148 wpa_printf(MSG_ERROR
, "Line %d: invalid "
149 "quotation '%s'.", *line
, pos2
);
155 if (wpa_config_set(ssid
, pos
, pos2
, *line
) < 0)
160 wpa_printf(MSG_ERROR
, "Line %d: network block was not "
161 "terminated properly.", *line
);
165 errors
+= wpa_config_validate_network(ssid
, *line
);
168 wpa_config_free_ssid(ssid
);
176 static struct wpa_cred
* wpa_config_read_cred(FILE *f
, int *line
, int id
)
178 struct wpa_cred
*cred
;
179 int errors
= 0, end
= 0;
180 char buf
[256], *pos
, *pos2
;
182 wpa_printf(MSG_MSGDUMP
, "Line: %d - start of a new cred block", *line
);
183 cred
= os_zalloc(sizeof(*cred
));
188 while (wpa_config_get_line(buf
, sizeof(buf
), f
, line
, &pos
)) {
189 if (os_strcmp(pos
, "}") == 0) {
194 pos2
= os_strchr(pos
, '=');
196 wpa_printf(MSG_ERROR
, "Line %d: Invalid cred line "
197 "'%s'.", *line
, pos
);
204 if (os_strchr(pos2
+ 1, '"') == NULL
) {
205 wpa_printf(MSG_ERROR
, "Line %d: invalid "
206 "quotation '%s'.", *line
, pos2
);
212 if (wpa_config_set_cred(cred
, pos
, pos2
, *line
) < 0)
217 wpa_printf(MSG_ERROR
, "Line %d: cred block was not "
218 "terminated properly.", *line
);
223 wpa_config_free_cred(cred
);
231 #ifndef CONFIG_NO_CONFIG_BLOBS
232 static struct wpa_config_blob
* wpa_config_read_blob(FILE *f
, int *line
,
235 struct wpa_config_blob
*blob
;
237 unsigned char *encoded
= NULL
, *nencoded
;
239 size_t encoded_len
= 0, len
;
241 wpa_printf(MSG_MSGDUMP
, "Line: %d - start of a new named blob '%s'",
244 while (wpa_config_get_line(buf
, sizeof(buf
), f
, line
, &pos
)) {
245 if (os_strcmp(pos
, "}") == 0) {
250 len
= os_strlen(pos
);
251 nencoded
= os_realloc(encoded
, encoded_len
+ len
);
252 if (nencoded
== NULL
) {
253 wpa_printf(MSG_ERROR
, "Line %d: not enough memory for "
259 os_memcpy(encoded
+ encoded_len
, pos
, len
);
264 wpa_printf(MSG_ERROR
, "Line %d: blob was not terminated "
270 blob
= os_zalloc(sizeof(*blob
));
275 blob
->name
= os_strdup(name
);
276 blob
->data
= base64_decode(encoded
, encoded_len
, &blob
->len
);
279 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
280 wpa_config_free_blob(blob
);
288 static int wpa_config_process_blob(struct wpa_config
*config
, FILE *f
,
289 int *line
, char *bname
)
292 struct wpa_config_blob
*blob
;
294 name_end
= os_strchr(bname
, '=');
295 if (name_end
== NULL
) {
296 wpa_printf(MSG_ERROR
, "Line %d: no blob name terminator",
302 blob
= wpa_config_read_blob(f
, line
, bname
);
304 wpa_printf(MSG_ERROR
, "Line %d: failed to read blob %s",
308 wpa_config_set_blob(config
, blob
);
311 #endif /* CONFIG_NO_CONFIG_BLOBS */
314 struct wpa_config
* wpa_config_read(const char *name
)
318 int errors
= 0, line
= 0;
319 struct wpa_ssid
*ssid
, *tail
= NULL
, *head
= NULL
;
320 struct wpa_cred
*cred
, *cred_tail
= NULL
, *cred_head
= NULL
;
321 struct wpa_config
*config
;
325 config
= wpa_config_alloc_empty(NULL
, NULL
);
328 wpa_printf(MSG_DEBUG
, "Reading configuration file '%s'", name
);
329 f
= fopen(name
, "r");
335 while (wpa_config_get_line(buf
, sizeof(buf
), f
, &line
, &pos
)) {
336 if (os_strcmp(pos
, "network={") == 0) {
337 ssid
= wpa_config_read_network(f
, &line
, id
++);
339 wpa_printf(MSG_ERROR
, "Line %d: failed to "
340 "parse network block.", line
);
350 if (wpa_config_add_prio_network(config
, ssid
)) {
351 wpa_printf(MSG_ERROR
, "Line %d: failed to add "
352 "network block to priority list.",
357 } else if (os_strcmp(pos
, "cred={") == 0) {
358 cred
= wpa_config_read_cred(f
, &line
, cred_id
++);
360 wpa_printf(MSG_ERROR
, "Line %d: failed to "
361 "parse cred block.", line
);
365 if (cred_head
== NULL
) {
366 cred_head
= cred_tail
= cred
;
368 cred_tail
->next
= cred
;
371 #ifndef CONFIG_NO_CONFIG_BLOBS
372 } else if (os_strncmp(pos
, "blob-base64-", 12) == 0) {
373 if (wpa_config_process_blob(config
, f
, &line
, pos
+ 12)
378 #endif /* CONFIG_NO_CONFIG_BLOBS */
379 } else if (wpa_config_process_global(config
, pos
, line
) < 0) {
380 wpa_printf(MSG_ERROR
, "Line %d: Invalid configuration "
381 "line '%s'.", line
, pos
);
390 wpa_config_debug_dump_networks(config
);
391 config
->cred
= cred_head
;
393 #ifndef WPA_IGNORE_CONFIG_ERRORS
395 wpa_config_free(config
);
399 #endif /* WPA_IGNORE_CONFIG_ERRORS */
405 #ifndef CONFIG_NO_CONFIG_WRITE
407 static void write_str(FILE *f
, const char *field
, struct wpa_ssid
*ssid
)
409 char *value
= wpa_config_get(ssid
, field
);
412 fprintf(f
, "\t%s=%s\n", field
, value
);
417 static void write_int(FILE *f
, const char *field
, int value
, int def
)
421 fprintf(f
, "\t%s=%d\n", field
, value
);
425 static void write_bssid(FILE *f
, struct wpa_ssid
*ssid
)
427 char *value
= wpa_config_get(ssid
, "bssid");
430 fprintf(f
, "\tbssid=%s\n", value
);
435 static void write_psk(FILE *f
, struct wpa_ssid
*ssid
)
437 char *value
= wpa_config_get(ssid
, "psk");
440 fprintf(f
, "\tpsk=%s\n", value
);
445 static void write_proto(FILE *f
, struct wpa_ssid
*ssid
)
449 if (ssid
->proto
== DEFAULT_PROTO
)
452 value
= wpa_config_get(ssid
, "proto");
456 fprintf(f
, "\tproto=%s\n", value
);
461 static void write_key_mgmt(FILE *f
, struct wpa_ssid
*ssid
)
465 if (ssid
->key_mgmt
== DEFAULT_KEY_MGMT
)
468 value
= wpa_config_get(ssid
, "key_mgmt");
472 fprintf(f
, "\tkey_mgmt=%s\n", value
);
477 static void write_pairwise(FILE *f
, struct wpa_ssid
*ssid
)
481 if (ssid
->pairwise_cipher
== DEFAULT_PAIRWISE
)
484 value
= wpa_config_get(ssid
, "pairwise");
488 fprintf(f
, "\tpairwise=%s\n", value
);
493 static void write_group(FILE *f
, struct wpa_ssid
*ssid
)
497 if (ssid
->group_cipher
== DEFAULT_GROUP
)
500 value
= wpa_config_get(ssid
, "group");
504 fprintf(f
, "\tgroup=%s\n", value
);
509 static void write_auth_alg(FILE *f
, struct wpa_ssid
*ssid
)
513 if (ssid
->auth_alg
== 0)
516 value
= wpa_config_get(ssid
, "auth_alg");
520 fprintf(f
, "\tauth_alg=%s\n", value
);
525 #ifdef IEEE8021X_EAPOL
526 static void write_eap(FILE *f
, struct wpa_ssid
*ssid
)
530 value
= wpa_config_get(ssid
, "eap");
535 fprintf(f
, "\teap=%s\n", value
);
538 #endif /* IEEE8021X_EAPOL */
541 static void write_wep_key(FILE *f
, int idx
, struct wpa_ssid
*ssid
)
543 char field
[20], *value
;
546 res
= os_snprintf(field
, sizeof(field
), "wep_key%d", idx
);
547 if (res
< 0 || (size_t) res
>= sizeof(field
))
549 value
= wpa_config_get(ssid
, field
);
551 fprintf(f
, "\t%s=%s\n", field
, value
);
558 static void write_p2p_client_list(FILE *f
, struct wpa_ssid
*ssid
)
560 char *value
= wpa_config_get(ssid
, "p2p_client_list");
563 fprintf(f
, "\tp2p_client_list=%s\n", value
);
566 #endif /* CONFIG_P2P */
569 static void wpa_config_write_network(FILE *f
, struct wpa_ssid
*ssid
)
573 #define STR(t) write_str(f, #t, ssid)
574 #define INT(t) write_int(f, #t, ssid->t, 0)
575 #define INTe(t) write_int(f, #t, ssid->eap.t, 0)
576 #define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
577 #define INT_DEFe(t, def) write_int(f, #t, ssid->eap.t, def)
581 write_bssid(f
, ssid
);
583 write_proto(f
, ssid
);
584 write_key_mgmt(f
, ssid
);
585 INT_DEF(bg_scan_period
, DEFAULT_BG_SCAN_PERIOD
);
586 write_pairwise(f
, ssid
);
587 write_group(f
, ssid
);
588 write_auth_alg(f
, ssid
);
591 #ifdef IEEE8021X_EAPOL
594 STR(anonymous_identity
);
600 STR(private_key_passwd
);
603 STR(altsubject_match
);
608 STR(private_key2_passwd
);
611 STR(altsubject_match2
);
627 INT_DEF(eapol_flags
, DEFAULT_EAPOL_FLAGS
);
628 #endif /* IEEE8021X_EAPOL */
629 for (i
= 0; i
< 4; i
++)
630 write_wep_key(f
, i
, ssid
);
633 #ifdef IEEE8021X_EAPOL
634 INT_DEF(eap_workaround
, DEFAULT_EAP_WORKAROUND
);
636 INT_DEFe(fragment_size
, DEFAULT_FRAGMENT_SIZE
);
637 #endif /* IEEE8021X_EAPOL */
639 INT(proactive_key_caching
);
642 #ifdef CONFIG_IEEE80211W
644 #endif /* CONFIG_IEEE80211W */
647 write_p2p_client_list(f
, ssid
);
648 #endif /* CONFIG_P2P */
656 static void wpa_config_write_cred(FILE *f
, struct wpa_cred
*cred
)
659 fprintf(f
, "\tpriority=%d\n", cred
->priority
);
661 fprintf(f
, "\tpcsc=%d\n", cred
->pcsc
);
663 fprintf(f
, "\trealm=\"%s\"\n", cred
->realm
);
665 fprintf(f
, "\tusername=\"%s\"\n", cred
->username
);
667 fprintf(f
, "\tpassword=\"%s\"\n", cred
->password
);
669 fprintf(f
, "\tca_cert=\"%s\"\n", cred
->ca_cert
);
671 fprintf(f
, "\timsi=\"%s\"\n", cred
->imsi
);
673 fprintf(f
, "\tmilenage=\"%s\"\n", cred
->milenage
);
675 fprintf(f
, "\tdomain=\"%s\"\n", cred
->domain
);
679 #ifndef CONFIG_NO_CONFIG_BLOBS
680 static int wpa_config_write_blob(FILE *f
, struct wpa_config_blob
*blob
)
682 unsigned char *encoded
;
684 encoded
= base64_encode(blob
->data
, blob
->len
, NULL
);
688 fprintf(f
, "\nblob-base64-%s={\n%s}\n", blob
->name
, encoded
);
692 #endif /* CONFIG_NO_CONFIG_BLOBS */
695 static void write_global_bin(FILE *f
, const char *field
,
696 const struct wpabuf
*val
)
704 fprintf(f
, "%s=", field
);
705 pos
= wpabuf_head(val
);
706 for (i
= 0; i
< wpabuf_len(val
); i
++)
707 fprintf(f
, "%02X", *pos
++);
712 static void wpa_config_write_global(FILE *f
, struct wpa_config
*config
)
714 #ifdef CONFIG_CTRL_IFACE
715 if (config
->ctrl_interface
)
716 fprintf(f
, "ctrl_interface=%s\n", config
->ctrl_interface
);
717 if (config
->ctrl_interface_group
)
718 fprintf(f
, "ctrl_interface_group=%s\n",
719 config
->ctrl_interface_group
);
720 #endif /* CONFIG_CTRL_IFACE */
721 if (config
->eapol_version
!= DEFAULT_EAPOL_VERSION
)
722 fprintf(f
, "eapol_version=%d\n", config
->eapol_version
);
723 if (config
->ap_scan
!= DEFAULT_AP_SCAN
)
724 fprintf(f
, "ap_scan=%d\n", config
->ap_scan
);
725 if (config
->disable_scan_offload
)
726 fprintf(f
, "disable_scan_offload=%d\n",
727 config
->disable_scan_offload
);
728 if (config
->fast_reauth
!= DEFAULT_FAST_REAUTH
)
729 fprintf(f
, "fast_reauth=%d\n", config
->fast_reauth
);
730 if (config
->opensc_engine_path
)
731 fprintf(f
, "opensc_engine_path=%s\n",
732 config
->opensc_engine_path
);
733 if (config
->pkcs11_engine_path
)
734 fprintf(f
, "pkcs11_engine_path=%s\n",
735 config
->pkcs11_engine_path
);
736 if (config
->pkcs11_module_path
)
737 fprintf(f
, "pkcs11_module_path=%s\n",
738 config
->pkcs11_module_path
);
739 if (config
->pcsc_reader
)
740 fprintf(f
, "pcsc_reader=%s\n", config
->pcsc_reader
);
741 if (config
->pcsc_pin
)
742 fprintf(f
, "pcsc_pin=%s\n", config
->pcsc_pin
);
743 if (config
->driver_param
)
744 fprintf(f
, "driver_param=%s\n", config
->driver_param
);
745 if (config
->dot11RSNAConfigPMKLifetime
)
746 fprintf(f
, "dot11RSNAConfigPMKLifetime=%d\n",
747 config
->dot11RSNAConfigPMKLifetime
);
748 if (config
->dot11RSNAConfigPMKReauthThreshold
)
749 fprintf(f
, "dot11RSNAConfigPMKReauthThreshold=%d\n",
750 config
->dot11RSNAConfigPMKReauthThreshold
);
751 if (config
->dot11RSNAConfigSATimeout
)
752 fprintf(f
, "dot11RSNAConfigSATimeout=%d\n",
753 config
->dot11RSNAConfigSATimeout
);
754 if (config
->update_config
)
755 fprintf(f
, "update_config=%d\n", config
->update_config
);
757 if (!is_nil_uuid(config
->uuid
)) {
759 uuid_bin2str(config
->uuid
, buf
, sizeof(buf
));
760 fprintf(f
, "uuid=%s\n", buf
);
762 if (config
->device_name
)
763 fprintf(f
, "device_name=%s\n", config
->device_name
);
764 if (config
->manufacturer
)
765 fprintf(f
, "manufacturer=%s\n", config
->manufacturer
);
766 if (config
->model_name
)
767 fprintf(f
, "model_name=%s\n", config
->model_name
);
768 if (config
->model_number
)
769 fprintf(f
, "model_number=%s\n", config
->model_number
);
770 if (config
->serial_number
)
771 fprintf(f
, "serial_number=%s\n", config
->serial_number
);
773 char _buf
[WPS_DEV_TYPE_BUFSIZE
], *buf
;
774 buf
= wps_dev_type_bin2str(config
->device_type
,
776 if (os_strcmp(buf
, "0-00000000-0") != 0)
777 fprintf(f
, "device_type=%s\n", buf
);
779 if (WPA_GET_BE32(config
->os_version
))
780 fprintf(f
, "os_version=%08x\n",
781 WPA_GET_BE32(config
->os_version
));
782 if (config
->config_methods
)
783 fprintf(f
, "config_methods=%s\n", config
->config_methods
);
784 if (config
->wps_cred_processing
)
785 fprintf(f
, "wps_cred_processing=%d\n",
786 config
->wps_cred_processing
);
787 if (config
->wps_vendor_ext_m1
) {
788 int i
, len
= wpabuf_len(config
->wps_vendor_ext_m1
);
789 const u8
*p
= wpabuf_head_u8(config
->wps_vendor_ext_m1
);
791 fprintf(f
, "wps_vendor_ext_m1=");
792 for (i
= 0; i
< len
; i
++)
793 fprintf(f
, "%02x", *p
++);
797 #endif /* CONFIG_WPS */
799 if (config
->p2p_listen_reg_class
)
800 fprintf(f
, "p2p_listen_reg_class=%u\n",
801 config
->p2p_listen_reg_class
);
802 if (config
->p2p_listen_channel
)
803 fprintf(f
, "p2p_listen_channel=%u\n",
804 config
->p2p_listen_channel
);
805 if (config
->p2p_oper_reg_class
)
806 fprintf(f
, "p2p_oper_reg_class=%u\n",
807 config
->p2p_oper_reg_class
);
808 if (config
->p2p_oper_channel
)
809 fprintf(f
, "p2p_oper_channel=%u\n", config
->p2p_oper_channel
);
810 if (config
->p2p_go_intent
!= DEFAULT_P2P_GO_INTENT
)
811 fprintf(f
, "p2p_go_intent=%u\n", config
->p2p_go_intent
);
812 if (config
->p2p_ssid_postfix
)
813 fprintf(f
, "p2p_ssid_postfix=%s\n", config
->p2p_ssid_postfix
);
814 if (config
->persistent_reconnect
)
815 fprintf(f
, "persistent_reconnect=%u\n",
816 config
->persistent_reconnect
);
817 if (config
->p2p_intra_bss
!= DEFAULT_P2P_INTRA_BSS
)
818 fprintf(f
, "p2p_intra_bss=%u\n", config
->p2p_intra_bss
);
819 if (config
->p2p_group_idle
)
820 fprintf(f
, "p2p_group_idle=%u\n", config
->p2p_group_idle
);
821 if (config
->p2p_pref_chan
) {
823 fprintf(f
, "p2p_pref_chan=");
824 for (i
= 0; i
< config
->num_p2p_pref_chan
; i
++) {
825 fprintf(f
, "%s%u:%u", i
> 0 ? "," : "",
826 config
->p2p_pref_chan
[i
].op_class
,
827 config
->p2p_pref_chan
[i
].chan
);
831 #endif /* CONFIG_P2P */
832 if (config
->country
[0] && config
->country
[1]) {
833 fprintf(f
, "country=%c%c\n",
834 config
->country
[0], config
->country
[1]);
836 if (config
->bss_max_count
!= DEFAULT_BSS_MAX_COUNT
)
837 fprintf(f
, "bss_max_count=%u\n", config
->bss_max_count
);
838 if (config
->bss_expiration_age
!= DEFAULT_BSS_EXPIRATION_AGE
)
839 fprintf(f
, "bss_expiration_age=%u\n",
840 config
->bss_expiration_age
);
841 if (config
->bss_expiration_scan_count
!=
842 DEFAULT_BSS_EXPIRATION_SCAN_COUNT
)
843 fprintf(f
, "bss_expiration_scan_count=%u\n",
844 config
->bss_expiration_scan_count
);
845 if (config
->filter_ssids
)
846 fprintf(f
, "filter_ssids=%d\n", config
->filter_ssids
);
847 if (config
->max_num_sta
!= DEFAULT_MAX_NUM_STA
)
848 fprintf(f
, "max_num_sta=%u\n", config
->max_num_sta
);
849 if (config
->disassoc_low_ack
)
850 fprintf(f
, "disassoc_low_ack=%u\n", config
->disassoc_low_ack
);
853 fprintf(f
, "hs20=1\n");
854 #endif /* CONFIG_HS20 */
855 #ifdef CONFIG_INTERWORKING
856 if (config
->interworking
)
857 fprintf(f
, "interworking=%u\n", config
->interworking
);
858 if (!is_zero_ether_addr(config
->hessid
))
859 fprintf(f
, "hessid=" MACSTR
"\n", MAC2STR(config
->hessid
));
860 if (config
->access_network_type
!= DEFAULT_ACCESS_NETWORK_TYPE
)
861 fprintf(f
, "access_network_type=%d\n",
862 config
->access_network_type
);
863 #endif /* CONFIG_INTERWORKING */
864 if (config
->pbc_in_m1
)
865 fprintf(f
, "pbc_in_m1=%u\n", config
->pbc_in_m1
);
866 if (config
->wps_nfc_dev_pw_id
)
867 fprintf(f
, "wps_nfc_dev_pw_id=%d\n",
868 config
->wps_nfc_dev_pw_id
);
869 write_global_bin(f
, "wps_nfc_dh_pubkey", config
->wps_nfc_dh_pubkey
);
870 write_global_bin(f
, "wps_nfc_dh_privkey", config
->wps_nfc_dh_privkey
);
871 write_global_bin(f
, "wps_nfc_dev_pw", config
->wps_nfc_dev_pw
);
873 if (config
->ext_password_backend
)
874 fprintf(f
, "ext_password_backend=%s\n",
875 config
->ext_password_backend
);
878 #endif /* CONFIG_NO_CONFIG_WRITE */
881 int wpa_config_write(const char *name
, struct wpa_config
*config
)
883 #ifndef CONFIG_NO_CONFIG_WRITE
885 struct wpa_ssid
*ssid
;
886 struct wpa_cred
*cred
;
887 #ifndef CONFIG_NO_CONFIG_BLOBS
888 struct wpa_config_blob
*blob
;
889 #endif /* CONFIG_NO_CONFIG_BLOBS */
892 wpa_printf(MSG_DEBUG
, "Writing configuration file '%s'", name
);
894 f
= fopen(name
, "w");
896 wpa_printf(MSG_DEBUG
, "Failed to open '%s' for writing", name
);
900 wpa_config_write_global(f
, config
);
902 for (cred
= config
->cred
; cred
; cred
= cred
->next
) {
903 fprintf(f
, "\ncred={\n");
904 wpa_config_write_cred(f
, cred
);
908 for (ssid
= config
->ssid
; ssid
; ssid
= ssid
->next
) {
909 if (ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
|| ssid
->temporary
)
910 continue; /* do not save temporary networks */
911 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) && !ssid
->psk_set
&&
913 continue; /* do not save invalid network */
914 fprintf(f
, "\nnetwork={\n");
915 wpa_config_write_network(f
, ssid
);
919 #ifndef CONFIG_NO_CONFIG_BLOBS
920 for (blob
= config
->blobs
; blob
; blob
= blob
->next
) {
921 ret
= wpa_config_write_blob(f
, blob
);
925 #endif /* CONFIG_NO_CONFIG_BLOBS */
929 wpa_printf(MSG_DEBUG
, "Configuration file '%s' written %ssuccessfully",
930 name
, ret
? "un" : "");
932 #else /* CONFIG_NO_CONFIG_WRITE */
934 #endif /* CONFIG_NO_CONFIG_WRITE */