Once a Bluetooth adapter changes its Powered property, PAN networks
need to be created or removed. Factor out device and PAN creation
and removal in order to call it when the adapter changes or the
device is enabled or disabled. PAN network creation and removal
needs to be done explicitely, as the Bluetooth adapter has already
changed state and thus the bluetooth plugin will not make a D-Bus
call to Bluez nor to the callback where network enabling and
disabling happens.
Thanks to Krzysztof Wilk for reporting the issue.
---
plugins/bluetooth.c | 79 +++++++++++++++++++++++++++++++----------------------
1 file changed, 47 insertions(+), 32 deletions(-)
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index ae3ac60..82217d0 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -461,27 +461,12 @@ static struct connman_network_driver network_driver = {
.disconnect = bluetooth_pan_disconnect,
};
-static void device_enable_cb(const DBusError *error, void *user_data)
+static void enable_device(struct connman_device *device, const char *path)
{
- char *path = user_data;
- struct connman_device *device;
GHashTableIter iter;
gpointer key, value;
- device = g_hash_table_lookup(devices, path);
- if (!device) {
- DBG("device already removed");
- goto out;
- }
-
- if (dbus_error_is_set(error)) {
- connman_warn("Bluetooth device %s not enabled %s",
- path, error->message);
- goto out;
- }
-
DBG("device %p %s", device, path);
-
connman_device_set_powered(device, true);
g_hash_table_iter_init(&iter, networks);
@@ -495,7 +480,26 @@ static void device_enable_cb(const DBusError *error, void
*user_data)
pan_create_nap(pan);
}
}
+}
+static void device_enable_cb(const DBusError *error, void *user_data)
+{
+ char *path = user_data;
+ struct connman_device *device;
+
+ device = g_hash_table_lookup(devices, path);
+ if (!device) {
+ DBG("device already removed");
+ goto out;
+ }
+
+ if (dbus_error_is_set(error)) {
+ connman_warn("Bluetooth device %s not enabled %s",
+ path, error->message);
+ goto out;
+ }
+
+ enable_device(device, path);
out:
g_free(path);
}
@@ -525,12 +529,30 @@ static int bluetooth_device_enable(struct connman_device
*device)
return -EINPROGRESS;
}
+static void disable_device(struct connman_device *device, const char *path)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ DBG("device %p %s", device, path);
+ connman_device_set_powered(device, false);
+
+ g_hash_table_iter_init(&iter, networks);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct bluetooth_pan *pan = value;
+
+ if (pan->network && connman_network_get_device(pan->network)
+ == device) {
+ DBG("disable network %p", pan->network);
+ connman_device_remove_network(device, pan->network);
+ }
+ }
+}
+
static void device_disable_cb(const DBusError *error, void *user_data)
{
char *path = user_data;
struct connman_device *device;
- GHashTableIter iter;
- gpointer key, value;
device = g_hash_table_lookup(devices, path);
if (!device) {
@@ -544,18 +566,7 @@ static void device_disable_cb(const DBusError *error, void
*user_data)
goto out;
}
- DBG("device %p %s", device, path);
- connman_device_set_powered(device, false);
-
- g_hash_table_iter_init(&iter, networks);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- struct bluetooth_pan *pan = value;
-
- if (pan->network && connman_network_get_device(pan->network) ==
device) {
- DBG("disable network %p", pan->network);
- connman_device_remove_network(device, pan->network);
- }
- }
+ disable_device(device, path);
out:
g_free(path);
@@ -605,8 +616,12 @@ static void adapter_property_change(GDBusProxy *proxy,
const char *name,
DBG("device %p %s device powered %d adapter powered %d", device, path,
device_powered, adapter_powered);
- if (device_powered != adapter_powered)
- connman_device_set_powered(device, adapter_powered);
+ if (device_powered != adapter_powered) {
+ if (adapter_powered)
+ enable_device(device, path);
+ else
+ disable_device(device, path);
+ }
}
static void device_free(gpointer data)
--
1.8.5.3
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman