1 /*
2 * WPA Supplicant / Configuration backend: text file
3 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 *
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"
14 #ifdef ANDROID
15 #include <sys/stat.h>
16 #endif /* ANDROID */
17
18 #include "common.h"
19 #include "config.h"
20 #include "base64.h"
21 #include "uuid.h"
22 #include "common/ieee802_1x_defs.h"
23 #include "p2p/p2p.h"
24 #include "eap_peer/eap_methods.h"
25 #include "eap_peer/eap.h"
26 #include "utils/config.h"
27
28
wpa_config_validate_network(struct wpa_ssid * ssid,int line)29 static 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
42 if (ssid->disabled == 2)
43 ssid->p2p_persistent_group = 1;
44
45 if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
46 !(ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 |
47 WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256 |
48 WPA_CIPHER_NONE))) {
49 /* 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
56 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 }
63 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
72 #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
81 return errors;
82 }
83
84
wpa_config_read_network(FILE * f,int * line,int id)85 static 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;
89 char buf[2000], *pos, *pos2;
90
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;
96 dl_list_init(&ssid->psk_list);
97 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
125 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 */
139 errors++;
140 }
141 }
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
wpa_config_read_cred(FILE * f,int * line,int id)160 static 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;
171 cred->sim_num = DEFAULT_USER_SELECTED_SIM;
172
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
216 #ifndef CONFIG_NO_CONFIG_BLOBS
wpa_config_read_blob(FILE * f,int * line,const char * name)217 static 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;
222 char *encoded = NULL, *nencoded;
223 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
248 if (!end || !encoded) {
249 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
wpa_config_process_blob(struct wpa_config * config,FILE * f,int * line,char * bname)273 static 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
wpa_config_read_identity(FILE * f,int * line,int id)299 static 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
wpa_config_read(const char * name,struct wpa_config * cfgp,bool ro)358 struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp,
359 bool ro)
360 {
361 FILE *f;
362 char buf[512], *pos;
363 int errors = 0, line = 0;
364 struct wpa_ssid *ssid, *tail, *head;
365 struct wpa_cred *cred, *cred_tail, *cred_head;
366 struct wpa_dev_ik *identity, *identity_tail, *identity_head;
367 struct wpa_config *config;
368 static int id = 0;
369 static int cred_id = 0;
370 static int identity_id = 1;
371
372 if (name == NULL)
373 return NULL;
374 if (cfgp)
375 config = cfgp;
376 else
377 config = wpa_config_alloc_empty(NULL, NULL);
378 if (config == NULL) {
379 wpa_printf(MSG_ERROR, "Failed to allocate config file "
380 "structure");
381 return NULL;
382 }
383 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;
389 identity_tail = identity_head = config->identity;
390 while (identity_tail && identity_tail->next)
391 identity_tail = identity_tail->next;
392
393 wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
394 f = fopen(name, "r");
395 if (f == NULL) {
396 wpa_printf(MSG_ERROR, "Failed to open config file '%s', "
397 "error: %s", name, strerror(errno));
398 if (config != cfgp)
399 os_free(config);
400 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 }
412 ssid->ro = ro;
413 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 }
426 } 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 }
440 #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) {
444 wpa_printf(MSG_ERROR, "Line %d: failed to "
445 "process blob.", line);
446 errors++;
447 continue;
448 }
449 #endif /* CONFIG_NO_CONFIG_BLOBS */
450 } 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 }
466 } 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
476 config->ssid = head;
477 wpa_config_debug_dump_networks(config);
478 config->cred = cred_head;
479 config->identity = identity_head;
480
481 #ifndef WPA_IGNORE_CONFIG_ERRORS
482 if (errors) {
483 if (config != cfgp)
484 wpa_config_free(config);
485 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
write_str(FILE * f,const char * field,struct wpa_ssid * ssid)496 static 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);
502 str_clear_free(value);
503 }
504
505
write_int(FILE * f,const char * field,int value,int def)506 static 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
write_bssid(FILE * f,struct wpa_ssid * ssid)514 static 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
write_bssid_hint(FILE * f,struct wpa_ssid * ssid)524 static 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
write_psk(FILE * f,struct wpa_ssid * ssid)535 static void write_psk(FILE *f, struct wpa_ssid *ssid)
536 {
537 char *value;
538
539 if (ssid->mem_only_psk)
540 return;
541
542 value = wpa_config_get(ssid, "psk");
543 if (value == NULL)
544 return;
545 fprintf(f, "\tpsk=%s\n", value);
546 os_free(value);
547 }
548
549
write_proto(FILE * f,struct wpa_ssid * ssid)550 static 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
write_key_mgmt(FILE * f,struct wpa_ssid * ssid)566 static 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
write_pairwise(FILE * f,struct wpa_ssid * ssid)582 static 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
write_group(FILE * f,struct wpa_ssid * ssid)598 static 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
write_group_mgmt(FILE * f,struct wpa_ssid * ssid)614 static 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
write_auth_alg(FILE * f,struct wpa_ssid * ssid)630 static 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
write_eap(FILE * f,struct wpa_ssid * ssid)647 static 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
662 #ifdef CONFIG_WEP
write_wep_key(FILE * f,int idx,struct wpa_ssid * ssid)663 static 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);
669 if (os_snprintf_error(sizeof(field), res))
670 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 }
677 #endif /* CONFIG_WEP */
678
679
680 #ifdef CONFIG_P2P
681
write_go_p2p_dev_addr(FILE * f,struct wpa_ssid * ssid)682 static 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
write_p2p_client_list(FILE * f,struct wpa_ssid * ssid)691 static 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 }
699
700
write_p2p2_client_list(FILE * f,struct wpa_ssid * ssid)701 static void write_p2p2_client_list(FILE *f, struct wpa_ssid *ssid)
702 {
703 char *value = wpa_config_get(ssid, "p2p2_client_list");
704
705 if (!value)
706 return;
707 fprintf(f, "\tp2p2_client_list=%s\n", value);
708 os_free(value);
709 }
710
711
write_psk_list(FILE * f,struct wpa_ssid * ssid)712 static void write_psk_list(FILE *f, struct wpa_ssid *ssid)
713 {
714 struct psk_list_entry *psk;
715 char hex[32 * 2 + 1];
716
717 dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) {
718 wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk));
719 fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n",
720 psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex);
721 }
722 }
723
724 #endif /* CONFIG_P2P */
725
726
727 #ifdef CONFIG_MACSEC
728
write_mka_cak(FILE * f,struct wpa_ssid * ssid)729 static void write_mka_cak(FILE *f, struct wpa_ssid *ssid)
730 {
731 char *value;
732
733 if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK))
734 return;
735
736 value = wpa_config_get(ssid, "mka_cak");
737 if (!value)
738 return;
739 fprintf(f, "\tmka_cak=%s\n", value);
740 os_free(value);
741 }
742
743
write_mka_ckn(FILE * f,struct wpa_ssid * ssid)744 static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid)
745 {
746 char *value;
747
748 if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN))
749 return;
750
751 value = wpa_config_get(ssid, "mka_ckn");
752 if (!value)
753 return;
754 fprintf(f, "\tmka_ckn=%s\n", value);
755 os_free(value);
756 }
757
758 #endif /* CONFIG_MACSEC */
759
760
wpa_config_write_network(FILE * f,struct wpa_ssid * ssid)761 static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
762 {
763 #define STR(t) write_str(f, #t, ssid)
764 #define INT(t) write_int(f, #t, ssid->t, 0)
765 #define INTe(t, m) write_int(f, #t, ssid->eap.m, 0)
766 #define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
767 #define INT_DEFe(t, m, def) write_int(f, #t, ssid->eap.m, def)
768
769 STR(ssid);
770 INT(scan_ssid);
771 write_bssid(f, ssid);
772 write_bssid_hint(f, ssid);
773 write_str(f, "bssid_ignore", ssid);
774 write_str(f, "bssid_accept", ssid);
775 write_psk(f, ssid);
776 INT(mem_only_psk);
777 STR(sae_password);
778 STR(sae_password_id);
779 write_int(f, "sae_pwe", ssid->sae_pwe, DEFAULT_SAE_PWE);
780 write_proto(f, ssid);
781 write_key_mgmt(f, ssid);
782 INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD);
783 write_pairwise(f, ssid);
784 write_group(f, ssid);
785 write_group_mgmt(f, ssid);
786 write_auth_alg(f, ssid);
787 STR(bgscan);
788 STR(autoscan);
789 STR(scan_freq);
790 #ifdef IEEE8021X_EAPOL
791 write_eap(f, ssid);
792 STR(identity);
793 STR(anonymous_identity);
794 STR(imsi_identity);
795 STR(machine_identity);
796 STR(password);
797 STR(machine_password);
798 STR(ca_cert);
799 STR(ca_path);
800 STR(client_cert);
801 STR(private_key);
802 STR(private_key_passwd);
803 STR(subject_match);
804 STR(check_cert_subject);
805 STR(altsubject_match);
806 STR(domain_suffix_match);
807 STR(domain_match);
808 STR(ca_cert2);
809 STR(ca_path2);
810 STR(client_cert2);
811 STR(private_key2);
812 STR(private_key2_passwd);
813 STR(subject_match2);
814 STR(check_cert_subject2);
815 STR(altsubject_match2);
816 STR(domain_suffix_match2);
817 STR(domain_match2);
818 STR(machine_ca_cert);
819 STR(machine_ca_path);
820 STR(machine_client_cert);
821 STR(machine_private_key);
822 STR(machine_private_key_passwd);
823 STR(machine_subject_match);
824 STR(machine_check_cert_subject);
825 STR(machine_altsubject_match);
826 STR(machine_domain_suffix_match);
827 STR(machine_domain_match);
828 STR(phase1);
829 STR(phase2);
830 STR(machine_phase2);
831 STR(pcsc);
832 STR(pin);
833 STR(engine_id);
834 STR(key_id);
835 STR(cert_id);
836 STR(ca_cert_id);
837 STR(key2_id);
838 STR(pin2);
839 STR(engine2_id);
840 STR(cert2_id);
841 STR(ca_cert2_id);
842 INTe(engine, cert.engine);
843 INTe(engine2, phase2_cert.engine);
844 INTe(machine_engine, machine_cert.engine);
845 INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
846 STR(openssl_ciphers);
847 INTe(erp, erp);
848 #endif /* IEEE8021X_EAPOL */
849 #ifdef CONFIG_WEP
850 {
851 int i;
852
853 for (i = 0; i < 4; i++)
854 write_wep_key(f, i, ssid);
855 INT(wep_tx_keyidx);
856 }
857 #endif /* CONFIG_WEP */
858 INT(priority);
859 #ifdef IEEE8021X_EAPOL
860 INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
861 STR(pac_file);
862 INT_DEFe(fragment_size, fragment_size, DEFAULT_FRAGMENT_SIZE);
863 INTe(ocsp, cert.ocsp);
864 INTe(ocsp2, phase2_cert.ocsp);
865 INTe(machine_ocsp, machine_cert.ocsp);
866 INT_DEFe(sim_num, sim_num, DEFAULT_USER_SELECTED_SIM);
867 #endif /* IEEE8021X_EAPOL */
868 INT(mode);
869 INT(no_auto_peer);
870 INT_DEF(mesh_fwding, DEFAULT_MESH_FWDING);
871 INT(frequency);
872 INT(enable_edmg);
873 INT(edmg_channel);
874 INT(fixed_freq);
875 #ifdef CONFIG_ACS
876 INT(acs);
877 #endif /* CONFIG_ACS */
878 write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1);
879 INT(disabled);
880 INT(mixed_cell);
881 INT_DEF(vht, 1);
882 INT_DEF(ht, 1);
883 INT(ht40);
884 INT_DEF(he, 1);
885 INT_DEF(max_oper_chwidth, DEFAULT_MAX_OPER_CHWIDTH);
886 INT(vht_center_freq1);
887 INT(vht_center_freq2);
888 INT(pbss);
889 INT(wps_disabled);
890 INT(fils_dh_group);
891 write_int(f, "ieee80211w", ssid->ieee80211w,
892 MGMT_FRAME_PROTECTION_DEFAULT);
893 STR(id_str);
894 #ifdef CONFIG_P2P
895 write_go_p2p_dev_addr(f, ssid);
896 write_p2p_client_list(f, ssid);
897 write_p2p2_client_list(f, ssid);
898 write_psk_list(f, ssid);
899 INT(go_dik_id);
900 #endif /* CONFIG_P2P */
901 INT(ap_max_inactivity);
902 INT(dtim_period);
903 INT(beacon_int);
904 #ifdef CONFIG_MACSEC
905 INT(macsec_policy);
906 write_mka_cak(f, ssid);
907 write_mka_ckn(f, ssid);
908 INT(macsec_integ_only);
909 INT(macsec_replay_protect);
910 INT(macsec_replay_window);
911 INT(macsec_offload);
912 INT(macsec_port);
913 INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER);
914 INT(macsec_csindex);
915 INT(macsec_icv_indicator);
916 #endif /* CONFIG_MACSEC */
917 #ifdef CONFIG_HS20
918 INT(update_identifier);
919 STR(roaming_consortium_selection);
920 #endif /* CONFIG_HS20 */
921 write_int(f, "mac_addr", ssid->mac_addr, -1);
922 #ifdef CONFIG_MESH
923 STR(mesh_basic_rates);
924 INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES);
925 INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT);
926 INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT);
927 INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT);
928 INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD);
929 #endif /* CONFIG_MESH */
930 INT(wpa_ptk_rekey);
931 INT(wpa_deny_ptk0_rekey);
932 INT(group_rekey);
933 INT(ignore_broadcast_ssid);
934 #ifdef CONFIG_DPP
935 STR(dpp_connector);
936 STR(dpp_netaccesskey);
937 INT(dpp_netaccesskey_expiry);
938 STR(dpp_csign);
939 STR(dpp_pp_key);
940 INT(dpp_pfs);
941 INT(dpp_connector_privacy);
942 #endif /* CONFIG_DPP */
943 INT(owe_group);
944 INT(owe_only);
945 INT(owe_ptk_workaround);
946 INT(multi_ap_backhaul_sta);
947 INT(ft_eap_pmksa_caching);
948 INT(multi_ap_profile);
949 INT(beacon_prot);
950 INT(transition_disable);
951 INT(sae_pk);
952 #ifdef CONFIG_HT_OVERRIDES
953 INT_DEF(disable_ht, DEFAULT_DISABLE_HT);
954 INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40);
955 INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI);
956 INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC);
957 INT(ht40_intolerant);
958 INT_DEF(tx_stbc, DEFAULT_TX_STBC);
959 INT_DEF(rx_stbc, DEFAULT_RX_STBC);
960 INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU);
961 INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR);
962 INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY);
963 STR(ht_mcs);
964 #endif /* CONFIG_HT_OVERRIDES */
965 #ifdef CONFIG_VHT_OVERRIDES
966 INT(disable_vht);
967 INT(vht_capa);
968 INT(vht_capa_mask);
969 INT_DEF(vht_rx_mcs_nss_1, -1);
970 INT_DEF(vht_rx_mcs_nss_2, -1);
971 INT_DEF(vht_rx_mcs_nss_3, -1);
972 INT_DEF(vht_rx_mcs_nss_4, -1);
973 INT_DEF(vht_rx_mcs_nss_5, -1);
974 INT_DEF(vht_rx_mcs_nss_6, -1);
975 INT_DEF(vht_rx_mcs_nss_7, -1);
976 INT_DEF(vht_rx_mcs_nss_8, -1);
977 INT_DEF(vht_tx_mcs_nss_1, -1);
978 INT_DEF(vht_tx_mcs_nss_2, -1);
979 INT_DEF(vht_tx_mcs_nss_3, -1);
980 INT_DEF(vht_tx_mcs_nss_4, -1);
981 INT_DEF(vht_tx_mcs_nss_5, -1);
982 INT_DEF(vht_tx_mcs_nss_6, -1);
983 INT_DEF(vht_tx_mcs_nss_7, -1);
984 INT_DEF(vht_tx_mcs_nss_8, -1);
985 #endif /* CONFIG_VHT_OVERRIDES */
986 #ifdef CONFIG_HE_OVERRIDES
987 INT(disable_he);
988 #endif /* CONFIG_HE_OVERRIDES */
989 INT(disable_eht);
990 INT(enable_4addr_mode);
991 INT(max_idle);
992 INT(ssid_protection);
993 INT_DEF(rsn_overriding, RSN_OVERRIDING_NOT_SET);
994
995 #undef STR
996 #undef INT
997 #undef INT_DEF
998 }
999
1000
wpa_config_write_cred(FILE * f,struct wpa_cred * cred)1001 static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred)
1002 {
1003 size_t i;
1004
1005 if (cred->priority)
1006 fprintf(f, "\tpriority=%d\n", cred->priority);
1007 if (cred->pcsc)
1008 fprintf(f, "\tpcsc=%d\n", cred->pcsc);
1009 if (cred->realm)
1010 fprintf(f, "\trealm=\"%s\"\n", cred->realm);
1011 if (cred->username)
1012 fprintf(f, "\tusername=\"%s\"\n", cred->username);
1013 if (cred->password && cred->ext_password)
1014 fprintf(f, "\tpassword=ext:%s\n", cred->password);
1015 else if (cred->password)
1016 fprintf(f, "\tpassword=\"%s\"\n", cred->password);
1017 if (cred->ca_cert)
1018 fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert);
1019 if (cred->client_cert)
1020 fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert);
1021 if (cred->private_key)
1022 fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key);
1023 if (cred->private_key_passwd)
1024 fprintf(f, "\tprivate_key_passwd=\"%s\"\n",
1025 cred->private_key_passwd);
1026 if (cred->imsi)
1027 fprintf(f, "\timsi=\"%s\"\n", cred->imsi);
1028 if (cred->milenage)
1029 fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage);
1030 for (i = 0; i < cred->num_domain; i++)
1031 fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]);
1032 if (cred->domain_suffix_match)
1033 fprintf(f, "\tdomain_suffix_match=\"%s\"\n",
1034 cred->domain_suffix_match);
1035 if (cred->eap_method) {
1036 const char *name;
1037 name = eap_get_name(cred->eap_method[0].vendor,
1038 cred->eap_method[0].method);
1039 if (name)
1040 fprintf(f, "\teap=%s\n", name);
1041 }
1042 if (cred->phase1)
1043 fprintf(f, "\tphase1=\"%s\"\n", cred->phase1);
1044 if (cred->phase2)
1045 fprintf(f, "\tphase2=\"%s\"\n", cred->phase2);
1046 if (cred->excluded_ssid) {
1047 size_t j;
1048 for (i = 0; i < cred->num_excluded_ssid; i++) {
1049 struct excluded_ssid *e = &cred->excluded_ssid[i];
1050 fprintf(f, "\texcluded_ssid=");
1051 for (j = 0; j < e->ssid_len; j++)
1052 fprintf(f, "%02x", e->ssid[j]);
1053 fprintf(f, "\n");
1054 }
1055 }
1056 if (cred->roaming_partner) {
1057 for (i = 0; i < cred->num_roaming_partner; i++) {
1058 struct roaming_partner *p = &cred->roaming_partner[i];
1059 fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n",
1060 p->fqdn, p->exact_match, p->priority,
1061 p->country);
1062 }
1063 }
1064 if (cred->update_identifier)
1065 fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier);
1066
1067 if (cred->provisioning_sp)
1068 fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp);
1069 if (cred->sp_priority)
1070 fprintf(f, "\tsp_priority=%d\n", cred->sp_priority);
1071
1072 if (cred->min_dl_bandwidth_home)
1073 fprintf(f, "\tmin_dl_bandwidth_home=%u\n",
1074 cred->min_dl_bandwidth_home);
1075 if (cred->min_ul_bandwidth_home)
1076 fprintf(f, "\tmin_ul_bandwidth_home=%u\n",
1077 cred->min_ul_bandwidth_home);
1078 if (cred->min_dl_bandwidth_roaming)
1079 fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n",
1080 cred->min_dl_bandwidth_roaming);
1081 if (cred->min_ul_bandwidth_roaming)
1082 fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n",
1083 cred->min_ul_bandwidth_roaming);
1084
1085 if (cred->max_bss_load)
1086 fprintf(f, "\tmax_bss_load=%u\n",
1087 cred->max_bss_load);
1088
1089 if (cred->ocsp)
1090 fprintf(f, "\tocsp=%d\n", cred->ocsp);
1091
1092 if (cred->num_req_conn_capab) {
1093 for (i = 0; i < cred->num_req_conn_capab; i++) {
1094 int *ports;
1095
1096 fprintf(f, "\treq_conn_capab=%u",
1097 cred->req_conn_capab_proto[i]);
1098 ports = cred->req_conn_capab_port[i];
1099 if (ports) {
1100 int j;
1101 for (j = 0; ports[j] != -1; j++) {
1102 fprintf(f, "%s%d", j > 0 ? "," : ":",
1103 ports[j]);
1104 }
1105 }
1106 fprintf(f, "\n");
1107 }
1108 }
1109
1110 if (cred->num_home_ois) {
1111 size_t j;
1112
1113 fprintf(f, "\thome_ois=\"");
1114 for (i = 0; i < cred->num_home_ois; i++) {
1115 if (i > 0)
1116 fprintf(f, ",");
1117 for (j = 0; j < cred->home_ois_len[i]; j++)
1118 fprintf(f, "%02x",
1119 cred->home_ois[i][j]);
1120 }
1121 fprintf(f, "\"\n");
1122 }
1123
1124 if (cred->num_required_home_ois) {
1125 size_t j;
1126
1127 fprintf(f, "\trequired_home_ois=\"");
1128 for (i = 0; i < cred->num_required_home_ois; i++) {
1129 if (i > 0)
1130 fprintf(f, ",");
1131 for (j = 0; j < cred->required_home_ois_len[i]; j++)
1132 fprintf(f, "%02x",
1133 cred->required_home_ois[i][j]);
1134 }
1135 fprintf(f, "\"\n");
1136 }
1137
1138 if (cred->num_roaming_consortiums) {
1139 size_t j;
1140
1141 fprintf(f, "\troaming_consortiums=\"");
1142 for (i = 0; i < cred->num_roaming_consortiums; i++) {
1143 if (i > 0)
1144 fprintf(f, ",");
1145 for (j = 0; j < cred->roaming_consortiums_len[i]; j++)
1146 fprintf(f, "%02x",
1147 cred->roaming_consortiums[i][j]);
1148 }
1149 fprintf(f, "\"\n");
1150 }
1151
1152 if (cred->sim_num != DEFAULT_USER_SELECTED_SIM)
1153 fprintf(f, "\tsim_num=%d\n", cred->sim_num);
1154
1155 if (cred->engine)
1156 fprintf(f, "\tengine=%d\n", cred->engine);
1157 if (cred->engine_id)
1158 fprintf(f, "\tengine_id=\"%s\"\n", cred->engine_id);
1159 if (cred->key_id)
1160 fprintf(f, "\tkey_id=\"%s\"\n", cred->key_id);
1161 if (cred->cert_id)
1162 fprintf(f, "\tcert_id=\"%s\"\n", cred->cert_id);
1163 if (cred->ca_cert_id)
1164 fprintf(f, "\tca_cert_id=\"%s\"\n", cred->ca_cert_id);
1165
1166 if (cred->imsi_privacy_cert)
1167 fprintf(f, "\timsi_privacy_cert=\"%s\"\n",
1168 cred->imsi_privacy_cert);
1169 if (cred->imsi_privacy_attr)
1170 fprintf(f, "\timsi_privacy_attr=\"%s\"\n",
1171 cred->imsi_privacy_attr);
1172 }
1173
1174
1175 #ifndef CONFIG_NO_CONFIG_BLOBS
wpa_config_write_blob(FILE * f,struct wpa_config_blob * blob)1176 static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
1177 {
1178 char *encoded;
1179
1180 encoded = base64_encode(blob->data, blob->len, NULL);
1181 if (encoded == NULL)
1182 return -1;
1183
1184 fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
1185 os_free(encoded);
1186 return 0;
1187 }
1188 #endif /* CONFIG_NO_CONFIG_BLOBS */
1189
1190
write_global_bin(FILE * f,const char * field,const struct wpabuf * val)1191 static void write_global_bin(FILE *f, const char *field,
1192 const struct wpabuf *val)
1193 {
1194 size_t i;
1195 const u8 *pos;
1196
1197 if (val == NULL)
1198 return;
1199
1200 fprintf(f, "%s=", field);
1201 pos = wpabuf_head(val);
1202 for (i = 0; i < wpabuf_len(val); i++)
1203 fprintf(f, "%02X", *pos++);
1204 fprintf(f, "\n");
1205 }
1206
1207
wpa_config_write_global(FILE * f,struct wpa_config * config)1208 static void wpa_config_write_global(FILE *f, struct wpa_config *config)
1209 {
1210 #ifdef CONFIG_CTRL_IFACE
1211 if (config->ctrl_interface)
1212 fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
1213 if (config->ctrl_interface_group)
1214 fprintf(f, "ctrl_interface_group=%s\n",
1215 config->ctrl_interface_group);
1216 #endif /* CONFIG_CTRL_IFACE */
1217 if (config->eapol_version != DEFAULT_EAPOL_VERSION)
1218 fprintf(f, "eapol_version=%d\n", config->eapol_version);
1219 if (config->ap_scan != DEFAULT_AP_SCAN)
1220 fprintf(f, "ap_scan=%d\n", config->ap_scan);
1221 if (config->disable_scan_offload)
1222 fprintf(f, "disable_scan_offload=%d\n",
1223 config->disable_scan_offload);
1224 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
1225 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
1226 #ifndef CONFIG_OPENSC_ENGINE_PATH
1227 if (config->opensc_engine_path)
1228 fprintf(f, "opensc_engine_path=%s\n",
1229 config->opensc_engine_path);
1230 #endif /* CONFIG_OPENSC_ENGINE_PATH */
1231 #ifndef CONFIG_PKCS11_ENGINE_PATH
1232 if (config->pkcs11_engine_path)
1233 fprintf(f, "pkcs11_engine_path=%s\n",
1234 config->pkcs11_engine_path);
1235 #endif /* CONFIG_PKCS11_ENGINE_PATH */
1236 #ifndef CONFIG_PKCS11_MODULE_PATH
1237 if (config->pkcs11_module_path)
1238 fprintf(f, "pkcs11_module_path=%s\n",
1239 config->pkcs11_module_path);
1240 #endif /* CONFIG_PKCS11_MODULE_PATH */
1241 if (config->openssl_ciphers)
1242 fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers);
1243 if (config->pcsc_reader)
1244 fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader);
1245 if (config->pcsc_pin)
1246 fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin);
1247 if (config->driver_param)
1248 fprintf(f, "driver_param=%s\n", config->driver_param);
1249 if (config->dot11RSNAConfigPMKLifetime)
1250 fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n",
1251 config->dot11RSNAConfigPMKLifetime);
1252 if (config->dot11RSNAConfigPMKReauthThreshold)
1253 fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n",
1254 config->dot11RSNAConfigPMKReauthThreshold);
1255 if (config->dot11RSNAConfigSATimeout)
1256 fprintf(f, "dot11RSNAConfigSATimeout=%u\n",
1257 config->dot11RSNAConfigSATimeout);
1258 if (config->update_config)
1259 fprintf(f, "update_config=%d\n", config->update_config);
1260 #ifdef CONFIG_WPS
1261 if (!is_nil_uuid(config->uuid)) {
1262 char buf[40];
1263 uuid_bin2str(config->uuid, buf, sizeof(buf));
1264 fprintf(f, "uuid=%s\n", buf);
1265 }
1266 if (config->auto_uuid)
1267 fprintf(f, "auto_uuid=%d\n", config->auto_uuid);
1268 if (config->device_name)
1269 fprintf(f, "device_name=%s\n", config->device_name);
1270 if (config->manufacturer)
1271 fprintf(f, "manufacturer=%s\n", config->manufacturer);
1272 if (config->model_name)
1273 fprintf(f, "model_name=%s\n", config->model_name);
1274 if (config->model_number)
1275 fprintf(f, "model_number=%s\n", config->model_number);
1276 if (config->serial_number)
1277 fprintf(f, "serial_number=%s\n", config->serial_number);
1278 {
1279 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1280 buf = wps_dev_type_bin2str(config->device_type,
1281 _buf, sizeof(_buf));
1282 if (os_strcmp(buf, "0-00000000-0") != 0)
1283 fprintf(f, "device_type=%s\n", buf);
1284 }
1285 if (WPA_GET_BE32(config->os_version))
1286 fprintf(f, "os_version=%08x\n",
1287 WPA_GET_BE32(config->os_version));
1288 if (config->config_methods)
1289 fprintf(f, "config_methods=%s\n", config->config_methods);
1290 if (config->wps_cred_processing)
1291 fprintf(f, "wps_cred_processing=%d\n",
1292 config->wps_cred_processing);
1293 if (config->wps_cred_add_sae)
1294 fprintf(f, "wps_cred_add_sae=%d\n",
1295 config->wps_cred_add_sae);
1296 if (config->wps_vendor_ext_m1) {
1297 int i, len = wpabuf_len(config->wps_vendor_ext_m1);
1298 const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1);
1299 if (len > 0) {
1300 fprintf(f, "wps_vendor_ext_m1=");
1301 for (i = 0; i < len; i++)
1302 fprintf(f, "%02x", *p++);
1303 fprintf(f, "\n");
1304 }
1305 }
1306 #endif /* CONFIG_WPS */
1307 #ifdef CONFIG_P2P
1308 {
1309 int i;
1310 char _buf[WPS_DEV_TYPE_BUFSIZE], *buf;
1311
1312 for (i = 0; i < config->num_sec_device_types; i++) {
1313 buf = wps_dev_type_bin2str(config->sec_device_type[i],
1314 _buf, sizeof(_buf));
1315 if (buf)
1316 fprintf(f, "sec_device_type=%s\n", buf);
1317 }
1318 }
1319 if (config->p2p_listen_reg_class)
1320 fprintf(f, "p2p_listen_reg_class=%d\n",
1321 config->p2p_listen_reg_class);
1322 if (config->p2p_listen_channel)
1323 fprintf(f, "p2p_listen_channel=%d\n",
1324 config->p2p_listen_channel);
1325 if (config->p2p_oper_reg_class)
1326 fprintf(f, "p2p_oper_reg_class=%d\n",
1327 config->p2p_oper_reg_class);
1328 if (config->p2p_oper_channel)
1329 fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel);
1330 if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT)
1331 fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent);
1332 if (config->p2p_ssid_postfix)
1333 fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix);
1334 if (config->persistent_reconnect)
1335 fprintf(f, "persistent_reconnect=%d\n",
1336 config->persistent_reconnect);
1337 if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS)
1338 fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss);
1339 if (config->p2p_group_idle)
1340 fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle);
1341 if (config->p2p_passphrase_len)
1342 fprintf(f, "p2p_passphrase_len=%u\n",
1343 config->p2p_passphrase_len);
1344 if (config->p2p_pref_chan) {
1345 unsigned int i;
1346 fprintf(f, "p2p_pref_chan=");
1347 for (i = 0; i < config->num_p2p_pref_chan; i++) {
1348 fprintf(f, "%s%u:%u", i > 0 ? "," : "",
1349 config->p2p_pref_chan[i].op_class,
1350 config->p2p_pref_chan[i].chan);
1351 }
1352 fprintf(f, "\n");
1353 }
1354 if (config->p2p_no_go_freq.num) {
1355 char *val = freq_range_list_str(&config->p2p_no_go_freq);
1356 if (val) {
1357 fprintf(f, "p2p_no_go_freq=%s\n", val);
1358 os_free(val);
1359 }
1360 }
1361 if (config->p2p_add_cli_chan)
1362 fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan);
1363 if (config->p2p_optimize_listen_chan !=
1364 DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN)
1365 fprintf(f, "p2p_optimize_listen_chan=%d\n",
1366 config->p2p_optimize_listen_chan);
1367 if (config->p2p_go_ht40)
1368 fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40);
1369 if (config->p2p_go_vht)
1370 fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht);
1371 if (config->p2p_go_he)
1372 fprintf(f, "p2p_go_he=%d\n", config->p2p_go_he);
1373 if (config->p2p_go_edmg)
1374 fprintf(f, "p2p_go_edmg=%d\n", config->p2p_go_edmg);
1375 if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW)
1376 fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow);
1377 if (config->p2p_disabled)
1378 fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled);
1379 if (config->p2p_no_group_iface)
1380 fprintf(f, "p2p_no_group_iface=%d\n",
1381 config->p2p_no_group_iface);
1382 if (config->p2p_ignore_shared_freq)
1383 fprintf(f, "p2p_ignore_shared_freq=%d\n",
1384 config->p2p_ignore_shared_freq);
1385 if (config->p2p_cli_probe)
1386 fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe);
1387 if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE)
1388 fprintf(f, "p2p_go_freq_change_policy=%u\n",
1389 config->p2p_go_freq_change_policy);
1390
1391 if (config->p2p_6ghz_disable)
1392 fprintf(f, "p2p_6ghz_disable=%d\n", config->p2p_6ghz_disable);
1393
1394 if (config->p2p_pairing_setup)
1395 fprintf(f, "p2p_pairing_setup=%d\n", config->p2p_pairing_setup);
1396 if (config->p2p_pairing_cache)
1397 fprintf(f, "p2p_pairing_cache=%d\n", config->p2p_pairing_cache);
1398 if (config->p2p_bootstrap_methods)
1399 fprintf(f, "p2p_bootstrap_methods=%d\n",
1400 config->p2p_bootstrap_methods);
1401 if (config->p2p_pasn_type)
1402 fprintf(f, "p2p_pasn_type=%d\n", config->p2p_pasn_type);
1403 if (config->p2p_comeback_after)
1404 fprintf(f, "p2p_comeback_after=%d\n",
1405 config->p2p_comeback_after);
1406 if (config->p2p_twt_power_mgmt)
1407 fprintf(f, "p2p_twt_power_mgmt=%d\n",
1408 config->p2p_twt_power_mgmt);
1409 if (config->p2p_chan_switch_req_enable)
1410 fprintf(f, "p2p_chan_switch_req_enable=%d\n",
1411 config->p2p_chan_switch_req_enable);
1412 if (config->p2p_reg_info)
1413 fprintf(f, "p2p_reg_info=%d\n", config->p2p_reg_info);
1414
1415 if (WPA_GET_BE32(config->ip_addr_go))
1416 fprintf(f, "ip_addr_go=%u.%u.%u.%u\n",
1417 config->ip_addr_go[0], config->ip_addr_go[1],
1418 config->ip_addr_go[2], config->ip_addr_go[3]);
1419 if (WPA_GET_BE32(config->ip_addr_mask))
1420 fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n",
1421 config->ip_addr_mask[0], config->ip_addr_mask[1],
1422 config->ip_addr_mask[2], config->ip_addr_mask[3]);
1423 if (WPA_GET_BE32(config->ip_addr_start))
1424 fprintf(f, "ip_addr_start=%u.%u.%u.%u\n",
1425 config->ip_addr_start[0], config->ip_addr_start[1],
1426 config->ip_addr_start[2], config->ip_addr_start[3]);
1427 if (WPA_GET_BE32(config->ip_addr_end))
1428 fprintf(f, "ip_addr_end=%u.%u.%u.%u\n",
1429 config->ip_addr_end[0], config->ip_addr_end[1],
1430 config->ip_addr_end[2], config->ip_addr_end[3]);
1431 #endif /* CONFIG_P2P */
1432 if (config->country[0] && config->country[1]) {
1433 fprintf(f, "country=%c%c\n",
1434 config->country[0], config->country[1]);
1435 }
1436 if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
1437 fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
1438 if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE)
1439 fprintf(f, "bss_expiration_age=%u\n",
1440 config->bss_expiration_age);
1441 if (config->bss_expiration_scan_count !=
1442 DEFAULT_BSS_EXPIRATION_SCAN_COUNT)
1443 fprintf(f, "bss_expiration_scan_count=%u\n",
1444 config->bss_expiration_scan_count);
1445 if (config->filter_ssids)
1446 fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
1447 if (config->filter_rssi)
1448 fprintf(f, "filter_rssi=%d\n", config->filter_rssi);
1449 if (config->max_num_sta != DEFAULT_MAX_NUM_STA)
1450 fprintf(f, "max_num_sta=%u\n", config->max_num_sta);
1451 if (config->ap_isolate != DEFAULT_AP_ISOLATE)
1452 fprintf(f, "ap_isolate=%u\n", config->ap_isolate);
1453 if (config->disassoc_low_ack)
1454 fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack);
1455 #ifdef CONFIG_HS20
1456 if (config->hs20)
1457 fprintf(f, "hs20=1\n");
1458 #endif /* CONFIG_HS20 */
1459 #ifdef CONFIG_INTERWORKING
1460 if (config->interworking)
1461 fprintf(f, "interworking=%d\n", config->interworking);
1462 if (!is_zero_ether_addr(config->hessid))
1463 fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid));
1464 if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE)
1465 fprintf(f, "access_network_type=%d\n",
1466 config->access_network_type);
1467 if (config->go_interworking)
1468 fprintf(f, "go_interworking=%d\n", config->go_interworking);
1469 if (config->go_access_network_type)
1470 fprintf(f, "go_access_network_type=%d\n",
1471 config->go_access_network_type);
1472 if (config->go_internet)
1473 fprintf(f, "go_internet=%d\n", config->go_internet);
1474 if (config->go_venue_group)
1475 fprintf(f, "go_venue_group=%d\n", config->go_venue_group);
1476 if (config->go_venue_type)
1477 fprintf(f, "go_venue_type=%d\n", config->go_venue_type);
1478 #endif /* CONFIG_INTERWORKING */
1479 if (config->pbc_in_m1)
1480 fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1);
1481 if (config->wps_nfc_pw_from_config) {
1482 if (config->wps_nfc_dev_pw_id)
1483 fprintf(f, "wps_nfc_dev_pw_id=%d\n",
1484 config->wps_nfc_dev_pw_id);
1485 write_global_bin(f, "wps_nfc_dh_pubkey",
1486 config->wps_nfc_dh_pubkey);
1487 write_global_bin(f, "wps_nfc_dh_privkey",
1488 config->wps_nfc_dh_privkey);
1489 write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw);
1490 }
1491
1492 if (config->ext_password_backend)
1493 fprintf(f, "ext_password_backend=%s\n",
1494 config->ext_password_backend);
1495 if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY)
1496 fprintf(f, "p2p_go_max_inactivity=%d\n",
1497 config->p2p_go_max_inactivity);
1498 if (config->auto_interworking)
1499 fprintf(f, "auto_interworking=%d\n",
1500 config->auto_interworking);
1501 if (config->okc)
1502 fprintf(f, "okc=%d\n", config->okc);
1503 if (config->pmf)
1504 fprintf(f, "pmf=%d\n", config->pmf);
1505 if (config->dtim_period)
1506 fprintf(f, "dtim_period=%d\n", config->dtim_period);
1507 if (config->beacon_int)
1508 fprintf(f, "beacon_int=%d\n", config->beacon_int);
1509
1510 if (config->sae_check_mfp)
1511 fprintf(f, "sae_check_mfp=%d\n", config->sae_check_mfp);
1512
1513 if (config->sae_groups) {
1514 int i;
1515 fprintf(f, "sae_groups=");
1516 for (i = 0; config->sae_groups[i] > 0; i++) {
1517 fprintf(f, "%s%d", i > 0 ? " " : "",
1518 config->sae_groups[i]);
1519 }
1520 fprintf(f, "\n");
1521 }
1522
1523 if (config->sae_pwe)
1524 fprintf(f, "sae_pwe=%d\n", config->sae_pwe);
1525
1526 if (config->sae_pmkid_in_assoc)
1527 fprintf(f, "sae_pmkid_in_assoc=%d\n",
1528 config->sae_pmkid_in_assoc);
1529
1530 if (config->ap_vendor_elements) {
1531 int i, len = wpabuf_len(config->ap_vendor_elements);
1532 const u8 *p = wpabuf_head_u8(config->ap_vendor_elements);
1533 if (len > 0) {
1534 fprintf(f, "ap_vendor_elements=");
1535 for (i = 0; i < len; i++)
1536 fprintf(f, "%02x", *p++);
1537 fprintf(f, "\n");
1538 }
1539 }
1540
1541 if (config->ap_assocresp_elements) {
1542 int i, len = wpabuf_len(config->ap_assocresp_elements);
1543 const u8 *p = wpabuf_head_u8(config->ap_assocresp_elements);
1544
1545 if (len > 0) {
1546 fprintf(f, "ap_assocresp_elements=");
1547 for (i = 0; i < len; i++)
1548 fprintf(f, "%02x", *p++);
1549 fprintf(f, "\n");
1550 }
1551 }
1552
1553 if (config->ignore_old_scan_res)
1554 fprintf(f, "ignore_old_scan_res=%d\n",
1555 config->ignore_old_scan_res);
1556
1557 if (config->freq_list && config->freq_list[0]) {
1558 int i;
1559 fprintf(f, "freq_list=");
1560 for (i = 0; config->freq_list[i]; i++) {
1561 fprintf(f, "%s%d", i > 0 ? " " : "",
1562 config->freq_list[i]);
1563 }
1564 fprintf(f, "\n");
1565 }
1566 if (config->initial_freq_list && config->initial_freq_list[0]) {
1567 int i;
1568 fprintf(f, "initial_freq_list=");
1569 for (i = 0; config->initial_freq_list[i]; i++) {
1570 fprintf(f, "%s%d", i > 0 ? " " : "",
1571 config->initial_freq_list[i]);
1572 }
1573 fprintf(f, "\n");
1574 }
1575 if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ)
1576 fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq);
1577
1578 if (config->scan_res_valid_for_connect !=
1579 DEFAULT_SCAN_RES_VALID_FOR_CONNECT)
1580 fprintf(f, "scan_res_valid_for_connect=%d\n",
1581 config->scan_res_valid_for_connect);
1582
1583 if (config->sched_scan_interval)
1584 fprintf(f, "sched_scan_interval=%u\n",
1585 config->sched_scan_interval);
1586
1587 if (config->sched_scan_start_delay)
1588 fprintf(f, "sched_scan_start_delay=%u\n",
1589 config->sched_scan_start_delay);
1590
1591 if (config->external_sim)
1592 fprintf(f, "external_sim=%d\n", config->external_sim);
1593
1594 if (config->tdls_external_control)
1595 fprintf(f, "tdls_external_control=%d\n",
1596 config->tdls_external_control);
1597
1598 if (config->wowlan_triggers)
1599 fprintf(f, "wowlan_triggers=%s\n",
1600 config->wowlan_triggers);
1601
1602 if (config->bgscan)
1603 fprintf(f, "bgscan=\"%s\"\n", config->bgscan);
1604
1605 if (config->autoscan)
1606 fprintf(f, "autoscan=%s\n", config->autoscan);
1607
1608 if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY)
1609 fprintf(f, "p2p_search_delay=%u\n",
1610 config->p2p_search_delay);
1611
1612 if (config->mac_addr)
1613 fprintf(f, "mac_addr=%d\n", config->mac_addr);
1614
1615 if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1616 fprintf(f, "rand_addr_lifetime=%u\n",
1617 config->rand_addr_lifetime);
1618
1619 if (config->preassoc_mac_addr)
1620 fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr);
1621
1622 if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD)
1623 fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload);
1624
1625 if (config->user_mpm != DEFAULT_USER_MPM)
1626 fprintf(f, "user_mpm=%d\n", config->user_mpm);
1627
1628 if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS)
1629 fprintf(f, "max_peer_links=%d\n", config->max_peer_links);
1630
1631 if (config->cert_in_cb != DEFAULT_CERT_IN_CB)
1632 fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb);
1633
1634 if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY)
1635 fprintf(f, "mesh_max_inactivity=%d\n",
1636 config->mesh_max_inactivity);
1637
1638 if (config->mesh_fwding != DEFAULT_MESH_FWDING)
1639 fprintf(f, "mesh_fwding=%d\n", config->mesh_fwding);
1640
1641 if (config->dot11RSNASAERetransPeriod !=
1642 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD)
1643 fprintf(f, "dot11RSNASAERetransPeriod=%d\n",
1644 config->dot11RSNASAERetransPeriod);
1645
1646 if (config->passive_scan)
1647 fprintf(f, "passive_scan=%d\n", config->passive_scan);
1648
1649 if (config->reassoc_same_bss_optim)
1650 fprintf(f, "reassoc_same_bss_optim=%d\n",
1651 config->reassoc_same_bss_optim);
1652
1653 if (config->wps_priority)
1654 fprintf(f, "wps_priority=%d\n", config->wps_priority);
1655
1656 if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION)
1657 fprintf(f, "wpa_rsc_relaxation=%d\n",
1658 config->wpa_rsc_relaxation);
1659
1660 if (config->sched_scan_plans)
1661 fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans);
1662
1663 #ifdef CONFIG_MBO
1664 if (config->non_pref_chan)
1665 fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan);
1666 if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA)
1667 fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa);
1668 if (config->disassoc_imminent_rssi_threshold !=
1669 DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD)
1670 fprintf(f, "disassoc_imminent_rssi_threshold=%d\n",
1671 config->disassoc_imminent_rssi_threshold);
1672 if (config->oce != DEFAULT_OCE_SUPPORT)
1673 fprintf(f, "oce=%u\n", config->oce);
1674 #endif /* CONFIG_MBO */
1675
1676 if (config->gas_address3)
1677 fprintf(f, "gas_address3=%d\n", config->gas_address3);
1678
1679 if (config->ftm_responder)
1680 fprintf(f, "ftm_responder=%d\n", config->ftm_responder);
1681 if (config->ftm_initiator)
1682 fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator);
1683
1684 if (config->twt_requester)
1685 fprintf(f, "twt_requester=%d\n", config->twt_requester);
1686
1687 if (config->fst_group_id)
1688 fprintf(f, "fst_group_id=%s\n", config->fst_group_id);
1689 if (config->fst_priority)
1690 fprintf(f, "fst_priority=%d\n", config->fst_priority);
1691 if (config->fst_llt)
1692 fprintf(f, "fst_llt=%d\n", config->fst_llt);
1693
1694 if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME)
1695 fprintf(f, "gas_rand_addr_lifetime=%u\n",
1696 config->gas_rand_addr_lifetime);
1697 if (config->gas_rand_mac_addr)
1698 fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr);
1699 if (config->dpp_config_processing)
1700 fprintf(f, "dpp_config_processing=%d\n",
1701 config->dpp_config_processing);
1702 if (config->dpp_name)
1703 fprintf(f, "dpp_name=%s\n", config->dpp_name);
1704 if (config->dpp_mud_url)
1705 fprintf(f, "dpp_mud_url=%s\n", config->dpp_mud_url);
1706 if (config->dpp_extra_conf_req_name)
1707 fprintf(f, "dpp_extra_conf_req_name=%s\n",
1708 config->dpp_extra_conf_req_name);
1709 if (config->dpp_extra_conf_req_value)
1710 fprintf(f, "dpp_extra_conf_req_value=%s\n",
1711 config->dpp_extra_conf_req_value);
1712 if (config->dpp_connector_privacy_default)
1713 fprintf(f, "dpp_connector_privacy_default=%d\n",
1714 config->dpp_connector_privacy_default);
1715 if (config->coloc_intf_reporting)
1716 fprintf(f, "coloc_intf_reporting=%d\n",
1717 config->coloc_intf_reporting);
1718 if (config->p2p_device_random_mac_addr)
1719 fprintf(f, "p2p_device_random_mac_addr=%d\n",
1720 config->p2p_device_random_mac_addr);
1721 if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr))
1722 fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n",
1723 MAC2STR(config->p2p_device_persistent_mac_addr));
1724 if (config->p2p_interface_random_mac_addr)
1725 fprintf(f, "p2p_interface_random_mac_addr=%d\n",
1726 config->p2p_interface_random_mac_addr);
1727 if (config->disable_btm)
1728 fprintf(f, "disable_btm=1\n");
1729 if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID)
1730 fprintf(f, "extended_key_id=%d\n",
1731 config->extended_key_id);
1732 if (config->wowlan_disconnect_on_deinit)
1733 fprintf(f, "wowlan_disconnect_on_deinit=%d\n",
1734 config->wowlan_disconnect_on_deinit);
1735 if (config->rsn_overriding)
1736 fprintf(f, "rsn_overriding=%d\n", config->rsn_overriding);
1737 #ifdef CONFIG_TESTING_OPTIONS
1738 if (config->mld_force_single_link)
1739 fprintf(f, "mld_force_single_link=1\n");
1740 if (config->mld_connect_band_pref != MLD_CONNECT_BAND_PREF_AUTO)
1741 fprintf(f, "mld_connect_band_pref=%d\n",
1742 config->mld_connect_band_pref);
1743 if (!is_zero_ether_addr(config->mld_connect_bssid_pref))
1744 fprintf(f, "mld_connect_bssid_pref=" MACSTR "\n",
1745 MAC2STR(config->mld_connect_bssid_pref));
1746 #endif /* CONFIG_TESTING_OPTIONS */
1747 if (config->ft_prepend_pmkid)
1748 fprintf(f, "ft_prepend_pmkid=%d\n", config->ft_prepend_pmkid);
1749 if (config->dik) {
1750 fprintf(f, "dik_cipher=%d\n", config->dik_cipher);
1751 write_global_bin(f, "dik", config->dik);
1752 }
1753 if (config->wfa_gen_capa)
1754 fprintf(f, "wfa_gen_capa=%d\n", config->wfa_gen_capa);
1755 write_global_bin(f, "wfa_gen_capa_supp", config->wfa_gen_capa_supp);
1756 write_global_bin(f, "wfa_gen_capa_cert", config->wfa_gen_capa_cert);
1757 }
1758
wpa_config_write_identity(FILE * f,struct wpa_dev_ik * dev_ik)1759 static void wpa_config_write_identity(FILE *f, struct wpa_dev_ik *dev_ik)
1760 {
1761 fprintf(f, "\tdik_cipher=%d\n", dev_ik->dik_cipher);
1762
1763 if (dev_ik->dik)
1764 write_global_bin(f, "\tdik", dev_ik->dik);
1765
1766 if (dev_ik->pmk)
1767 write_global_bin(f, "\tpmk", dev_ik->pmk);
1768
1769 if (dev_ik->pmkid)
1770 write_global_bin(f, "\tpmkid", dev_ik->pmkid);
1771 }
1772
1773 #endif /* CONFIG_NO_CONFIG_WRITE */
1774
1775
wpa_config_write(const char * name,struct wpa_config * config)1776 int wpa_config_write(const char *name, struct wpa_config *config)
1777 {
1778 #ifndef CONFIG_NO_CONFIG_WRITE
1779 FILE *f;
1780 struct wpa_ssid *ssid;
1781 struct wpa_cred *cred;
1782 struct wpa_dev_ik *dev_ik;
1783 #ifndef CONFIG_NO_CONFIG_BLOBS
1784 struct wpa_config_blob *blob;
1785 #endif /* CONFIG_NO_CONFIG_BLOBS */
1786 int ret = 0;
1787 const char *orig_name = name;
1788 int tmp_len;
1789 char *tmp_name;
1790
1791 if (!name) {
1792 wpa_printf(MSG_ERROR, "No configuration file for writing");
1793 return -1;
1794 }
1795
1796 tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
1797 tmp_name = os_malloc(tmp_len);
1798 if (tmp_name) {
1799 os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
1800 name = tmp_name;
1801 }
1802
1803 wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
1804
1805 f = fopen(name, "w");
1806 if (f == NULL) {
1807 wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
1808 os_free(tmp_name);
1809 return -1;
1810 }
1811
1812 wpa_config_write_global(f, config);
1813
1814 for (cred = config->cred; cred; cred = cred->next) {
1815 if (cred->temporary)
1816 continue;
1817 fprintf(f, "\ncred={\n");
1818 wpa_config_write_cred(f, cred);
1819 fprintf(f, "}\n");
1820 }
1821
1822 for (ssid = config->ssid; ssid; ssid = ssid->next) {
1823 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary ||
1824 ssid->ro)
1825 continue; /* do not save temporary networks */
1826 if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt) &&
1827 !ssid->psk_set && !ssid->passphrase)
1828 continue; /* do not save invalid network */
1829 if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
1830 !ssid->passphrase && !ssid->sae_password &&
1831 !ssid->pmk_valid)
1832 continue; /* do not save invalid network */
1833 fprintf(f, "\nnetwork={\n");
1834 wpa_config_write_network(f, ssid);
1835 fprintf(f, "}\n");
1836 }
1837
1838 for (dev_ik = config->identity; dev_ik; dev_ik = dev_ik->next) {
1839 fprintf(f, "\nidentity={\n");
1840 wpa_config_write_identity(f, dev_ik);
1841 fprintf(f, "}\n");
1842 }
1843
1844 #ifndef CONFIG_NO_CONFIG_BLOBS
1845 for (blob = config->blobs; blob; blob = blob->next) {
1846 ret = wpa_config_write_blob(f, blob);
1847 if (ret)
1848 break;
1849 }
1850 #endif /* CONFIG_NO_CONFIG_BLOBS */
1851
1852 os_fdatasync(f);
1853
1854 fclose(f);
1855
1856 if (tmp_name) {
1857 int chmod_ret = 0;
1858
1859 #ifdef ANDROID
1860 chmod_ret = chmod(tmp_name,
1861 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
1862 #endif /* ANDROID */
1863 if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0)
1864 ret = -1;
1865
1866 os_free(tmp_name);
1867 }
1868
1869 wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
1870 orig_name, ret ? "un" : "");
1871 return ret;
1872 #else /* CONFIG_NO_CONFIG_WRITE */
1873 return -1;
1874 #endif /* CONFIG_NO_CONFIG_WRITE */
1875 }
1876