Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe 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 v2 04/10] iwd: Add KnownNetwork property to struct iwd_network
      (Daniel Wagner)
   2. [PATCH v2 03/10] iwd: Add KnownNetwork support (Daniel Wagner)
   3. [PATCH v2 08/10] iwd: Re-add update_signal_strenght()
      (Daniel Wagner)
   4. [PATCH v2 07/10] iwd: Add AccessPoint API support (Daniel Wagner)
   5. [PATCH v2 06/10] iwd: Add AdHoc API support (Daniel Wagner)
   6. [PATCH v2 05/10] iwd: Add Station API support (Daniel Wagner)


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

Date: Tue,  7 Jan 2020 19:51:11 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 04/10] iwd: Add KnownNetwork property to struct
        iwd_network
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

Parse the KnownNetwork property and add it to struct iwd_network.
---
 plugins/iwd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 82e0b6c794e2..94284996a6bb 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -87,6 +87,7 @@ struct iwd_network {
        char *name;
        char *type;
        bool connected;
+       char *known_network;
 
        struct iwd_device *iwdd;
        struct connman_network *network;
@@ -672,6 +673,7 @@ static void network_free(gpointer data)
        g_free(iwdn->device);
        g_free(iwdn->name);
        g_free(iwdn->type);
+       g_free(iwdn->known_network);
        g_free(iwdn);
 }
 
@@ -943,12 +945,11 @@ static void create_network(GDBusProxy *proxy)
        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");
+       iwdn->known_network = g_strdup(proxy_get_string(proxy, "KnownNetwork"));
 
-       DBG("device %s name '%s' type %s connected %d",
-               iwdn->device,
-               iwdn->name,
-               iwdn->type,
-               iwdn->connected);
+       DBG("device %s name '%s' type %s connected %d known_network %s",
+               iwdn->device, iwdn->name, iwdn->type, iwdn->connected,
+               iwdn->known_network);
 
        g_dbus_proxy_set_property_watch(iwdn->proxy,
                        network_property_change, NULL);
-- 
2.24.1

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

Date: Tue,  7 Jan 2020 19:51:10 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 03/10] iwd: Add KnownNetwork support
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

iwd exports all network it has been connected in the past via the
KnowNetwork interface. Add basic support to extract the information
from D-Bus.
---
 plugins/iwd.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 7222dd80e89d..82e0b6c794e2 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -42,6 +42,7 @@ static GDBusProxy *agent_proxy;
 static GHashTable *adapters;
 static GHashTable *devices;
 static GHashTable *networks;
+static GHashTable *known_networks;
 static bool agent_registered;
 
 #define IWD_SERVICE                    "net.connman.iwd"
@@ -50,6 +51,7 @@ static bool agent_registered;
 #define IWD_ADAPTER_INTERFACE          "net.connman.iwd.Adapter"
 #define IWD_DEVICE_INTERFACE           "net.connman.iwd.Device"
 #define IWD_NETWORK_INTERFACE          "net.connman.iwd.Network"
+#define IWD_KNOWN_NETWORK_INTERFACE    "net.connman.iwd.KnownNetwork"
 
 #define IWD_AGENT_INTERFACE            "net.connman.iwd.Agent"
 #define IWD_AGENT_ERROR_INTERFACE      "net.connman.iwd.Agent.Error"
@@ -90,6 +92,16 @@ struct iwd_network {
        struct connman_network *network;
 };
 
+struct iwd_known_network {
+       GDBusProxy *proxy;
+       char *path;
+       char *name;
+       char *type;
+       bool hidden;
+       char *last_connected_time;
+       bool auto_connect;
+};
+
 static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
 {
        DBusMessageIter iter;
@@ -663,6 +675,22 @@ static void network_free(gpointer data)
        g_free(iwdn);
 }
 
+static void known_network_free(gpointer data)
+{
+       struct iwd_known_network *iwdkn = data;
+
+       if (iwdkn->proxy) {
+               g_dbus_proxy_unref(iwdkn->proxy);
+               iwdkn->proxy = NULL;
+       }
+
+       g_free(iwdkn->path);
+       g_free(iwdkn->name);
+       g_free(iwdkn->type);
+       g_free(iwdkn->last_connected_time);
+       g_free(iwdkn);
+}
+
 static void create_adapter(GDBusProxy *proxy)
 {
        const char *path = g_dbus_proxy_get_path(proxy);
@@ -928,6 +956,40 @@ static void create_network(GDBusProxy *proxy)
        add_network(path, iwdn);
 }
 
+static void create_know_network(GDBusProxy *proxy)
+{
+       const char *path = g_dbus_proxy_get_path(proxy);
+       struct iwd_known_network *iwdkn;
+
+       iwdkn = g_try_new0(struct iwd_known_network, 1);
+       if (!iwdkn) {
+               connman_error("Out of memory creating IWD known network");
+               return;
+       }
+
+       iwdkn->path = g_strdup(path);
+       g_hash_table_replace(known_networks, iwdkn->path, iwdkn);
+
+       iwdkn->proxy = g_dbus_proxy_ref(proxy);
+
+       if (!iwdkn->proxy) {
+               connman_error("Cannot create IWD known network watcher %s", 
path);
+               g_hash_table_remove(known_networks, path);
+               return;
+       }
+
+       iwdkn->name = g_strdup(proxy_get_string(proxy, "Name"));
+       iwdkn->type = g_strdup(proxy_get_string(proxy, "Type"));
+       iwdkn->hidden = proxy_get_bool(proxy, "Hidden");
+       iwdkn->last_connected_time =
+               g_strdup(proxy_get_string(proxy, "LastConnectedTime"));
+       iwdkn->auto_connect = proxy_get_bool(proxy, "AutoConnec");
+
+       DBG("name '%s' type %s hidden %d, last_connection_time %s auto_connect 
%d",
+               iwdkn->name, iwdkn->type, iwdkn->hidden,
+               iwdkn->last_connected_time, iwdkn->auto_connect);
+}
+
 static void object_added(GDBusProxy *proxy, void *user_data)
 {
        const char *interface;
@@ -949,6 +1011,8 @@ static void object_added(GDBusProxy *proxy, void 
*user_data)
                create_device(proxy);
        else if (!strcmp(interface, IWD_NETWORK_INTERFACE))
                create_network(proxy);
+       else if (!strcmp(interface, IWD_KNOWN_NETWORK_INTERFACE))
+               create_know_network(proxy);
 }
 
 static void object_removed(GDBusProxy *proxy, void *user_data)
@@ -973,6 +1037,8 @@ static void object_removed(GDBusProxy *proxy, void 
*user_data)
                g_hash_table_remove(devices, path);
        else if (!strcmp(interface, IWD_NETWORK_INTERFACE))
                g_hash_table_remove(networks, path);
+       else if (!strcmp(interface, IWD_KNOWN_NETWORK_INTERFACE))
+               g_hash_table_remove(known_networks, path);
 }
 
 static int iwd_init(void)
@@ -990,6 +1056,9 @@ static int iwd_init(void)
        networks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                        network_free);
 
+       known_networks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       known_network_free);
+
        if (connman_technology_driver_register(&tech_driver) < 0) {
                connman_warn("Failed to initialize technology for IWD");
                goto out;
@@ -1029,6 +1098,9 @@ static int iwd_init(void)
        if (networks)
                g_hash_table_destroy(networks);
 
+       if (known_networks)
+               g_hash_table_destroy(known_networks);
+
        if (adapters)
                g_hash_table_destroy(adapters);
 
@@ -1046,6 +1118,7 @@ static void iwd_exit(void)
 
        g_dbus_client_unref(client);
 
+       g_hash_table_destroy(known_networks);
        g_hash_table_destroy(networks);
        g_hash_table_destroy(devices);
        g_hash_table_destroy(adapters);
-- 
2.24.1

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

Date: Tue,  7 Jan 2020 19:51:15 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 08/10] iwd: Re-add update_signal_strenght()
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

Bring back the update_signal_strenght() code.
---
 plugins/iwd.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 102d56798a31..cc359770587f 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -652,6 +652,84 @@ static void network_property_change(GDBusProxy *proxy, 
const char *name,
        }
 }
 
+static unsigned char calculate_strength(int strength)
+{
+       unsigned char res;
+
+       /*
+        * Network's maximum signal strength expressed in 100 * dBm.
+        * The value is the range of 0 (strongest signal) to -10000
+        * (weakest signal)
+        *
+        * ConnMan expects it in the range from 100 (strongest) to 0
+        * (weakest).
+        */
+       res = (unsigned char)((strength * -10000) / 100);
+
+       return res;
+}
+
+static void _update_signal_strength(const char *path, int16_t signal_strength)
+{
+       struct iwd_station *iwds;
+       struct iwd_network *iwdn;
+
+       iwds = g_hash_table_lookup(stations, path);
+       if (!iwds)
+               return;
+
+       if (!iwds->connected_network)
+               return;
+
+       iwdn = g_hash_table_lookup(networks, iwds->connected_network);
+       if (!iwdn)
+               return;
+
+       connman_network_set_strength(iwdn->network,
+                                       calculate_strength(signal_strength));
+}
+
+static void ordered_networks_cb(DBusMessage *message, void *user_data)
+{
+       DBusMessageIter array, entry;
+
+       DBG("");
+
+       if (!dbus_message_iter_init(message, &array))
+               return;
+
+       if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+               return;
+
+       dbus_message_iter_recurse(&array, &entry);
+       while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRUCT) {
+               DBusMessageIter value;
+               const char *path;
+               int16_t signal_strength;
+
+
+               dbus_message_iter_recurse(&entry, &value);
+
+               dbus_message_iter_get_basic(&value, &path);
+
+               dbus_message_iter_next(&value);
+               dbus_message_iter_get_basic(&value, &signal_strength);
+
+               _update_signal_strength(path, signal_strength);
+
+               dbus_message_iter_next(&entry);
+       }
+}
+
+static void update_signal_strength(struct iwd_station *iwds)
+{
+       if (!g_dbus_proxy_method_call(iwds->proxy,
+                                       "GetOrderedNetworks",
+                                       NULL, ordered_networks_cb,
+                                       NULL, NULL))
+               DBG("GetOrderedNetworks() failed");
+}
+
 static void station_property_change(GDBusProxy *proxy, const char *name,
                DBusMessageIter *iter, void *user_data)
 {
@@ -689,6 +767,9 @@ static void station_property_change(GDBusProxy *proxy, 
const char *name,
                dbus_message_iter_get_basic(iter, &scanning);
                iwds->scanning = scanning;
 
+               if (!iwds->scanning)
+                       update_signal_strength(iwds);
+
                DBG("%s scanning %d", path, iwds->scanning);
        }
 }
-- 
2.24.1

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

Date: Tue,  7 Jan 2020 19:51:14 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 07/10] iwd: Add AccessPoint API support
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

iwd exposes the AcessPoint API under the same path as the Device API. Add
the initial D-Bus parsing code to the plugin.
---
 plugins/iwd.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 1e31ec59fb8a..102d56798a31 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -45,6 +45,7 @@ static GHashTable *networks;
 static GHashTable *known_networks;
 static GHashTable *stations;
 static GHashTable *adhocs;
+static GHashTable *access_points;
 static bool agent_registered;
 
 #define IWD_SERVICE                    "net.connman.iwd"
@@ -56,6 +57,7 @@ static bool agent_registered;
 #define IWD_KNOWN_NETWORK_INTERFACE    "net.connman.iwd.KnownNetwork"
 #define IWD_STATION_INTERFACE          "net.connman.iwd.Station"
 #define IWD_ADHOC_INTERFACE            "net.connman.iwd.AdHoc"
+#define IWD_AP_INTERFACE               "net.connman.iwd.AccessPoint"
 
 #define IWD_AGENT_INTERFACE            "net.connman.iwd.Agent"
 #define IWD_AGENT_ERROR_INTERFACE      "net.connman.iwd.Agent.Error"
@@ -122,6 +124,12 @@ struct iwd_adhoc {
        bool started;
 };
 
+struct iwd_ap {
+       GDBusProxy *proxy;
+       char *path;
+       bool started;
+};
+
 static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
 {
        DBusMessageIter iter;
@@ -708,6 +716,27 @@ static void adhoc_property_change(GDBusProxy *proxy, const 
char *name,
        }
 }
 
+static void ap_property_change(GDBusProxy *proxy, const char *name,
+               DBusMessageIter *iter, void *user_data)
+{
+       struct iwd_ap *iwdap;
+       const char *path;
+
+       path = g_dbus_proxy_get_path(proxy);
+       iwdap = g_hash_table_lookup(access_points, path);
+       if (!iwdap)
+               return;
+
+        if (!strcmp(name, "Started")) {
+               dbus_bool_t started;
+
+               dbus_message_iter_get_basic(iter, &started);
+               iwdap->started = started;
+
+               DBG("%s started %d", path, iwdap->started);
+       }
+}
+
 static void adapter_free(gpointer data)
 {
        struct iwd_adapter *iwda = data;
@@ -801,6 +830,17 @@ static void adhoc_free(gpointer data)
        g_free(iwdah);
 }
 
+static void ap_free(gpointer data)
+{
+       struct iwd_ap *iwdap = data;
+
+       if (iwdap->proxy) {
+               g_dbus_proxy_unref(iwdap->proxy);
+               iwdap->proxy = NULL;
+       }
+       g_free(iwdap);
+}
+
 static void create_adapter(GDBusProxy *proxy)
 {
        const char *path = g_dbus_proxy_get_path(proxy);
@@ -1179,6 +1219,36 @@ static void create_adhoc(GDBusProxy *proxy)
                        adhoc_property_change, NULL);
 }
 
+static void create_ap(GDBusProxy *proxy)
+{
+       const char *path = g_dbus_proxy_get_path(proxy);
+       struct iwd_ap *iwdap;
+
+       iwdap = g_try_new0(struct iwd_ap, 1);
+       if (!iwdap) {
+               connman_error("Out of memory creating IWD access point");
+               return;
+       }
+
+       iwdap->path = g_strdup(path);
+       g_hash_table_replace(access_points, iwdap->path, iwdap);
+
+       iwdap->proxy = g_dbus_proxy_ref(proxy);
+
+       if (!iwdap->proxy) {
+               connman_error("Cannot create IWD access point watcher %s", 
path);
+               g_hash_table_remove(access_points, path);
+               return;
+       }
+
+       iwdap->started = proxy_get_bool(proxy, "Started");
+
+       DBG("started %d", iwdap->started);
+
+       g_dbus_proxy_set_property_watch(iwdap->proxy,
+                       ap_property_change, NULL);
+}
+
 static void object_added(GDBusProxy *proxy, void *user_data)
 {
        const char *interface;
@@ -1206,6 +1276,8 @@ static void object_added(GDBusProxy *proxy, void 
*user_data)
                create_station(proxy);
        else if (!strcmp(interface, IWD_ADHOC_INTERFACE))
                create_adhoc(proxy);
+       else if (!strcmp(interface, IWD_AP_INTERFACE))
+               create_ap(proxy);
 }
 
 static void object_removed(GDBusProxy *proxy, void *user_data)
@@ -1236,6 +1308,8 @@ static void object_removed(GDBusProxy *proxy, void 
*user_data)
                g_hash_table_remove(stations, path);
        else if (!strcmp(interface, IWD_ADHOC_INTERFACE))
                g_hash_table_remove(adhocs, path);
+       else if (!strcmp(interface, IWD_AP_INTERFACE))
+               g_hash_table_remove(access_points, path);
 }
 
 static int iwd_init(void)
@@ -1262,6 +1336,9 @@ static int iwd_init(void)
        adhocs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                        adhoc_free);
 
+       access_points = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       ap_free);
+
        if (connman_technology_driver_register(&tech_driver) < 0) {
                connman_warn("Failed to initialize technology for IWD");
                goto out;
@@ -1310,6 +1387,9 @@ static int iwd_init(void)
        if (adhocs)
                g_hash_table_destroy(adhocs);
 
+       if (access_points)
+               g_hash_table_destroy(access_points);
+
        if (adapters)
                g_hash_table_destroy(adapters);
 
@@ -1327,6 +1407,7 @@ static void iwd_exit(void)
 
        g_dbus_client_unref(client);
 
+       g_hash_table_destroy(access_points);
        g_hash_table_destroy(adhocs);
        g_hash_table_destroy(stations);
        g_hash_table_destroy(known_networks);
-- 
2.24.1

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

Date: Tue,  7 Jan 2020 19:51:13 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 06/10] iwd: Add AdHoc API support
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

iwd exposes the AdHoc API under the same path as the Device API. Add
the initial D-Bus parsing code to the plugin.
---
 plugins/iwd.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index b3dac13d47ae..1e31ec59fb8a 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -44,6 +44,7 @@ static GHashTable *devices;
 static GHashTable *networks;
 static GHashTable *known_networks;
 static GHashTable *stations;
+static GHashTable *adhocs;
 static bool agent_registered;
 
 #define IWD_SERVICE                    "net.connman.iwd"
@@ -54,6 +55,7 @@ static bool agent_registered;
 #define IWD_NETWORK_INTERFACE          "net.connman.iwd.Network"
 #define IWD_KNOWN_NETWORK_INTERFACE    "net.connman.iwd.KnownNetwork"
 #define IWD_STATION_INTERFACE          "net.connman.iwd.Station"
+#define IWD_ADHOC_INTERFACE            "net.connman.iwd.AdHoc"
 
 #define IWD_AGENT_INTERFACE            "net.connman.iwd.Agent"
 #define IWD_AGENT_ERROR_INTERFACE      "net.connman.iwd.Agent.Error"
@@ -113,6 +115,13 @@ struct iwd_station {
        bool scanning;
 };
 
+struct iwd_adhoc {
+       GDBusProxy *proxy;
+       char *path;
+       GSList *connected_peers;
+       bool started;
+};
+
 static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
 {
        DBusMessageIter iter;
@@ -676,6 +685,29 @@ static void station_property_change(GDBusProxy *proxy, 
const char *name,
        }
 }
 
+static void adhoc_property_change(GDBusProxy *proxy, const char *name,
+               DBusMessageIter *iter, void *user_data)
+{
+       struct iwd_adhoc *iwdah;
+       const char *path;
+
+       path = g_dbus_proxy_get_path(proxy);
+       iwdah = g_hash_table_lookup(stations, path);
+       if (!iwdah)
+               return;
+
+       if (!strcmp(name, "ConnectedPeers")) {
+               DBG("%s connected_peers", path);
+       } else if (!strcmp(name, "Started")) {
+               dbus_bool_t started;
+
+               dbus_message_iter_get_basic(iter, &started);
+               iwdah->started = started;
+
+               DBG("%s started %d", path, iwdah->started);
+       }
+}
+
 static void adapter_free(gpointer data)
 {
        struct iwd_adapter *iwda = data;
@@ -757,6 +789,18 @@ static void station_free(gpointer data)
        g_free(iwds);
 }
 
+static void adhoc_free(gpointer data)
+{
+       struct iwd_adhoc *iwdah = data;
+
+       if (iwdah->proxy) {
+               g_dbus_proxy_unref(iwdah->proxy);
+               iwdah->proxy = NULL;
+       }
+       g_slist_free_full(iwdah->connected_peers, g_free);
+       g_free(iwdah);
+}
+
 static void create_adapter(GDBusProxy *proxy)
 {
        const char *path = g_dbus_proxy_get_path(proxy);
@@ -1088,6 +1132,53 @@ static void create_station(GDBusProxy *proxy)
                        station_property_change, NULL);
 }
 
+static void create_adhoc(GDBusProxy *proxy)
+{
+       const char *path = g_dbus_proxy_get_path(proxy);
+       struct iwd_adhoc *iwdah;
+       GSList *list;
+       char *peers = NULL;
+
+       iwdah = g_try_new0(struct iwd_adhoc, 1);
+       if (!iwdah) {
+               connman_error("Out of memory creating IWD ad-hoc");
+               return;
+       }
+
+       iwdah->path = g_strdup(path);
+       g_hash_table_replace(adhocs, iwdah->path, iwdah);
+
+       iwdah->proxy = g_dbus_proxy_ref(proxy);
+
+       if (!iwdah->proxy) {
+               connman_error("Cannot create IWD ah-hoc watcher %s", path);
+               g_hash_table_remove(adhocs, path);
+               return;
+       }
+
+       iwdah->connected_peers = proxy_get_strings(proxy, "ConnectedPeers");
+       iwdah->started = proxy_get_bool(proxy, "Started");
+
+       for (list = iwdah->connected_peers; list; list = list->next) {
+               char *peer = list->data;
+               char *old_peers;
+
+               if (!peers) {
+                       peers = g_strdup(peer);
+                       continue;
+               }
+
+               old_peers = peers;
+               peers = g_strconcat(peers, ",", peer, NULL);
+               g_free(old_peers);
+       }
+       DBG("peers %s started '%d'", peers, iwdah->started);
+       g_free(peers);
+
+       g_dbus_proxy_set_property_watch(iwdah->proxy,
+                       adhoc_property_change, NULL);
+}
+
 static void object_added(GDBusProxy *proxy, void *user_data)
 {
        const char *interface;
@@ -1113,6 +1204,8 @@ static void object_added(GDBusProxy *proxy, void 
*user_data)
                create_know_network(proxy);
        else if (!strcmp(interface, IWD_STATION_INTERFACE))
                create_station(proxy);
+       else if (!strcmp(interface, IWD_ADHOC_INTERFACE))
+               create_adhoc(proxy);
 }
 
 static void object_removed(GDBusProxy *proxy, void *user_data)
@@ -1141,6 +1234,8 @@ static void object_removed(GDBusProxy *proxy, void 
*user_data)
                g_hash_table_remove(known_networks, path);
        else if (!strcmp(interface, IWD_STATION_INTERFACE))
                g_hash_table_remove(stations, path);
+       else if (!strcmp(interface, IWD_ADHOC_INTERFACE))
+               g_hash_table_remove(adhocs, path);
 }
 
 static int iwd_init(void)
@@ -1164,6 +1259,9 @@ static int iwd_init(void)
        stations = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                        station_free);
 
+       adhocs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       adhoc_free);
+
        if (connman_technology_driver_register(&tech_driver) < 0) {
                connman_warn("Failed to initialize technology for IWD");
                goto out;
@@ -1209,6 +1307,9 @@ static int iwd_init(void)
        if (stations)
                g_hash_table_destroy(stations);
 
+       if (adhocs)
+               g_hash_table_destroy(adhocs);
+
        if (adapters)
                g_hash_table_destroy(adapters);
 
@@ -1226,6 +1327,7 @@ static void iwd_exit(void)
 
        g_dbus_client_unref(client);
 
+       g_hash_table_destroy(adhocs);
        g_hash_table_destroy(stations);
        g_hash_table_destroy(known_networks);
        g_hash_table_destroy(networks);
-- 
2.24.1

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

Date: Tue,  7 Jan 2020 19:51:12 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v2 05/10] iwd: Add Station API support
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

iwd exposes the Station API under the same path as the Device API. Add
the initial D-Bus parsing code to the plugin.
---
 plugins/iwd.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 94284996a6bb..b3dac13d47ae 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -43,6 +43,7 @@ static GHashTable *adapters;
 static GHashTable *devices;
 static GHashTable *networks;
 static GHashTable *known_networks;
+static GHashTable *stations;
 static bool agent_registered;
 
 #define IWD_SERVICE                    "net.connman.iwd"
@@ -52,6 +53,7 @@ static bool agent_registered;
 #define IWD_DEVICE_INTERFACE           "net.connman.iwd.Device"
 #define IWD_NETWORK_INTERFACE          "net.connman.iwd.Network"
 #define IWD_KNOWN_NETWORK_INTERFACE    "net.connman.iwd.KnownNetwork"
+#define IWD_STATION_INTERFACE          "net.connman.iwd.Station"
 
 #define IWD_AGENT_INTERFACE            "net.connman.iwd.Agent"
 #define IWD_AGENT_ERROR_INTERFACE      "net.connman.iwd.Agent.Error"
@@ -103,6 +105,14 @@ struct iwd_known_network {
        bool auto_connect;
 };
 
+struct iwd_station {
+       GDBusProxy *proxy;
+       char *path;
+       char *state;
+       char *connected_network;
+       bool scanning;
+};
+
 static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
 {
        DBusMessageIter iter;
@@ -625,6 +635,47 @@ static void network_property_change(GDBusProxy *proxy, 
const char *name,
        }
 }
 
+static void station_property_change(GDBusProxy *proxy, const char *name,
+               DBusMessageIter *iter, void *user_data)
+{
+       struct iwd_station *iwds;
+       const char *path;
+
+       path = g_dbus_proxy_get_path(proxy);
+       iwds = g_hash_table_lookup(stations, path);
+       if (!iwds)
+               return;
+
+       if (!strcmp(name, "State")) {
+               const char *state;
+
+               dbus_message_iter_get_basic(iter, &state);
+               g_free(iwds->state);
+               iwds->state = g_strdup(state);
+
+               DBG("%s state %s", path, iwds->state);
+       } else if (!strcmp(name, "ConnectedNetwork")) {
+               const char *connected_network;
+
+               g_free(iwds->connected_network);
+               if (!g_strcmp0(iwds->state, "disconnecting")) {
+                       dbus_message_iter_get_basic(iter, &connected_network);
+                       iwds->connected_network = g_strdup(connected_network);
+               } else {
+                       iwds->connected_network = NULL;
+               }
+
+               DBG("%s connected_network %s", path, iwds->connected_network);
+       } else if (!strcmp(name, "Scanning")) {
+               dbus_bool_t scanning;
+
+               dbus_message_iter_get_basic(iter, &scanning);
+               iwds->scanning = scanning;
+
+               DBG("%s scanning %d", path, iwds->scanning);
+       }
+}
+
 static void adapter_free(gpointer data)
 {
        struct iwd_adapter *iwda = data;
@@ -693,6 +744,19 @@ static void known_network_free(gpointer data)
        g_free(iwdkn);
 }
 
+static void station_free(gpointer data)
+{
+       struct iwd_station *iwds = data;
+
+       if (iwds->proxy) {
+               g_dbus_proxy_unref(iwds->proxy);
+               iwds->proxy = NULL;
+       }
+       g_free(iwds->path);
+       g_free(iwds->connected_network);
+       g_free(iwds);
+}
+
 static void create_adapter(GDBusProxy *proxy)
 {
        const char *path = g_dbus_proxy_get_path(proxy);
@@ -991,6 +1055,39 @@ static void create_know_network(GDBusProxy *proxy)
                iwdkn->last_connected_time, iwdkn->auto_connect);
 }
 
+static void create_station(GDBusProxy *proxy)
+{
+       const char *path = g_dbus_proxy_get_path(proxy);
+       struct iwd_station *iwds;
+
+       iwds = g_try_new0(struct iwd_station, 1);
+       if (!iwds) {
+               connman_error("Out of memory creating IWD station");
+               return;
+       }
+
+       iwds->path = g_strdup(path);
+       g_hash_table_replace(stations, iwds->path, iwds);
+
+       iwds->proxy = g_dbus_proxy_ref(proxy);
+
+       if (!iwds->proxy) {
+               connman_error("Cannot create IWD station watcher %s", path);
+               g_hash_table_remove(stations, path);
+               return;
+       }
+
+       iwds->state = g_strdup(proxy_get_string(proxy, "State"));
+       iwds->connected_network = g_strdup(proxy_get_string(proxy, 
"ConnectedNetwork"));
+       iwds->scanning = proxy_get_bool(proxy, "Scanning");
+
+       DBG("state '%s' connected_network %s scanning %d",
+               iwds->state, iwds->connected_network, iwds->scanning);
+
+       g_dbus_proxy_set_property_watch(iwds->proxy,
+                       station_property_change, NULL);
+}
+
 static void object_added(GDBusProxy *proxy, void *user_data)
 {
        const char *interface;
@@ -1014,6 +1111,8 @@ static void object_added(GDBusProxy *proxy, void 
*user_data)
                create_network(proxy);
        else if (!strcmp(interface, IWD_KNOWN_NETWORK_INTERFACE))
                create_know_network(proxy);
+       else if (!strcmp(interface, IWD_STATION_INTERFACE))
+               create_station(proxy);
 }
 
 static void object_removed(GDBusProxy *proxy, void *user_data)
@@ -1040,6 +1139,8 @@ static void object_removed(GDBusProxy *proxy, void 
*user_data)
                g_hash_table_remove(networks, path);
        else if (!strcmp(interface, IWD_KNOWN_NETWORK_INTERFACE))
                g_hash_table_remove(known_networks, path);
+       else if (!strcmp(interface, IWD_STATION_INTERFACE))
+               g_hash_table_remove(stations, path);
 }
 
 static int iwd_init(void)
@@ -1060,6 +1161,9 @@ static int iwd_init(void)
        known_networks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                        known_network_free);
 
+       stations = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       station_free);
+
        if (connman_technology_driver_register(&tech_driver) < 0) {
                connman_warn("Failed to initialize technology for IWD");
                goto out;
@@ -1102,6 +1206,9 @@ static int iwd_init(void)
        if (known_networks)
                g_hash_table_destroy(known_networks);
 
+       if (stations)
+               g_hash_table_destroy(stations);
+
        if (adapters)
                g_hash_table_destroy(adapters);
 
@@ -1119,6 +1226,7 @@ static void iwd_exit(void)
 
        g_dbus_client_unref(client);
 
+       g_hash_table_destroy(stations);
        g_hash_table_destroy(known_networks);
        g_hash_table_destroy(networks);
        g_hash_table_destroy(devices);
-- 
2.24.1

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

Subject: Digest Footer

_______________________________________________
connman mailing list -- [email protected]
To unsubscribe send an email to [email protected]


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

End of connman Digest, Vol 51, Issue 8
**************************************

Reply via email to