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 v3 7/9] dpp: SharedCode interface, {Register,Unregister}SharedCodeAgent
Date: Tue, 31 Oct 2023 11:47:48 -0700	[thread overview]
Message-ID: <20231031184750.722404-8-prestwoj@gmail.com> (raw)
In-Reply-To: <20231031184750.722404-1-prestwoj@gmail.com>

This adds the SharedCodeDeviceProvisioning interface as well as
the two agent methods. After the PKEX configurator role is added
it will need this to request a shared code from a registered agent.
---
 src/dpp.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/src/dpp.c b/src/dpp.c
index b0a79361..57024a26 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -79,6 +79,13 @@ enum dpp_capability {
 	DPP_CAPABILITY_CONFIGURATOR = 0x02,
 };
 
+struct pkex_agent {
+	char *owner;
+	char *path;
+	unsigned int disconnect_watch;
+	uint32_t pending_id;
+};
+
 struct dpp_sm {
 	struct netdev *netdev;
 	char *uri;
@@ -101,6 +108,8 @@ struct dpp_sm {
 
 	enum dpp_state state;
 
+	struct pkex_agent *agent;
+
 	/*
 	 * List of frequencies to jump between. The presence of this list is
 	 * also used to signify that a configurator is an initiator vs responder
@@ -335,6 +344,16 @@ static void dpp_reset(struct dpp_sm *dpp)
 	dpp_property_changed_notify(dpp);
 }
 
+static void pkex_agent_free(void *data)
+{
+	struct pkex_agent *agent = data;
+
+	l_free(agent->owner);
+	l_free(agent->path);
+	l_dbus_remove_watch(dbus_get_bus(), agent->disconnect_watch);
+	l_free(agent);
+}
+
 static void dpp_free(struct dpp_sm *dpp)
 {
 	dpp_reset(dpp);
@@ -354,6 +373,11 @@ static void dpp_free(struct dpp_sm *dpp)
 		dpp->boot_private = NULL;
 	}
 
+	if (dpp->agent) {
+		pkex_agent_free(dpp->agent);
+		dpp->agent = NULL;
+	}
+
 	l_free(dpp);
 }
 
@@ -2753,6 +2777,79 @@ static void dpp_setup_interface(struct l_dbus_interface *interface)
 	l_dbus_interface_property(interface, "URI", 0, "s", dpp_get_uri, NULL);
 }
 
+static void pkex_agent_disconnect(struct l_dbus *dbus, void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+
+	l_debug("SharedCodeAgent %s disconnected", dpp->agent->path);
+
+	if (dpp->agent->pending_id)
+		l_dbus_cancel(dbus_get_bus(), dpp->agent->pending_id);
+
+	pkex_agent_free(dpp->agent);
+	dpp->agent = NULL;
+}
+
+static struct l_dbus_message *dpp_dbus_pkex_register_agent(
+						struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+	const char *sender = l_dbus_message_get_sender(message);
+	const char *path;
+
+	if (dpp->agent)
+		return dbus_error_already_exists(message);
+
+	if (!l_dbus_message_get_arguments(message, "o", &path))
+		return dbus_error_invalid_args(message);
+
+	dpp->agent = l_new(struct pkex_agent, 1);
+	dpp->agent->owner = l_strdup(sender);
+	dpp->agent->path = l_strdup(path);
+	dpp->agent->disconnect_watch = l_dbus_add_disconnect_watch(dbus, sender,
+							pkex_agent_disconnect,
+							dpp, NULL);
+
+	l_debug("%s registered a SharedCodeAgent on path %s", sender, path);
+
+	return l_dbus_message_new_method_return(message);
+}
+
+static struct l_dbus_message *dpp_dbus_pkex_unregister_agent(
+						struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+
+	if (!dpp->agent)
+		return dbus_error_not_found(message);
+
+	if (strcmp(dpp->agent->owner, l_dbus_message_get_sender(message)))
+		return dbus_error_not_found(message);
+
+	l_debug("%s unregistered SharedCodeAgent on path %s", dpp->agent->owner,
+			dpp->agent->path);
+
+	if (dpp->agent->pending_id)
+		l_dbus_cancel(dbus_get_bus(), dpp->agent->pending_id);
+
+	pkex_agent_free(dpp->agent);
+	dpp->agent = NULL;
+
+	return l_dbus_message_new_method_return(message);
+}
+
+static void dpp_setup_pkex_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_method(interface, "RegisterSharedCodeAgent", 0,
+			dpp_dbus_pkex_register_agent, "", "o", "path");
+	l_dbus_interface_method(interface, "UnregisterSharedCodeAgent", 0,
+			dpp_dbus_pkex_unregister_agent, "", "");
+}
+
 static void dpp_destroy_interface(void *user_data)
 {
 	struct dpp_sm *dpp = user_data;
@@ -2775,6 +2872,9 @@ static int dpp_init(void)
 	l_dbus_register_interface(dbus_get_bus(), IWD_DPP_INTERFACE,
 					dpp_setup_interface,
 					dpp_destroy_interface, false);
+	l_dbus_register_interface(dbus_get_bus(), IWD_DPP_PKEX_INTERFACE,
+					dpp_setup_pkex_interface,
+					NULL, false);
 
 	mlme_watch = l_genl_family_register(nl80211, "mlme", dpp_mlme_notify,
 						NULL, NULL);
-- 
2.25.1


  parent reply	other threads:[~2023-10-31 18:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 18:47 [PATCH v3 0/9] DPP PKEX Changes James Prestwood
2023-10-31 18:47 ` [PATCH v3 1/9] dpp: remove scan_periodic_stop calls James Prestwood
2023-11-03  1:40   ` Denis Kenzior
2023-10-31 18:47 ` [PATCH v3 2/9] dpp: fix config request header check James Prestwood
2023-10-31 18:47 ` [PATCH v3 3/9] dpp: allow enrollee to be authentication initiator James Prestwood
2023-10-31 18:47 ` [PATCH v3 4/9] dbus: add net.connman.iwd.SharedCodeAgent DBus interface James Prestwood
2023-10-31 18:47 ` [PATCH v3 5/9] station: provide new state in __station_connect_network James Prestwood
2023-10-31 18:47 ` [PATCH v3 6/9] doc: PKEX support for DPP James Prestwood
2023-11-03  2:07   ` Denis Kenzior
2023-11-03 11:24     ` James Prestwood
2023-10-31 18:47 ` James Prestwood [this message]
2023-11-03  2:09   ` [PATCH v3 7/9] dpp: SharedCode interface, {Register,Unregister}SharedCodeAgent Denis Kenzior
2023-10-31 18:47 ` [PATCH v3 8/9] dpp: initial version of PKEX enrollee support James Prestwood
2023-11-03  2:12   ` Denis Kenzior
2023-11-03 11:27     ` James Prestwood
2023-10-31 18:47 ` [PATCH v3 9/9] dpp: initial version of PKEX configurator support 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=20231031184750.722404-8-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