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. Re: [PATCH] ntp: clear ADJ_MAXERROR to keep STA_UNSYNC
      cleared after jump adjust (Patrik Flykt)
   2. Re: [PATCH] ntp: clear ADJ_MAXERROR to keep STA_UNSYNC
      cleared after jump adjust (Patrik Flykt)
   3. [RFC v0 00/10] IWD plugin (Daniel Wagner)
   4. [RFC v0 01/10] service: Remove noisy DBGs (Daniel Wagner)
   5. [RFC v0 02/10] service: Connect() should not block (Daniel Wagner)
   6. [RFC v0 03/10] service: Add support for IWD security type
      mapping (Daniel Wagner)
   7. [RFC v0 04/10] iwd: Add infrastructure for iwd plugin
      (Daniel Wagner)
   8. [RFC v0 05/10] iwd: Track D-Bus API (Daniel Wagner)


----------------------------------------------------------------------

Message: 1
Date: Thu, 10 Nov 2016 08:46:33 +0200
From: Patrik Flykt <[email protected]>
To: Daniel Wagner <[email protected]>, Alexander Kochetkov
        <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] ntp: clear ADJ_MAXERROR to keep STA_UNSYNC
        cleared after jump adjust
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

On Wed, 2016-11-09 at 14:22 +0100, Daniel Wagner wrote:

> Thanks for your patch. Since I have no clue how this stuff works I
> would?like an ACK from Jukka who did some work in the past and seem
> to?understand it.

Patch looks fine to me. Should not work any more worse than the current
implementation. ACK from me.

Cheers,

        Patrik



------------------------------

Message: 2
Date: Thu, 10 Nov 2016 08:48:31 +0200
From: Patrik Flykt <[email protected]>
To: Alexander Kochetkov <[email protected]>, Daniel Wagner
        <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] ntp: clear ADJ_MAXERROR to keep STA_UNSYNC
        cleared after jump adjust
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

On Wed, 2016-11-09 at 19:47 +0300, Alexander Kochetkov wrote:
> Hi Daniel,
> 
> Actually the patch implement same code (keep STA_UNSYNC) already
> present for slew updates.
> 
> Here a quick test you can do to see issue:
> 
> 1. boot into linux
> 2. disconnect network
> 3. set incorrect date and time
> ????date --set "2010-09-13 21:08:00"?
> ????hwclock --systohc ?utc
> 4. reboot (keep network disconnected, so connman cannot update system
> time using NTP)
> 5. wait a bit (30 seconds)
> 6. run script in terminal
> ????while true; do date; hwclock -r; echo; sleep 1; done
> 7. connect network
> 
> expected behavior:
> system time and RTC time was corrected by NTP
> 
> actual behaviour:
> system time was corrected by NTP, but RTC time still incorrect.
> you should wait a lot, until NTP make another (slew) adjustment and
> clear STA_UNSYNC
> 
> For testing that I made automatic test. But for running test fast
> linux kernel should be patched also.

Cool! This should go into ./tests so we don't loose it. 

> 8<======================================================
> #!/bin/sh
> 
> trap 'exit' TERM INT EXIT
> 
> while [ true ]; do
> ????echo Starting test
> ????systemctl stop connman
> 
> ????date --set "2010-09-13 21:08:00"
> ????hwclock --systohc --utc
> 
> ????systemctl start connman
> 
> ????while true; do
> ????????date | grep -q 2016 && break
> ????????sleep 1
> ????done
> ????echo NTP sync OK
> 
> ????counter=0
> ????while true; do
> ????????if [ $counter -eq 10 ]; then
> ????????????echo RTC not synced
> ????????????exit
> ????????fi
> ????????hwclock -r | grep -q 2016 && break
> ????????counter=`expr $counter + 1`
> ????????sleep 1
> ????done
> ????echo RTC sync OK
> done

Cheers,

        Patrik


------------------------------

Message: 3
Date: Thu, 10 Nov 2016 13:43:01 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 00/10] IWD plugin
Message-ID: <[email protected]>

From: Daniel Wagner <[email protected]>

A first rough version for testing. There are still a few open question
or misbehave but generally it should be usable.

patch 1:   Makes service a bit more silent
patch 2:   Fixes a small bug where we block ourself in D-Bus
           message processing
patch 3-8: Add basic infrastructre for the plugin and then add
           piece by piece relevant code
patch 9:   Start of tethering support WIP


cheers,
daniel

Daniel Wagner (10):
  service: Remove noisy DBGs
  service: Connect() should not block
  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
  iwd: Add tethering support

 Makefile.plugins |    5 +
 configure.ac     |    5 +
 plugins/iwd.c    | 1116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/service.c    |   14 +-
 4 files changed, 1130 insertions(+), 10 deletions(-)
 create mode 100644 plugins/iwd.c

-- 
2.7.4


------------------------------

Message: 4
Date: Thu, 10 Nov 2016 13:43:02 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 01/10] service: Remove noisy DBGs
Message-ID: <[email protected]>

From: Daniel Wagner <[email protected]>

These DBGs are very noisy in the log and don't provide any real
value. So let's remove them and make the log great again.
---
 src/service.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/service.c b/src/service.c
index f6a76f6bb4a5..5304c0db72bd 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1665,8 +1665,6 @@ static void append_nameservers(DBusMessageIter *iter,
                                                CONNMAN_IPCONFIG_TYPE_ALL,
                                                servers[i]);
 
-               DBG("servers[%d] %s available %d", i, servers[i], available);
-
                if (available)
                        dbus_message_iter_append_basic(iter,
                                        DBUS_TYPE_STRING, &servers[i]);
@@ -2928,8 +2926,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBusMessage *reply;
        DBusMessageIter array, dict;
 
-       DBG("service %p", service);
-
        reply = dbus_message_new_method_return(msg);
        if (!reply)
                return NULL;
@@ -4452,10 +4448,8 @@ static void service_schedule_removed(struct 
connman_service *service)
 static bool allow_property_changed(struct connman_service *service)
 {
        if (g_hash_table_lookup_extended(services_notify->add, service->path,
-                                       NULL, NULL)) {
-               DBG("no property updates for service %p", service);
+                                       NULL, NULL))
                return false;
-       }
 
        return true;
 }
-- 
2.7.4


------------------------------

Message: 5
Date: Thu, 10 Nov 2016 13:43:03 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 02/10] service: Connect() should not block
Message-ID: <[email protected]>

From: Daniel Wagner <[email protected]>

According the documentation the Connect() call should never block.

For a network we don't have a passphrase yet we ask via the agent the user
for one. From connect_service() we call __connman_service_connect()
which will eventually call connman_agent_queue_message(). The last
function creates a new DBus message and queues it up into the dbus
layer. Unforntatly, that message wont be sent until the pending
message (connect_service) has been handled. The result is we wait
until a timer expires before moving on. With returning an empty D-Bus
message we unblock the dbus layer and everytying moves on.
---
 src/service.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/service.c b/src/service.c
index 5304c0db72bd..9c3dde4a2667 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4049,7 +4049,7 @@ static DBusMessage *connect_service(DBusConnection *conn,
                        CONNMAN_SERVICE_CONNECT_REASON_USER);
 
        if (err == -EINPROGRESS)
-               return NULL;
+               return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 
        if (service->pending) {
                dbus_message_unref(service->pending);
-- 
2.7.4


------------------------------

Message: 6
Date: Thu, 10 Nov 2016 13:43:04 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 03/10] 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 9c3dde4a2667..856cf154e306 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: 7
Date: Thu, 10 Nov 2016 13:43:05 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 04/10] 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: 8
Date: Thu, 10 Nov 2016 13:43:06 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [RFC v0 05/10] iwd: Track D-Bus API
Message-ID: <[email protected]>

From: Daniel Wagner <[email protected]>

---
 plugins/iwd.c | 483 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 483 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index d42f21a2281e..4036ad276a37 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -23,16 +23,499 @@
 #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 *vendor;
+       char *model;
+       bool powered;
+};
+
+struct iwd_device {
+       GDBusProxy *proxy;
+       char *adapter;
+       char *name;
+       char *address;
+       enum iwd_device_state state;
+       bool powered;
+       bool scanning;
+};
+
+struct iwd_network {
+       GDBusProxy *proxy;
+       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 "unkonwn";
+}
+
+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, "Address")) {
+               const char *address;
+
+               dbus_message_iter_get_basic(iter, &address);
+               g_free(iwdd->address);
+               iwdd->address = g_strdup(address);
+
+               DBG("%p address %s", path, iwdd->address);
+       } 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, "Name")) {
+               const char *name;
+
+               dbus_message_iter_get_basic(iter, &name);
+               g_free(iwdn->name);
+               iwdn->name = g_strdup(name);
+
+               DBG("%p name %s", path, iwdn->name);
+       } else 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);
+       } else if (!strcmp(name, "Type")) {
+               const char *type;
+
+               dbus_message_iter_get_basic(iter, &type);
+               g_free(iwdn->type);
+               iwdn->type = g_strdup(type);
+
+               DBG("%p type %s", path, iwdn->type);
+       }
+}
+
+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->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->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->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;
+       DBusMessageIter iter, value;
+
+       iwda = g_try_new0(struct iwd_adapter, 1);
+
+       if (!iwda) {
+               connman_error("Out of memory creating IWD adapter");
+               return;
+       }
+
+       g_hash_table_replace(adapters, g_strdup(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);
+
+       if (!g_dbus_proxy_get_property(iwda->proxy, "Devices", &iter))
+               return;
+
+       dbus_message_iter_recurse(&iter, &value);
+       while (dbus_message_iter_get_arg_type(&value) ==
+                       DBUS_TYPE_OBJECT_PATH) {
+               const char *path;
+
+               dbus_message_iter_get_basic(&value, &path);
+               DBG("device %s", path);
+
+               dbus_message_iter_next(&value);
+       }
+
+       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;
+       }
+
+       g_hash_table_replace(devices, g_strdup(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 *network;
+
+       network = g_try_new0(struct iwd_network, 1);
+
+       if (!network) {
+               connman_error("Out of memory creating IWD network");
+               return;
+       }
+
+       g_hash_table_replace(networks, g_strdup(path), network);
+
+       network->proxy = g_dbus_proxy_ref(proxy);
+
+       if (!network->proxy) {
+               connman_error("Cannot create IWD network watcher %s", path);
+               g_hash_table_remove(networks, path);
+               return;
+       }
+
+       network->device = g_strdup(proxy_get_string(proxy, "Device"));
+       network->name = g_strdup(proxy_get_string(proxy, "Name"));
+       network->type = g_strdup(proxy_get_string(proxy, "Type"));
+       network->connected = proxy_get_bool(proxy, "Connected");
+
+       DBG("device %s name '%s' type %s connected %d",
+               network->device,
+               network->name,
+               network->type,
+               network->connected);
+
+       g_dbus_proxy_set_property_watch(network->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, g_free,
+                       adapter_free);
+
+       devices = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+                       device_free);
+
+       networks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+                       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


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 13, Issue 9
**************************************

Reply via email to