2 * WPA Supplicant / Configuration backend: text file
3 * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
14 * This file implements a configuration backend for text files. All the
15 * configuration information is stored in a text file that uses a format
16 * described in the sample configuration file, wpa_supplicant.conf.
25 #include "eap_peer/eap_methods.h"
29 * wpa_config_get_line - Read the next configuration file line
30 * @s: Buffer for the line
31 * @size: The buffer length
32 * @stream: File stream to read from
33 * @line: Pointer to a variable storing the file line number
34 * @_pos: Buffer for the pointer to the beginning of data on the text line or
35 * %NULL if not needed (returned value used instead)
36 * Returns: Pointer to the beginning of data on the text line or %NULL if no
37 * more text lines are available.
39 * This function reads the next non-empty line from the configuration file and
40 * removes comments. The returned string is guaranteed to be null-terminated.
42 static char * wpa_config_get_line(char *s, int size, FILE *stream, int *line,
45 char *pos, *end, *sstart;
47 while (fgets(s, size, stream)) {
52 /* Skip white space from the beginning of line. */
53 while (*pos == ' ' || *pos == '\t' || *pos == '\r')
56 /* Skip comment lines and empty lines */
57 if (*pos == '#' || *pos == '\n' || *pos == '\0')
61 * Remove # comments unless they are within a double quoted
64 sstart = os_strchr(pos, '"');
66 sstart = os_strrchr(sstart + 1, '"');
69 end = os_strchr(sstart, '#');
73 end = pos + os_strlen(pos) - 1;
75 /* Remove trailing white space. */
77 (*end == '\n' || *end == ' ' || *end == '\t' ||
95 static int wpa_config_validate_network(struct wpa_ssid *ssid, int line)
99 if (ssid->passphrase) {
101 wpa_printf(MSG_ERROR, "Line %d: both PSK and "
102 "passphrase configured.", line);
105 wpa_config_update_psk(ssid);
108 if ((ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK |
109 WPA_KEY_MGMT_PSK_SHA256)) &&
111 wpa_printf(MSG_ERROR, "Line %d: WPA-PSK accepted for key "
112 "management, but no PSK configured.", line);
116 if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
117 !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
118 !(ssid->pairwise_cipher & WPA_CIPHER_NONE)) {
119 /* Group cipher cannot be stronger than the pairwise cipher. */
120 wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher"
121 " list since it was not allowed for pairwise "
123 ssid->group_cipher &= ~WPA_CIPHER_CCMP;
130 static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id)
132 struct wpa_ssid *ssid;
133 int errors = 0, end = 0;
134 char buf[256], *pos, *pos2;
136 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block",
138 ssid = os_zalloc(sizeof(*ssid));
143 wpa_config_set_network_defaults(ssid);
145 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
146 if (os_strcmp(pos, "}") == 0) {
151 pos2 = os_strchr(pos, '=');
153 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line "
154 "'%s'.", *line, pos);
161 if (os_strchr(pos2 + 1, '"') == NULL) {
162 wpa_printf(MSG_ERROR, "Line %d: invalid "
163 "quotation '%s'.", *line, pos2);
169 if (wpa_config_set(ssid, pos, pos2, *line) < 0)
174 wpa_printf(MSG_ERROR, "Line %d: network block was not "
175 "terminated properly.", *line);
179 errors += wpa_config_validate_network(ssid, *line);
182 wpa_config_free_ssid(ssid);
190 #ifndef CONFIG_NO_CONFIG_BLOBS
191 static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line,
194 struct wpa_config_blob *blob;
196 unsigned char *encoded = NULL, *nencoded;
198 size_t encoded_len = 0, len;
200 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'",
203 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
204 if (os_strcmp(pos, "}") == 0) {
209 len = os_strlen(pos);
210 nencoded = os_realloc(encoded, encoded_len + len);
211 if (nencoded == NULL) {
212 wpa_printf(MSG_ERROR, "Line %d: not enough memory for "
218 os_memcpy(encoded + encoded_len, pos, len);
223 wpa_printf(MSG_ERROR, "Line %d: blob was not terminated "
229 blob = os_zalloc(sizeof(*blob));
234 blob->name = os_strdup(name);
235 blob->data = base64_decode(encoded, encoded_len, &blob->len);
238 if (blob->name == NULL || blob->data == NULL) {
239 wpa_config_free_blob(blob);
247 static int wpa_config_process_blob(struct wpa_config *config, FILE *f,
248 int *line, char *bname)
251 struct wpa_config_blob *blob;
253 name_end = os_strchr(bname, '=');
254 if (name_end == NULL) {
255 wpa_printf(MSG_ERROR, "Line %d: no blob name terminator",
261 blob = wpa_config_read_blob(f, line, bname);
263 wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s",
267 wpa_config_set_blob(config, blob);
270 #endif /* CONFIG_NO_CONFIG_BLOBS */
273 struct global_parse_data {
275 int (*parser)(const struct global_parse_data *data,
276 struct wpa_config *config, int line, const char *value);
280 static int wpa_config_process_country(const struct global_parse_data *data,
281 struct wpa_config *config, int line,
284 if (!pos[0] || !pos[1]) {
285 wpa_printf(MSG_DEBUG, "Invalid country set");
288 config->country[0] = pos[0];
289 config->country[1] = pos[1];
290 wpa_printf(MSG_DEBUG, "country='%c%c'",
291 config->country[0], config->country[1]);
296 #ifdef CONFIG_CTRL_IFACE
297 static int wpa_config_process_ctrl_interface(
298 const struct global_parse_data *data, struct wpa_config *config,
299 int line, const char *pos)
301 os_free(config->ctrl_interface);
302 config->ctrl_interface = os_strdup(pos);
303 wpa_printf(MSG_DEBUG, "ctrl_interface='%s'", config->ctrl_interface);
308 static int wpa_config_process_ctrl_interface_group(
309 const struct global_parse_data *data, struct wpa_config *config,
310 int line, const char *pos)
312 os_free(config->ctrl_interface_group);
313 config->ctrl_interface_group = os_strdup(pos);
314 wpa_printf(MSG_DEBUG, "ctrl_interface_group='%s' (DEPRECATED)",
315 config->ctrl_interface_group);
318 #endif /* CONFIG_CTRL_IFACE */
321 static int wpa_config_process_eapol_version(
322 const struct global_parse_data *data, struct wpa_config *config,
323 int line, const char *pos)
325 config->eapol_version = atoi(pos);
326 if (config->eapol_version < 1 || config->eapol_version > 2) {
327 wpa_printf(MSG_ERROR, "Line %d: Invalid EAPOL version (%d): "
328 "'%s'.", line, config->eapol_version, pos);
331 wpa_printf(MSG_DEBUG, "eapol_version=%d", config->eapol_version);
336 static int wpa_config_process_ap_scan(const struct global_parse_data *data,
337 struct wpa_config *config, int line,
340 config->ap_scan = atoi(pos);
341 wpa_printf(MSG_DEBUG, "ap_scan=%d", config->ap_scan);
346 static int wpa_config_process_fast_reauth(const struct global_parse_data *data,
347 struct wpa_config *config, int line,
350 config->fast_reauth = atoi(pos);
351 wpa_printf(MSG_DEBUG, "fast_reauth=%d", config->fast_reauth);
356 #ifdef EAP_TLS_OPENSSL
358 static int wpa_config_process_opensc_engine_path(
359 const struct global_parse_data *data, struct wpa_config *config,
360 int line, const char *pos)
362 os_free(config->opensc_engine_path);
363 config->opensc_engine_path = os_strdup(pos);
364 wpa_printf(MSG_DEBUG, "opensc_engine_path='%s'",
365 config->opensc_engine_path);
370 static int wpa_config_process_pkcs11_engine_path(
371 const struct global_parse_data *data, struct wpa_config *config,
372 int line, const char *pos)
374 os_free(config->pkcs11_engine_path);
375 config->pkcs11_engine_path = os_strdup(pos);
376 wpa_printf(MSG_DEBUG, "pkcs11_engine_path='%s'",
377 config->pkcs11_engine_path);
382 static int wpa_config_process_pkcs11_module_path(
383 const struct global_parse_data *data, struct wpa_config *config,
384 int line, const char *pos)
386 os_free(config->pkcs11_module_path);
387 config->pkcs11_module_path = os_strdup(pos);
388 wpa_printf(MSG_DEBUG, "pkcs11_module_path='%s'",
389 config->pkcs11_module_path);
393 #endif /* EAP_TLS_OPENSSL */
396 static int wpa_config_process_driver_param(
397 const struct global_parse_data *data, struct wpa_config *config,
398 int line, const char *pos)
400 os_free(config->driver_param);
401 config->driver_param = os_strdup(pos);
402 wpa_printf(MSG_DEBUG, "driver_param='%s'", config->driver_param);
407 static int wpa_config_process_dot11RSNAConfigPMKLifetime(
408 const struct global_parse_data *data,
409 struct wpa_config *config, int line, const char *pos)
411 config->dot11RSNAConfigPMKLifetime = atoi(pos);
412 wpa_printf(MSG_DEBUG, "dot11RSNAConfigPMKLifetime=%d",
413 config->dot11RSNAConfigPMKLifetime);
418 static int wpa_config_process_dot11RSNAConfigPMKReauthThreshold(
419 const struct global_parse_data *data,
420 struct wpa_config *config, int line, const char *pos)
422 config->dot11RSNAConfigPMKReauthThreshold = atoi(pos);
423 wpa_printf(MSG_DEBUG, "dot11RSNAConfigPMKReauthThreshold=%d",
424 config->dot11RSNAConfigPMKReauthThreshold);
429 static int wpa_config_process_dot11RSNAConfigSATimeout(
430 const struct global_parse_data *data,
431 struct wpa_config *config, int line, const char *pos)
433 config->dot11RSNAConfigSATimeout = atoi(pos);
434 wpa_printf(MSG_DEBUG, "dot11RSNAConfigSATimeout=%d",
435 config->dot11RSNAConfigSATimeout);
440 #ifndef CONFIG_NO_CONFIG_WRITE
441 static int wpa_config_process_update_config(
442 const struct global_parse_data *data, struct wpa_config *config,
443 int line, const char *pos)
445 config->update_config = atoi(pos);
446 wpa_printf(MSG_DEBUG, "update_config=%d", config->update_config);
449 #endif /* CONFIG_NO_CONFIG_WRITE */
452 static int wpa_config_process_load_dynamic_eap(
453 const struct global_parse_data *data, struct wpa_config *config,
454 int line, const char *so)
457 wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
458 ret = eap_peer_method_load(so);
460 wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
463 wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
464 "method '%s'.", line, so);
474 static int wpa_config_process_uuid(const struct global_parse_data *data,
475 struct wpa_config *config, int line,
479 if (uuid_str2bin(pos, config->uuid)) {
480 wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
483 uuid_bin2str(config->uuid, buf, sizeof(buf));
484 wpa_printf(MSG_DEBUG, "uuid=%s", buf);
489 static int wpa_config_process_device_name(const struct global_parse_data *data,
490 struct wpa_config *config, int line,
493 if (os_strlen(pos) > 32)
495 os_free(config->device_name);
496 config->device_name = os_strdup(pos);
497 wpa_printf(MSG_DEBUG, "device_name='%s'", config->device_name);
502 static int wpa_config_process_manufacturer(
503 const struct global_parse_data *data, struct wpa_config *config,
504 int line, const char *pos)
506 if (os_strlen(pos) > 64)
508 os_free(config->manufacturer);
509 config->manufacturer = os_strdup(pos);
510 wpa_printf(MSG_DEBUG, "manufacturer='%s'", config->manufacturer);
515 static int wpa_config_process_model_name(const struct global_parse_data *data,
516 struct wpa_config *config, int line,
519 if (os_strlen(pos) > 32)
521 os_free(config->model_name);
522 config->model_name = os_strdup(pos);
523 wpa_printf(MSG_DEBUG, "model_name='%s'", config->model_name);
528 static int wpa_config_process_model_number(
529 const struct global_parse_data *data, struct wpa_config *config,
530 int line, const char *pos)
532 if (os_strlen(pos) > 32)
534 os_free(config->model_number);
535 config->model_number = os_strdup(pos);
536 wpa_printf(MSG_DEBUG, "model_number='%s'", config->model_number);
541 static int wpa_config_process_serial_number(
542 const struct global_parse_data *data, struct wpa_config *config,
543 int line, const char *pos)
545 if (os_strlen(pos) > 32)
547 os_free(config->serial_number);
548 config->serial_number = os_strdup(pos);
549 wpa_printf(MSG_DEBUG, "serial_number='%s'", config->serial_number);
554 static int wpa_config_process_device_type(const struct global_parse_data *data,
555 struct wpa_config *config, int line,
558 os_free(config->device_type);
559 config->device_type = os_strdup(pos);
560 wpa_printf(MSG_DEBUG, "device_type='%s'", config->device_type);
565 static int wpa_config_process_os_version(const struct global_parse_data *data,
566 struct wpa_config *config, int line,
569 if (hexstr2bin(pos, config->os_version, 4)) {
570 wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
573 wpa_printf(MSG_DEBUG, "os_version=%08x",
574 WPA_GET_BE32(config->os_version));
578 #endif /* CONFIG_WPS */
581 #define FUNC(f) #f, wpa_config_process_ ## f
583 static const struct global_parse_data global_fields[] = {
584 #ifdef CONFIG_CTRL_IFACE
585 { FUNC(ctrl_interface) },
586 { FUNC(ctrl_interface_group) },
587 #endif /* CONFIG_CTRL_IFACE */
588 { FUNC(eapol_version) },
590 { FUNC(fast_reauth) },
591 #ifdef EAP_TLS_OPENSSL
592 { FUNC(opensc_engine_path) },
593 { FUNC(pkcs11_engine_path) },
594 { FUNC(pkcs11_module_path) },
595 #endif /* EAP_TLS_OPENSSL */
596 { FUNC(driver_param) },
597 { FUNC(dot11RSNAConfigPMKLifetime) },
598 { FUNC(dot11RSNAConfigPMKReauthThreshold) },
599 { FUNC(dot11RSNAConfigSATimeout) },
600 #ifndef CONFIG_NO_CONFIG_WRITE
601 { FUNC(update_config) },
602 #endif /* CONFIG_NO_CONFIG_WRITE */
603 { FUNC(load_dynamic_eap) },
606 { FUNC(device_name) },
607 { FUNC(manufacturer) },
608 { FUNC(model_name) },
609 { FUNC(model_number) },
610 { FUNC(serial_number) },
611 { FUNC(device_type) },
612 { FUNC(os_version) },
613 #endif /* CONFIG_WPS */
616 #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
619 static int wpa_config_process_global(struct wpa_config *config, char *pos,
625 for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
626 const struct global_parse_data *field = &global_fields[i];
627 size_t flen = os_strlen(field->name);
628 if (os_strncmp(pos, field->name, flen) != 0 ||
632 if (field->parser(field, config, line, pos + flen + 1)) {
633 wpa_printf(MSG_ERROR, "Line %d: failed to "
634 "parse '%s'.", line, pos);
639 if (i == NUM_GLOBAL_FIELDS) {
640 wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",
649 struct wpa_config * wpa_config_read(const char *name)
653 int errors = 0, line = 0;
654 struct wpa_ssid *ssid, *tail = NULL, *head = NULL;
655 struct wpa_config *config;
658 config = wpa_config_alloc_empty(NULL, NULL);
661 wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
662 f = fopen(name, "r");
668 while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
669 if (os_strcmp(pos, "network={") == 0) {
670 ssid = wpa_config_read_network(f, &line, id++);
672 wpa_printf(MSG_ERROR, "Line %d: failed to "
673 "parse network block.", line);
683 if (wpa_config_add_prio_network(config, ssid)) {
684 wpa_printf(MSG_ERROR, "Line %d: failed to add "
685 "network block to priority list.",
690 #ifndef CONFIG_NO_CONFIG_BLOBS
691 } else if (os_strncmp(pos, "blob-base64-", 12) == 0) {
692 if (wpa_config_process_blob(config, f, &line, pos + 12)
697 #endif /* CONFIG_NO_CONFIG_BLOBS */
698 } else if (wpa_config_process_global(config, pos, line) < 0) {
699 wpa_printf(MSG_ERROR, "Line %d: Invalid configuration "
700 "line '%s'.", line, pos);
709 wpa_config_debug_dump_networks(config);
712 wpa_config_free(config);
721 #ifndef CONFIG_NO_CONFIG_WRITE
723 static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid)
725 char *value = wpa_config_get(ssid, field);
728 fprintf(f, "\t%s=%s\n", field, value);
733 static void write_int(FILE *f, const char *field, int value, int def)
737 fprintf(f, "\t%s=%d\n", field, value);
741 static void write_bssid(FILE *f, struct wpa_ssid *ssid)
743 char *value = wpa_config_get(ssid, "bssid");
746 fprintf(f, "\tbssid=%s\n", value);
751 static void write_psk(FILE *f, struct wpa_ssid *ssid)
753 char *value = wpa_config_get(ssid, "psk");
756 fprintf(f, "\tpsk=%s\n", value);
761 static void write_proto(FILE *f, struct wpa_ssid *ssid)
765 if (ssid->proto == DEFAULT_PROTO)
768 value = wpa_config_get(ssid, "proto");
772 fprintf(f, "\tproto=%s\n", value);
777 static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid)
781 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
784 value = wpa_config_get(ssid, "key_mgmt");
788 fprintf(f, "\tkey_mgmt=%s\n", value);
793 static void write_pairwise(FILE *f, struct wpa_ssid *ssid)
797 if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
800 value = wpa_config_get(ssid, "pairwise");
804 fprintf(f, "\tpairwise=%s\n", value);
809 static void write_group(FILE *f, struct wpa_ssid *ssid)
813 if (ssid->group_cipher == DEFAULT_GROUP)
816 value = wpa_config_get(ssid, "group");
820 fprintf(f, "\tgroup=%s\n", value);
825 static void write_auth_alg(FILE *f, struct wpa_ssid *ssid)
829 if (ssid->auth_alg == 0)
832 value = wpa_config_get(ssid, "auth_alg");
836 fprintf(f, "\tauth_alg=%s\n", value);
841 #ifdef IEEE8021X_EAPOL
842 static void write_eap(FILE *f, struct wpa_ssid *ssid)
846 value = wpa_config_get(ssid, "eap");
851 fprintf(f, "\teap=%s\n", value);
854 #endif /* IEEE8021X_EAPOL */
857 static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
859 char field[20], *value;
862 res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
863 if (res < 0 || (size_t) res >= sizeof(field))
865 value = wpa_config_get(ssid, field);
867 fprintf(f, "\t%s=%s\n", field, value);
873 static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
877 #define STR(t) write_str(f, #t, ssid)
878 #define INT(t) write_int(f, #t, ssid->t, 0)
879 #define INTe(t) write_int(f, #t, ssid->eap.t, 0)
880 #define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
881 #define INT_DEFe(t, def) write_int(f, #t, ssid->eap.t, def)
885 write_bssid(f, ssid);
887 write_proto(f, ssid);
888 write_key_mgmt(f, ssid);
889 write_pairwise(f, ssid);
890 write_group(f, ssid);
891 write_auth_alg(f, ssid);
892 #ifdef IEEE8021X_EAPOL
895 STR(anonymous_identity);
901 STR(private_key_passwd);
904 STR(altsubject_match);
909 STR(private_key2_passwd);
912 STR(altsubject_match2);
928 INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
929 #endif /* IEEE8021X_EAPOL */
930 for (i = 0; i < 4; i++)
931 write_wep_key(f, i, ssid);
934 #ifdef IEEE8021X_EAPOL
935 INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
937 INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE);
938 #endif /* IEEE8021X_EAPOL */
940 INT(proactive_key_caching);
943 #ifdef CONFIG_IEEE80211W
945 #endif /* CONFIG_IEEE80211W */
954 #ifndef CONFIG_NO_CONFIG_BLOBS
955 static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
957 unsigned char *encoded;
959 encoded = base64_encode(blob->data, blob->len, NULL);
963 fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
967 #endif /* CONFIG_NO_CONFIG_BLOBS */
970 static void wpa_config_write_global(FILE *f, struct wpa_config *config)
972 #ifdef CONFIG_CTRL_IFACE
973 if (config->ctrl_interface)
974 fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
975 if (config->ctrl_interface_group)
976 fprintf(f, "ctrl_interface_group=%s\n",
977 config->ctrl_interface_group);
978 #endif /* CONFIG_CTRL_IFACE */
979 if (config->eapol_version != DEFAULT_EAPOL_VERSION)
980 fprintf(f, "eapol_version=%d\n", config->eapol_version);
981 if (config->ap_scan != DEFAULT_AP_SCAN)
982 fprintf(f, "ap_scan=%d\n", config->ap_scan);
983 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
984 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
985 #ifdef EAP_TLS_OPENSSL
986 if (config->opensc_engine_path)
987 fprintf(f, "opensc_engine_path=%s\n",
988 config->opensc_engine_path);
989 if (config->pkcs11_engine_path)
990 fprintf(f, "pkcs11_engine_path=%s\n",
991 config->pkcs11_engine_path);
992 if (config->pkcs11_module_path)
993 fprintf(f, "pkcs11_module_path=%s\n",
994 config->pkcs11_module_path);
995 #endif /* EAP_TLS_OPENSSL */
996 if (config->driver_param)
997 fprintf(f, "driver_param=%s\n", config->driver_param);
998 if (config->dot11RSNAConfigPMKLifetime)
999 fprintf(f, "dot11RSNAConfigPMKLifetime=%d\n",
1000 config->dot11RSNAConfigPMKLifetime);
1001 if (config->dot11RSNAConfigPMKReauthThreshold)
1002 fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%d\n",
1003 config->dot11RSNAConfigPMKReauthThreshold);
1004 if (config->dot11RSNAConfigSATimeout)
1005 fprintf(f, "dot11RSNAConfigSATimeout=%d\n",
1006 config->dot11RSNAConfigSATimeout);
1007 if (config->update_config)
1008 fprintf(f, "update_config=%d\n", config->update_config);
1010 if (is_nil_uuid(config->uuid)) {
1012 uuid_bin2str(config->uuid, buf, sizeof(buf));
1013 fprintf(f, "uuid=%s\n", buf);
1015 if (config->device_name)
1016 fprintf(f, "device_name=%s\n", config->device_name);
1017 if (config->manufacturer)
1018 fprintf(f, "manufacturer=%s\n", config->manufacturer);
1019 if (config->model_name)
1020 fprintf(f, "model_name=%s\n", config->model_name);
1021 if (config->model_number)
1022 fprintf(f, "model_number=%s\n", config->model_number);
1023 if (config->serial_number)
1024 fprintf(f, "serial_number=%s\n", config->serial_number);
1025 if (config->device_type)
1026 fprintf(f, "device_type=%s\n", config->device_type);
1027 if (config->os_version)
1028 fprintf(f, "os_version=%08x\n",
1029 WPA_GET_BE32(config->os_version));
1030 #endif /* CONFIG_WPS */
1031 if (config->country[0] && config->country[1]) {
1032 fprintf(f, "country=%c%c\n",
1033 config->country[0], config->country[1]);
1037 #endif /* CONFIG_NO_CONFIG_WRITE */
1040 int wpa_config_write(const char *name, struct wpa_config *config)
1042 #ifndef CONFIG_NO_CONFIG_WRITE
1044 struct wpa_ssid *ssid;
1045 #ifndef CONFIG_NO_CONFIG_BLOBS
1046 struct wpa_config_blob *blob;
1047 #endif /* CONFIG_NO_CONFIG_BLOBS */
1050 wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
1052 f = fopen(name, "w");
1054 wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
1058 wpa_config_write_global(f, config);
1060 for (ssid = config->ssid; ssid; ssid = ssid->next) {
1061 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS)
1062 continue; /* do not save temporary WPS networks */
1063 fprintf(f, "\nnetwork={\n");
1064 wpa_config_write_network(f, ssid);
1068 #ifndef CONFIG_NO_CONFIG_BLOBS
1069 for (blob = config->blobs; blob; blob = blob->next) {
1070 ret = wpa_config_write_blob(f, blob);
1074 #endif /* CONFIG_NO_CONFIG_BLOBS */
1078 wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
1079 name, ret ? "un" : "");
1081 #else /* CONFIG_NO_CONFIG_WRITE */
1083 #endif /* CONFIG_NO_CONFIG_WRITE */