public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 04/16] dpp-util: refactor dpp_configuration_to_json for only PSK networks
Date: Tue, 24 Sep 2024 05:04:35 -0700	[thread overview]
Message-ID: <20240924120447.251761-4-prestwoj@gmail.com> (raw)
In-Reply-To: <20240924120447.251761-1-prestwoj@gmail.com>

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 --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,
-- 
2.34.1


  parent reply	other threads:[~2024-09-24 12:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 12:04 [PATCH 01/16] ie: add IE_AKM_IS_PSK James Prestwood
2024-09-24 12:04 ` [PATCH 02/16] dpp-util: refactor dpp_configuration_new into a _psk helper James Prestwood
2024-09-24 12:04 ` [PATCH 03/16] dpp: fix some return/cleanup issues for error cases James Prestwood
2024-09-24 12:04 ` James Prestwood [this message]
2024-09-24 12:04 ` [PATCH 05/16] dpp: refactor dpp_send_config_response to take JSON as a parameter James Prestwood
2024-09-24 12:04 ` [PATCH 06/16] dpp: refactor dpp_configuration_start to take the " James Prestwood
2024-09-24 12:04 ` [PATCH 07/16] dpp: refactor config writing, add checks for PSK James Prestwood
2024-09-24 12:04 ` [PATCH 08/16] dpp-util: check the AKM is "psk" before further parsing the object James Prestwood
2024-09-24 12:04 ` [PATCH 09/16] dbus: add generic DPP agent interface James Prestwood
2024-09-24 12:04 ` [PATCH 10/16] dpp: replace PKEX agent with generic DPP agent James Prestwood
2024-09-24 12:04 ` [PATCH 11/16] agent: add APIs for DeviceProvisioningAgent James Prestwood
2024-09-24 12:04 ` [PATCH 12/16] dpp: replace SharedCodeAgent with DeviceProvisioningAgent James Prestwood
2024-09-24 12:04 ` [PATCH 13/16] dpp: remove agent path from StartConfigurator James Prestwood
2024-09-24 12:04 ` [PATCH 14/16] auto-t: update utils to use DeviceProvisioningAgent James Prestwood
2024-09-24 12:04 ` [PATCH 15/16] auto-t: update PKEX test " James Prestwood
2024-09-24 12:04 ` [PATCH 16/16] doc: Document new DeviceProvisioningAgent James Prestwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240924120447.251761-4-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox