public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2 02/10] dpp: initial skeleton DPP module
@ 2021-12-14 18:12 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-12-14 18:12 UTC (permalink / raw)
  To: iwd 

[-- Attachment #1: Type: text/plain, Size: 4056 bytes --]

---
 Makefile.am |   1 +
 src/dpp.c   | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+)
 create mode 100644 src/dpp.c

v2:
 * Only create dpp_sm if device is station

diff --git a/Makefile.am b/Makefile.am
index 312081a0..5d14963b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -250,6 +250,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
 					src/offchannel.h src/offchannel.c \
 					src/dpp-util.h src/dpp-util.c \
 					src/json.h src/json.c \
+					src/dpp.c \
 					$(eap_sources) \
 					$(builtin_sources)
 
diff --git a/src/dpp.c b/src/dpp.c
new file mode 100644
index 00000000..d727e639
--- /dev/null
+++ b/src/dpp.c
@@ -0,0 +1,128 @@
+/*
+ *
+ *  Wireless daemon for Linux
+ *
+ *  Copyright (C) 2021  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ell/ell.h>
+
+#include "src/dbus.h"
+#include "src/netdev.h"
+#include "src/module.h"
+
+static uint32_t netdev_watch;
+
+struct dpp_sm {
+	struct netdev *netdev;
+};
+
+static void dpp_create(struct netdev *netdev)
+{
+	struct l_dbus *dbus = dbus_get_bus();
+	struct dpp_sm *dpp = l_new(struct dpp_sm, 1);
+
+	dpp->netdev = netdev;
+
+	l_dbus_object_add_interface(dbus, netdev_get_path(netdev),
+					IWD_DPP_INTERFACE, dpp);
+}
+
+static void dpp_free(struct dpp_sm *dpp)
+{
+	l_free(dpp);
+}
+
+static void dpp_netdev_watch(struct netdev *netdev,
+				enum netdev_watch_event event, void *userdata)
+{
+	if (netdev_get_iftype(netdev) != NETDEV_IFTYPE_STATION)
+		return;
+
+	switch (event) {
+	case NETDEV_WATCH_EVENT_NEW:
+		dpp_create(netdev);
+		break;
+	case NETDEV_WATCH_EVENT_DEL:
+		l_dbus_object_remove_interface(dbus_get_bus(),
+						netdev_get_path(netdev),
+						IWD_DPP_INTERFACE);
+		break;
+	default:
+		break;
+	}
+}
+
+static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+
+	if (!netdev_get_is_up(dpp->netdev))
+		return dbus_error_not_available(message);
+
+	return dbus_error_not_supported(message);
+}
+
+static struct l_dbus_message *dpp_dbus_stop(struct l_dbus *dbus,
+						struct l_dbus_message *message,
+						void *user_data)
+{
+	return dbus_error_not_supported(message);
+}
+
+static void dpp_setup_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_method(interface, "StartEnrollee", 0,
+				dpp_dbus_start_enrollee, "", "a{sv}",
+				"uri", "args");
+	l_dbus_interface_method(interface, "Stop", 0,
+				dpp_dbus_stop, "", "");
+}
+
+static void dpp_destroy_interface(void *user_data)
+{
+	struct dpp_sm *dpp = user_data;
+
+	dpp_free(dpp);
+}
+
+static int dpp_init(void)
+{
+	netdev_watch = netdev_watch_add(dpp_netdev_watch, NULL, NULL);
+
+	l_dbus_register_interface(dbus_get_bus(), IWD_DPP_INTERFACE,
+					dpp_setup_interface,
+					dpp_destroy_interface, false);
+	return 0;
+}
+
+static void dpp_exit(void)
+{
+	l_debug("");
+
+	netdev_watch_remove(netdev_watch);
+}
+
+IWD_MODULE(dpp, dpp_init, dpp_exit);
+IWD_MODULE_DEPENDS(dpp, netdev);
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 02/10] dpp: initial skeleton DPP module
@ 2021-12-14 21:32 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-12-14 21:32 UTC (permalink / raw)
  To: iwd 

[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]

Hi James,

On 12/14/21 12:12 PM, James Prestwood wrote:
> ---
>   Makefile.am |   1 +
>   src/dpp.c   | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 129 insertions(+)
>   create mode 100644 src/dpp.c
> 
> v2:
>   * Only create dpp_sm if device is station
> 

<snip>

> +
> +static void dpp_netdev_watch(struct netdev *netdev,
> +				enum netdev_watch_event event, void *userdata)
> +{
> +	if (netdev_get_iftype(netdev) != NETDEV_IFTYPE_STATION)
> +		return;
> +
> +	switch (event) {
> +	case NETDEV_WATCH_EVENT_NEW:

Can we also create it if the device is UP?

> +		dpp_create(netdev);
> +		break;
> +	case NETDEV_WATCH_EVENT_DEL:

And delete if the device is DOWN?

> +		l_dbus_object_remove_interface(dbus_get_bus(),
> +						netdev_get_path(netdev),
> +						IWD_DPP_INTERFACE);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
> +static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,
> +						struct l_dbus_message *message,
> +						void *user_data)
> +{
> +	struct dpp_sm *dpp = user_data;
> +
> +	if (!netdev_get_is_up(dpp->netdev))
> +		return dbus_error_not_available(message);

That way you can skip this check.  There isn't much point in having this 
interface around if the device is not UP anyway.

> +
> +	return dbus_error_not_supported(message);
> +}
> +

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-14 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-14 18:12 [PATCH v2 02/10] dpp: initial skeleton DPP module James Prestwood
  -- strict thread matches above, loose matches on Subject: below --
2021-12-14 21:32 Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox