xref: /freebsd/contrib/wpa/wpa_supplicant/config_file.c (revision 32a95656b51ebefcdf3e0b02c110825f59abd26f)
139beb93cSSam Leffler /*
239beb93cSSam Leffler  * WPA Supplicant / Configuration backend: text file
3c1d255d3SCy Schubert  * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
439beb93cSSam Leffler  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
739beb93cSSam Leffler  *
839beb93cSSam Leffler  * This file implements a configuration backend for text files. All the
939beb93cSSam Leffler  * configuration information is stored in a text file that uses a format
1039beb93cSSam Leffler  * described in the sample configuration file, wpa_supplicant.conf.
1139beb93cSSam Leffler  */
1239beb93cSSam Leffler 
1339beb93cSSam Leffler #include "includes.h"
145b9c547cSRui Paulo #ifdef ANDROID
155b9c547cSRui Paulo #include <sys/stat.h>
165b9c547cSRui Paulo #endif /* ANDROID */
1739beb93cSSam Leffler 
1839beb93cSSam Leffler #include "common.h"
1939beb93cSSam Leffler #include "config.h"
2039beb93cSSam Leffler #include "base64.h"
2139beb93cSSam Leffler #include "uuid.h"
2285732ac8SCy Schubert #include "common/ieee802_1x_defs.h"
23f05cddf9SRui Paulo #include "p2p/p2p.h"
2439beb93cSSam Leffler #include "eap_peer/eap_methods.h"
25f05cddf9SRui Paulo #include "eap_peer/eap.h"
26c1d255d3SCy Schubert #include "utils/config.h"
2739beb93cSSam Leffler 
2839beb93cSSam Leffler 
2939beb93cSSam Leffler static int wpa_config_validate_network(struct wpa_ssid *ssid, int line)
3039beb93cSSam Leffler {
3139beb93cSSam Leffler 	int errors = 0;
3239beb93cSSam Leffler 
3339beb93cSSam Leffler 	if (ssid->passphrase) {
3439beb93cSSam Leffler 		if (ssid->psk_set) {
3539beb93cSSam Leffler 			wpa_printf(MSG_ERROR, "Line %d: both PSK and "
3639beb93cSSam Leffler 				   "passphrase configured.", line);
3739beb93cSSam Leffler 			errors++;
3839beb93cSSam Leffler 		}
3939beb93cSSam Leffler 		wpa_config_update_psk(ssid);
4039beb93cSSam Leffler 	}
4139beb93cSSam Leffler 
4285732ac8SCy Schubert 	if (ssid->disabled == 2)
4385732ac8SCy Schubert 		ssid->p2p_persistent_group = 1;
4485732ac8SCy Schubert 
4539beb93cSSam Leffler 	if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
4685732ac8SCy Schubert 	    !(ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 |
4785732ac8SCy Schubert 				       WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256 |
4885732ac8SCy Schubert 				       WPA_CIPHER_NONE))) {
4939beb93cSSam Leffler 		/* Group cipher cannot be stronger than the pairwise cipher. */
5039beb93cSSam Leffler 		wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher"
5139beb93cSSam Leffler 			   " list since it was not allowed for pairwise "
5239beb93cSSam Leffler 			   "cipher", line);
5339beb93cSSam Leffler 		ssid->group_cipher &= ~WPA_CIPHER_CCMP;
5439beb93cSSam Leffler 	}
5539beb93cSSam Leffler 
565b9c547cSRui Paulo 	if (ssid->mode == WPAS_MODE_MESH &&
575b9c547cSRui Paulo 	    (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
585b9c547cSRui Paulo 	    ssid->key_mgmt != WPA_KEY_MGMT_SAE)) {
595b9c547cSRui Paulo 		wpa_printf(MSG_ERROR,
605b9c547cSRui Paulo 			   "Line %d: key_mgmt for mesh network should be open or SAE",
615b9c547cSRui Paulo 			   line);
625b9c547cSRui Paulo 		errors++;
635b9c547cSRui Paulo 	}
645b9c547cSRui Paulo 
654bc52338SCy Schubert #ifdef CONFIG_OCV
664bc52338SCy Schubert 	if (ssid->ocv && ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
674bc52338SCy Schubert 		wpa_printf(MSG_ERROR,
684bc52338SCy Schubert 			   "Line %d: PMF needs to be enabled whenever using OCV",
694bc52338SCy Schubert 			   line);
704bc52338SCy Schubert 		errors++;
714bc52338SCy Schubert 	}
724bc52338SCy Schubert #endif /* CONFIG_OCV */
734bc52338SCy Schubert 
7439beb93cSSam Leffler 	return errors;
7539beb93cSSam Leffler }
7639beb93cSSam Leffler 
7739beb93cSSam Leffler 
7839beb93cSSam Leffler static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id)
7939beb93cSSam Leffler {
8039beb93cSSam Leffler 	struct wpa_ssid *ssid;
8139beb93cSSam Leffler 	int errors = 0, end = 0;
82f05cddf9SRui Paulo 	char buf[2000], *pos, *pos2;
8339beb93cSSam Leffler 
8439beb93cSSam Leffler 	wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block",
8539beb93cSSam Leffler 		   *line);
8639beb93cSSam Leffler 	ssid = os_zalloc(sizeof(*ssid));
8739beb93cSSam Leffler 	if (ssid == NULL)
8839beb93cSSam Leffler 		return NULL;
895b9c547cSRui Paulo 	dl_list_init(&ssid->psk_list);
9039beb93cSSam Leffler 	ssid->id = id;
9139beb93cSSam Leffler 
9239beb93cSSam Leffler 	wpa_config_set_network_defaults(ssid);
9339beb93cSSam Leffler 
9439beb93cSSam Leffler 	while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
9539beb93cSSam Leffler 		if (os_strcmp(pos, "}") == 0) {
9639beb93cSSam Leffler 			end = 1;
9739beb93cSSam Leffler 			break;
9839beb93cSSam Leffler 		}
9939beb93cSSam Leffler 
10039beb93cSSam Leffler 		pos2 = os_strchr(pos, '=');
10139beb93cSSam Leffler 		if (pos2 == NULL) {
10239beb93cSSam Leffler 			wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line "
10339beb93cSSam Leffler 				   "'%s'.", *line, pos);
10439beb93cSSam Leffler 			errors++;
10539beb93cSSam Leffler 			continue;
10639beb93cSSam Leffler 		}
10739beb93cSSam Leffler 
10839beb93cSSam Leffler 		*pos2++ = '\0';
10939beb93cSSam Leffler 		if (*pos2 == '"') {
11039beb93cSSam Leffler 			if (os_strchr(pos2 + 1, '"') == NULL) {
11139beb93cSSam Leffler 				wpa_printf(MSG_ERROR, "Line %d: invalid "
11239beb93cSSam Leffler 					   "quotation '%s'.", *line, pos2);
11339beb93cSSam Leffler 				errors++;
11439beb93cSSam Leffler 				continue;
11539beb93cSSam Leffler 			}
11639beb93cSSam Leffler 		}
11739beb93cSSam Leffler 
118c1d255d3SCy Schubert 		if (wpa_config_set(ssid, pos, pos2, *line) < 0) {
119c1d255d3SCy Schubert #ifndef CONFIG_WEP
120c1d255d3SCy Schubert 			if (os_strcmp(pos, "wep_key0") == 0 ||
121c1d255d3SCy Schubert 			    os_strcmp(pos, "wep_key1") == 0 ||
122c1d255d3SCy Schubert 			    os_strcmp(pos, "wep_key2") == 0 ||
123c1d255d3SCy Schubert 			    os_strcmp(pos, "wep_key3") == 0 ||
124c1d255d3SCy Schubert 			    os_strcmp(pos, "wep_tx_keyidx") == 0) {
125c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
126c1d255d3SCy Schubert 					   "Line %d: unsupported WEP parameter",
127c1d255d3SCy Schubert 					   *line);
128c1d255d3SCy Schubert 				ssid->disabled = 1;
129c1d255d3SCy Schubert 				continue;
130c1d255d3SCy Schubert 			}
131c1d255d3SCy Schubert #endif /* CONFIG_WEP */
13239beb93cSSam Leffler 			errors++;
13339beb93cSSam Leffler 		}
134c1d255d3SCy Schubert 	}
13539beb93cSSam Leffler 
13639beb93cSSam Leffler 	if (!end) {
13739beb93cSSam Leffler 		wpa_printf(MSG_ERROR, "Line %d: network block was not "
13839beb93cSSam Leffler 			   "terminated properly.", *line);
13939beb93cSSam Leffler 		errors++;
14039beb93cSSam Leffler 	}
14139beb93cSSam Leffler 
14239beb93cSSam Leffler 	errors += wpa_config_validate_network(ssid, *line);
14339beb93cSSam Leffler 
14439beb93cSSam Leffler 	if (errors) {
14539beb93cSSam Leffler 		wpa_config_free_ssid(ssid);
14639beb93cSSam Leffler 		ssid = NULL;
14739beb93cSSam Leffler 	}
14839beb93cSSam Leffler 
14939beb93cSSam Leffler 	return ssid;
15039beb93cSSam Leffler }
15139beb93cSSam Leffler 
15239beb93cSSam Leffler 
153f05cddf9SRui Paulo static struct wpa_cred * wpa_config_read_cred(FILE *f, int *line, int id)
154f05cddf9SRui Paulo {
155f05cddf9SRui Paulo 	struct wpa_cred *cred;
156f05cddf9SRui Paulo 	int errors = 0, end = 0;
157f05cddf9SRui Paulo 	char buf[256], *pos, *pos2;
158f05cddf9SRui Paulo 
159f05cddf9SRui Paulo 	wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new cred block", *line);
160f05cddf9SRui Paulo 	cred = os_zalloc(sizeof(*cred));
161f05cddf9SRui Paulo 	if (cred == NULL)
162f05cddf9SRui Paulo 		return NULL;
163f05cddf9SRui Paulo 	cred->id = id;
1645b9c547cSRui Paulo 	cred->sim_num = DEFAULT_USER_SELECTED_SIM;
165f05cddf9SRui Paulo 
166f05cddf9SRui Paulo 	while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
167f05cddf9SRui Paulo 		if (os_strcmp(pos, "}") == 0) {
168f05cddf9SRui Paulo 			end = 1;
169f05cddf9SRui Paulo 			break;
170f05cddf9SRui Paulo 		}
171f05cddf9SRui Paulo 
172f05cddf9SRui Paulo 		pos2 = os_strchr(pos, '=');
173f05cddf9SRui Paulo 		if (pos2 == NULL) {
174f05cddf9SRui Paulo 			wpa_printf(MSG_ERROR, "Line %d: Invalid cred line "
175f05cddf9SRui Paulo 				   "'%s'.", *line, pos);
176f05cddf9SRui Paulo 			errors++;
177f05cddf9SRui Paulo 			continue;
178f05cddf9SRui Paulo 		}
179f05cddf9SRui Paulo 
180f05cddf9SRui Paulo 		*pos2++ = '\0';
181f05cddf9SRui Paulo 		if (*pos2 == '"') {
182f05cddf9SRui Paulo 			if (os_strchr(pos2 + 1, '"') == NULL) {
183f05cddf9SRui Paulo 				wpa_printf(MSG_ERROR, "Line %d: invalid "
184f05cddf9SRui Paulo 					   "quotation '%s'.", *line, pos2);
185f05cddf9SRui Paulo 				errors++;
186f05cddf9SRui Paulo 				continue;
187f05cddf9SRui Paulo 			}
188f05cddf9SRui Paulo 		}
189f05cddf9SRui Paulo 
190f05cddf9SRui Paulo 		if (wpa_config_set_cred(cred, pos, pos2, *line) < 0)
191f05cddf9SRui Paulo 			errors++;
192f05cddf9SRui Paulo 	}
193f05cddf9SRui Paulo 
194f05cddf9SRui Paulo 	if (!end) {
195f05cddf9SRui Paulo 		wpa_printf(MSG_ERROR, "Line %d: cred block was not "
196f05cddf9SRui Paulo 			   "terminated properly.", *line);
197f05cddf9SRui Paulo 		errors++;
198f05cddf9SRui Paulo 	}
199f05cddf9SRui Paulo 
200f05cddf9SRui Paulo 	if (errors) {
201f05cddf9SRui Paulo 		wpa_config_free_cred(cred);
202f05cddf9SRui Paulo 		cred = NULL;
203f05cddf9SRui Paulo 	}
204f05cddf9SRui Paulo 
205f05cddf9SRui Paulo 	return cred;
206f05cddf9SRui Paulo }
207f05cddf9SRui Paulo 
208f05cddf9SRui Paulo 
20939beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS
21039beb93cSSam Leffler static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line,
21139beb93cSSam Leffler 						     const char *name)
21239beb93cSSam Leffler {
21339beb93cSSam Leffler 	struct wpa_config_blob *blob;
21439beb93cSSam Leffler 	char buf[256], *pos;
215c1d255d3SCy Schubert 	char *encoded = NULL, *nencoded;
21639beb93cSSam Leffler 	int end = 0;
21739beb93cSSam Leffler 	size_t encoded_len = 0, len;
21839beb93cSSam Leffler 
21939beb93cSSam Leffler 	wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'",
22039beb93cSSam Leffler 		   *line, name);
22139beb93cSSam Leffler 
22239beb93cSSam Leffler 	while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
22339beb93cSSam Leffler 		if (os_strcmp(pos, "}") == 0) {
22439beb93cSSam Leffler 			end = 1;
22539beb93cSSam Leffler 			break;
22639beb93cSSam Leffler 		}
22739beb93cSSam Leffler 
22839beb93cSSam Leffler 		len = os_strlen(pos);
22939beb93cSSam Leffler 		nencoded = os_realloc(encoded, encoded_len + len);
23039beb93cSSam Leffler 		if (nencoded == NULL) {
23139beb93cSSam Leffler 			wpa_printf(MSG_ERROR, "Line %d: not enough memory for "
23239beb93cSSam Leffler 				   "blob", *line);
23339beb93cSSam Leffler 			os_free(encoded);
23439beb93cSSam Leffler 			return NULL;
23539beb93cSSam Leffler 		}
23639beb93cSSam Leffler 		encoded = nencoded;
23739beb93cSSam Leffler 		os_memcpy(encoded + encoded_len, pos, len);
23839beb93cSSam Leffler 		encoded_len += len;
23939beb93cSSam Leffler 	}
24039beb93cSSam Leffler 
24185732ac8SCy Schubert 	if (!end || !encoded) {
24239beb93cSSam Leffler 		wpa_printf(MSG_ERROR, "Line %d: blob was not terminated "
24339beb93cSSam Leffler 			   "properly", *line);
24439beb93cSSam Leffler 		os_free(encoded);
24539beb93cSSam Leffler 		return NULL;
24639beb93cSSam Leffler 	}
24739beb93cSSam Leffler 
24839beb93cSSam Leffler 	blob = os_zalloc(sizeof(*blob));
24939beb93cSSam Leffler 	if (blob == NULL) {
25039beb93cSSam Leffler 		os_free(encoded);
25139beb93cSSam Leffler 		return NULL;
25239beb93cSSam Leffler 	}
25339beb93cSSam Leffler 	blob->name = os_strdup(name);
25439beb93cSSam Leffler 	blob->data = base64_decode(encoded, encoded_len, &blob->len);
25539beb93cSSam Leffler 	os_free(encoded);
25639beb93cSSam Leffler 
25739beb93cSSam Leffler 	if (blob->name == NULL || blob->data == NULL) {
25839beb93cSSam Leffler 		wpa_config_free_blob(blob);
25939beb93cSSam Leffler 		return NULL;
26039beb93cSSam Leffler 	}
26139beb93cSSam Leffler 
26239beb93cSSam Leffler 	return blob;
26339beb93cSSam Leffler }
26439beb93cSSam Leffler 
26539beb93cSSam Leffler 
26639beb93cSSam Leffler static int wpa_config_process_blob(struct wpa_config *config, FILE *f,
26739beb93cSSam Leffler 				   int *line, char *bname)
26839beb93cSSam Leffler {
26939beb93cSSam Leffler 	char *name_end;
27039beb93cSSam Leffler 	struct wpa_config_blob *blob;
27139beb93cSSam Leffler 
27239beb93cSSam Leffler 	name_end = os_strchr(bname, '=');
27339beb93cSSam Leffler 	if (name_end == NULL) {
27439beb93cSSam Leffler 		wpa_printf(MSG_ERROR, "Line %d: no blob name terminator",
27539beb93cSSam Leffler 			   *line);
27639beb93cSSam Leffler 		return -1;
27739beb93cSSam Leffler 	}
27839beb93cSSam Leffler 	*name_end = '\0';
27939beb93cSSam Leffler 
28039beb93cSSam Leffler 	blob = wpa_config_read_blob(f, line, bname);
28139beb93cSSam Leffler 	if (blob == NULL) {
28239beb93cSSam Leffler 		wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s",
28339beb93cSSam Leffler 			   *line, bname);
28439beb93cSSam Leffler 		return -1;
28539beb93cSSam Leffler 	}
28639beb93cSSam Leffler 	wpa_config_set_blob(config, blob);
28739beb93cSSam Leffler 	return 0;
28839beb93cSSam Leffler }
28939beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */
29039beb93cSSam Leffler 
29139beb93cSSam Leffler 
2925b9c547cSRui Paulo struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp)
29339beb93cSSam Leffler {
29439beb93cSSam Leffler 	FILE *f;
295f05cddf9SRui Paulo 	char buf[512], *pos;
29639beb93cSSam Leffler 	int errors = 0, line = 0;
2975b9c547cSRui Paulo 	struct wpa_ssid *ssid, *tail, *head;
2985b9c547cSRui Paulo 	struct wpa_cred *cred, *cred_tail, *cred_head;
29939beb93cSSam Leffler 	struct wpa_config *config;
30039beb93cSSam Leffler 	int id = 0;
301f05cddf9SRui Paulo 	int cred_id = 0;
30239beb93cSSam Leffler 
3035b9c547cSRui Paulo 	if (name == NULL)
3045b9c547cSRui Paulo 		return NULL;
3055b9c547cSRui Paulo 	if (cfgp)
3065b9c547cSRui Paulo 		config = cfgp;
3075b9c547cSRui Paulo 	else
30839beb93cSSam Leffler 		config = wpa_config_alloc_empty(NULL, NULL);
309f05cddf9SRui Paulo 	if (config == NULL) {
310f05cddf9SRui Paulo 		wpa_printf(MSG_ERROR, "Failed to allocate config file "
311f05cddf9SRui Paulo 			   "structure");
31239beb93cSSam Leffler 		return NULL;
313f05cddf9SRui Paulo 	}
3145b9c547cSRui Paulo 	tail = head = config->ssid;
3155b9c547cSRui Paulo 	while (tail && tail->next)
3165b9c547cSRui Paulo 		tail = tail->next;
3175b9c547cSRui Paulo 	cred_tail = cred_head = config->cred;
3185b9c547cSRui Paulo 	while (cred_tail && cred_tail->next)
3195b9c547cSRui Paulo 		cred_tail = cred_tail->next;
320f05cddf9SRui Paulo 
32139beb93cSSam Leffler 	wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
32239beb93cSSam Leffler 	f = fopen(name, "r");
32339beb93cSSam Leffler 	if (f == NULL) {
324f05cddf9SRui Paulo 		wpa_printf(MSG_ERROR, "Failed to open config file '%s', "
325f05cddf9SRui Paulo 			   "error: %s", name, strerror(errno));
32685732ac8SCy Schubert 		if (config != cfgp)
32739beb93cSSam Leffler 			os_free(config);
32839beb93cSSam Leffler 		return NULL;
32939beb93cSSam Leffler 	}
33039beb93cSSam Leffler 
33139beb93cSSam Leffler 	while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
33239beb93cSSam Leffler 		if (os_strcmp(pos, "network={") == 0) {
33339beb93cSSam Leffler 			ssid = wpa_config_read_network(f, &line, id++);
33439beb93cSSam Leffler 			if (ssid == NULL) {
33539beb93cSSam Leffler 				wpa_printf(MSG_ERROR, "Line %d: failed to "
33639beb93cSSam Leffler 					   "parse network block.", line);
33739beb93cSSam Leffler 				errors++;
33839beb93cSSam Leffler 				continue;
33939beb93cSSam Leffler 			}
34039beb93cSSam Leffler 			if (head == NULL) {
34139beb93cSSam Leffler 				head = tail = ssid;
34239beb93cSSam Leffler 			} else {
34339beb93cSSam Leffler 				tail->next = ssid;
34439beb93cSSam Leffler 				tail = ssid;
34539beb93cSSam Leffler 			}
34639beb93cSSam Leffler 			if (wpa_config_add_prio_network(config, ssid)) {
34739beb93cSSam Leffler 				wpa_printf(MSG_ERROR, "Line %d: failed to add "
34839beb93cSSam Leffler 					   "network block to priority list.",
34939beb93cSSam Leffler 					   line);
35039beb93cSSam Leffler 				errors++;
35139beb93cSSam Leffler 				continue;
35239beb93cSSam Leffler 			}
353f05cddf9SRui Paulo 		} else if (os_strcmp(pos, "cred={") == 0) {
354f05cddf9SRui Paulo 			cred = wpa_config_read_cred(f, &line, cred_id++);
355f05cddf9SRui Paulo 			if (cred == NULL) {
356f05cddf9SRui Paulo 				wpa_printf(MSG_ERROR, "Line %d: failed to "
357f05cddf9SRui Paulo 					   "parse cred block.", line);
358f05cddf9SRui Paulo 				errors++;
359f05cddf9SRui Paulo 				continue;
360f05cddf9SRui Paulo 			}
361f05cddf9SRui Paulo 			if (cred_head == NULL) {
362f05cddf9SRui Paulo 				cred_head = cred_tail = cred;
363f05cddf9SRui Paulo 			} else {
364f05cddf9SRui Paulo 				cred_tail->next = cred;
365f05cddf9SRui Paulo 				cred_tail = cred;
366f05cddf9SRui Paulo 			}
36739beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS
36839beb93cSSam Leffler 		} else if (os_strncmp(pos, "blob-base64-", 12) == 0) {
36939beb93cSSam Leffler 			if (wpa_config_process_blob(config, f, &line, pos + 12)
37039beb93cSSam Leffler 			    < 0) {
371f05cddf9SRui Paulo 				wpa_printf(MSG_ERROR, "Line %d: failed to "
372f05cddf9SRui Paulo 					   "process blob.", line);
37339beb93cSSam Leffler 				errors++;
37439beb93cSSam Leffler 				continue;
37539beb93cSSam Leffler 			}
37639beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */
37739beb93cSSam Leffler 		} else if (wpa_config_process_global(config, pos, line) < 0) {
37839beb93cSSam Leffler 			wpa_printf(MSG_ERROR, "Line %d: Invalid configuration "
37939beb93cSSam Leffler 				   "line '%s'.", line, pos);
38039beb93cSSam Leffler 			errors++;
38139beb93cSSam Leffler 			continue;
38239beb93cSSam Leffler 		}
38339beb93cSSam Leffler 	}
38439beb93cSSam Leffler 
38539beb93cSSam Leffler 	fclose(f);
38639beb93cSSam Leffler 
38739beb93cSSam Leffler 	config->ssid = head;
38839beb93cSSam Leffler 	wpa_config_debug_dump_networks(config);
389f05cddf9SRui Paulo 	config->cred = cred_head;
39039beb93cSSam Leffler 
391f05cddf9SRui Paulo #ifndef WPA_IGNORE_CONFIG_ERRORS
39239beb93cSSam Leffler 	if (errors) {
39385732ac8SCy Schubert 		if (config != cfgp)
39439beb93cSSam Leffler 			wpa_config_free(config);
39539beb93cSSam Leffler 		config = NULL;
39639beb93cSSam Leffler 		head = NULL;
39739beb93cSSam Leffler 	}
398f05cddf9SRui Paulo #endif /* WPA_IGNORE_CONFIG_ERRORS */
39939beb93cSSam Leffler 
40039beb93cSSam Leffler 	return config;
40139beb93cSSam Leffler }
40239beb93cSSam Leffler 
40339beb93cSSam Leffler 
40439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE
40539beb93cSSam Leffler 
40639beb93cSSam Leffler static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid)
40739beb93cSSam Leffler {
40839beb93cSSam Leffler 	char *value = wpa_config_get(ssid, field);
40939beb93cSSam Leffler 	if (value == NULL)
41039beb93cSSam Leffler 		return;
41139beb93cSSam Leffler 	fprintf(f, "\t%s=%s\n", field, value);
4124bc52338SCy Schubert 	str_clear_free(value);
41339beb93cSSam Leffler }
41439beb93cSSam Leffler 
41539beb93cSSam Leffler 
41639beb93cSSam Leffler static void write_int(FILE *f, const char *field, int value, int def)
41739beb93cSSam Leffler {
41839beb93cSSam Leffler 	if (value == def)
41939beb93cSSam Leffler 		return;
42039beb93cSSam Leffler 	fprintf(f, "\t%s=%d\n", field, value);
42139beb93cSSam Leffler }
42239beb93cSSam Leffler 
42339beb93cSSam Leffler 
42439beb93cSSam Leffler static void write_bssid(FILE *f, struct wpa_ssid *ssid)
42539beb93cSSam Leffler {
42639beb93cSSam Leffler 	char *value = wpa_config_get(ssid, "bssid");
42739beb93cSSam Leffler 	if (value == NULL)
42839beb93cSSam Leffler 		return;
42939beb93cSSam Leffler 	fprintf(f, "\tbssid=%s\n", value);
43039beb93cSSam Leffler 	os_free(value);
43139beb93cSSam Leffler }
43239beb93cSSam Leffler 
43339beb93cSSam Leffler 
43485732ac8SCy Schubert static void write_bssid_hint(FILE *f, struct wpa_ssid *ssid)
43585732ac8SCy Schubert {
43685732ac8SCy Schubert 	char *value = wpa_config_get(ssid, "bssid_hint");
43785732ac8SCy Schubert 
43885732ac8SCy Schubert 	if (!value)
43985732ac8SCy Schubert 		return;
44085732ac8SCy Schubert 	fprintf(f, "\tbssid_hint=%s\n", value);
44185732ac8SCy Schubert 	os_free(value);
44285732ac8SCy Schubert }
44385732ac8SCy Schubert 
44485732ac8SCy Schubert 
44539beb93cSSam Leffler static void write_psk(FILE *f, struct wpa_ssid *ssid)
44639beb93cSSam Leffler {
447325151a3SRui Paulo 	char *value;
448325151a3SRui Paulo 
449325151a3SRui Paulo 	if (ssid->mem_only_psk)
450325151a3SRui Paulo 		return;
451325151a3SRui Paulo 
452325151a3SRui Paulo 	value = wpa_config_get(ssid, "psk");
45339beb93cSSam Leffler 	if (value == NULL)
45439beb93cSSam Leffler 		return;
45539beb93cSSam Leffler 	fprintf(f, "\tpsk=%s\n", value);
45639beb93cSSam Leffler 	os_free(value);
45739beb93cSSam Leffler }
45839beb93cSSam Leffler 
45939beb93cSSam Leffler 
46039beb93cSSam Leffler static void write_proto(FILE *f, struct wpa_ssid *ssid)
46139beb93cSSam Leffler {
46239beb93cSSam Leffler 	char *value;
46339beb93cSSam Leffler 
46439beb93cSSam Leffler 	if (ssid->proto == DEFAULT_PROTO)
46539beb93cSSam Leffler 		return;
46639beb93cSSam Leffler 
46739beb93cSSam Leffler 	value = wpa_config_get(ssid, "proto");
46839beb93cSSam Leffler 	if (value == NULL)
46939beb93cSSam Leffler 		return;
47039beb93cSSam Leffler 	if (value[0])
47139beb93cSSam Leffler 		fprintf(f, "\tproto=%s\n", value);
47239beb93cSSam Leffler 	os_free(value);
47339beb93cSSam Leffler }
47439beb93cSSam Leffler 
47539beb93cSSam Leffler 
47639beb93cSSam Leffler static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid)
47739beb93cSSam Leffler {
47839beb93cSSam Leffler 	char *value;
47939beb93cSSam Leffler 
48039beb93cSSam Leffler 	if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
48139beb93cSSam Leffler 		return;
48239beb93cSSam Leffler 
48339beb93cSSam Leffler 	value = wpa_config_get(ssid, "key_mgmt");
48439beb93cSSam Leffler 	if (value == NULL)
48539beb93cSSam Leffler 		return;
48639beb93cSSam Leffler 	if (value[0])
48739beb93cSSam Leffler 		fprintf(f, "\tkey_mgmt=%s\n", value);
48839beb93cSSam Leffler 	os_free(value);
48939beb93cSSam Leffler }
49039beb93cSSam Leffler 
49139beb93cSSam Leffler 
49239beb93cSSam Leffler static void write_pairwise(FILE *f, struct wpa_ssid *ssid)
49339beb93cSSam Leffler {
49439beb93cSSam Leffler 	char *value;
49539beb93cSSam Leffler 
49639beb93cSSam Leffler 	if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
49739beb93cSSam Leffler 		return;
49839beb93cSSam Leffler 
49939beb93cSSam Leffler 	value = wpa_config_get(ssid, "pairwise");
50039beb93cSSam Leffler 	if (value == NULL)
50139beb93cSSam Leffler 		return;
50239beb93cSSam Leffler 	if (value[0])
50339beb93cSSam Leffler 		fprintf(f, "\tpairwise=%s\n", value);
50439beb93cSSam Leffler 	os_free(value);
50539beb93cSSam Leffler }
50639beb93cSSam Leffler 
50739beb93cSSam Leffler 
50839beb93cSSam Leffler static void write_group(FILE *f, struct wpa_ssid *ssid)
50939beb93cSSam Leffler {
51039beb93cSSam Leffler 	char *value;
51139beb93cSSam Leffler 
51239beb93cSSam Leffler 	if (ssid->group_cipher == DEFAULT_GROUP)
51339beb93cSSam Leffler 		return;
51439beb93cSSam Leffler 
51539beb93cSSam Leffler 	value = wpa_config_get(ssid, "group");
51639beb93cSSam Leffler 	if (value == NULL)
51739beb93cSSam Leffler 		return;
51839beb93cSSam Leffler 	if (value[0])
51939beb93cSSam Leffler 		fprintf(f, "\tgroup=%s\n", value);
52039beb93cSSam Leffler 	os_free(value);
52139beb93cSSam Leffler }
52239beb93cSSam Leffler 
52339beb93cSSam Leffler 
52485732ac8SCy Schubert static void write_group_mgmt(FILE *f, struct wpa_ssid *ssid)
52585732ac8SCy Schubert {
52685732ac8SCy Schubert 	char *value;
52785732ac8SCy Schubert 
52885732ac8SCy Schubert 	if (!ssid->group_mgmt_cipher)
52985732ac8SCy Schubert 		return;
53085732ac8SCy Schubert 
53185732ac8SCy Schubert 	value = wpa_config_get(ssid, "group_mgmt");
53285732ac8SCy Schubert 	if (!value)
53385732ac8SCy Schubert 		return;
53485732ac8SCy Schubert 	if (value[0])
53585732ac8SCy Schubert 		fprintf(f, "\tgroup_mgmt=%s\n", value);
53685732ac8SCy Schubert 	os_free(value);
53785732ac8SCy Schubert }
53885732ac8SCy Schubert 
53985732ac8SCy Schubert 
54039beb93cSSam Leffler static void write_auth_alg(FILE *f, struct wpa_ssid *ssid)
54139beb93cSSam Leffler {
54239beb93cSSam Leffler 	char *value;
54339beb93cSSam Leffler 
54439beb93cSSam Leffler 	if (ssid->auth_alg == 0)
54539beb93cSSam Leffler 		return;
54639beb93cSSam Leffler 
54739beb93cSSam Leffler 	value = wpa_config_get(ssid, "auth_alg");
54839beb93cSSam Leffler 	if (value == NULL)
54939beb93cSSam Leffler 		return;
55039beb93cSSam Leffler 	if (value[0])
55139beb93cSSam Leffler 		fprintf(f, "\tauth_alg=%s\n", value);
55239beb93cSSam Leffler 	os_free(value);
55339beb93cSSam Leffler }
55439beb93cSSam Leffler 
55539beb93cSSam Leffler 
55639beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
55739beb93cSSam Leffler static void write_eap(FILE *f, struct wpa_ssid *ssid)
55839beb93cSSam Leffler {
55939beb93cSSam Leffler 	char *value;
56039beb93cSSam Leffler 
56139beb93cSSam Leffler 	value = wpa_config_get(ssid, "eap");
56239beb93cSSam Leffler 	if (value == NULL)
56339beb93cSSam Leffler 		return;
56439beb93cSSam Leffler 
56539beb93cSSam Leffler 	if (value[0])
56639beb93cSSam Leffler 		fprintf(f, "\teap=%s\n", value);
56739beb93cSSam Leffler 	os_free(value);
56839beb93cSSam Leffler }
56939beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
57039beb93cSSam Leffler 
57139beb93cSSam Leffler 
572c1d255d3SCy Schubert #ifdef CONFIG_WEP
57339beb93cSSam Leffler static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
57439beb93cSSam Leffler {
57539beb93cSSam Leffler 	char field[20], *value;
57639beb93cSSam Leffler 	int res;
57739beb93cSSam Leffler 
57839beb93cSSam Leffler 	res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
5795b9c547cSRui Paulo 	if (os_snprintf_error(sizeof(field), res))
58039beb93cSSam Leffler 		return;
58139beb93cSSam Leffler 	value = wpa_config_get(ssid, field);
58239beb93cSSam Leffler 	if (value) {
58339beb93cSSam Leffler 		fprintf(f, "\t%s=%s\n", field, value);
58439beb93cSSam Leffler 		os_free(value);
58539beb93cSSam Leffler 	}
58639beb93cSSam Leffler }
587c1d255d3SCy Schubert #endif /* CONFIG_WEP */
58839beb93cSSam Leffler 
58939beb93cSSam Leffler 
590f05cddf9SRui Paulo #ifdef CONFIG_P2P
5915b9c547cSRui Paulo 
5925b9c547cSRui Paulo static void write_go_p2p_dev_addr(FILE *f, struct wpa_ssid *ssid)
5935b9c547cSRui Paulo {
5945b9c547cSRui Paulo 	char *value = wpa_config_get(ssid, "go_p2p_dev_addr");
5955b9c547cSRui Paulo 	if (value == NULL)
5965b9c547cSRui Paulo 		return;
5975b9c547cSRui Paulo 	fprintf(f, "\tgo_p2p_dev_addr=%s\n", value);
5985b9c547cSRui Paulo 	os_free(value);
5995b9c547cSRui Paulo }
6005b9c547cSRui Paulo 
601f05cddf9SRui Paulo static void write_p2p_client_list(FILE *f, struct wpa_ssid *ssid)
602f05cddf9SRui Paulo {
603f05cddf9SRui Paulo 	char *value = wpa_config_get(ssid, "p2p_client_list");
604f05cddf9SRui Paulo 	if (value == NULL)
605f05cddf9SRui Paulo 		return;
606f05cddf9SRui Paulo 	fprintf(f, "\tp2p_client_list=%s\n", value);
607f05cddf9SRui Paulo 	os_free(value);
608f05cddf9SRui Paulo }
6095b9c547cSRui Paulo 
6105b9c547cSRui Paulo 
6115b9c547cSRui Paulo static void write_psk_list(FILE *f, struct wpa_ssid *ssid)
6125b9c547cSRui Paulo {
6135b9c547cSRui Paulo 	struct psk_list_entry *psk;
6145b9c547cSRui Paulo 	char hex[32 * 2 + 1];
6155b9c547cSRui Paulo 
6165b9c547cSRui Paulo 	dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) {
6175b9c547cSRui Paulo 		wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk));
6185b9c547cSRui Paulo 		fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n",
6195b9c547cSRui Paulo 			psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex);
6205b9c547cSRui Paulo 	}
6215b9c547cSRui Paulo }
6225b9c547cSRui Paulo 
623f05cddf9SRui Paulo #endif /* CONFIG_P2P */
624f05cddf9SRui Paulo 
625f05cddf9SRui Paulo 
62685732ac8SCy Schubert #ifdef CONFIG_MACSEC
62785732ac8SCy Schubert 
62885732ac8SCy Schubert static void write_mka_cak(FILE *f, struct wpa_ssid *ssid)
62985732ac8SCy Schubert {
63085732ac8SCy Schubert 	char *value;
63185732ac8SCy Schubert 
63285732ac8SCy Schubert 	if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK))
63385732ac8SCy Schubert 		return;
63485732ac8SCy Schubert 
63585732ac8SCy Schubert 	value = wpa_config_get(ssid, "mka_cak");
63685732ac8SCy Schubert 	if (!value)
63785732ac8SCy Schubert 		return;
63885732ac8SCy Schubert 	fprintf(f, "\tmka_cak=%s\n", value);
63985732ac8SCy Schubert 	os_free(value);
64085732ac8SCy Schubert }
64185732ac8SCy Schubert 
64285732ac8SCy Schubert 
64385732ac8SCy Schubert static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid)
64485732ac8SCy Schubert {
64585732ac8SCy Schubert 	char *value;
64685732ac8SCy Schubert 
64785732ac8SCy Schubert 	if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN))
64885732ac8SCy Schubert 		return;
64985732ac8SCy Schubert 
65085732ac8SCy Schubert 	value = wpa_config_get(ssid, "mka_ckn");
65185732ac8SCy Schubert 	if (!value)
65285732ac8SCy Schubert 		return;
65385732ac8SCy Schubert 	fprintf(f, "\tmka_ckn=%s\n", value);
65485732ac8SCy Schubert 	os_free(value);
65585732ac8SCy Schubert }
65685732ac8SCy Schubert 
65785732ac8SCy Schubert #endif /* CONFIG_MACSEC */
65885732ac8SCy Schubert 
65985732ac8SCy Schubert 
66039beb93cSSam Leffler static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
66139beb93cSSam Leffler {
66239beb93cSSam Leffler #define STR(t) write_str(f, #t, ssid)
66339beb93cSSam Leffler #define INT(t) write_int(f, #t, ssid->t, 0)
664c1d255d3SCy Schubert #define INTe(t, m) write_int(f, #t, ssid->eap.m, 0)
66539beb93cSSam Leffler #define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
666c1d255d3SCy Schubert #define INT_DEFe(t, m, def) write_int(f, #t, ssid->eap.m, def)
66739beb93cSSam Leffler 
66839beb93cSSam Leffler 	STR(ssid);
66939beb93cSSam Leffler 	INT(scan_ssid);
67039beb93cSSam Leffler 	write_bssid(f, ssid);
67185732ac8SCy Schubert 	write_bssid_hint(f, ssid);
672c1d255d3SCy Schubert 	write_str(f, "bssid_ignore", ssid);
673c1d255d3SCy Schubert 	write_str(f, "bssid_accept", ssid);
67439beb93cSSam Leffler 	write_psk(f, ssid);
675325151a3SRui Paulo 	INT(mem_only_psk);
67685732ac8SCy Schubert 	STR(sae_password);
67785732ac8SCy Schubert 	STR(sae_password_id);
6784b72b91aSCy Schubert 	write_int(f, "sae_pwe", ssid->sae_pwe, DEFAULT_SAE_PWE);
67939beb93cSSam Leffler 	write_proto(f, ssid);
68039beb93cSSam Leffler 	write_key_mgmt(f, ssid);
681f05cddf9SRui Paulo 	INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD);
68239beb93cSSam Leffler 	write_pairwise(f, ssid);
68339beb93cSSam Leffler 	write_group(f, ssid);
68485732ac8SCy Schubert 	write_group_mgmt(f, ssid);
68539beb93cSSam Leffler 	write_auth_alg(f, ssid);
686f05cddf9SRui Paulo 	STR(bgscan);
687f05cddf9SRui Paulo 	STR(autoscan);
6885b9c547cSRui Paulo 	STR(scan_freq);
68939beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
69039beb93cSSam Leffler 	write_eap(f, ssid);
69139beb93cSSam Leffler 	STR(identity);
69239beb93cSSam Leffler 	STR(anonymous_identity);
69385732ac8SCy Schubert 	STR(imsi_identity);
694c1d255d3SCy Schubert 	STR(machine_identity);
69539beb93cSSam Leffler 	STR(password);
696c1d255d3SCy Schubert 	STR(machine_password);
69739beb93cSSam Leffler 	STR(ca_cert);
69839beb93cSSam Leffler 	STR(ca_path);
69939beb93cSSam Leffler 	STR(client_cert);
70039beb93cSSam Leffler 	STR(private_key);
70139beb93cSSam Leffler 	STR(private_key_passwd);
70239beb93cSSam Leffler 	STR(dh_file);
70339beb93cSSam Leffler 	STR(subject_match);
7044bc52338SCy Schubert 	STR(check_cert_subject);
70539beb93cSSam Leffler 	STR(altsubject_match);
7065b9c547cSRui Paulo 	STR(domain_suffix_match);
7075b9c547cSRui Paulo 	STR(domain_match);
70839beb93cSSam Leffler 	STR(ca_cert2);
70939beb93cSSam Leffler 	STR(ca_path2);
71039beb93cSSam Leffler 	STR(client_cert2);
71139beb93cSSam Leffler 	STR(private_key2);
71239beb93cSSam Leffler 	STR(private_key2_passwd);
71339beb93cSSam Leffler 	STR(dh_file2);
71439beb93cSSam Leffler 	STR(subject_match2);
7154bc52338SCy Schubert 	STR(check_cert_subject2);
71639beb93cSSam Leffler 	STR(altsubject_match2);
7175b9c547cSRui Paulo 	STR(domain_suffix_match2);
7185b9c547cSRui Paulo 	STR(domain_match2);
719c1d255d3SCy Schubert 	STR(machine_ca_cert);
720c1d255d3SCy Schubert 	STR(machine_ca_path);
721c1d255d3SCy Schubert 	STR(machine_client_cert);
722c1d255d3SCy Schubert 	STR(machine_private_key);
723c1d255d3SCy Schubert 	STR(machine_private_key_passwd);
724c1d255d3SCy Schubert 	STR(machine_dh_file);
725c1d255d3SCy Schubert 	STR(machine_subject_match);
726c1d255d3SCy Schubert 	STR(machine_check_cert_subject);
727c1d255d3SCy Schubert 	STR(machine_altsubject_match);
728c1d255d3SCy Schubert 	STR(machine_domain_suffix_match);
729c1d255d3SCy Schubert 	STR(machine_domain_match);
73039beb93cSSam Leffler 	STR(phase1);
73139beb93cSSam Leffler 	STR(phase2);
732c1d255d3SCy Schubert 	STR(machine_phase2);
73339beb93cSSam Leffler 	STR(pcsc);
73439beb93cSSam Leffler 	STR(pin);
73539beb93cSSam Leffler 	STR(engine_id);
73639beb93cSSam Leffler 	STR(key_id);
73739beb93cSSam Leffler 	STR(cert_id);
73839beb93cSSam Leffler 	STR(ca_cert_id);
73939beb93cSSam Leffler 	STR(key2_id);
74039beb93cSSam Leffler 	STR(pin2);
74139beb93cSSam Leffler 	STR(engine2_id);
74239beb93cSSam Leffler 	STR(cert2_id);
74339beb93cSSam Leffler 	STR(ca_cert2_id);
744c1d255d3SCy Schubert 	INTe(engine, cert.engine);
745c1d255d3SCy Schubert 	INTe(engine2, phase2_cert.engine);
746c1d255d3SCy Schubert 	INTe(machine_engine, machine_cert.engine);
74739beb93cSSam Leffler 	INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
7485b9c547cSRui Paulo 	STR(openssl_ciphers);
749c1d255d3SCy Schubert 	INTe(erp, erp);
75039beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
751c1d255d3SCy Schubert #ifdef CONFIG_WEP
752c1d255d3SCy Schubert 	{
753c1d255d3SCy Schubert 		int i;
754c1d255d3SCy Schubert 
75539beb93cSSam Leffler 		for (i = 0; i < 4; i++)
75639beb93cSSam Leffler 			write_wep_key(f, i, ssid);
75739beb93cSSam Leffler 		INT(wep_tx_keyidx);
758c1d255d3SCy Schubert 	}
759c1d255d3SCy Schubert #endif /* CONFIG_WEP */
76039beb93cSSam Leffler 	INT(priority);
76139beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
76239beb93cSSam Leffler 	INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
76339beb93cSSam Leffler 	STR(pac_file);
764c1d255d3SCy Schubert 	INT_DEFe(fragment_size, fragment_size, DEFAULT_FRAGMENT_SIZE);
765c1d255d3SCy Schubert 	INTe(ocsp, cert.ocsp);
766c1d255d3SCy Schubert 	INTe(ocsp2, phase2_cert.ocsp);
767c1d255d3SCy Schubert 	INTe(machine_ocsp, machine_cert.ocsp);
768c1d255d3SCy Schubert 	INT_DEFe(sim_num, sim_num, DEFAULT_USER_SELECTED_SIM);
76939beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
77039beb93cSSam Leffler 	INT(mode);
7715b9c547cSRui Paulo 	INT(no_auto_peer);
772*32a95656SCy Schubert 	INT(mesh_fwding);
773f05cddf9SRui Paulo 	INT(frequency);
774c1d255d3SCy Schubert 	INT(enable_edmg);
775c1d255d3SCy Schubert 	INT(edmg_channel);
7765b9c547cSRui Paulo 	INT(fixed_freq);
777780fb4a2SCy Schubert #ifdef CONFIG_ACS
778780fb4a2SCy Schubert 	INT(acs);
779780fb4a2SCy Schubert #endif /* CONFIG_ACS */
780f05cddf9SRui Paulo 	write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1);
78139beb93cSSam Leffler 	INT(disabled);
7825b9c547cSRui Paulo 	INT(mixed_cell);
783c1d255d3SCy Schubert 	INT_DEF(vht, 1);
78485732ac8SCy Schubert 	INT_DEF(ht, 1);
78585732ac8SCy Schubert 	INT(ht40);
786c1d255d3SCy Schubert 	INT_DEF(he, 1);
7874bc52338SCy Schubert 	INT_DEF(max_oper_chwidth, DEFAULT_MAX_OPER_CHWIDTH);
78885732ac8SCy Schubert 	INT(vht_center_freq1);
78985732ac8SCy Schubert 	INT(vht_center_freq2);
790780fb4a2SCy Schubert 	INT(pbss);
791780fb4a2SCy Schubert 	INT(wps_disabled);
79285732ac8SCy Schubert 	INT(fils_dh_group);
793f05cddf9SRui Paulo 	write_int(f, "ieee80211w", ssid->ieee80211w,
794f05cddf9SRui Paulo 		  MGMT_FRAME_PROTECTION_DEFAULT);
79539beb93cSSam Leffler 	STR(id_str);
796f05cddf9SRui Paulo #ifdef CONFIG_P2P
7975b9c547cSRui Paulo 	write_go_p2p_dev_addr(f, ssid);
798f05cddf9SRui Paulo 	write_p2p_client_list(f, ssid);
7995b9c547cSRui Paulo 	write_psk_list(f, ssid);
800f05cddf9SRui Paulo #endif /* CONFIG_P2P */
8015b9c547cSRui Paulo 	INT(ap_max_inactivity);
8025b9c547cSRui Paulo 	INT(dtim_period);
8035b9c547cSRui Paulo 	INT(beacon_int);
8045b9c547cSRui Paulo #ifdef CONFIG_MACSEC
8055b9c547cSRui Paulo 	INT(macsec_policy);
80685732ac8SCy Schubert 	write_mka_cak(f, ssid);
80785732ac8SCy Schubert 	write_mka_ckn(f, ssid);
80885732ac8SCy Schubert 	INT(macsec_integ_only);
8094bc52338SCy Schubert 	INT(macsec_replay_protect);
8104bc52338SCy Schubert 	INT(macsec_replay_window);
81185732ac8SCy Schubert 	INT(macsec_port);
81285732ac8SCy Schubert 	INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER);
8135b9c547cSRui Paulo #endif /* CONFIG_MACSEC */
8145b9c547cSRui Paulo #ifdef CONFIG_HS20
8155b9c547cSRui Paulo 	INT(update_identifier);
81685732ac8SCy Schubert 	STR(roaming_consortium_selection);
8175b9c547cSRui Paulo #endif /* CONFIG_HS20 */
8185b9c547cSRui Paulo 	write_int(f, "mac_addr", ssid->mac_addr, -1);
8195b9c547cSRui Paulo #ifdef CONFIG_MESH
8205b9c547cSRui Paulo 	STR(mesh_basic_rates);
8215b9c547cSRui Paulo 	INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES);
8225b9c547cSRui Paulo 	INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT);
8235b9c547cSRui Paulo 	INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT);
8245b9c547cSRui Paulo 	INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT);
82585732ac8SCy Schubert 	INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD);
8265b9c547cSRui Paulo #endif /* CONFIG_MESH */
8275b9c547cSRui Paulo 	INT(wpa_ptk_rekey);
828c1d255d3SCy Schubert 	INT(wpa_deny_ptk0_rekey);
829780fb4a2SCy Schubert 	INT(group_rekey);
8305b9c547cSRui Paulo 	INT(ignore_broadcast_ssid);
83185732ac8SCy Schubert #ifdef CONFIG_DPP
83285732ac8SCy Schubert 	STR(dpp_connector);
83385732ac8SCy Schubert 	STR(dpp_netaccesskey);
83485732ac8SCy Schubert 	INT(dpp_netaccesskey_expiry);
83585732ac8SCy Schubert 	STR(dpp_csign);
836c1d255d3SCy Schubert 	STR(dpp_pp_key);
837c1d255d3SCy Schubert 	INT(dpp_pfs);
83885732ac8SCy Schubert #endif /* CONFIG_DPP */
83985732ac8SCy Schubert 	INT(owe_group);
84085732ac8SCy Schubert 	INT(owe_only);
841c1d255d3SCy Schubert 	INT(owe_ptk_workaround);
8424bc52338SCy Schubert 	INT(multi_ap_backhaul_sta);
843206b73d0SCy Schubert 	INT(ft_eap_pmksa_caching);
844c1d255d3SCy Schubert 	INT(beacon_prot);
845c1d255d3SCy Schubert 	INT(transition_disable);
846c1d255d3SCy Schubert 	INT(sae_pk);
8475b9c547cSRui Paulo #ifdef CONFIG_HT_OVERRIDES
8485b9c547cSRui Paulo 	INT_DEF(disable_ht, DEFAULT_DISABLE_HT);
8495b9c547cSRui Paulo 	INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40);
8505b9c547cSRui Paulo 	INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI);
8515b9c547cSRui Paulo 	INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC);
8525b9c547cSRui Paulo 	INT(ht40_intolerant);
8534bc52338SCy Schubert 	INT_DEF(tx_stbc, DEFAULT_TX_STBC);
8544bc52338SCy Schubert 	INT_DEF(rx_stbc, DEFAULT_RX_STBC);
8555b9c547cSRui Paulo 	INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU);
8565b9c547cSRui Paulo 	INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR);
8575b9c547cSRui Paulo 	INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY);
8585b9c547cSRui Paulo 	STR(ht_mcs);
8595b9c547cSRui Paulo #endif /* CONFIG_HT_OVERRIDES */
8605b9c547cSRui Paulo #ifdef CONFIG_VHT_OVERRIDES
8615b9c547cSRui Paulo 	INT(disable_vht);
8625b9c547cSRui Paulo 	INT(vht_capa);
8635b9c547cSRui Paulo 	INT(vht_capa_mask);
8645b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_1, -1);
8655b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_2, -1);
8665b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_3, -1);
8675b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_4, -1);
8685b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_5, -1);
8695b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_6, -1);
8705b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_7, -1);
8715b9c547cSRui Paulo 	INT_DEF(vht_rx_mcs_nss_8, -1);
8725b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_1, -1);
8735b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_2, -1);
8745b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_3, -1);
8755b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_4, -1);
8765b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_5, -1);
8775b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_6, -1);
8785b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_7, -1);
8795b9c547cSRui Paulo 	INT_DEF(vht_tx_mcs_nss_8, -1);
8805b9c547cSRui Paulo #endif /* CONFIG_VHT_OVERRIDES */
881c1d255d3SCy Schubert #ifdef CONFIG_HE_OVERRIDES
882c1d255d3SCy Schubert 	INT(disable_he);
883c1d255d3SCy Schubert #endif /* CONFIG_HE_OVERRIDES */
88439beb93cSSam Leffler 
88539beb93cSSam Leffler #undef STR
88639beb93cSSam Leffler #undef INT
88739beb93cSSam Leffler #undef INT_DEF
88839beb93cSSam Leffler }
88939beb93cSSam Leffler 
89039beb93cSSam Leffler 
891f05cddf9SRui Paulo static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred)
892f05cddf9SRui Paulo {
8935b9c547cSRui Paulo 	size_t i;
8945b9c547cSRui Paulo 
895f05cddf9SRui Paulo 	if (cred->priority)
896f05cddf9SRui Paulo 		fprintf(f, "\tpriority=%d\n", cred->priority);
897f05cddf9SRui Paulo 	if (cred->pcsc)
898f05cddf9SRui Paulo 		fprintf(f, "\tpcsc=%d\n", cred->pcsc);
899f05cddf9SRui Paulo 	if (cred->realm)
900f05cddf9SRui Paulo 		fprintf(f, "\trealm=\"%s\"\n", cred->realm);
901f05cddf9SRui Paulo 	if (cred->username)
902f05cddf9SRui Paulo 		fprintf(f, "\tusername=\"%s\"\n", cred->username);
903f05cddf9SRui Paulo 	if (cred->password && cred->ext_password)
904f05cddf9SRui Paulo 		fprintf(f, "\tpassword=ext:%s\n", cred->password);
905f05cddf9SRui Paulo 	else if (cred->password)
906f05cddf9SRui Paulo 		fprintf(f, "\tpassword=\"%s\"\n", cred->password);
907f05cddf9SRui Paulo 	if (cred->ca_cert)
908f05cddf9SRui Paulo 		fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert);
909f05cddf9SRui Paulo 	if (cred->client_cert)
910f05cddf9SRui Paulo 		fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert);
911f05cddf9SRui Paulo 	if (cred->private_key)
912f05cddf9SRui Paulo 		fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key);
913f05cddf9SRui Paulo 	if (cred->private_key_passwd)
914f05cddf9SRui Paulo 		fprintf(f, "\tprivate_key_passwd=\"%s\"\n",
915f05cddf9SRui Paulo 			cred->private_key_passwd);
916f05cddf9SRui Paulo 	if (cred->imsi)
917f05cddf9SRui Paulo 		fprintf(f, "\timsi=\"%s\"\n", cred->imsi);
918f05cddf9SRui Paulo 	if (cred->milenage)
919f05cddf9SRui Paulo 		fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage);
9205b9c547cSRui Paulo 	for (i = 0; i < cred->num_domain; i++)
9215b9c547cSRui Paulo 		fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]);
9225b9c547cSRui Paulo 	if (cred->domain_suffix_match)
9235b9c547cSRui Paulo 		fprintf(f, "\tdomain_suffix_match=\"%s\"\n",
9245b9c547cSRui Paulo 			cred->domain_suffix_match);
925f05cddf9SRui Paulo 	if (cred->roaming_consortium_len) {
926f05cddf9SRui Paulo 		fprintf(f, "\troaming_consortium=");
927f05cddf9SRui Paulo 		for (i = 0; i < cred->roaming_consortium_len; i++)
928f05cddf9SRui Paulo 			fprintf(f, "%02x", cred->roaming_consortium[i]);
929f05cddf9SRui Paulo 		fprintf(f, "\n");
930f05cddf9SRui Paulo 	}
931f05cddf9SRui Paulo 	if (cred->eap_method) {
932f05cddf9SRui Paulo 		const char *name;
933f05cddf9SRui Paulo 		name = eap_get_name(cred->eap_method[0].vendor,
934f05cddf9SRui Paulo 				    cred->eap_method[0].method);
9355b9c547cSRui Paulo 		if (name)
936f05cddf9SRui Paulo 			fprintf(f, "\teap=%s\n", name);
937f05cddf9SRui Paulo 	}
938f05cddf9SRui Paulo 	if (cred->phase1)
939f05cddf9SRui Paulo 		fprintf(f, "\tphase1=\"%s\"\n", cred->phase1);
940f05cddf9SRui Paulo 	if (cred->phase2)
941f05cddf9SRui Paulo 		fprintf(f, "\tphase2=\"%s\"\n", cred->phase2);
942f05cddf9SRui Paulo 	if (cred->excluded_ssid) {
9435b9c547cSRui Paulo 		size_t j;
944f05cddf9SRui Paulo 		for (i = 0; i < cred->num_excluded_ssid; i++) {
945f05cddf9SRui Paulo 			struct excluded_ssid *e = &cred->excluded_ssid[i];
946f05cddf9SRui Paulo 			fprintf(f, "\texcluded_ssid=");
947f05cddf9SRui Paulo 			for (j = 0; j < e->ssid_len; j++)
948f05cddf9SRui Paulo 				fprintf(f, "%02x", e->ssid[j]);
949f05cddf9SRui Paulo 			fprintf(f, "\n");
950f05cddf9SRui Paulo 		}
951f05cddf9SRui Paulo 	}
9525b9c547cSRui Paulo 	if (cred->roaming_partner) {
9535b9c547cSRui Paulo 		for (i = 0; i < cred->num_roaming_partner; i++) {
9545b9c547cSRui Paulo 			struct roaming_partner *p = &cred->roaming_partner[i];
9555b9c547cSRui Paulo 			fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n",
9565b9c547cSRui Paulo 				p->fqdn, p->exact_match, p->priority,
9575b9c547cSRui Paulo 				p->country);
9585b9c547cSRui Paulo 		}
9595b9c547cSRui Paulo 	}
9605b9c547cSRui Paulo 	if (cred->update_identifier)
9615b9c547cSRui Paulo 		fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier);
9625b9c547cSRui Paulo 
9635b9c547cSRui Paulo 	if (cred->provisioning_sp)
9645b9c547cSRui Paulo 		fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp);
9655b9c547cSRui Paulo 	if (cred->sp_priority)
9665b9c547cSRui Paulo 		fprintf(f, "\tsp_priority=%d\n", cred->sp_priority);
9675b9c547cSRui Paulo 
9685b9c547cSRui Paulo 	if (cred->min_dl_bandwidth_home)
9695b9c547cSRui Paulo 		fprintf(f, "\tmin_dl_bandwidth_home=%u\n",
9705b9c547cSRui Paulo 			cred->min_dl_bandwidth_home);
9715b9c547cSRui Paulo 	if (cred->min_ul_bandwidth_home)
9725b9c547cSRui Paulo 		fprintf(f, "\tmin_ul_bandwidth_home=%u\n",
9735b9c547cSRui Paulo 			cred->min_ul_bandwidth_home);
9745b9c547cSRui Paulo 	if (cred->min_dl_bandwidth_roaming)
9755b9c547cSRui Paulo 		fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n",
9765b9c547cSRui Paulo 			cred->min_dl_bandwidth_roaming);
9775b9c547cSRui Paulo 	if (cred->min_ul_bandwidth_roaming)
9785b9c547cSRui Paulo 		fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n",
9795b9c547cSRui Paulo 			cred->min_ul_bandwidth_roaming);
9805b9c547cSRui Paulo 
9815b9c547cSRui Paulo 	if (cred->max_bss_load)
9825b9c547cSRui Paulo 		fprintf(f, "\tmax_bss_load=%u\n",
9835b9c547cSRui Paulo 			cred->max_bss_load);
9845b9c547cSRui Paulo 
9855b9c547cSRui Paulo 	if (cred->ocsp)
9865b9c547cSRui Paulo 		fprintf(f, "\tocsp=%d\n", cred->ocsp);
9875b9c547cSRui Paulo 
9885b9c547cSRui Paulo 	if (cred->num_req_conn_capab) {
9895b9c547cSRui Paulo 		for (i = 0; i < cred->num_req_conn_capab; i++) {
9905b9c547cSRui Paulo 			int *ports;
9915b9c547cSRui Paulo 
9925b9c547cSRui Paulo 			fprintf(f, "\treq_conn_capab=%u",
9935b9c547cSRui Paulo 				cred->req_conn_capab_proto[i]);
9945b9c547cSRui Paulo 			ports = cred->req_conn_capab_port[i];
9955b9c547cSRui Paulo 			if (ports) {
9965b9c547cSRui Paulo 				int j;
9975b9c547cSRui Paulo 				for (j = 0; ports[j] != -1; j++) {
9985b9c547cSRui Paulo 					fprintf(f, "%s%d", j > 0 ? "," : ":",
9995b9c547cSRui Paulo 						ports[j]);
10005b9c547cSRui Paulo 				}
10015b9c547cSRui Paulo 			}
10025b9c547cSRui Paulo 			fprintf(f, "\n");
10035b9c547cSRui Paulo 		}
10045b9c547cSRui Paulo 	}
10055b9c547cSRui Paulo 
10065b9c547cSRui Paulo 	if (cred->required_roaming_consortium_len) {
10075b9c547cSRui Paulo 		fprintf(f, "\trequired_roaming_consortium=");
10085b9c547cSRui Paulo 		for (i = 0; i < cred->required_roaming_consortium_len; i++)
10095b9c547cSRui Paulo 			fprintf(f, "%02x",
10105b9c547cSRui Paulo 				cred->required_roaming_consortium[i]);
10115b9c547cSRui Paulo 		fprintf(f, "\n");
10125b9c547cSRui Paulo 	}
10135b9c547cSRui Paulo 
101485732ac8SCy Schubert 	if (cred->num_roaming_consortiums) {
101585732ac8SCy Schubert 		size_t j;
101685732ac8SCy Schubert 
101785732ac8SCy Schubert 		fprintf(f, "\troaming_consortiums=\"");
101885732ac8SCy Schubert 		for (i = 0; i < cred->num_roaming_consortiums; i++) {
101985732ac8SCy Schubert 			if (i > 0)
102085732ac8SCy Schubert 				fprintf(f, ",");
102185732ac8SCy Schubert 			for (j = 0; j < cred->roaming_consortiums_len[i]; j++)
102285732ac8SCy Schubert 				fprintf(f, "%02x",
102385732ac8SCy Schubert 					cred->roaming_consortiums[i][j]);
102485732ac8SCy Schubert 		}
102585732ac8SCy Schubert 		fprintf(f, "\"\n");
102685732ac8SCy Schubert 	}
102785732ac8SCy Schubert 
10285b9c547cSRui Paulo 	if (cred->sim_num != DEFAULT_USER_SELECTED_SIM)
10295b9c547cSRui Paulo 		fprintf(f, "\tsim_num=%d\n", cred->sim_num);
1030*32a95656SCy Schubert 
1031*32a95656SCy Schubert 	if (cred->engine)
1032*32a95656SCy Schubert 		fprintf(f, "\tengine=%d\n", cred->engine);
1033*32a95656SCy Schubert 	if (cred->engine_id)
1034*32a95656SCy Schubert 		fprintf(f, "\tengine_id=\"%s\"\n", cred->engine_id);
1035*32a95656SCy Schubert 	if (cred->key_id)
1036*32a95656SCy Schubert 		fprintf(f, "\tkey_id=\"%s\"\n", cred->key_id);
1037*32a95656SCy Schubert 	if (cred->cert_id)
1038*32a95656SCy Schubert 		fprintf(f, "\tcert_id=\"%s\"\n", cred->cert_id);
1039*32a95656SCy Schubert 	if (cred->ca_cert_id)
1040*32a95656SCy Schubert 		fprintf(f, "\tca_cert_id=\"%s\"\n", cred->ca_cert_id);
1041f05cddf9SRui Paulo }
1042f05cddf9SRui Paulo 
1043f05cddf9SRui Paulo 
104439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS
104539beb93cSSam Leffler static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
104639beb93cSSam Leffler {
1047c1d255d3SCy Schubert 	char *encoded;
104839beb93cSSam Leffler 
104939beb93cSSam Leffler 	encoded = base64_encode(blob->data, blob->len, NULL);
105039beb93cSSam Leffler 	if (encoded == NULL)
105139beb93cSSam Leffler 		return -1;
105239beb93cSSam Leffler 
105339beb93cSSam Leffler 	fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
105439beb93cSSam Leffler 	os_free(encoded);
105539beb93cSSam Leffler 	return 0;
105639beb93cSSam Leffler }
105739beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */
105839beb93cSSam Leffler 
105939beb93cSSam Leffler 
1060f05cddf9SRui Paulo static void write_global_bin(FILE *f, const char *field,
1061f05cddf9SRui Paulo 			     const struct wpabuf *val)
1062f05cddf9SRui Paulo {
1063f05cddf9SRui Paulo 	size_t i;
1064f05cddf9SRui Paulo 	const u8 *pos;
1065f05cddf9SRui Paulo 
1066f05cddf9SRui Paulo 	if (val == NULL)
1067f05cddf9SRui Paulo 		return;
1068f05cddf9SRui Paulo 
1069f05cddf9SRui Paulo 	fprintf(f, "%s=", field);
1070f05cddf9SRui Paulo 	pos = wpabuf_head(val);
1071f05cddf9SRui Paulo 	for (i = 0; i < wpabuf_len(val); i++)
1072f05cddf9SRui Paulo 		fprintf(f, "%02X", *pos++);
1073f05cddf9SRui Paulo 	fprintf(f, "\n");
1074f05cddf9SRui Paulo }
1075f05cddf9SRui Paulo 
1076f05cddf9SRui Paulo 
107739beb93cSSam Leffler static void wpa_config_write_global(FILE *f, struct wpa_config *config)
107839beb93cSSam Leffler {
107939beb93cSSam Leffler #ifdef CONFIG_CTRL_IFACE
108039beb93cSSam Leffler 	if (config->ctrl_interface)
108139beb93cSSam Leffler 		fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
108239beb93cSSam Leffler 	if (config->ctrl_interface_group)
108339beb93cSSam Leffler 		fprintf(f, "ctrl_interface_group=%s\n",
108439beb93cSSam Leffler 			config->ctrl_interface_group);
108539beb93cSSam Leffler #endif /* CONFIG_CTRL_IFACE */
108639beb93cSSam Leffler 	if (config->eapol_version != DEFAULT_EAPOL_VERSION)
108739beb93cSSam Leffler 		fprintf(f, "eapol_version=%d\n", config->eapol_version);
108839beb93cSSam Leffler 	if (config->ap_scan != DEFAULT_AP_SCAN)
108939beb93cSSam Leffler 		fprintf(f, "ap_scan=%d\n", config->ap_scan);
1090f05cddf9SRui Paulo 	if (config->disable_scan_offload)
1091f05cddf9SRui Paulo 		fprintf(f, "disable_scan_offload=%d\n",
1092f05cddf9SRui Paulo 			config->disable_scan_offload);
109339beb93cSSam Leffler 	if (config->fast_reauth != DEFAULT_FAST_REAUTH)
109439beb93cSSam Leffler 		fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
109539beb93cSSam Leffler 	if (config->opensc_engine_path)
109639beb93cSSam Leffler 		fprintf(f, "opensc_engine_path=%s\n",
109739beb93cSSam Leffler 			config->opensc_engine_path);
109839beb93cSSam Leffler 	if (config->pkcs11_engine_path)
109939beb93cSSam Leffler 		fprintf(f, "pkcs11_engine_path=%s\n",
110039beb93cSSam Leffler 			config->pkcs11_engine_path);
110139beb93cSSam Leffler 	if (config->pkcs11_module_path)
110239beb93cSSam Leffler 		fprintf(f, "pkcs11_module_path=%s\n",
110339beb93cSSam Leffler 			config->pkcs11_module_path);
11045b9c547cSRui Paulo 	if (config->openssl_ciphers)
11055b9c547cSRui Paulo 		fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers);
1106f05cddf9SRui Paulo 	if (config->pcsc_reader)
1107f05cddf9SRui Paulo 		fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader);
1108f05cddf9SRui Paulo 	if (config->pcsc_pin)
1109f05cddf9SRui Paulo 		fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin);
111039beb93cSSam Leffler 	if (config->driver_param)
111139beb93cSSam Leffler 		fprintf(f, "driver_param=%s\n", config->driver_param);
111239beb93cSSam Leffler 	if (config->dot11RSNAConfigPMKLifetime)
1113325151a3SRui Paulo 		fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n",
111439beb93cSSam Leffler 			config->dot11RSNAConfigPMKLifetime);
111539beb93cSSam Leffler 	if (config->dot11RSNAConfigPMKReauthThreshold)
1116325151a3SRui Paulo 		fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n",
111739beb93cSSam Leffler 			config->dot11RSNAConfigPMKReauthThreshold);
111839beb93cSSam Leffler 	if (config->dot11RSNAConfigSATimeout)
1119325151a3SRui Paulo 		fprintf(f, "dot11RSNAConfigSATimeout=%u\n",
112039beb93cSSam Leffler 			config->dot11RSNAConfigSATimeout);
112139beb93cSSam Leffler 	if (config->update_config)
112239beb93cSSam Leffler 		fprintf(f, "update_config=%d\n", config->update_config);
112339beb93cSSam Leffler #ifdef CONFIG_WPS
112439beb93cSSam Leffler 	if (!is_nil_uuid(config->uuid)) {
112539beb93cSSam Leffler 		char buf[40];
112639beb93cSSam Leffler 		uuid_bin2str(config->uuid, buf, sizeof(buf));
112739beb93cSSam Leffler 		fprintf(f, "uuid=%s\n", buf);
112839beb93cSSam Leffler 	}
112985732ac8SCy Schubert 	if (config->auto_uuid)
113085732ac8SCy Schubert 		fprintf(f, "auto_uuid=%d\n", config->auto_uuid);
113139beb93cSSam Leffler 	if (config->device_name)
113239beb93cSSam Leffler 		fprintf(f, "device_name=%s\n", config->device_name);
113339beb93cSSam Leffler 	if (config->manufacturer)
113439beb93cSSam Leffler 		fprintf(f, "manufacturer=%s\n", config->manufacturer);
113539beb93cSSam Leffler 	if (config->model_name)
113639beb93cSSam Leffler 		fprintf(f, "model_name=%s\n", config->model_name);
113739beb93cSSam Leffler 	if (config->model_number)
113839beb93cSSam Leffler 		fprintf(f, "model_number=%s\n", config->model_number);
113939beb93cSSam Leffler 	if (config->serial_number)
114039beb93cSSam Leffler 		fprintf(f, "serial_number=%s\n", config->serial_number);
1141f05cddf9SRui Paulo 	{
1142f05cddf9SRui Paulo 		char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1143f05cddf9SRui Paulo 		buf = wps_dev_type_bin2str(config->device_type,
1144f05cddf9SRui Paulo 					   _buf, sizeof(_buf));
1145f05cddf9SRui Paulo 		if (os_strcmp(buf, "0-00000000-0") != 0)
1146f05cddf9SRui Paulo 			fprintf(f, "device_type=%s\n", buf);
1147f05cddf9SRui Paulo 	}
114839beb93cSSam Leffler 	if (WPA_GET_BE32(config->os_version))
114939beb93cSSam Leffler 		fprintf(f, "os_version=%08x\n",
115039beb93cSSam Leffler 			WPA_GET_BE32(config->os_version));
1151e28a4053SRui Paulo 	if (config->config_methods)
1152e28a4053SRui Paulo 		fprintf(f, "config_methods=%s\n", config->config_methods);
115339beb93cSSam Leffler 	if (config->wps_cred_processing)
115439beb93cSSam Leffler 		fprintf(f, "wps_cred_processing=%d\n",
115539beb93cSSam Leffler 			config->wps_cred_processing);
11564bc52338SCy Schubert 	if (config->wps_cred_add_sae)
11574bc52338SCy Schubert 		fprintf(f, "wps_cred_add_sae=%d\n",
11584bc52338SCy Schubert 			config->wps_cred_add_sae);
1159f05cddf9SRui Paulo 	if (config->wps_vendor_ext_m1) {
1160f05cddf9SRui Paulo 		int i, len = wpabuf_len(config->wps_vendor_ext_m1);
1161f05cddf9SRui Paulo 		const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1);
1162f05cddf9SRui Paulo 		if (len > 0) {
1163f05cddf9SRui Paulo 			fprintf(f, "wps_vendor_ext_m1=");
1164f05cddf9SRui Paulo 			for (i = 0; i < len; i++)
1165f05cddf9SRui Paulo 				fprintf(f, "%02x", *p++);
1166f05cddf9SRui Paulo 			fprintf(f, "\n");
1167f05cddf9SRui Paulo 		}
1168f05cddf9SRui Paulo 	}
116939beb93cSSam Leffler #endif /* CONFIG_WPS */
1170f05cddf9SRui Paulo #ifdef CONFIG_P2P
117185732ac8SCy Schubert 	{
117285732ac8SCy Schubert 		int i;
117385732ac8SCy Schubert 		char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
117485732ac8SCy Schubert 
117585732ac8SCy Schubert 		for (i = 0; i < config->num_sec_device_types; i++) {
117685732ac8SCy Schubert 			buf = wps_dev_type_bin2str(config->sec_device_type[i],
117785732ac8SCy Schubert 						   _buf, sizeof(_buf));
117885732ac8SCy Schubert 			if (buf)
117985732ac8SCy Schubert 				fprintf(f, "sec_device_type=%s\n", buf);
118085732ac8SCy Schubert 		}
118185732ac8SCy Schubert 	}
1182f05cddf9SRui Paulo 	if (config->p2p_listen_reg_class)
1183325151a3SRui Paulo 		fprintf(f, "p2p_listen_reg_class=%d\n",
1184f05cddf9SRui Paulo 			config->p2p_listen_reg_class);
1185f05cddf9SRui Paulo 	if (config->p2p_listen_channel)
1186325151a3SRui Paulo 		fprintf(f, "p2p_listen_channel=%d\n",
1187f05cddf9SRui Paulo 			config->p2p_listen_channel);
1188f05cddf9SRui Paulo 	if (config->p2p_oper_reg_class)
1189325151a3SRui Paulo 		fprintf(f, "p2p_oper_reg_class=%d\n",
1190f05cddf9SRui Paulo 			config->p2p_oper_reg_class);
1191f05cddf9SRui Paulo 	if (config->p2p_oper_channel)
1192325151a3SRui Paulo 		fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel);
1193f05cddf9SRui Paulo 	if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT)
1194325151a3SRui Paulo 		fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent);
1195f05cddf9SRui Paulo 	if (config->p2p_ssid_postfix)
1196f05cddf9SRui Paulo 		fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix);
1197f05cddf9SRui Paulo 	if (config->persistent_reconnect)
1198325151a3SRui Paulo 		fprintf(f, "persistent_reconnect=%d\n",
1199f05cddf9SRui Paulo 			config->persistent_reconnect);
1200f05cddf9SRui Paulo 	if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS)
1201325151a3SRui Paulo 		fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss);
1202f05cddf9SRui Paulo 	if (config->p2p_group_idle)
1203325151a3SRui Paulo 		fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle);
12045b9c547cSRui Paulo 	if (config->p2p_passphrase_len)
12055b9c547cSRui Paulo 		fprintf(f, "p2p_passphrase_len=%u\n",
12065b9c547cSRui Paulo 			config->p2p_passphrase_len);
1207f05cddf9SRui Paulo 	if (config->p2p_pref_chan) {
1208f05cddf9SRui Paulo 		unsigned int i;
1209f05cddf9SRui Paulo 		fprintf(f, "p2p_pref_chan=");
1210f05cddf9SRui Paulo 		for (i = 0; i < config->num_p2p_pref_chan; i++) {
1211f05cddf9SRui Paulo 			fprintf(f, "%s%u:%u", i > 0 ? "," : "",
1212f05cddf9SRui Paulo 				config->p2p_pref_chan[i].op_class,
1213f05cddf9SRui Paulo 				config->p2p_pref_chan[i].chan);
1214f05cddf9SRui Paulo 		}
1215f05cddf9SRui Paulo 		fprintf(f, "\n");
1216f05cddf9SRui Paulo 	}
12175b9c547cSRui Paulo 	if (config->p2p_no_go_freq.num) {
12185b9c547cSRui Paulo 		char *val = freq_range_list_str(&config->p2p_no_go_freq);
12195b9c547cSRui Paulo 		if (val) {
12205b9c547cSRui Paulo 			fprintf(f, "p2p_no_go_freq=%s\n", val);
12215b9c547cSRui Paulo 			os_free(val);
12225b9c547cSRui Paulo 		}
12235b9c547cSRui Paulo 	}
12245b9c547cSRui Paulo 	if (config->p2p_add_cli_chan)
12255b9c547cSRui Paulo 		fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan);
12265b9c547cSRui Paulo 	if (config->p2p_optimize_listen_chan !=
12275b9c547cSRui Paulo 	    DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN)
12285b9c547cSRui Paulo 		fprintf(f, "p2p_optimize_listen_chan=%d\n",
12295b9c547cSRui Paulo 			config->p2p_optimize_listen_chan);
1230f05cddf9SRui Paulo 	if (config->p2p_go_ht40)
1231325151a3SRui Paulo 		fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40);
12325b9c547cSRui Paulo 	if (config->p2p_go_vht)
1233325151a3SRui Paulo 		fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht);
12344bc52338SCy Schubert 	if (config->p2p_go_he)
12354bc52338SCy Schubert 		fprintf(f, "p2p_go_he=%d\n", config->p2p_go_he);
1236c1d255d3SCy Schubert 	if (config->p2p_go_edmg)
1237c1d255d3SCy Schubert 		fprintf(f, "p2p_go_edmg=%d\n", config->p2p_go_edmg);
12385b9c547cSRui Paulo 	if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW)
1239325151a3SRui Paulo 		fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow);
1240f05cddf9SRui Paulo 	if (config->p2p_disabled)
1241325151a3SRui Paulo 		fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled);
1242f05cddf9SRui Paulo 	if (config->p2p_no_group_iface)
1243325151a3SRui Paulo 		fprintf(f, "p2p_no_group_iface=%d\n",
1244f05cddf9SRui Paulo 			config->p2p_no_group_iface);
12455b9c547cSRui Paulo 	if (config->p2p_ignore_shared_freq)
1246325151a3SRui Paulo 		fprintf(f, "p2p_ignore_shared_freq=%d\n",
12475b9c547cSRui Paulo 			config->p2p_ignore_shared_freq);
1248325151a3SRui Paulo 	if (config->p2p_cli_probe)
1249325151a3SRui Paulo 		fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe);
1250325151a3SRui Paulo 	if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE)
1251325151a3SRui Paulo 		fprintf(f, "p2p_go_freq_change_policy=%u\n",
1252325151a3SRui Paulo 			config->p2p_go_freq_change_policy);
1253c1d255d3SCy Schubert 
1254c1d255d3SCy Schubert 	if (config->p2p_6ghz_disable)
1255c1d255d3SCy Schubert 		fprintf(f, "p2p_6ghz_disable=%d\n", config->p2p_6ghz_disable);
1256c1d255d3SCy Schubert 
1257780fb4a2SCy Schubert 	if (WPA_GET_BE32(config->ip_addr_go))
1258780fb4a2SCy Schubert 		fprintf(f, "ip_addr_go=%u.%u.%u.%u\n",
1259780fb4a2SCy Schubert 			config->ip_addr_go[0], config->ip_addr_go[1],
1260780fb4a2SCy Schubert 			config->ip_addr_go[2], config->ip_addr_go[3]);
1261780fb4a2SCy Schubert 	if (WPA_GET_BE32(config->ip_addr_mask))
1262780fb4a2SCy Schubert 		fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n",
1263780fb4a2SCy Schubert 			config->ip_addr_mask[0], config->ip_addr_mask[1],
1264780fb4a2SCy Schubert 			config->ip_addr_mask[2], config->ip_addr_mask[3]);
1265780fb4a2SCy Schubert 	if (WPA_GET_BE32(config->ip_addr_start))
1266780fb4a2SCy Schubert 		fprintf(f, "ip_addr_start=%u.%u.%u.%u\n",
1267780fb4a2SCy Schubert 			config->ip_addr_start[0], config->ip_addr_start[1],
1268780fb4a2SCy Schubert 			config->ip_addr_start[2], config->ip_addr_start[3]);
1269780fb4a2SCy Schubert 	if (WPA_GET_BE32(config->ip_addr_end))
1270780fb4a2SCy Schubert 		fprintf(f, "ip_addr_end=%u.%u.%u.%u\n",
1271780fb4a2SCy Schubert 			config->ip_addr_end[0], config->ip_addr_end[1],
1272780fb4a2SCy Schubert 			config->ip_addr_end[2], config->ip_addr_end[3]);
1273f05cddf9SRui Paulo #endif /* CONFIG_P2P */
127439beb93cSSam Leffler 	if (config->country[0] && config->country[1]) {
127539beb93cSSam Leffler 		fprintf(f, "country=%c%c\n",
127639beb93cSSam Leffler 			config->country[0], config->country[1]);
127739beb93cSSam Leffler 	}
1278e28a4053SRui Paulo 	if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
1279e28a4053SRui Paulo 		fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
1280f05cddf9SRui Paulo 	if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE)
1281f05cddf9SRui Paulo 		fprintf(f, "bss_expiration_age=%u\n",
1282f05cddf9SRui Paulo 			config->bss_expiration_age);
1283f05cddf9SRui Paulo 	if (config->bss_expiration_scan_count !=
1284f05cddf9SRui Paulo 	    DEFAULT_BSS_EXPIRATION_SCAN_COUNT)
1285f05cddf9SRui Paulo 		fprintf(f, "bss_expiration_scan_count=%u\n",
1286f05cddf9SRui Paulo 			config->bss_expiration_scan_count);
1287e28a4053SRui Paulo 	if (config->filter_ssids)
1288e28a4053SRui Paulo 		fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
128985732ac8SCy Schubert 	if (config->filter_rssi)
129085732ac8SCy Schubert 		fprintf(f, "filter_rssi=%d\n", config->filter_rssi);
1291f05cddf9SRui Paulo 	if (config->max_num_sta != DEFAULT_MAX_NUM_STA)
1292f05cddf9SRui Paulo 		fprintf(f, "max_num_sta=%u\n", config->max_num_sta);
129385732ac8SCy Schubert 	if (config->ap_isolate != DEFAULT_AP_ISOLATE)
129485732ac8SCy Schubert 		fprintf(f, "ap_isolate=%u\n", config->ap_isolate);
1295f05cddf9SRui Paulo 	if (config->disassoc_low_ack)
1296325151a3SRui Paulo 		fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack);
1297f05cddf9SRui Paulo #ifdef CONFIG_HS20
1298f05cddf9SRui Paulo 	if (config->hs20)
1299f05cddf9SRui Paulo 		fprintf(f, "hs20=1\n");
1300f05cddf9SRui Paulo #endif /* CONFIG_HS20 */
1301f05cddf9SRui Paulo #ifdef CONFIG_INTERWORKING
1302f05cddf9SRui Paulo 	if (config->interworking)
1303325151a3SRui Paulo 		fprintf(f, "interworking=%d\n", config->interworking);
1304f05cddf9SRui Paulo 	if (!is_zero_ether_addr(config->hessid))
1305f05cddf9SRui Paulo 		fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid));
1306f05cddf9SRui Paulo 	if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE)
1307f05cddf9SRui Paulo 		fprintf(f, "access_network_type=%d\n",
1308f05cddf9SRui Paulo 			config->access_network_type);
130985732ac8SCy Schubert 	if (config->go_interworking)
131085732ac8SCy Schubert 		fprintf(f, "go_interworking=%d\n", config->go_interworking);
131185732ac8SCy Schubert 	if (config->go_access_network_type)
131285732ac8SCy Schubert 		fprintf(f, "go_access_network_type=%d\n",
131385732ac8SCy Schubert 			config->go_access_network_type);
131485732ac8SCy Schubert 	if (config->go_internet)
131585732ac8SCy Schubert 		fprintf(f, "go_internet=%d\n", config->go_internet);
131685732ac8SCy Schubert 	if (config->go_venue_group)
131785732ac8SCy Schubert 		fprintf(f, "go_venue_group=%d\n", config->go_venue_group);
131885732ac8SCy Schubert 	if (config->go_venue_type)
131985732ac8SCy Schubert 		fprintf(f, "go_venue_type=%d\n", config->go_venue_type);
1320f05cddf9SRui Paulo #endif /* CONFIG_INTERWORKING */
1321f05cddf9SRui Paulo 	if (config->pbc_in_m1)
1322325151a3SRui Paulo 		fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1);
13235b9c547cSRui Paulo 	if (config->wps_nfc_pw_from_config) {
1324f05cddf9SRui Paulo 		if (config->wps_nfc_dev_pw_id)
1325f05cddf9SRui Paulo 			fprintf(f, "wps_nfc_dev_pw_id=%d\n",
1326f05cddf9SRui Paulo 				config->wps_nfc_dev_pw_id);
13275b9c547cSRui Paulo 		write_global_bin(f, "wps_nfc_dh_pubkey",
13285b9c547cSRui Paulo 				 config->wps_nfc_dh_pubkey);
13295b9c547cSRui Paulo 		write_global_bin(f, "wps_nfc_dh_privkey",
13305b9c547cSRui Paulo 				 config->wps_nfc_dh_privkey);
1331f05cddf9SRui Paulo 		write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw);
13325b9c547cSRui Paulo 	}
1333f05cddf9SRui Paulo 
1334f05cddf9SRui Paulo 	if (config->ext_password_backend)
1335f05cddf9SRui Paulo 		fprintf(f, "ext_password_backend=%s\n",
1336f05cddf9SRui Paulo 			config->ext_password_backend);
1337f05cddf9SRui Paulo 	if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY)
1338f05cddf9SRui Paulo 		fprintf(f, "p2p_go_max_inactivity=%d\n",
1339f05cddf9SRui Paulo 			config->p2p_go_max_inactivity);
1340f05cddf9SRui Paulo 	if (config->auto_interworking)
1341f05cddf9SRui Paulo 		fprintf(f, "auto_interworking=%d\n",
1342f05cddf9SRui Paulo 			config->auto_interworking);
1343f05cddf9SRui Paulo 	if (config->okc)
1344f05cddf9SRui Paulo 		fprintf(f, "okc=%d\n", config->okc);
1345f05cddf9SRui Paulo 	if (config->pmf)
1346f05cddf9SRui Paulo 		fprintf(f, "pmf=%d\n", config->pmf);
13475b9c547cSRui Paulo 	if (config->dtim_period)
13485b9c547cSRui Paulo 		fprintf(f, "dtim_period=%d\n", config->dtim_period);
13495b9c547cSRui Paulo 	if (config->beacon_int)
13505b9c547cSRui Paulo 		fprintf(f, "beacon_int=%d\n", config->beacon_int);
13515b9c547cSRui Paulo 
13525b9c547cSRui Paulo 	if (config->sae_groups) {
13535b9c547cSRui Paulo 		int i;
13545b9c547cSRui Paulo 		fprintf(f, "sae_groups=");
135585732ac8SCy Schubert 		for (i = 0; config->sae_groups[i] > 0; i++) {
13565b9c547cSRui Paulo 			fprintf(f, "%s%d", i > 0 ? " " : "",
13575b9c547cSRui Paulo 				config->sae_groups[i]);
13585b9c547cSRui Paulo 		}
13595b9c547cSRui Paulo 		fprintf(f, "\n");
13605b9c547cSRui Paulo 	}
13615b9c547cSRui Paulo 
1362c1d255d3SCy Schubert 	if (config->sae_pwe)
1363c1d255d3SCy Schubert 		fprintf(f, "sae_pwe=%d\n", config->sae_pwe);
1364c1d255d3SCy Schubert 
1365c1d255d3SCy Schubert 	if (config->sae_pmkid_in_assoc)
1366c1d255d3SCy Schubert 		fprintf(f, "sae_pmkid_in_assoc=%d\n",
1367c1d255d3SCy Schubert 			config->sae_pmkid_in_assoc);
1368c1d255d3SCy Schubert 
13695b9c547cSRui Paulo 	if (config->ap_vendor_elements) {
13705b9c547cSRui Paulo 		int i, len = wpabuf_len(config->ap_vendor_elements);
13715b9c547cSRui Paulo 		const u8 *p = wpabuf_head_u8(config->ap_vendor_elements);
13725b9c547cSRui Paulo 		if (len > 0) {
13735b9c547cSRui Paulo 			fprintf(f, "ap_vendor_elements=");
13745b9c547cSRui Paulo 			for (i = 0; i < len; i++)
13755b9c547cSRui Paulo 				fprintf(f, "%02x", *p++);
13765b9c547cSRui Paulo 			fprintf(f, "\n");
13775b9c547cSRui Paulo 		}
13785b9c547cSRui Paulo 	}
13795b9c547cSRui Paulo 
13804b72b91aSCy Schubert 	if (config->ap_assocresp_elements) {
13814b72b91aSCy Schubert 		int i, len = wpabuf_len(config->ap_assocresp_elements);
13824b72b91aSCy Schubert 		const u8 *p = wpabuf_head_u8(config->ap_assocresp_elements);
13834b72b91aSCy Schubert 
13844b72b91aSCy Schubert 		if (len > 0) {
13854b72b91aSCy Schubert 			fprintf(f, "ap_assocresp_elements=");
13864b72b91aSCy Schubert 			for (i = 0; i < len; i++)
13874b72b91aSCy Schubert 				fprintf(f, "%02x", *p++);
13884b72b91aSCy Schubert 			fprintf(f, "\n");
13894b72b91aSCy Schubert 		}
13904b72b91aSCy Schubert 	}
13914b72b91aSCy Schubert 
13925b9c547cSRui Paulo 	if (config->ignore_old_scan_res)
13935b9c547cSRui Paulo 		fprintf(f, "ignore_old_scan_res=%d\n",
13945b9c547cSRui Paulo 			config->ignore_old_scan_res);
13955b9c547cSRui Paulo 
13965b9c547cSRui Paulo 	if (config->freq_list && config->freq_list[0]) {
13975b9c547cSRui Paulo 		int i;
13985b9c547cSRui Paulo 		fprintf(f, "freq_list=");
13995b9c547cSRui Paulo 		for (i = 0; config->freq_list[i]; i++) {
1400325151a3SRui Paulo 			fprintf(f, "%s%d", i > 0 ? " " : "",
14015b9c547cSRui Paulo 				config->freq_list[i]);
14025b9c547cSRui Paulo 		}
14035b9c547cSRui Paulo 		fprintf(f, "\n");
14045b9c547cSRui Paulo 	}
1405c1d255d3SCy Schubert 	if (config->initial_freq_list && config->initial_freq_list[0]) {
1406c1d255d3SCy Schubert 		int i;
1407c1d255d3SCy Schubert 		fprintf(f, "initial_freq_list=");
1408c1d255d3SCy Schubert 		for (i = 0; config->initial_freq_list[i]; i++) {
1409c1d255d3SCy Schubert 			fprintf(f, "%s%d", i > 0 ? " " : "",
1410c1d255d3SCy Schubert 				config->initial_freq_list[i]);
1411c1d255d3SCy Schubert 		}
1412c1d255d3SCy Schubert 		fprintf(f, "\n");
1413c1d255d3SCy Schubert 	}
14145b9c547cSRui Paulo 	if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ)
14155b9c547cSRui Paulo 		fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq);
14165b9c547cSRui Paulo 
1417c1d255d3SCy Schubert 	if (config->scan_res_valid_for_connect !=
1418c1d255d3SCy Schubert 	    DEFAULT_SCAN_RES_VALID_FOR_CONNECT)
1419c1d255d3SCy Schubert 		fprintf(f, "scan_res_valid_for_connect=%d\n",
1420c1d255d3SCy Schubert 			config->scan_res_valid_for_connect);
1421c1d255d3SCy Schubert 
14225b9c547cSRui Paulo 	if (config->sched_scan_interval)
14235b9c547cSRui Paulo 		fprintf(f, "sched_scan_interval=%u\n",
14245b9c547cSRui Paulo 			config->sched_scan_interval);
14255b9c547cSRui Paulo 
142685732ac8SCy Schubert 	if (config->sched_scan_start_delay)
142785732ac8SCy Schubert 		fprintf(f, "sched_scan_start_delay=%u\n",
142885732ac8SCy Schubert 			config->sched_scan_start_delay);
142985732ac8SCy Schubert 
14305b9c547cSRui Paulo 	if (config->external_sim)
14315b9c547cSRui Paulo 		fprintf(f, "external_sim=%d\n", config->external_sim);
14325b9c547cSRui Paulo 
14335b9c547cSRui Paulo 	if (config->tdls_external_control)
14345b9c547cSRui Paulo 		fprintf(f, "tdls_external_control=%d\n",
14355b9c547cSRui Paulo 			config->tdls_external_control);
14365b9c547cSRui Paulo 
14375b9c547cSRui Paulo 	if (config->wowlan_triggers)
14385b9c547cSRui Paulo 		fprintf(f, "wowlan_triggers=%s\n",
14395b9c547cSRui Paulo 			config->wowlan_triggers);
14405b9c547cSRui Paulo 
14415b9c547cSRui Paulo 	if (config->bgscan)
14425b9c547cSRui Paulo 		fprintf(f, "bgscan=\"%s\"\n", config->bgscan);
14435b9c547cSRui Paulo 
144485732ac8SCy Schubert 	if (config->autoscan)
144585732ac8SCy Schubert 		fprintf(f, "autoscan=%s\n", config->autoscan);
144685732ac8SCy Schubert 
14475b9c547cSRui Paulo 	if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY)
14485b9c547cSRui Paulo 		fprintf(f, "p2p_search_delay=%u\n",
14495b9c547cSRui Paulo 			config->p2p_search_delay);
14505b9c547cSRui Paulo 
14515b9c547cSRui Paulo 	if (config->mac_addr)
14525b9c547cSRui Paulo 		fprintf(f, "mac_addr=%d\n", config->mac_addr);
14535b9c547cSRui Paulo 
14545b9c547cSRui Paulo 	if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
14555b9c547cSRui Paulo 		fprintf(f, "rand_addr_lifetime=%u\n",
14565b9c547cSRui Paulo 			config->rand_addr_lifetime);
14575b9c547cSRui Paulo 
14585b9c547cSRui Paulo 	if (config->preassoc_mac_addr)
14595b9c547cSRui Paulo 		fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr);
14605b9c547cSRui Paulo 
14615b9c547cSRui Paulo 	if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD)
1462325151a3SRui Paulo 		fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload);
14635b9c547cSRui Paulo 
14645b9c547cSRui Paulo 	if (config->user_mpm != DEFAULT_USER_MPM)
14655b9c547cSRui Paulo 		fprintf(f, "user_mpm=%d\n", config->user_mpm);
14665b9c547cSRui Paulo 
14675b9c547cSRui Paulo 	if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS)
14685b9c547cSRui Paulo 		fprintf(f, "max_peer_links=%d\n", config->max_peer_links);
14695b9c547cSRui Paulo 
14705b9c547cSRui Paulo 	if (config->cert_in_cb != DEFAULT_CERT_IN_CB)
14715b9c547cSRui Paulo 		fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb);
14725b9c547cSRui Paulo 
14735b9c547cSRui Paulo 	if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY)
14745b9c547cSRui Paulo 		fprintf(f, "mesh_max_inactivity=%d\n",
14755b9c547cSRui Paulo 			config->mesh_max_inactivity);
14765b9c547cSRui Paulo 
1477*32a95656SCy Schubert 	if (config->mesh_fwding != DEFAULT_MESH_FWDING)
1478*32a95656SCy Schubert 		fprintf(f, "mesh_fwding=%d\n", config->mesh_fwding);
1479*32a95656SCy Schubert 
1480325151a3SRui Paulo 	if (config->dot11RSNASAERetransPeriod !=
1481325151a3SRui Paulo 	    DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD)
1482325151a3SRui Paulo 		fprintf(f, "dot11RSNASAERetransPeriod=%d\n",
1483325151a3SRui Paulo 			config->dot11RSNASAERetransPeriod);
1484325151a3SRui Paulo 
14855b9c547cSRui Paulo 	if (config->passive_scan)
14865b9c547cSRui Paulo 		fprintf(f, "passive_scan=%d\n", config->passive_scan);
14875b9c547cSRui Paulo 
14885b9c547cSRui Paulo 	if (config->reassoc_same_bss_optim)
14895b9c547cSRui Paulo 		fprintf(f, "reassoc_same_bss_optim=%d\n",
14905b9c547cSRui Paulo 			config->reassoc_same_bss_optim);
1491325151a3SRui Paulo 
1492325151a3SRui Paulo 	if (config->wps_priority)
1493325151a3SRui Paulo 		fprintf(f, "wps_priority=%d\n", config->wps_priority);
1494780fb4a2SCy Schubert 
1495780fb4a2SCy Schubert 	if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION)
1496780fb4a2SCy Schubert 		fprintf(f, "wpa_rsc_relaxation=%d\n",
1497780fb4a2SCy Schubert 			config->wpa_rsc_relaxation);
1498780fb4a2SCy Schubert 
1499780fb4a2SCy Schubert 	if (config->sched_scan_plans)
1500780fb4a2SCy Schubert 		fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans);
1501780fb4a2SCy Schubert 
1502780fb4a2SCy Schubert #ifdef CONFIG_MBO
1503780fb4a2SCy Schubert 	if (config->non_pref_chan)
1504780fb4a2SCy Schubert 		fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan);
1505780fb4a2SCy Schubert 	if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA)
1506780fb4a2SCy Schubert 		fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa);
150785732ac8SCy Schubert 	if (config->disassoc_imminent_rssi_threshold !=
150885732ac8SCy Schubert 	    DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD)
150985732ac8SCy Schubert 		fprintf(f, "disassoc_imminent_rssi_threshold=%d\n",
151085732ac8SCy Schubert 			config->disassoc_imminent_rssi_threshold);
151185732ac8SCy Schubert 	if (config->oce != DEFAULT_OCE_SUPPORT)
151285732ac8SCy Schubert 		fprintf(f, "oce=%u\n", config->oce);
1513780fb4a2SCy Schubert #endif /* CONFIG_MBO */
1514780fb4a2SCy Schubert 
1515780fb4a2SCy Schubert 	if (config->gas_address3)
1516780fb4a2SCy Schubert 		fprintf(f, "gas_address3=%d\n", config->gas_address3);
1517780fb4a2SCy Schubert 
1518780fb4a2SCy Schubert 	if (config->ftm_responder)
1519780fb4a2SCy Schubert 		fprintf(f, "ftm_responder=%d\n", config->ftm_responder);
1520780fb4a2SCy Schubert 	if (config->ftm_initiator)
1521780fb4a2SCy Schubert 		fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator);
152285732ac8SCy Schubert 
152385732ac8SCy Schubert 	if (config->osu_dir)
152485732ac8SCy Schubert 		fprintf(f, "osu_dir=%s\n", config->osu_dir);
152585732ac8SCy Schubert 
152685732ac8SCy Schubert 	if (config->fst_group_id)
152785732ac8SCy Schubert 		fprintf(f, "fst_group_id=%s\n", config->fst_group_id);
152885732ac8SCy Schubert 	if (config->fst_priority)
152985732ac8SCy Schubert 		fprintf(f, "fst_priority=%d\n", config->fst_priority);
153085732ac8SCy Schubert 	if (config->fst_llt)
153185732ac8SCy Schubert 		fprintf(f, "fst_llt=%d\n", config->fst_llt);
153285732ac8SCy Schubert 
153385732ac8SCy Schubert 	if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
153485732ac8SCy Schubert 		fprintf(f, "gas_rand_addr_lifetime=%u\n",
153585732ac8SCy Schubert 			config->gas_rand_addr_lifetime);
153685732ac8SCy Schubert 	if (config->gas_rand_mac_addr)
153785732ac8SCy Schubert 		fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr);
153885732ac8SCy Schubert 	if (config->dpp_config_processing)
153985732ac8SCy Schubert 		fprintf(f, "dpp_config_processing=%d\n",
154085732ac8SCy Schubert 			config->dpp_config_processing);
154185732ac8SCy Schubert 	if (config->coloc_intf_reporting)
154285732ac8SCy Schubert 		fprintf(f, "coloc_intf_reporting=%d\n",
154385732ac8SCy Schubert 			config->coloc_intf_reporting);
15444bc52338SCy Schubert 	if (config->p2p_device_random_mac_addr)
15454bc52338SCy Schubert 		fprintf(f, "p2p_device_random_mac_addr=%d\n",
15464bc52338SCy Schubert 			config->p2p_device_random_mac_addr);
15474bc52338SCy Schubert 	if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr))
15484bc52338SCy Schubert 		fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n",
15494bc52338SCy Schubert 			MAC2STR(config->p2p_device_persistent_mac_addr));
15504bc52338SCy Schubert 	if (config->p2p_interface_random_mac_addr)
15514bc52338SCy Schubert 		fprintf(f, "p2p_interface_random_mac_addr=%d\n",
15524bc52338SCy Schubert 			config->p2p_interface_random_mac_addr);
1553206b73d0SCy Schubert 	if (config->disable_btm)
1554206b73d0SCy Schubert 		fprintf(f, "disable_btm=1\n");
1555c1d255d3SCy Schubert 	if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID)
1556c1d255d3SCy Schubert 		fprintf(f, "extended_key_id=%d\n",
1557c1d255d3SCy Schubert 			config->extended_key_id);
1558c1d255d3SCy Schubert 	if (config->wowlan_disconnect_on_deinit)
1559c1d255d3SCy Schubert 		fprintf(f, "wowlan_disconnect_on_deinit=%d\n",
1560c1d255d3SCy Schubert 			config->wowlan_disconnect_on_deinit);
156139beb93cSSam Leffler }
156239beb93cSSam Leffler 
156339beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */
156439beb93cSSam Leffler 
156539beb93cSSam Leffler 
156639beb93cSSam Leffler int wpa_config_write(const char *name, struct wpa_config *config)
156739beb93cSSam Leffler {
156839beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE
156939beb93cSSam Leffler 	FILE *f;
157039beb93cSSam Leffler 	struct wpa_ssid *ssid;
1571f05cddf9SRui Paulo 	struct wpa_cred *cred;
157239beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS
157339beb93cSSam Leffler 	struct wpa_config_blob *blob;
157439beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */
157539beb93cSSam Leffler 	int ret = 0;
15765b9c547cSRui Paulo 	const char *orig_name = name;
1577c1d255d3SCy Schubert 	int tmp_len;
1578c1d255d3SCy Schubert 	char *tmp_name;
15795b9c547cSRui Paulo 
1580c1d255d3SCy Schubert 	if (!name) {
1581c1d255d3SCy Schubert 		wpa_printf(MSG_ERROR, "No configuration file for writing");
1582c1d255d3SCy Schubert 		return -1;
1583c1d255d3SCy Schubert 	}
1584c1d255d3SCy Schubert 
1585c1d255d3SCy Schubert 	tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
1586c1d255d3SCy Schubert 	tmp_name = os_malloc(tmp_len);
15875b9c547cSRui Paulo 	if (tmp_name) {
15885b9c547cSRui Paulo 		os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
15895b9c547cSRui Paulo 		name = tmp_name;
15905b9c547cSRui Paulo 	}
159139beb93cSSam Leffler 
159239beb93cSSam Leffler 	wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
159339beb93cSSam Leffler 
159439beb93cSSam Leffler 	f = fopen(name, "w");
159539beb93cSSam Leffler 	if (f == NULL) {
159639beb93cSSam Leffler 		wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
15975b9c547cSRui Paulo 		os_free(tmp_name);
159839beb93cSSam Leffler 		return -1;
159939beb93cSSam Leffler 	}
160039beb93cSSam Leffler 
160139beb93cSSam Leffler 	wpa_config_write_global(f, config);
160239beb93cSSam Leffler 
1603f05cddf9SRui Paulo 	for (cred = config->cred; cred; cred = cred->next) {
16045b9c547cSRui Paulo 		if (cred->temporary)
16055b9c547cSRui Paulo 			continue;
1606f05cddf9SRui Paulo 		fprintf(f, "\ncred={\n");
1607f05cddf9SRui Paulo 		wpa_config_write_cred(f, cred);
1608f05cddf9SRui Paulo 		fprintf(f, "}\n");
1609f05cddf9SRui Paulo 	}
1610f05cddf9SRui Paulo 
161139beb93cSSam Leffler 	for (ssid = config->ssid; ssid; ssid = ssid->next) {
1612f05cddf9SRui Paulo 		if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary)
1613f05cddf9SRui Paulo 			continue; /* do not save temporary networks */
1614c1d255d3SCy Schubert 		if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt) &&
1615c1d255d3SCy Schubert 		    !ssid->psk_set && !ssid->passphrase)
1616c1d255d3SCy Schubert 			continue; /* do not save invalid network */
1617c1d255d3SCy Schubert 		if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
1618c1d255d3SCy Schubert 		    !ssid->passphrase && !ssid->sae_password)
1619f05cddf9SRui Paulo 			continue; /* do not save invalid network */
162039beb93cSSam Leffler 		fprintf(f, "\nnetwork={\n");
162139beb93cSSam Leffler 		wpa_config_write_network(f, ssid);
162239beb93cSSam Leffler 		fprintf(f, "}\n");
162339beb93cSSam Leffler 	}
162439beb93cSSam Leffler 
162539beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS
162639beb93cSSam Leffler 	for (blob = config->blobs; blob; blob = blob->next) {
162739beb93cSSam Leffler 		ret = wpa_config_write_blob(f, blob);
162839beb93cSSam Leffler 		if (ret)
162939beb93cSSam Leffler 			break;
163039beb93cSSam Leffler 	}
163139beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */
163239beb93cSSam Leffler 
1633325151a3SRui Paulo 	os_fdatasync(f);
1634325151a3SRui Paulo 
163539beb93cSSam Leffler 	fclose(f);
163639beb93cSSam Leffler 
16375b9c547cSRui Paulo 	if (tmp_name) {
16385b9c547cSRui Paulo 		int chmod_ret = 0;
16395b9c547cSRui Paulo 
16405b9c547cSRui Paulo #ifdef ANDROID
16415b9c547cSRui Paulo 		chmod_ret = chmod(tmp_name,
16425b9c547cSRui Paulo 				  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
16435b9c547cSRui Paulo #endif /* ANDROID */
16445b9c547cSRui Paulo 		if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0)
16455b9c547cSRui Paulo 			ret = -1;
16465b9c547cSRui Paulo 
16475b9c547cSRui Paulo 		os_free(tmp_name);
16485b9c547cSRui Paulo 	}
16495b9c547cSRui Paulo 
165039beb93cSSam Leffler 	wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
16515b9c547cSRui Paulo 		   orig_name, ret ? "un" : "");
165239beb93cSSam Leffler 	return ret;
165339beb93cSSam Leffler #else /* CONFIG_NO_CONFIG_WRITE */
165439beb93cSSam Leffler 	return -1;
165539beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */
165639beb93cSSam Leffler }
1657