Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH] nftables: Do no leak memory in error case (Daniel Wagner)
2. [PATCH v2 0/7] IWD plugin (Daniel Wagner)
3. [PATCH v2 1/7] service: Add support for IWD security type
mapping (Daniel Wagner)
4. [PATCH v2 2/7] iwd: Add infrastructure for iwd plugin
(Daniel Wagner)
5. [PATCH v2 3/7] iwd: Track D-Bus API (Daniel Wagner)
6. [PATCH v2 4/7] iwd: Add Agent support (Daniel Wagner)
----------------------------------------------------------------------
Message: 1
Date: Sat, 12 Nov 2016 22:05:38 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH] nftables: Do no leak memory in error case
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
mnl_nlmsg_batch_start() allocated memory which needs be freed by
mnl_nlmsg_batch_stop().
---
src/firewall-nftables.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/firewall-nftables.c b/src/firewall-nftables.c
index d36e90b657be..4d47f20097ec 100644
--- a/src/firewall-nftables.c
+++ b/src/firewall-nftables.c
@@ -418,12 +418,9 @@ static int table_cmd(struct mnl_socket *nl, struct
nftnl_table *t,
/* The current table commands do not support any callback returns. */
err = send_and_dispatch(nl, mnl_nlmsg_batch_head(batch),
mnl_nlmsg_batch_size(batch), 0, NULL);
- if (err < 0)
- return err;
mnl_nlmsg_batch_stop(batch);
-
- return 0;
+ return err;
}
static int chain_cmd(struct mnl_socket *nl, struct nftnl_chain *chain,
@@ -451,12 +448,9 @@ static int chain_cmd(struct mnl_socket *nl, struct
nftnl_chain *chain,
err = send_and_dispatch(nl, mnl_nlmsg_batch_head(batch),
mnl_nlmsg_batch_size(batch), cb_type, cb_val);
- if (err < 0)
- return err;
mnl_nlmsg_batch_stop(batch);
-
- return 0;
+ return err;
}
static int rule_cmd(struct mnl_socket *nl, struct nftnl_rule *rule,
--
2.7.4
------------------------------
Message: 2
Date: Sat, 12 Nov 2016 22:12:28 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 0/7] IWD plugin
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
This version passes heavy stress testing without leaking memory or
crashing. So far so good. I still seem to have problems to get a
working setup with iwd. For example when I connect to a network
sometimes it works without a problem but most of the time iwd just
disconnects immediallty. It looks like a problem with the interaction
between iwd and the hardware. I get different behavior depending on
the WiFi hardware.
changes from v1:
- move memory leaks fixed: un/ref devices
- remove all network when device goes away
- all objects live time is bounded to d-bus live time
changes from v0:
- addressed feedback from Denis (property changed)
- fixed a couple of memory overwrites due to wrong ref/unref
- dropped tethering bits (not implemented)
- handling of signal strength
Daniel Wagner (7):
service: Add support for IWD security type mapping
iwd: Add infrastructure for iwd plugin
iwd: Track D-Bus API
iwd: Add Agent support
iwd: Register technology, device and network driver stub
iwd: Add/remove ConnMan devices
iwd: Add/remove ConnMan networks
Makefile.plugins | 5 +
configure.ac | 5 +
plugins/iwd.c | 1104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/service.c | 4 +-
4 files changed, 1116 insertions(+), 2 deletions(-)
create mode 100644 plugins/iwd.c
--
2.7.4
------------------------------
Message: 3
Date: Sat, 12 Nov 2016 22:12:29 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 1/7] service: Add support for IWD security type
mapping
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
IWD names the security types slightly different to what
gsupplicant returns. Though we need to map them to those names
because ConnMan exposes these strings via the Service.Security
property.
---
src/service.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/service.c b/src/service.c
index 5304c0db72bd..40e117d5dd35 100644
--- a/src/service.c
+++ b/src/service.c
@@ -241,9 +241,9 @@ enum connman_service_security
__connman_service_string2security(const char *str)
if (!strcmp(str, "psk"))
return CONNMAN_SERVICE_SECURITY_PSK;
- if (!strcmp(str, "ieee8021x"))
+ if (!strcmp(str, "ieee8021x") || !strcmp(str, "8021x"))
return CONNMAN_SERVICE_SECURITY_8021X;
- if (!strcmp(str, "none"))
+ if (!strcmp(str, "none") || !strcmp(str, "open"))
return CONNMAN_SERVICE_SECURITY_NONE;
if (!strcmp(str, "wep"))
return CONNMAN_SERVICE_SECURITY_WEP;
--
2.7.4
------------------------------
Message: 4
Date: Sat, 12 Nov 2016 22:12:30 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 2/7] iwd: Add infrastructure for iwd plugin
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
Makefile.plugins | 5 +++++
configure.ac | 5 +++++
plugins/iwd.c | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+)
create mode 100644 plugins/iwd.c
diff --git a/Makefile.plugins b/Makefile.plugins
index b01fd808d481..dce8b2834a4d 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -26,6 +26,11 @@ builtin_modules += wifi
builtin_sources += plugins/wifi.c $(gsupplicant_sources)
endif
+if IWD
+builtin_modules += iwd
+builtin_sources += plugins/iwd.c
+endif
+
if BLUETOOTH
builtin_modules += bluetooth
builtin_sources += plugins/bluetooth.c
diff --git a/configure.ac b/configure.ac
index b477aa1682cb..20d3b56a494d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -340,6 +340,11 @@ AC_ARG_ENABLE(wifi, AC_HELP_STRING([--disable-wifi],
[enable_wifi=${enableval}])
AM_CONDITIONAL(WIFI, test "${enable_wifi}" != "no")
+AC_ARG_ENABLE(iwd, AC_HELP_STRING([--disable-iwd],
+ [disable iwd support]),
+ [enable_iwd=${enableval}])
+AM_CONDITIONAL(IWD, test "${enable_iwd}" != "no")
+
AC_ARG_ENABLE(bluetooth, AC_HELP_STRING([--disable-bluetooth],
[disable Bluetooth support]),
[enable_bluetooth=${enableval}])
diff --git a/plugins/iwd.c b/plugins/iwd.c
new file mode 100644
index 000000000000..d42f21a2281e
--- /dev/null
+++ b/plugins/iwd.c
@@ -0,0 +1,39 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2016 BMW Car IT GmbH.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+
+static int iwd_init(void)
+{
+ return 0;
+}
+
+static void iwd_exit(void)
+{
+}
+
+CONNMAN_PLUGIN_DEFINE(iwd, "IWD plugin", VERSION,
+ CONNMAN_PLUGIN_PRIORITY_DEFAULT, iwd_init, iwd_exit)
--
2.7.4
------------------------------
Message: 5
Date: Sat, 12 Nov 2016 22:12:31 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 3/7] iwd: Track D-Bus API
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
plugins/iwd.c | 456 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 456 insertions(+)
diff --git a/plugins/iwd.c b/plugins/iwd.c
index d42f21a2281e..d372e9f1ac5c 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -23,16 +23,472 @@
#include <config.h>
#endif
+#include <errno.h>
+#include <string.h>
+#include <stdbool.h>
+
#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
+#include <connman/dbus.h>
+#include <gdbus.h>
+
+static DBusConnection *connection;
+static GDBusClient *client;
+static GHashTable *adapters;
+static GHashTable *devices;
+static GHashTable *networks;
+
+#define IWD_SERVICE "net.connman.iwd"
+#define IWD_PATH "/"
+#define IWD_AGENT_MANAGER_INTERFACE "net.connman.iwd.AgentManager"
+#define IWD_ADAPTER_INTERFACE "net.connman.iwd.Adapter"
+#define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
+#define IWD_NETWORK_INTERFACE "net.connman.iwd.Network"
+
+enum iwd_device_state {
+ IWD_DEVICE_STATE_UNKNOWN,
+ IWD_DEVICE_STATE_CONNECTED,
+ IWD_DEVICE_STATE_DISCONNECTED,
+ IWD_DEVICE_STATE_CONNECTING,
+ IWD_DEVICE_STATE_DISCONNECTING,
+};
+
+struct iwd_adapter {
+ GDBusProxy *proxy;
+ char *path;
+ char *vendor;
+ char *model;
+ bool powered;
+};
+
+struct iwd_device {
+ GDBusProxy *proxy;
+ char *path;
+ char *adapter;
+ char *name;
+ char *address;
+ enum iwd_device_state state;
+ bool powered;
+ bool scanning;
+};
+
+struct iwd_network {
+ GDBusProxy *proxy;
+ char *path;
+ char *device;
+ char *name;
+ char *type;
+ bool connected;
+};
+
+static enum iwd_device_state string2state(const char *str)
+{
+ if (!strcmp(str, "connected"))
+ return IWD_DEVICE_STATE_CONNECTED;
+ else if (!strcmp(str, "disconnected"))
+ return IWD_DEVICE_STATE_DISCONNECTED;
+ else if (!strcmp(str, "connecting"))
+ return IWD_DEVICE_STATE_CONNECTING;
+ else if (!strcmp(str, "disconnecting"))
+ return IWD_DEVICE_STATE_DISCONNECTING;
+
+ return IWD_DEVICE_STATE_UNKNOWN;
+}
+
+static const char *state2string(enum iwd_device_state state)
+{
+ switch (state) {
+ case IWD_DEVICE_STATE_CONNECTED:
+ return "connected";
+ case IWD_DEVICE_STATE_DISCONNECTED:
+ return "disconnected";
+ case IWD_DEVICE_STATE_CONNECTING:
+ return "connecting";
+ case IWD_DEVICE_STATE_DISCONNECTING:
+ return "disconnecting";
+ default:
+ break;
+ }
+
+ return "unknown";
+}
+
+static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
+{
+ DBusMessageIter iter;
+ const char *str;
+
+ if (!g_dbus_proxy_get_property(proxy, property, &iter))
+ return NULL;
+
+ dbus_message_iter_get_basic(&iter, &str);
+
+ return str;
+}
+
+static bool proxy_get_bool(GDBusProxy *proxy, const char *property)
+{
+ DBusMessageIter iter;
+ dbus_bool_t value;
+
+ if (!g_dbus_proxy_get_property(proxy, property, &iter))
+ return false;
+
+ dbus_message_iter_get_basic(&iter, &value);
+
+ return value;
+}
+
+static void adapter_property_change(GDBusProxy *proxy, const char *name,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct iwd_adapter *adapter;
+ const char *path;
+
+ path = g_dbus_proxy_get_path(proxy);
+ adapter = g_hash_table_lookup(adapters, path);
+ if (!adapter)
+ return;
+
+ if (!strcmp(name, "Powered")) {
+ dbus_bool_t powered;
+
+ dbus_message_iter_get_basic(iter, &powered);
+ adapter->powered = powered;
+
+ DBG("%p powered %d", path, adapter->powered);
+ }
+}
+
+static void device_property_change(GDBusProxy *proxy, const char *name,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct iwd_device *iwdd;
+ const char *path;
+
+ path = g_dbus_proxy_get_path(proxy);
+ iwdd = g_hash_table_lookup(devices, path);
+ if (!iwdd)
+ return;
+
+ if (!strcmp(name, "Name")) {
+ const char *name;
+
+ dbus_message_iter_get_basic(iter, &name);
+ g_free(iwdd->name);
+ iwdd->name = g_strdup(name);
+
+ DBG("%p name %s", path, iwdd->name);
+ } else if (!strcmp(name, "State")) {
+ const char *state;
+
+ dbus_message_iter_get_basic(iter, &state);
+ iwdd->state = string2state(state);
+
+ DBG("%s state %s", path, state2string(iwdd->state));
+ } else if (!strcmp(name, "Powered")) {
+ dbus_bool_t powered;
+
+ dbus_message_iter_get_basic(iter, &powered);
+ iwdd->powered = powered;
+
+ DBG("%s powered %d", path, iwdd->powered);
+ } else if (!strcmp(name, "Scanning")) {
+ dbus_bool_t scanning;
+
+ dbus_message_iter_get_basic(iter, &scanning);
+ iwdd->scanning = scanning;
+
+ DBG("%s scanning %d", path, iwdd->scanning);
+ }
+}
+
+static void network_property_change(GDBusProxy *proxy, const char *name,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct iwd_network *iwdn;
+ const char *path;
+
+ path = g_dbus_proxy_get_path(proxy);
+ iwdn = g_hash_table_lookup(networks, path);
+ if (!iwdn)
+ return;
+
+ if (!strcmp(name, "Connected")) {
+ dbus_bool_t connected;
+
+ dbus_message_iter_get_basic(iter, &connected);
+ iwdn->connected = connected;
+
+ DBG("%s connected %d", path, iwdn->connected);
+ }
+}
+
+static void adapter_free(gpointer data)
+{
+ struct iwd_adapter *iwda = data;
+
+ if (iwda->proxy) {
+ g_dbus_proxy_unref(iwda->proxy);
+ iwda->proxy = NULL;
+ }
+
+ g_free(iwda->path);
+ g_free(iwda->vendor);
+ g_free(iwda->model);
+ g_free(iwda);
+}
+
+static void device_free(gpointer data)
+{
+ struct iwd_device *iwdd = data;
+
+ if (iwdd->proxy) {
+ g_dbus_proxy_unref(iwdd->proxy);
+ iwdd->proxy = NULL;
+ }
+
+ g_free(iwdd->path);
+ g_free(iwdd->adapter);
+ g_free(iwdd->name);
+ g_free(iwdd->address);
+ g_free(iwdd);
+}
+
+static void network_free(gpointer data)
+{
+ struct iwd_network *iwdn = data;
+
+ if (iwdn->proxy) {
+ g_dbus_proxy_unref(iwdn->proxy);
+ iwdn->proxy = NULL;
+ }
+
+ g_free(iwdn->path);
+ g_free(iwdn->device);
+ g_free(iwdn->name);
+ g_free(iwdn->type);
+ g_free(iwdn);
+}
+
+static void create_adapter(GDBusProxy *proxy)
+{
+ const char *path = g_dbus_proxy_get_path(proxy);
+ struct iwd_adapter *iwda;
+
+ iwda = g_try_new0(struct iwd_adapter, 1);
+
+ if (!iwda) {
+ connman_error("Out of memory creating IWD adapter");
+ return;
+ }
+
+ iwda->path = g_strdup(path);
+ g_hash_table_replace(adapters, iwda->path, iwda);
+
+ iwda->proxy = g_dbus_proxy_ref(proxy);
+
+ if (!iwda->proxy) {
+ connman_error("Cannot create IWD adapter watcher %s", path);
+ g_hash_table_remove(adapters, path);
+ return;
+ }
+
+ iwda->vendor = g_strdup(proxy_get_string(proxy, "Vendor"));
+ iwda->model = g_strdup(proxy_get_string(proxy, "Model"));
+ iwda->powered = proxy_get_bool(proxy, "Powered");
+
+ DBG("%s vendor '%s' model '%s' powered %d", path, iwda->vendor,
+ iwda->model, iwda->powered);
+
+ g_dbus_proxy_set_property_watch(iwda->proxy,
+ adapter_property_change, NULL);
+}
+
+static void create_device(GDBusProxy *proxy)
+{
+ const char *path = g_dbus_proxy_get_path(proxy);
+ struct iwd_device *iwdd;
+
+ iwdd = g_try_new0(struct iwd_device, 1);
+
+ if (!iwdd) {
+ connman_error("Out of memory creating IWD device");
+ return;
+ }
+
+ iwdd->path = g_strdup(path);
+ g_hash_table_replace(devices, iwdd->path, iwdd);
+
+ iwdd->proxy = g_dbus_proxy_ref(proxy);
+
+ if (!iwdd->proxy) {
+ connman_error("Cannot create IWD device watcher %s", path);
+ g_hash_table_remove(devices, path);
+ return;
+ }
+
+ iwdd->adapter = g_strdup(proxy_get_string(proxy, "Adapter"));
+ iwdd->name = g_strdup(proxy_get_string(proxy, "Name"));
+ iwdd->address = g_strdup(proxy_get_string(proxy, "Address"));
+ iwdd->state = string2state(proxy_get_string(proxy, "State"));
+ iwdd->powered = proxy_get_bool(proxy, "Powered");
+ iwdd->scanning = proxy_get_bool(proxy, "Scanning");
+
+ DBG("adapter %s name %s address %s state %s powered %d scanning %d",
+ iwdd->adapter, iwdd->name, iwdd->address,
+ state2string(iwdd->state),
+ iwdd->powered, iwdd->scanning);
+
+ g_dbus_proxy_set_property_watch(iwdd->proxy,
+ device_property_change, NULL);
+}
+
+static void register_agent(GDBusProxy *proxy)
+{
+}
+
+static void unregister_agent()
+{
+}
+
+static void create_network(GDBusProxy *proxy)
+{
+ const char *path = g_dbus_proxy_get_path(proxy);
+ struct iwd_network *iwdn;
+
+ iwdn = g_try_new0(struct iwd_network, 1);
+
+ if (!iwdn) {
+ connman_error("Out of memory creating IWD network");
+ return;
+ }
+
+ iwdn->path = g_strdup(path);
+ g_hash_table_replace(networks, iwdn->path, iwdn);
+
+ iwdn->proxy = g_dbus_proxy_ref(proxy);
+
+ if (!iwdn->proxy) {
+ connman_error("Cannot create IWD network watcher %s", path);
+ g_hash_table_remove(networks, path);
+ return;
+ }
+
+ iwdn->device = g_strdup(proxy_get_string(proxy, "Device"));
+ iwdn->name = g_strdup(proxy_get_string(proxy, "Name"));
+ iwdn->type = g_strdup(proxy_get_string(proxy, "Type"));
+ iwdn->connected = proxy_get_bool(proxy, "Connected");
+
+ DBG("device %s name '%s' type %s connected %d",
+ iwdn->device,
+ iwdn->name,
+ iwdn->type,
+ iwdn->connected);
+
+ g_dbus_proxy_set_property_watch(iwdn->proxy,
+ network_property_change, NULL);
+}
+
+static void object_added(GDBusProxy *proxy, void *user_data)
+{
+ const char *interface;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ if (!interface) {
+ connman_warn("Interface or proxy missing when adding "
+ "iwd object");
+ return;
+ }
+
+ DBG("%s %s", interface, g_dbus_proxy_get_path(proxy));
+
+ if (!strcmp(interface, IWD_AGENT_MANAGER_INTERFACE))
+ register_agent(proxy);
+ else if (!strcmp(interface, IWD_ADAPTER_INTERFACE))
+ create_adapter(proxy);
+ else if (!strcmp(interface, IWD_DEVICE_INTERFACE))
+ create_device(proxy);
+ else if (!strcmp(interface, IWD_NETWORK_INTERFACE))
+ create_network(proxy);
+}
+
+static void object_removed(GDBusProxy *proxy, void *user_data)
+{
+ const char *interface, *path;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ if (!interface) {
+ connman_warn("Interface or proxy missing when removing "
+ "iwd object");
+ return;
+ }
+
+ path = g_dbus_proxy_get_path(proxy);
+ DBG("%s %s", interface, path);
+
+ if (!strcmp(interface, IWD_AGENT_MANAGER_INTERFACE))
+ unregister_agent();
+ if (!strcmp(interface, IWD_ADAPTER_INTERFACE))
+ g_hash_table_remove(adapters, path);
+ else if (!strcmp(interface, IWD_DEVICE_INTERFACE))
+ g_hash_table_remove(devices, path);
+ else if (!strcmp(interface, IWD_NETWORK_INTERFACE))
+ g_hash_table_remove(networks, path);
+}
static int iwd_init(void)
{
+ connection = connman_dbus_get_connection();
+ if (!connection)
+ goto out;
+
+ adapters = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ adapter_free);
+
+ devices = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ device_free);
+
+ networks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ network_free);
+
+ client = g_dbus_client_new(connection, IWD_SERVICE, IWD_PATH);
+ if (!client) {
+ connman_warn("Failed to initialize D-Bus client for "
+ IWD_SERVICE);
+ goto out;
+ }
+
+ g_dbus_client_set_proxy_handlers(client, object_added, object_removed,
+ NULL, NULL);
+
return 0;
+
+out:
+ if (devices)
+ g_hash_table_destroy(devices);
+
+ if (networks)
+ g_hash_table_destroy(networks);
+
+ if (adapters)
+ g_hash_table_destroy(adapters);
+
+ if (connection)
+ dbus_connection_unref(connection);
+
+ return -EIO;
}
static void iwd_exit(void)
{
+ g_dbus_client_unref(client);
+
+ g_hash_table_destroy(networks);
+ g_hash_table_destroy(devices);
+ g_hash_table_destroy(adapters);
+
+ dbus_connection_unref(connection);
}
CONNMAN_PLUGIN_DEFINE(iwd, "IWD plugin", VERSION,
--
2.7.4
------------------------------
Message: 6
Date: Sat, 12 Nov 2016 22:12:32 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 4/7] iwd: Add Agent support
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
plugins/iwd.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)
diff --git a/plugins/iwd.c b/plugins/iwd.c
index d372e9f1ac5c..eb13e6d4b966 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -34,9 +34,11 @@
static DBusConnection *connection;
static GDBusClient *client;
+static GDBusProxy *agent_proxy;
static GHashTable *adapters;
static GHashTable *devices;
static GHashTable *networks;
+static bool agent_registered;
#define IWD_SERVICE "net.connman.iwd"
#define IWD_PATH "/"
@@ -45,6 +47,10 @@ static GHashTable *networks;
#define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
#define IWD_NETWORK_INTERFACE "net.connman.iwd.Network"
+#define IWD_AGENT_INTERFACE "net.connman.iwd.Agent"
+#define IWD_AGENT_ERROR_INTERFACE "net.connman.iwd.Agent.Error"
+#define AGENT_PATH "/net/connman/iwd_agent"
+
enum iwd_device_state {
IWD_DEVICE_STATE_UNKNOWN,
IWD_DEVICE_STATE_CONNECTED,
@@ -344,12 +350,132 @@ static void create_device(GDBusProxy *proxy)
device_property_change, NULL);
}
+static void unregister_agent();
+
+static DBusMessage *agent_release_method(DBusConnection *dbus_conn,
+ DBusMessage *message, void *user_data)
+{
+ unregister_agent();
+ return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *get_reply_on_error(DBusMessage *message, int error)
+{
+ return g_dbus_create_error(message,
+ IWD_AGENT_ERROR_INTERFACE ".Failed", "Invalid parameters");
+}
+
+static DBusMessage *agent_request_passphrase(DBusConnection *dbus_conn,
+ DBusMessage *message,
+ void *user_data)
+{
+ struct iwd_network *iwdn;
+ DBusMessageIter iter;
+ const char *path, *passwd;
+
+ DBG("");
+
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ return get_reply_on_error(message, EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &path);
+
+ iwdn = g_hash_table_lookup(networks, path);
+ if (!iwdn)
+ return get_reply_on_error(message, EINVAL);
+
+ passwd = "mysecret";
+
+ return g_dbus_create_reply(message, DBUS_TYPE_STRING, &passwd,
+ DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *agent_cancel(DBusConnection *dbus_conn,
+ DBusMessage *message, void *user_data)
+{
+ DBusMessageIter iter;
+ const char *reason;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return get_reply_on_error(message, EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &reason);
+
+ DBG("cancel: %s", reason);
+ /* XXX stop connection attempt, which one? */
+
+ return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable agent_methods[] = {
+ { GDBUS_METHOD("Release", NULL, NULL, agent_release_method) },
+ { GDBUS_METHOD("RequestPassphrase",
+ GDBUS_ARGS({ "path", "o" }),
+ GDBUS_ARGS({ "passphrase", "s" }),
+ agent_request_passphrase)},
+ { GDBUS_METHOD("Cancel",
+ GDBUS_ARGS({ "reason", "s" }),
+ NULL, agent_cancel) },
+ { },
+};
+
+static void agent_register_builder(DBusMessageIter *iter, void *user_data)
+{
+ const char *path = AGENT_PATH;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+ &path);
+}
+
static void register_agent(GDBusProxy *proxy)
{
+ if (!g_dbus_proxy_method_call(proxy,
+ "RegisterAgent",
+ agent_register_builder,
+ NULL, NULL, NULL))
+ return;
+
+ agent_proxy = g_dbus_proxy_ref(proxy);
}
static void unregister_agent()
{
+ if (!agent_proxy)
+ return;
+
+ g_dbus_proxy_method_call(agent_proxy,
+ "UnregisterAgent",
+ agent_register_builder,
+ NULL, NULL, NULL);
+
+ g_dbus_proxy_unref(agent_proxy);
+ agent_proxy = NULL;
+}
+
+static void iwd_is_present(DBusConnection *conn, void *user_data)
+{
+ if (agent_registered)
+ return;
+
+ if (!g_dbus_register_interface(connection, AGENT_PATH,
+ IWD_AGENT_INTERFACE, agent_methods,
+ NULL, NULL, NULL, NULL))
+ return;
+
+ agent_registered = true;
+}
+
+static void iwd_is_out(DBusConnection *conn, void *user_data)
+{
+ if (agent_registered) {
+ g_dbus_unregister_interface(connection,
+ AGENT_PATH, IWD_AGENT_INTERFACE);
+ agent_registered = false;
+ }
}
static void create_network(GDBusProxy *proxy)
@@ -459,6 +585,8 @@ static int iwd_init(void)
goto out;
}
+ g_dbus_client_set_connect_watch(client, iwd_is_present, NULL);
+ g_dbus_client_set_disconnect_watch(client, iwd_is_out, NULL);
g_dbus_client_set_proxy_handlers(client, object_added, object_removed,
NULL, NULL);
--
2.7.4
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 13, Issue 19
***************************************