linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services
@ 2019-03-18 16:19 Luiz Augusto von Dentz
  2019-03-18 16:19 ` [PATCH BlueZ 2/3] shared/gatt-client: Fix failing to discover included attributes Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2019-03-18 16:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 1119d1a34..ec1041f66 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -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:
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ 2/3] shared/gatt-client: Fix failing to discover included attributes
  2019-03-18 16:19 [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
@ 2019-03-18 16:19 ` Luiz Augusto von Dentz
  2019-03-18 16:19 ` [PATCH BlueZ 3/3] shared/gatt-db: Remove update_attribute Luiz Augusto von Dentz
  2019-03-19  8:44 ` [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2019-03-18 16:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(+)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index ec1041f66..858209c24 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ 3/3] shared/gatt-db: Remove update_attribute
  2019-03-18 16:19 [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
  2019-03-18 16:19 ` [PATCH BlueZ 2/3] shared/gatt-client: Fix failing to discover included attributes Luiz Augusto von Dentz
@ 2019-03-18 16:19 ` Luiz Augusto von Dentz
  2019-03-19  8:44 ` [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2019-03-18 16:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index bdce3da47..b5f7094da 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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 *
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services
  2019-03-18 16:19 [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
  2019-03-18 16:19 ` [PATCH BlueZ 2/3] shared/gatt-client: Fix failing to discover included attributes Luiz Augusto von Dentz
  2019-03-18 16:19 ` [PATCH BlueZ 3/3] shared/gatt-db: Remove update_attribute Luiz Augusto von Dentz
@ 2019-03-19  8:44 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2019-03-19  8:44 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Mon, Mar 18, 2019 at 6:19 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> 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(-)
>
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 1119d1a34..ec1041f66 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -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:
> --
> 2.20.1
>

Applied.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-19  8:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 16:19 [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz
2019-03-18 16:19 ` [PATCH BlueZ 2/3] shared/gatt-client: Fix failing to discover included attributes Luiz Augusto von Dentz
2019-03-18 16:19 ` [PATCH BlueZ 3/3] shared/gatt-db: Remove update_attribute Luiz Augusto von Dentz
2019-03-19  8:44 ` [PATCH BlueZ 1/3] shared/gatt-client: Add debug for error with included services Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).