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 v2 5/7] iwd: Register technology, device and network
driver stub (Daniel Wagner)
2. [PATCH v2 6/7] iwd: Add/remove ConnMan devices (Daniel Wagner)
3. [PATCH v2 7/7] iwd: Add/remove ConnMan networks (Daniel Wagner)
----------------------------------------------------------------------
Message: 1
Date: Sat, 12 Nov 2016 22:12:33 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 5/7] iwd: Register technology, device and network
driver stub
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
plugins/iwd.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
diff --git a/plugins/iwd.c b/plugins/iwd.c
index eb13e6d4b966..cc947ded59cb 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -30,6 +30,8 @@
#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
#include <connman/dbus.h>
+#include <connman/network.h>
+#include <connman/technology.h>
#include <gdbus.h>
static DBusConnection *connection;
@@ -145,6 +147,78 @@ static bool proxy_get_bool(GDBusProxy *proxy, const char
*property)
return value;
}
+static int cm_network_probe(struct connman_network *network)
+{
+ return -EOPNOTSUPP;
+}
+
+static int cm_network_connect(struct connman_network *network)
+{
+ return -EINPROGRESS;
+}
+
+static int cm_network_disconnect(struct connman_network *network)
+{
+ return -EINPROGRESS;
+}
+
+static struct connman_network_driver network_driver = {
+ .name = "iwd",
+ .type = CONNMAN_NETWORK_TYPE_WIFI,
+ .probe = cm_network_probe,
+ .connect = cm_network_connect,
+ .disconnect = cm_network_disconnect,
+};
+
+static int cm_device_probe(struct connman_device *device)
+{
+ return -EOPNOTSUPP;
+}
+
+static void cm_device_remove(struct connman_device *device)
+{
+}
+
+static int set_device_powered(struct connman_device *device, bool powered)
+{
+ return -EINPROGRESS;
+}
+
+static int cm_device_enable(struct connman_device *device)
+{
+ return set_device_powered(device, true);
+}
+
+static int cm_device_disable(struct connman_device *device)
+{
+ return set_device_powered(device, false);
+}
+
+static struct connman_device_driver device_driver = {
+ .name = "iwd",
+ .type = CONNMAN_DEVICE_TYPE_WIFI,
+ .probe = cm_device_probe,
+ .remove = cm_device_remove,
+ .enable = cm_device_enable,
+ .disable = cm_device_disable,
+};
+
+static int cm_tech_probe(struct connman_technology *technology)
+{
+ return 0;
+}
+
+static void cm_tech_remove(struct connman_technology *technology)
+{
+}
+
+static struct connman_technology_driver tech_driver = {
+ .name = "iwd",
+ .type = CONNMAN_SERVICE_TYPE_WIFI,
+ .probe = cm_tech_probe,
+ .remove = cm_tech_remove,
+};
+
static void adapter_property_change(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
@@ -578,6 +652,24 @@ static int iwd_init(void)
networks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
network_free);
+ if (connman_technology_driver_register(&tech_driver) < 0) {
+ connman_warn("Failed to initialize technology for IWD");
+ goto out;
+ }
+
+ if (connman_device_driver_register(&device_driver) < 0) {
+ connman_warn("Failed to initialize device driver for "
+ IWD_SERVICE);
+ connman_technology_driver_unregister(&tech_driver);
+ goto out;
+ }
+
+ if (connman_network_driver_register(&network_driver) < 0) {
+ connman_technology_driver_unregister(&tech_driver);
+ connman_device_driver_unregister(&device_driver);
+ goto out;
+ }
+
client = g_dbus_client_new(connection, IWD_SERVICE, IWD_PATH);
if (!client) {
connman_warn("Failed to initialize D-Bus client for "
@@ -610,6 +702,10 @@ static int iwd_init(void)
static void iwd_exit(void)
{
+ connman_network_driver_unregister(&network_driver);
+ connman_device_driver_unregister(&device_driver);
+ connman_technology_driver_unregister(&tech_driver);
+
g_dbus_client_unref(client);
g_hash_table_destroy(networks);
--
2.7.4
------------------------------
Message: 2
Date: Sat, 12 Nov 2016 22:12:34 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 6/7] iwd: Add/remove ConnMan devices
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
plugins/iwd.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/plugins/iwd.c b/plugins/iwd.c
index cc947ded59cb..d960c7494df4 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -26,12 +26,14 @@
#include <errno.h>
#include <string.h>
#include <stdbool.h>
+#include <linux/if_ether.h>
#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
#include <connman/dbus.h>
#include <connman/network.h>
#include <connman/technology.h>
+#include <connman/inet.h>
#include <gdbus.h>
static DBusConnection *connection;
@@ -78,6 +80,8 @@ struct iwd_device {
enum iwd_device_state state;
bool powered;
bool scanning;
+
+ struct connman_device *device;
};
struct iwd_network {
@@ -147,6 +151,17 @@ static bool proxy_get_bool(GDBusProxy *proxy, const char
*property)
return value;
}
+static void address2ident(const char *address, char *ident)
+{
+ int i;
+
+ for (i = 0; i < ETH_ALEN; i++) {
+ ident[i * 2] = address[i * 3];
+ ident[i * 2 + 1] = address[i * 3 + 1];
+ }
+ ident[ETH_ALEN * 2] = '\0';
+}
+
static int cm_network_probe(struct connman_network *network)
{
return -EOPNOTSUPP;
@@ -172,6 +187,18 @@ static struct connman_network_driver network_driver = {
static int cm_device_probe(struct connman_device *device)
{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, devices);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct iwd_device *iwdd = value;
+
+ if (device == iwdd->device)
+ return 0;
+ }
+
return -EOPNOTSUPP;
}
@@ -179,8 +206,49 @@ static void cm_device_remove(struct connman_device *device)
{
}
+struct dev_cb_data {
+ char *path;
+ bool powered;
+};
+
+static void device_powered_cb(const DBusError *error, void *user_data)
+{
+ struct dev_cb_data *cbd = user_data;
+ struct iwd_device *iwdd;
+
+ iwdd = g_hash_table_lookup(devices, cbd->path);
+ if (!iwdd)
+ goto out;
+
+ if (dbus_error_is_set(error)) {
+ connman_warn("WiFi device %s not enabled %s",
+ cbd->path, error->message);
+ goto out;
+ }
+
+ connman_device_set_powered(iwdd->device, cbd->powered);
+out:
+ g_free(cbd->path);
+ g_free(cbd);
+}
+
static int set_device_powered(struct connman_device *device, bool powered)
{
+ struct iwd_device *iwdd = connman_device_get_data(device);
+ dbus_bool_t device_powered = powered;
+ struct dev_cb_data *cbd;
+
+ if (proxy_get_bool(iwdd->proxy, "Powered"))
+ return -EALREADY;
+
+ cbd = g_new(struct dev_cb_data, 1);
+ cbd->path = g_strdup(iwdd->path);
+ cbd->powered = powered;
+
+ g_dbus_proxy_set_property_basic(iwdd->proxy, "Powered",
+ DBUS_TYPE_BOOLEAN, &device_powered,
+ device_powered_cb, cbd, NULL);
+
return -EINPROGRESS;
}
@@ -219,6 +287,36 @@ static struct connman_technology_driver tech_driver = {
.remove = cm_tech_remove,
};
+static void add_device(const char *path, struct iwd_device *iwdd)
+{
+ char ident[ETH_ALEN * 2 + 1];
+
+ iwdd->device = connman_device_create("wifi", CONNMAN_DEVICE_TYPE_WIFI);
+ if (!iwdd->device)
+ return;
+
+ connman_device_set_data(iwdd->device, iwdd);
+
+ address2ident(iwdd->address, ident);
+ connman_device_set_ident(iwdd->device, ident);
+
+ if (connman_device_register(iwdd->device) < 0) {
+ g_hash_table_remove(devices, path);
+ return;
+ }
+
+ connman_device_set_powered(iwdd->device, iwdd->powered);
+}
+
+static void remove_device(struct iwd_device *iwdd)
+{
+ if (!iwdd->device)
+ return;
+
+ connman_device_unref(iwdd->device);
+ iwdd->device = NULL;
+}
+
static void adapter_property_change(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
@@ -328,6 +426,8 @@ static void device_free(gpointer data)
iwdd->proxy = NULL;
}
+ remove_device(iwdd);
+
g_free(iwdd->path);
g_free(iwdd->adapter);
g_free(iwdd->name);
@@ -422,6 +522,8 @@ static void create_device(GDBusProxy *proxy)
g_dbus_proxy_set_property_watch(iwdd->proxy,
device_property_change, NULL);
+
+ add_device(path, iwdd);
}
static void unregister_agent();
--
2.7.4
------------------------------
Message: 3
Date: Sat, 12 Nov 2016 22:12:35 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Subject: [PATCH v2 7/7] iwd: Add/remove ConnMan networks
Message-ID: <[email protected]>
From: Daniel Wagner <[email protected]>
---
plugins/iwd.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 284 insertions(+), 1 deletion(-)
diff --git a/plugins/iwd.c b/plugins/iwd.c
index d960c7494df4..37ccf93b46b7 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -91,6 +91,9 @@ struct iwd_network {
char *name;
char *type;
bool connected;
+
+ struct iwd_device *iwdd;
+ struct connman_network *network;
};
static enum iwd_device_state string2state(const char *str)
@@ -164,16 +167,133 @@ static void address2ident(const char *address, char
*ident)
static int cm_network_probe(struct connman_network *network)
{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&iter, networks);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct iwd_network *iwdn = value;
+
+ if (network == iwdn->network)
+ return 0;
+ }
+
return -EOPNOTSUPP;
}
+static void update_network_connected(struct iwd_network *iwdn)
+{
+ struct iwd_device *iwdd;
+ int index;
+
+ iwdd = g_hash_table_lookup(devices, iwdn->device);
+ if (!iwdd)
+ return;
+
+ index = connman_inet_ifindex(iwdd->name);
+ if (index < 0)
+ return;
+
+ DBG("interface name %s index %d", iwdd->name, index);
+ connman_network_set_index(iwdn->network, index);
+ connman_network_set_connected(iwdn->network, true);
+}
+
+static void update_network_disconnected(struct iwd_network *iwdn)
+{
+ DBG("interface name %s", iwdn->name);
+ connman_network_set_connectable(iwdn->network, false);
+ connman_network_set_connected(iwdn->network, false);
+}
+
+static void cm_network_connect_cb(DBusMessage *message, void *user_data)
+{
+ const char *path = user_data;
+ struct iwd_network *iwdn;
+
+ iwdn = g_hash_table_lookup(networks, path);
+ if (!iwdn)
+ return;
+
+ if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+ const char *dbus_error = dbus_message_get_error_name(message);
+
+ if (!strcmp(dbus_error, "net.connman.iwd.InProgress"))
+ return;
+
+ DBG("%s connect failed: %s", path, dbus_error);
+ connman_network_set_error(iwdn->network,
+ CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
+ return;
+ }
+
+ update_network_connected(iwdn);
+}
+
static int cm_network_connect(struct connman_network *network)
{
+ struct iwd_network *iwdn = connman_network_get_data(network);
+
+ if (!iwdn)
+ return -EINVAL;
+
+ if (!g_dbus_proxy_method_call(iwdn->proxy, "Connect",
+ NULL, cm_network_connect_cb,
+ g_strdup(iwdn->path), g_free))
+ return -EIO;
+
+ connman_network_set_connectable(iwdn->network, true);
+ connman_network_set_associating(iwdn->network, true);
+
return -EINPROGRESS;
}
+static void cm_network_disconnect_cb(DBusMessage *message, void *user_data)
+{
+ const char *path = user_data;
+ struct iwd_network *iwdn;
+
+ iwdn = g_hash_table_lookup(networks, path);
+ if (!iwdn)
+ return;
+
+ if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+ const char *dbus_error = dbus_message_get_error_name(message);
+
+ if (!strcmp(dbus_error, "net.connman.iwd.NotConnected")) {
+ /* fall through */
+ } else {
+ DBG("%s disconnect failed: %s", path, dbus_error);
+ return;
+ }
+ }
+
+ /*
+ * We end up in a tight loop in the error case. That is
+ * when we can't connect, bail out in cm_network_connect_cb() with
+ * an error.
+ */
+ if (connman_network_get_connected(iwdn->network))
+ update_network_disconnected(iwdn);
+}
+
static int cm_network_disconnect(struct connman_network *network)
{
+ struct iwd_network *iwdn = connman_network_get_data(network);
+ struct iwd_device *iwdd;
+
+ if (!iwdn)
+ return -EINVAL;
+
+ iwdd = g_hash_table_lookup(devices, iwdn->device);
+ if (!iwdd)
+ return -EIO;
+
+ if (!g_dbus_proxy_method_call(iwdd->proxy, "Disconnect",
+ NULL, cm_network_disconnect_cb, g_strdup(iwdn->path),
g_free))
+ return -EIO;
+
return -EINPROGRESS;
}
@@ -287,6 +407,130 @@ static struct connman_technology_driver tech_driver = {
.remove = cm_tech_remove,
};
+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_network *iwdn;
+
+ iwdn = g_hash_table_lookup(networks, path);
+ if (!iwdn)
+ return;
+
+ if (!iwdn->network)
+ 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, *name, *type;
+ 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, &name);
+
+ dbus_message_iter_next(&value);
+ dbus_message_iter_get_basic(&value, &signal_strength);
+
+ dbus_message_iter_next(&value);
+ dbus_message_iter_get_basic(&value, &type);
+
+ _update_signal_strength(path, signal_strength);
+
+ dbus_message_iter_next(&entry);
+ }
+}
+
+static void update_signal_strength(struct iwd_device *iwdd)
+{
+ if (!g_dbus_proxy_method_call(iwdd->proxy,
+ "GetOrderedNetworks",
+ NULL, ordered_networks_cb,
+ NULL, NULL))
+ DBG("GetOrderedNetworks() failed");
+}
+
+static void add_network(const char *path, struct iwd_network *iwdn)
+{
+ struct iwd_device *iwdd;
+ const char *identifier;
+
+ iwdd = g_hash_table_lookup(devices, iwdn->device);
+ if (!iwdd)
+ return;
+
+ identifier = strrchr(path, '/');
+ identifier++; /* strip leading slash as well */
+ iwdn->network = connman_network_create(identifier,
+ CONNMAN_NETWORK_TYPE_WIFI);
+ connman_network_set_data(iwdn->network, iwdn);
+
+ connman_network_set_name(iwdn->network, iwdn->name);
+ connman_network_set_blob(iwdn->network, "WiFi.SSID", iwdn->name,
+ strlen(iwdn->name));
+ connman_network_set_string(iwdn->network, "WiFi.Security",
+ iwdn->type);
+
+ if (connman_device_add_network(iwdd->device, iwdn->network) < 0) {
+ connman_network_unref(iwdn->network);
+ iwdn->network = NULL;
+ return;
+ }
+ iwdn->iwdd = iwdd;
+
+ connman_network_set_available(iwdn->network, true);
+ connman_network_set_group(iwdn->network, identifier);
+}
+
+static void remove_network(struct iwd_network *iwdn)
+{
+ if (!iwdn->network)
+ return;
+
+ if (iwdn->iwdd)
+ connman_device_remove_network(iwdn->iwdd->device,
+ iwdn->network);
+
+ connman_network_unref(iwdn->network);
+ iwdn->network = NULL;
+}
+
static void add_device(const char *path, struct iwd_device *iwdd)
{
char ident[ETH_ALEN * 2 + 1];
@@ -308,11 +552,37 @@ static void add_device(const char *path, struct
iwd_device *iwdd)
connman_device_set_powered(iwdd->device, iwdd->powered);
}
+static void remove_device_networks(struct iwd_device *iwdd)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ struct iwd_network *iwdn;
+ GSList *list, *nets = NULL;
+
+ g_hash_table_iter_init(&iter, networks);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ iwdn = value;
+
+ if (!strcmp(iwdd->path, iwdn->device))
+ nets = g_slist_prepend(nets, iwdn);
+ }
+
+ for (list = nets; list; list = list->next) {
+ iwdn = list->data;
+ g_hash_table_remove(networks, iwdn->path);
+ }
+
+ g_slist_free(nets);
+}
+
static void remove_device(struct iwd_device *iwdd)
{
if (!iwdd->device)
return;
+ remove_device_networks(iwdd);
+ connman_device_unregister(iwdd->device);
connman_device_unref(iwdd->device);
iwdd->device = NULL;
}
@@ -378,6 +648,10 @@ static void device_property_change(GDBusProxy *proxy,
const char *name,
iwdd->scanning = scanning;
DBG("%s scanning %d", path, iwdd->scanning);
+
+ if (!iwdd->scanning)
+ update_signal_strength(iwdd);
+
}
}
@@ -399,6 +673,11 @@ static void network_property_change(GDBusProxy *proxy,
const char *name,
iwdn->connected = connected;
DBG("%s connected %d", path, iwdn->connected);
+
+ if (iwdn->connected)
+ update_network_connected(iwdn);
+ else
+ update_network_disconnected(iwdn);
}
}
@@ -444,6 +723,8 @@ static void network_free(gpointer data)
iwdn->proxy = NULL;
}
+ remove_network(iwdn);
+
g_free(iwdn->path);
g_free(iwdn->device);
g_free(iwdn->name);
@@ -562,7 +843,7 @@ static DBusMessage *agent_request_passphrase(DBusConnection
*dbus_conn,
if (!iwdn)
return get_reply_on_error(message, EINVAL);
- passwd = "mysecret";
+ passwd = connman_network_get_string(iwdn->network, "WiFi.Passphrase");
return g_dbus_create_reply(message, DBUS_TYPE_STRING, &passwd,
DBUS_TYPE_INVALID);
@@ -690,6 +971,8 @@ static void create_network(GDBusProxy *proxy)
g_dbus_proxy_set_property_watch(iwdn->proxy,
network_property_change, NULL);
+
+ add_network(path, iwdn);
}
static void object_added(GDBusProxy *proxy, void *user_data)
--
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 20
***************************************