diff mbox series

[04/16] dpp-util: refactor dpp_configuration_to_json for only PSK networks

Message ID 20240924120447.251761-4-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [01/16] ie: add IE_AKM_IS_PSK | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Sept. 24, 2024, 12:04 p.m. UTC
This renames dpp_configuration_to_json to dpp_psk_config_to_json to
prepare for adding 802.1x provisioning. The 802.1x variant will need
to take additional arguments, so we'll need to isolate the PSK
logic into its own API.
---
 src/dpp-util.c | 27 +++++++++++++++++----------
 src/dpp-util.h |  2 +-
 src/dpp.c      |  2 +-
 3 files changed, 19 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/src/dpp-util.c b/src/dpp-util.c
index 2eacc587..62db2081 100644
--- a/src/dpp-util.c
+++ b/src/dpp-util.c
@@ -282,22 +282,15 @@  static const char *dpp_akm_to_string(enum ie_rsn_akm_suite akm_suite)
 	}
 }
 
-char *dpp_configuration_to_json(struct dpp_configuration *config)
+static char *dpp_configuration_to_json(struct dpp_configuration *config,
+					const char *creds)
 {
-	_auto_(l_free) char *pass_or_psk;
 	_auto_(l_free) char *ssid;
 
 	ssid = l_malloc(config->ssid_len + 1);
 	memcpy(ssid, config->ssid, config->ssid_len);
 	ssid[config->ssid_len] = '\0';
 
-	if (config->passphrase)
-		pass_or_psk = l_strdup_printf("\"pass\":\"%s\"",
-						config->passphrase);
-	else
-		pass_or_psk = l_strdup_printf("\"psk\":\"%s\"",
-						config->psk);
-
 	return l_strdup_printf("{\"wi-fi_tech\":\"infra\","
 				"\"discovery\":{"
 					"\"ssid\":\"%s\""
@@ -310,11 +303,25 @@  char *dpp_configuration_to_json(struct dpp_configuration *config)
 					"\"hidden\":%s}"
 				"}",
 				ssid, dpp_akm_to_string(config->akm_suites),
-				pass_or_psk,
+				creds,
 				config->send_hostname ? "true" : "false",
 				config->hidden ? "true" : "false");
 }
 
+char *dpp_psk_config_to_json(struct dpp_configuration *config)
+{
+	_auto_(l_free) char *pass_or_psk;
+
+	if (config->passphrase)
+		pass_or_psk = l_strdup_printf("\"pass\":\"%s\"",
+						config->passphrase);
+	else
+		pass_or_psk = l_strdup_printf("\"psk\":\"%s\"",
+						config->psk);
+
+	return dpp_configuration_to_json(config, pass_or_psk);
+}
+
 static struct dpp_configuration *dpp_configuration_new_psk(
 					const struct l_settings *settings)
 {
diff --git a/src/dpp-util.h b/src/dpp-util.h
index 86ef36f9..f7d7122c 100644
--- a/src/dpp-util.h
+++ b/src/dpp-util.h
@@ -132,7 +132,7 @@  struct dpp_configuration *dpp_configuration_new(
 					const struct l_settings *settings,
 					const char *ssid,
 					enum ie_rsn_akm_suite akm_suite);
-char *dpp_configuration_to_json(struct dpp_configuration *config);
+char *dpp_psk_config_to_json(struct dpp_configuration *config);
 void dpp_configuration_free(struct dpp_configuration *conf);
 
 struct dpp_attr_iter {
diff --git a/src/dpp.c b/src/dpp.c
index 32160d96..41e56197 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -1212,7 +1212,7 @@  static void dpp_send_config_response(struct dpp_sm *dpp, uint8_t status)
 	 * STATUS_CONFIGURE_FAILURE which only includes the E-Nonce.
 	 */
 	if (status == DPP_STATUS_OK) {
-		json = dpp_configuration_to_json(dpp->config);
+		json = dpp_psk_config_to_json(dpp->config);
 		json_len = strlen(json);
 
 		ptr += dpp_append_wrapped_data(attrs + 2, ptr - attrs - 2,