Skip to contentSkip to conversation

shared/gatt-client: Add debug for error with included services

PATCH Applied Luiz Augusto von Dentz 1 participant 4 messages Mar 18, 2019 – Mar 19, 2019 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/3 shared/gatt-client: Add debug for error with included services

From: Luiz Augusto von Dentz <[email protected]>

This logs errors with included service so it is easier to noticed when they are malformed.

---
 src/shared/gatt-client.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
src/shared/gatt-client.c +14 -3
index 1119d1a34..ec1041f66 100644
@@ -532,12 +532,19 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
 				"uuid: %s", handle, start, end, uuid_str);
 
 		attr = gatt_db_get_attribute(client->db, start);
-		if (!attr)
+		if (!attr) {
+			util_debug(client->debug_callback, client->debug_data,
+				"Unable to find attribute at 0x%04x", start);
 			goto failed;
+		}
 
 		attr = gatt_db_insert_included(client->db, handle, attr);
-		if (!attr)
+		if (!attr) {
+			util_debug(client->debug_callback, client->debug_data,
+				"Unable to add include attribute at 0x%04x",
+				handle);
 			goto failed;
+		}
 
 		/*
 		 * GATT requires that all include definitions precede
@@ -545,8 +552,12 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
 		 * these entries, the correct handle must be assigned to the new
 		 * attribute.
 		 */
-		if (gatt_db_attribute_get_handle(attr) != handle)
+		if (gatt_db_attribute_get_handle(attr) != handle) {
+			util_debug(client->debug_callback, client->debug_data,
+				"Invalid attribute 0x%04x expect it at 0x%04x",
+				gatt_db_attribute_get_handle(attr), handle);
 			goto failed;
+		}
 	}
 
 next:
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/3 shared/gatt-client: Fix failing to discover included attributes

From: Luiz Augusto von Dentz <[email protected]>

When there exists a included service a descriptor may already exists in the handle location so instead of failing check if the UUID matches and then skip to the next descriptor.

---
 src/shared/gatt-client.c | 5 +++++
 1 file changed, 5 insertions(+)
src/shared/gatt-client.c +5 -0
index ec1041f66..858209c24 100644
@@ -815,6 +815,11 @@ static void discover_descs_cb(bool success, uint8_t att_ecode,
 							&uuid, 0, NULL, NULL,
 							NULL);
 		if (!attr) {
+			attr = gatt_db_get_attribute(client->db, handle);
+			if (attr && !bt_uuid_cmp(&uuid,
+					gatt_db_attribute_get_type(attr)))
+				continue;
+
 			util_debug(client->debug_callback, client->debug_data,
 				"Failed to insert descriptor at 0x%04x",
 				handle);
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 3/3 shared/gatt-db: Remove update_attribute

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

It is not longer needed to access the last attribute handle to figure out its attribute since the handle is either passed directly or the db->last_handle is used.

---
 src/shared/gatt-db.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
src/shared/gatt-db.c +3 -16
index bdce3da47..b5f7094da 100644
@@ -776,20 +776,6 @@ static uint16_t get_handle_at_index(struct gatt_db_service *service,
 	return service->attributes[index]->handle;
 }
 
-static struct gatt_db_attribute *
-attribute_update(struct gatt_db_service *service, int index)
-{
-	uint16_t previous_handle;
-
-	/* We call this function with index > 0, because index 0 is reserved
-	 * for service declaration, and is set in add_service()
-	 */
-	previous_handle = service->attributes[index - 1]->handle;
-	service->attributes[index]->handle = previous_handle + 1;
-
-	return service->attributes[index];
-}
-
 static struct gatt_db_attribute *
 service_insert_characteristic(struct gatt_db_service *service,
 					uint16_t handle,
@@ -1054,9 +1040,10 @@ service_insert_included(struct gatt_db_service *service, uint16_t handle,
 	 *
 	 * TODO handle permissions
 	 */
-	set_attribute_data(service->attributes[index], NULL, NULL, BT_ATT_PERM_READ, NULL);
+	set_attribute_data(service->attributes[index], NULL, NULL,
+					BT_ATT_PERM_READ, NULL);
 
-	return attribute_update(service, index);
+	return service->attributes[index];
 }
 
 struct gatt_db_attribute *
Signature · 1 line
2.20.1
author maintainer Applied
#3 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 50 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This logs errors with included service so it is easier to noticed when they are malformed.

---
 src/shared/gatt-client.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
src/shared/gatt-client.c +14 -4
index 1119d1a34..ec1041f66 100644
@@ -532,12 +532,19 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
                                "uuid: %s", handle, start, end, uuid_str);
 
                attr = gatt_db_get_attribute(client->db, start);
-               if (!attr)
+               if (!attr) {
+                       util_debug(client->debug_callback, client->debug_data,
+                               "Unable to find attribute at 0x%04x", start);
                        goto failed;
+               }
 
                attr = gatt_db_insert_included(client->db, handle, attr);
-               if (!attr)
+               if (!attr) {
+                       util_debug(client->debug_callback, client->debug_data,
+                               "Unable to add include attribute at 0x%04x",
+                               handle);
                        goto failed;
+               }
 
                /*
                 * GATT requires that all include definitions precede
@@ -545,8 +552,12 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
                 * these entries, the correct handle must be assigned to the new
                 * attribute.
                 */
-               if (gatt_db_attribute_get_handle(attr) != handle)
+               if (gatt_db_attribute_get_handle(attr) != handle) {
+                       util_debug(client->debug_callback, client->debug_data,
+                               "Invalid attribute 0x%04x expect it at 0x%04x",
+                               gatt_db_attribute_get_handle(attr), handle);
                        goto failed;
+               }
        }
 
 next:
--
Quoted 2 lines

2.20.1

Applied.

Signature · 1 line
Luiz Augusto von Dentz