blob: 53614ae0a57212a3a069420c227726cc597bbe77 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Configuration backend: text file
Hai Shalomc3565922019-10-28 11:58:20 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 *
8 * This file implements a configuration backend for text files. All the
9 * configuration information is stored in a text file that uses a format
10 * described in the sample configuration file, wpa_supplicant.conf.
11 */
12
13#include "includes.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080014#ifdef ANDROID
15#include <sys/stat.h>
16#endif /* ANDROID */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017
18#include "common.h"
19#include "config.h"
20#include "base64.h"
21#include "uuid.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080022#include "common/ieee802_1x_defs.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070023#include "p2p/p2p.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080024#include "eap_peer/eap_methods.h"
25#include "eap_peer/eap.h"
Hai Shalom60840252021-02-19 19:02:11 -080026#include "utils/config.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027
28
29static int wpa_config_validate_network(struct wpa_ssid *ssid, int line)
30{
31 int errors = 0;
32
33 if (ssid->passphrase) {
34 if (ssid->psk_set) {
35 wpa_printf(MSG_ERROR, "Line %d: both PSK and "
36 "passphrase configured.", line);
37 errors++;
38 }
39 wpa_config_update_psk(ssid);
40 }
41
Dmitry Shmidt29333592017-01-09 12:27:11 -080042 if (ssid->disabled == 2)
43 ssid->p2p_persistent_group = 1;
44
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045 if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -070046 !(ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 |
47 WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256 |
48 WPA_CIPHER_NONE))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049 /* Group cipher cannot be stronger than the pairwise cipher. */
50 wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher"
51 " list since it was not allowed for pairwise "
52 "cipher", line);
53 ssid->group_cipher &= ~WPA_CIPHER_CCMP;
54 }
55
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000056 if (is_6ghz_freq(ssid->frequency) && ssid->mode == WPAS_MODE_MESH &&
57 ssid->key_mgmt == WPA_KEY_MGMT_NONE) {
58 wpa_printf(MSG_ERROR,
59 "Line %d: key_mgmt for mesh network in 6 GHz should be SAE",
60 line);
61 errors++;
62 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080063 if (ssid->mode == WPAS_MODE_MESH &&
64 (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
65 ssid->key_mgmt != WPA_KEY_MGMT_SAE)) {
66 wpa_printf(MSG_ERROR,
67 "Line %d: key_mgmt for mesh network should be open or SAE",
68 line);
69 errors++;
70 }
71
Hai Shalom74f70d42019-02-11 14:42:39 -080072#ifdef CONFIG_OCV
73 if (ssid->ocv && ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
74 wpa_printf(MSG_ERROR,
75 "Line %d: PMF needs to be enabled whenever using OCV",
76 line);
77 errors++;
78 }
79#endif /* CONFIG_OCV */
80
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070081 return errors;
82}
83
84
85static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id)
86{
87 struct wpa_ssid *ssid;
88 int errors = 0, end = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070089 char buf[2000], *pos, *pos2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090
91 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block",
92 *line);
93 ssid = os_zalloc(sizeof(*ssid));
94 if (ssid == NULL)
95 return NULL;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070096 dl_list_init(&ssid->psk_list);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 ssid->id = id;
98
99 wpa_config_set_network_defaults(ssid);
100
101 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
102 if (os_strcmp(pos, "}") == 0) {
103 end = 1;
104 break;
105 }
106
107 pos2 = os_strchr(pos, '=');
108 if (pos2 == NULL) {
109 wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line "
110 "'%s'.", *line, pos);
111 errors++;
112 continue;
113 }
114
115 *pos2++ = '\0';
116 if (*pos2 == '"') {
117 if (os_strchr(pos2 + 1, '"') == NULL) {
118 wpa_printf(MSG_ERROR, "Line %d: invalid "
119 "quotation '%s'.", *line, pos2);
120 errors++;
121 continue;
122 }
123 }
124
Hai Shalomfdcde762020-04-02 11:19:20 -0700125 if (wpa_config_set(ssid, pos, pos2, *line) < 0) {
126#ifndef CONFIG_WEP
127 if (os_strcmp(pos, "wep_key0") == 0 ||
128 os_strcmp(pos, "wep_key1") == 0 ||
129 os_strcmp(pos, "wep_key2") == 0 ||
130 os_strcmp(pos, "wep_key3") == 0 ||
131 os_strcmp(pos, "wep_tx_keyidx") == 0) {
132 wpa_printf(MSG_ERROR,
133 "Line %d: unsupported WEP parameter",
134 *line);
135 ssid->disabled = 1;
136 continue;
137 }
138#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139 errors++;
Hai Shalomfdcde762020-04-02 11:19:20 -0700140 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141 }
142
143 if (!end) {
144 wpa_printf(MSG_ERROR, "Line %d: network block was not "
145 "terminated properly.", *line);
146 errors++;
147 }
148
149 errors += wpa_config_validate_network(ssid, *line);
150
151 if (errors) {
152 wpa_config_free_ssid(ssid);
153 ssid = NULL;
154 }
155
156 return ssid;
157}
158
159
Dmitry Shmidt04949592012-07-19 12:16:46 -0700160static struct wpa_cred * wpa_config_read_cred(FILE *f, int *line, int id)
161{
162 struct wpa_cred *cred;
163 int errors = 0, end = 0;
164 char buf[256], *pos, *pos2;
165
166 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new cred block", *line);
167 cred = os_zalloc(sizeof(*cred));
168 if (cred == NULL)
169 return NULL;
170 cred->id = id;
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700171 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700172
173 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
174 if (os_strcmp(pos, "}") == 0) {
175 end = 1;
176 break;
177 }
178
179 pos2 = os_strchr(pos, '=');
180 if (pos2 == NULL) {
181 wpa_printf(MSG_ERROR, "Line %d: Invalid cred line "
182 "'%s'.", *line, pos);
183 errors++;
184 continue;
185 }
186
187 *pos2++ = '\0';
188 if (*pos2 == '"') {
189 if (os_strchr(pos2 + 1, '"') == NULL) {
190 wpa_printf(MSG_ERROR, "Line %d: invalid "
191 "quotation '%s'.", *line, pos2);
192 errors++;
193 continue;
194 }
195 }
196
197 if (wpa_config_set_cred(cred, pos, pos2, *line) < 0)
198 errors++;
199 }
200
201 if (!end) {
202 wpa_printf(MSG_ERROR, "Line %d: cred block was not "
203 "terminated properly.", *line);
204 errors++;
205 }
206
207 if (errors) {
208 wpa_config_free_cred(cred);
209 cred = NULL;
210 }
211
212 return cred;
213}
214
215
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216#ifndef CONFIG_NO_CONFIG_BLOBS
217static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line,
218 const char *name)
219{
220 struct wpa_config_blob *blob;
221 char buf[256], *pos;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800222 char *encoded = NULL, *nencoded;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 int end = 0;
224 size_t encoded_len = 0, len;
225
226 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'",
227 *line, name);
228
229 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
230 if (os_strcmp(pos, "}") == 0) {
231 end = 1;
232 break;
233 }
234
235 len = os_strlen(pos);
236 nencoded = os_realloc(encoded, encoded_len + len);
237 if (nencoded == NULL) {
238 wpa_printf(MSG_ERROR, "Line %d: not enough memory for "
239 "blob", *line);
240 os_free(encoded);
241 return NULL;
242 }
243 encoded = nencoded;
244 os_memcpy(encoded + encoded_len, pos, len);
245 encoded_len += len;
246 }
247
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700248 if (!end || !encoded) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249 wpa_printf(MSG_ERROR, "Line %d: blob was not terminated "
250 "properly", *line);
251 os_free(encoded);
252 return NULL;
253 }
254
255 blob = os_zalloc(sizeof(*blob));
256 if (blob == NULL) {
257 os_free(encoded);
258 return NULL;
259 }
260 blob->name = os_strdup(name);
261 blob->data = base64_decode(encoded, encoded_len, &blob->len);
262 os_free(encoded);
263
264 if (blob->name == NULL || blob->data == NULL) {
265 wpa_config_free_blob(blob);
266 return NULL;
267 }
268
269 return blob;
270}
271
272
273static int wpa_config_process_blob(struct wpa_config *config, FILE *f,
274 int *line, char *bname)
275{
276 char *name_end;
277 struct wpa_config_blob *blob;
278
279 name_end = os_strchr(bname, '=');
280 if (name_end == NULL) {
281 wpa_printf(MSG_ERROR, "Line %d: no blob name terminator",
282 *line);
283 return -1;
284 }
285 *name_end = '\0';
286
287 blob = wpa_config_read_blob(f, line, bname);
288 if (blob == NULL) {
289 wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s",
290 *line, bname);
291 return -1;
292 }
293 wpa_config_set_blob(config, blob);
294 return 0;
295}
296#endif /* CONFIG_NO_CONFIG_BLOBS */
297
298
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000299struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
300 bool ro)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301{
302 FILE *f;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700303 char buf[512], *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 int errors = 0, line = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700305 struct wpa_ssid *ssid, *tail, *head;
306 struct wpa_cred *cred, *cred_tail, *cred_head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 struct wpa_config *config;
Sunil Ravia04bd252022-05-02 22:54:18 -0700308 static int id = 0;
309 static int cred_id = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310
Dmitry Shmidt64f47c52013-04-16 10:41:54 -0700311 if (name == NULL)
312 return NULL;
313 if (cfgp)
314 config = cfgp;
315 else
316 config = wpa_config_alloc_empty(NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700317 if (config == NULL) {
318 wpa_printf(MSG_ERROR, "Failed to allocate config file "
319 "structure");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 return NULL;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700321 }
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700322 tail = head = config->ssid;
323 while (tail && tail->next)
324 tail = tail->next;
325 cred_tail = cred_head = config->cred;
326 while (cred_tail && cred_tail->next)
327 cred_tail = cred_tail->next;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
330 f = fopen(name, "r");
331 if (f == NULL) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700332 wpa_printf(MSG_ERROR, "Failed to open config file '%s', "
333 "error: %s", name, strerror(errno));
Dmitry Shmidte3d76d92018-02-01 00:34:54 +0000334 if (config != cfgp)
335 os_free(config);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 return NULL;
337 }
338
339 while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
340 if (os_strcmp(pos, "network={") == 0) {
341 ssid = wpa_config_read_network(f, &line, id++);
342 if (ssid == NULL) {
343 wpa_printf(MSG_ERROR, "Line %d: failed to "
344 "parse network block.", line);
345 errors++;
346 continue;
347 }
Sunil Raviaf8751c2023-03-29 11:35:17 -0700348 ssid->ro = ro;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349 if (head == NULL) {
350 head = tail = ssid;
351 } else {
352 tail->next = ssid;
353 tail = ssid;
354 }
355 if (wpa_config_add_prio_network(config, ssid)) {
356 wpa_printf(MSG_ERROR, "Line %d: failed to add "
357 "network block to priority list.",
358 line);
359 errors++;
360 continue;
361 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700362 } else if (os_strcmp(pos, "cred={") == 0) {
363 cred = wpa_config_read_cred(f, &line, cred_id++);
364 if (cred == NULL) {
365 wpa_printf(MSG_ERROR, "Line %d: failed to "
366 "parse cred block.", line);
367 errors++;
368 continue;
369 }
370 if (cred_head == NULL) {
371 cred_head = cred_tail = cred;
372 } else {
373 cred_tail->next = cred;
374 cred_tail = cred;
375 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376#ifndef CONFIG_NO_CONFIG_BLOBS
377 } else if (os_strncmp(pos, "blob-base64-", 12) == 0) {
378 if (wpa_config_process_blob(config, f, &line, pos + 12)
379 < 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700380 wpa_printf(MSG_ERROR, "Line %d: failed to "
381 "process blob.", line);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 errors++;
383 continue;
384 }
385#endif /* CONFIG_NO_CONFIG_BLOBS */
386 } else if (wpa_config_process_global(config, pos, line) < 0) {
387 wpa_printf(MSG_ERROR, "Line %d: Invalid configuration "
388 "line '%s'.", line, pos);
389 errors++;
390 continue;
391 }
392 }
393
394 fclose(f);
395
Iliyan Malchev97d98062013-04-23 02:37:51 +0000396 config->ssid = head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 wpa_config_debug_dump_networks(config);
Iliyan Malchev97d98062013-04-23 02:37:51 +0000398 config->cred = cred_head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399
400#ifndef WPA_IGNORE_CONFIG_ERRORS
401 if (errors) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700402 if (config != cfgp)
403 wpa_config_free(config);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 config = NULL;
405 head = NULL;
406 }
407#endif /* WPA_IGNORE_CONFIG_ERRORS */
408
409 return config;
410}
411
412
413#ifndef CONFIG_NO_CONFIG_WRITE
414
415static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid)
416{
417 char *value = wpa_config_get(ssid, field);
418 if (value == NULL)
419 return;
420 fprintf(f, "\t%s=%s\n", field, value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800421 str_clear_free(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422}
423
424
425static void write_int(FILE *f, const char *field, int value, int def)
426{
427 if (value == def)
428 return;
429 fprintf(f, "\t%s=%d\n", field, value);
430}
431
432
433static void write_bssid(FILE *f, struct wpa_ssid *ssid)
434{
435 char *value = wpa_config_get(ssid, "bssid");
436 if (value == NULL)
437 return;
438 fprintf(f, "\tbssid=%s\n", value);
439 os_free(value);
440}
441
442
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700443static void write_bssid_hint(FILE *f, struct wpa_ssid *ssid)
444{
445 char *value = wpa_config_get(ssid, "bssid_hint");
446
447 if (!value)
448 return;
449 fprintf(f, "\tbssid_hint=%s\n", value);
450 os_free(value);
451}
452
453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454static void write_psk(FILE *f, struct wpa_ssid *ssid)
455{
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700456 char *value;
457
458 if (ssid->mem_only_psk)
459 return;
460
461 value = wpa_config_get(ssid, "psk");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700462 if (value == NULL)
463 return;
464 fprintf(f, "\tpsk=%s\n", value);
465 os_free(value);
466}
467
468
469static void write_proto(FILE *f, struct wpa_ssid *ssid)
470{
471 char *value;
472
473 if (ssid->proto == DEFAULT_PROTO)
474 return;
475
476 value = wpa_config_get(ssid, "proto");
477 if (value == NULL)
478 return;
479 if (value[0])
480 fprintf(f, "\tproto=%s\n", value);
481 os_free(value);
482}
483
484
485static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid)
486{
487 char *value;
488
489 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
490 return;
491
492 value = wpa_config_get(ssid, "key_mgmt");
493 if (value == NULL)
494 return;
495 if (value[0])
496 fprintf(f, "\tkey_mgmt=%s\n", value);
497 os_free(value);
498}
499
500
501static void write_pairwise(FILE *f, struct wpa_ssid *ssid)
502{
503 char *value;
504
505 if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
506 return;
507
508 value = wpa_config_get(ssid, "pairwise");
509 if (value == NULL)
510 return;
511 if (value[0])
512 fprintf(f, "\tpairwise=%s\n", value);
513 os_free(value);
514}
515
516
517static void write_group(FILE *f, struct wpa_ssid *ssid)
518{
519 char *value;
520
521 if (ssid->group_cipher == DEFAULT_GROUP)
522 return;
523
524 value = wpa_config_get(ssid, "group");
525 if (value == NULL)
526 return;
527 if (value[0])
528 fprintf(f, "\tgroup=%s\n", value);
529 os_free(value);
530}
531
532
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700533static void write_group_mgmt(FILE *f, struct wpa_ssid *ssid)
534{
535 char *value;
536
537 if (!ssid->group_mgmt_cipher)
538 return;
539
540 value = wpa_config_get(ssid, "group_mgmt");
541 if (!value)
542 return;
543 if (value[0])
544 fprintf(f, "\tgroup_mgmt=%s\n", value);
545 os_free(value);
546}
547
548
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549static void write_auth_alg(FILE *f, struct wpa_ssid *ssid)
550{
551 char *value;
552
553 if (ssid->auth_alg == 0)
554 return;
555
556 value = wpa_config_get(ssid, "auth_alg");
557 if (value == NULL)
558 return;
559 if (value[0])
560 fprintf(f, "\tauth_alg=%s\n", value);
561 os_free(value);
562}
563
564
565#ifdef IEEE8021X_EAPOL
566static void write_eap(FILE *f, struct wpa_ssid *ssid)
567{
568 char *value;
569
570 value = wpa_config_get(ssid, "eap");
571 if (value == NULL)
572 return;
573
574 if (value[0])
575 fprintf(f, "\teap=%s\n", value);
576 os_free(value);
577}
578#endif /* IEEE8021X_EAPOL */
579
580
Hai Shalomfdcde762020-04-02 11:19:20 -0700581#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
583{
584 char field[20], *value;
585 int res;
586
587 res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800588 if (os_snprintf_error(sizeof(field), res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 return;
590 value = wpa_config_get(ssid, field);
591 if (value) {
592 fprintf(f, "\t%s=%s\n", field, value);
593 os_free(value);
594 }
595}
Hai Shalomfdcde762020-04-02 11:19:20 -0700596#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597
598
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800599#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700600
Dmitry Shmidt54605472013-11-08 11:10:19 -0800601static void write_go_p2p_dev_addr(FILE *f, struct wpa_ssid *ssid)
602{
603 char *value = wpa_config_get(ssid, "go_p2p_dev_addr");
604 if (value == NULL)
605 return;
606 fprintf(f, "\tgo_p2p_dev_addr=%s\n", value);
607 os_free(value);
608}
609
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800610static void write_p2p_client_list(FILE *f, struct wpa_ssid *ssid)
611{
612 char *value = wpa_config_get(ssid, "p2p_client_list");
613 if (value == NULL)
614 return;
615 fprintf(f, "\tp2p_client_list=%s\n", value);
616 os_free(value);
617}
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700618
619
620static void write_psk_list(FILE *f, struct wpa_ssid *ssid)
621{
622 struct psk_list_entry *psk;
623 char hex[32 * 2 + 1];
624
625 dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) {
626 wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk));
627 fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n",
628 psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex);
629 }
630}
631
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800632#endif /* CONFIG_P2P */
633
634
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800635#ifdef CONFIG_MACSEC
636
637static void write_mka_cak(FILE *f, struct wpa_ssid *ssid)
638{
639 char *value;
640
641 if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK))
642 return;
643
644 value = wpa_config_get(ssid, "mka_cak");
645 if (!value)
646 return;
647 fprintf(f, "\tmka_cak=%s\n", value);
648 os_free(value);
649}
650
651
652static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid)
653{
654 char *value;
655
656 if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN))
657 return;
658
659 value = wpa_config_get(ssid, "mka_ckn");
660 if (!value)
661 return;
662 fprintf(f, "\tmka_ckn=%s\n", value);
663 os_free(value);
664}
665
666#endif /* CONFIG_MACSEC */
667
668
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
670{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671#define STR(t) write_str(f, #t, ssid)
672#define INT(t) write_int(f, #t, ssid->t, 0)
Hai Shalomc3565922019-10-28 11:58:20 -0700673#define INTe(t, m) write_int(f, #t, ssid->eap.m, 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674#define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
Hai Shalomc3565922019-10-28 11:58:20 -0700675#define INT_DEFe(t, m, def) write_int(f, #t, ssid->eap.m, def)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676
677 STR(ssid);
678 INT(scan_ssid);
679 write_bssid(f, ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700680 write_bssid_hint(f, ssid);
Hai Shalom60840252021-02-19 19:02:11 -0800681 write_str(f, "bssid_ignore", ssid);
682 write_str(f, "bssid_accept", ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 write_psk(f, ssid);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700684 INT(mem_only_psk);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700685 STR(sae_password);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700686 STR(sae_password_id);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800687 write_int(f, "sae_pwe", ssid->sae_pwe, DEFAULT_SAE_PWE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 write_proto(f, ssid);
689 write_key_mgmt(f, ssid);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700690 INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 write_pairwise(f, ssid);
692 write_group(f, ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700693 write_group_mgmt(f, ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694 write_auth_alg(f, ssid);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700695 STR(bgscan);
696 STR(autoscan);
Dmitry Shmidt56052862013-10-04 10:23:25 -0700697 STR(scan_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698#ifdef IEEE8021X_EAPOL
699 write_eap(f, ssid);
700 STR(identity);
701 STR(anonymous_identity);
Jouni Malinena3cb6f02017-12-08 17:05:40 +0200702 STR(imsi_identity);
Hai Shalomc3565922019-10-28 11:58:20 -0700703 STR(machine_identity);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 STR(password);
Hai Shalomc3565922019-10-28 11:58:20 -0700705 STR(machine_password);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 STR(ca_cert);
707 STR(ca_path);
708 STR(client_cert);
709 STR(private_key);
710 STR(private_key_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 STR(subject_match);
Hai Shalom021b0b52019-04-10 11:17:58 -0700712 STR(check_cert_subject);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 STR(altsubject_match);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700714 STR(domain_suffix_match);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800715 STR(domain_match);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716 STR(ca_cert2);
717 STR(ca_path2);
718 STR(client_cert2);
719 STR(private_key2);
720 STR(private_key2_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 STR(subject_match2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700722 STR(check_cert_subject2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 STR(altsubject_match2);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700724 STR(domain_suffix_match2);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800725 STR(domain_match2);
Hai Shalomc3565922019-10-28 11:58:20 -0700726 STR(machine_ca_cert);
727 STR(machine_ca_path);
728 STR(machine_client_cert);
729 STR(machine_private_key);
730 STR(machine_private_key_passwd);
Hai Shalomc3565922019-10-28 11:58:20 -0700731 STR(machine_subject_match);
732 STR(machine_check_cert_subject);
733 STR(machine_altsubject_match);
734 STR(machine_domain_suffix_match);
735 STR(machine_domain_match);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736 STR(phase1);
737 STR(phase2);
Hai Shalomc3565922019-10-28 11:58:20 -0700738 STR(machine_phase2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739 STR(pcsc);
740 STR(pin);
741 STR(engine_id);
742 STR(key_id);
743 STR(cert_id);
744 STR(ca_cert_id);
745 STR(key2_id);
746 STR(pin2);
747 STR(engine2_id);
748 STR(cert2_id);
749 STR(ca_cert2_id);
Hai Shalomc3565922019-10-28 11:58:20 -0700750 INTe(engine, cert.engine);
751 INTe(engine2, phase2_cert.engine);
752 INTe(machine_engine, machine_cert.engine);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800754 STR(openssl_ciphers);
Hai Shalomc3565922019-10-28 11:58:20 -0700755 INTe(erp, erp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700756#endif /* IEEE8021X_EAPOL */
Hai Shalomfdcde762020-04-02 11:19:20 -0700757#ifdef CONFIG_WEP
758 {
759 int i;
760
761 for (i = 0; i < 4; i++)
762 write_wep_key(f, i, ssid);
763 INT(wep_tx_keyidx);
764 }
765#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 INT(priority);
767#ifdef IEEE8021X_EAPOL
768 INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
769 STR(pac_file);
Hai Shalomc3565922019-10-28 11:58:20 -0700770 INT_DEFe(fragment_size, fragment_size, DEFAULT_FRAGMENT_SIZE);
771 INTe(ocsp, cert.ocsp);
772 INTe(ocsp2, phase2_cert.ocsp);
773 INTe(machine_ocsp, machine_cert.ocsp);
774 INT_DEFe(sim_num, sim_num, DEFAULT_USER_SELECTED_SIM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775#endif /* IEEE8021X_EAPOL */
776 INT(mode);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800777 INT(no_auto_peer);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800778 INT(mesh_fwding);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800779 INT(frequency);
Hai Shalomc3565922019-10-28 11:58:20 -0700780 INT(enable_edmg);
781 INT(edmg_channel);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800782 INT(fixed_freq);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800783#ifdef CONFIG_ACS
784 INT(acs);
785#endif /* CONFIG_ACS */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800786 write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 INT(disabled);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800788 INT(mixed_cell);
Hai Shalom899fcc72020-10-19 14:38:18 -0700789 INT_DEF(vht, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700790 INT_DEF(ht, 1);
791 INT(ht40);
Hai Shalom899fcc72020-10-19 14:38:18 -0700792 INT_DEF(he, 1);
Hai Shalom74f70d42019-02-11 14:42:39 -0800793 INT_DEF(max_oper_chwidth, DEFAULT_MAX_OPER_CHWIDTH);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700794 INT(vht_center_freq1);
795 INT(vht_center_freq2);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800796 INT(pbss);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700797 INT(wps_disabled);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700798 INT(fils_dh_group);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800799 write_int(f, "ieee80211w", ssid->ieee80211w,
800 MGMT_FRAME_PROTECTION_DEFAULT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 STR(id_str);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802#ifdef CONFIG_P2P
Dmitry Shmidt54605472013-11-08 11:10:19 -0800803 write_go_p2p_dev_addr(f, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800804 write_p2p_client_list(f, ssid);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700805 write_psk_list(f, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806#endif /* CONFIG_P2P */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800807 INT(ap_max_inactivity);
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800808 INT(dtim_period);
809 INT(beacon_int);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700810#ifdef CONFIG_MACSEC
811 INT(macsec_policy);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800812 write_mka_cak(f, ssid);
813 write_mka_ckn(f, ssid);
814 INT(macsec_integ_only);
Hai Shalom74f70d42019-02-11 14:42:39 -0800815 INT(macsec_replay_protect);
816 INT(macsec_replay_window);
Sunil Raviaf8751c2023-03-29 11:35:17 -0700817 INT(macsec_offload);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800818 INT(macsec_port);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800819 INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER);
Sunil Ravia04bd252022-05-02 22:54:18 -0700820 INT(macsec_csindex);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700821#endif /* CONFIG_MACSEC */
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700822#ifdef CONFIG_HS20
823 INT(update_identifier);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700824 STR(roaming_consortium_selection);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700825#endif /* CONFIG_HS20 */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700826 write_int(f, "mac_addr", ssid->mac_addr, -1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800827#ifdef CONFIG_MESH
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800828 STR(mesh_basic_rates);
829 INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES);
830 INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT);
831 INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT);
832 INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700833 INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834#endif /* CONFIG_MESH */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800835 INT(wpa_ptk_rekey);
Hai Shalomfdcde762020-04-02 11:19:20 -0700836 INT(wpa_deny_ptk0_rekey);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700837 INT(group_rekey);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800838 INT(ignore_broadcast_ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700839#ifdef CONFIG_DPP
840 STR(dpp_connector);
841 STR(dpp_netaccesskey);
842 INT(dpp_netaccesskey_expiry);
843 STR(dpp_csign);
Hai Shalom899fcc72020-10-19 14:38:18 -0700844 STR(dpp_pp_key);
Hai Shalomfdcde762020-04-02 11:19:20 -0700845 INT(dpp_pfs);
Sunil Ravi89eba102022-09-13 21:04:37 -0700846 INT(dpp_connector_privacy);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700847#endif /* CONFIG_DPP */
848 INT(owe_group);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700849 INT(owe_only);
Hai Shalomfdcde762020-04-02 11:19:20 -0700850 INT(owe_ptk_workaround);
Hai Shalom74f70d42019-02-11 14:42:39 -0800851 INT(multi_ap_backhaul_sta);
Hai Shalom81f62d82019-07-22 12:10:00 -0700852 INT(ft_eap_pmksa_caching);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000853 INT(multi_ap_profile);
Hai Shalomfdcde762020-04-02 11:19:20 -0700854 INT(beacon_prot);
855 INT(transition_disable);
Hai Shalom899fcc72020-10-19 14:38:18 -0700856 INT(sae_pk);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800857#ifdef CONFIG_HT_OVERRIDES
858 INT_DEF(disable_ht, DEFAULT_DISABLE_HT);
859 INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40);
860 INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI);
861 INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC);
862 INT(ht40_intolerant);
Hai Shalom74f70d42019-02-11 14:42:39 -0800863 INT_DEF(tx_stbc, DEFAULT_TX_STBC);
864 INT_DEF(rx_stbc, DEFAULT_RX_STBC);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800865 INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU);
866 INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR);
867 INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY);
868 STR(ht_mcs);
869#endif /* CONFIG_HT_OVERRIDES */
870#ifdef CONFIG_VHT_OVERRIDES
871 INT(disable_vht);
872 INT(vht_capa);
873 INT(vht_capa_mask);
874 INT_DEF(vht_rx_mcs_nss_1, -1);
875 INT_DEF(vht_rx_mcs_nss_2, -1);
876 INT_DEF(vht_rx_mcs_nss_3, -1);
877 INT_DEF(vht_rx_mcs_nss_4, -1);
878 INT_DEF(vht_rx_mcs_nss_5, -1);
879 INT_DEF(vht_rx_mcs_nss_6, -1);
880 INT_DEF(vht_rx_mcs_nss_7, -1);
881 INT_DEF(vht_rx_mcs_nss_8, -1);
882 INT_DEF(vht_tx_mcs_nss_1, -1);
883 INT_DEF(vht_tx_mcs_nss_2, -1);
884 INT_DEF(vht_tx_mcs_nss_3, -1);
885 INT_DEF(vht_tx_mcs_nss_4, -1);
886 INT_DEF(vht_tx_mcs_nss_5, -1);
887 INT_DEF(vht_tx_mcs_nss_6, -1);
888 INT_DEF(vht_tx_mcs_nss_7, -1);
889 INT_DEF(vht_tx_mcs_nss_8, -1);
890#endif /* CONFIG_VHT_OVERRIDES */
Hai Shalomfdcde762020-04-02 11:19:20 -0700891#ifdef CONFIG_HE_OVERRIDES
892 INT(disable_he);
893#endif /* CONFIG_HE_OVERRIDES */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000894 INT(disable_eht);
Sunil Raviaf8751c2023-03-29 11:35:17 -0700895 INT(enable_4addr_mode);
Sunil Ravi7f769292024-07-23 22:21:32 +0000896 INT(max_idle);
897 INT(ssid_protection);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898
899#undef STR
900#undef INT
901#undef INT_DEF
902}
903
904
Dmitry Shmidt04949592012-07-19 12:16:46 -0700905static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred)
906{
Dmitry Shmidt051af732013-10-22 13:52:46 -0700907 size_t i;
908
Dmitry Shmidt04949592012-07-19 12:16:46 -0700909 if (cred->priority)
910 fprintf(f, "\tpriority=%d\n", cred->priority);
911 if (cred->pcsc)
912 fprintf(f, "\tpcsc=%d\n", cred->pcsc);
913 if (cred->realm)
914 fprintf(f, "\trealm=\"%s\"\n", cred->realm);
915 if (cred->username)
916 fprintf(f, "\tusername=\"%s\"\n", cred->username);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800917 if (cred->password && cred->ext_password)
918 fprintf(f, "\tpassword=ext:%s\n", cred->password);
919 else if (cred->password)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700920 fprintf(f, "\tpassword=\"%s\"\n", cred->password);
921 if (cred->ca_cert)
922 fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800923 if (cred->client_cert)
924 fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert);
925 if (cred->private_key)
926 fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key);
927 if (cred->private_key_passwd)
928 fprintf(f, "\tprivate_key_passwd=\"%s\"\n",
929 cred->private_key_passwd);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700930 if (cred->imsi)
931 fprintf(f, "\timsi=\"%s\"\n", cred->imsi);
932 if (cred->milenage)
933 fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700934 for (i = 0; i < cred->num_domain; i++)
935 fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]);
936 if (cred->domain_suffix_match)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -0700937 fprintf(f, "\tdomain_suffix_match=\"%s\"\n",
Dmitry Shmidt051af732013-10-22 13:52:46 -0700938 cred->domain_suffix_match);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800939 if (cred->eap_method) {
940 const char *name;
941 name = eap_get_name(cred->eap_method[0].vendor,
942 cred->eap_method[0].method);
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700943 if (name)
944 fprintf(f, "\teap=%s\n", name);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800945 }
946 if (cred->phase1)
947 fprintf(f, "\tphase1=\"%s\"\n", cred->phase1);
948 if (cred->phase2)
949 fprintf(f, "\tphase2=\"%s\"\n", cred->phase2);
950 if (cred->excluded_ssid) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700951 size_t j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800952 for (i = 0; i < cred->num_excluded_ssid; i++) {
953 struct excluded_ssid *e = &cred->excluded_ssid[i];
954 fprintf(f, "\texcluded_ssid=");
955 for (j = 0; j < e->ssid_len; j++)
956 fprintf(f, "%02x", e->ssid[j]);
957 fprintf(f, "\n");
958 }
959 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800960 if (cred->roaming_partner) {
961 for (i = 0; i < cred->num_roaming_partner; i++) {
962 struct roaming_partner *p = &cred->roaming_partner[i];
963 fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n",
964 p->fqdn, p->exact_match, p->priority,
965 p->country);
966 }
967 }
968 if (cred->update_identifier)
969 fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier);
970
971 if (cred->provisioning_sp)
Dmitry Shmidt61593f02014-04-21 16:27:35 -0700972 fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800973 if (cred->sp_priority)
974 fprintf(f, "\tsp_priority=%d\n", cred->sp_priority);
975
976 if (cred->min_dl_bandwidth_home)
977 fprintf(f, "\tmin_dl_bandwidth_home=%u\n",
978 cred->min_dl_bandwidth_home);
979 if (cred->min_ul_bandwidth_home)
980 fprintf(f, "\tmin_ul_bandwidth_home=%u\n",
981 cred->min_ul_bandwidth_home);
982 if (cred->min_dl_bandwidth_roaming)
983 fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n",
984 cred->min_dl_bandwidth_roaming);
985 if (cred->min_ul_bandwidth_roaming)
986 fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n",
987 cred->min_ul_bandwidth_roaming);
988
989 if (cred->max_bss_load)
990 fprintf(f, "\tmax_bss_load=%u\n",
991 cred->max_bss_load);
992
993 if (cred->ocsp)
994 fprintf(f, "\tocsp=%d\n", cred->ocsp);
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -0700995
996 if (cred->num_req_conn_capab) {
997 for (i = 0; i < cred->num_req_conn_capab; i++) {
998 int *ports;
999
1000 fprintf(f, "\treq_conn_capab=%u",
1001 cred->req_conn_capab_proto[i]);
1002 ports = cred->req_conn_capab_port[i];
1003 if (ports) {
1004 int j;
1005 for (j = 0; ports[j] != -1; j++) {
1006 fprintf(f, "%s%d", j > 0 ? "," : ":",
1007 ports[j]);
1008 }
1009 }
1010 fprintf(f, "\n");
1011 }
1012 }
1013
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001014 if (cred->num_home_ois) {
1015 size_t j;
1016
1017 fprintf(f, "\thome_ois=\"");
1018 for (i = 0; i < cred->num_home_ois; i++) {
1019 if (i > 0)
1020 fprintf(f, ",");
1021 for (j = 0; j < cred->home_ois_len[i]; j++)
1022 fprintf(f, "%02x",
1023 cred->home_ois[i][j]);
1024 }
1025 fprintf(f, "\"\n");
1026 }
1027
1028 if (cred->num_required_home_ois) {
1029 size_t j;
1030
1031 fprintf(f, "\trequired_home_ois=\"");
1032 for (i = 0; i < cred->num_required_home_ois; i++) {
1033 if (i > 0)
1034 fprintf(f, ",");
1035 for (j = 0; j < cred->required_home_ois_len[i]; j++)
1036 fprintf(f, "%02x",
1037 cred->required_home_ois[i][j]);
1038 }
1039 fprintf(f, "\"\n");
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07001040 }
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001041
Roshan Pius3a1667e2018-07-03 15:17:14 -07001042 if (cred->num_roaming_consortiums) {
1043 size_t j;
1044
1045 fprintf(f, "\troaming_consortiums=\"");
1046 for (i = 0; i < cred->num_roaming_consortiums; i++) {
1047 if (i > 0)
1048 fprintf(f, ",");
1049 for (j = 0; j < cred->roaming_consortiums_len[i]; j++)
1050 fprintf(f, "%02x",
1051 cred->roaming_consortiums[i][j]);
1052 }
1053 fprintf(f, "\"\n");
1054 }
1055
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001056 if (cred->sim_num != DEFAULT_USER_SELECTED_SIM)
1057 fprintf(f, "\tsim_num=%d\n", cred->sim_num);
Hai Shaloma20dcd72022-02-04 13:43:00 -08001058
1059 if (cred->engine)
1060 fprintf(f, "\tengine=%d\n", cred->engine);
1061 if (cred->engine_id)
1062 fprintf(f, "\tengine_id=\"%s\"\n", cred->engine_id);
1063 if (cred->key_id)
1064 fprintf(f, "\tkey_id=\"%s\"\n", cred->key_id);
1065 if (cred->cert_id)
1066 fprintf(f, "\tcert_id=\"%s\"\n", cred->cert_id);
1067 if (cred->ca_cert_id)
1068 fprintf(f, "\tca_cert_id=\"%s\"\n", cred->ca_cert_id);
Sunil8cd6f4d2022-06-28 18:40:46 +00001069
1070 if (cred->imsi_privacy_cert)
1071 fprintf(f, "\timsi_privacy_cert=\"%s\"\n",
1072 cred->imsi_privacy_cert);
1073 if (cred->imsi_privacy_attr)
1074 fprintf(f, "\timsi_privacy_attr=\"%s\"\n",
1075 cred->imsi_privacy_attr);
Steven Liu9138d432022-11-23 22:29:05 +00001076 if (cred->strict_conservative_peer_mode)
1077 fprintf(f,"\tstrict_conservative_peer_mode=\"%d\"\n",
1078 cred->strict_conservative_peer_mode);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001079}
1080
1081
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082#ifndef CONFIG_NO_CONFIG_BLOBS
1083static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
1084{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001085 char *encoded;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086
1087 encoded = base64_encode(blob->data, blob->len, NULL);
1088 if (encoded == NULL)
1089 return -1;
1090
1091 fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
1092 os_free(encoded);
1093 return 0;
1094}
1095#endif /* CONFIG_NO_CONFIG_BLOBS */
1096
1097
Dmitry Shmidt04949592012-07-19 12:16:46 -07001098static void write_global_bin(FILE *f, const char *field,
1099 const struct wpabuf *val)
1100{
1101 size_t i;
1102 const u8 *pos;
1103
1104 if (val == NULL)
1105 return;
1106
1107 fprintf(f, "%s=", field);
1108 pos = wpabuf_head(val);
1109 for (i = 0; i < wpabuf_len(val); i++)
1110 fprintf(f, "%02X", *pos++);
1111 fprintf(f, "\n");
1112}
1113
1114
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001115static void wpa_config_write_global(FILE *f, struct wpa_config *config)
1116{
1117#ifdef CONFIG_CTRL_IFACE
1118 if (config->ctrl_interface)
1119 fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
1120 if (config->ctrl_interface_group)
1121 fprintf(f, "ctrl_interface_group=%s\n",
1122 config->ctrl_interface_group);
1123#endif /* CONFIG_CTRL_IFACE */
1124 if (config->eapol_version != DEFAULT_EAPOL_VERSION)
1125 fprintf(f, "eapol_version=%d\n", config->eapol_version);
1126 if (config->ap_scan != DEFAULT_AP_SCAN)
1127 fprintf(f, "ap_scan=%d\n", config->ap_scan);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001128 if (config->disable_scan_offload)
1129 fprintf(f, "disable_scan_offload=%d\n",
1130 config->disable_scan_offload);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
1132 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001133#ifndef CONFIG_OPENSC_ENGINE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 if (config->opensc_engine_path)
1135 fprintf(f, "opensc_engine_path=%s\n",
1136 config->opensc_engine_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001137#endif /* CONFIG_OPENSC_ENGINE_PATH */
1138#ifndef CONFIG_PKCS11_ENGINE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 if (config->pkcs11_engine_path)
1140 fprintf(f, "pkcs11_engine_path=%s\n",
1141 config->pkcs11_engine_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001142#endif /* CONFIG_PKCS11_ENGINE_PATH */
1143#ifndef CONFIG_PKCS11_MODULE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 if (config->pkcs11_module_path)
1145 fprintf(f, "pkcs11_module_path=%s\n",
1146 config->pkcs11_module_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001147#endif /* CONFIG_PKCS11_MODULE_PATH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001148 if (config->openssl_ciphers)
1149 fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001150 if (config->pcsc_reader)
1151 fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader);
1152 if (config->pcsc_pin)
1153 fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154 if (config->driver_param)
1155 fprintf(f, "driver_param=%s\n", config->driver_param);
1156 if (config->dot11RSNAConfigPMKLifetime)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001157 fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158 config->dot11RSNAConfigPMKLifetime);
1159 if (config->dot11RSNAConfigPMKReauthThreshold)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001160 fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161 config->dot11RSNAConfigPMKReauthThreshold);
1162 if (config->dot11RSNAConfigSATimeout)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001163 fprintf(f, "dot11RSNAConfigSATimeout=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 config->dot11RSNAConfigSATimeout);
1165 if (config->update_config)
1166 fprintf(f, "update_config=%d\n", config->update_config);
1167#ifdef CONFIG_WPS
1168 if (!is_nil_uuid(config->uuid)) {
1169 char buf[40];
1170 uuid_bin2str(config->uuid, buf, sizeof(buf));
1171 fprintf(f, "uuid=%s\n", buf);
1172 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001173 if (config->auto_uuid)
1174 fprintf(f, "auto_uuid=%d\n", config->auto_uuid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175 if (config->device_name)
1176 fprintf(f, "device_name=%s\n", config->device_name);
1177 if (config->manufacturer)
1178 fprintf(f, "manufacturer=%s\n", config->manufacturer);
1179 if (config->model_name)
1180 fprintf(f, "model_name=%s\n", config->model_name);
1181 if (config->model_number)
1182 fprintf(f, "model_number=%s\n", config->model_number);
1183 if (config->serial_number)
1184 fprintf(f, "serial_number=%s\n", config->serial_number);
1185 {
1186 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1187 buf = wps_dev_type_bin2str(config->device_type,
1188 _buf, sizeof(_buf));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001189 if (os_strcmp(buf, "0-00000000-0") != 0)
1190 fprintf(f, "device_type=%s\n", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 }
1192 if (WPA_GET_BE32(config->os_version))
1193 fprintf(f, "os_version=%08x\n",
1194 WPA_GET_BE32(config->os_version));
1195 if (config->config_methods)
1196 fprintf(f, "config_methods=%s\n", config->config_methods);
1197 if (config->wps_cred_processing)
1198 fprintf(f, "wps_cred_processing=%d\n",
1199 config->wps_cred_processing);
Hai Shalom021b0b52019-04-10 11:17:58 -07001200 if (config->wps_cred_add_sae)
1201 fprintf(f, "wps_cred_add_sae=%d\n",
1202 config->wps_cred_add_sae);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001203 if (config->wps_vendor_ext_m1) {
1204 int i, len = wpabuf_len(config->wps_vendor_ext_m1);
1205 const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1);
1206 if (len > 0) {
1207 fprintf(f, "wps_vendor_ext_m1=");
1208 for (i = 0; i < len; i++)
1209 fprintf(f, "%02x", *p++);
1210 fprintf(f, "\n");
1211 }
1212 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213#endif /* CONFIG_WPS */
1214#ifdef CONFIG_P2P
Paul Stewart092955c2017-02-06 09:13:09 -08001215 {
1216 int i;
1217 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1218
1219 for (i = 0; i < config->num_sec_device_types; i++) {
1220 buf = wps_dev_type_bin2str(config->sec_device_type[i],
1221 _buf, sizeof(_buf));
1222 if (buf)
1223 fprintf(f, "sec_device_type=%s\n", buf);
1224 }
1225 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 if (config->p2p_listen_reg_class)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001227 fprintf(f, "p2p_listen_reg_class=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228 config->p2p_listen_reg_class);
1229 if (config->p2p_listen_channel)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001230 fprintf(f, "p2p_listen_channel=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 config->p2p_listen_channel);
1232 if (config->p2p_oper_reg_class)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001233 fprintf(f, "p2p_oper_reg_class=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 config->p2p_oper_reg_class);
1235 if (config->p2p_oper_channel)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001236 fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001238 fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 if (config->p2p_ssid_postfix)
1240 fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix);
1241 if (config->persistent_reconnect)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001242 fprintf(f, "persistent_reconnect=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 config->persistent_reconnect);
1244 if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001245 fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 if (config->p2p_group_idle)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001247 fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001248 if (config->p2p_passphrase_len)
1249 fprintf(f, "p2p_passphrase_len=%u\n",
1250 config->p2p_passphrase_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001251 if (config->p2p_pref_chan) {
1252 unsigned int i;
1253 fprintf(f, "p2p_pref_chan=");
1254 for (i = 0; i < config->num_p2p_pref_chan; i++) {
1255 fprintf(f, "%s%u:%u", i > 0 ? "," : "",
1256 config->p2p_pref_chan[i].op_class,
1257 config->p2p_pref_chan[i].chan);
1258 }
1259 fprintf(f, "\n");
1260 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001261 if (config->p2p_no_go_freq.num) {
1262 char *val = freq_range_list_str(&config->p2p_no_go_freq);
1263 if (val) {
1264 fprintf(f, "p2p_no_go_freq=%s\n", val);
1265 os_free(val);
1266 }
1267 }
1268 if (config->p2p_add_cli_chan)
1269 fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan);
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001270 if (config->p2p_optimize_listen_chan !=
1271 DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN)
1272 fprintf(f, "p2p_optimize_listen_chan=%d\n",
1273 config->p2p_optimize_listen_chan);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001274 if (config->p2p_go_ht40)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001275 fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001276 if (config->p2p_go_vht)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001277 fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht);
Hai Shalom74f70d42019-02-11 14:42:39 -08001278 if (config->p2p_go_he)
1279 fprintf(f, "p2p_go_he=%d\n", config->p2p_go_he);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001280 if (config->p2p_go_edmg)
1281 fprintf(f, "p2p_go_edmg=%d\n", config->p2p_go_edmg);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001282 if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001283 fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001284 if (config->p2p_disabled)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001285 fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001286 if (config->p2p_no_group_iface)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001287 fprintf(f, "p2p_no_group_iface=%d\n",
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001288 config->p2p_no_group_iface);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001289 if (config->p2p_ignore_shared_freq)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001290 fprintf(f, "p2p_ignore_shared_freq=%d\n",
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001291 config->p2p_ignore_shared_freq);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001292 if (config->p2p_cli_probe)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001293 fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001294 if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE)
1295 fprintf(f, "p2p_go_freq_change_policy=%u\n",
1296 config->p2p_go_freq_change_policy);
Hai Shalom899fcc72020-10-19 14:38:18 -07001297
1298 if (config->p2p_6ghz_disable)
1299 fprintf(f, "p2p_6ghz_disable=%d\n", config->p2p_6ghz_disable);
1300
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001301 if (WPA_GET_BE32(config->ip_addr_go))
1302 fprintf(f, "ip_addr_go=%u.%u.%u.%u\n",
1303 config->ip_addr_go[0], config->ip_addr_go[1],
1304 config->ip_addr_go[2], config->ip_addr_go[3]);
1305 if (WPA_GET_BE32(config->ip_addr_mask))
1306 fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n",
1307 config->ip_addr_mask[0], config->ip_addr_mask[1],
1308 config->ip_addr_mask[2], config->ip_addr_mask[3]);
1309 if (WPA_GET_BE32(config->ip_addr_start))
1310 fprintf(f, "ip_addr_start=%u.%u.%u.%u\n",
1311 config->ip_addr_start[0], config->ip_addr_start[1],
1312 config->ip_addr_start[2], config->ip_addr_start[3]);
1313 if (WPA_GET_BE32(config->ip_addr_end))
1314 fprintf(f, "ip_addr_end=%u.%u.%u.%u\n",
1315 config->ip_addr_end[0], config->ip_addr_end[1],
1316 config->ip_addr_end[2], config->ip_addr_end[3]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001317#endif /* CONFIG_P2P */
1318 if (config->country[0] && config->country[1]) {
1319 fprintf(f, "country=%c%c\n",
1320 config->country[0], config->country[1]);
1321 }
1322 if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
1323 fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
1324 if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE)
1325 fprintf(f, "bss_expiration_age=%u\n",
1326 config->bss_expiration_age);
1327 if (config->bss_expiration_scan_count !=
1328 DEFAULT_BSS_EXPIRATION_SCAN_COUNT)
1329 fprintf(f, "bss_expiration_scan_count=%u\n",
1330 config->bss_expiration_scan_count);
1331 if (config->filter_ssids)
1332 fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
Paul Stewart092955c2017-02-06 09:13:09 -08001333 if (config->filter_rssi)
1334 fprintf(f, "filter_rssi=%d\n", config->filter_rssi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001335 if (config->max_num_sta != DEFAULT_MAX_NUM_STA)
1336 fprintf(f, "max_num_sta=%u\n", config->max_num_sta);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001337 if (config->ap_isolate != DEFAULT_AP_ISOLATE)
1338 fprintf(f, "ap_isolate=%u\n", config->ap_isolate);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001339 if (config->disassoc_low_ack)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001340 fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001341#ifdef CONFIG_HS20
1342 if (config->hs20)
1343 fprintf(f, "hs20=1\n");
1344#endif /* CONFIG_HS20 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001345#ifdef CONFIG_INTERWORKING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001346 if (config->interworking)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001347 fprintf(f, "interworking=%d\n", config->interworking);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001348 if (!is_zero_ether_addr(config->hessid))
1349 fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid));
1350 if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE)
1351 fprintf(f, "access_network_type=%d\n",
1352 config->access_network_type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001353 if (config->go_interworking)
1354 fprintf(f, "go_interworking=%d\n", config->go_interworking);
1355 if (config->go_access_network_type)
1356 fprintf(f, "go_access_network_type=%d\n",
1357 config->go_access_network_type);
1358 if (config->go_internet)
1359 fprintf(f, "go_internet=%d\n", config->go_internet);
1360 if (config->go_venue_group)
1361 fprintf(f, "go_venue_group=%d\n", config->go_venue_group);
1362 if (config->go_venue_type)
1363 fprintf(f, "go_venue_type=%d\n", config->go_venue_type);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001364#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001365 if (config->pbc_in_m1)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001366 fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001367 if (config->wps_nfc_pw_from_config) {
1368 if (config->wps_nfc_dev_pw_id)
1369 fprintf(f, "wps_nfc_dev_pw_id=%d\n",
1370 config->wps_nfc_dev_pw_id);
1371 write_global_bin(f, "wps_nfc_dh_pubkey",
1372 config->wps_nfc_dh_pubkey);
1373 write_global_bin(f, "wps_nfc_dh_privkey",
1374 config->wps_nfc_dh_privkey);
1375 write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw);
1376 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001377
1378 if (config->ext_password_backend)
1379 fprintf(f, "ext_password_backend=%s\n",
1380 config->ext_password_backend);
1381 if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY)
1382 fprintf(f, "p2p_go_max_inactivity=%d\n",
1383 config->p2p_go_max_inactivity);
1384 if (config->auto_interworking)
1385 fprintf(f, "auto_interworking=%d\n",
1386 config->auto_interworking);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001387 if (config->okc)
1388 fprintf(f, "okc=%d\n", config->okc);
1389 if (config->pmf)
1390 fprintf(f, "pmf=%d\n", config->pmf);
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08001391 if (config->dtim_period)
1392 fprintf(f, "dtim_period=%d\n", config->dtim_period);
1393 if (config->beacon_int)
1394 fprintf(f, "beacon_int=%d\n", config->beacon_int);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001395
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001396 if (config->sae_check_mfp)
1397 fprintf(f, "sae_check_mfp=%d\n", config->sae_check_mfp);
1398
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001399 if (config->sae_groups) {
1400 int i;
1401 fprintf(f, "sae_groups=");
Paul Stewart092955c2017-02-06 09:13:09 -08001402 for (i = 0; config->sae_groups[i] > 0; i++) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001403 fprintf(f, "%s%d", i > 0 ? " " : "",
1404 config->sae_groups[i]);
1405 }
1406 fprintf(f, "\n");
1407 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001408
Hai Shalomc3565922019-10-28 11:58:20 -07001409 if (config->sae_pwe)
1410 fprintf(f, "sae_pwe=%d\n", config->sae_pwe);
1411
1412 if (config->sae_pmkid_in_assoc)
1413 fprintf(f, "sae_pmkid_in_assoc=%d\n",
1414 config->sae_pmkid_in_assoc);
1415
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001416 if (config->ap_vendor_elements) {
1417 int i, len = wpabuf_len(config->ap_vendor_elements);
1418 const u8 *p = wpabuf_head_u8(config->ap_vendor_elements);
1419 if (len > 0) {
1420 fprintf(f, "ap_vendor_elements=");
1421 for (i = 0; i < len; i++)
1422 fprintf(f, "%02x", *p++);
1423 fprintf(f, "\n");
1424 }
1425 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001426
Hai Shaloma20dcd72022-02-04 13:43:00 -08001427 if (config->ap_assocresp_elements) {
1428 int i, len = wpabuf_len(config->ap_assocresp_elements);
1429 const u8 *p = wpabuf_head_u8(config->ap_assocresp_elements);
1430
1431 if (len > 0) {
1432 fprintf(f, "ap_assocresp_elements=");
1433 for (i = 0; i < len; i++)
1434 fprintf(f, "%02x", *p++);
1435 fprintf(f, "\n");
1436 }
1437 }
1438
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001439 if (config->ignore_old_scan_res)
1440 fprintf(f, "ignore_old_scan_res=%d\n",
1441 config->ignore_old_scan_res);
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001442
1443 if (config->freq_list && config->freq_list[0]) {
1444 int i;
1445 fprintf(f, "freq_list=");
1446 for (i = 0; config->freq_list[i]; i++) {
Dmitry Shmidt41712582015-06-29 11:02:15 -07001447 fprintf(f, "%s%d", i > 0 ? " " : "",
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001448 config->freq_list[i]);
1449 }
1450 fprintf(f, "\n");
1451 }
Hai Shalom60840252021-02-19 19:02:11 -08001452 if (config->initial_freq_list && config->initial_freq_list[0]) {
1453 int i;
1454 fprintf(f, "initial_freq_list=");
1455 for (i = 0; config->initial_freq_list[i]; i++) {
1456 fprintf(f, "%s%d", i > 0 ? " " : "",
1457 config->initial_freq_list[i]);
1458 }
1459 fprintf(f, "\n");
1460 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07001461 if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ)
1462 fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq);
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001463
Hai Shalom60840252021-02-19 19:02:11 -08001464 if (config->scan_res_valid_for_connect !=
1465 DEFAULT_SCAN_RES_VALID_FOR_CONNECT)
1466 fprintf(f, "scan_res_valid_for_connect=%d\n",
1467 config->scan_res_valid_for_connect);
1468
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001469 if (config->sched_scan_interval)
1470 fprintf(f, "sched_scan_interval=%u\n",
1471 config->sched_scan_interval);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001472
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001473 if (config->sched_scan_start_delay)
1474 fprintf(f, "sched_scan_start_delay=%u\n",
1475 config->sched_scan_start_delay);
1476
Dmitry Shmidt051af732013-10-22 13:52:46 -07001477 if (config->external_sim)
1478 fprintf(f, "external_sim=%d\n", config->external_sim);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001479
1480 if (config->tdls_external_control)
1481 fprintf(f, "tdls_external_control=%d\n",
1482 config->tdls_external_control);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001483
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07001484 if (config->wowlan_triggers)
Dmitry Shmidt03658832014-08-13 11:03:49 -07001485 fprintf(f, "wowlan_triggers=%s\n",
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07001486 config->wowlan_triggers);
1487
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001488 if (config->bgscan)
1489 fprintf(f, "bgscan=\"%s\"\n", config->bgscan);
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001490
Paul Stewart092955c2017-02-06 09:13:09 -08001491 if (config->autoscan)
1492 fprintf(f, "autoscan=%s\n", config->autoscan);
1493
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001494 if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY)
1495 fprintf(f, "p2p_search_delay=%u\n",
1496 config->p2p_search_delay);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001497
1498 if (config->mac_addr)
1499 fprintf(f, "mac_addr=%d\n", config->mac_addr);
1500
1501 if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1502 fprintf(f, "rand_addr_lifetime=%u\n",
1503 config->rand_addr_lifetime);
1504
1505 if (config->preassoc_mac_addr)
1506 fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001507
1508 if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001509 fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001510
1511 if (config->user_mpm != DEFAULT_USER_MPM)
1512 fprintf(f, "user_mpm=%d\n", config->user_mpm);
1513
1514 if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS)
1515 fprintf(f, "max_peer_links=%d\n", config->max_peer_links);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001516
1517 if (config->cert_in_cb != DEFAULT_CERT_IN_CB)
1518 fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb);
1519
1520 if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY)
1521 fprintf(f, "mesh_max_inactivity=%d\n",
1522 config->mesh_max_inactivity);
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001523
Hai Shaloma20dcd72022-02-04 13:43:00 -08001524 if (config->mesh_fwding != DEFAULT_MESH_FWDING)
1525 fprintf(f, "mesh_fwding=%d\n", config->mesh_fwding);
1526
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001527 if (config->dot11RSNASAERetransPeriod !=
1528 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD)
1529 fprintf(f, "dot11RSNASAERetransPeriod=%d\n",
1530 config->dot11RSNASAERetransPeriod);
1531
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001532 if (config->passive_scan)
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001533 fprintf(f, "passive_scan=%d\n", config->passive_scan);
1534
1535 if (config->reassoc_same_bss_optim)
1536 fprintf(f, "reassoc_same_bss_optim=%d\n",
1537 config->reassoc_same_bss_optim);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001538
1539 if (config->wps_priority)
1540 fprintf(f, "wps_priority=%d\n", config->wps_priority);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001541
1542 if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION)
1543 fprintf(f, "wpa_rsc_relaxation=%d\n",
1544 config->wpa_rsc_relaxation);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001545
1546 if (config->sched_scan_plans)
1547 fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001548
1549#ifdef CONFIG_MBO
1550 if (config->non_pref_chan)
1551 fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan);
1552 if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA)
1553 fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001554 if (config->disassoc_imminent_rssi_threshold !=
1555 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD)
1556 fprintf(f, "disassoc_imminent_rssi_threshold=%d\n",
1557 config->disassoc_imminent_rssi_threshold);
1558 if (config->oce != DEFAULT_OCE_SUPPORT)
1559 fprintf(f, "oce=%u\n", config->oce);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001560#endif /* CONFIG_MBO */
1561
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001562 if (config->gas_address3)
1563 fprintf(f, "gas_address3=%d\n", config->gas_address3);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001564
1565 if (config->ftm_responder)
1566 fprintf(f, "ftm_responder=%d\n", config->ftm_responder);
1567 if (config->ftm_initiator)
1568 fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator);
Paul Stewart092955c2017-02-06 09:13:09 -08001569
1570 if (config->osu_dir)
1571 fprintf(f, "osu_dir=%s\n", config->osu_dir);
1572
1573 if (config->fst_group_id)
1574 fprintf(f, "fst_group_id=%s\n", config->fst_group_id);
1575 if (config->fst_priority)
1576 fprintf(f, "fst_priority=%d\n", config->fst_priority);
1577 if (config->fst_llt)
1578 fprintf(f, "fst_llt=%d\n", config->fst_llt);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001579
1580 if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1581 fprintf(f, "gas_rand_addr_lifetime=%u\n",
1582 config->gas_rand_addr_lifetime);
1583 if (config->gas_rand_mac_addr)
1584 fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001585 if (config->dpp_config_processing)
1586 fprintf(f, "dpp_config_processing=%d\n",
1587 config->dpp_config_processing);
Sunil Ravi89eba102022-09-13 21:04:37 -07001588 if (config->dpp_name)
1589 fprintf(f, "dpp_name=%s\n", config->dpp_name);
1590 if (config->dpp_mud_url)
1591 fprintf(f, "dpp_mud_url=%s\n", config->dpp_mud_url);
1592 if (config->dpp_extra_conf_req_name)
1593 fprintf(f, "dpp_extra_conf_req_name=%s\n",
1594 config->dpp_extra_conf_req_name);
1595 if (config->dpp_extra_conf_req_value)
1596 fprintf(f, "dpp_extra_conf_req_value=%s\n",
1597 config->dpp_extra_conf_req_value);
1598 if (config->dpp_connector_privacy_default)
1599 fprintf(f, "dpp_connector_privacy_default=%d\n",
1600 config->dpp_connector_privacy_default);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001601 if (config->coloc_intf_reporting)
1602 fprintf(f, "coloc_intf_reporting=%d\n",
1603 config->coloc_intf_reporting);
Jimmy Chenf887c7b2018-11-13 15:19:57 +08001604 if (config->p2p_device_random_mac_addr)
1605 fprintf(f, "p2p_device_random_mac_addr=%d\n",
1606 config->p2p_device_random_mac_addr);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001607 if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr))
1608 fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n",
1609 MAC2STR(config->p2p_device_persistent_mac_addr));
Jimmy Chen36c21992018-11-29 16:46:43 +08001610 if (config->p2p_interface_random_mac_addr)
1611 fprintf(f, "p2p_interface_random_mac_addr=%d\n",
1612 config->p2p_interface_random_mac_addr);
Jimmy Chen0bb4f862019-03-21 18:41:47 +08001613 if (config->bss_no_flush_when_down)
1614 fprintf(f, "bss_no_flush_when_down=%d\n",
1615 config->bss_no_flush_when_down);
Hai Shalom81f62d82019-07-22 12:10:00 -07001616 if (config->disable_btm)
1617 fprintf(f, "disable_btm=1\n");
Hai Shalomfdcde762020-04-02 11:19:20 -07001618 if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID)
1619 fprintf(f, "extended_key_id=%d\n",
1620 config->extended_key_id);
Hai Shalom60840252021-02-19 19:02:11 -08001621 if (config->wowlan_disconnect_on_deinit)
1622 fprintf(f, "wowlan_disconnect_on_deinit=%d\n",
1623 config->wowlan_disconnect_on_deinit);
Sunil Ravi7f769292024-07-23 22:21:32 +00001624 if (config->rsn_overriding)
1625 fprintf(f, "rsn_overriding=%d\n", config->rsn_overriding);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001626#ifdef CONFIG_TESTING_OPTIONS
1627 if (config->mld_force_single_link)
1628 fprintf(f, "mld_force_single_link=1\n");
1629 if (config->mld_connect_band_pref != MLD_CONNECT_BAND_PREF_AUTO)
1630 fprintf(f, "mld_connect_band_pref=%d\n",
1631 config->mld_connect_band_pref);
1632 if (!is_zero_ether_addr(config->mld_connect_bssid_pref))
1633 fprintf(f, "mld_connect_bssid_pref=" MACSTR "\n",
1634 MAC2STR(config->mld_connect_bssid_pref));
1635#endif /* CONFIG_TESTING_OPTIONS */
1636 if (config->ft_prepend_pmkid)
Sunil Ravic0f5d412024-09-11 22:12:49 +00001637 fprintf(f, "ft_prepend_pmkid=%d\n", config->ft_prepend_pmkid);
1638 if (config->dik) {
1639 fprintf(f, "dik_cipher=%d\n", config->dik_cipher);
1640 write_global_bin(f, "dik", config->dik);
1641 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642}
1643
1644#endif /* CONFIG_NO_CONFIG_WRITE */
1645
1646
1647int wpa_config_write(const char *name, struct wpa_config *config)
1648{
1649#ifndef CONFIG_NO_CONFIG_WRITE
1650 FILE *f;
1651 struct wpa_ssid *ssid;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001652 struct wpa_cred *cred;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653#ifndef CONFIG_NO_CONFIG_BLOBS
1654 struct wpa_config_blob *blob;
1655#endif /* CONFIG_NO_CONFIG_BLOBS */
1656 int ret = 0;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001657 const char *orig_name = name;
Hai Shalomfdcde762020-04-02 11:19:20 -07001658 int tmp_len;
1659 char *tmp_name;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Hai Shalomfdcde762020-04-02 11:19:20 -07001661 if (!name) {
1662 wpa_printf(MSG_ERROR, "No configuration file for writing");
1663 return -1;
1664 }
1665
1666 tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
1667 tmp_name = os_malloc(tmp_len);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001668 if (tmp_name) {
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001669 os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001670 name = tmp_name;
1671 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001673 wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001674
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001675 f = fopen(name, "w");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001676 if (f == NULL) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001677 wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
1678 os_free(tmp_name);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679 return -1;
1680 }
1681
1682 wpa_config_write_global(f, config);
1683
Dmitry Shmidt04949592012-07-19 12:16:46 -07001684 for (cred = config->cred; cred; cred = cred->next) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001685 if (cred->temporary)
1686 continue;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001687 fprintf(f, "\ncred={\n");
1688 wpa_config_write_cred(f, cred);
1689 fprintf(f, "}\n");
1690 }
1691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692 for (ssid = config->ssid; ssid; ssid = ssid->next) {
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001693 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary ||
1694 ssid->ro)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 continue; /* do not save temporary networks */
Hai Shalomfdcde762020-04-02 11:19:20 -07001696 if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt) &&
1697 !ssid->psk_set && !ssid->passphrase)
1698 continue; /* do not save invalid network */
1699 if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
1700 !ssid->passphrase && !ssid->sae_password)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001701 continue; /* do not save invalid network */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 fprintf(f, "\nnetwork={\n");
1703 wpa_config_write_network(f, ssid);
1704 fprintf(f, "}\n");
1705 }
1706
1707#ifndef CONFIG_NO_CONFIG_BLOBS
1708 for (blob = config->blobs; blob; blob = blob->next) {
1709 ret = wpa_config_write_blob(f, blob);
1710 if (ret)
1711 break;
1712 }
1713#endif /* CONFIG_NO_CONFIG_BLOBS */
1714
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001715 os_fdatasync(f);
Mitchell Wills447c7ff2015-08-24 17:24:30 -07001716
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717 fclose(f);
1718
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001719 if (tmp_name) {
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001720 int chmod_ret = 0;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001721
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001722#ifdef ANDROID
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001723 chmod_ret = chmod(tmp_name,
1724 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
1725#endif /* ANDROID */
1726 if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0)
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001727 ret = -1;
1728
1729 os_free(tmp_name);
1730 }
1731
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732 wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001733 orig_name, ret ? "un" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734 return ret;
1735#else /* CONFIG_NO_CONFIG_WRITE */
1736 return -1;
1737#endif /* CONFIG_NO_CONFIG_WRITE */
1738}