From 905032851aa912dc0ca1b78de8065cd2989ce45e Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 29 Jan 2013 17:13:36 -0600 Subject: [PATCH] core: Move connect_list handling to ATT specific callbacks This is more reliable since we're not always guaranteed to get the right mgmt events, e.g. a socket connect timeout might not trigger those. --- src/adapter.c | 24 ------------------------ src/device.c | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 11be7b58c..805a80ae9 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -4996,11 +4996,6 @@ static void dev_disconnected(struct btd_adapter *adapter, bonding_complete(adapter, &addr->bdaddr, addr->type, MGMT_STATUS_DISCONNECTED); - - /* If this device should be connected through passive scanning - * add it back to the connect_list */ - if (device && device_get_auto_connect(device)) - adapter_connect_list_add(adapter, device); } static void disconnect_complete(uint8_t status, uint16_t length, @@ -5583,19 +5578,6 @@ static void connected_callback(uint16_t index, uint16_t length, } eir_data_free(&eir_data); - - /* - * If this was an LE device being connected through passive - * scanning remove the device from the connect_list and give the - * passive scanning another chance to be restarted in case - * there are other devices in the connect_list. - */ - if (device == adapter->connect_le) { - adapter->connect_le = NULL; - adapter->connect_list = g_slist_remove(adapter->connect_list, - device); - trigger_passive_scanning(adapter); - } } static void device_blocked_callback(uint16_t index, uint16_t length, @@ -5663,12 +5645,6 @@ static void connect_failed_callback(uint16_t index, uint16_t length, device_bonding_failed(device, ev->status); if (device_is_temporary(device)) adapter_remove_device(adapter, device, TRUE); - if (device_is_le(device)) { - if (device == adapter->connect_le) - adapter->connect_le = NULL; - if (device_get_auto_connect(device)) - adapter_connect_list_add(adapter, device); - } } /* In the case of security mode 3 devices */ diff --git a/src/device.c b/src/device.c index c13e2d065..bd0ee759e 100644 --- a/src/device.c +++ b/src/device.c @@ -2934,7 +2934,7 @@ static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond, g_slist_foreach(device->attios, attio_disconnected, NULL); - if (device->auto_connect == FALSE) { + if (!device_get_auto_connect(device)) { DBG("Automatic connection disabled"); goto done; } @@ -3155,11 +3155,10 @@ static void att_error_cb(const GError *gerr, gpointer user_data) if (g_error_matches(gerr, BT_IO_ERROR, ECONNABORTED)) return; - if (device->auto_connect == FALSE) - return; - - adapter_connect_list_add(device->adapter, device); - DBG("Enabling automatic connections"); + if (device_get_auto_connect(device)) { + DBG("Enabling automatic connections"); + adapter_connect_list_add(device->adapter, device); + } } static void att_success_cb(gpointer user_data) @@ -3170,6 +3169,13 @@ static void att_success_cb(gpointer user_data) if (device->attios == NULL) return; + /* + * Remove the device from the connect_list and give the passive + * scanning another chance to be restarted in case there are + * other devices in the connect_list. + */ + adapter_connect_list_remove(device->adapter, device); + g_slist_foreach(device->attios, attio_connected, device->attrib); } -- 2.47.3