blob: 4029d4909797aba715a98b4196e0d620dfc0c977 [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 Ravi79e6c4f2025-01-04 00:47:06 +0000299static struct wpa_dev_ik * wpa_config_read_identity(FILE *f, int *line, int id)
300{
301 struct wpa_dev_ik *identity;
302 int errors = 0, end = 0;
303 char buf[256], *pos, *pos2;
304
305 wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new identity block",
306 *line);
307 identity = os_zalloc(sizeof(*identity));
308 if (!identity)
309 return NULL;
310 identity->id = id;
311
312 while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
313 if (os_strcmp(pos, "}") == 0) {
314 end = 1;
315 break;
316 }
317
318 pos2 = os_strchr(pos, '=');
319 if (!pos2) {
320 wpa_printf(MSG_ERROR,
321 "Line %d: Invalid identity line '%s'.",
322 *line, pos);
323 errors++;
324 continue;
325 }
326
327 *pos2++ = '\0';
328 if (*pos2 == '"') {
329 if (os_strchr(pos2 + 1, '"') == NULL) {
330 wpa_printf(MSG_ERROR,
331 "Line %d: invalid quotation '%s'.",
332 *line, pos2);
333 errors++;
334 continue;
335 }
336 }
337
338 if (wpa_config_set_identity(identity, pos, pos2, *line) < 0)
339 errors++;
340 }
341
342 if (!end) {
343 wpa_printf(MSG_ERROR,
344 "Line %d: identity block was not terminated properly.",
345 *line);
346 errors++;
347 }
348
349 if (errors) {
350 wpa_config_free_identity(identity);
351 identity = NULL;
352 }
353
354 return identity;
355}
356
357
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000358struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
359 bool ro)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360{
361 FILE *f;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700362 char buf[512], *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 int errors = 0, line = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700364 struct wpa_ssid *ssid, *tail, *head;
365 struct wpa_cred *cred, *cred_tail, *cred_head;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000366 struct wpa_dev_ik *identity, *identity_tail, *identity_head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367 struct wpa_config *config;
Sunil Ravia04bd252022-05-02 22:54:18 -0700368 static int id = 0;
369 static int cred_id = 0;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000370 static int identity_id = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371
Dmitry Shmidt64f47c52013-04-16 10:41:54 -0700372 if (name == NULL)
373 return NULL;
374 if (cfgp)
375 config = cfgp;
376 else
377 config = wpa_config_alloc_empty(NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700378 if (config == NULL) {
379 wpa_printf(MSG_ERROR, "Failed to allocate config file "
380 "structure");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 return NULL;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700382 }
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700383 tail = head = config->ssid;
384 while (tail && tail->next)
385 tail = tail->next;
386 cred_tail = cred_head = config->cred;
387 while (cred_tail && cred_tail->next)
388 cred_tail = cred_tail->next;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000389 identity_tail = identity_head = config->identity;
390 while (identity_tail && identity_tail->next)
391 identity_tail = identity_tail->next;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700392
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393 wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
394 f = fopen(name, "r");
395 if (f == NULL) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700396 wpa_printf(MSG_ERROR, "Failed to open config file '%s', "
397 "error: %s", name, strerror(errno));
Dmitry Shmidte3d76d92018-02-01 00:34:54 +0000398 if (config != cfgp)
399 os_free(config);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 return NULL;
401 }
402
403 while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
404 if (os_strcmp(pos, "network={") == 0) {
405 ssid = wpa_config_read_network(f, &line, id++);
406 if (ssid == NULL) {
407 wpa_printf(MSG_ERROR, "Line %d: failed to "
408 "parse network block.", line);
409 errors++;
410 continue;
411 }
Sunil Raviaf8751c2023-03-29 11:35:17 -0700412 ssid->ro = ro;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 if (head == NULL) {
414 head = tail = ssid;
415 } else {
416 tail->next = ssid;
417 tail = ssid;
418 }
419 if (wpa_config_add_prio_network(config, ssid)) {
420 wpa_printf(MSG_ERROR, "Line %d: failed to add "
421 "network block to priority list.",
422 line);
423 errors++;
424 continue;
425 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700426 } else if (os_strcmp(pos, "cred={") == 0) {
427 cred = wpa_config_read_cred(f, &line, cred_id++);
428 if (cred == NULL) {
429 wpa_printf(MSG_ERROR, "Line %d: failed to "
430 "parse cred block.", line);
431 errors++;
432 continue;
433 }
434 if (cred_head == NULL) {
435 cred_head = cred_tail = cred;
436 } else {
437 cred_tail->next = cred;
438 cred_tail = cred;
439 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440#ifndef CONFIG_NO_CONFIG_BLOBS
441 } else if (os_strncmp(pos, "blob-base64-", 12) == 0) {
442 if (wpa_config_process_blob(config, f, &line, pos + 12)
443 < 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700444 wpa_printf(MSG_ERROR, "Line %d: failed to "
445 "process blob.", line);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 errors++;
447 continue;
448 }
449#endif /* CONFIG_NO_CONFIG_BLOBS */
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000450 } else if (os_strcmp(pos, "identity={") == 0) {
451 identity = wpa_config_read_identity(f, &line,
452 identity_id++);
453 if (!identity) {
454 wpa_printf(MSG_ERROR,
455 "Line %d: failed to parse identity block.",
456 line);
457 errors++;
458 continue;
459 }
460 if (!identity_head) {
461 identity_head = identity_tail = identity;
462 } else {
463 identity_tail->next = identity;
464 identity_tail = identity;
465 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 } else if (wpa_config_process_global(config, pos, line) < 0) {
467 wpa_printf(MSG_ERROR, "Line %d: Invalid configuration "
468 "line '%s'.", line, pos);
469 errors++;
470 continue;
471 }
472 }
473
474 fclose(f);
475
Iliyan Malchev97d98062013-04-23 02:37:51 +0000476 config->ssid = head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 wpa_config_debug_dump_networks(config);
Iliyan Malchev97d98062013-04-23 02:37:51 +0000478 config->cred = cred_head;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000479 config->identity = identity_head;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480
481#ifndef WPA_IGNORE_CONFIG_ERRORS
482 if (errors) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700483 if (config != cfgp)
484 wpa_config_free(config);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 config = NULL;
486 head = NULL;
487 }
488#endif /* WPA_IGNORE_CONFIG_ERRORS */
489
490 return config;
491}
492
493
494#ifndef CONFIG_NO_CONFIG_WRITE
495
496static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid)
497{
498 char *value = wpa_config_get(ssid, field);
499 if (value == NULL)
500 return;
501 fprintf(f, "\t%s=%s\n", field, value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800502 str_clear_free(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503}
504
505
506static void write_int(FILE *f, const char *field, int value, int def)
507{
508 if (value == def)
509 return;
510 fprintf(f, "\t%s=%d\n", field, value);
511}
512
513
514static void write_bssid(FILE *f, struct wpa_ssid *ssid)
515{
516 char *value = wpa_config_get(ssid, "bssid");
517 if (value == NULL)
518 return;
519 fprintf(f, "\tbssid=%s\n", value);
520 os_free(value);
521}
522
523
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700524static void write_bssid_hint(FILE *f, struct wpa_ssid *ssid)
525{
526 char *value = wpa_config_get(ssid, "bssid_hint");
527
528 if (!value)
529 return;
530 fprintf(f, "\tbssid_hint=%s\n", value);
531 os_free(value);
532}
533
534
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535static void write_psk(FILE *f, struct wpa_ssid *ssid)
536{
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700537 char *value;
538
539 if (ssid->mem_only_psk)
540 return;
541
542 value = wpa_config_get(ssid, "psk");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 if (value == NULL)
544 return;
545 fprintf(f, "\tpsk=%s\n", value);
546 os_free(value);
547}
548
549
550static void write_proto(FILE *f, struct wpa_ssid *ssid)
551{
552 char *value;
553
554 if (ssid->proto == DEFAULT_PROTO)
555 return;
556
557 value = wpa_config_get(ssid, "proto");
558 if (value == NULL)
559 return;
560 if (value[0])
561 fprintf(f, "\tproto=%s\n", value);
562 os_free(value);
563}
564
565
566static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid)
567{
568 char *value;
569
570 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
571 return;
572
573 value = wpa_config_get(ssid, "key_mgmt");
574 if (value == NULL)
575 return;
576 if (value[0])
577 fprintf(f, "\tkey_mgmt=%s\n", value);
578 os_free(value);
579}
580
581
582static void write_pairwise(FILE *f, struct wpa_ssid *ssid)
583{
584 char *value;
585
586 if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
587 return;
588
589 value = wpa_config_get(ssid, "pairwise");
590 if (value == NULL)
591 return;
592 if (value[0])
593 fprintf(f, "\tpairwise=%s\n", value);
594 os_free(value);
595}
596
597
598static void write_group(FILE *f, struct wpa_ssid *ssid)
599{
600 char *value;
601
602 if (ssid->group_cipher == DEFAULT_GROUP)
603 return;
604
605 value = wpa_config_get(ssid, "group");
606 if (value == NULL)
607 return;
608 if (value[0])
609 fprintf(f, "\tgroup=%s\n", value);
610 os_free(value);
611}
612
613
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700614static void write_group_mgmt(FILE *f, struct wpa_ssid *ssid)
615{
616 char *value;
617
618 if (!ssid->group_mgmt_cipher)
619 return;
620
621 value = wpa_config_get(ssid, "group_mgmt");
622 if (!value)
623 return;
624 if (value[0])
625 fprintf(f, "\tgroup_mgmt=%s\n", value);
626 os_free(value);
627}
628
629
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630static void write_auth_alg(FILE *f, struct wpa_ssid *ssid)
631{
632 char *value;
633
634 if (ssid->auth_alg == 0)
635 return;
636
637 value = wpa_config_get(ssid, "auth_alg");
638 if (value == NULL)
639 return;
640 if (value[0])
641 fprintf(f, "\tauth_alg=%s\n", value);
642 os_free(value);
643}
644
645
646#ifdef IEEE8021X_EAPOL
647static void write_eap(FILE *f, struct wpa_ssid *ssid)
648{
649 char *value;
650
651 value = wpa_config_get(ssid, "eap");
652 if (value == NULL)
653 return;
654
655 if (value[0])
656 fprintf(f, "\teap=%s\n", value);
657 os_free(value);
658}
659#endif /* IEEE8021X_EAPOL */
660
661
Hai Shalomfdcde762020-04-02 11:19:20 -0700662#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
664{
665 char field[20], *value;
666 int res;
667
668 res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800669 if (os_snprintf_error(sizeof(field), res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 return;
671 value = wpa_config_get(ssid, field);
672 if (value) {
673 fprintf(f, "\t%s=%s\n", field, value);
674 os_free(value);
675 }
676}
Hai Shalomfdcde762020-04-02 11:19:20 -0700677#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678
679
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800680#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700681
Dmitry Shmidt54605472013-11-08 11:10:19 -0800682static void write_go_p2p_dev_addr(FILE *f, struct wpa_ssid *ssid)
683{
684 char *value = wpa_config_get(ssid, "go_p2p_dev_addr");
685 if (value == NULL)
686 return;
687 fprintf(f, "\tgo_p2p_dev_addr=%s\n", value);
688 os_free(value);
689}
690
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800691static void write_p2p_client_list(FILE *f, struct wpa_ssid *ssid)
692{
693 char *value = wpa_config_get(ssid, "p2p_client_list");
694 if (value == NULL)
695 return;
696 fprintf(f, "\tp2p_client_list=%s\n", value);
697 os_free(value);
698}
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700699
700
701static void write_psk_list(FILE *f, struct wpa_ssid *ssid)
702{
703 struct psk_list_entry *psk;
704 char hex[32 * 2 + 1];
705
706 dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) {
707 wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk));
708 fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n",
709 psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex);
710 }
711}
712
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800713#endif /* CONFIG_P2P */
714
715
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716#ifdef CONFIG_MACSEC
717
718static void write_mka_cak(FILE *f, struct wpa_ssid *ssid)
719{
720 char *value;
721
722 if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK))
723 return;
724
725 value = wpa_config_get(ssid, "mka_cak");
726 if (!value)
727 return;
728 fprintf(f, "\tmka_cak=%s\n", value);
729 os_free(value);
730}
731
732
733static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid)
734{
735 char *value;
736
737 if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN))
738 return;
739
740 value = wpa_config_get(ssid, "mka_ckn");
741 if (!value)
742 return;
743 fprintf(f, "\tmka_ckn=%s\n", value);
744 os_free(value);
745}
746
747#endif /* CONFIG_MACSEC */
748
749
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
751{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752#define STR(t) write_str(f, #t, ssid)
753#define INT(t) write_int(f, #t, ssid->t, 0)
Hai Shalomc3565922019-10-28 11:58:20 -0700754#define INTe(t, m) write_int(f, #t, ssid->eap.m, 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755#define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
Hai Shalomc3565922019-10-28 11:58:20 -0700756#define INT_DEFe(t, m, def) write_int(f, #t, ssid->eap.m, def)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757
758 STR(ssid);
759 INT(scan_ssid);
760 write_bssid(f, ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700761 write_bssid_hint(f, ssid);
Hai Shalom60840252021-02-19 19:02:11 -0800762 write_str(f, "bssid_ignore", ssid);
763 write_str(f, "bssid_accept", ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 write_psk(f, ssid);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700765 INT(mem_only_psk);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700766 STR(sae_password);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700767 STR(sae_password_id);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800768 write_int(f, "sae_pwe", ssid->sae_pwe, DEFAULT_SAE_PWE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 write_proto(f, ssid);
770 write_key_mgmt(f, ssid);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700771 INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 write_pairwise(f, ssid);
773 write_group(f, ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700774 write_group_mgmt(f, ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 write_auth_alg(f, ssid);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700776 STR(bgscan);
777 STR(autoscan);
Dmitry Shmidt56052862013-10-04 10:23:25 -0700778 STR(scan_freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779#ifdef IEEE8021X_EAPOL
780 write_eap(f, ssid);
781 STR(identity);
782 STR(anonymous_identity);
Jouni Malinena3cb6f02017-12-08 17:05:40 +0200783 STR(imsi_identity);
Hai Shalomc3565922019-10-28 11:58:20 -0700784 STR(machine_identity);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 STR(password);
Hai Shalomc3565922019-10-28 11:58:20 -0700786 STR(machine_password);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 STR(ca_cert);
788 STR(ca_path);
789 STR(client_cert);
790 STR(private_key);
791 STR(private_key_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792 STR(subject_match);
Hai Shalom021b0b52019-04-10 11:17:58 -0700793 STR(check_cert_subject);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 STR(altsubject_match);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700795 STR(domain_suffix_match);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800796 STR(domain_match);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 STR(ca_cert2);
798 STR(ca_path2);
799 STR(client_cert2);
800 STR(private_key2);
801 STR(private_key2_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 STR(subject_match2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700803 STR(check_cert_subject2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 STR(altsubject_match2);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700805 STR(domain_suffix_match2);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800806 STR(domain_match2);
Hai Shalomc3565922019-10-28 11:58:20 -0700807 STR(machine_ca_cert);
808 STR(machine_ca_path);
809 STR(machine_client_cert);
810 STR(machine_private_key);
811 STR(machine_private_key_passwd);
Hai Shalomc3565922019-10-28 11:58:20 -0700812 STR(machine_subject_match);
813 STR(machine_check_cert_subject);
814 STR(machine_altsubject_match);
815 STR(machine_domain_suffix_match);
816 STR(machine_domain_match);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 STR(phase1);
818 STR(phase2);
Hai Shalomc3565922019-10-28 11:58:20 -0700819 STR(machine_phase2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820 STR(pcsc);
821 STR(pin);
822 STR(engine_id);
823 STR(key_id);
824 STR(cert_id);
825 STR(ca_cert_id);
826 STR(key2_id);
827 STR(pin2);
828 STR(engine2_id);
829 STR(cert2_id);
830 STR(ca_cert2_id);
Hai Shalomc3565922019-10-28 11:58:20 -0700831 INTe(engine, cert.engine);
832 INTe(engine2, phase2_cert.engine);
833 INTe(machine_engine, machine_cert.engine);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800835 STR(openssl_ciphers);
Hai Shalomc3565922019-10-28 11:58:20 -0700836 INTe(erp, erp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837#endif /* IEEE8021X_EAPOL */
Hai Shalomfdcde762020-04-02 11:19:20 -0700838#ifdef CONFIG_WEP
839 {
840 int i;
841
842 for (i = 0; i < 4; i++)
843 write_wep_key(f, i, ssid);
844 INT(wep_tx_keyidx);
845 }
846#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 INT(priority);
848#ifdef IEEE8021X_EAPOL
849 INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
850 STR(pac_file);
Hai Shalomc3565922019-10-28 11:58:20 -0700851 INT_DEFe(fragment_size, fragment_size, DEFAULT_FRAGMENT_SIZE);
852 INTe(ocsp, cert.ocsp);
853 INTe(ocsp2, phase2_cert.ocsp);
854 INTe(machine_ocsp, machine_cert.ocsp);
855 INT_DEFe(sim_num, sim_num, DEFAULT_USER_SELECTED_SIM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856#endif /* IEEE8021X_EAPOL */
857 INT(mode);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800858 INT(no_auto_peer);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800859 INT(mesh_fwding);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800860 INT(frequency);
Hai Shalomc3565922019-10-28 11:58:20 -0700861 INT(enable_edmg);
862 INT(edmg_channel);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800863 INT(fixed_freq);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800864#ifdef CONFIG_ACS
865 INT(acs);
866#endif /* CONFIG_ACS */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800867 write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868 INT(disabled);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800869 INT(mixed_cell);
Hai Shalom899fcc72020-10-19 14:38:18 -0700870 INT_DEF(vht, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700871 INT_DEF(ht, 1);
872 INT(ht40);
Hai Shalom899fcc72020-10-19 14:38:18 -0700873 INT_DEF(he, 1);
Hai Shalom74f70d42019-02-11 14:42:39 -0800874 INT_DEF(max_oper_chwidth, DEFAULT_MAX_OPER_CHWIDTH);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700875 INT(vht_center_freq1);
876 INT(vht_center_freq2);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800877 INT(pbss);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700878 INT(wps_disabled);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700879 INT(fils_dh_group);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800880 write_int(f, "ieee80211w", ssid->ieee80211w,
881 MGMT_FRAME_PROTECTION_DEFAULT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 STR(id_str);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800883#ifdef CONFIG_P2P
Dmitry Shmidt54605472013-11-08 11:10:19 -0800884 write_go_p2p_dev_addr(f, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885 write_p2p_client_list(f, ssid);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700886 write_psk_list(f, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800887#endif /* CONFIG_P2P */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800888 INT(ap_max_inactivity);
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800889 INT(dtim_period);
890 INT(beacon_int);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700891#ifdef CONFIG_MACSEC
892 INT(macsec_policy);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800893 write_mka_cak(f, ssid);
894 write_mka_ckn(f, ssid);
895 INT(macsec_integ_only);
Hai Shalom74f70d42019-02-11 14:42:39 -0800896 INT(macsec_replay_protect);
897 INT(macsec_replay_window);
Sunil Raviaf8751c2023-03-29 11:35:17 -0700898 INT(macsec_offload);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800899 INT(macsec_port);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800900 INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER);
Sunil Ravia04bd252022-05-02 22:54:18 -0700901 INT(macsec_csindex);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700902#endif /* CONFIG_MACSEC */
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700903#ifdef CONFIG_HS20
904 INT(update_identifier);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700905 STR(roaming_consortium_selection);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700906#endif /* CONFIG_HS20 */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700907 write_int(f, "mac_addr", ssid->mac_addr, -1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800908#ifdef CONFIG_MESH
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800909 STR(mesh_basic_rates);
910 INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES);
911 INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT);
912 INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT);
913 INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700914 INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800915#endif /* CONFIG_MESH */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800916 INT(wpa_ptk_rekey);
Hai Shalomfdcde762020-04-02 11:19:20 -0700917 INT(wpa_deny_ptk0_rekey);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700918 INT(group_rekey);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800919 INT(ignore_broadcast_ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700920#ifdef CONFIG_DPP
921 STR(dpp_connector);
922 STR(dpp_netaccesskey);
923 INT(dpp_netaccesskey_expiry);
924 STR(dpp_csign);
Hai Shalom899fcc72020-10-19 14:38:18 -0700925 STR(dpp_pp_key);
Hai Shalomfdcde762020-04-02 11:19:20 -0700926 INT(dpp_pfs);
Sunil Ravi89eba102022-09-13 21:04:37 -0700927 INT(dpp_connector_privacy);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700928#endif /* CONFIG_DPP */
929 INT(owe_group);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700930 INT(owe_only);
Hai Shalomfdcde762020-04-02 11:19:20 -0700931 INT(owe_ptk_workaround);
Hai Shalom74f70d42019-02-11 14:42:39 -0800932 INT(multi_ap_backhaul_sta);
Hai Shalom81f62d82019-07-22 12:10:00 -0700933 INT(ft_eap_pmksa_caching);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000934 INT(multi_ap_profile);
Hai Shalomfdcde762020-04-02 11:19:20 -0700935 INT(beacon_prot);
936 INT(transition_disable);
Hai Shalom899fcc72020-10-19 14:38:18 -0700937 INT(sae_pk);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800938#ifdef CONFIG_HT_OVERRIDES
939 INT_DEF(disable_ht, DEFAULT_DISABLE_HT);
940 INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40);
941 INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI);
942 INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC);
943 INT(ht40_intolerant);
Hai Shalom74f70d42019-02-11 14:42:39 -0800944 INT_DEF(tx_stbc, DEFAULT_TX_STBC);
945 INT_DEF(rx_stbc, DEFAULT_RX_STBC);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800946 INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU);
947 INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR);
948 INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY);
949 STR(ht_mcs);
950#endif /* CONFIG_HT_OVERRIDES */
951#ifdef CONFIG_VHT_OVERRIDES
952 INT(disable_vht);
953 INT(vht_capa);
954 INT(vht_capa_mask);
955 INT_DEF(vht_rx_mcs_nss_1, -1);
956 INT_DEF(vht_rx_mcs_nss_2, -1);
957 INT_DEF(vht_rx_mcs_nss_3, -1);
958 INT_DEF(vht_rx_mcs_nss_4, -1);
959 INT_DEF(vht_rx_mcs_nss_5, -1);
960 INT_DEF(vht_rx_mcs_nss_6, -1);
961 INT_DEF(vht_rx_mcs_nss_7, -1);
962 INT_DEF(vht_rx_mcs_nss_8, -1);
963 INT_DEF(vht_tx_mcs_nss_1, -1);
964 INT_DEF(vht_tx_mcs_nss_2, -1);
965 INT_DEF(vht_tx_mcs_nss_3, -1);
966 INT_DEF(vht_tx_mcs_nss_4, -1);
967 INT_DEF(vht_tx_mcs_nss_5, -1);
968 INT_DEF(vht_tx_mcs_nss_6, -1);
969 INT_DEF(vht_tx_mcs_nss_7, -1);
970 INT_DEF(vht_tx_mcs_nss_8, -1);
971#endif /* CONFIG_VHT_OVERRIDES */
Hai Shalomfdcde762020-04-02 11:19:20 -0700972#ifdef CONFIG_HE_OVERRIDES
973 INT(disable_he);
974#endif /* CONFIG_HE_OVERRIDES */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000975 INT(disable_eht);
Sunil Raviaf8751c2023-03-29 11:35:17 -0700976 INT(enable_4addr_mode);
Sunil Ravi7f769292024-07-23 22:21:32 +0000977 INT(max_idle);
978 INT(ssid_protection);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000979 INT_DEF(rsn_overriding, RSN_OVERRIDING_NOT_SET);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980
981#undef STR
982#undef INT
983#undef INT_DEF
984}
985
986
Dmitry Shmidt04949592012-07-19 12:16:46 -0700987static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred)
988{
Dmitry Shmidt051af732013-10-22 13:52:46 -0700989 size_t i;
990
Dmitry Shmidt04949592012-07-19 12:16:46 -0700991 if (cred->priority)
992 fprintf(f, "\tpriority=%d\n", cred->priority);
993 if (cred->pcsc)
994 fprintf(f, "\tpcsc=%d\n", cred->pcsc);
995 if (cred->realm)
996 fprintf(f, "\trealm=\"%s\"\n", cred->realm);
997 if (cred->username)
998 fprintf(f, "\tusername=\"%s\"\n", cred->username);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800999 if (cred->password && cred->ext_password)
1000 fprintf(f, "\tpassword=ext:%s\n", cred->password);
1001 else if (cred->password)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001002 fprintf(f, "\tpassword=\"%s\"\n", cred->password);
1003 if (cred->ca_cert)
1004 fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001005 if (cred->client_cert)
1006 fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert);
1007 if (cred->private_key)
1008 fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key);
1009 if (cred->private_key_passwd)
1010 fprintf(f, "\tprivate_key_passwd=\"%s\"\n",
1011 cred->private_key_passwd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001012 if (cred->imsi)
1013 fprintf(f, "\timsi=\"%s\"\n", cred->imsi);
1014 if (cred->milenage)
1015 fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001016 for (i = 0; i < cred->num_domain; i++)
1017 fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]);
1018 if (cred->domain_suffix_match)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07001019 fprintf(f, "\tdomain_suffix_match=\"%s\"\n",
Dmitry Shmidt051af732013-10-22 13:52:46 -07001020 cred->domain_suffix_match);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001021 if (cred->eap_method) {
1022 const char *name;
1023 name = eap_get_name(cred->eap_method[0].vendor,
1024 cred->eap_method[0].method);
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001025 if (name)
1026 fprintf(f, "\teap=%s\n", name);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001027 }
1028 if (cred->phase1)
1029 fprintf(f, "\tphase1=\"%s\"\n", cred->phase1);
1030 if (cred->phase2)
1031 fprintf(f, "\tphase2=\"%s\"\n", cred->phase2);
1032 if (cred->excluded_ssid) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001033 size_t j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001034 for (i = 0; i < cred->num_excluded_ssid; i++) {
1035 struct excluded_ssid *e = &cred->excluded_ssid[i];
1036 fprintf(f, "\texcluded_ssid=");
1037 for (j = 0; j < e->ssid_len; j++)
1038 fprintf(f, "%02x", e->ssid[j]);
1039 fprintf(f, "\n");
1040 }
1041 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001042 if (cred->roaming_partner) {
1043 for (i = 0; i < cred->num_roaming_partner; i++) {
1044 struct roaming_partner *p = &cred->roaming_partner[i];
1045 fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n",
1046 p->fqdn, p->exact_match, p->priority,
1047 p->country);
1048 }
1049 }
1050 if (cred->update_identifier)
1051 fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier);
1052
1053 if (cred->provisioning_sp)
Dmitry Shmidt61593f02014-04-21 16:27:35 -07001054 fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001055 if (cred->sp_priority)
1056 fprintf(f, "\tsp_priority=%d\n", cred->sp_priority);
1057
1058 if (cred->min_dl_bandwidth_home)
1059 fprintf(f, "\tmin_dl_bandwidth_home=%u\n",
1060 cred->min_dl_bandwidth_home);
1061 if (cred->min_ul_bandwidth_home)
1062 fprintf(f, "\tmin_ul_bandwidth_home=%u\n",
1063 cred->min_ul_bandwidth_home);
1064 if (cred->min_dl_bandwidth_roaming)
1065 fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n",
1066 cred->min_dl_bandwidth_roaming);
1067 if (cred->min_ul_bandwidth_roaming)
1068 fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n",
1069 cred->min_ul_bandwidth_roaming);
1070
1071 if (cred->max_bss_load)
1072 fprintf(f, "\tmax_bss_load=%u\n",
1073 cred->max_bss_load);
1074
1075 if (cred->ocsp)
1076 fprintf(f, "\tocsp=%d\n", cred->ocsp);
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07001077
1078 if (cred->num_req_conn_capab) {
1079 for (i = 0; i < cred->num_req_conn_capab; i++) {
1080 int *ports;
1081
1082 fprintf(f, "\treq_conn_capab=%u",
1083 cred->req_conn_capab_proto[i]);
1084 ports = cred->req_conn_capab_port[i];
1085 if (ports) {
1086 int j;
1087 for (j = 0; ports[j] != -1; j++) {
1088 fprintf(f, "%s%d", j > 0 ? "," : ":",
1089 ports[j]);
1090 }
1091 }
1092 fprintf(f, "\n");
1093 }
1094 }
1095
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001096 if (cred->num_home_ois) {
1097 size_t j;
1098
1099 fprintf(f, "\thome_ois=\"");
1100 for (i = 0; i < cred->num_home_ois; i++) {
1101 if (i > 0)
1102 fprintf(f, ",");
1103 for (j = 0; j < cred->home_ois_len[i]; j++)
1104 fprintf(f, "%02x",
1105 cred->home_ois[i][j]);
1106 }
1107 fprintf(f, "\"\n");
1108 }
1109
1110 if (cred->num_required_home_ois) {
1111 size_t j;
1112
1113 fprintf(f, "\trequired_home_ois=\"");
1114 for (i = 0; i < cred->num_required_home_ois; i++) {
1115 if (i > 0)
1116 fprintf(f, ",");
1117 for (j = 0; j < cred->required_home_ois_len[i]; j++)
1118 fprintf(f, "%02x",
1119 cred->required_home_ois[i][j]);
1120 }
1121 fprintf(f, "\"\n");
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07001122 }
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001123
Roshan Pius3a1667e2018-07-03 15:17:14 -07001124 if (cred->num_roaming_consortiums) {
1125 size_t j;
1126
1127 fprintf(f, "\troaming_consortiums=\"");
1128 for (i = 0; i < cred->num_roaming_consortiums; i++) {
1129 if (i > 0)
1130 fprintf(f, ",");
1131 for (j = 0; j < cred->roaming_consortiums_len[i]; j++)
1132 fprintf(f, "%02x",
1133 cred->roaming_consortiums[i][j]);
1134 }
1135 fprintf(f, "\"\n");
1136 }
1137
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001138 if (cred->sim_num != DEFAULT_USER_SELECTED_SIM)
1139 fprintf(f, "\tsim_num=%d\n", cred->sim_num);
Hai Shaloma20dcd72022-02-04 13:43:00 -08001140
1141 if (cred->engine)
1142 fprintf(f, "\tengine=%d\n", cred->engine);
1143 if (cred->engine_id)
1144 fprintf(f, "\tengine_id=\"%s\"\n", cred->engine_id);
1145 if (cred->key_id)
1146 fprintf(f, "\tkey_id=\"%s\"\n", cred->key_id);
1147 if (cred->cert_id)
1148 fprintf(f, "\tcert_id=\"%s\"\n", cred->cert_id);
1149 if (cred->ca_cert_id)
1150 fprintf(f, "\tca_cert_id=\"%s\"\n", cred->ca_cert_id);
Sunil8cd6f4d2022-06-28 18:40:46 +00001151
1152 if (cred->imsi_privacy_cert)
1153 fprintf(f, "\timsi_privacy_cert=\"%s\"\n",
1154 cred->imsi_privacy_cert);
1155 if (cred->imsi_privacy_attr)
1156 fprintf(f, "\timsi_privacy_attr=\"%s\"\n",
1157 cred->imsi_privacy_attr);
Steven Liu9138d432022-11-23 22:29:05 +00001158 if (cred->strict_conservative_peer_mode)
1159 fprintf(f,"\tstrict_conservative_peer_mode=\"%d\"\n",
1160 cred->strict_conservative_peer_mode);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001161}
1162
1163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164#ifndef CONFIG_NO_CONFIG_BLOBS
1165static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
1166{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001167 char *encoded;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168
1169 encoded = base64_encode(blob->data, blob->len, NULL);
1170 if (encoded == NULL)
1171 return -1;
1172
1173 fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
1174 os_free(encoded);
1175 return 0;
1176}
1177#endif /* CONFIG_NO_CONFIG_BLOBS */
1178
1179
Dmitry Shmidt04949592012-07-19 12:16:46 -07001180static void write_global_bin(FILE *f, const char *field,
1181 const struct wpabuf *val)
1182{
1183 size_t i;
1184 const u8 *pos;
1185
1186 if (val == NULL)
1187 return;
1188
1189 fprintf(f, "%s=", field);
1190 pos = wpabuf_head(val);
1191 for (i = 0; i < wpabuf_len(val); i++)
1192 fprintf(f, "%02X", *pos++);
1193 fprintf(f, "\n");
1194}
1195
1196
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001197static void wpa_config_write_global(FILE *f, struct wpa_config *config)
1198{
1199#ifdef CONFIG_CTRL_IFACE
1200 if (config->ctrl_interface)
1201 fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
1202 if (config->ctrl_interface_group)
1203 fprintf(f, "ctrl_interface_group=%s\n",
1204 config->ctrl_interface_group);
1205#endif /* CONFIG_CTRL_IFACE */
1206 if (config->eapol_version != DEFAULT_EAPOL_VERSION)
1207 fprintf(f, "eapol_version=%d\n", config->eapol_version);
1208 if (config->ap_scan != DEFAULT_AP_SCAN)
1209 fprintf(f, "ap_scan=%d\n", config->ap_scan);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001210 if (config->disable_scan_offload)
1211 fprintf(f, "disable_scan_offload=%d\n",
1212 config->disable_scan_offload);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
1214 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001215#ifndef CONFIG_OPENSC_ENGINE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 if (config->opensc_engine_path)
1217 fprintf(f, "opensc_engine_path=%s\n",
1218 config->opensc_engine_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001219#endif /* CONFIG_OPENSC_ENGINE_PATH */
1220#ifndef CONFIG_PKCS11_ENGINE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221 if (config->pkcs11_engine_path)
1222 fprintf(f, "pkcs11_engine_path=%s\n",
1223 config->pkcs11_engine_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001224#endif /* CONFIG_PKCS11_ENGINE_PATH */
1225#ifndef CONFIG_PKCS11_MODULE_PATH
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 if (config->pkcs11_module_path)
1227 fprintf(f, "pkcs11_module_path=%s\n",
1228 config->pkcs11_module_path);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001229#endif /* CONFIG_PKCS11_MODULE_PATH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001230 if (config->openssl_ciphers)
1231 fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001232 if (config->pcsc_reader)
1233 fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader);
1234 if (config->pcsc_pin)
1235 fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 if (config->driver_param)
1237 fprintf(f, "driver_param=%s\n", config->driver_param);
1238 if (config->dot11RSNAConfigPMKLifetime)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001239 fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 config->dot11RSNAConfigPMKLifetime);
1241 if (config->dot11RSNAConfigPMKReauthThreshold)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001242 fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 config->dot11RSNAConfigPMKReauthThreshold);
1244 if (config->dot11RSNAConfigSATimeout)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001245 fprintf(f, "dot11RSNAConfigSATimeout=%u\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 config->dot11RSNAConfigSATimeout);
1247 if (config->update_config)
1248 fprintf(f, "update_config=%d\n", config->update_config);
1249#ifdef CONFIG_WPS
1250 if (!is_nil_uuid(config->uuid)) {
1251 char buf[40];
1252 uuid_bin2str(config->uuid, buf, sizeof(buf));
1253 fprintf(f, "uuid=%s\n", buf);
1254 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001255 if (config->auto_uuid)
1256 fprintf(f, "auto_uuid=%d\n", config->auto_uuid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257 if (config->device_name)
1258 fprintf(f, "device_name=%s\n", config->device_name);
1259 if (config->manufacturer)
1260 fprintf(f, "manufacturer=%s\n", config->manufacturer);
1261 if (config->model_name)
1262 fprintf(f, "model_name=%s\n", config->model_name);
1263 if (config->model_number)
1264 fprintf(f, "model_number=%s\n", config->model_number);
1265 if (config->serial_number)
1266 fprintf(f, "serial_number=%s\n", config->serial_number);
1267 {
1268 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1269 buf = wps_dev_type_bin2str(config->device_type,
1270 _buf, sizeof(_buf));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001271 if (os_strcmp(buf, "0-00000000-0") != 0)
1272 fprintf(f, "device_type=%s\n", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273 }
1274 if (WPA_GET_BE32(config->os_version))
1275 fprintf(f, "os_version=%08x\n",
1276 WPA_GET_BE32(config->os_version));
1277 if (config->config_methods)
1278 fprintf(f, "config_methods=%s\n", config->config_methods);
1279 if (config->wps_cred_processing)
1280 fprintf(f, "wps_cred_processing=%d\n",
1281 config->wps_cred_processing);
Hai Shalom021b0b52019-04-10 11:17:58 -07001282 if (config->wps_cred_add_sae)
1283 fprintf(f, "wps_cred_add_sae=%d\n",
1284 config->wps_cred_add_sae);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001285 if (config->wps_vendor_ext_m1) {
1286 int i, len = wpabuf_len(config->wps_vendor_ext_m1);
1287 const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1);
1288 if (len > 0) {
1289 fprintf(f, "wps_vendor_ext_m1=");
1290 for (i = 0; i < len; i++)
1291 fprintf(f, "%02x", *p++);
1292 fprintf(f, "\n");
1293 }
1294 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001295#endif /* CONFIG_WPS */
1296#ifdef CONFIG_P2P
Paul Stewart092955c2017-02-06 09:13:09 -08001297 {
1298 int i;
1299 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1300
1301 for (i = 0; i < config->num_sec_device_types; i++) {
1302 buf = wps_dev_type_bin2str(config->sec_device_type[i],
1303 _buf, sizeof(_buf));
1304 if (buf)
1305 fprintf(f, "sec_device_type=%s\n", buf);
1306 }
1307 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 if (config->p2p_listen_reg_class)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001309 fprintf(f, "p2p_listen_reg_class=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001310 config->p2p_listen_reg_class);
1311 if (config->p2p_listen_channel)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001312 fprintf(f, "p2p_listen_channel=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313 config->p2p_listen_channel);
1314 if (config->p2p_oper_reg_class)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001315 fprintf(f, "p2p_oper_reg_class=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316 config->p2p_oper_reg_class);
1317 if (config->p2p_oper_channel)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001318 fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319 if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001320 fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321 if (config->p2p_ssid_postfix)
1322 fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix);
1323 if (config->persistent_reconnect)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001324 fprintf(f, "persistent_reconnect=%d\n",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001325 config->persistent_reconnect);
1326 if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001327 fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001328 if (config->p2p_group_idle)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001329 fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001330 if (config->p2p_passphrase_len)
1331 fprintf(f, "p2p_passphrase_len=%u\n",
1332 config->p2p_passphrase_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001333 if (config->p2p_pref_chan) {
1334 unsigned int i;
1335 fprintf(f, "p2p_pref_chan=");
1336 for (i = 0; i < config->num_p2p_pref_chan; i++) {
1337 fprintf(f, "%s%u:%u", i > 0 ? "," : "",
1338 config->p2p_pref_chan[i].op_class,
1339 config->p2p_pref_chan[i].chan);
1340 }
1341 fprintf(f, "\n");
1342 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001343 if (config->p2p_no_go_freq.num) {
1344 char *val = freq_range_list_str(&config->p2p_no_go_freq);
1345 if (val) {
1346 fprintf(f, "p2p_no_go_freq=%s\n", val);
1347 os_free(val);
1348 }
1349 }
1350 if (config->p2p_add_cli_chan)
1351 fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan);
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001352 if (config->p2p_optimize_listen_chan !=
1353 DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN)
1354 fprintf(f, "p2p_optimize_listen_chan=%d\n",
1355 config->p2p_optimize_listen_chan);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001356 if (config->p2p_go_ht40)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001357 fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001358 if (config->p2p_go_vht)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001359 fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht);
Hai Shalom74f70d42019-02-11 14:42:39 -08001360 if (config->p2p_go_he)
1361 fprintf(f, "p2p_go_he=%d\n", config->p2p_go_he);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001362 if (config->p2p_go_edmg)
1363 fprintf(f, "p2p_go_edmg=%d\n", config->p2p_go_edmg);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001364 if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001365 fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001366 if (config->p2p_disabled)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001367 fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001368 if (config->p2p_no_group_iface)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001369 fprintf(f, "p2p_no_group_iface=%d\n",
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001370 config->p2p_no_group_iface);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001371 if (config->p2p_ignore_shared_freq)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001372 fprintf(f, "p2p_ignore_shared_freq=%d\n",
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001373 config->p2p_ignore_shared_freq);
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07001374 if (config->p2p_cli_probe)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001375 fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001376 if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE)
1377 fprintf(f, "p2p_go_freq_change_policy=%u\n",
1378 config->p2p_go_freq_change_policy);
Hai Shalom899fcc72020-10-19 14:38:18 -07001379
1380 if (config->p2p_6ghz_disable)
1381 fprintf(f, "p2p_6ghz_disable=%d\n", config->p2p_6ghz_disable);
1382
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001383 if (config->p2p_pairing_setup)
1384 fprintf(f, "p2p_pairing_setup=%d\n", config->p2p_pairing_setup);
1385 if (config->p2p_pairing_cache)
1386 fprintf(f, "p2p_pairing_cache=%d\n", config->p2p_pairing_cache);
1387 if (config->p2p_bootstrap_methods)
1388 fprintf(f, "p2p_bootstrap_methods=%d\n",
1389 config->p2p_bootstrap_methods);
1390 if (config->p2p_pasn_type)
1391 fprintf(f, "p2p_pasn_type=%d\n", config->p2p_pasn_type);
1392 if (config->p2p_comeback_after)
1393 fprintf(f, "p2p_comeback_after=%d\n",
1394 config->p2p_comeback_after);
1395 if (config->p2p_twt_power_mgmt)
1396 fprintf(f, "p2p_twt_power_mgmt=%d\n",
1397 config->p2p_twt_power_mgmt);
1398 if (config->p2p_chan_switch_req_enable)
1399 fprintf(f, "p2p_chan_switch_req_enable=%d\n",
1400 config->p2p_chan_switch_req_enable);
1401 if (config->p2p_reg_info)
1402 fprintf(f, "p2p_reg_info=%d\n", config->p2p_reg_info);
1403
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001404 if (WPA_GET_BE32(config->ip_addr_go))
1405 fprintf(f, "ip_addr_go=%u.%u.%u.%u\n",
1406 config->ip_addr_go[0], config->ip_addr_go[1],
1407 config->ip_addr_go[2], config->ip_addr_go[3]);
1408 if (WPA_GET_BE32(config->ip_addr_mask))
1409 fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n",
1410 config->ip_addr_mask[0], config->ip_addr_mask[1],
1411 config->ip_addr_mask[2], config->ip_addr_mask[3]);
1412 if (WPA_GET_BE32(config->ip_addr_start))
1413 fprintf(f, "ip_addr_start=%u.%u.%u.%u\n",
1414 config->ip_addr_start[0], config->ip_addr_start[1],
1415 config->ip_addr_start[2], config->ip_addr_start[3]);
1416 if (WPA_GET_BE32(config->ip_addr_end))
1417 fprintf(f, "ip_addr_end=%u.%u.%u.%u\n",
1418 config->ip_addr_end[0], config->ip_addr_end[1],
1419 config->ip_addr_end[2], config->ip_addr_end[3]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420#endif /* CONFIG_P2P */
1421 if (config->country[0] && config->country[1]) {
1422 fprintf(f, "country=%c%c\n",
1423 config->country[0], config->country[1]);
1424 }
1425 if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
1426 fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
1427 if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE)
1428 fprintf(f, "bss_expiration_age=%u\n",
1429 config->bss_expiration_age);
1430 if (config->bss_expiration_scan_count !=
1431 DEFAULT_BSS_EXPIRATION_SCAN_COUNT)
1432 fprintf(f, "bss_expiration_scan_count=%u\n",
1433 config->bss_expiration_scan_count);
1434 if (config->filter_ssids)
1435 fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
Paul Stewart092955c2017-02-06 09:13:09 -08001436 if (config->filter_rssi)
1437 fprintf(f, "filter_rssi=%d\n", config->filter_rssi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001438 if (config->max_num_sta != DEFAULT_MAX_NUM_STA)
1439 fprintf(f, "max_num_sta=%u\n", config->max_num_sta);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001440 if (config->ap_isolate != DEFAULT_AP_ISOLATE)
1441 fprintf(f, "ap_isolate=%u\n", config->ap_isolate);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 if (config->disassoc_low_ack)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001443 fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001444#ifdef CONFIG_HS20
1445 if (config->hs20)
1446 fprintf(f, "hs20=1\n");
1447#endif /* CONFIG_HS20 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001448#ifdef CONFIG_INTERWORKING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001449 if (config->interworking)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001450 fprintf(f, "interworking=%d\n", config->interworking);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451 if (!is_zero_ether_addr(config->hessid))
1452 fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid));
1453 if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE)
1454 fprintf(f, "access_network_type=%d\n",
1455 config->access_network_type);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001456 if (config->go_interworking)
1457 fprintf(f, "go_interworking=%d\n", config->go_interworking);
1458 if (config->go_access_network_type)
1459 fprintf(f, "go_access_network_type=%d\n",
1460 config->go_access_network_type);
1461 if (config->go_internet)
1462 fprintf(f, "go_internet=%d\n", config->go_internet);
1463 if (config->go_venue_group)
1464 fprintf(f, "go_venue_group=%d\n", config->go_venue_group);
1465 if (config->go_venue_type)
1466 fprintf(f, "go_venue_type=%d\n", config->go_venue_type);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001467#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001468 if (config->pbc_in_m1)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001469 fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001470 if (config->wps_nfc_pw_from_config) {
1471 if (config->wps_nfc_dev_pw_id)
1472 fprintf(f, "wps_nfc_dev_pw_id=%d\n",
1473 config->wps_nfc_dev_pw_id);
1474 write_global_bin(f, "wps_nfc_dh_pubkey",
1475 config->wps_nfc_dh_pubkey);
1476 write_global_bin(f, "wps_nfc_dh_privkey",
1477 config->wps_nfc_dh_privkey);
1478 write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw);
1479 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001480
1481 if (config->ext_password_backend)
1482 fprintf(f, "ext_password_backend=%s\n",
1483 config->ext_password_backend);
1484 if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY)
1485 fprintf(f, "p2p_go_max_inactivity=%d\n",
1486 config->p2p_go_max_inactivity);
1487 if (config->auto_interworking)
1488 fprintf(f, "auto_interworking=%d\n",
1489 config->auto_interworking);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001490 if (config->okc)
1491 fprintf(f, "okc=%d\n", config->okc);
1492 if (config->pmf)
1493 fprintf(f, "pmf=%d\n", config->pmf);
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08001494 if (config->dtim_period)
1495 fprintf(f, "dtim_period=%d\n", config->dtim_period);
1496 if (config->beacon_int)
1497 fprintf(f, "beacon_int=%d\n", config->beacon_int);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001498
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001499 if (config->sae_check_mfp)
1500 fprintf(f, "sae_check_mfp=%d\n", config->sae_check_mfp);
1501
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001502 if (config->sae_groups) {
1503 int i;
1504 fprintf(f, "sae_groups=");
Paul Stewart092955c2017-02-06 09:13:09 -08001505 for (i = 0; config->sae_groups[i] > 0; i++) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001506 fprintf(f, "%s%d", i > 0 ? " " : "",
1507 config->sae_groups[i]);
1508 }
1509 fprintf(f, "\n");
1510 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001511
Hai Shalomc3565922019-10-28 11:58:20 -07001512 if (config->sae_pwe)
1513 fprintf(f, "sae_pwe=%d\n", config->sae_pwe);
1514
1515 if (config->sae_pmkid_in_assoc)
1516 fprintf(f, "sae_pmkid_in_assoc=%d\n",
1517 config->sae_pmkid_in_assoc);
1518
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001519 if (config->ap_vendor_elements) {
1520 int i, len = wpabuf_len(config->ap_vendor_elements);
1521 const u8 *p = wpabuf_head_u8(config->ap_vendor_elements);
1522 if (len > 0) {
1523 fprintf(f, "ap_vendor_elements=");
1524 for (i = 0; i < len; i++)
1525 fprintf(f, "%02x", *p++);
1526 fprintf(f, "\n");
1527 }
1528 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001529
Hai Shaloma20dcd72022-02-04 13:43:00 -08001530 if (config->ap_assocresp_elements) {
1531 int i, len = wpabuf_len(config->ap_assocresp_elements);
1532 const u8 *p = wpabuf_head_u8(config->ap_assocresp_elements);
1533
1534 if (len > 0) {
1535 fprintf(f, "ap_assocresp_elements=");
1536 for (i = 0; i < len; i++)
1537 fprintf(f, "%02x", *p++);
1538 fprintf(f, "\n");
1539 }
1540 }
1541
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001542 if (config->ignore_old_scan_res)
1543 fprintf(f, "ignore_old_scan_res=%d\n",
1544 config->ignore_old_scan_res);
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001545
1546 if (config->freq_list && config->freq_list[0]) {
1547 int i;
1548 fprintf(f, "freq_list=");
1549 for (i = 0; config->freq_list[i]; i++) {
Dmitry Shmidt41712582015-06-29 11:02:15 -07001550 fprintf(f, "%s%d", i > 0 ? " " : "",
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001551 config->freq_list[i]);
1552 }
1553 fprintf(f, "\n");
1554 }
Hai Shalom60840252021-02-19 19:02:11 -08001555 if (config->initial_freq_list && config->initial_freq_list[0]) {
1556 int i;
1557 fprintf(f, "initial_freq_list=");
1558 for (i = 0; config->initial_freq_list[i]; i++) {
1559 fprintf(f, "%s%d", i > 0 ? " " : "",
1560 config->initial_freq_list[i]);
1561 }
1562 fprintf(f, "\n");
1563 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07001564 if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ)
1565 fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq);
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001566
Hai Shalom60840252021-02-19 19:02:11 -08001567 if (config->scan_res_valid_for_connect !=
1568 DEFAULT_SCAN_RES_VALID_FOR_CONNECT)
1569 fprintf(f, "scan_res_valid_for_connect=%d\n",
1570 config->scan_res_valid_for_connect);
1571
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001572 if (config->sched_scan_interval)
1573 fprintf(f, "sched_scan_interval=%u\n",
1574 config->sched_scan_interval);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001575
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001576 if (config->sched_scan_start_delay)
1577 fprintf(f, "sched_scan_start_delay=%u\n",
1578 config->sched_scan_start_delay);
1579
Dmitry Shmidt051af732013-10-22 13:52:46 -07001580 if (config->external_sim)
1581 fprintf(f, "external_sim=%d\n", config->external_sim);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001582
1583 if (config->tdls_external_control)
1584 fprintf(f, "tdls_external_control=%d\n",
1585 config->tdls_external_control);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001586
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07001587 if (config->wowlan_triggers)
Dmitry Shmidt03658832014-08-13 11:03:49 -07001588 fprintf(f, "wowlan_triggers=%s\n",
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07001589 config->wowlan_triggers);
1590
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001591 if (config->bgscan)
1592 fprintf(f, "bgscan=\"%s\"\n", config->bgscan);
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001593
Paul Stewart092955c2017-02-06 09:13:09 -08001594 if (config->autoscan)
1595 fprintf(f, "autoscan=%s\n", config->autoscan);
1596
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001597 if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY)
1598 fprintf(f, "p2p_search_delay=%u\n",
1599 config->p2p_search_delay);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001600
1601 if (config->mac_addr)
1602 fprintf(f, "mac_addr=%d\n", config->mac_addr);
1603
1604 if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1605 fprintf(f, "rand_addr_lifetime=%u\n",
1606 config->rand_addr_lifetime);
1607
1608 if (config->preassoc_mac_addr)
1609 fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001610
1611 if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD)
Dmitry Shmidt41712582015-06-29 11:02:15 -07001612 fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001613
1614 if (config->user_mpm != DEFAULT_USER_MPM)
1615 fprintf(f, "user_mpm=%d\n", config->user_mpm);
1616
1617 if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS)
1618 fprintf(f, "max_peer_links=%d\n", config->max_peer_links);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001619
1620 if (config->cert_in_cb != DEFAULT_CERT_IN_CB)
1621 fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb);
1622
1623 if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY)
1624 fprintf(f, "mesh_max_inactivity=%d\n",
1625 config->mesh_max_inactivity);
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001626
Hai Shaloma20dcd72022-02-04 13:43:00 -08001627 if (config->mesh_fwding != DEFAULT_MESH_FWDING)
1628 fprintf(f, "mesh_fwding=%d\n", config->mesh_fwding);
1629
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001630 if (config->dot11RSNASAERetransPeriod !=
1631 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD)
1632 fprintf(f, "dot11RSNASAERetransPeriod=%d\n",
1633 config->dot11RSNASAERetransPeriod);
1634
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001635 if (config->passive_scan)
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001636 fprintf(f, "passive_scan=%d\n", config->passive_scan);
1637
1638 if (config->reassoc_same_bss_optim)
1639 fprintf(f, "reassoc_same_bss_optim=%d\n",
1640 config->reassoc_same_bss_optim);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001641
1642 if (config->wps_priority)
1643 fprintf(f, "wps_priority=%d\n", config->wps_priority);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001644
1645 if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION)
1646 fprintf(f, "wpa_rsc_relaxation=%d\n",
1647 config->wpa_rsc_relaxation);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001648
1649 if (config->sched_scan_plans)
1650 fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001651
1652#ifdef CONFIG_MBO
1653 if (config->non_pref_chan)
1654 fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan);
1655 if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA)
1656 fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001657 if (config->disassoc_imminent_rssi_threshold !=
1658 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD)
1659 fprintf(f, "disassoc_imminent_rssi_threshold=%d\n",
1660 config->disassoc_imminent_rssi_threshold);
1661 if (config->oce != DEFAULT_OCE_SUPPORT)
1662 fprintf(f, "oce=%u\n", config->oce);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001663#endif /* CONFIG_MBO */
1664
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001665 if (config->gas_address3)
1666 fprintf(f, "gas_address3=%d\n", config->gas_address3);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001667
1668 if (config->ftm_responder)
1669 fprintf(f, "ftm_responder=%d\n", config->ftm_responder);
1670 if (config->ftm_initiator)
1671 fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator);
Paul Stewart092955c2017-02-06 09:13:09 -08001672
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001673 if (config->twt_requester)
1674 fprintf(f, "twt_requester=%d\n", config->twt_requester);
1675
Paul Stewart092955c2017-02-06 09:13:09 -08001676 if (config->osu_dir)
1677 fprintf(f, "osu_dir=%s\n", config->osu_dir);
1678
1679 if (config->fst_group_id)
1680 fprintf(f, "fst_group_id=%s\n", config->fst_group_id);
1681 if (config->fst_priority)
1682 fprintf(f, "fst_priority=%d\n", config->fst_priority);
1683 if (config->fst_llt)
1684 fprintf(f, "fst_llt=%d\n", config->fst_llt);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001685
1686 if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1687 fprintf(f, "gas_rand_addr_lifetime=%u\n",
1688 config->gas_rand_addr_lifetime);
1689 if (config->gas_rand_mac_addr)
1690 fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001691 if (config->dpp_config_processing)
1692 fprintf(f, "dpp_config_processing=%d\n",
1693 config->dpp_config_processing);
Sunil Ravi89eba102022-09-13 21:04:37 -07001694 if (config->dpp_name)
1695 fprintf(f, "dpp_name=%s\n", config->dpp_name);
1696 if (config->dpp_mud_url)
1697 fprintf(f, "dpp_mud_url=%s\n", config->dpp_mud_url);
1698 if (config->dpp_extra_conf_req_name)
1699 fprintf(f, "dpp_extra_conf_req_name=%s\n",
1700 config->dpp_extra_conf_req_name);
1701 if (config->dpp_extra_conf_req_value)
1702 fprintf(f, "dpp_extra_conf_req_value=%s\n",
1703 config->dpp_extra_conf_req_value);
1704 if (config->dpp_connector_privacy_default)
1705 fprintf(f, "dpp_connector_privacy_default=%d\n",
1706 config->dpp_connector_privacy_default);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001707 if (config->coloc_intf_reporting)
1708 fprintf(f, "coloc_intf_reporting=%d\n",
1709 config->coloc_intf_reporting);
Jimmy Chenf887c7b2018-11-13 15:19:57 +08001710 if (config->p2p_device_random_mac_addr)
1711 fprintf(f, "p2p_device_random_mac_addr=%d\n",
1712 config->p2p_device_random_mac_addr);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001713 if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr))
1714 fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n",
1715 MAC2STR(config->p2p_device_persistent_mac_addr));
Jimmy Chen36c21992018-11-29 16:46:43 +08001716 if (config->p2p_interface_random_mac_addr)
1717 fprintf(f, "p2p_interface_random_mac_addr=%d\n",
1718 config->p2p_interface_random_mac_addr);
Jimmy Chen0bb4f862019-03-21 18:41:47 +08001719 if (config->bss_no_flush_when_down)
1720 fprintf(f, "bss_no_flush_when_down=%d\n",
1721 config->bss_no_flush_when_down);
Hai Shalom81f62d82019-07-22 12:10:00 -07001722 if (config->disable_btm)
1723 fprintf(f, "disable_btm=1\n");
Hai Shalomfdcde762020-04-02 11:19:20 -07001724 if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID)
1725 fprintf(f, "extended_key_id=%d\n",
1726 config->extended_key_id);
Hai Shalom60840252021-02-19 19:02:11 -08001727 if (config->wowlan_disconnect_on_deinit)
1728 fprintf(f, "wowlan_disconnect_on_deinit=%d\n",
1729 config->wowlan_disconnect_on_deinit);
Sunil Ravi7f769292024-07-23 22:21:32 +00001730 if (config->rsn_overriding)
1731 fprintf(f, "rsn_overriding=%d\n", config->rsn_overriding);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001732#ifdef CONFIG_TESTING_OPTIONS
1733 if (config->mld_force_single_link)
1734 fprintf(f, "mld_force_single_link=1\n");
1735 if (config->mld_connect_band_pref != MLD_CONNECT_BAND_PREF_AUTO)
1736 fprintf(f, "mld_connect_band_pref=%d\n",
1737 config->mld_connect_band_pref);
1738 if (!is_zero_ether_addr(config->mld_connect_bssid_pref))
1739 fprintf(f, "mld_connect_bssid_pref=" MACSTR "\n",
1740 MAC2STR(config->mld_connect_bssid_pref));
1741#endif /* CONFIG_TESTING_OPTIONS */
1742 if (config->ft_prepend_pmkid)
Sunil Ravic0f5d412024-09-11 22:12:49 +00001743 fprintf(f, "ft_prepend_pmkid=%d\n", config->ft_prepend_pmkid);
1744 if (config->dik) {
1745 fprintf(f, "dik_cipher=%d\n", config->dik_cipher);
1746 write_global_bin(f, "dik", config->dik);
1747 }
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001748 if (config->wfa_gen_capa)
1749 fprintf(f, "wfa_gen_capa=%d\n", config->wfa_gen_capa);
1750 write_global_bin(f, "wfa_gen_capa_supp", config->wfa_gen_capa_supp);
1751 write_global_bin(f, "wfa_gen_capa_cert", config->wfa_gen_capa_cert);
1752}
1753
1754static void wpa_config_write_identity(FILE *f, struct wpa_dev_ik *dev_ik)
1755{
1756 fprintf(f, "\tdik_cipher=%d\n", dev_ik->dik_cipher);
1757
1758 if (dev_ik->dik)
1759 write_global_bin(f, "\tdik", dev_ik->dik);
1760
1761 if (dev_ik->pmk)
1762 write_global_bin(f, "\tpmk", dev_ik->pmk);
1763
1764 if (dev_ik->pmkid)
1765 write_global_bin(f, "\tpmkid", dev_ik->pmkid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766}
1767
1768#endif /* CONFIG_NO_CONFIG_WRITE */
1769
1770
1771int wpa_config_write(const char *name, struct wpa_config *config)
1772{
1773#ifndef CONFIG_NO_CONFIG_WRITE
1774 FILE *f;
1775 struct wpa_ssid *ssid;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001776 struct wpa_cred *cred;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001777 struct wpa_dev_ik *dev_ik;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778#ifndef CONFIG_NO_CONFIG_BLOBS
1779 struct wpa_config_blob *blob;
1780#endif /* CONFIG_NO_CONFIG_BLOBS */
1781 int ret = 0;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001782 const char *orig_name = name;
Hai Shalomfdcde762020-04-02 11:19:20 -07001783 int tmp_len;
1784 char *tmp_name;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785
Hai Shalomfdcde762020-04-02 11:19:20 -07001786 if (!name) {
1787 wpa_printf(MSG_ERROR, "No configuration file for writing");
1788 return -1;
1789 }
1790
1791 tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
1792 tmp_name = os_malloc(tmp_len);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001793 if (tmp_name) {
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001794 os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001795 name = tmp_name;
1796 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001798 wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001799
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001800 f = fopen(name, "w");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 if (f == NULL) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001802 wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
1803 os_free(tmp_name);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001804 return -1;
1805 }
1806
1807 wpa_config_write_global(f, config);
1808
Dmitry Shmidt04949592012-07-19 12:16:46 -07001809 for (cred = config->cred; cred; cred = cred->next) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001810 if (cred->temporary)
1811 continue;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001812 fprintf(f, "\ncred={\n");
1813 wpa_config_write_cred(f, cred);
1814 fprintf(f, "}\n");
1815 }
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 for (ssid = config->ssid; ssid; ssid = ssid->next) {
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001818 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary ||
1819 ssid->ro)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 continue; /* do not save temporary networks */
Hai Shalomfdcde762020-04-02 11:19:20 -07001821 if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt) &&
1822 !ssid->psk_set && !ssid->passphrase)
1823 continue; /* do not save invalid network */
1824 if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001825 !ssid->passphrase && !ssid->sae_password &&
1826 !ssid->pmk_valid)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001827 continue; /* do not save invalid network */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828 fprintf(f, "\nnetwork={\n");
1829 wpa_config_write_network(f, ssid);
1830 fprintf(f, "}\n");
1831 }
1832
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001833 for (dev_ik = config->identity; dev_ik; dev_ik = dev_ik->next) {
1834 fprintf(f, "\nidentity={\n");
1835 wpa_config_write_identity(f, dev_ik);
1836 fprintf(f, "}\n");
1837 }
1838
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839#ifndef CONFIG_NO_CONFIG_BLOBS
1840 for (blob = config->blobs; blob; blob = blob->next) {
1841 ret = wpa_config_write_blob(f, blob);
1842 if (ret)
1843 break;
1844 }
1845#endif /* CONFIG_NO_CONFIG_BLOBS */
1846
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001847 os_fdatasync(f);
Mitchell Wills447c7ff2015-08-24 17:24:30 -07001848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001849 fclose(f);
1850
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001851 if (tmp_name) {
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001852 int chmod_ret = 0;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001853
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001854#ifdef ANDROID
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001855 chmod_ret = chmod(tmp_name,
1856 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
1857#endif /* ANDROID */
1858 if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0)
Vinit Deshpande0a217de2015-02-05 12:48:02 -08001859 ret = -1;
1860
1861 os_free(tmp_name);
1862 }
1863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001864 wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001865 orig_name, ret ? "un" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 return ret;
1867#else /* CONFIG_NO_CONFIG_WRITE */
1868 return -1;
1869#endif /* CONFIG_NO_CONFIG_WRITE */
1870}