Re: [PATCH BlueZ 5/5] shared/gatt-client: Fix service discovery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andrejs,

On Thu, Mar 19, 2015 at 12:17 PM, Luiz Augusto von Dentz
<luiz.dentz@xxxxxxxxx> wrote:
> Hi Andrejs,
>
> On Thu, Mar 19, 2015 at 9:36 AM, Andrejs Hanins <andrejs.hanins@xxxxxxxx> wrote:
>> Hi Luiz
>>
>> On 2015.03.18. 23:04, Luiz Augusto von Dentz wrote:
>>> From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
>>>
>>> The code should proceed to discover all descriptors before moving to
>>> next service otherwise it may attempt to insert characteristics in the
>>> wrong service which would probably fail.
>>> ---
>>>  src/shared/gatt-client.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
>>> index 3e28c6e..729bd87 100644
>>> --- a/src/shared/gatt-client.c
>>> +++ b/src/shared/gatt-client.c
>>> @@ -690,13 +690,13 @@ static void discover_descs_cb(bool success, uint8_t att_ecode,
>>>                       goto failed;
>>>       }
>>>
>>> +next:
>>>       if (!discover_descs(op, &discovering))
>>>               goto failed;
>>>
>>>       if (discovering)
>>>               return;
>>>
>>> -next:
>>>       /* Done with the current service */
>>>       gatt_db_service_set_active(op->cur_svc, true);
>>>
>>>
>>
>> I tested this new patch-set and and results are the following:
>> 1. Three characteristics (GAP, GATT and custom) do appear on D-BUs. This was not the case before.
>> 2. CCC descriptor still does not appear on D-Bus. If I change handles on the peripheral back to sequential, then CCC appears on D-Bus also.
>> 3. Reading of any characteristic times out with 'g-io-error-quark: Timeout was reached (24)'. Logs attached. Based on HCI dumps the ATT reading is OK, but for some reason result is not propagated to the D-Bus level, so D-Dbus method times out. With sequential handles reading works fine.
>
> Strange for me it is working normally:
>
> [NEW] Service /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011
> Battery Service (Primary)
> [NEW] Characteristic
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012 Battery
> Level
> [NEW] Descriptor
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012/desc0014
> Client Characteristic Configuration
> [Arc Touch Mouse SE]# select-attribute
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012
> [Arc Touch Mouse SE:/service0011/char0012]# read
> Attempting to read /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012
> [CHG] Attribute
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012 Value: 0x5d
>   5d                                               ]
> [Arc Touch Mouse SE:/service0011/char0012]# select-attribute
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012/desc0014
> [Arc Touch Mouse SE:/service0011/char0012/desc0014]# read
> Attempting to read
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012/desc0014
> [CHG] Attribute
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012/desc0014
> Value: 0x00
> [CHG] Attribute
> /org/bluez/hci0/dev_F3_43_74_B7_86_24/service0011/char0012/desc0014
> Value: 0x00
>   00 00
>
> But perhaps this is because the handles are in sequence as you said,
> can you try with the following changes:
>
> http://fpaste.org/199962/67601931/

See if the attachment works.


-- 
Luiz Augusto von Dentz
From dbad03bf1432f1eec3260f6db77c08aca58e2575 Mon Sep 17 00:00:00 2001
From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
Date: Thu, 19 Mar 2015 12:52:47 +0200
Subject: [PATCH BlueZ] core/gatt: Fix not replying if db operation fail

---
 src/gatt-client.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index a85b9d2..80b9f47 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -778,20 +778,19 @@ static void chrc_read_cb(bool success, uint8_t att_ecode, const uint8_t *value,
 	struct async_dbus_op *op = user_data;
 	struct characteristic *chrc = op->data;
 	struct service *service = chrc->service;
+	DBusMessage *reply;
 
-	if (!success) {
-		DBusMessage *reply = create_gatt_dbus_error(op->msg, att_ecode);
-
-		chrc->read_id = 0;
-		g_dbus_send_message(btd_get_dbus_connection(), reply);
-		return ;
-	}
+	if (!success)
+		goto fail;
 
 	if (!op->offset)
 		gatt_db_attribute_reset(chrc->attr);
 
-	gatt_db_attribute_write(chrc->attr, op->offset, value, length, 0, NULL,
-						write_characteristic_cb, chrc);
+	if (!gatt_db_attribute_write(chrc->attr, op->offset, value, length, 0,
+					NULL, write_characteristic_cb, chrc)) {
+		error("Failed to store attribute");
+		goto fail;
+	}
 
 	/*
 	 * If the value length is exactly MTU-1, then we may not have read the
@@ -814,7 +813,17 @@ static void chrc_read_cb(bool success, uint8_t att_ecode, const uint8_t *value,
 	chrc->read_id = 0;
 
 	/* Read the stored data from db */
-	gatt_db_attribute_read(chrc->attr, 0, 0, NULL, read_op_cb, op);
+	if (!gatt_db_attribute_read(chrc->attr, 0, 0, NULL, read_op_cb, op)) {
+		error("Failed to read database");
+		goto fail;
+	}
+
+	return;
+
+fail:
+	reply = create_gatt_dbus_error(op->msg, att_ecode);
+	chrc->read_id = 0;
+	g_dbus_send_message(btd_get_dbus_connection(), reply);
 }
 
 static DBusMessage *characteristic_read_value(DBusConnection *conn,
-- 
2.1.0


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux