139beb93cSSam Leffler /* 239beb93cSSam Leffler * WPA Supplicant / Configuration backend: text file 3c1d255d3SCy Schubert * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi> 439beb93cSSam Leffler * 5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license. 6f05cddf9SRui Paulo * See README for more details. 739beb93cSSam Leffler * 839beb93cSSam Leffler * This file implements a configuration backend for text files. All the 939beb93cSSam Leffler * configuration information is stored in a text file that uses a format 1039beb93cSSam Leffler * described in the sample configuration file, wpa_supplicant.conf. 1139beb93cSSam Leffler */ 1239beb93cSSam Leffler 1339beb93cSSam Leffler #include "includes.h" 145b9c547cSRui Paulo #ifdef ANDROID 155b9c547cSRui Paulo #include <sys/stat.h> 165b9c547cSRui Paulo #endif /* ANDROID */ 1739beb93cSSam Leffler 1839beb93cSSam Leffler #include "common.h" 1939beb93cSSam Leffler #include "config.h" 2039beb93cSSam Leffler #include "base64.h" 2139beb93cSSam Leffler #include "uuid.h" 2285732ac8SCy Schubert #include "common/ieee802_1x_defs.h" 23f05cddf9SRui Paulo #include "p2p/p2p.h" 2439beb93cSSam Leffler #include "eap_peer/eap_methods.h" 25f05cddf9SRui Paulo #include "eap_peer/eap.h" 26c1d255d3SCy Schubert #include "utils/config.h" 2739beb93cSSam Leffler 2839beb93cSSam Leffler 2939beb93cSSam Leffler static int wpa_config_validate_network(struct wpa_ssid *ssid, int line) 3039beb93cSSam Leffler { 3139beb93cSSam Leffler int errors = 0; 3239beb93cSSam Leffler 3339beb93cSSam Leffler if (ssid->passphrase) { 3439beb93cSSam Leffler if (ssid->psk_set) { 3539beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: both PSK and " 3639beb93cSSam Leffler "passphrase configured.", line); 3739beb93cSSam Leffler errors++; 3839beb93cSSam Leffler } 3939beb93cSSam Leffler wpa_config_update_psk(ssid); 4039beb93cSSam Leffler } 4139beb93cSSam Leffler 4285732ac8SCy Schubert if (ssid->disabled == 2) 4385732ac8SCy Schubert ssid->p2p_persistent_group = 1; 4485732ac8SCy Schubert 4539beb93cSSam Leffler if ((ssid->group_cipher & WPA_CIPHER_CCMP) && 4685732ac8SCy Schubert !(ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 | 4785732ac8SCy Schubert WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256 | 4885732ac8SCy Schubert WPA_CIPHER_NONE))) { 4939beb93cSSam Leffler /* Group cipher cannot be stronger than the pairwise cipher. */ 5039beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher" 5139beb93cSSam Leffler " list since it was not allowed for pairwise " 5239beb93cSSam Leffler "cipher", line); 5339beb93cSSam Leffler ssid->group_cipher &= ~WPA_CIPHER_CCMP; 5439beb93cSSam Leffler } 5539beb93cSSam Leffler 565b9c547cSRui Paulo if (ssid->mode == WPAS_MODE_MESH && 575b9c547cSRui Paulo (ssid->key_mgmt != WPA_KEY_MGMT_NONE && 585b9c547cSRui Paulo ssid->key_mgmt != WPA_KEY_MGMT_SAE)) { 595b9c547cSRui Paulo wpa_printf(MSG_ERROR, 605b9c547cSRui Paulo "Line %d: key_mgmt for mesh network should be open or SAE", 615b9c547cSRui Paulo line); 625b9c547cSRui Paulo errors++; 635b9c547cSRui Paulo } 645b9c547cSRui Paulo 654bc52338SCy Schubert #ifdef CONFIG_OCV 664bc52338SCy Schubert if (ssid->ocv && ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION) { 674bc52338SCy Schubert wpa_printf(MSG_ERROR, 684bc52338SCy Schubert "Line %d: PMF needs to be enabled whenever using OCV", 694bc52338SCy Schubert line); 704bc52338SCy Schubert errors++; 714bc52338SCy Schubert } 724bc52338SCy Schubert #endif /* CONFIG_OCV */ 734bc52338SCy Schubert 7439beb93cSSam Leffler return errors; 7539beb93cSSam Leffler } 7639beb93cSSam Leffler 7739beb93cSSam Leffler 7839beb93cSSam Leffler static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id) 7939beb93cSSam Leffler { 8039beb93cSSam Leffler struct wpa_ssid *ssid; 8139beb93cSSam Leffler int errors = 0, end = 0; 82f05cddf9SRui Paulo char buf[2000], *pos, *pos2; 8339beb93cSSam Leffler 8439beb93cSSam Leffler wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block", 8539beb93cSSam Leffler *line); 8639beb93cSSam Leffler ssid = os_zalloc(sizeof(*ssid)); 8739beb93cSSam Leffler if (ssid == NULL) 8839beb93cSSam Leffler return NULL; 895b9c547cSRui Paulo dl_list_init(&ssid->psk_list); 9039beb93cSSam Leffler ssid->id = id; 9139beb93cSSam Leffler 9239beb93cSSam Leffler wpa_config_set_network_defaults(ssid); 9339beb93cSSam Leffler 9439beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 9539beb93cSSam Leffler if (os_strcmp(pos, "}") == 0) { 9639beb93cSSam Leffler end = 1; 9739beb93cSSam Leffler break; 9839beb93cSSam Leffler } 9939beb93cSSam Leffler 10039beb93cSSam Leffler pos2 = os_strchr(pos, '='); 10139beb93cSSam Leffler if (pos2 == NULL) { 10239beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line " 10339beb93cSSam Leffler "'%s'.", *line, pos); 10439beb93cSSam Leffler errors++; 10539beb93cSSam Leffler continue; 10639beb93cSSam Leffler } 10739beb93cSSam Leffler 10839beb93cSSam Leffler *pos2++ = '\0'; 10939beb93cSSam Leffler if (*pos2 == '"') { 11039beb93cSSam Leffler if (os_strchr(pos2 + 1, '"') == NULL) { 11139beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: invalid " 11239beb93cSSam Leffler "quotation '%s'.", *line, pos2); 11339beb93cSSam Leffler errors++; 11439beb93cSSam Leffler continue; 11539beb93cSSam Leffler } 11639beb93cSSam Leffler } 11739beb93cSSam Leffler 118c1d255d3SCy Schubert if (wpa_config_set(ssid, pos, pos2, *line) < 0) { 119c1d255d3SCy Schubert #ifndef CONFIG_WEP 120c1d255d3SCy Schubert if (os_strcmp(pos, "wep_key0") == 0 || 121c1d255d3SCy Schubert os_strcmp(pos, "wep_key1") == 0 || 122c1d255d3SCy Schubert os_strcmp(pos, "wep_key2") == 0 || 123c1d255d3SCy Schubert os_strcmp(pos, "wep_key3") == 0 || 124c1d255d3SCy Schubert os_strcmp(pos, "wep_tx_keyidx") == 0) { 125c1d255d3SCy Schubert wpa_printf(MSG_ERROR, 126c1d255d3SCy Schubert "Line %d: unsupported WEP parameter", 127c1d255d3SCy Schubert *line); 128c1d255d3SCy Schubert ssid->disabled = 1; 129c1d255d3SCy Schubert continue; 130c1d255d3SCy Schubert } 131c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 13239beb93cSSam Leffler errors++; 13339beb93cSSam Leffler } 134c1d255d3SCy Schubert } 13539beb93cSSam Leffler 13639beb93cSSam Leffler if (!end) { 13739beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: network block was not " 13839beb93cSSam Leffler "terminated properly.", *line); 13939beb93cSSam Leffler errors++; 14039beb93cSSam Leffler } 14139beb93cSSam Leffler 14239beb93cSSam Leffler errors += wpa_config_validate_network(ssid, *line); 14339beb93cSSam Leffler 14439beb93cSSam Leffler if (errors) { 14539beb93cSSam Leffler wpa_config_free_ssid(ssid); 14639beb93cSSam Leffler ssid = NULL; 14739beb93cSSam Leffler } 14839beb93cSSam Leffler 14939beb93cSSam Leffler return ssid; 15039beb93cSSam Leffler } 15139beb93cSSam Leffler 15239beb93cSSam Leffler 153f05cddf9SRui Paulo static struct wpa_cred * wpa_config_read_cred(FILE *f, int *line, int id) 154f05cddf9SRui Paulo { 155f05cddf9SRui Paulo struct wpa_cred *cred; 156f05cddf9SRui Paulo int errors = 0, end = 0; 157f05cddf9SRui Paulo char buf[256], *pos, *pos2; 158f05cddf9SRui Paulo 159f05cddf9SRui Paulo wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new cred block", *line); 160f05cddf9SRui Paulo cred = os_zalloc(sizeof(*cred)); 161f05cddf9SRui Paulo if (cred == NULL) 162f05cddf9SRui Paulo return NULL; 163f05cddf9SRui Paulo cred->id = id; 1645b9c547cSRui Paulo cred->sim_num = DEFAULT_USER_SELECTED_SIM; 165f05cddf9SRui Paulo 166f05cddf9SRui Paulo while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 167f05cddf9SRui Paulo if (os_strcmp(pos, "}") == 0) { 168f05cddf9SRui Paulo end = 1; 169f05cddf9SRui Paulo break; 170f05cddf9SRui Paulo } 171f05cddf9SRui Paulo 172f05cddf9SRui Paulo pos2 = os_strchr(pos, '='); 173f05cddf9SRui Paulo if (pos2 == NULL) { 174f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: Invalid cred line " 175f05cddf9SRui Paulo "'%s'.", *line, pos); 176f05cddf9SRui Paulo errors++; 177f05cddf9SRui Paulo continue; 178f05cddf9SRui Paulo } 179f05cddf9SRui Paulo 180f05cddf9SRui Paulo *pos2++ = '\0'; 181f05cddf9SRui Paulo if (*pos2 == '"') { 182f05cddf9SRui Paulo if (os_strchr(pos2 + 1, '"') == NULL) { 183f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: invalid " 184f05cddf9SRui Paulo "quotation '%s'.", *line, pos2); 185f05cddf9SRui Paulo errors++; 186f05cddf9SRui Paulo continue; 187f05cddf9SRui Paulo } 188f05cddf9SRui Paulo } 189f05cddf9SRui Paulo 190f05cddf9SRui Paulo if (wpa_config_set_cred(cred, pos, pos2, *line) < 0) 191f05cddf9SRui Paulo errors++; 192f05cddf9SRui Paulo } 193f05cddf9SRui Paulo 194f05cddf9SRui Paulo if (!end) { 195f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: cred block was not " 196f05cddf9SRui Paulo "terminated properly.", *line); 197f05cddf9SRui Paulo errors++; 198f05cddf9SRui Paulo } 199f05cddf9SRui Paulo 200f05cddf9SRui Paulo if (errors) { 201f05cddf9SRui Paulo wpa_config_free_cred(cred); 202f05cddf9SRui Paulo cred = NULL; 203f05cddf9SRui Paulo } 204f05cddf9SRui Paulo 205f05cddf9SRui Paulo return cred; 206f05cddf9SRui Paulo } 207f05cddf9SRui Paulo 208f05cddf9SRui Paulo 20939beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 21039beb93cSSam Leffler static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line, 21139beb93cSSam Leffler const char *name) 21239beb93cSSam Leffler { 21339beb93cSSam Leffler struct wpa_config_blob *blob; 21439beb93cSSam Leffler char buf[256], *pos; 215c1d255d3SCy Schubert char *encoded = NULL, *nencoded; 21639beb93cSSam Leffler int end = 0; 21739beb93cSSam Leffler size_t encoded_len = 0, len; 21839beb93cSSam Leffler 21939beb93cSSam Leffler wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'", 22039beb93cSSam Leffler *line, name); 22139beb93cSSam Leffler 22239beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 22339beb93cSSam Leffler if (os_strcmp(pos, "}") == 0) { 22439beb93cSSam Leffler end = 1; 22539beb93cSSam Leffler break; 22639beb93cSSam Leffler } 22739beb93cSSam Leffler 22839beb93cSSam Leffler len = os_strlen(pos); 22939beb93cSSam Leffler nencoded = os_realloc(encoded, encoded_len + len); 23039beb93cSSam Leffler if (nencoded == NULL) { 23139beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: not enough memory for " 23239beb93cSSam Leffler "blob", *line); 23339beb93cSSam Leffler os_free(encoded); 23439beb93cSSam Leffler return NULL; 23539beb93cSSam Leffler } 23639beb93cSSam Leffler encoded = nencoded; 23739beb93cSSam Leffler os_memcpy(encoded + encoded_len, pos, len); 23839beb93cSSam Leffler encoded_len += len; 23939beb93cSSam Leffler } 24039beb93cSSam Leffler 24185732ac8SCy Schubert if (!end || !encoded) { 24239beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: blob was not terminated " 24339beb93cSSam Leffler "properly", *line); 24439beb93cSSam Leffler os_free(encoded); 24539beb93cSSam Leffler return NULL; 24639beb93cSSam Leffler } 24739beb93cSSam Leffler 24839beb93cSSam Leffler blob = os_zalloc(sizeof(*blob)); 24939beb93cSSam Leffler if (blob == NULL) { 25039beb93cSSam Leffler os_free(encoded); 25139beb93cSSam Leffler return NULL; 25239beb93cSSam Leffler } 25339beb93cSSam Leffler blob->name = os_strdup(name); 25439beb93cSSam Leffler blob->data = base64_decode(encoded, encoded_len, &blob->len); 25539beb93cSSam Leffler os_free(encoded); 25639beb93cSSam Leffler 25739beb93cSSam Leffler if (blob->name == NULL || blob->data == NULL) { 25839beb93cSSam Leffler wpa_config_free_blob(blob); 25939beb93cSSam Leffler return NULL; 26039beb93cSSam Leffler } 26139beb93cSSam Leffler 26239beb93cSSam Leffler return blob; 26339beb93cSSam Leffler } 26439beb93cSSam Leffler 26539beb93cSSam Leffler 26639beb93cSSam Leffler static int wpa_config_process_blob(struct wpa_config *config, FILE *f, 26739beb93cSSam Leffler int *line, char *bname) 26839beb93cSSam Leffler { 26939beb93cSSam Leffler char *name_end; 27039beb93cSSam Leffler struct wpa_config_blob *blob; 27139beb93cSSam Leffler 27239beb93cSSam Leffler name_end = os_strchr(bname, '='); 27339beb93cSSam Leffler if (name_end == NULL) { 27439beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: no blob name terminator", 27539beb93cSSam Leffler *line); 27639beb93cSSam Leffler return -1; 27739beb93cSSam Leffler } 27839beb93cSSam Leffler *name_end = '\0'; 27939beb93cSSam Leffler 28039beb93cSSam Leffler blob = wpa_config_read_blob(f, line, bname); 28139beb93cSSam Leffler if (blob == NULL) { 28239beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s", 28339beb93cSSam Leffler *line, bname); 28439beb93cSSam Leffler return -1; 28539beb93cSSam Leffler } 28639beb93cSSam Leffler wpa_config_set_blob(config, blob); 28739beb93cSSam Leffler return 0; 28839beb93cSSam Leffler } 28939beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 29039beb93cSSam Leffler 29139beb93cSSam Leffler 2925b9c547cSRui Paulo struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp) 29339beb93cSSam Leffler { 29439beb93cSSam Leffler FILE *f; 295f05cddf9SRui Paulo char buf[512], *pos; 29639beb93cSSam Leffler int errors = 0, line = 0; 2975b9c547cSRui Paulo struct wpa_ssid *ssid, *tail, *head; 2985b9c547cSRui Paulo struct wpa_cred *cred, *cred_tail, *cred_head; 29939beb93cSSam Leffler struct wpa_config *config; 30039beb93cSSam Leffler int id = 0; 301f05cddf9SRui Paulo int cred_id = 0; 30239beb93cSSam Leffler 3035b9c547cSRui Paulo if (name == NULL) 3045b9c547cSRui Paulo return NULL; 3055b9c547cSRui Paulo if (cfgp) 3065b9c547cSRui Paulo config = cfgp; 3075b9c547cSRui Paulo else 30839beb93cSSam Leffler config = wpa_config_alloc_empty(NULL, NULL); 309f05cddf9SRui Paulo if (config == NULL) { 310f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Failed to allocate config file " 311f05cddf9SRui Paulo "structure"); 31239beb93cSSam Leffler return NULL; 313f05cddf9SRui Paulo } 3145b9c547cSRui Paulo tail = head = config->ssid; 3155b9c547cSRui Paulo while (tail && tail->next) 3165b9c547cSRui Paulo tail = tail->next; 3175b9c547cSRui Paulo cred_tail = cred_head = config->cred; 3185b9c547cSRui Paulo while (cred_tail && cred_tail->next) 3195b9c547cSRui Paulo cred_tail = cred_tail->next; 320f05cddf9SRui Paulo 32139beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name); 32239beb93cSSam Leffler f = fopen(name, "r"); 32339beb93cSSam Leffler if (f == NULL) { 324f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Failed to open config file '%s', " 325f05cddf9SRui Paulo "error: %s", name, strerror(errno)); 32685732ac8SCy Schubert if (config != cfgp) 32739beb93cSSam Leffler os_free(config); 32839beb93cSSam Leffler return NULL; 32939beb93cSSam Leffler } 33039beb93cSSam Leffler 33139beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) { 33239beb93cSSam Leffler if (os_strcmp(pos, "network={") == 0) { 33339beb93cSSam Leffler ssid = wpa_config_read_network(f, &line, id++); 33439beb93cSSam Leffler if (ssid == NULL) { 33539beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to " 33639beb93cSSam Leffler "parse network block.", line); 33739beb93cSSam Leffler errors++; 33839beb93cSSam Leffler continue; 33939beb93cSSam Leffler } 34039beb93cSSam Leffler if (head == NULL) { 34139beb93cSSam Leffler head = tail = ssid; 34239beb93cSSam Leffler } else { 34339beb93cSSam Leffler tail->next = ssid; 34439beb93cSSam Leffler tail = ssid; 34539beb93cSSam Leffler } 34639beb93cSSam Leffler if (wpa_config_add_prio_network(config, ssid)) { 34739beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to add " 34839beb93cSSam Leffler "network block to priority list.", 34939beb93cSSam Leffler line); 35039beb93cSSam Leffler errors++; 35139beb93cSSam Leffler continue; 35239beb93cSSam Leffler } 353f05cddf9SRui Paulo } else if (os_strcmp(pos, "cred={") == 0) { 354f05cddf9SRui Paulo cred = wpa_config_read_cred(f, &line, cred_id++); 355f05cddf9SRui Paulo if (cred == NULL) { 356f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: failed to " 357f05cddf9SRui Paulo "parse cred block.", line); 358f05cddf9SRui Paulo errors++; 359f05cddf9SRui Paulo continue; 360f05cddf9SRui Paulo } 361f05cddf9SRui Paulo if (cred_head == NULL) { 362f05cddf9SRui Paulo cred_head = cred_tail = cred; 363f05cddf9SRui Paulo } else { 364f05cddf9SRui Paulo cred_tail->next = cred; 365f05cddf9SRui Paulo cred_tail = cred; 366f05cddf9SRui Paulo } 36739beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 36839beb93cSSam Leffler } else if (os_strncmp(pos, "blob-base64-", 12) == 0) { 36939beb93cSSam Leffler if (wpa_config_process_blob(config, f, &line, pos + 12) 37039beb93cSSam Leffler < 0) { 371f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: failed to " 372f05cddf9SRui Paulo "process blob.", line); 37339beb93cSSam Leffler errors++; 37439beb93cSSam Leffler continue; 37539beb93cSSam Leffler } 37639beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 37739beb93cSSam Leffler } else if (wpa_config_process_global(config, pos, line) < 0) { 37839beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: Invalid configuration " 37939beb93cSSam Leffler "line '%s'.", line, pos); 38039beb93cSSam Leffler errors++; 38139beb93cSSam Leffler continue; 38239beb93cSSam Leffler } 38339beb93cSSam Leffler } 38439beb93cSSam Leffler 38539beb93cSSam Leffler fclose(f); 38639beb93cSSam Leffler 38739beb93cSSam Leffler config->ssid = head; 38839beb93cSSam Leffler wpa_config_debug_dump_networks(config); 389f05cddf9SRui Paulo config->cred = cred_head; 39039beb93cSSam Leffler 391f05cddf9SRui Paulo #ifndef WPA_IGNORE_CONFIG_ERRORS 39239beb93cSSam Leffler if (errors) { 39385732ac8SCy Schubert if (config != cfgp) 39439beb93cSSam Leffler wpa_config_free(config); 39539beb93cSSam Leffler config = NULL; 39639beb93cSSam Leffler head = NULL; 39739beb93cSSam Leffler } 398f05cddf9SRui Paulo #endif /* WPA_IGNORE_CONFIG_ERRORS */ 39939beb93cSSam Leffler 40039beb93cSSam Leffler return config; 40139beb93cSSam Leffler } 40239beb93cSSam Leffler 40339beb93cSSam Leffler 40439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE 40539beb93cSSam Leffler 40639beb93cSSam Leffler static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid) 40739beb93cSSam Leffler { 40839beb93cSSam Leffler char *value = wpa_config_get(ssid, field); 40939beb93cSSam Leffler if (value == NULL) 41039beb93cSSam Leffler return; 41139beb93cSSam Leffler fprintf(f, "\t%s=%s\n", field, value); 4124bc52338SCy Schubert str_clear_free(value); 41339beb93cSSam Leffler } 41439beb93cSSam Leffler 41539beb93cSSam Leffler 41639beb93cSSam Leffler static void write_int(FILE *f, const char *field, int value, int def) 41739beb93cSSam Leffler { 41839beb93cSSam Leffler if (value == def) 41939beb93cSSam Leffler return; 42039beb93cSSam Leffler fprintf(f, "\t%s=%d\n", field, value); 42139beb93cSSam Leffler } 42239beb93cSSam Leffler 42339beb93cSSam Leffler 42439beb93cSSam Leffler static void write_bssid(FILE *f, struct wpa_ssid *ssid) 42539beb93cSSam Leffler { 42639beb93cSSam Leffler char *value = wpa_config_get(ssid, "bssid"); 42739beb93cSSam Leffler if (value == NULL) 42839beb93cSSam Leffler return; 42939beb93cSSam Leffler fprintf(f, "\tbssid=%s\n", value); 43039beb93cSSam Leffler os_free(value); 43139beb93cSSam Leffler } 43239beb93cSSam Leffler 43339beb93cSSam Leffler 43485732ac8SCy Schubert static void write_bssid_hint(FILE *f, struct wpa_ssid *ssid) 43585732ac8SCy Schubert { 43685732ac8SCy Schubert char *value = wpa_config_get(ssid, "bssid_hint"); 43785732ac8SCy Schubert 43885732ac8SCy Schubert if (!value) 43985732ac8SCy Schubert return; 44085732ac8SCy Schubert fprintf(f, "\tbssid_hint=%s\n", value); 44185732ac8SCy Schubert os_free(value); 44285732ac8SCy Schubert } 44385732ac8SCy Schubert 44485732ac8SCy Schubert 44539beb93cSSam Leffler static void write_psk(FILE *f, struct wpa_ssid *ssid) 44639beb93cSSam Leffler { 447325151a3SRui Paulo char *value; 448325151a3SRui Paulo 449325151a3SRui Paulo if (ssid->mem_only_psk) 450325151a3SRui Paulo return; 451325151a3SRui Paulo 452325151a3SRui Paulo value = wpa_config_get(ssid, "psk"); 45339beb93cSSam Leffler if (value == NULL) 45439beb93cSSam Leffler return; 45539beb93cSSam Leffler fprintf(f, "\tpsk=%s\n", value); 45639beb93cSSam Leffler os_free(value); 45739beb93cSSam Leffler } 45839beb93cSSam Leffler 45939beb93cSSam Leffler 46039beb93cSSam Leffler static void write_proto(FILE *f, struct wpa_ssid *ssid) 46139beb93cSSam Leffler { 46239beb93cSSam Leffler char *value; 46339beb93cSSam Leffler 46439beb93cSSam Leffler if (ssid->proto == DEFAULT_PROTO) 46539beb93cSSam Leffler return; 46639beb93cSSam Leffler 46739beb93cSSam Leffler value = wpa_config_get(ssid, "proto"); 46839beb93cSSam Leffler if (value == NULL) 46939beb93cSSam Leffler return; 47039beb93cSSam Leffler if (value[0]) 47139beb93cSSam Leffler fprintf(f, "\tproto=%s\n", value); 47239beb93cSSam Leffler os_free(value); 47339beb93cSSam Leffler } 47439beb93cSSam Leffler 47539beb93cSSam Leffler 47639beb93cSSam Leffler static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid) 47739beb93cSSam Leffler { 47839beb93cSSam Leffler char *value; 47939beb93cSSam Leffler 48039beb93cSSam Leffler if (ssid->key_mgmt == DEFAULT_KEY_MGMT) 48139beb93cSSam Leffler return; 48239beb93cSSam Leffler 48339beb93cSSam Leffler value = wpa_config_get(ssid, "key_mgmt"); 48439beb93cSSam Leffler if (value == NULL) 48539beb93cSSam Leffler return; 48639beb93cSSam Leffler if (value[0]) 48739beb93cSSam Leffler fprintf(f, "\tkey_mgmt=%s\n", value); 48839beb93cSSam Leffler os_free(value); 48939beb93cSSam Leffler } 49039beb93cSSam Leffler 49139beb93cSSam Leffler 49239beb93cSSam Leffler static void write_pairwise(FILE *f, struct wpa_ssid *ssid) 49339beb93cSSam Leffler { 49439beb93cSSam Leffler char *value; 49539beb93cSSam Leffler 49639beb93cSSam Leffler if (ssid->pairwise_cipher == DEFAULT_PAIRWISE) 49739beb93cSSam Leffler return; 49839beb93cSSam Leffler 49939beb93cSSam Leffler value = wpa_config_get(ssid, "pairwise"); 50039beb93cSSam Leffler if (value == NULL) 50139beb93cSSam Leffler return; 50239beb93cSSam Leffler if (value[0]) 50339beb93cSSam Leffler fprintf(f, "\tpairwise=%s\n", value); 50439beb93cSSam Leffler os_free(value); 50539beb93cSSam Leffler } 50639beb93cSSam Leffler 50739beb93cSSam Leffler 50839beb93cSSam Leffler static void write_group(FILE *f, struct wpa_ssid *ssid) 50939beb93cSSam Leffler { 51039beb93cSSam Leffler char *value; 51139beb93cSSam Leffler 51239beb93cSSam Leffler if (ssid->group_cipher == DEFAULT_GROUP) 51339beb93cSSam Leffler return; 51439beb93cSSam Leffler 51539beb93cSSam Leffler value = wpa_config_get(ssid, "group"); 51639beb93cSSam Leffler if (value == NULL) 51739beb93cSSam Leffler return; 51839beb93cSSam Leffler if (value[0]) 51939beb93cSSam Leffler fprintf(f, "\tgroup=%s\n", value); 52039beb93cSSam Leffler os_free(value); 52139beb93cSSam Leffler } 52239beb93cSSam Leffler 52339beb93cSSam Leffler 52485732ac8SCy Schubert static void write_group_mgmt(FILE *f, struct wpa_ssid *ssid) 52585732ac8SCy Schubert { 52685732ac8SCy Schubert char *value; 52785732ac8SCy Schubert 52885732ac8SCy Schubert if (!ssid->group_mgmt_cipher) 52985732ac8SCy Schubert return; 53085732ac8SCy Schubert 53185732ac8SCy Schubert value = wpa_config_get(ssid, "group_mgmt"); 53285732ac8SCy Schubert if (!value) 53385732ac8SCy Schubert return; 53485732ac8SCy Schubert if (value[0]) 53585732ac8SCy Schubert fprintf(f, "\tgroup_mgmt=%s\n", value); 53685732ac8SCy Schubert os_free(value); 53785732ac8SCy Schubert } 53885732ac8SCy Schubert 53985732ac8SCy Schubert 54039beb93cSSam Leffler static void write_auth_alg(FILE *f, struct wpa_ssid *ssid) 54139beb93cSSam Leffler { 54239beb93cSSam Leffler char *value; 54339beb93cSSam Leffler 54439beb93cSSam Leffler if (ssid->auth_alg == 0) 54539beb93cSSam Leffler return; 54639beb93cSSam Leffler 54739beb93cSSam Leffler value = wpa_config_get(ssid, "auth_alg"); 54839beb93cSSam Leffler if (value == NULL) 54939beb93cSSam Leffler return; 55039beb93cSSam Leffler if (value[0]) 55139beb93cSSam Leffler fprintf(f, "\tauth_alg=%s\n", value); 55239beb93cSSam Leffler os_free(value); 55339beb93cSSam Leffler } 55439beb93cSSam Leffler 55539beb93cSSam Leffler 55639beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 55739beb93cSSam Leffler static void write_eap(FILE *f, struct wpa_ssid *ssid) 55839beb93cSSam Leffler { 55939beb93cSSam Leffler char *value; 56039beb93cSSam Leffler 56139beb93cSSam Leffler value = wpa_config_get(ssid, "eap"); 56239beb93cSSam Leffler if (value == NULL) 56339beb93cSSam Leffler return; 56439beb93cSSam Leffler 56539beb93cSSam Leffler if (value[0]) 56639beb93cSSam Leffler fprintf(f, "\teap=%s\n", value); 56739beb93cSSam Leffler os_free(value); 56839beb93cSSam Leffler } 56939beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 57039beb93cSSam Leffler 57139beb93cSSam Leffler 572c1d255d3SCy Schubert #ifdef CONFIG_WEP 57339beb93cSSam Leffler static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid) 57439beb93cSSam Leffler { 57539beb93cSSam Leffler char field[20], *value; 57639beb93cSSam Leffler int res; 57739beb93cSSam Leffler 57839beb93cSSam Leffler res = os_snprintf(field, sizeof(field), "wep_key%d", idx); 5795b9c547cSRui Paulo if (os_snprintf_error(sizeof(field), res)) 58039beb93cSSam Leffler return; 58139beb93cSSam Leffler value = wpa_config_get(ssid, field); 58239beb93cSSam Leffler if (value) { 58339beb93cSSam Leffler fprintf(f, "\t%s=%s\n", field, value); 58439beb93cSSam Leffler os_free(value); 58539beb93cSSam Leffler } 58639beb93cSSam Leffler } 587c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 58839beb93cSSam Leffler 58939beb93cSSam Leffler 590f05cddf9SRui Paulo #ifdef CONFIG_P2P 5915b9c547cSRui Paulo 5925b9c547cSRui Paulo static void write_go_p2p_dev_addr(FILE *f, struct wpa_ssid *ssid) 5935b9c547cSRui Paulo { 5945b9c547cSRui Paulo char *value = wpa_config_get(ssid, "go_p2p_dev_addr"); 5955b9c547cSRui Paulo if (value == NULL) 5965b9c547cSRui Paulo return; 5975b9c547cSRui Paulo fprintf(f, "\tgo_p2p_dev_addr=%s\n", value); 5985b9c547cSRui Paulo os_free(value); 5995b9c547cSRui Paulo } 6005b9c547cSRui Paulo 601f05cddf9SRui Paulo static void write_p2p_client_list(FILE *f, struct wpa_ssid *ssid) 602f05cddf9SRui Paulo { 603f05cddf9SRui Paulo char *value = wpa_config_get(ssid, "p2p_client_list"); 604f05cddf9SRui Paulo if (value == NULL) 605f05cddf9SRui Paulo return; 606f05cddf9SRui Paulo fprintf(f, "\tp2p_client_list=%s\n", value); 607f05cddf9SRui Paulo os_free(value); 608f05cddf9SRui Paulo } 6095b9c547cSRui Paulo 6105b9c547cSRui Paulo 6115b9c547cSRui Paulo static void write_psk_list(FILE *f, struct wpa_ssid *ssid) 6125b9c547cSRui Paulo { 6135b9c547cSRui Paulo struct psk_list_entry *psk; 6145b9c547cSRui Paulo char hex[32 * 2 + 1]; 6155b9c547cSRui Paulo 6165b9c547cSRui Paulo dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) { 6175b9c547cSRui Paulo wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk)); 6185b9c547cSRui Paulo fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n", 6195b9c547cSRui Paulo psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex); 6205b9c547cSRui Paulo } 6215b9c547cSRui Paulo } 6225b9c547cSRui Paulo 623f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 624f05cddf9SRui Paulo 625f05cddf9SRui Paulo 62685732ac8SCy Schubert #ifdef CONFIG_MACSEC 62785732ac8SCy Schubert 62885732ac8SCy Schubert static void write_mka_cak(FILE *f, struct wpa_ssid *ssid) 62985732ac8SCy Schubert { 63085732ac8SCy Schubert char *value; 63185732ac8SCy Schubert 63285732ac8SCy Schubert if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK)) 63385732ac8SCy Schubert return; 63485732ac8SCy Schubert 63585732ac8SCy Schubert value = wpa_config_get(ssid, "mka_cak"); 63685732ac8SCy Schubert if (!value) 63785732ac8SCy Schubert return; 63885732ac8SCy Schubert fprintf(f, "\tmka_cak=%s\n", value); 63985732ac8SCy Schubert os_free(value); 64085732ac8SCy Schubert } 64185732ac8SCy Schubert 64285732ac8SCy Schubert 64385732ac8SCy Schubert static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid) 64485732ac8SCy Schubert { 64585732ac8SCy Schubert char *value; 64685732ac8SCy Schubert 64785732ac8SCy Schubert if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN)) 64885732ac8SCy Schubert return; 64985732ac8SCy Schubert 65085732ac8SCy Schubert value = wpa_config_get(ssid, "mka_ckn"); 65185732ac8SCy Schubert if (!value) 65285732ac8SCy Schubert return; 65385732ac8SCy Schubert fprintf(f, "\tmka_ckn=%s\n", value); 65485732ac8SCy Schubert os_free(value); 65585732ac8SCy Schubert } 65685732ac8SCy Schubert 65785732ac8SCy Schubert #endif /* CONFIG_MACSEC */ 65885732ac8SCy Schubert 65985732ac8SCy Schubert 66039beb93cSSam Leffler static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid) 66139beb93cSSam Leffler { 66239beb93cSSam Leffler #define STR(t) write_str(f, #t, ssid) 66339beb93cSSam Leffler #define INT(t) write_int(f, #t, ssid->t, 0) 664c1d255d3SCy Schubert #define INTe(t, m) write_int(f, #t, ssid->eap.m, 0) 66539beb93cSSam Leffler #define INT_DEF(t, def) write_int(f, #t, ssid->t, def) 666c1d255d3SCy Schubert #define INT_DEFe(t, m, def) write_int(f, #t, ssid->eap.m, def) 66739beb93cSSam Leffler 66839beb93cSSam Leffler STR(ssid); 66939beb93cSSam Leffler INT(scan_ssid); 67039beb93cSSam Leffler write_bssid(f, ssid); 67185732ac8SCy Schubert write_bssid_hint(f, ssid); 672c1d255d3SCy Schubert write_str(f, "bssid_ignore", ssid); 673c1d255d3SCy Schubert write_str(f, "bssid_accept", ssid); 67439beb93cSSam Leffler write_psk(f, ssid); 675325151a3SRui Paulo INT(mem_only_psk); 67685732ac8SCy Schubert STR(sae_password); 67785732ac8SCy Schubert STR(sae_password_id); 678*4b72b91aSCy Schubert write_int(f, "sae_pwe", ssid->sae_pwe, DEFAULT_SAE_PWE); 67939beb93cSSam Leffler write_proto(f, ssid); 68039beb93cSSam Leffler write_key_mgmt(f, ssid); 681f05cddf9SRui Paulo INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD); 68239beb93cSSam Leffler write_pairwise(f, ssid); 68339beb93cSSam Leffler write_group(f, ssid); 68485732ac8SCy Schubert write_group_mgmt(f, ssid); 68539beb93cSSam Leffler write_auth_alg(f, ssid); 686f05cddf9SRui Paulo STR(bgscan); 687f05cddf9SRui Paulo STR(autoscan); 6885b9c547cSRui Paulo STR(scan_freq); 68939beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 69039beb93cSSam Leffler write_eap(f, ssid); 69139beb93cSSam Leffler STR(identity); 69239beb93cSSam Leffler STR(anonymous_identity); 69385732ac8SCy Schubert STR(imsi_identity); 694c1d255d3SCy Schubert STR(machine_identity); 69539beb93cSSam Leffler STR(password); 696c1d255d3SCy Schubert STR(machine_password); 69739beb93cSSam Leffler STR(ca_cert); 69839beb93cSSam Leffler STR(ca_path); 69939beb93cSSam Leffler STR(client_cert); 70039beb93cSSam Leffler STR(private_key); 70139beb93cSSam Leffler STR(private_key_passwd); 70239beb93cSSam Leffler STR(dh_file); 70339beb93cSSam Leffler STR(subject_match); 7044bc52338SCy Schubert STR(check_cert_subject); 70539beb93cSSam Leffler STR(altsubject_match); 7065b9c547cSRui Paulo STR(domain_suffix_match); 7075b9c547cSRui Paulo STR(domain_match); 70839beb93cSSam Leffler STR(ca_cert2); 70939beb93cSSam Leffler STR(ca_path2); 71039beb93cSSam Leffler STR(client_cert2); 71139beb93cSSam Leffler STR(private_key2); 71239beb93cSSam Leffler STR(private_key2_passwd); 71339beb93cSSam Leffler STR(dh_file2); 71439beb93cSSam Leffler STR(subject_match2); 7154bc52338SCy Schubert STR(check_cert_subject2); 71639beb93cSSam Leffler STR(altsubject_match2); 7175b9c547cSRui Paulo STR(domain_suffix_match2); 7185b9c547cSRui Paulo STR(domain_match2); 719c1d255d3SCy Schubert STR(machine_ca_cert); 720c1d255d3SCy Schubert STR(machine_ca_path); 721c1d255d3SCy Schubert STR(machine_client_cert); 722c1d255d3SCy Schubert STR(machine_private_key); 723c1d255d3SCy Schubert STR(machine_private_key_passwd); 724c1d255d3SCy Schubert STR(machine_dh_file); 725c1d255d3SCy Schubert STR(machine_subject_match); 726c1d255d3SCy Schubert STR(machine_check_cert_subject); 727c1d255d3SCy Schubert STR(machine_altsubject_match); 728c1d255d3SCy Schubert STR(machine_domain_suffix_match); 729c1d255d3SCy Schubert STR(machine_domain_match); 73039beb93cSSam Leffler STR(phase1); 73139beb93cSSam Leffler STR(phase2); 732c1d255d3SCy Schubert STR(machine_phase2); 73339beb93cSSam Leffler STR(pcsc); 73439beb93cSSam Leffler STR(pin); 73539beb93cSSam Leffler STR(engine_id); 73639beb93cSSam Leffler STR(key_id); 73739beb93cSSam Leffler STR(cert_id); 73839beb93cSSam Leffler STR(ca_cert_id); 73939beb93cSSam Leffler STR(key2_id); 74039beb93cSSam Leffler STR(pin2); 74139beb93cSSam Leffler STR(engine2_id); 74239beb93cSSam Leffler STR(cert2_id); 74339beb93cSSam Leffler STR(ca_cert2_id); 744c1d255d3SCy Schubert INTe(engine, cert.engine); 745c1d255d3SCy Schubert INTe(engine2, phase2_cert.engine); 746c1d255d3SCy Schubert INTe(machine_engine, machine_cert.engine); 74739beb93cSSam Leffler INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS); 7485b9c547cSRui Paulo STR(openssl_ciphers); 749c1d255d3SCy Schubert INTe(erp, erp); 75039beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 751c1d255d3SCy Schubert #ifdef CONFIG_WEP 752c1d255d3SCy Schubert { 753c1d255d3SCy Schubert int i; 754c1d255d3SCy Schubert 75539beb93cSSam Leffler for (i = 0; i < 4; i++) 75639beb93cSSam Leffler write_wep_key(f, i, ssid); 75739beb93cSSam Leffler INT(wep_tx_keyidx); 758c1d255d3SCy Schubert } 759c1d255d3SCy Schubert #endif /* CONFIG_WEP */ 76039beb93cSSam Leffler INT(priority); 76139beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 76239beb93cSSam Leffler INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND); 76339beb93cSSam Leffler STR(pac_file); 764c1d255d3SCy Schubert INT_DEFe(fragment_size, fragment_size, DEFAULT_FRAGMENT_SIZE); 765c1d255d3SCy Schubert INTe(ocsp, cert.ocsp); 766c1d255d3SCy Schubert INTe(ocsp2, phase2_cert.ocsp); 767c1d255d3SCy Schubert INTe(machine_ocsp, machine_cert.ocsp); 768c1d255d3SCy Schubert INT_DEFe(sim_num, sim_num, DEFAULT_USER_SELECTED_SIM); 76939beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 77039beb93cSSam Leffler INT(mode); 7715b9c547cSRui Paulo INT(no_auto_peer); 772f05cddf9SRui Paulo INT(frequency); 773c1d255d3SCy Schubert INT(enable_edmg); 774c1d255d3SCy Schubert INT(edmg_channel); 7755b9c547cSRui Paulo INT(fixed_freq); 776780fb4a2SCy Schubert #ifdef CONFIG_ACS 777780fb4a2SCy Schubert INT(acs); 778780fb4a2SCy Schubert #endif /* CONFIG_ACS */ 779f05cddf9SRui Paulo write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1); 78039beb93cSSam Leffler INT(disabled); 7815b9c547cSRui Paulo INT(mixed_cell); 782c1d255d3SCy Schubert INT_DEF(vht, 1); 78385732ac8SCy Schubert INT_DEF(ht, 1); 78485732ac8SCy Schubert INT(ht40); 785c1d255d3SCy Schubert INT_DEF(he, 1); 7864bc52338SCy Schubert INT_DEF(max_oper_chwidth, DEFAULT_MAX_OPER_CHWIDTH); 78785732ac8SCy Schubert INT(vht_center_freq1); 78885732ac8SCy Schubert INT(vht_center_freq2); 789780fb4a2SCy Schubert INT(pbss); 790780fb4a2SCy Schubert INT(wps_disabled); 79185732ac8SCy Schubert INT(fils_dh_group); 792f05cddf9SRui Paulo write_int(f, "ieee80211w", ssid->ieee80211w, 793f05cddf9SRui Paulo MGMT_FRAME_PROTECTION_DEFAULT); 79439beb93cSSam Leffler STR(id_str); 795f05cddf9SRui Paulo #ifdef CONFIG_P2P 7965b9c547cSRui Paulo write_go_p2p_dev_addr(f, ssid); 797f05cddf9SRui Paulo write_p2p_client_list(f, ssid); 7985b9c547cSRui Paulo write_psk_list(f, ssid); 799f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 8005b9c547cSRui Paulo INT(ap_max_inactivity); 8015b9c547cSRui Paulo INT(dtim_period); 8025b9c547cSRui Paulo INT(beacon_int); 8035b9c547cSRui Paulo #ifdef CONFIG_MACSEC 8045b9c547cSRui Paulo INT(macsec_policy); 80585732ac8SCy Schubert write_mka_cak(f, ssid); 80685732ac8SCy Schubert write_mka_ckn(f, ssid); 80785732ac8SCy Schubert INT(macsec_integ_only); 8084bc52338SCy Schubert INT(macsec_replay_protect); 8094bc52338SCy Schubert INT(macsec_replay_window); 81085732ac8SCy Schubert INT(macsec_port); 81185732ac8SCy Schubert INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER); 8125b9c547cSRui Paulo #endif /* CONFIG_MACSEC */ 8135b9c547cSRui Paulo #ifdef CONFIG_HS20 8145b9c547cSRui Paulo INT(update_identifier); 81585732ac8SCy Schubert STR(roaming_consortium_selection); 8165b9c547cSRui Paulo #endif /* CONFIG_HS20 */ 8175b9c547cSRui Paulo write_int(f, "mac_addr", ssid->mac_addr, -1); 8185b9c547cSRui Paulo #ifdef CONFIG_MESH 8195b9c547cSRui Paulo STR(mesh_basic_rates); 8205b9c547cSRui Paulo INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES); 8215b9c547cSRui Paulo INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT); 8225b9c547cSRui Paulo INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT); 8235b9c547cSRui Paulo INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT); 82485732ac8SCy Schubert INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD); 8255b9c547cSRui Paulo #endif /* CONFIG_MESH */ 8265b9c547cSRui Paulo INT(wpa_ptk_rekey); 827c1d255d3SCy Schubert INT(wpa_deny_ptk0_rekey); 828780fb4a2SCy Schubert INT(group_rekey); 8295b9c547cSRui Paulo INT(ignore_broadcast_ssid); 83085732ac8SCy Schubert #ifdef CONFIG_DPP 83185732ac8SCy Schubert STR(dpp_connector); 83285732ac8SCy Schubert STR(dpp_netaccesskey); 83385732ac8SCy Schubert INT(dpp_netaccesskey_expiry); 83485732ac8SCy Schubert STR(dpp_csign); 835c1d255d3SCy Schubert STR(dpp_pp_key); 836c1d255d3SCy Schubert INT(dpp_pfs); 83785732ac8SCy Schubert #endif /* CONFIG_DPP */ 83885732ac8SCy Schubert INT(owe_group); 83985732ac8SCy Schubert INT(owe_only); 840c1d255d3SCy Schubert INT(owe_ptk_workaround); 8414bc52338SCy Schubert INT(multi_ap_backhaul_sta); 842206b73d0SCy Schubert INT(ft_eap_pmksa_caching); 843c1d255d3SCy Schubert INT(beacon_prot); 844c1d255d3SCy Schubert INT(transition_disable); 845c1d255d3SCy Schubert INT(sae_pk); 8465b9c547cSRui Paulo #ifdef CONFIG_HT_OVERRIDES 8475b9c547cSRui Paulo INT_DEF(disable_ht, DEFAULT_DISABLE_HT); 8485b9c547cSRui Paulo INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40); 8495b9c547cSRui Paulo INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI); 8505b9c547cSRui Paulo INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC); 8515b9c547cSRui Paulo INT(ht40_intolerant); 8524bc52338SCy Schubert INT_DEF(tx_stbc, DEFAULT_TX_STBC); 8534bc52338SCy Schubert INT_DEF(rx_stbc, DEFAULT_RX_STBC); 8545b9c547cSRui Paulo INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU); 8555b9c547cSRui Paulo INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR); 8565b9c547cSRui Paulo INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY); 8575b9c547cSRui Paulo STR(ht_mcs); 8585b9c547cSRui Paulo #endif /* CONFIG_HT_OVERRIDES */ 8595b9c547cSRui Paulo #ifdef CONFIG_VHT_OVERRIDES 8605b9c547cSRui Paulo INT(disable_vht); 8615b9c547cSRui Paulo INT(vht_capa); 8625b9c547cSRui Paulo INT(vht_capa_mask); 8635b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_1, -1); 8645b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_2, -1); 8655b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_3, -1); 8665b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_4, -1); 8675b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_5, -1); 8685b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_6, -1); 8695b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_7, -1); 8705b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_8, -1); 8715b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_1, -1); 8725b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_2, -1); 8735b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_3, -1); 8745b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_4, -1); 8755b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_5, -1); 8765b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_6, -1); 8775b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_7, -1); 8785b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_8, -1); 8795b9c547cSRui Paulo #endif /* CONFIG_VHT_OVERRIDES */ 880c1d255d3SCy Schubert #ifdef CONFIG_HE_OVERRIDES 881c1d255d3SCy Schubert INT(disable_he); 882c1d255d3SCy Schubert #endif /* CONFIG_HE_OVERRIDES */ 88339beb93cSSam Leffler 88439beb93cSSam Leffler #undef STR 88539beb93cSSam Leffler #undef INT 88639beb93cSSam Leffler #undef INT_DEF 88739beb93cSSam Leffler } 88839beb93cSSam Leffler 88939beb93cSSam Leffler 890f05cddf9SRui Paulo static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred) 891f05cddf9SRui Paulo { 8925b9c547cSRui Paulo size_t i; 8935b9c547cSRui Paulo 894f05cddf9SRui Paulo if (cred->priority) 895f05cddf9SRui Paulo fprintf(f, "\tpriority=%d\n", cred->priority); 896f05cddf9SRui Paulo if (cred->pcsc) 897f05cddf9SRui Paulo fprintf(f, "\tpcsc=%d\n", cred->pcsc); 898f05cddf9SRui Paulo if (cred->realm) 899f05cddf9SRui Paulo fprintf(f, "\trealm=\"%s\"\n", cred->realm); 900f05cddf9SRui Paulo if (cred->username) 901f05cddf9SRui Paulo fprintf(f, "\tusername=\"%s\"\n", cred->username); 902f05cddf9SRui Paulo if (cred->password && cred->ext_password) 903f05cddf9SRui Paulo fprintf(f, "\tpassword=ext:%s\n", cred->password); 904f05cddf9SRui Paulo else if (cred->password) 905f05cddf9SRui Paulo fprintf(f, "\tpassword=\"%s\"\n", cred->password); 906f05cddf9SRui Paulo if (cred->ca_cert) 907f05cddf9SRui Paulo fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert); 908f05cddf9SRui Paulo if (cred->client_cert) 909f05cddf9SRui Paulo fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert); 910f05cddf9SRui Paulo if (cred->private_key) 911f05cddf9SRui Paulo fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key); 912f05cddf9SRui Paulo if (cred->private_key_passwd) 913f05cddf9SRui Paulo fprintf(f, "\tprivate_key_passwd=\"%s\"\n", 914f05cddf9SRui Paulo cred->private_key_passwd); 915f05cddf9SRui Paulo if (cred->imsi) 916f05cddf9SRui Paulo fprintf(f, "\timsi=\"%s\"\n", cred->imsi); 917f05cddf9SRui Paulo if (cred->milenage) 918f05cddf9SRui Paulo fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage); 9195b9c547cSRui Paulo for (i = 0; i < cred->num_domain; i++) 9205b9c547cSRui Paulo fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]); 9215b9c547cSRui Paulo if (cred->domain_suffix_match) 9225b9c547cSRui Paulo fprintf(f, "\tdomain_suffix_match=\"%s\"\n", 9235b9c547cSRui Paulo cred->domain_suffix_match); 924f05cddf9SRui Paulo if (cred->roaming_consortium_len) { 925f05cddf9SRui Paulo fprintf(f, "\troaming_consortium="); 926f05cddf9SRui Paulo for (i = 0; i < cred->roaming_consortium_len; i++) 927f05cddf9SRui Paulo fprintf(f, "%02x", cred->roaming_consortium[i]); 928f05cddf9SRui Paulo fprintf(f, "\n"); 929f05cddf9SRui Paulo } 930f05cddf9SRui Paulo if (cred->eap_method) { 931f05cddf9SRui Paulo const char *name; 932f05cddf9SRui Paulo name = eap_get_name(cred->eap_method[0].vendor, 933f05cddf9SRui Paulo cred->eap_method[0].method); 9345b9c547cSRui Paulo if (name) 935f05cddf9SRui Paulo fprintf(f, "\teap=%s\n", name); 936f05cddf9SRui Paulo } 937f05cddf9SRui Paulo if (cred->phase1) 938f05cddf9SRui Paulo fprintf(f, "\tphase1=\"%s\"\n", cred->phase1); 939f05cddf9SRui Paulo if (cred->phase2) 940f05cddf9SRui Paulo fprintf(f, "\tphase2=\"%s\"\n", cred->phase2); 941f05cddf9SRui Paulo if (cred->excluded_ssid) { 9425b9c547cSRui Paulo size_t j; 943f05cddf9SRui Paulo for (i = 0; i < cred->num_excluded_ssid; i++) { 944f05cddf9SRui Paulo struct excluded_ssid *e = &cred->excluded_ssid[i]; 945f05cddf9SRui Paulo fprintf(f, "\texcluded_ssid="); 946f05cddf9SRui Paulo for (j = 0; j < e->ssid_len; j++) 947f05cddf9SRui Paulo fprintf(f, "%02x", e->ssid[j]); 948f05cddf9SRui Paulo fprintf(f, "\n"); 949f05cddf9SRui Paulo } 950f05cddf9SRui Paulo } 9515b9c547cSRui Paulo if (cred->roaming_partner) { 9525b9c547cSRui Paulo for (i = 0; i < cred->num_roaming_partner; i++) { 9535b9c547cSRui Paulo struct roaming_partner *p = &cred->roaming_partner[i]; 9545b9c547cSRui Paulo fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n", 9555b9c547cSRui Paulo p->fqdn, p->exact_match, p->priority, 9565b9c547cSRui Paulo p->country); 9575b9c547cSRui Paulo } 9585b9c547cSRui Paulo } 9595b9c547cSRui Paulo if (cred->update_identifier) 9605b9c547cSRui Paulo fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier); 9615b9c547cSRui Paulo 9625b9c547cSRui Paulo if (cred->provisioning_sp) 9635b9c547cSRui Paulo fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp); 9645b9c547cSRui Paulo if (cred->sp_priority) 9655b9c547cSRui Paulo fprintf(f, "\tsp_priority=%d\n", cred->sp_priority); 9665b9c547cSRui Paulo 9675b9c547cSRui Paulo if (cred->min_dl_bandwidth_home) 9685b9c547cSRui Paulo fprintf(f, "\tmin_dl_bandwidth_home=%u\n", 9695b9c547cSRui Paulo cred->min_dl_bandwidth_home); 9705b9c547cSRui Paulo if (cred->min_ul_bandwidth_home) 9715b9c547cSRui Paulo fprintf(f, "\tmin_ul_bandwidth_home=%u\n", 9725b9c547cSRui Paulo cred->min_ul_bandwidth_home); 9735b9c547cSRui Paulo if (cred->min_dl_bandwidth_roaming) 9745b9c547cSRui Paulo fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n", 9755b9c547cSRui Paulo cred->min_dl_bandwidth_roaming); 9765b9c547cSRui Paulo if (cred->min_ul_bandwidth_roaming) 9775b9c547cSRui Paulo fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n", 9785b9c547cSRui Paulo cred->min_ul_bandwidth_roaming); 9795b9c547cSRui Paulo 9805b9c547cSRui Paulo if (cred->max_bss_load) 9815b9c547cSRui Paulo fprintf(f, "\tmax_bss_load=%u\n", 9825b9c547cSRui Paulo cred->max_bss_load); 9835b9c547cSRui Paulo 9845b9c547cSRui Paulo if (cred->ocsp) 9855b9c547cSRui Paulo fprintf(f, "\tocsp=%d\n", cred->ocsp); 9865b9c547cSRui Paulo 9875b9c547cSRui Paulo if (cred->num_req_conn_capab) { 9885b9c547cSRui Paulo for (i = 0; i < cred->num_req_conn_capab; i++) { 9895b9c547cSRui Paulo int *ports; 9905b9c547cSRui Paulo 9915b9c547cSRui Paulo fprintf(f, "\treq_conn_capab=%u", 9925b9c547cSRui Paulo cred->req_conn_capab_proto[i]); 9935b9c547cSRui Paulo ports = cred->req_conn_capab_port[i]; 9945b9c547cSRui Paulo if (ports) { 9955b9c547cSRui Paulo int j; 9965b9c547cSRui Paulo for (j = 0; ports[j] != -1; j++) { 9975b9c547cSRui Paulo fprintf(f, "%s%d", j > 0 ? "," : ":", 9985b9c547cSRui Paulo ports[j]); 9995b9c547cSRui Paulo } 10005b9c547cSRui Paulo } 10015b9c547cSRui Paulo fprintf(f, "\n"); 10025b9c547cSRui Paulo } 10035b9c547cSRui Paulo } 10045b9c547cSRui Paulo 10055b9c547cSRui Paulo if (cred->required_roaming_consortium_len) { 10065b9c547cSRui Paulo fprintf(f, "\trequired_roaming_consortium="); 10075b9c547cSRui Paulo for (i = 0; i < cred->required_roaming_consortium_len; i++) 10085b9c547cSRui Paulo fprintf(f, "%02x", 10095b9c547cSRui Paulo cred->required_roaming_consortium[i]); 10105b9c547cSRui Paulo fprintf(f, "\n"); 10115b9c547cSRui Paulo } 10125b9c547cSRui Paulo 101385732ac8SCy Schubert if (cred->num_roaming_consortiums) { 101485732ac8SCy Schubert size_t j; 101585732ac8SCy Schubert 101685732ac8SCy Schubert fprintf(f, "\troaming_consortiums=\""); 101785732ac8SCy Schubert for (i = 0; i < cred->num_roaming_consortiums; i++) { 101885732ac8SCy Schubert if (i > 0) 101985732ac8SCy Schubert fprintf(f, ","); 102085732ac8SCy Schubert for (j = 0; j < cred->roaming_consortiums_len[i]; j++) 102185732ac8SCy Schubert fprintf(f, "%02x", 102285732ac8SCy Schubert cred->roaming_consortiums[i][j]); 102385732ac8SCy Schubert } 102485732ac8SCy Schubert fprintf(f, "\"\n"); 102585732ac8SCy Schubert } 102685732ac8SCy Schubert 10275b9c547cSRui Paulo if (cred->sim_num != DEFAULT_USER_SELECTED_SIM) 10285b9c547cSRui Paulo fprintf(f, "\tsim_num=%d\n", cred->sim_num); 1029f05cddf9SRui Paulo } 1030f05cddf9SRui Paulo 1031f05cddf9SRui Paulo 103239beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 103339beb93cSSam Leffler static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob) 103439beb93cSSam Leffler { 1035c1d255d3SCy Schubert char *encoded; 103639beb93cSSam Leffler 103739beb93cSSam Leffler encoded = base64_encode(blob->data, blob->len, NULL); 103839beb93cSSam Leffler if (encoded == NULL) 103939beb93cSSam Leffler return -1; 104039beb93cSSam Leffler 104139beb93cSSam Leffler fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded); 104239beb93cSSam Leffler os_free(encoded); 104339beb93cSSam Leffler return 0; 104439beb93cSSam Leffler } 104539beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 104639beb93cSSam Leffler 104739beb93cSSam Leffler 1048f05cddf9SRui Paulo static void write_global_bin(FILE *f, const char *field, 1049f05cddf9SRui Paulo const struct wpabuf *val) 1050f05cddf9SRui Paulo { 1051f05cddf9SRui Paulo size_t i; 1052f05cddf9SRui Paulo const u8 *pos; 1053f05cddf9SRui Paulo 1054f05cddf9SRui Paulo if (val == NULL) 1055f05cddf9SRui Paulo return; 1056f05cddf9SRui Paulo 1057f05cddf9SRui Paulo fprintf(f, "%s=", field); 1058f05cddf9SRui Paulo pos = wpabuf_head(val); 1059f05cddf9SRui Paulo for (i = 0; i < wpabuf_len(val); i++) 1060f05cddf9SRui Paulo fprintf(f, "%02X", *pos++); 1061f05cddf9SRui Paulo fprintf(f, "\n"); 1062f05cddf9SRui Paulo } 1063f05cddf9SRui Paulo 1064f05cddf9SRui Paulo 106539beb93cSSam Leffler static void wpa_config_write_global(FILE *f, struct wpa_config *config) 106639beb93cSSam Leffler { 106739beb93cSSam Leffler #ifdef CONFIG_CTRL_IFACE 106839beb93cSSam Leffler if (config->ctrl_interface) 106939beb93cSSam Leffler fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface); 107039beb93cSSam Leffler if (config->ctrl_interface_group) 107139beb93cSSam Leffler fprintf(f, "ctrl_interface_group=%s\n", 107239beb93cSSam Leffler config->ctrl_interface_group); 107339beb93cSSam Leffler #endif /* CONFIG_CTRL_IFACE */ 107439beb93cSSam Leffler if (config->eapol_version != DEFAULT_EAPOL_VERSION) 107539beb93cSSam Leffler fprintf(f, "eapol_version=%d\n", config->eapol_version); 107639beb93cSSam Leffler if (config->ap_scan != DEFAULT_AP_SCAN) 107739beb93cSSam Leffler fprintf(f, "ap_scan=%d\n", config->ap_scan); 1078f05cddf9SRui Paulo if (config->disable_scan_offload) 1079f05cddf9SRui Paulo fprintf(f, "disable_scan_offload=%d\n", 1080f05cddf9SRui Paulo config->disable_scan_offload); 108139beb93cSSam Leffler if (config->fast_reauth != DEFAULT_FAST_REAUTH) 108239beb93cSSam Leffler fprintf(f, "fast_reauth=%d\n", config->fast_reauth); 108339beb93cSSam Leffler if (config->opensc_engine_path) 108439beb93cSSam Leffler fprintf(f, "opensc_engine_path=%s\n", 108539beb93cSSam Leffler config->opensc_engine_path); 108639beb93cSSam Leffler if (config->pkcs11_engine_path) 108739beb93cSSam Leffler fprintf(f, "pkcs11_engine_path=%s\n", 108839beb93cSSam Leffler config->pkcs11_engine_path); 108939beb93cSSam Leffler if (config->pkcs11_module_path) 109039beb93cSSam Leffler fprintf(f, "pkcs11_module_path=%s\n", 109139beb93cSSam Leffler config->pkcs11_module_path); 10925b9c547cSRui Paulo if (config->openssl_ciphers) 10935b9c547cSRui Paulo fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers); 1094f05cddf9SRui Paulo if (config->pcsc_reader) 1095f05cddf9SRui Paulo fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader); 1096f05cddf9SRui Paulo if (config->pcsc_pin) 1097f05cddf9SRui Paulo fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin); 109839beb93cSSam Leffler if (config->driver_param) 109939beb93cSSam Leffler fprintf(f, "driver_param=%s\n", config->driver_param); 110039beb93cSSam Leffler if (config->dot11RSNAConfigPMKLifetime) 1101325151a3SRui Paulo fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n", 110239beb93cSSam Leffler config->dot11RSNAConfigPMKLifetime); 110339beb93cSSam Leffler if (config->dot11RSNAConfigPMKReauthThreshold) 1104325151a3SRui Paulo fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n", 110539beb93cSSam Leffler config->dot11RSNAConfigPMKReauthThreshold); 110639beb93cSSam Leffler if (config->dot11RSNAConfigSATimeout) 1107325151a3SRui Paulo fprintf(f, "dot11RSNAConfigSATimeout=%u\n", 110839beb93cSSam Leffler config->dot11RSNAConfigSATimeout); 110939beb93cSSam Leffler if (config->update_config) 111039beb93cSSam Leffler fprintf(f, "update_config=%d\n", config->update_config); 111139beb93cSSam Leffler #ifdef CONFIG_WPS 111239beb93cSSam Leffler if (!is_nil_uuid(config->uuid)) { 111339beb93cSSam Leffler char buf[40]; 111439beb93cSSam Leffler uuid_bin2str(config->uuid, buf, sizeof(buf)); 111539beb93cSSam Leffler fprintf(f, "uuid=%s\n", buf); 111639beb93cSSam Leffler } 111785732ac8SCy Schubert if (config->auto_uuid) 111885732ac8SCy Schubert fprintf(f, "auto_uuid=%d\n", config->auto_uuid); 111939beb93cSSam Leffler if (config->device_name) 112039beb93cSSam Leffler fprintf(f, "device_name=%s\n", config->device_name); 112139beb93cSSam Leffler if (config->manufacturer) 112239beb93cSSam Leffler fprintf(f, "manufacturer=%s\n", config->manufacturer); 112339beb93cSSam Leffler if (config->model_name) 112439beb93cSSam Leffler fprintf(f, "model_name=%s\n", config->model_name); 112539beb93cSSam Leffler if (config->model_number) 112639beb93cSSam Leffler fprintf(f, "model_number=%s\n", config->model_number); 112739beb93cSSam Leffler if (config->serial_number) 112839beb93cSSam Leffler fprintf(f, "serial_number=%s\n", config->serial_number); 1129f05cddf9SRui Paulo { 1130f05cddf9SRui Paulo char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; 1131f05cddf9SRui Paulo buf = wps_dev_type_bin2str(config->device_type, 1132f05cddf9SRui Paulo _buf, sizeof(_buf)); 1133f05cddf9SRui Paulo if (os_strcmp(buf, "0-00000000-0") != 0) 1134f05cddf9SRui Paulo fprintf(f, "device_type=%s\n", buf); 1135f05cddf9SRui Paulo } 113639beb93cSSam Leffler if (WPA_GET_BE32(config->os_version)) 113739beb93cSSam Leffler fprintf(f, "os_version=%08x\n", 113839beb93cSSam Leffler WPA_GET_BE32(config->os_version)); 1139e28a4053SRui Paulo if (config->config_methods) 1140e28a4053SRui Paulo fprintf(f, "config_methods=%s\n", config->config_methods); 114139beb93cSSam Leffler if (config->wps_cred_processing) 114239beb93cSSam Leffler fprintf(f, "wps_cred_processing=%d\n", 114339beb93cSSam Leffler config->wps_cred_processing); 11444bc52338SCy Schubert if (config->wps_cred_add_sae) 11454bc52338SCy Schubert fprintf(f, "wps_cred_add_sae=%d\n", 11464bc52338SCy Schubert config->wps_cred_add_sae); 1147f05cddf9SRui Paulo if (config->wps_vendor_ext_m1) { 1148f05cddf9SRui Paulo int i, len = wpabuf_len(config->wps_vendor_ext_m1); 1149f05cddf9SRui Paulo const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1); 1150f05cddf9SRui Paulo if (len > 0) { 1151f05cddf9SRui Paulo fprintf(f, "wps_vendor_ext_m1="); 1152f05cddf9SRui Paulo for (i = 0; i < len; i++) 1153f05cddf9SRui Paulo fprintf(f, "%02x", *p++); 1154f05cddf9SRui Paulo fprintf(f, "\n"); 1155f05cddf9SRui Paulo } 1156f05cddf9SRui Paulo } 115739beb93cSSam Leffler #endif /* CONFIG_WPS */ 1158f05cddf9SRui Paulo #ifdef CONFIG_P2P 115985732ac8SCy Schubert { 116085732ac8SCy Schubert int i; 116185732ac8SCy Schubert char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; 116285732ac8SCy Schubert 116385732ac8SCy Schubert for (i = 0; i < config->num_sec_device_types; i++) { 116485732ac8SCy Schubert buf = wps_dev_type_bin2str(config->sec_device_type[i], 116585732ac8SCy Schubert _buf, sizeof(_buf)); 116685732ac8SCy Schubert if (buf) 116785732ac8SCy Schubert fprintf(f, "sec_device_type=%s\n", buf); 116885732ac8SCy Schubert } 116985732ac8SCy Schubert } 1170f05cddf9SRui Paulo if (config->p2p_listen_reg_class) 1171325151a3SRui Paulo fprintf(f, "p2p_listen_reg_class=%d\n", 1172f05cddf9SRui Paulo config->p2p_listen_reg_class); 1173f05cddf9SRui Paulo if (config->p2p_listen_channel) 1174325151a3SRui Paulo fprintf(f, "p2p_listen_channel=%d\n", 1175f05cddf9SRui Paulo config->p2p_listen_channel); 1176f05cddf9SRui Paulo if (config->p2p_oper_reg_class) 1177325151a3SRui Paulo fprintf(f, "p2p_oper_reg_class=%d\n", 1178f05cddf9SRui Paulo config->p2p_oper_reg_class); 1179f05cddf9SRui Paulo if (config->p2p_oper_channel) 1180325151a3SRui Paulo fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel); 1181f05cddf9SRui Paulo if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT) 1182325151a3SRui Paulo fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent); 1183f05cddf9SRui Paulo if (config->p2p_ssid_postfix) 1184f05cddf9SRui Paulo fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix); 1185f05cddf9SRui Paulo if (config->persistent_reconnect) 1186325151a3SRui Paulo fprintf(f, "persistent_reconnect=%d\n", 1187f05cddf9SRui Paulo config->persistent_reconnect); 1188f05cddf9SRui Paulo if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS) 1189325151a3SRui Paulo fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss); 1190f05cddf9SRui Paulo if (config->p2p_group_idle) 1191325151a3SRui Paulo fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle); 11925b9c547cSRui Paulo if (config->p2p_passphrase_len) 11935b9c547cSRui Paulo fprintf(f, "p2p_passphrase_len=%u\n", 11945b9c547cSRui Paulo config->p2p_passphrase_len); 1195f05cddf9SRui Paulo if (config->p2p_pref_chan) { 1196f05cddf9SRui Paulo unsigned int i; 1197f05cddf9SRui Paulo fprintf(f, "p2p_pref_chan="); 1198f05cddf9SRui Paulo for (i = 0; i < config->num_p2p_pref_chan; i++) { 1199f05cddf9SRui Paulo fprintf(f, "%s%u:%u", i > 0 ? "," : "", 1200f05cddf9SRui Paulo config->p2p_pref_chan[i].op_class, 1201f05cddf9SRui Paulo config->p2p_pref_chan[i].chan); 1202f05cddf9SRui Paulo } 1203f05cddf9SRui Paulo fprintf(f, "\n"); 1204f05cddf9SRui Paulo } 12055b9c547cSRui Paulo if (config->p2p_no_go_freq.num) { 12065b9c547cSRui Paulo char *val = freq_range_list_str(&config->p2p_no_go_freq); 12075b9c547cSRui Paulo if (val) { 12085b9c547cSRui Paulo fprintf(f, "p2p_no_go_freq=%s\n", val); 12095b9c547cSRui Paulo os_free(val); 12105b9c547cSRui Paulo } 12115b9c547cSRui Paulo } 12125b9c547cSRui Paulo if (config->p2p_add_cli_chan) 12135b9c547cSRui Paulo fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan); 12145b9c547cSRui Paulo if (config->p2p_optimize_listen_chan != 12155b9c547cSRui Paulo DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN) 12165b9c547cSRui Paulo fprintf(f, "p2p_optimize_listen_chan=%d\n", 12175b9c547cSRui Paulo config->p2p_optimize_listen_chan); 1218f05cddf9SRui Paulo if (config->p2p_go_ht40) 1219325151a3SRui Paulo fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40); 12205b9c547cSRui Paulo if (config->p2p_go_vht) 1221325151a3SRui Paulo fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht); 12224bc52338SCy Schubert if (config->p2p_go_he) 12234bc52338SCy Schubert fprintf(f, "p2p_go_he=%d\n", config->p2p_go_he); 1224c1d255d3SCy Schubert if (config->p2p_go_edmg) 1225c1d255d3SCy Schubert fprintf(f, "p2p_go_edmg=%d\n", config->p2p_go_edmg); 12265b9c547cSRui Paulo if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW) 1227325151a3SRui Paulo fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow); 1228f05cddf9SRui Paulo if (config->p2p_disabled) 1229325151a3SRui Paulo fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled); 1230f05cddf9SRui Paulo if (config->p2p_no_group_iface) 1231325151a3SRui Paulo fprintf(f, "p2p_no_group_iface=%d\n", 1232f05cddf9SRui Paulo config->p2p_no_group_iface); 12335b9c547cSRui Paulo if (config->p2p_ignore_shared_freq) 1234325151a3SRui Paulo fprintf(f, "p2p_ignore_shared_freq=%d\n", 12355b9c547cSRui Paulo config->p2p_ignore_shared_freq); 1236325151a3SRui Paulo if (config->p2p_cli_probe) 1237325151a3SRui Paulo fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe); 1238325151a3SRui Paulo if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE) 1239325151a3SRui Paulo fprintf(f, "p2p_go_freq_change_policy=%u\n", 1240325151a3SRui Paulo config->p2p_go_freq_change_policy); 1241c1d255d3SCy Schubert 1242c1d255d3SCy Schubert if (config->p2p_6ghz_disable) 1243c1d255d3SCy Schubert fprintf(f, "p2p_6ghz_disable=%d\n", config->p2p_6ghz_disable); 1244c1d255d3SCy Schubert 1245780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_go)) 1246780fb4a2SCy Schubert fprintf(f, "ip_addr_go=%u.%u.%u.%u\n", 1247780fb4a2SCy Schubert config->ip_addr_go[0], config->ip_addr_go[1], 1248780fb4a2SCy Schubert config->ip_addr_go[2], config->ip_addr_go[3]); 1249780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_mask)) 1250780fb4a2SCy Schubert fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n", 1251780fb4a2SCy Schubert config->ip_addr_mask[0], config->ip_addr_mask[1], 1252780fb4a2SCy Schubert config->ip_addr_mask[2], config->ip_addr_mask[3]); 1253780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_start)) 1254780fb4a2SCy Schubert fprintf(f, "ip_addr_start=%u.%u.%u.%u\n", 1255780fb4a2SCy Schubert config->ip_addr_start[0], config->ip_addr_start[1], 1256780fb4a2SCy Schubert config->ip_addr_start[2], config->ip_addr_start[3]); 1257780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_end)) 1258780fb4a2SCy Schubert fprintf(f, "ip_addr_end=%u.%u.%u.%u\n", 1259780fb4a2SCy Schubert config->ip_addr_end[0], config->ip_addr_end[1], 1260780fb4a2SCy Schubert config->ip_addr_end[2], config->ip_addr_end[3]); 1261f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 126239beb93cSSam Leffler if (config->country[0] && config->country[1]) { 126339beb93cSSam Leffler fprintf(f, "country=%c%c\n", 126439beb93cSSam Leffler config->country[0], config->country[1]); 126539beb93cSSam Leffler } 1266e28a4053SRui Paulo if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT) 1267e28a4053SRui Paulo fprintf(f, "bss_max_count=%u\n", config->bss_max_count); 1268f05cddf9SRui Paulo if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE) 1269f05cddf9SRui Paulo fprintf(f, "bss_expiration_age=%u\n", 1270f05cddf9SRui Paulo config->bss_expiration_age); 1271f05cddf9SRui Paulo if (config->bss_expiration_scan_count != 1272f05cddf9SRui Paulo DEFAULT_BSS_EXPIRATION_SCAN_COUNT) 1273f05cddf9SRui Paulo fprintf(f, "bss_expiration_scan_count=%u\n", 1274f05cddf9SRui Paulo config->bss_expiration_scan_count); 1275e28a4053SRui Paulo if (config->filter_ssids) 1276e28a4053SRui Paulo fprintf(f, "filter_ssids=%d\n", config->filter_ssids); 127785732ac8SCy Schubert if (config->filter_rssi) 127885732ac8SCy Schubert fprintf(f, "filter_rssi=%d\n", config->filter_rssi); 1279f05cddf9SRui Paulo if (config->max_num_sta != DEFAULT_MAX_NUM_STA) 1280f05cddf9SRui Paulo fprintf(f, "max_num_sta=%u\n", config->max_num_sta); 128185732ac8SCy Schubert if (config->ap_isolate != DEFAULT_AP_ISOLATE) 128285732ac8SCy Schubert fprintf(f, "ap_isolate=%u\n", config->ap_isolate); 1283f05cddf9SRui Paulo if (config->disassoc_low_ack) 1284325151a3SRui Paulo fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack); 1285f05cddf9SRui Paulo #ifdef CONFIG_HS20 1286f05cddf9SRui Paulo if (config->hs20) 1287f05cddf9SRui Paulo fprintf(f, "hs20=1\n"); 1288f05cddf9SRui Paulo #endif /* CONFIG_HS20 */ 1289f05cddf9SRui Paulo #ifdef CONFIG_INTERWORKING 1290f05cddf9SRui Paulo if (config->interworking) 1291325151a3SRui Paulo fprintf(f, "interworking=%d\n", config->interworking); 1292f05cddf9SRui Paulo if (!is_zero_ether_addr(config->hessid)) 1293f05cddf9SRui Paulo fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid)); 1294f05cddf9SRui Paulo if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE) 1295f05cddf9SRui Paulo fprintf(f, "access_network_type=%d\n", 1296f05cddf9SRui Paulo config->access_network_type); 129785732ac8SCy Schubert if (config->go_interworking) 129885732ac8SCy Schubert fprintf(f, "go_interworking=%d\n", config->go_interworking); 129985732ac8SCy Schubert if (config->go_access_network_type) 130085732ac8SCy Schubert fprintf(f, "go_access_network_type=%d\n", 130185732ac8SCy Schubert config->go_access_network_type); 130285732ac8SCy Schubert if (config->go_internet) 130385732ac8SCy Schubert fprintf(f, "go_internet=%d\n", config->go_internet); 130485732ac8SCy Schubert if (config->go_venue_group) 130585732ac8SCy Schubert fprintf(f, "go_venue_group=%d\n", config->go_venue_group); 130685732ac8SCy Schubert if (config->go_venue_type) 130785732ac8SCy Schubert fprintf(f, "go_venue_type=%d\n", config->go_venue_type); 1308f05cddf9SRui Paulo #endif /* CONFIG_INTERWORKING */ 1309f05cddf9SRui Paulo if (config->pbc_in_m1) 1310325151a3SRui Paulo fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1); 13115b9c547cSRui Paulo if (config->wps_nfc_pw_from_config) { 1312f05cddf9SRui Paulo if (config->wps_nfc_dev_pw_id) 1313f05cddf9SRui Paulo fprintf(f, "wps_nfc_dev_pw_id=%d\n", 1314f05cddf9SRui Paulo config->wps_nfc_dev_pw_id); 13155b9c547cSRui Paulo write_global_bin(f, "wps_nfc_dh_pubkey", 13165b9c547cSRui Paulo config->wps_nfc_dh_pubkey); 13175b9c547cSRui Paulo write_global_bin(f, "wps_nfc_dh_privkey", 13185b9c547cSRui Paulo config->wps_nfc_dh_privkey); 1319f05cddf9SRui Paulo write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw); 13205b9c547cSRui Paulo } 1321f05cddf9SRui Paulo 1322f05cddf9SRui Paulo if (config->ext_password_backend) 1323f05cddf9SRui Paulo fprintf(f, "ext_password_backend=%s\n", 1324f05cddf9SRui Paulo config->ext_password_backend); 1325f05cddf9SRui Paulo if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY) 1326f05cddf9SRui Paulo fprintf(f, "p2p_go_max_inactivity=%d\n", 1327f05cddf9SRui Paulo config->p2p_go_max_inactivity); 1328f05cddf9SRui Paulo if (config->auto_interworking) 1329f05cddf9SRui Paulo fprintf(f, "auto_interworking=%d\n", 1330f05cddf9SRui Paulo config->auto_interworking); 1331f05cddf9SRui Paulo if (config->okc) 1332f05cddf9SRui Paulo fprintf(f, "okc=%d\n", config->okc); 1333f05cddf9SRui Paulo if (config->pmf) 1334f05cddf9SRui Paulo fprintf(f, "pmf=%d\n", config->pmf); 13355b9c547cSRui Paulo if (config->dtim_period) 13365b9c547cSRui Paulo fprintf(f, "dtim_period=%d\n", config->dtim_period); 13375b9c547cSRui Paulo if (config->beacon_int) 13385b9c547cSRui Paulo fprintf(f, "beacon_int=%d\n", config->beacon_int); 13395b9c547cSRui Paulo 13405b9c547cSRui Paulo if (config->sae_groups) { 13415b9c547cSRui Paulo int i; 13425b9c547cSRui Paulo fprintf(f, "sae_groups="); 134385732ac8SCy Schubert for (i = 0; config->sae_groups[i] > 0; i++) { 13445b9c547cSRui Paulo fprintf(f, "%s%d", i > 0 ? " " : "", 13455b9c547cSRui Paulo config->sae_groups[i]); 13465b9c547cSRui Paulo } 13475b9c547cSRui Paulo fprintf(f, "\n"); 13485b9c547cSRui Paulo } 13495b9c547cSRui Paulo 1350c1d255d3SCy Schubert if (config->sae_pwe) 1351c1d255d3SCy Schubert fprintf(f, "sae_pwe=%d\n", config->sae_pwe); 1352c1d255d3SCy Schubert 1353c1d255d3SCy Schubert if (config->sae_pmkid_in_assoc) 1354c1d255d3SCy Schubert fprintf(f, "sae_pmkid_in_assoc=%d\n", 1355c1d255d3SCy Schubert config->sae_pmkid_in_assoc); 1356c1d255d3SCy Schubert 13575b9c547cSRui Paulo if (config->ap_vendor_elements) { 13585b9c547cSRui Paulo int i, len = wpabuf_len(config->ap_vendor_elements); 13595b9c547cSRui Paulo const u8 *p = wpabuf_head_u8(config->ap_vendor_elements); 13605b9c547cSRui Paulo if (len > 0) { 13615b9c547cSRui Paulo fprintf(f, "ap_vendor_elements="); 13625b9c547cSRui Paulo for (i = 0; i < len; i++) 13635b9c547cSRui Paulo fprintf(f, "%02x", *p++); 13645b9c547cSRui Paulo fprintf(f, "\n"); 13655b9c547cSRui Paulo } 13665b9c547cSRui Paulo } 13675b9c547cSRui Paulo 1368*4b72b91aSCy Schubert if (config->ap_assocresp_elements) { 1369*4b72b91aSCy Schubert int i, len = wpabuf_len(config->ap_assocresp_elements); 1370*4b72b91aSCy Schubert const u8 *p = wpabuf_head_u8(config->ap_assocresp_elements); 1371*4b72b91aSCy Schubert 1372*4b72b91aSCy Schubert if (len > 0) { 1373*4b72b91aSCy Schubert fprintf(f, "ap_assocresp_elements="); 1374*4b72b91aSCy Schubert for (i = 0; i < len; i++) 1375*4b72b91aSCy Schubert fprintf(f, "%02x", *p++); 1376*4b72b91aSCy Schubert fprintf(f, "\n"); 1377*4b72b91aSCy Schubert } 1378*4b72b91aSCy Schubert } 1379*4b72b91aSCy Schubert 13805b9c547cSRui Paulo if (config->ignore_old_scan_res) 13815b9c547cSRui Paulo fprintf(f, "ignore_old_scan_res=%d\n", 13825b9c547cSRui Paulo config->ignore_old_scan_res); 13835b9c547cSRui Paulo 13845b9c547cSRui Paulo if (config->freq_list && config->freq_list[0]) { 13855b9c547cSRui Paulo int i; 13865b9c547cSRui Paulo fprintf(f, "freq_list="); 13875b9c547cSRui Paulo for (i = 0; config->freq_list[i]; i++) { 1388325151a3SRui Paulo fprintf(f, "%s%d", i > 0 ? " " : "", 13895b9c547cSRui Paulo config->freq_list[i]); 13905b9c547cSRui Paulo } 13915b9c547cSRui Paulo fprintf(f, "\n"); 13925b9c547cSRui Paulo } 1393c1d255d3SCy Schubert if (config->initial_freq_list && config->initial_freq_list[0]) { 1394c1d255d3SCy Schubert int i; 1395c1d255d3SCy Schubert fprintf(f, "initial_freq_list="); 1396c1d255d3SCy Schubert for (i = 0; config->initial_freq_list[i]; i++) { 1397c1d255d3SCy Schubert fprintf(f, "%s%d", i > 0 ? " " : "", 1398c1d255d3SCy Schubert config->initial_freq_list[i]); 1399c1d255d3SCy Schubert } 1400c1d255d3SCy Schubert fprintf(f, "\n"); 1401c1d255d3SCy Schubert } 14025b9c547cSRui Paulo if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ) 14035b9c547cSRui Paulo fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq); 14045b9c547cSRui Paulo 1405c1d255d3SCy Schubert if (config->scan_res_valid_for_connect != 1406c1d255d3SCy Schubert DEFAULT_SCAN_RES_VALID_FOR_CONNECT) 1407c1d255d3SCy Schubert fprintf(f, "scan_res_valid_for_connect=%d\n", 1408c1d255d3SCy Schubert config->scan_res_valid_for_connect); 1409c1d255d3SCy Schubert 14105b9c547cSRui Paulo if (config->sched_scan_interval) 14115b9c547cSRui Paulo fprintf(f, "sched_scan_interval=%u\n", 14125b9c547cSRui Paulo config->sched_scan_interval); 14135b9c547cSRui Paulo 141485732ac8SCy Schubert if (config->sched_scan_start_delay) 141585732ac8SCy Schubert fprintf(f, "sched_scan_start_delay=%u\n", 141685732ac8SCy Schubert config->sched_scan_start_delay); 141785732ac8SCy Schubert 14185b9c547cSRui Paulo if (config->external_sim) 14195b9c547cSRui Paulo fprintf(f, "external_sim=%d\n", config->external_sim); 14205b9c547cSRui Paulo 14215b9c547cSRui Paulo if (config->tdls_external_control) 14225b9c547cSRui Paulo fprintf(f, "tdls_external_control=%d\n", 14235b9c547cSRui Paulo config->tdls_external_control); 14245b9c547cSRui Paulo 14255b9c547cSRui Paulo if (config->wowlan_triggers) 14265b9c547cSRui Paulo fprintf(f, "wowlan_triggers=%s\n", 14275b9c547cSRui Paulo config->wowlan_triggers); 14285b9c547cSRui Paulo 14295b9c547cSRui Paulo if (config->bgscan) 14305b9c547cSRui Paulo fprintf(f, "bgscan=\"%s\"\n", config->bgscan); 14315b9c547cSRui Paulo 143285732ac8SCy Schubert if (config->autoscan) 143385732ac8SCy Schubert fprintf(f, "autoscan=%s\n", config->autoscan); 143485732ac8SCy Schubert 14355b9c547cSRui Paulo if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY) 14365b9c547cSRui Paulo fprintf(f, "p2p_search_delay=%u\n", 14375b9c547cSRui Paulo config->p2p_search_delay); 14385b9c547cSRui Paulo 14395b9c547cSRui Paulo if (config->mac_addr) 14405b9c547cSRui Paulo fprintf(f, "mac_addr=%d\n", config->mac_addr); 14415b9c547cSRui Paulo 14425b9c547cSRui Paulo if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME) 14435b9c547cSRui Paulo fprintf(f, "rand_addr_lifetime=%u\n", 14445b9c547cSRui Paulo config->rand_addr_lifetime); 14455b9c547cSRui Paulo 14465b9c547cSRui Paulo if (config->preassoc_mac_addr) 14475b9c547cSRui Paulo fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr); 14485b9c547cSRui Paulo 14495b9c547cSRui Paulo if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD) 1450325151a3SRui Paulo fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload); 14515b9c547cSRui Paulo 14525b9c547cSRui Paulo if (config->user_mpm != DEFAULT_USER_MPM) 14535b9c547cSRui Paulo fprintf(f, "user_mpm=%d\n", config->user_mpm); 14545b9c547cSRui Paulo 14555b9c547cSRui Paulo if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS) 14565b9c547cSRui Paulo fprintf(f, "max_peer_links=%d\n", config->max_peer_links); 14575b9c547cSRui Paulo 14585b9c547cSRui Paulo if (config->cert_in_cb != DEFAULT_CERT_IN_CB) 14595b9c547cSRui Paulo fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb); 14605b9c547cSRui Paulo 14615b9c547cSRui Paulo if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY) 14625b9c547cSRui Paulo fprintf(f, "mesh_max_inactivity=%d\n", 14635b9c547cSRui Paulo config->mesh_max_inactivity); 14645b9c547cSRui Paulo 1465325151a3SRui Paulo if (config->dot11RSNASAERetransPeriod != 1466325151a3SRui Paulo DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD) 1467325151a3SRui Paulo fprintf(f, "dot11RSNASAERetransPeriod=%d\n", 1468325151a3SRui Paulo config->dot11RSNASAERetransPeriod); 1469325151a3SRui Paulo 14705b9c547cSRui Paulo if (config->passive_scan) 14715b9c547cSRui Paulo fprintf(f, "passive_scan=%d\n", config->passive_scan); 14725b9c547cSRui Paulo 14735b9c547cSRui Paulo if (config->reassoc_same_bss_optim) 14745b9c547cSRui Paulo fprintf(f, "reassoc_same_bss_optim=%d\n", 14755b9c547cSRui Paulo config->reassoc_same_bss_optim); 1476325151a3SRui Paulo 1477325151a3SRui Paulo if (config->wps_priority) 1478325151a3SRui Paulo fprintf(f, "wps_priority=%d\n", config->wps_priority); 1479780fb4a2SCy Schubert 1480780fb4a2SCy Schubert if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION) 1481780fb4a2SCy Schubert fprintf(f, "wpa_rsc_relaxation=%d\n", 1482780fb4a2SCy Schubert config->wpa_rsc_relaxation); 1483780fb4a2SCy Schubert 1484780fb4a2SCy Schubert if (config->sched_scan_plans) 1485780fb4a2SCy Schubert fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans); 1486780fb4a2SCy Schubert 1487780fb4a2SCy Schubert #ifdef CONFIG_MBO 1488780fb4a2SCy Schubert if (config->non_pref_chan) 1489780fb4a2SCy Schubert fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan); 1490780fb4a2SCy Schubert if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA) 1491780fb4a2SCy Schubert fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa); 149285732ac8SCy Schubert if (config->disassoc_imminent_rssi_threshold != 149385732ac8SCy Schubert DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD) 149485732ac8SCy Schubert fprintf(f, "disassoc_imminent_rssi_threshold=%d\n", 149585732ac8SCy Schubert config->disassoc_imminent_rssi_threshold); 149685732ac8SCy Schubert if (config->oce != DEFAULT_OCE_SUPPORT) 149785732ac8SCy Schubert fprintf(f, "oce=%u\n", config->oce); 1498780fb4a2SCy Schubert #endif /* CONFIG_MBO */ 1499780fb4a2SCy Schubert 1500780fb4a2SCy Schubert if (config->gas_address3) 1501780fb4a2SCy Schubert fprintf(f, "gas_address3=%d\n", config->gas_address3); 1502780fb4a2SCy Schubert 1503780fb4a2SCy Schubert if (config->ftm_responder) 1504780fb4a2SCy Schubert fprintf(f, "ftm_responder=%d\n", config->ftm_responder); 1505780fb4a2SCy Schubert if (config->ftm_initiator) 1506780fb4a2SCy Schubert fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator); 150785732ac8SCy Schubert 150885732ac8SCy Schubert if (config->osu_dir) 150985732ac8SCy Schubert fprintf(f, "osu_dir=%s\n", config->osu_dir); 151085732ac8SCy Schubert 151185732ac8SCy Schubert if (config->fst_group_id) 151285732ac8SCy Schubert fprintf(f, "fst_group_id=%s\n", config->fst_group_id); 151385732ac8SCy Schubert if (config->fst_priority) 151485732ac8SCy Schubert fprintf(f, "fst_priority=%d\n", config->fst_priority); 151585732ac8SCy Schubert if (config->fst_llt) 151685732ac8SCy Schubert fprintf(f, "fst_llt=%d\n", config->fst_llt); 151785732ac8SCy Schubert 151885732ac8SCy Schubert if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME) 151985732ac8SCy Schubert fprintf(f, "gas_rand_addr_lifetime=%u\n", 152085732ac8SCy Schubert config->gas_rand_addr_lifetime); 152185732ac8SCy Schubert if (config->gas_rand_mac_addr) 152285732ac8SCy Schubert fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr); 152385732ac8SCy Schubert if (config->dpp_config_processing) 152485732ac8SCy Schubert fprintf(f, "dpp_config_processing=%d\n", 152585732ac8SCy Schubert config->dpp_config_processing); 152685732ac8SCy Schubert if (config->coloc_intf_reporting) 152785732ac8SCy Schubert fprintf(f, "coloc_intf_reporting=%d\n", 152885732ac8SCy Schubert config->coloc_intf_reporting); 15294bc52338SCy Schubert if (config->p2p_device_random_mac_addr) 15304bc52338SCy Schubert fprintf(f, "p2p_device_random_mac_addr=%d\n", 15314bc52338SCy Schubert config->p2p_device_random_mac_addr); 15324bc52338SCy Schubert if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr)) 15334bc52338SCy Schubert fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n", 15344bc52338SCy Schubert MAC2STR(config->p2p_device_persistent_mac_addr)); 15354bc52338SCy Schubert if (config->p2p_interface_random_mac_addr) 15364bc52338SCy Schubert fprintf(f, "p2p_interface_random_mac_addr=%d\n", 15374bc52338SCy Schubert config->p2p_interface_random_mac_addr); 1538206b73d0SCy Schubert if (config->disable_btm) 1539206b73d0SCy Schubert fprintf(f, "disable_btm=1\n"); 1540c1d255d3SCy Schubert if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID) 1541c1d255d3SCy Schubert fprintf(f, "extended_key_id=%d\n", 1542c1d255d3SCy Schubert config->extended_key_id); 1543c1d255d3SCy Schubert if (config->wowlan_disconnect_on_deinit) 1544c1d255d3SCy Schubert fprintf(f, "wowlan_disconnect_on_deinit=%d\n", 1545c1d255d3SCy Schubert config->wowlan_disconnect_on_deinit); 154639beb93cSSam Leffler } 154739beb93cSSam Leffler 154839beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */ 154939beb93cSSam Leffler 155039beb93cSSam Leffler 155139beb93cSSam Leffler int wpa_config_write(const char *name, struct wpa_config *config) 155239beb93cSSam Leffler { 155339beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE 155439beb93cSSam Leffler FILE *f; 155539beb93cSSam Leffler struct wpa_ssid *ssid; 1556f05cddf9SRui Paulo struct wpa_cred *cred; 155739beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 155839beb93cSSam Leffler struct wpa_config_blob *blob; 155939beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 156039beb93cSSam Leffler int ret = 0; 15615b9c547cSRui Paulo const char *orig_name = name; 1562c1d255d3SCy Schubert int tmp_len; 1563c1d255d3SCy Schubert char *tmp_name; 15645b9c547cSRui Paulo 1565c1d255d3SCy Schubert if (!name) { 1566c1d255d3SCy Schubert wpa_printf(MSG_ERROR, "No configuration file for writing"); 1567c1d255d3SCy Schubert return -1; 1568c1d255d3SCy Schubert } 1569c1d255d3SCy Schubert 1570c1d255d3SCy Schubert tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */ 1571c1d255d3SCy Schubert tmp_name = os_malloc(tmp_len); 15725b9c547cSRui Paulo if (tmp_name) { 15735b9c547cSRui Paulo os_snprintf(tmp_name, tmp_len, "%s.tmp", name); 15745b9c547cSRui Paulo name = tmp_name; 15755b9c547cSRui Paulo } 157639beb93cSSam Leffler 157739beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name); 157839beb93cSSam Leffler 157939beb93cSSam Leffler f = fopen(name, "w"); 158039beb93cSSam Leffler if (f == NULL) { 158139beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name); 15825b9c547cSRui Paulo os_free(tmp_name); 158339beb93cSSam Leffler return -1; 158439beb93cSSam Leffler } 158539beb93cSSam Leffler 158639beb93cSSam Leffler wpa_config_write_global(f, config); 158739beb93cSSam Leffler 1588f05cddf9SRui Paulo for (cred = config->cred; cred; cred = cred->next) { 15895b9c547cSRui Paulo if (cred->temporary) 15905b9c547cSRui Paulo continue; 1591f05cddf9SRui Paulo fprintf(f, "\ncred={\n"); 1592f05cddf9SRui Paulo wpa_config_write_cred(f, cred); 1593f05cddf9SRui Paulo fprintf(f, "}\n"); 1594f05cddf9SRui Paulo } 1595f05cddf9SRui Paulo 159639beb93cSSam Leffler for (ssid = config->ssid; ssid; ssid = ssid->next) { 1597f05cddf9SRui Paulo if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary) 1598f05cddf9SRui Paulo continue; /* do not save temporary networks */ 1599c1d255d3SCy Schubert if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt) && 1600c1d255d3SCy Schubert !ssid->psk_set && !ssid->passphrase) 1601c1d255d3SCy Schubert continue; /* do not save invalid network */ 1602c1d255d3SCy Schubert if (wpa_key_mgmt_sae(ssid->key_mgmt) && 1603c1d255d3SCy Schubert !ssid->passphrase && !ssid->sae_password) 1604f05cddf9SRui Paulo continue; /* do not save invalid network */ 160539beb93cSSam Leffler fprintf(f, "\nnetwork={\n"); 160639beb93cSSam Leffler wpa_config_write_network(f, ssid); 160739beb93cSSam Leffler fprintf(f, "}\n"); 160839beb93cSSam Leffler } 160939beb93cSSam Leffler 161039beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 161139beb93cSSam Leffler for (blob = config->blobs; blob; blob = blob->next) { 161239beb93cSSam Leffler ret = wpa_config_write_blob(f, blob); 161339beb93cSSam Leffler if (ret) 161439beb93cSSam Leffler break; 161539beb93cSSam Leffler } 161639beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 161739beb93cSSam Leffler 1618325151a3SRui Paulo os_fdatasync(f); 1619325151a3SRui Paulo 162039beb93cSSam Leffler fclose(f); 162139beb93cSSam Leffler 16225b9c547cSRui Paulo if (tmp_name) { 16235b9c547cSRui Paulo int chmod_ret = 0; 16245b9c547cSRui Paulo 16255b9c547cSRui Paulo #ifdef ANDROID 16265b9c547cSRui Paulo chmod_ret = chmod(tmp_name, 16275b9c547cSRui Paulo S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 16285b9c547cSRui Paulo #endif /* ANDROID */ 16295b9c547cSRui Paulo if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0) 16305b9c547cSRui Paulo ret = -1; 16315b9c547cSRui Paulo 16325b9c547cSRui Paulo os_free(tmp_name); 16335b9c547cSRui Paulo } 16345b9c547cSRui Paulo 163539beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully", 16365b9c547cSRui Paulo orig_name, ret ? "un" : ""); 163739beb93cSSam Leffler return ret; 163839beb93cSSam Leffler #else /* CONFIG_NO_CONFIG_WRITE */ 163939beb93cSSam Leffler return -1; 164039beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */ 164139beb93cSSam Leffler } 1642