summaryrefslogtreecommitdiff
path: root/plugins/bluetooth.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/bluetooth.c')
-rw-r--r--plugins/bluetooth.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 82217d03..45cc3194 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -36,7 +36,9 @@
#define BLUEZ_SERVICE "org.bluez"
#define BLUEZ_PATH "/org/bluez"
+#define BLUETOOTH_PAN_PANU "00001115-0000-1000-8000-00805f9b34fb"
#define BLUETOOTH_PAN_NAP "00001116-0000-1000-8000-00805f9b34fb"
+#define BLUETOOTH_PAN_GN "00001117-0000-1000-8000-00805f9b34fb"
#define BLUETOOTH_ADDR_LEN 6
@@ -50,6 +52,7 @@ struct bluetooth_pan {
struct connman_network *network;
GDBusProxy *btdevice_proxy;
GDBusProxy *btnetwork_proxy;
+ const char *pan_role;
};
static void address2ident(const char *address, char *ident)
@@ -85,28 +88,37 @@ static bool proxy_get_bool(GDBusProxy *proxy, const char *property)
return value;
}
-static bool proxy_get_nap(GDBusProxy *proxy)
+static const char *proxy_get_role(GDBusProxy *proxy)
{
- DBusMessageIter iter, value;
+ DBusMessageIter iter, value;
+ const char *pref = NULL;
if (!proxy)
- return false;
+ return NULL;
if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter))
- return false;
+ return NULL;
dbus_message_iter_recurse(&iter, &value);
while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
const char *uuid;
- dbus_message_iter_get_basic(&value, &uuid);
- if (strcmp(uuid, BLUETOOTH_PAN_NAP) == 0)
- return true;
+ dbus_message_iter_get_basic(&value, &uuid);
+ /*
+ * If a device offers more than one role, we prefer NAP,
+ * then GN, then PANU.
+ */
+ if (!strcmp(uuid, BLUETOOTH_PAN_NAP))
+ return "nap";
+ if (!strcmp(uuid, BLUETOOTH_PAN_GN))
+ pref = "gn";
+ if (!strcmp(uuid, BLUETOOTH_PAN_PANU) && !pref)
+ pref = "panu";
dbus_message_iter_next(&value);
}
- return false;
+ return pref;
}
static int bluetooth_pan_probe(struct connman_network *network)
@@ -225,9 +237,11 @@ static void pan_connect_cb(DBusMessage *message, void *user_data)
static void pan_connect_append(DBusMessageIter *iter,
void *user_data)
{
- const char *role = BLUETOOTH_PAN_NAP;
+ const char *path = user_data;
+ struct bluetooth_pan *pan;
- dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &role);
+ pan = g_hash_table_lookup(networks, path);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &pan->pan_role);
}
static int bluetooth_pan_connect(struct connman_network *network)
@@ -322,8 +336,10 @@ static void btnetwork_property_change(GDBusProxy *proxy, const char *name,
static void pan_create_nap(struct bluetooth_pan *pan)
{
struct connman_device *device;
+ const char* role;
- if (!proxy_get_nap(pan->btdevice_proxy)) {
+ role = proxy_get_role(pan->btdevice_proxy);
+ if (!role) {
pan_remove_nap(pan);
return;
}
@@ -366,6 +382,7 @@ static void pan_create_nap(struct bluetooth_pan *pan)
connman_network_set_group(pan->network, ident);
}
+ pan->pan_role = role;
connman_device_add_network(device, pan->network);
if (pan_connect(pan, NULL))
@@ -376,9 +393,10 @@ static void btdevice_property_change(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
struct bluetooth_pan *pan;
- bool pan_nap = false;
+ const char *old_role = NULL;
+ const char *new_role;
- if (strcmp(name, "UUIDs") != 0)
+ if (strcmp(name, "UUIDs"))
return;
pan = g_hash_table_lookup(networks, g_dbus_proxy_get_path(proxy));
@@ -387,12 +405,13 @@ static void btdevice_property_change(GDBusProxy *proxy, const char *name,
if (pan->network &&
connman_network_get_device(pan->network))
- pan_nap = true;
+ old_role = pan->pan_role;
+ new_role = proxy_get_role(pan->btdevice_proxy);
- DBG("network %p network nap %d proxy nap %d", pan->network, pan_nap,
- proxy_get_nap(pan->btdevice_proxy));
+ DBG("network %p network role %s proxy role %s", pan->network, old_role,
+ new_role);
- if (proxy_get_nap(pan->btdevice_proxy) == pan_nap)
+ if (old_role && new_role && !strcmp(old_role, new_role))
return;
pan_create_nap(pan);
@@ -447,7 +466,7 @@ static void pan_create(GDBusProxy *network_proxy)
g_dbus_proxy_set_property_watch(pan->btdevice_proxy,
btdevice_property_change, NULL);
- DBG("pan %p %s nap %d", pan, path, proxy_get_nap(pan->btdevice_proxy));
+ DBG("pan %p %s role %s", pan, path, proxy_get_role(pan->btdevice_proxy));
pan_create_nap(pan);
}
@@ -756,7 +775,7 @@ static void device_create(GDBusProxy *proxy)
powered = proxy_get_bool(proxy, "Powered");
connman_device_set_powered(device, powered);
- if (proxy_get_nap(proxy) && !bluetooth_tethering)
+ if (proxy_get_role(proxy) && !bluetooth_tethering)
tethering_create(path, NULL, NULL, false);
}
@@ -880,7 +899,7 @@ static int bluetooth_tech_set_tethering(struct connman_technology *technology,
if (i == 0)
return -ENODEV;
- return -EINPROGRESS;
+ return 0;
}
static struct connman_technology_driver tech_driver = {
@@ -957,6 +976,8 @@ static void bluetooth_exit(void)
*/
device_driver.disable = NULL;
+ g_dbus_client_unref(client);
+
connman_network_driver_unregister(&network_driver);
g_hash_table_destroy(networks);