2015-01-15 03:52:13

by Arman Uguray

[permalink] [raw]
Subject: [PATCH BlueZ 1/3] core: device: Fix connect bearer selection

For dual-mode devices created from storage, trying to connect without
a scan sometimes causes the incorrect bearer to be connected. This
patch modifies device.c:select_conn_bearer so that it simply returns the
stored bdaddr_type of a device if neither bredr nor le have been seen
in a while.
---
src/device.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/src/device.c b/src/device.c
index 1e13565..b5c19dd 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1537,6 +1537,9 @@ static uint8_t select_conn_bearer(struct btd_device *dev)
le_last = NVAL_TIME;
}

+ if (le_last == NVAL_TIME && bredr_last == NVAL_TIME)
+ return dev->bdaddr_type;
+
if (dev->bredr && (!dev->le || le_last == NVAL_TIME))
return BDADDR_BREDR;

--
2.2.0.rc0.207.ga3a616c



2015-01-15 20:11:34

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/3] core: device: Fix connect bearer selection

Hi Arman,

On Wed, Jan 14, 2015, Arman Uguray wrote:
> For dual-mode devices created from storage, trying to connect without
> a scan sometimes causes the incorrect bearer to be connected. This
> patch modifies device.c:select_conn_bearer so that it simply returns the
> stored bdaddr_type of a device if neither bredr nor le have been seen
> in a while.
> ---
> src/device.c | 3 +++
> 1 file changed, 3 insertions(+)

All three patches in this set have been applied. Thanks.

Johan

2015-01-15 03:52:15

by Arman Uguray

[permalink] [raw]
Subject: [PATCH BlueZ 3/3] core: adapter: Fix device name setting

This patch fixes adapter.c:connected_callback so that it only sets the
device name based on the complete local name EIR data, if the device
already has a known name.
---
src/adapter.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/adapter.c b/src/adapter.c
index d7e2550..1839286 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -6672,6 +6672,7 @@ static void connected_callback(uint16_t index, uint16_t length,
struct eir_data eir_data;
uint16_t eir_len;
char addr[18];
+ bool name_known;

if (length < sizeof(*ev)) {
error("Too small device connected event");
@@ -6704,7 +6705,9 @@ static void connected_callback(uint16_t index, uint16_t length,

adapter_add_connection(adapter, device, ev->addr.type);

- if (eir_data.name != NULL) {
+ name_known = device_name_known(device);
+
+ if (eir_data.name && (eir_data.name_complete || !name_known)) {
device_store_cached_name(device, eir_data.name);
btd_device_device_set_name(device, eir_data.name);
}
--
2.2.0.rc0.207.ga3a616c


2015-01-15 03:52:14

by Arman Uguray

[permalink] [raw]
Subject: [PATCH BlueZ 2/3] core: device: Fix device_browse_gatt

This patch fixes an issue that occurs in device.c:device_browse_gatt
when an ATT data connection already exists. This patch solves the
following problems:

1. In the case when services are already discovered, the old code
re-probed all profiles which caused crashes.
2. In the case when services are already discovered, the old code
never actually resolved the browse request when initiated from
an outgoing bonding request. This caused, for example, a D-Bus
call to Pair to receive no response.
---
src/device.c | 39 ++++++++++++++++-----------------------
1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/device.c b/src/device.c
index b5c19dd..f73a082 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4232,29 +4232,9 @@ static void att_browse_error_cb(const GError *gerr, gpointer user_data)
browse_request_free(req);
}

-static void browse_gatt_client(struct browse_req *req)
-{
- struct btd_device *device = req->device;
-
- if (!device->client) {
- DBG("No instance currently attached");
- return;
- }
-
- /*
- * If gatt-client is ready, then register all services. Otherwise, this
- * will be deferred until client becomes ready.
- */
- if (bt_gatt_client_is_ready(device->client))
- register_gatt_services(req);
-}
-
static void att_browse_cb(gpointer user_data)
{
- struct att_callbacks *attcb = user_data;
- struct btd_device *device = attcb->user_data;
-
- browse_gatt_client(device->browse);
+ DBG("ATT connection successful");
}

static int device_browse_gatt(struct btd_device *device, DBusMessage *msg)
@@ -4272,8 +4252,21 @@ static int device_browse_gatt(struct btd_device *device, DBusMessage *msg)
device->browse = req;

if (device->attrib) {
- browse_gatt_client(device->browse);
- goto done;
+ /*
+ * If discovery has not yet completed, then wait for gatt-client
+ * to become ready.
+ */
+ if (!device->le_state.svc_resolved)
+ goto done;
+
+ /*
+ * Services have already been discovered, so signal this browse
+ * request as resolved.
+ */
+ device_svc_resolved(device, device->bdaddr_type, 0);
+ device->browse = NULL;
+ browse_request_free(req);
+ return 0;
}

attcb = g_new0(struct att_callbacks, 1);
--
2.2.0.rc0.207.ga3a616c