139beb93cSSam Leffler /* 239beb93cSSam Leffler * WPA Supplicant / Configuration backend: text file 3f05cddf9SRui Paulo * Copyright (c) 2003-2012, 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" 22*85732ac8SCy 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" 26f05cddf9SRui Paulo 27f05cddf9SRui Paulo 28f05cddf9SRui Paulo static int newline_terminated(const char *buf, size_t buflen) 29f05cddf9SRui Paulo { 30f05cddf9SRui Paulo size_t len = os_strlen(buf); 31f05cddf9SRui Paulo if (len == 0) 32f05cddf9SRui Paulo return 0; 33f05cddf9SRui Paulo if (len == buflen - 1 && buf[buflen - 1] != '\r' && 34f05cddf9SRui Paulo buf[len - 1] != '\n') 35f05cddf9SRui Paulo return 0; 36f05cddf9SRui Paulo return 1; 37f05cddf9SRui Paulo } 38f05cddf9SRui Paulo 39f05cddf9SRui Paulo 40f05cddf9SRui Paulo static void skip_line_end(FILE *stream) 41f05cddf9SRui Paulo { 42f05cddf9SRui Paulo char buf[100]; 43f05cddf9SRui Paulo while (fgets(buf, sizeof(buf), stream)) { 44f05cddf9SRui Paulo buf[sizeof(buf) - 1] = '\0'; 45f05cddf9SRui Paulo if (newline_terminated(buf, sizeof(buf))) 46f05cddf9SRui Paulo return; 47f05cddf9SRui Paulo } 48f05cddf9SRui Paulo } 4939beb93cSSam Leffler 5039beb93cSSam Leffler 5139beb93cSSam Leffler /** 5239beb93cSSam Leffler * wpa_config_get_line - Read the next configuration file line 5339beb93cSSam Leffler * @s: Buffer for the line 5439beb93cSSam Leffler * @size: The buffer length 5539beb93cSSam Leffler * @stream: File stream to read from 5639beb93cSSam Leffler * @line: Pointer to a variable storing the file line number 5739beb93cSSam Leffler * @_pos: Buffer for the pointer to the beginning of data on the text line or 5839beb93cSSam Leffler * %NULL if not needed (returned value used instead) 5939beb93cSSam Leffler * Returns: Pointer to the beginning of data on the text line or %NULL if no 6039beb93cSSam Leffler * more text lines are available. 6139beb93cSSam Leffler * 6239beb93cSSam Leffler * This function reads the next non-empty line from the configuration file and 6339beb93cSSam Leffler * removes comments. The returned string is guaranteed to be null-terminated. 6439beb93cSSam Leffler */ 6539beb93cSSam Leffler static char * wpa_config_get_line(char *s, int size, FILE *stream, int *line, 6639beb93cSSam Leffler char **_pos) 6739beb93cSSam Leffler { 6839beb93cSSam Leffler char *pos, *end, *sstart; 6939beb93cSSam Leffler 7039beb93cSSam Leffler while (fgets(s, size, stream)) { 7139beb93cSSam Leffler (*line)++; 7239beb93cSSam Leffler s[size - 1] = '\0'; 73f05cddf9SRui Paulo if (!newline_terminated(s, size)) { 74f05cddf9SRui Paulo /* 75f05cddf9SRui Paulo * The line was truncated - skip rest of it to avoid 76f05cddf9SRui Paulo * confusing error messages. 77f05cddf9SRui Paulo */ 78f05cddf9SRui Paulo wpa_printf(MSG_INFO, "Long line in configuration file " 79f05cddf9SRui Paulo "truncated"); 80f05cddf9SRui Paulo skip_line_end(stream); 81f05cddf9SRui Paulo } 8239beb93cSSam Leffler pos = s; 8339beb93cSSam Leffler 8439beb93cSSam Leffler /* Skip white space from the beginning of line. */ 8539beb93cSSam Leffler while (*pos == ' ' || *pos == '\t' || *pos == '\r') 8639beb93cSSam Leffler pos++; 8739beb93cSSam Leffler 8839beb93cSSam Leffler /* Skip comment lines and empty lines */ 8939beb93cSSam Leffler if (*pos == '#' || *pos == '\n' || *pos == '\0') 9039beb93cSSam Leffler continue; 9139beb93cSSam Leffler 9239beb93cSSam Leffler /* 9339beb93cSSam Leffler * Remove # comments unless they are within a double quoted 9439beb93cSSam Leffler * string. 9539beb93cSSam Leffler */ 9639beb93cSSam Leffler sstart = os_strchr(pos, '"'); 9739beb93cSSam Leffler if (sstart) 9839beb93cSSam Leffler sstart = os_strrchr(sstart + 1, '"'); 9939beb93cSSam Leffler if (!sstart) 10039beb93cSSam Leffler sstart = pos; 10139beb93cSSam Leffler end = os_strchr(sstart, '#'); 10239beb93cSSam Leffler if (end) 10339beb93cSSam Leffler *end-- = '\0'; 10439beb93cSSam Leffler else 10539beb93cSSam Leffler end = pos + os_strlen(pos) - 1; 10639beb93cSSam Leffler 10739beb93cSSam Leffler /* Remove trailing white space. */ 10839beb93cSSam Leffler while (end > pos && 10939beb93cSSam Leffler (*end == '\n' || *end == ' ' || *end == '\t' || 11039beb93cSSam Leffler *end == '\r')) 11139beb93cSSam Leffler *end-- = '\0'; 11239beb93cSSam Leffler 11339beb93cSSam Leffler if (*pos == '\0') 11439beb93cSSam Leffler continue; 11539beb93cSSam Leffler 11639beb93cSSam Leffler if (_pos) 11739beb93cSSam Leffler *_pos = pos; 11839beb93cSSam Leffler return pos; 11939beb93cSSam Leffler } 12039beb93cSSam Leffler 12139beb93cSSam Leffler if (_pos) 12239beb93cSSam Leffler *_pos = NULL; 12339beb93cSSam Leffler return NULL; 12439beb93cSSam Leffler } 12539beb93cSSam Leffler 12639beb93cSSam Leffler 12739beb93cSSam Leffler static int wpa_config_validate_network(struct wpa_ssid *ssid, int line) 12839beb93cSSam Leffler { 12939beb93cSSam Leffler int errors = 0; 13039beb93cSSam Leffler 13139beb93cSSam Leffler if (ssid->passphrase) { 13239beb93cSSam Leffler if (ssid->psk_set) { 13339beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: both PSK and " 13439beb93cSSam Leffler "passphrase configured.", line); 13539beb93cSSam Leffler errors++; 13639beb93cSSam Leffler } 13739beb93cSSam Leffler wpa_config_update_psk(ssid); 13839beb93cSSam Leffler } 13939beb93cSSam Leffler 140*85732ac8SCy Schubert if (ssid->disabled == 2) 141*85732ac8SCy Schubert ssid->p2p_persistent_group = 1; 142*85732ac8SCy Schubert 14339beb93cSSam Leffler if ((ssid->group_cipher & WPA_CIPHER_CCMP) && 144*85732ac8SCy Schubert !(ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 | 145*85732ac8SCy Schubert WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256 | 146*85732ac8SCy Schubert WPA_CIPHER_NONE))) { 14739beb93cSSam Leffler /* Group cipher cannot be stronger than the pairwise cipher. */ 14839beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher" 14939beb93cSSam Leffler " list since it was not allowed for pairwise " 15039beb93cSSam Leffler "cipher", line); 15139beb93cSSam Leffler ssid->group_cipher &= ~WPA_CIPHER_CCMP; 15239beb93cSSam Leffler } 15339beb93cSSam Leffler 1545b9c547cSRui Paulo if (ssid->mode == WPAS_MODE_MESH && 1555b9c547cSRui Paulo (ssid->key_mgmt != WPA_KEY_MGMT_NONE && 1565b9c547cSRui Paulo ssid->key_mgmt != WPA_KEY_MGMT_SAE)) { 1575b9c547cSRui Paulo wpa_printf(MSG_ERROR, 1585b9c547cSRui Paulo "Line %d: key_mgmt for mesh network should be open or SAE", 1595b9c547cSRui Paulo line); 1605b9c547cSRui Paulo errors++; 1615b9c547cSRui Paulo } 1625b9c547cSRui Paulo 16339beb93cSSam Leffler return errors; 16439beb93cSSam Leffler } 16539beb93cSSam Leffler 16639beb93cSSam Leffler 16739beb93cSSam Leffler static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id) 16839beb93cSSam Leffler { 16939beb93cSSam Leffler struct wpa_ssid *ssid; 17039beb93cSSam Leffler int errors = 0, end = 0; 171f05cddf9SRui Paulo char buf[2000], *pos, *pos2; 17239beb93cSSam Leffler 17339beb93cSSam Leffler wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block", 17439beb93cSSam Leffler *line); 17539beb93cSSam Leffler ssid = os_zalloc(sizeof(*ssid)); 17639beb93cSSam Leffler if (ssid == NULL) 17739beb93cSSam Leffler return NULL; 1785b9c547cSRui Paulo dl_list_init(&ssid->psk_list); 17939beb93cSSam Leffler ssid->id = id; 18039beb93cSSam Leffler 18139beb93cSSam Leffler wpa_config_set_network_defaults(ssid); 18239beb93cSSam Leffler 18339beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 18439beb93cSSam Leffler if (os_strcmp(pos, "}") == 0) { 18539beb93cSSam Leffler end = 1; 18639beb93cSSam Leffler break; 18739beb93cSSam Leffler } 18839beb93cSSam Leffler 18939beb93cSSam Leffler pos2 = os_strchr(pos, '='); 19039beb93cSSam Leffler if (pos2 == NULL) { 19139beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line " 19239beb93cSSam Leffler "'%s'.", *line, pos); 19339beb93cSSam Leffler errors++; 19439beb93cSSam Leffler continue; 19539beb93cSSam Leffler } 19639beb93cSSam Leffler 19739beb93cSSam Leffler *pos2++ = '\0'; 19839beb93cSSam Leffler if (*pos2 == '"') { 19939beb93cSSam Leffler if (os_strchr(pos2 + 1, '"') == NULL) { 20039beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: invalid " 20139beb93cSSam Leffler "quotation '%s'.", *line, pos2); 20239beb93cSSam Leffler errors++; 20339beb93cSSam Leffler continue; 20439beb93cSSam Leffler } 20539beb93cSSam Leffler } 20639beb93cSSam Leffler 20739beb93cSSam Leffler if (wpa_config_set(ssid, pos, pos2, *line) < 0) 20839beb93cSSam Leffler errors++; 20939beb93cSSam Leffler } 21039beb93cSSam Leffler 21139beb93cSSam Leffler if (!end) { 21239beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: network block was not " 21339beb93cSSam Leffler "terminated properly.", *line); 21439beb93cSSam Leffler errors++; 21539beb93cSSam Leffler } 21639beb93cSSam Leffler 21739beb93cSSam Leffler errors += wpa_config_validate_network(ssid, *line); 21839beb93cSSam Leffler 21939beb93cSSam Leffler if (errors) { 22039beb93cSSam Leffler wpa_config_free_ssid(ssid); 22139beb93cSSam Leffler ssid = NULL; 22239beb93cSSam Leffler } 22339beb93cSSam Leffler 22439beb93cSSam Leffler return ssid; 22539beb93cSSam Leffler } 22639beb93cSSam Leffler 22739beb93cSSam Leffler 228f05cddf9SRui Paulo static struct wpa_cred * wpa_config_read_cred(FILE *f, int *line, int id) 229f05cddf9SRui Paulo { 230f05cddf9SRui Paulo struct wpa_cred *cred; 231f05cddf9SRui Paulo int errors = 0, end = 0; 232f05cddf9SRui Paulo char buf[256], *pos, *pos2; 233f05cddf9SRui Paulo 234f05cddf9SRui Paulo wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new cred block", *line); 235f05cddf9SRui Paulo cred = os_zalloc(sizeof(*cred)); 236f05cddf9SRui Paulo if (cred == NULL) 237f05cddf9SRui Paulo return NULL; 238f05cddf9SRui Paulo cred->id = id; 2395b9c547cSRui Paulo cred->sim_num = DEFAULT_USER_SELECTED_SIM; 240f05cddf9SRui Paulo 241f05cddf9SRui Paulo while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 242f05cddf9SRui Paulo if (os_strcmp(pos, "}") == 0) { 243f05cddf9SRui Paulo end = 1; 244f05cddf9SRui Paulo break; 245f05cddf9SRui Paulo } 246f05cddf9SRui Paulo 247f05cddf9SRui Paulo pos2 = os_strchr(pos, '='); 248f05cddf9SRui Paulo if (pos2 == NULL) { 249f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: Invalid cred line " 250f05cddf9SRui Paulo "'%s'.", *line, pos); 251f05cddf9SRui Paulo errors++; 252f05cddf9SRui Paulo continue; 253f05cddf9SRui Paulo } 254f05cddf9SRui Paulo 255f05cddf9SRui Paulo *pos2++ = '\0'; 256f05cddf9SRui Paulo if (*pos2 == '"') { 257f05cddf9SRui Paulo if (os_strchr(pos2 + 1, '"') == NULL) { 258f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: invalid " 259f05cddf9SRui Paulo "quotation '%s'.", *line, pos2); 260f05cddf9SRui Paulo errors++; 261f05cddf9SRui Paulo continue; 262f05cddf9SRui Paulo } 263f05cddf9SRui Paulo } 264f05cddf9SRui Paulo 265f05cddf9SRui Paulo if (wpa_config_set_cred(cred, pos, pos2, *line) < 0) 266f05cddf9SRui Paulo errors++; 267f05cddf9SRui Paulo } 268f05cddf9SRui Paulo 269f05cddf9SRui Paulo if (!end) { 270f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: cred block was not " 271f05cddf9SRui Paulo "terminated properly.", *line); 272f05cddf9SRui Paulo errors++; 273f05cddf9SRui Paulo } 274f05cddf9SRui Paulo 275f05cddf9SRui Paulo if (errors) { 276f05cddf9SRui Paulo wpa_config_free_cred(cred); 277f05cddf9SRui Paulo cred = NULL; 278f05cddf9SRui Paulo } 279f05cddf9SRui Paulo 280f05cddf9SRui Paulo return cred; 281f05cddf9SRui Paulo } 282f05cddf9SRui Paulo 283f05cddf9SRui Paulo 28439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 28539beb93cSSam Leffler static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line, 28639beb93cSSam Leffler const char *name) 28739beb93cSSam Leffler { 28839beb93cSSam Leffler struct wpa_config_blob *blob; 28939beb93cSSam Leffler char buf[256], *pos; 29039beb93cSSam Leffler unsigned char *encoded = NULL, *nencoded; 29139beb93cSSam Leffler int end = 0; 29239beb93cSSam Leffler size_t encoded_len = 0, len; 29339beb93cSSam Leffler 29439beb93cSSam Leffler wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'", 29539beb93cSSam Leffler *line, name); 29639beb93cSSam Leffler 29739beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) { 29839beb93cSSam Leffler if (os_strcmp(pos, "}") == 0) { 29939beb93cSSam Leffler end = 1; 30039beb93cSSam Leffler break; 30139beb93cSSam Leffler } 30239beb93cSSam Leffler 30339beb93cSSam Leffler len = os_strlen(pos); 30439beb93cSSam Leffler nencoded = os_realloc(encoded, encoded_len + len); 30539beb93cSSam Leffler if (nencoded == NULL) { 30639beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: not enough memory for " 30739beb93cSSam Leffler "blob", *line); 30839beb93cSSam Leffler os_free(encoded); 30939beb93cSSam Leffler return NULL; 31039beb93cSSam Leffler } 31139beb93cSSam Leffler encoded = nencoded; 31239beb93cSSam Leffler os_memcpy(encoded + encoded_len, pos, len); 31339beb93cSSam Leffler encoded_len += len; 31439beb93cSSam Leffler } 31539beb93cSSam Leffler 316*85732ac8SCy Schubert if (!end || !encoded) { 31739beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: blob was not terminated " 31839beb93cSSam Leffler "properly", *line); 31939beb93cSSam Leffler os_free(encoded); 32039beb93cSSam Leffler return NULL; 32139beb93cSSam Leffler } 32239beb93cSSam Leffler 32339beb93cSSam Leffler blob = os_zalloc(sizeof(*blob)); 32439beb93cSSam Leffler if (blob == NULL) { 32539beb93cSSam Leffler os_free(encoded); 32639beb93cSSam Leffler return NULL; 32739beb93cSSam Leffler } 32839beb93cSSam Leffler blob->name = os_strdup(name); 32939beb93cSSam Leffler blob->data = base64_decode(encoded, encoded_len, &blob->len); 33039beb93cSSam Leffler os_free(encoded); 33139beb93cSSam Leffler 33239beb93cSSam Leffler if (blob->name == NULL || blob->data == NULL) { 33339beb93cSSam Leffler wpa_config_free_blob(blob); 33439beb93cSSam Leffler return NULL; 33539beb93cSSam Leffler } 33639beb93cSSam Leffler 33739beb93cSSam Leffler return blob; 33839beb93cSSam Leffler } 33939beb93cSSam Leffler 34039beb93cSSam Leffler 34139beb93cSSam Leffler static int wpa_config_process_blob(struct wpa_config *config, FILE *f, 34239beb93cSSam Leffler int *line, char *bname) 34339beb93cSSam Leffler { 34439beb93cSSam Leffler char *name_end; 34539beb93cSSam Leffler struct wpa_config_blob *blob; 34639beb93cSSam Leffler 34739beb93cSSam Leffler name_end = os_strchr(bname, '='); 34839beb93cSSam Leffler if (name_end == NULL) { 34939beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: no blob name terminator", 35039beb93cSSam Leffler *line); 35139beb93cSSam Leffler return -1; 35239beb93cSSam Leffler } 35339beb93cSSam Leffler *name_end = '\0'; 35439beb93cSSam Leffler 35539beb93cSSam Leffler blob = wpa_config_read_blob(f, line, bname); 35639beb93cSSam Leffler if (blob == NULL) { 35739beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s", 35839beb93cSSam Leffler *line, bname); 35939beb93cSSam Leffler return -1; 36039beb93cSSam Leffler } 36139beb93cSSam Leffler wpa_config_set_blob(config, blob); 36239beb93cSSam Leffler return 0; 36339beb93cSSam Leffler } 36439beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 36539beb93cSSam Leffler 36639beb93cSSam Leffler 3675b9c547cSRui Paulo struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp) 36839beb93cSSam Leffler { 36939beb93cSSam Leffler FILE *f; 370f05cddf9SRui Paulo char buf[512], *pos; 37139beb93cSSam Leffler int errors = 0, line = 0; 3725b9c547cSRui Paulo struct wpa_ssid *ssid, *tail, *head; 3735b9c547cSRui Paulo struct wpa_cred *cred, *cred_tail, *cred_head; 37439beb93cSSam Leffler struct wpa_config *config; 37539beb93cSSam Leffler int id = 0; 376f05cddf9SRui Paulo int cred_id = 0; 37739beb93cSSam Leffler 3785b9c547cSRui Paulo if (name == NULL) 3795b9c547cSRui Paulo return NULL; 3805b9c547cSRui Paulo if (cfgp) 3815b9c547cSRui Paulo config = cfgp; 3825b9c547cSRui Paulo else 38339beb93cSSam Leffler config = wpa_config_alloc_empty(NULL, NULL); 384f05cddf9SRui Paulo if (config == NULL) { 385f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Failed to allocate config file " 386f05cddf9SRui Paulo "structure"); 38739beb93cSSam Leffler return NULL; 388f05cddf9SRui Paulo } 3895b9c547cSRui Paulo tail = head = config->ssid; 3905b9c547cSRui Paulo while (tail && tail->next) 3915b9c547cSRui Paulo tail = tail->next; 3925b9c547cSRui Paulo cred_tail = cred_head = config->cred; 3935b9c547cSRui Paulo while (cred_tail && cred_tail->next) 3945b9c547cSRui Paulo cred_tail = cred_tail->next; 395f05cddf9SRui Paulo 39639beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name); 39739beb93cSSam Leffler f = fopen(name, "r"); 39839beb93cSSam Leffler if (f == NULL) { 399f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Failed to open config file '%s', " 400f05cddf9SRui Paulo "error: %s", name, strerror(errno)); 401*85732ac8SCy Schubert if (config != cfgp) 40239beb93cSSam Leffler os_free(config); 40339beb93cSSam Leffler return NULL; 40439beb93cSSam Leffler } 40539beb93cSSam Leffler 40639beb93cSSam Leffler while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) { 40739beb93cSSam Leffler if (os_strcmp(pos, "network={") == 0) { 40839beb93cSSam Leffler ssid = wpa_config_read_network(f, &line, id++); 40939beb93cSSam Leffler if (ssid == NULL) { 41039beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to " 41139beb93cSSam Leffler "parse network block.", line); 41239beb93cSSam Leffler errors++; 41339beb93cSSam Leffler continue; 41439beb93cSSam Leffler } 41539beb93cSSam Leffler if (head == NULL) { 41639beb93cSSam Leffler head = tail = ssid; 41739beb93cSSam Leffler } else { 41839beb93cSSam Leffler tail->next = ssid; 41939beb93cSSam Leffler tail = ssid; 42039beb93cSSam Leffler } 42139beb93cSSam Leffler if (wpa_config_add_prio_network(config, ssid)) { 42239beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: failed to add " 42339beb93cSSam Leffler "network block to priority list.", 42439beb93cSSam Leffler line); 42539beb93cSSam Leffler errors++; 42639beb93cSSam Leffler continue; 42739beb93cSSam Leffler } 428f05cddf9SRui Paulo } else if (os_strcmp(pos, "cred={") == 0) { 429f05cddf9SRui Paulo cred = wpa_config_read_cred(f, &line, cred_id++); 430f05cddf9SRui Paulo if (cred == NULL) { 431f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: failed to " 432f05cddf9SRui Paulo "parse cred block.", line); 433f05cddf9SRui Paulo errors++; 434f05cddf9SRui Paulo continue; 435f05cddf9SRui Paulo } 436f05cddf9SRui Paulo if (cred_head == NULL) { 437f05cddf9SRui Paulo cred_head = cred_tail = cred; 438f05cddf9SRui Paulo } else { 439f05cddf9SRui Paulo cred_tail->next = cred; 440f05cddf9SRui Paulo cred_tail = cred; 441f05cddf9SRui Paulo } 44239beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 44339beb93cSSam Leffler } else if (os_strncmp(pos, "blob-base64-", 12) == 0) { 44439beb93cSSam Leffler if (wpa_config_process_blob(config, f, &line, pos + 12) 44539beb93cSSam Leffler < 0) { 446f05cddf9SRui Paulo wpa_printf(MSG_ERROR, "Line %d: failed to " 447f05cddf9SRui Paulo "process blob.", line); 44839beb93cSSam Leffler errors++; 44939beb93cSSam Leffler continue; 45039beb93cSSam Leffler } 45139beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 45239beb93cSSam Leffler } else if (wpa_config_process_global(config, pos, line) < 0) { 45339beb93cSSam Leffler wpa_printf(MSG_ERROR, "Line %d: Invalid configuration " 45439beb93cSSam Leffler "line '%s'.", line, pos); 45539beb93cSSam Leffler errors++; 45639beb93cSSam Leffler continue; 45739beb93cSSam Leffler } 45839beb93cSSam Leffler } 45939beb93cSSam Leffler 46039beb93cSSam Leffler fclose(f); 46139beb93cSSam Leffler 46239beb93cSSam Leffler config->ssid = head; 46339beb93cSSam Leffler wpa_config_debug_dump_networks(config); 464f05cddf9SRui Paulo config->cred = cred_head; 46539beb93cSSam Leffler 466f05cddf9SRui Paulo #ifndef WPA_IGNORE_CONFIG_ERRORS 46739beb93cSSam Leffler if (errors) { 468*85732ac8SCy Schubert if (config != cfgp) 46939beb93cSSam Leffler wpa_config_free(config); 47039beb93cSSam Leffler config = NULL; 47139beb93cSSam Leffler head = NULL; 47239beb93cSSam Leffler } 473f05cddf9SRui Paulo #endif /* WPA_IGNORE_CONFIG_ERRORS */ 47439beb93cSSam Leffler 47539beb93cSSam Leffler return config; 47639beb93cSSam Leffler } 47739beb93cSSam Leffler 47839beb93cSSam Leffler 47939beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE 48039beb93cSSam Leffler 48139beb93cSSam Leffler static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid) 48239beb93cSSam Leffler { 48339beb93cSSam Leffler char *value = wpa_config_get(ssid, field); 48439beb93cSSam Leffler if (value == NULL) 48539beb93cSSam Leffler return; 48639beb93cSSam Leffler fprintf(f, "\t%s=%s\n", field, value); 48739beb93cSSam Leffler os_free(value); 48839beb93cSSam Leffler } 48939beb93cSSam Leffler 49039beb93cSSam Leffler 49139beb93cSSam Leffler static void write_int(FILE *f, const char *field, int value, int def) 49239beb93cSSam Leffler { 49339beb93cSSam Leffler if (value == def) 49439beb93cSSam Leffler return; 49539beb93cSSam Leffler fprintf(f, "\t%s=%d\n", field, value); 49639beb93cSSam Leffler } 49739beb93cSSam Leffler 49839beb93cSSam Leffler 49939beb93cSSam Leffler static void write_bssid(FILE *f, struct wpa_ssid *ssid) 50039beb93cSSam Leffler { 50139beb93cSSam Leffler char *value = wpa_config_get(ssid, "bssid"); 50239beb93cSSam Leffler if (value == NULL) 50339beb93cSSam Leffler return; 50439beb93cSSam Leffler fprintf(f, "\tbssid=%s\n", value); 50539beb93cSSam Leffler os_free(value); 50639beb93cSSam Leffler } 50739beb93cSSam Leffler 50839beb93cSSam Leffler 509*85732ac8SCy Schubert static void write_bssid_hint(FILE *f, struct wpa_ssid *ssid) 510*85732ac8SCy Schubert { 511*85732ac8SCy Schubert char *value = wpa_config_get(ssid, "bssid_hint"); 512*85732ac8SCy Schubert 513*85732ac8SCy Schubert if (!value) 514*85732ac8SCy Schubert return; 515*85732ac8SCy Schubert fprintf(f, "\tbssid_hint=%s\n", value); 516*85732ac8SCy Schubert os_free(value); 517*85732ac8SCy Schubert } 518*85732ac8SCy Schubert 519*85732ac8SCy Schubert 52039beb93cSSam Leffler static void write_psk(FILE *f, struct wpa_ssid *ssid) 52139beb93cSSam Leffler { 522325151a3SRui Paulo char *value; 523325151a3SRui Paulo 524325151a3SRui Paulo if (ssid->mem_only_psk) 525325151a3SRui Paulo return; 526325151a3SRui Paulo 527325151a3SRui Paulo value = wpa_config_get(ssid, "psk"); 52839beb93cSSam Leffler if (value == NULL) 52939beb93cSSam Leffler return; 53039beb93cSSam Leffler fprintf(f, "\tpsk=%s\n", value); 53139beb93cSSam Leffler os_free(value); 53239beb93cSSam Leffler } 53339beb93cSSam Leffler 53439beb93cSSam Leffler 53539beb93cSSam Leffler static void write_proto(FILE *f, struct wpa_ssid *ssid) 53639beb93cSSam Leffler { 53739beb93cSSam Leffler char *value; 53839beb93cSSam Leffler 53939beb93cSSam Leffler if (ssid->proto == DEFAULT_PROTO) 54039beb93cSSam Leffler return; 54139beb93cSSam Leffler 54239beb93cSSam Leffler value = wpa_config_get(ssid, "proto"); 54339beb93cSSam Leffler if (value == NULL) 54439beb93cSSam Leffler return; 54539beb93cSSam Leffler if (value[0]) 54639beb93cSSam Leffler fprintf(f, "\tproto=%s\n", value); 54739beb93cSSam Leffler os_free(value); 54839beb93cSSam Leffler } 54939beb93cSSam Leffler 55039beb93cSSam Leffler 55139beb93cSSam Leffler static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid) 55239beb93cSSam Leffler { 55339beb93cSSam Leffler char *value; 55439beb93cSSam Leffler 55539beb93cSSam Leffler if (ssid->key_mgmt == DEFAULT_KEY_MGMT) 55639beb93cSSam Leffler return; 55739beb93cSSam Leffler 55839beb93cSSam Leffler value = wpa_config_get(ssid, "key_mgmt"); 55939beb93cSSam Leffler if (value == NULL) 56039beb93cSSam Leffler return; 56139beb93cSSam Leffler if (value[0]) 56239beb93cSSam Leffler fprintf(f, "\tkey_mgmt=%s\n", value); 56339beb93cSSam Leffler os_free(value); 56439beb93cSSam Leffler } 56539beb93cSSam Leffler 56639beb93cSSam Leffler 56739beb93cSSam Leffler static void write_pairwise(FILE *f, struct wpa_ssid *ssid) 56839beb93cSSam Leffler { 56939beb93cSSam Leffler char *value; 57039beb93cSSam Leffler 57139beb93cSSam Leffler if (ssid->pairwise_cipher == DEFAULT_PAIRWISE) 57239beb93cSSam Leffler return; 57339beb93cSSam Leffler 57439beb93cSSam Leffler value = wpa_config_get(ssid, "pairwise"); 57539beb93cSSam Leffler if (value == NULL) 57639beb93cSSam Leffler return; 57739beb93cSSam Leffler if (value[0]) 57839beb93cSSam Leffler fprintf(f, "\tpairwise=%s\n", value); 57939beb93cSSam Leffler os_free(value); 58039beb93cSSam Leffler } 58139beb93cSSam Leffler 58239beb93cSSam Leffler 58339beb93cSSam Leffler static void write_group(FILE *f, struct wpa_ssid *ssid) 58439beb93cSSam Leffler { 58539beb93cSSam Leffler char *value; 58639beb93cSSam Leffler 58739beb93cSSam Leffler if (ssid->group_cipher == DEFAULT_GROUP) 58839beb93cSSam Leffler return; 58939beb93cSSam Leffler 59039beb93cSSam Leffler value = wpa_config_get(ssid, "group"); 59139beb93cSSam Leffler if (value == NULL) 59239beb93cSSam Leffler return; 59339beb93cSSam Leffler if (value[0]) 59439beb93cSSam Leffler fprintf(f, "\tgroup=%s\n", value); 59539beb93cSSam Leffler os_free(value); 59639beb93cSSam Leffler } 59739beb93cSSam Leffler 59839beb93cSSam Leffler 599*85732ac8SCy Schubert static void write_group_mgmt(FILE *f, struct wpa_ssid *ssid) 600*85732ac8SCy Schubert { 601*85732ac8SCy Schubert char *value; 602*85732ac8SCy Schubert 603*85732ac8SCy Schubert if (!ssid->group_mgmt_cipher) 604*85732ac8SCy Schubert return; 605*85732ac8SCy Schubert 606*85732ac8SCy Schubert value = wpa_config_get(ssid, "group_mgmt"); 607*85732ac8SCy Schubert if (!value) 608*85732ac8SCy Schubert return; 609*85732ac8SCy Schubert if (value[0]) 610*85732ac8SCy Schubert fprintf(f, "\tgroup_mgmt=%s\n", value); 611*85732ac8SCy Schubert os_free(value); 612*85732ac8SCy Schubert } 613*85732ac8SCy Schubert 614*85732ac8SCy Schubert 61539beb93cSSam Leffler static void write_auth_alg(FILE *f, struct wpa_ssid *ssid) 61639beb93cSSam Leffler { 61739beb93cSSam Leffler char *value; 61839beb93cSSam Leffler 61939beb93cSSam Leffler if (ssid->auth_alg == 0) 62039beb93cSSam Leffler return; 62139beb93cSSam Leffler 62239beb93cSSam Leffler value = wpa_config_get(ssid, "auth_alg"); 62339beb93cSSam Leffler if (value == NULL) 62439beb93cSSam Leffler return; 62539beb93cSSam Leffler if (value[0]) 62639beb93cSSam Leffler fprintf(f, "\tauth_alg=%s\n", value); 62739beb93cSSam Leffler os_free(value); 62839beb93cSSam Leffler } 62939beb93cSSam Leffler 63039beb93cSSam Leffler 63139beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 63239beb93cSSam Leffler static void write_eap(FILE *f, struct wpa_ssid *ssid) 63339beb93cSSam Leffler { 63439beb93cSSam Leffler char *value; 63539beb93cSSam Leffler 63639beb93cSSam Leffler value = wpa_config_get(ssid, "eap"); 63739beb93cSSam Leffler if (value == NULL) 63839beb93cSSam Leffler return; 63939beb93cSSam Leffler 64039beb93cSSam Leffler if (value[0]) 64139beb93cSSam Leffler fprintf(f, "\teap=%s\n", value); 64239beb93cSSam Leffler os_free(value); 64339beb93cSSam Leffler } 64439beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 64539beb93cSSam Leffler 64639beb93cSSam Leffler 64739beb93cSSam Leffler static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid) 64839beb93cSSam Leffler { 64939beb93cSSam Leffler char field[20], *value; 65039beb93cSSam Leffler int res; 65139beb93cSSam Leffler 65239beb93cSSam Leffler res = os_snprintf(field, sizeof(field), "wep_key%d", idx); 6535b9c547cSRui Paulo if (os_snprintf_error(sizeof(field), res)) 65439beb93cSSam Leffler return; 65539beb93cSSam Leffler value = wpa_config_get(ssid, field); 65639beb93cSSam Leffler if (value) { 65739beb93cSSam Leffler fprintf(f, "\t%s=%s\n", field, value); 65839beb93cSSam Leffler os_free(value); 65939beb93cSSam Leffler } 66039beb93cSSam Leffler } 66139beb93cSSam Leffler 66239beb93cSSam Leffler 663f05cddf9SRui Paulo #ifdef CONFIG_P2P 6645b9c547cSRui Paulo 6655b9c547cSRui Paulo static void write_go_p2p_dev_addr(FILE *f, struct wpa_ssid *ssid) 6665b9c547cSRui Paulo { 6675b9c547cSRui Paulo char *value = wpa_config_get(ssid, "go_p2p_dev_addr"); 6685b9c547cSRui Paulo if (value == NULL) 6695b9c547cSRui Paulo return; 6705b9c547cSRui Paulo fprintf(f, "\tgo_p2p_dev_addr=%s\n", value); 6715b9c547cSRui Paulo os_free(value); 6725b9c547cSRui Paulo } 6735b9c547cSRui Paulo 674f05cddf9SRui Paulo static void write_p2p_client_list(FILE *f, struct wpa_ssid *ssid) 675f05cddf9SRui Paulo { 676f05cddf9SRui Paulo char *value = wpa_config_get(ssid, "p2p_client_list"); 677f05cddf9SRui Paulo if (value == NULL) 678f05cddf9SRui Paulo return; 679f05cddf9SRui Paulo fprintf(f, "\tp2p_client_list=%s\n", value); 680f05cddf9SRui Paulo os_free(value); 681f05cddf9SRui Paulo } 6825b9c547cSRui Paulo 6835b9c547cSRui Paulo 6845b9c547cSRui Paulo static void write_psk_list(FILE *f, struct wpa_ssid *ssid) 6855b9c547cSRui Paulo { 6865b9c547cSRui Paulo struct psk_list_entry *psk; 6875b9c547cSRui Paulo char hex[32 * 2 + 1]; 6885b9c547cSRui Paulo 6895b9c547cSRui Paulo dl_list_for_each(psk, &ssid->psk_list, struct psk_list_entry, list) { 6905b9c547cSRui Paulo wpa_snprintf_hex(hex, sizeof(hex), psk->psk, sizeof(psk->psk)); 6915b9c547cSRui Paulo fprintf(f, "\tpsk_list=%s" MACSTR "-%s\n", 6925b9c547cSRui Paulo psk->p2p ? "P2P-" : "", MAC2STR(psk->addr), hex); 6935b9c547cSRui Paulo } 6945b9c547cSRui Paulo } 6955b9c547cSRui Paulo 696f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 697f05cddf9SRui Paulo 698f05cddf9SRui Paulo 699*85732ac8SCy Schubert #ifdef CONFIG_MACSEC 700*85732ac8SCy Schubert 701*85732ac8SCy Schubert static void write_mka_cak(FILE *f, struct wpa_ssid *ssid) 702*85732ac8SCy Schubert { 703*85732ac8SCy Schubert char *value; 704*85732ac8SCy Schubert 705*85732ac8SCy Schubert if (!(ssid->mka_psk_set & MKA_PSK_SET_CAK)) 706*85732ac8SCy Schubert return; 707*85732ac8SCy Schubert 708*85732ac8SCy Schubert value = wpa_config_get(ssid, "mka_cak"); 709*85732ac8SCy Schubert if (!value) 710*85732ac8SCy Schubert return; 711*85732ac8SCy Schubert fprintf(f, "\tmka_cak=%s\n", value); 712*85732ac8SCy Schubert os_free(value); 713*85732ac8SCy Schubert } 714*85732ac8SCy Schubert 715*85732ac8SCy Schubert 716*85732ac8SCy Schubert static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid) 717*85732ac8SCy Schubert { 718*85732ac8SCy Schubert char *value; 719*85732ac8SCy Schubert 720*85732ac8SCy Schubert if (!(ssid->mka_psk_set & MKA_PSK_SET_CKN)) 721*85732ac8SCy Schubert return; 722*85732ac8SCy Schubert 723*85732ac8SCy Schubert value = wpa_config_get(ssid, "mka_ckn"); 724*85732ac8SCy Schubert if (!value) 725*85732ac8SCy Schubert return; 726*85732ac8SCy Schubert fprintf(f, "\tmka_ckn=%s\n", value); 727*85732ac8SCy Schubert os_free(value); 728*85732ac8SCy Schubert } 729*85732ac8SCy Schubert 730*85732ac8SCy Schubert #endif /* CONFIG_MACSEC */ 731*85732ac8SCy Schubert 732*85732ac8SCy Schubert 73339beb93cSSam Leffler static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid) 73439beb93cSSam Leffler { 73539beb93cSSam Leffler int i; 73639beb93cSSam Leffler 73739beb93cSSam Leffler #define STR(t) write_str(f, #t, ssid) 73839beb93cSSam Leffler #define INT(t) write_int(f, #t, ssid->t, 0) 73939beb93cSSam Leffler #define INTe(t) write_int(f, #t, ssid->eap.t, 0) 74039beb93cSSam Leffler #define INT_DEF(t, def) write_int(f, #t, ssid->t, def) 74139beb93cSSam Leffler #define INT_DEFe(t, def) write_int(f, #t, ssid->eap.t, def) 74239beb93cSSam Leffler 74339beb93cSSam Leffler STR(ssid); 74439beb93cSSam Leffler INT(scan_ssid); 74539beb93cSSam Leffler write_bssid(f, ssid); 746*85732ac8SCy Schubert write_bssid_hint(f, ssid); 7475b9c547cSRui Paulo write_str(f, "bssid_blacklist", ssid); 7485b9c547cSRui Paulo write_str(f, "bssid_whitelist", ssid); 74939beb93cSSam Leffler write_psk(f, ssid); 750325151a3SRui Paulo INT(mem_only_psk); 751*85732ac8SCy Schubert STR(sae_password); 752*85732ac8SCy Schubert STR(sae_password_id); 75339beb93cSSam Leffler write_proto(f, ssid); 75439beb93cSSam Leffler write_key_mgmt(f, ssid); 755f05cddf9SRui Paulo INT_DEF(bg_scan_period, DEFAULT_BG_SCAN_PERIOD); 75639beb93cSSam Leffler write_pairwise(f, ssid); 75739beb93cSSam Leffler write_group(f, ssid); 758*85732ac8SCy Schubert write_group_mgmt(f, ssid); 75939beb93cSSam Leffler write_auth_alg(f, ssid); 760f05cddf9SRui Paulo STR(bgscan); 761f05cddf9SRui Paulo STR(autoscan); 7625b9c547cSRui Paulo STR(scan_freq); 76339beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 76439beb93cSSam Leffler write_eap(f, ssid); 76539beb93cSSam Leffler STR(identity); 76639beb93cSSam Leffler STR(anonymous_identity); 767*85732ac8SCy Schubert STR(imsi_identity); 76839beb93cSSam Leffler STR(password); 76939beb93cSSam Leffler STR(ca_cert); 77039beb93cSSam Leffler STR(ca_path); 77139beb93cSSam Leffler STR(client_cert); 77239beb93cSSam Leffler STR(private_key); 77339beb93cSSam Leffler STR(private_key_passwd); 77439beb93cSSam Leffler STR(dh_file); 77539beb93cSSam Leffler STR(subject_match); 77639beb93cSSam Leffler STR(altsubject_match); 7775b9c547cSRui Paulo STR(domain_suffix_match); 7785b9c547cSRui Paulo STR(domain_match); 77939beb93cSSam Leffler STR(ca_cert2); 78039beb93cSSam Leffler STR(ca_path2); 78139beb93cSSam Leffler STR(client_cert2); 78239beb93cSSam Leffler STR(private_key2); 78339beb93cSSam Leffler STR(private_key2_passwd); 78439beb93cSSam Leffler STR(dh_file2); 78539beb93cSSam Leffler STR(subject_match2); 78639beb93cSSam Leffler STR(altsubject_match2); 7875b9c547cSRui Paulo STR(domain_suffix_match2); 7885b9c547cSRui Paulo STR(domain_match2); 78939beb93cSSam Leffler STR(phase1); 79039beb93cSSam Leffler STR(phase2); 79139beb93cSSam Leffler STR(pcsc); 79239beb93cSSam Leffler STR(pin); 79339beb93cSSam Leffler STR(engine_id); 79439beb93cSSam Leffler STR(key_id); 79539beb93cSSam Leffler STR(cert_id); 79639beb93cSSam Leffler STR(ca_cert_id); 79739beb93cSSam Leffler STR(key2_id); 79839beb93cSSam Leffler STR(pin2); 79939beb93cSSam Leffler STR(engine2_id); 80039beb93cSSam Leffler STR(cert2_id); 80139beb93cSSam Leffler STR(ca_cert2_id); 80239beb93cSSam Leffler INTe(engine); 80339beb93cSSam Leffler INTe(engine2); 80439beb93cSSam Leffler INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS); 8055b9c547cSRui Paulo STR(openssl_ciphers); 8065b9c547cSRui Paulo INTe(erp); 80739beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 80839beb93cSSam Leffler for (i = 0; i < 4; i++) 80939beb93cSSam Leffler write_wep_key(f, i, ssid); 81039beb93cSSam Leffler INT(wep_tx_keyidx); 81139beb93cSSam Leffler INT(priority); 81239beb93cSSam Leffler #ifdef IEEE8021X_EAPOL 81339beb93cSSam Leffler INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND); 81439beb93cSSam Leffler STR(pac_file); 81539beb93cSSam Leffler INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE); 8165b9c547cSRui Paulo INTe(ocsp); 8175b9c547cSRui Paulo INT_DEFe(sim_num, DEFAULT_USER_SELECTED_SIM); 81839beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */ 81939beb93cSSam Leffler INT(mode); 8205b9c547cSRui Paulo INT(no_auto_peer); 821f05cddf9SRui Paulo INT(frequency); 8225b9c547cSRui Paulo INT(fixed_freq); 823780fb4a2SCy Schubert #ifdef CONFIG_ACS 824780fb4a2SCy Schubert INT(acs); 825780fb4a2SCy Schubert #endif /* CONFIG_ACS */ 826f05cddf9SRui Paulo write_int(f, "proactive_key_caching", ssid->proactive_key_caching, -1); 82739beb93cSSam Leffler INT(disabled); 8285b9c547cSRui Paulo INT(mixed_cell); 829*85732ac8SCy Schubert INT(vht); 830*85732ac8SCy Schubert INT_DEF(ht, 1); 831*85732ac8SCy Schubert INT(ht40); 832780fb4a2SCy Schubert INT(max_oper_chwidth); 833*85732ac8SCy Schubert INT(vht_center_freq1); 834*85732ac8SCy Schubert INT(vht_center_freq2); 835780fb4a2SCy Schubert INT(pbss); 836780fb4a2SCy Schubert INT(wps_disabled); 837*85732ac8SCy Schubert INT(fils_dh_group); 83839beb93cSSam Leffler #ifdef CONFIG_IEEE80211W 839f05cddf9SRui Paulo write_int(f, "ieee80211w", ssid->ieee80211w, 840f05cddf9SRui Paulo MGMT_FRAME_PROTECTION_DEFAULT); 84139beb93cSSam Leffler #endif /* CONFIG_IEEE80211W */ 84239beb93cSSam Leffler STR(id_str); 843f05cddf9SRui Paulo #ifdef CONFIG_P2P 8445b9c547cSRui Paulo write_go_p2p_dev_addr(f, ssid); 845f05cddf9SRui Paulo write_p2p_client_list(f, ssid); 8465b9c547cSRui Paulo write_psk_list(f, ssid); 847f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 8485b9c547cSRui Paulo INT(ap_max_inactivity); 8495b9c547cSRui Paulo INT(dtim_period); 8505b9c547cSRui Paulo INT(beacon_int); 8515b9c547cSRui Paulo #ifdef CONFIG_MACSEC 8525b9c547cSRui Paulo INT(macsec_policy); 853*85732ac8SCy Schubert write_mka_cak(f, ssid); 854*85732ac8SCy Schubert write_mka_ckn(f, ssid); 855*85732ac8SCy Schubert INT(macsec_integ_only); 856*85732ac8SCy Schubert INT(macsec_port); 857*85732ac8SCy Schubert INT_DEF(mka_priority, DEFAULT_PRIO_NOT_KEY_SERVER); 8585b9c547cSRui Paulo #endif /* CONFIG_MACSEC */ 8595b9c547cSRui Paulo #ifdef CONFIG_HS20 8605b9c547cSRui Paulo INT(update_identifier); 861*85732ac8SCy Schubert STR(roaming_consortium_selection); 8625b9c547cSRui Paulo #endif /* CONFIG_HS20 */ 8635b9c547cSRui Paulo write_int(f, "mac_addr", ssid->mac_addr, -1); 8645b9c547cSRui Paulo #ifdef CONFIG_MESH 8655b9c547cSRui Paulo STR(mesh_basic_rates); 8665b9c547cSRui Paulo INT_DEF(dot11MeshMaxRetries, DEFAULT_MESH_MAX_RETRIES); 8675b9c547cSRui Paulo INT_DEF(dot11MeshRetryTimeout, DEFAULT_MESH_RETRY_TIMEOUT); 8685b9c547cSRui Paulo INT_DEF(dot11MeshConfirmTimeout, DEFAULT_MESH_CONFIRM_TIMEOUT); 8695b9c547cSRui Paulo INT_DEF(dot11MeshHoldingTimeout, DEFAULT_MESH_HOLDING_TIMEOUT); 870*85732ac8SCy Schubert INT_DEF(mesh_rssi_threshold, DEFAULT_MESH_RSSI_THRESHOLD); 8715b9c547cSRui Paulo #endif /* CONFIG_MESH */ 8725b9c547cSRui Paulo INT(wpa_ptk_rekey); 873780fb4a2SCy Schubert INT(group_rekey); 8745b9c547cSRui Paulo INT(ignore_broadcast_ssid); 875*85732ac8SCy Schubert #ifdef CONFIG_DPP 876*85732ac8SCy Schubert STR(dpp_connector); 877*85732ac8SCy Schubert STR(dpp_netaccesskey); 878*85732ac8SCy Schubert INT(dpp_netaccesskey_expiry); 879*85732ac8SCy Schubert STR(dpp_csign); 880*85732ac8SCy Schubert #endif /* CONFIG_DPP */ 881*85732ac8SCy Schubert INT(owe_group); 882*85732ac8SCy Schubert INT(owe_only); 8835b9c547cSRui Paulo #ifdef CONFIG_HT_OVERRIDES 8845b9c547cSRui Paulo INT_DEF(disable_ht, DEFAULT_DISABLE_HT); 8855b9c547cSRui Paulo INT_DEF(disable_ht40, DEFAULT_DISABLE_HT40); 8865b9c547cSRui Paulo INT_DEF(disable_sgi, DEFAULT_DISABLE_SGI); 8875b9c547cSRui Paulo INT_DEF(disable_ldpc, DEFAULT_DISABLE_LDPC); 8885b9c547cSRui Paulo INT(ht40_intolerant); 8895b9c547cSRui Paulo INT_DEF(disable_max_amsdu, DEFAULT_DISABLE_MAX_AMSDU); 8905b9c547cSRui Paulo INT_DEF(ampdu_factor, DEFAULT_AMPDU_FACTOR); 8915b9c547cSRui Paulo INT_DEF(ampdu_density, DEFAULT_AMPDU_DENSITY); 8925b9c547cSRui Paulo STR(ht_mcs); 8935b9c547cSRui Paulo #endif /* CONFIG_HT_OVERRIDES */ 8945b9c547cSRui Paulo #ifdef CONFIG_VHT_OVERRIDES 8955b9c547cSRui Paulo INT(disable_vht); 8965b9c547cSRui Paulo INT(vht_capa); 8975b9c547cSRui Paulo INT(vht_capa_mask); 8985b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_1, -1); 8995b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_2, -1); 9005b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_3, -1); 9015b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_4, -1); 9025b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_5, -1); 9035b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_6, -1); 9045b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_7, -1); 9055b9c547cSRui Paulo INT_DEF(vht_rx_mcs_nss_8, -1); 9065b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_1, -1); 9075b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_2, -1); 9085b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_3, -1); 9095b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_4, -1); 9105b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_5, -1); 9115b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_6, -1); 9125b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_7, -1); 9135b9c547cSRui Paulo INT_DEF(vht_tx_mcs_nss_8, -1); 9145b9c547cSRui Paulo #endif /* CONFIG_VHT_OVERRIDES */ 91539beb93cSSam Leffler 91639beb93cSSam Leffler #undef STR 91739beb93cSSam Leffler #undef INT 91839beb93cSSam Leffler #undef INT_DEF 91939beb93cSSam Leffler } 92039beb93cSSam Leffler 92139beb93cSSam Leffler 922f05cddf9SRui Paulo static void wpa_config_write_cred(FILE *f, struct wpa_cred *cred) 923f05cddf9SRui Paulo { 9245b9c547cSRui Paulo size_t i; 9255b9c547cSRui Paulo 926f05cddf9SRui Paulo if (cred->priority) 927f05cddf9SRui Paulo fprintf(f, "\tpriority=%d\n", cred->priority); 928f05cddf9SRui Paulo if (cred->pcsc) 929f05cddf9SRui Paulo fprintf(f, "\tpcsc=%d\n", cred->pcsc); 930f05cddf9SRui Paulo if (cred->realm) 931f05cddf9SRui Paulo fprintf(f, "\trealm=\"%s\"\n", cred->realm); 932f05cddf9SRui Paulo if (cred->username) 933f05cddf9SRui Paulo fprintf(f, "\tusername=\"%s\"\n", cred->username); 934f05cddf9SRui Paulo if (cred->password && cred->ext_password) 935f05cddf9SRui Paulo fprintf(f, "\tpassword=ext:%s\n", cred->password); 936f05cddf9SRui Paulo else if (cred->password) 937f05cddf9SRui Paulo fprintf(f, "\tpassword=\"%s\"\n", cred->password); 938f05cddf9SRui Paulo if (cred->ca_cert) 939f05cddf9SRui Paulo fprintf(f, "\tca_cert=\"%s\"\n", cred->ca_cert); 940f05cddf9SRui Paulo if (cred->client_cert) 941f05cddf9SRui Paulo fprintf(f, "\tclient_cert=\"%s\"\n", cred->client_cert); 942f05cddf9SRui Paulo if (cred->private_key) 943f05cddf9SRui Paulo fprintf(f, "\tprivate_key=\"%s\"\n", cred->private_key); 944f05cddf9SRui Paulo if (cred->private_key_passwd) 945f05cddf9SRui Paulo fprintf(f, "\tprivate_key_passwd=\"%s\"\n", 946f05cddf9SRui Paulo cred->private_key_passwd); 947f05cddf9SRui Paulo if (cred->imsi) 948f05cddf9SRui Paulo fprintf(f, "\timsi=\"%s\"\n", cred->imsi); 949f05cddf9SRui Paulo if (cred->milenage) 950f05cddf9SRui Paulo fprintf(f, "\tmilenage=\"%s\"\n", cred->milenage); 9515b9c547cSRui Paulo for (i = 0; i < cred->num_domain; i++) 9525b9c547cSRui Paulo fprintf(f, "\tdomain=\"%s\"\n", cred->domain[i]); 9535b9c547cSRui Paulo if (cred->domain_suffix_match) 9545b9c547cSRui Paulo fprintf(f, "\tdomain_suffix_match=\"%s\"\n", 9555b9c547cSRui Paulo cred->domain_suffix_match); 956f05cddf9SRui Paulo if (cred->roaming_consortium_len) { 957f05cddf9SRui Paulo fprintf(f, "\troaming_consortium="); 958f05cddf9SRui Paulo for (i = 0; i < cred->roaming_consortium_len; i++) 959f05cddf9SRui Paulo fprintf(f, "%02x", cred->roaming_consortium[i]); 960f05cddf9SRui Paulo fprintf(f, "\n"); 961f05cddf9SRui Paulo } 962f05cddf9SRui Paulo if (cred->eap_method) { 963f05cddf9SRui Paulo const char *name; 964f05cddf9SRui Paulo name = eap_get_name(cred->eap_method[0].vendor, 965f05cddf9SRui Paulo cred->eap_method[0].method); 9665b9c547cSRui Paulo if (name) 967f05cddf9SRui Paulo fprintf(f, "\teap=%s\n", name); 968f05cddf9SRui Paulo } 969f05cddf9SRui Paulo if (cred->phase1) 970f05cddf9SRui Paulo fprintf(f, "\tphase1=\"%s\"\n", cred->phase1); 971f05cddf9SRui Paulo if (cred->phase2) 972f05cddf9SRui Paulo fprintf(f, "\tphase2=\"%s\"\n", cred->phase2); 973f05cddf9SRui Paulo if (cred->excluded_ssid) { 9745b9c547cSRui Paulo size_t j; 975f05cddf9SRui Paulo for (i = 0; i < cred->num_excluded_ssid; i++) { 976f05cddf9SRui Paulo struct excluded_ssid *e = &cred->excluded_ssid[i]; 977f05cddf9SRui Paulo fprintf(f, "\texcluded_ssid="); 978f05cddf9SRui Paulo for (j = 0; j < e->ssid_len; j++) 979f05cddf9SRui Paulo fprintf(f, "%02x", e->ssid[j]); 980f05cddf9SRui Paulo fprintf(f, "\n"); 981f05cddf9SRui Paulo } 982f05cddf9SRui Paulo } 9835b9c547cSRui Paulo if (cred->roaming_partner) { 9845b9c547cSRui Paulo for (i = 0; i < cred->num_roaming_partner; i++) { 9855b9c547cSRui Paulo struct roaming_partner *p = &cred->roaming_partner[i]; 9865b9c547cSRui Paulo fprintf(f, "\troaming_partner=\"%s,%d,%u,%s\"\n", 9875b9c547cSRui Paulo p->fqdn, p->exact_match, p->priority, 9885b9c547cSRui Paulo p->country); 9895b9c547cSRui Paulo } 9905b9c547cSRui Paulo } 9915b9c547cSRui Paulo if (cred->update_identifier) 9925b9c547cSRui Paulo fprintf(f, "\tupdate_identifier=%d\n", cred->update_identifier); 9935b9c547cSRui Paulo 9945b9c547cSRui Paulo if (cred->provisioning_sp) 9955b9c547cSRui Paulo fprintf(f, "\tprovisioning_sp=\"%s\"\n", cred->provisioning_sp); 9965b9c547cSRui Paulo if (cred->sp_priority) 9975b9c547cSRui Paulo fprintf(f, "\tsp_priority=%d\n", cred->sp_priority); 9985b9c547cSRui Paulo 9995b9c547cSRui Paulo if (cred->min_dl_bandwidth_home) 10005b9c547cSRui Paulo fprintf(f, "\tmin_dl_bandwidth_home=%u\n", 10015b9c547cSRui Paulo cred->min_dl_bandwidth_home); 10025b9c547cSRui Paulo if (cred->min_ul_bandwidth_home) 10035b9c547cSRui Paulo fprintf(f, "\tmin_ul_bandwidth_home=%u\n", 10045b9c547cSRui Paulo cred->min_ul_bandwidth_home); 10055b9c547cSRui Paulo if (cred->min_dl_bandwidth_roaming) 10065b9c547cSRui Paulo fprintf(f, "\tmin_dl_bandwidth_roaming=%u\n", 10075b9c547cSRui Paulo cred->min_dl_bandwidth_roaming); 10085b9c547cSRui Paulo if (cred->min_ul_bandwidth_roaming) 10095b9c547cSRui Paulo fprintf(f, "\tmin_ul_bandwidth_roaming=%u\n", 10105b9c547cSRui Paulo cred->min_ul_bandwidth_roaming); 10115b9c547cSRui Paulo 10125b9c547cSRui Paulo if (cred->max_bss_load) 10135b9c547cSRui Paulo fprintf(f, "\tmax_bss_load=%u\n", 10145b9c547cSRui Paulo cred->max_bss_load); 10155b9c547cSRui Paulo 10165b9c547cSRui Paulo if (cred->ocsp) 10175b9c547cSRui Paulo fprintf(f, "\tocsp=%d\n", cred->ocsp); 10185b9c547cSRui Paulo 10195b9c547cSRui Paulo if (cred->num_req_conn_capab) { 10205b9c547cSRui Paulo for (i = 0; i < cred->num_req_conn_capab; i++) { 10215b9c547cSRui Paulo int *ports; 10225b9c547cSRui Paulo 10235b9c547cSRui Paulo fprintf(f, "\treq_conn_capab=%u", 10245b9c547cSRui Paulo cred->req_conn_capab_proto[i]); 10255b9c547cSRui Paulo ports = cred->req_conn_capab_port[i]; 10265b9c547cSRui Paulo if (ports) { 10275b9c547cSRui Paulo int j; 10285b9c547cSRui Paulo for (j = 0; ports[j] != -1; j++) { 10295b9c547cSRui Paulo fprintf(f, "%s%d", j > 0 ? "," : ":", 10305b9c547cSRui Paulo ports[j]); 10315b9c547cSRui Paulo } 10325b9c547cSRui Paulo } 10335b9c547cSRui Paulo fprintf(f, "\n"); 10345b9c547cSRui Paulo } 10355b9c547cSRui Paulo } 10365b9c547cSRui Paulo 10375b9c547cSRui Paulo if (cred->required_roaming_consortium_len) { 10385b9c547cSRui Paulo fprintf(f, "\trequired_roaming_consortium="); 10395b9c547cSRui Paulo for (i = 0; i < cred->required_roaming_consortium_len; i++) 10405b9c547cSRui Paulo fprintf(f, "%02x", 10415b9c547cSRui Paulo cred->required_roaming_consortium[i]); 10425b9c547cSRui Paulo fprintf(f, "\n"); 10435b9c547cSRui Paulo } 10445b9c547cSRui Paulo 1045*85732ac8SCy Schubert if (cred->num_roaming_consortiums) { 1046*85732ac8SCy Schubert size_t j; 1047*85732ac8SCy Schubert 1048*85732ac8SCy Schubert fprintf(f, "\troaming_consortiums=\""); 1049*85732ac8SCy Schubert for (i = 0; i < cred->num_roaming_consortiums; i++) { 1050*85732ac8SCy Schubert if (i > 0) 1051*85732ac8SCy Schubert fprintf(f, ","); 1052*85732ac8SCy Schubert for (j = 0; j < cred->roaming_consortiums_len[i]; j++) 1053*85732ac8SCy Schubert fprintf(f, "%02x", 1054*85732ac8SCy Schubert cred->roaming_consortiums[i][j]); 1055*85732ac8SCy Schubert } 1056*85732ac8SCy Schubert fprintf(f, "\"\n"); 1057*85732ac8SCy Schubert } 1058*85732ac8SCy Schubert 10595b9c547cSRui Paulo if (cred->sim_num != DEFAULT_USER_SELECTED_SIM) 10605b9c547cSRui Paulo fprintf(f, "\tsim_num=%d\n", cred->sim_num); 1061f05cddf9SRui Paulo } 1062f05cddf9SRui Paulo 1063f05cddf9SRui Paulo 106439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 106539beb93cSSam Leffler static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob) 106639beb93cSSam Leffler { 106739beb93cSSam Leffler unsigned char *encoded; 106839beb93cSSam Leffler 106939beb93cSSam Leffler encoded = base64_encode(blob->data, blob->len, NULL); 107039beb93cSSam Leffler if (encoded == NULL) 107139beb93cSSam Leffler return -1; 107239beb93cSSam Leffler 107339beb93cSSam Leffler fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded); 107439beb93cSSam Leffler os_free(encoded); 107539beb93cSSam Leffler return 0; 107639beb93cSSam Leffler } 107739beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 107839beb93cSSam Leffler 107939beb93cSSam Leffler 1080f05cddf9SRui Paulo static void write_global_bin(FILE *f, const char *field, 1081f05cddf9SRui Paulo const struct wpabuf *val) 1082f05cddf9SRui Paulo { 1083f05cddf9SRui Paulo size_t i; 1084f05cddf9SRui Paulo const u8 *pos; 1085f05cddf9SRui Paulo 1086f05cddf9SRui Paulo if (val == NULL) 1087f05cddf9SRui Paulo return; 1088f05cddf9SRui Paulo 1089f05cddf9SRui Paulo fprintf(f, "%s=", field); 1090f05cddf9SRui Paulo pos = wpabuf_head(val); 1091f05cddf9SRui Paulo for (i = 0; i < wpabuf_len(val); i++) 1092f05cddf9SRui Paulo fprintf(f, "%02X", *pos++); 1093f05cddf9SRui Paulo fprintf(f, "\n"); 1094f05cddf9SRui Paulo } 1095f05cddf9SRui Paulo 1096f05cddf9SRui Paulo 109739beb93cSSam Leffler static void wpa_config_write_global(FILE *f, struct wpa_config *config) 109839beb93cSSam Leffler { 109939beb93cSSam Leffler #ifdef CONFIG_CTRL_IFACE 110039beb93cSSam Leffler if (config->ctrl_interface) 110139beb93cSSam Leffler fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface); 110239beb93cSSam Leffler if (config->ctrl_interface_group) 110339beb93cSSam Leffler fprintf(f, "ctrl_interface_group=%s\n", 110439beb93cSSam Leffler config->ctrl_interface_group); 110539beb93cSSam Leffler #endif /* CONFIG_CTRL_IFACE */ 110639beb93cSSam Leffler if (config->eapol_version != DEFAULT_EAPOL_VERSION) 110739beb93cSSam Leffler fprintf(f, "eapol_version=%d\n", config->eapol_version); 110839beb93cSSam Leffler if (config->ap_scan != DEFAULT_AP_SCAN) 110939beb93cSSam Leffler fprintf(f, "ap_scan=%d\n", config->ap_scan); 1110f05cddf9SRui Paulo if (config->disable_scan_offload) 1111f05cddf9SRui Paulo fprintf(f, "disable_scan_offload=%d\n", 1112f05cddf9SRui Paulo config->disable_scan_offload); 111339beb93cSSam Leffler if (config->fast_reauth != DEFAULT_FAST_REAUTH) 111439beb93cSSam Leffler fprintf(f, "fast_reauth=%d\n", config->fast_reauth); 111539beb93cSSam Leffler if (config->opensc_engine_path) 111639beb93cSSam Leffler fprintf(f, "opensc_engine_path=%s\n", 111739beb93cSSam Leffler config->opensc_engine_path); 111839beb93cSSam Leffler if (config->pkcs11_engine_path) 111939beb93cSSam Leffler fprintf(f, "pkcs11_engine_path=%s\n", 112039beb93cSSam Leffler config->pkcs11_engine_path); 112139beb93cSSam Leffler if (config->pkcs11_module_path) 112239beb93cSSam Leffler fprintf(f, "pkcs11_module_path=%s\n", 112339beb93cSSam Leffler config->pkcs11_module_path); 11245b9c547cSRui Paulo if (config->openssl_ciphers) 11255b9c547cSRui Paulo fprintf(f, "openssl_ciphers=%s\n", config->openssl_ciphers); 1126f05cddf9SRui Paulo if (config->pcsc_reader) 1127f05cddf9SRui Paulo fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader); 1128f05cddf9SRui Paulo if (config->pcsc_pin) 1129f05cddf9SRui Paulo fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin); 113039beb93cSSam Leffler if (config->driver_param) 113139beb93cSSam Leffler fprintf(f, "driver_param=%s\n", config->driver_param); 113239beb93cSSam Leffler if (config->dot11RSNAConfigPMKLifetime) 1133325151a3SRui Paulo fprintf(f, "dot11RSNAConfigPMKLifetime=%u\n", 113439beb93cSSam Leffler config->dot11RSNAConfigPMKLifetime); 113539beb93cSSam Leffler if (config->dot11RSNAConfigPMKReauthThreshold) 1136325151a3SRui Paulo fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%u\n", 113739beb93cSSam Leffler config->dot11RSNAConfigPMKReauthThreshold); 113839beb93cSSam Leffler if (config->dot11RSNAConfigSATimeout) 1139325151a3SRui Paulo fprintf(f, "dot11RSNAConfigSATimeout=%u\n", 114039beb93cSSam Leffler config->dot11RSNAConfigSATimeout); 114139beb93cSSam Leffler if (config->update_config) 114239beb93cSSam Leffler fprintf(f, "update_config=%d\n", config->update_config); 114339beb93cSSam Leffler #ifdef CONFIG_WPS 114439beb93cSSam Leffler if (!is_nil_uuid(config->uuid)) { 114539beb93cSSam Leffler char buf[40]; 114639beb93cSSam Leffler uuid_bin2str(config->uuid, buf, sizeof(buf)); 114739beb93cSSam Leffler fprintf(f, "uuid=%s\n", buf); 114839beb93cSSam Leffler } 1149*85732ac8SCy Schubert if (config->auto_uuid) 1150*85732ac8SCy Schubert fprintf(f, "auto_uuid=%d\n", config->auto_uuid); 115139beb93cSSam Leffler if (config->device_name) 115239beb93cSSam Leffler fprintf(f, "device_name=%s\n", config->device_name); 115339beb93cSSam Leffler if (config->manufacturer) 115439beb93cSSam Leffler fprintf(f, "manufacturer=%s\n", config->manufacturer); 115539beb93cSSam Leffler if (config->model_name) 115639beb93cSSam Leffler fprintf(f, "model_name=%s\n", config->model_name); 115739beb93cSSam Leffler if (config->model_number) 115839beb93cSSam Leffler fprintf(f, "model_number=%s\n", config->model_number); 115939beb93cSSam Leffler if (config->serial_number) 116039beb93cSSam Leffler fprintf(f, "serial_number=%s\n", config->serial_number); 1161f05cddf9SRui Paulo { 1162f05cddf9SRui Paulo char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; 1163f05cddf9SRui Paulo buf = wps_dev_type_bin2str(config->device_type, 1164f05cddf9SRui Paulo _buf, sizeof(_buf)); 1165f05cddf9SRui Paulo if (os_strcmp(buf, "0-00000000-0") != 0) 1166f05cddf9SRui Paulo fprintf(f, "device_type=%s\n", buf); 1167f05cddf9SRui Paulo } 116839beb93cSSam Leffler if (WPA_GET_BE32(config->os_version)) 116939beb93cSSam Leffler fprintf(f, "os_version=%08x\n", 117039beb93cSSam Leffler WPA_GET_BE32(config->os_version)); 1171e28a4053SRui Paulo if (config->config_methods) 1172e28a4053SRui Paulo fprintf(f, "config_methods=%s\n", config->config_methods); 117339beb93cSSam Leffler if (config->wps_cred_processing) 117439beb93cSSam Leffler fprintf(f, "wps_cred_processing=%d\n", 117539beb93cSSam Leffler config->wps_cred_processing); 1176f05cddf9SRui Paulo if (config->wps_vendor_ext_m1) { 1177f05cddf9SRui Paulo int i, len = wpabuf_len(config->wps_vendor_ext_m1); 1178f05cddf9SRui Paulo const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1); 1179f05cddf9SRui Paulo if (len > 0) { 1180f05cddf9SRui Paulo fprintf(f, "wps_vendor_ext_m1="); 1181f05cddf9SRui Paulo for (i = 0; i < len; i++) 1182f05cddf9SRui Paulo fprintf(f, "%02x", *p++); 1183f05cddf9SRui Paulo fprintf(f, "\n"); 1184f05cddf9SRui Paulo } 1185f05cddf9SRui Paulo } 118639beb93cSSam Leffler #endif /* CONFIG_WPS */ 1187f05cddf9SRui Paulo #ifdef CONFIG_P2P 1188*85732ac8SCy Schubert { 1189*85732ac8SCy Schubert int i; 1190*85732ac8SCy Schubert char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; 1191*85732ac8SCy Schubert 1192*85732ac8SCy Schubert for (i = 0; i < config->num_sec_device_types; i++) { 1193*85732ac8SCy Schubert buf = wps_dev_type_bin2str(config->sec_device_type[i], 1194*85732ac8SCy Schubert _buf, sizeof(_buf)); 1195*85732ac8SCy Schubert if (buf) 1196*85732ac8SCy Schubert fprintf(f, "sec_device_type=%s\n", buf); 1197*85732ac8SCy Schubert } 1198*85732ac8SCy Schubert } 1199f05cddf9SRui Paulo if (config->p2p_listen_reg_class) 1200325151a3SRui Paulo fprintf(f, "p2p_listen_reg_class=%d\n", 1201f05cddf9SRui Paulo config->p2p_listen_reg_class); 1202f05cddf9SRui Paulo if (config->p2p_listen_channel) 1203325151a3SRui Paulo fprintf(f, "p2p_listen_channel=%d\n", 1204f05cddf9SRui Paulo config->p2p_listen_channel); 1205f05cddf9SRui Paulo if (config->p2p_oper_reg_class) 1206325151a3SRui Paulo fprintf(f, "p2p_oper_reg_class=%d\n", 1207f05cddf9SRui Paulo config->p2p_oper_reg_class); 1208f05cddf9SRui Paulo if (config->p2p_oper_channel) 1209325151a3SRui Paulo fprintf(f, "p2p_oper_channel=%d\n", config->p2p_oper_channel); 1210f05cddf9SRui Paulo if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT) 1211325151a3SRui Paulo fprintf(f, "p2p_go_intent=%d\n", config->p2p_go_intent); 1212f05cddf9SRui Paulo if (config->p2p_ssid_postfix) 1213f05cddf9SRui Paulo fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix); 1214f05cddf9SRui Paulo if (config->persistent_reconnect) 1215325151a3SRui Paulo fprintf(f, "persistent_reconnect=%d\n", 1216f05cddf9SRui Paulo config->persistent_reconnect); 1217f05cddf9SRui Paulo if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS) 1218325151a3SRui Paulo fprintf(f, "p2p_intra_bss=%d\n", config->p2p_intra_bss); 1219f05cddf9SRui Paulo if (config->p2p_group_idle) 1220325151a3SRui Paulo fprintf(f, "p2p_group_idle=%d\n", config->p2p_group_idle); 12215b9c547cSRui Paulo if (config->p2p_passphrase_len) 12225b9c547cSRui Paulo fprintf(f, "p2p_passphrase_len=%u\n", 12235b9c547cSRui Paulo config->p2p_passphrase_len); 1224f05cddf9SRui Paulo if (config->p2p_pref_chan) { 1225f05cddf9SRui Paulo unsigned int i; 1226f05cddf9SRui Paulo fprintf(f, "p2p_pref_chan="); 1227f05cddf9SRui Paulo for (i = 0; i < config->num_p2p_pref_chan; i++) { 1228f05cddf9SRui Paulo fprintf(f, "%s%u:%u", i > 0 ? "," : "", 1229f05cddf9SRui Paulo config->p2p_pref_chan[i].op_class, 1230f05cddf9SRui Paulo config->p2p_pref_chan[i].chan); 1231f05cddf9SRui Paulo } 1232f05cddf9SRui Paulo fprintf(f, "\n"); 1233f05cddf9SRui Paulo } 12345b9c547cSRui Paulo if (config->p2p_no_go_freq.num) { 12355b9c547cSRui Paulo char *val = freq_range_list_str(&config->p2p_no_go_freq); 12365b9c547cSRui Paulo if (val) { 12375b9c547cSRui Paulo fprintf(f, "p2p_no_go_freq=%s\n", val); 12385b9c547cSRui Paulo os_free(val); 12395b9c547cSRui Paulo } 12405b9c547cSRui Paulo } 12415b9c547cSRui Paulo if (config->p2p_add_cli_chan) 12425b9c547cSRui Paulo fprintf(f, "p2p_add_cli_chan=%d\n", config->p2p_add_cli_chan); 12435b9c547cSRui Paulo if (config->p2p_optimize_listen_chan != 12445b9c547cSRui Paulo DEFAULT_P2P_OPTIMIZE_LISTEN_CHAN) 12455b9c547cSRui Paulo fprintf(f, "p2p_optimize_listen_chan=%d\n", 12465b9c547cSRui Paulo config->p2p_optimize_listen_chan); 1247f05cddf9SRui Paulo if (config->p2p_go_ht40) 1248325151a3SRui Paulo fprintf(f, "p2p_go_ht40=%d\n", config->p2p_go_ht40); 12495b9c547cSRui Paulo if (config->p2p_go_vht) 1250325151a3SRui Paulo fprintf(f, "p2p_go_vht=%d\n", config->p2p_go_vht); 12515b9c547cSRui Paulo if (config->p2p_go_ctwindow != DEFAULT_P2P_GO_CTWINDOW) 1252325151a3SRui Paulo fprintf(f, "p2p_go_ctwindow=%d\n", config->p2p_go_ctwindow); 1253f05cddf9SRui Paulo if (config->p2p_disabled) 1254325151a3SRui Paulo fprintf(f, "p2p_disabled=%d\n", config->p2p_disabled); 1255f05cddf9SRui Paulo if (config->p2p_no_group_iface) 1256325151a3SRui Paulo fprintf(f, "p2p_no_group_iface=%d\n", 1257f05cddf9SRui Paulo config->p2p_no_group_iface); 12585b9c547cSRui Paulo if (config->p2p_ignore_shared_freq) 1259325151a3SRui Paulo fprintf(f, "p2p_ignore_shared_freq=%d\n", 12605b9c547cSRui Paulo config->p2p_ignore_shared_freq); 1261325151a3SRui Paulo if (config->p2p_cli_probe) 1262325151a3SRui Paulo fprintf(f, "p2p_cli_probe=%d\n", config->p2p_cli_probe); 1263325151a3SRui Paulo if (config->p2p_go_freq_change_policy != DEFAULT_P2P_GO_FREQ_MOVE) 1264325151a3SRui Paulo fprintf(f, "p2p_go_freq_change_policy=%u\n", 1265325151a3SRui Paulo config->p2p_go_freq_change_policy); 1266780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_go)) 1267780fb4a2SCy Schubert fprintf(f, "ip_addr_go=%u.%u.%u.%u\n", 1268780fb4a2SCy Schubert config->ip_addr_go[0], config->ip_addr_go[1], 1269780fb4a2SCy Schubert config->ip_addr_go[2], config->ip_addr_go[3]); 1270780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_mask)) 1271780fb4a2SCy Schubert fprintf(f, "ip_addr_mask=%u.%u.%u.%u\n", 1272780fb4a2SCy Schubert config->ip_addr_mask[0], config->ip_addr_mask[1], 1273780fb4a2SCy Schubert config->ip_addr_mask[2], config->ip_addr_mask[3]); 1274780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_start)) 1275780fb4a2SCy Schubert fprintf(f, "ip_addr_start=%u.%u.%u.%u\n", 1276780fb4a2SCy Schubert config->ip_addr_start[0], config->ip_addr_start[1], 1277780fb4a2SCy Schubert config->ip_addr_start[2], config->ip_addr_start[3]); 1278780fb4a2SCy Schubert if (WPA_GET_BE32(config->ip_addr_end)) 1279780fb4a2SCy Schubert fprintf(f, "ip_addr_end=%u.%u.%u.%u\n", 1280780fb4a2SCy Schubert config->ip_addr_end[0], config->ip_addr_end[1], 1281780fb4a2SCy Schubert config->ip_addr_end[2], config->ip_addr_end[3]); 1282f05cddf9SRui Paulo #endif /* CONFIG_P2P */ 128339beb93cSSam Leffler if (config->country[0] && config->country[1]) { 128439beb93cSSam Leffler fprintf(f, "country=%c%c\n", 128539beb93cSSam Leffler config->country[0], config->country[1]); 128639beb93cSSam Leffler } 1287e28a4053SRui Paulo if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT) 1288e28a4053SRui Paulo fprintf(f, "bss_max_count=%u\n", config->bss_max_count); 1289f05cddf9SRui Paulo if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE) 1290f05cddf9SRui Paulo fprintf(f, "bss_expiration_age=%u\n", 1291f05cddf9SRui Paulo config->bss_expiration_age); 1292f05cddf9SRui Paulo if (config->bss_expiration_scan_count != 1293f05cddf9SRui Paulo DEFAULT_BSS_EXPIRATION_SCAN_COUNT) 1294f05cddf9SRui Paulo fprintf(f, "bss_expiration_scan_count=%u\n", 1295f05cddf9SRui Paulo config->bss_expiration_scan_count); 1296e28a4053SRui Paulo if (config->filter_ssids) 1297e28a4053SRui Paulo fprintf(f, "filter_ssids=%d\n", config->filter_ssids); 1298*85732ac8SCy Schubert if (config->filter_rssi) 1299*85732ac8SCy Schubert fprintf(f, "filter_rssi=%d\n", config->filter_rssi); 1300f05cddf9SRui Paulo if (config->max_num_sta != DEFAULT_MAX_NUM_STA) 1301f05cddf9SRui Paulo fprintf(f, "max_num_sta=%u\n", config->max_num_sta); 1302*85732ac8SCy Schubert if (config->ap_isolate != DEFAULT_AP_ISOLATE) 1303*85732ac8SCy Schubert fprintf(f, "ap_isolate=%u\n", config->ap_isolate); 1304f05cddf9SRui Paulo if (config->disassoc_low_ack) 1305325151a3SRui Paulo fprintf(f, "disassoc_low_ack=%d\n", config->disassoc_low_ack); 1306f05cddf9SRui Paulo #ifdef CONFIG_HS20 1307f05cddf9SRui Paulo if (config->hs20) 1308f05cddf9SRui Paulo fprintf(f, "hs20=1\n"); 1309f05cddf9SRui Paulo #endif /* CONFIG_HS20 */ 1310f05cddf9SRui Paulo #ifdef CONFIG_INTERWORKING 1311f05cddf9SRui Paulo if (config->interworking) 1312325151a3SRui Paulo fprintf(f, "interworking=%d\n", config->interworking); 1313f05cddf9SRui Paulo if (!is_zero_ether_addr(config->hessid)) 1314f05cddf9SRui Paulo fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid)); 1315f05cddf9SRui Paulo if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE) 1316f05cddf9SRui Paulo fprintf(f, "access_network_type=%d\n", 1317f05cddf9SRui Paulo config->access_network_type); 1318*85732ac8SCy Schubert if (config->go_interworking) 1319*85732ac8SCy Schubert fprintf(f, "go_interworking=%d\n", config->go_interworking); 1320*85732ac8SCy Schubert if (config->go_access_network_type) 1321*85732ac8SCy Schubert fprintf(f, "go_access_network_type=%d\n", 1322*85732ac8SCy Schubert config->go_access_network_type); 1323*85732ac8SCy Schubert if (config->go_internet) 1324*85732ac8SCy Schubert fprintf(f, "go_internet=%d\n", config->go_internet); 1325*85732ac8SCy Schubert if (config->go_venue_group) 1326*85732ac8SCy Schubert fprintf(f, "go_venue_group=%d\n", config->go_venue_group); 1327*85732ac8SCy Schubert if (config->go_venue_type) 1328*85732ac8SCy Schubert fprintf(f, "go_venue_type=%d\n", config->go_venue_type); 1329f05cddf9SRui Paulo #endif /* CONFIG_INTERWORKING */ 1330f05cddf9SRui Paulo if (config->pbc_in_m1) 1331325151a3SRui Paulo fprintf(f, "pbc_in_m1=%d\n", config->pbc_in_m1); 13325b9c547cSRui Paulo if (config->wps_nfc_pw_from_config) { 1333f05cddf9SRui Paulo if (config->wps_nfc_dev_pw_id) 1334f05cddf9SRui Paulo fprintf(f, "wps_nfc_dev_pw_id=%d\n", 1335f05cddf9SRui Paulo config->wps_nfc_dev_pw_id); 13365b9c547cSRui Paulo write_global_bin(f, "wps_nfc_dh_pubkey", 13375b9c547cSRui Paulo config->wps_nfc_dh_pubkey); 13385b9c547cSRui Paulo write_global_bin(f, "wps_nfc_dh_privkey", 13395b9c547cSRui Paulo config->wps_nfc_dh_privkey); 1340f05cddf9SRui Paulo write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw); 13415b9c547cSRui Paulo } 1342f05cddf9SRui Paulo 1343f05cddf9SRui Paulo if (config->ext_password_backend) 1344f05cddf9SRui Paulo fprintf(f, "ext_password_backend=%s\n", 1345f05cddf9SRui Paulo config->ext_password_backend); 1346f05cddf9SRui Paulo if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY) 1347f05cddf9SRui Paulo fprintf(f, "p2p_go_max_inactivity=%d\n", 1348f05cddf9SRui Paulo config->p2p_go_max_inactivity); 1349f05cddf9SRui Paulo if (config->auto_interworking) 1350f05cddf9SRui Paulo fprintf(f, "auto_interworking=%d\n", 1351f05cddf9SRui Paulo config->auto_interworking); 1352f05cddf9SRui Paulo if (config->okc) 1353f05cddf9SRui Paulo fprintf(f, "okc=%d\n", config->okc); 1354f05cddf9SRui Paulo if (config->pmf) 1355f05cddf9SRui Paulo fprintf(f, "pmf=%d\n", config->pmf); 13565b9c547cSRui Paulo if (config->dtim_period) 13575b9c547cSRui Paulo fprintf(f, "dtim_period=%d\n", config->dtim_period); 13585b9c547cSRui Paulo if (config->beacon_int) 13595b9c547cSRui Paulo fprintf(f, "beacon_int=%d\n", config->beacon_int); 13605b9c547cSRui Paulo 13615b9c547cSRui Paulo if (config->sae_groups) { 13625b9c547cSRui Paulo int i; 13635b9c547cSRui Paulo fprintf(f, "sae_groups="); 1364*85732ac8SCy Schubert for (i = 0; config->sae_groups[i] > 0; i++) { 13655b9c547cSRui Paulo fprintf(f, "%s%d", i > 0 ? " " : "", 13665b9c547cSRui Paulo config->sae_groups[i]); 13675b9c547cSRui Paulo } 13685b9c547cSRui Paulo fprintf(f, "\n"); 13695b9c547cSRui Paulo } 13705b9c547cSRui Paulo 13715b9c547cSRui Paulo if (config->ap_vendor_elements) { 13725b9c547cSRui Paulo int i, len = wpabuf_len(config->ap_vendor_elements); 13735b9c547cSRui Paulo const u8 *p = wpabuf_head_u8(config->ap_vendor_elements); 13745b9c547cSRui Paulo if (len > 0) { 13755b9c547cSRui Paulo fprintf(f, "ap_vendor_elements="); 13765b9c547cSRui Paulo for (i = 0; i < len; i++) 13775b9c547cSRui Paulo fprintf(f, "%02x", *p++); 13785b9c547cSRui Paulo fprintf(f, "\n"); 13795b9c547cSRui Paulo } 13805b9c547cSRui Paulo } 13815b9c547cSRui Paulo 13825b9c547cSRui Paulo if (config->ignore_old_scan_res) 13835b9c547cSRui Paulo fprintf(f, "ignore_old_scan_res=%d\n", 13845b9c547cSRui Paulo config->ignore_old_scan_res); 13855b9c547cSRui Paulo 13865b9c547cSRui Paulo if (config->freq_list && config->freq_list[0]) { 13875b9c547cSRui Paulo int i; 13885b9c547cSRui Paulo fprintf(f, "freq_list="); 13895b9c547cSRui Paulo for (i = 0; config->freq_list[i]; i++) { 1390325151a3SRui Paulo fprintf(f, "%s%d", i > 0 ? " " : "", 13915b9c547cSRui Paulo config->freq_list[i]); 13925b9c547cSRui Paulo } 13935b9c547cSRui Paulo fprintf(f, "\n"); 13945b9c547cSRui Paulo } 13955b9c547cSRui Paulo if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ) 13965b9c547cSRui Paulo fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq); 13975b9c547cSRui Paulo 13985b9c547cSRui Paulo if (config->sched_scan_interval) 13995b9c547cSRui Paulo fprintf(f, "sched_scan_interval=%u\n", 14005b9c547cSRui Paulo config->sched_scan_interval); 14015b9c547cSRui Paulo 1402*85732ac8SCy Schubert if (config->sched_scan_start_delay) 1403*85732ac8SCy Schubert fprintf(f, "sched_scan_start_delay=%u\n", 1404*85732ac8SCy Schubert config->sched_scan_start_delay); 1405*85732ac8SCy Schubert 14065b9c547cSRui Paulo if (config->external_sim) 14075b9c547cSRui Paulo fprintf(f, "external_sim=%d\n", config->external_sim); 14085b9c547cSRui Paulo 14095b9c547cSRui Paulo if (config->tdls_external_control) 14105b9c547cSRui Paulo fprintf(f, "tdls_external_control=%d\n", 14115b9c547cSRui Paulo config->tdls_external_control); 14125b9c547cSRui Paulo 14135b9c547cSRui Paulo if (config->wowlan_triggers) 14145b9c547cSRui Paulo fprintf(f, "wowlan_triggers=%s\n", 14155b9c547cSRui Paulo config->wowlan_triggers); 14165b9c547cSRui Paulo 14175b9c547cSRui Paulo if (config->bgscan) 14185b9c547cSRui Paulo fprintf(f, "bgscan=\"%s\"\n", config->bgscan); 14195b9c547cSRui Paulo 1420*85732ac8SCy Schubert if (config->autoscan) 1421*85732ac8SCy Schubert fprintf(f, "autoscan=%s\n", config->autoscan); 1422*85732ac8SCy Schubert 14235b9c547cSRui Paulo if (config->p2p_search_delay != DEFAULT_P2P_SEARCH_DELAY) 14245b9c547cSRui Paulo fprintf(f, "p2p_search_delay=%u\n", 14255b9c547cSRui Paulo config->p2p_search_delay); 14265b9c547cSRui Paulo 14275b9c547cSRui Paulo if (config->mac_addr) 14285b9c547cSRui Paulo fprintf(f, "mac_addr=%d\n", config->mac_addr); 14295b9c547cSRui Paulo 14305b9c547cSRui Paulo if (config->rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME) 14315b9c547cSRui Paulo fprintf(f, "rand_addr_lifetime=%u\n", 14325b9c547cSRui Paulo config->rand_addr_lifetime); 14335b9c547cSRui Paulo 14345b9c547cSRui Paulo if (config->preassoc_mac_addr) 14355b9c547cSRui Paulo fprintf(f, "preassoc_mac_addr=%d\n", config->preassoc_mac_addr); 14365b9c547cSRui Paulo 14375b9c547cSRui Paulo if (config->key_mgmt_offload != DEFAULT_KEY_MGMT_OFFLOAD) 1438325151a3SRui Paulo fprintf(f, "key_mgmt_offload=%d\n", config->key_mgmt_offload); 14395b9c547cSRui Paulo 14405b9c547cSRui Paulo if (config->user_mpm != DEFAULT_USER_MPM) 14415b9c547cSRui Paulo fprintf(f, "user_mpm=%d\n", config->user_mpm); 14425b9c547cSRui Paulo 14435b9c547cSRui Paulo if (config->max_peer_links != DEFAULT_MAX_PEER_LINKS) 14445b9c547cSRui Paulo fprintf(f, "max_peer_links=%d\n", config->max_peer_links); 14455b9c547cSRui Paulo 14465b9c547cSRui Paulo if (config->cert_in_cb != DEFAULT_CERT_IN_CB) 14475b9c547cSRui Paulo fprintf(f, "cert_in_cb=%d\n", config->cert_in_cb); 14485b9c547cSRui Paulo 14495b9c547cSRui Paulo if (config->mesh_max_inactivity != DEFAULT_MESH_MAX_INACTIVITY) 14505b9c547cSRui Paulo fprintf(f, "mesh_max_inactivity=%d\n", 14515b9c547cSRui Paulo config->mesh_max_inactivity); 14525b9c547cSRui Paulo 1453325151a3SRui Paulo if (config->dot11RSNASAERetransPeriod != 1454325151a3SRui Paulo DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD) 1455325151a3SRui Paulo fprintf(f, "dot11RSNASAERetransPeriod=%d\n", 1456325151a3SRui Paulo config->dot11RSNASAERetransPeriod); 1457325151a3SRui Paulo 14585b9c547cSRui Paulo if (config->passive_scan) 14595b9c547cSRui Paulo fprintf(f, "passive_scan=%d\n", config->passive_scan); 14605b9c547cSRui Paulo 14615b9c547cSRui Paulo if (config->reassoc_same_bss_optim) 14625b9c547cSRui Paulo fprintf(f, "reassoc_same_bss_optim=%d\n", 14635b9c547cSRui Paulo config->reassoc_same_bss_optim); 1464325151a3SRui Paulo 1465325151a3SRui Paulo if (config->wps_priority) 1466325151a3SRui Paulo fprintf(f, "wps_priority=%d\n", config->wps_priority); 1467780fb4a2SCy Schubert 1468780fb4a2SCy Schubert if (config->wpa_rsc_relaxation != DEFAULT_WPA_RSC_RELAXATION) 1469780fb4a2SCy Schubert fprintf(f, "wpa_rsc_relaxation=%d\n", 1470780fb4a2SCy Schubert config->wpa_rsc_relaxation); 1471780fb4a2SCy Schubert 1472780fb4a2SCy Schubert if (config->sched_scan_plans) 1473780fb4a2SCy Schubert fprintf(f, "sched_scan_plans=%s\n", config->sched_scan_plans); 1474780fb4a2SCy Schubert 1475780fb4a2SCy Schubert #ifdef CONFIG_MBO 1476780fb4a2SCy Schubert if (config->non_pref_chan) 1477780fb4a2SCy Schubert fprintf(f, "non_pref_chan=%s\n", config->non_pref_chan); 1478780fb4a2SCy Schubert if (config->mbo_cell_capa != DEFAULT_MBO_CELL_CAPA) 1479780fb4a2SCy Schubert fprintf(f, "mbo_cell_capa=%u\n", config->mbo_cell_capa); 1480*85732ac8SCy Schubert if (config->disassoc_imminent_rssi_threshold != 1481*85732ac8SCy Schubert DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD) 1482*85732ac8SCy Schubert fprintf(f, "disassoc_imminent_rssi_threshold=%d\n", 1483*85732ac8SCy Schubert config->disassoc_imminent_rssi_threshold); 1484*85732ac8SCy Schubert if (config->oce != DEFAULT_OCE_SUPPORT) 1485*85732ac8SCy Schubert fprintf(f, "oce=%u\n", config->oce); 1486780fb4a2SCy Schubert #endif /* CONFIG_MBO */ 1487780fb4a2SCy Schubert 1488780fb4a2SCy Schubert if (config->gas_address3) 1489780fb4a2SCy Schubert fprintf(f, "gas_address3=%d\n", config->gas_address3); 1490780fb4a2SCy Schubert 1491780fb4a2SCy Schubert if (config->ftm_responder) 1492780fb4a2SCy Schubert fprintf(f, "ftm_responder=%d\n", config->ftm_responder); 1493780fb4a2SCy Schubert if (config->ftm_initiator) 1494780fb4a2SCy Schubert fprintf(f, "ftm_initiator=%d\n", config->ftm_initiator); 1495*85732ac8SCy Schubert 1496*85732ac8SCy Schubert if (config->osu_dir) 1497*85732ac8SCy Schubert fprintf(f, "osu_dir=%s\n", config->osu_dir); 1498*85732ac8SCy Schubert 1499*85732ac8SCy Schubert if (config->fst_group_id) 1500*85732ac8SCy Schubert fprintf(f, "fst_group_id=%s\n", config->fst_group_id); 1501*85732ac8SCy Schubert if (config->fst_priority) 1502*85732ac8SCy Schubert fprintf(f, "fst_priority=%d\n", config->fst_priority); 1503*85732ac8SCy Schubert if (config->fst_llt) 1504*85732ac8SCy Schubert fprintf(f, "fst_llt=%d\n", config->fst_llt); 1505*85732ac8SCy Schubert 1506*85732ac8SCy Schubert if (config->gas_rand_addr_lifetime != DEFAULT_RAND_ADDR_LIFETIME) 1507*85732ac8SCy Schubert fprintf(f, "gas_rand_addr_lifetime=%u\n", 1508*85732ac8SCy Schubert config->gas_rand_addr_lifetime); 1509*85732ac8SCy Schubert if (config->gas_rand_mac_addr) 1510*85732ac8SCy Schubert fprintf(f, "gas_rand_mac_addr=%d\n", config->gas_rand_mac_addr); 1511*85732ac8SCy Schubert if (config->dpp_config_processing) 1512*85732ac8SCy Schubert fprintf(f, "dpp_config_processing=%d\n", 1513*85732ac8SCy Schubert config->dpp_config_processing); 1514*85732ac8SCy Schubert if (config->coloc_intf_reporting) 1515*85732ac8SCy Schubert fprintf(f, "coloc_intf_reporting=%d\n", 1516*85732ac8SCy Schubert config->coloc_intf_reporting); 151739beb93cSSam Leffler } 151839beb93cSSam Leffler 151939beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */ 152039beb93cSSam Leffler 152139beb93cSSam Leffler 152239beb93cSSam Leffler int wpa_config_write(const char *name, struct wpa_config *config) 152339beb93cSSam Leffler { 152439beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_WRITE 152539beb93cSSam Leffler FILE *f; 152639beb93cSSam Leffler struct wpa_ssid *ssid; 1527f05cddf9SRui Paulo struct wpa_cred *cred; 152839beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 152939beb93cSSam Leffler struct wpa_config_blob *blob; 153039beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 153139beb93cSSam Leffler int ret = 0; 15325b9c547cSRui Paulo const char *orig_name = name; 15335b9c547cSRui Paulo int tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */ 15345b9c547cSRui Paulo char *tmp_name = os_malloc(tmp_len); 15355b9c547cSRui Paulo 15365b9c547cSRui Paulo if (tmp_name) { 15375b9c547cSRui Paulo os_snprintf(tmp_name, tmp_len, "%s.tmp", name); 15385b9c547cSRui Paulo name = tmp_name; 15395b9c547cSRui Paulo } 154039beb93cSSam Leffler 154139beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name); 154239beb93cSSam Leffler 154339beb93cSSam Leffler f = fopen(name, "w"); 154439beb93cSSam Leffler if (f == NULL) { 154539beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name); 15465b9c547cSRui Paulo os_free(tmp_name); 154739beb93cSSam Leffler return -1; 154839beb93cSSam Leffler } 154939beb93cSSam Leffler 155039beb93cSSam Leffler wpa_config_write_global(f, config); 155139beb93cSSam Leffler 1552f05cddf9SRui Paulo for (cred = config->cred; cred; cred = cred->next) { 15535b9c547cSRui Paulo if (cred->temporary) 15545b9c547cSRui Paulo continue; 1555f05cddf9SRui Paulo fprintf(f, "\ncred={\n"); 1556f05cddf9SRui Paulo wpa_config_write_cred(f, cred); 1557f05cddf9SRui Paulo fprintf(f, "}\n"); 1558f05cddf9SRui Paulo } 1559f05cddf9SRui Paulo 156039beb93cSSam Leffler for (ssid = config->ssid; ssid; ssid = ssid->next) { 1561f05cddf9SRui Paulo if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary) 1562f05cddf9SRui Paulo continue; /* do not save temporary networks */ 1563f05cddf9SRui Paulo if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set && 1564f05cddf9SRui Paulo !ssid->passphrase) 1565f05cddf9SRui Paulo continue; /* do not save invalid network */ 156639beb93cSSam Leffler fprintf(f, "\nnetwork={\n"); 156739beb93cSSam Leffler wpa_config_write_network(f, ssid); 156839beb93cSSam Leffler fprintf(f, "}\n"); 156939beb93cSSam Leffler } 157039beb93cSSam Leffler 157139beb93cSSam Leffler #ifndef CONFIG_NO_CONFIG_BLOBS 157239beb93cSSam Leffler for (blob = config->blobs; blob; blob = blob->next) { 157339beb93cSSam Leffler ret = wpa_config_write_blob(f, blob); 157439beb93cSSam Leffler if (ret) 157539beb93cSSam Leffler break; 157639beb93cSSam Leffler } 157739beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_BLOBS */ 157839beb93cSSam Leffler 1579325151a3SRui Paulo os_fdatasync(f); 1580325151a3SRui Paulo 158139beb93cSSam Leffler fclose(f); 158239beb93cSSam Leffler 15835b9c547cSRui Paulo if (tmp_name) { 15845b9c547cSRui Paulo int chmod_ret = 0; 15855b9c547cSRui Paulo 15865b9c547cSRui Paulo #ifdef ANDROID 15875b9c547cSRui Paulo chmod_ret = chmod(tmp_name, 15885b9c547cSRui Paulo S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 15895b9c547cSRui Paulo #endif /* ANDROID */ 15905b9c547cSRui Paulo if (chmod_ret != 0 || rename(tmp_name, orig_name) != 0) 15915b9c547cSRui Paulo ret = -1; 15925b9c547cSRui Paulo 15935b9c547cSRui Paulo os_free(tmp_name); 15945b9c547cSRui Paulo } 15955b9c547cSRui Paulo 159639beb93cSSam Leffler wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully", 15975b9c547cSRui Paulo orig_name, ret ? "un" : ""); 159839beb93cSSam Leffler return ret; 159939beb93cSSam Leffler #else /* CONFIG_NO_CONFIG_WRITE */ 160039beb93cSSam Leffler return -1; 160139beb93cSSam Leffler #endif /* CONFIG_NO_CONFIG_WRITE */ 160239beb93cSSam Leffler } 1603