All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails
@ 2022-03-14 21:50 Luiz Augusto von Dentz
  2022-03-14 21:50 ` [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-03-14 21:50 UTC (permalink / raw)
  To: linux-bluetooth

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

This prints an error if gatt_db_attribut_notify fails.
---
 src/gatt-database.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 485af04ea..d6c94058c 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1523,8 +1523,9 @@ static void send_service_changed(struct btd_gatt_database *database,
 	put_le16(start, value);
 	put_le16(end, value + 2);
 
-	gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value),
-				NULL);
+	if (!gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value),
+								NULL))
+		error("Failed to notify Service Changed");
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -3967,6 +3968,7 @@ void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database)
 	put_le16(0x0001, value);
 	put_le16(0xffff, value + 2);
 
-	gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value),
-				NULL);
+	if (!gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value),
+								NULL))
+		error("Failed to notify Service Changed");
 }
-- 
2.35.1


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

* [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify
  2022-03-14 21:50 [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails Luiz Augusto von Dentz
@ 2022-03-14 21:50 ` Luiz Augusto von Dentz
  2022-03-14 23:40 ` [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails patchwork-bot+bluetooth
  2022-03-15  0:15 ` [BlueZ,1/2] " bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-03-14 21:50 UTC (permalink / raw)
  To: linux-bluetooth

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

gatt_db_attribute_notify was only accepting passing the Characteristic
Declaration instead of accepting its value as well,
gatt_db_service_foreach_desc also have similar limitation so both have
been updated to allow working with both value and declaration.
---
 src/shared/gatt-db.c | 63 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 51 insertions(+), 12 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 53d3e1243..be07cdbe4 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1528,32 +1528,71 @@ void gatt_db_service_foreach_char(struct gatt_db_attribute *attrib,
 	gatt_db_service_foreach(attrib, &characteristic_uuid, func, user_data);
 }
 
+static int gatt_db_attribute_get_index(struct gatt_db_attribute *attrib)
+{
+	struct gatt_db_service *service;
+	int index;
+
+	if (!attrib)
+		return -1;
+
+	service = attrib->service;
+	index = attrib->handle - service->attributes[0]->handle;
+
+	if (index > (service->num_handles - 1))
+		return -1;
+
+	return index;
+}
+
+static struct gatt_db_attribute *
+gatt_db_attribute_get_value(struct gatt_db_attribute *attrib)
+{
+	struct gatt_db_service *service;
+	int index;
+
+	if (!attrib)
+		return NULL;
+
+	index = gatt_db_attribute_get_index(attrib);
+	if (index < 0)
+		return NULL;
+
+	service = attrib->service;
+
+	if (!bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+		index++;
+	else if (bt_uuid_cmp(&characteristic_uuid,
+				&service->attributes[index - 1]->uuid))
+		return NULL;
+
+	return service->attributes[index];
+}
+
 void gatt_db_service_foreach_desc(struct gatt_db_attribute *attrib,
 						gatt_db_attribute_cb_t func,
 						void *user_data)
 {
 	struct gatt_db_service *service;
 	struct gatt_db_attribute *attr;
+	int index;
 	uint16_t i;
 
 	if (!attrib || !func)
 		return;
 
-	/* Return if this attribute is not a characteristic declaration */
-	if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+	attrib = gatt_db_attribute_get_value(attrib);
+	if (!attrib)
+		return;
+
+	index = gatt_db_attribute_get_index(attrib);
+	if (index < 0)
 		return;
 
 	service = attrib->service;
 
 	/* Start from the attribute following the value handle */
-	for (i = 0; i < service->num_handles; i++) {
-		if (service->attributes[i] == attrib) {
-			i += 2;
-			break;
-		}
-	}
-
-	for (; i < service->num_handles; i++) {
+	for (i = index + 1; i < service->num_handles; i++) {
 		attr = service->attributes[i];
 		if (!attr)
 			continue;
@@ -2163,8 +2202,8 @@ bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib,
 	if (!attrib || !attrib->notify_func)
 		return false;
 
-	/* Return if this attribute is not a characteristic declaration */
-	if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+	attrib = gatt_db_attribute_get_value(attrib);
+	if (!attrib)
 		return false;
 
 	ccc = gatt_db_attribute_get_ccc(attrib);
-- 
2.35.1


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

* Re: [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails
  2022-03-14 21:50 [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails Luiz Augusto von Dentz
  2022-03-14 21:50 ` [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify Luiz Augusto von Dentz
@ 2022-03-14 23:40 ` patchwork-bot+bluetooth
  2022-03-15  0:15 ` [BlueZ,1/2] " bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2022-03-14 23:40 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 14 Mar 2022 14:50:09 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This prints an error if gatt_db_attribut_notify fails.
> ---
>  src/gatt-database.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [BlueZ,1/2] gatt: Print error if gatt_db_attribut_notify fails
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8fb8f9e73ff8
  - [BlueZ,2/2] gatt-db: Fix gatt_db_attribute_notify
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=411d63ec33a2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* RE: [BlueZ,1/2] gatt: Print error if gatt_db_attribut_notify fails
  2022-03-14 21:50 [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails Luiz Augusto von Dentz
  2022-03-14 21:50 ` [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify Luiz Augusto von Dentz
  2022-03-14 23:40 ` [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails patchwork-bot+bluetooth
@ 2022-03-15  0:15 ` bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2022-03-15  0:15 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=623328

---Test result---

Test Summary:
CheckPatch                    PASS      1.36 seconds
GitLint                       PASS      0.91 seconds
Prep - Setup ELL              PASS      49.35 seconds
Build - Prep                  PASS      0.52 seconds
Build - Configure             PASS      9.55 seconds
Build - Make                  PASS      1419.91 seconds
Make Check                    PASS      12.00 seconds
Make Check w/Valgrind         PASS      510.87 seconds
Make Distcheck                PASS      265.65 seconds
Build w/ext ELL - Configure   PASS      9.87 seconds
Build w/ext ELL - Make        PASS      1390.20 seconds
Incremental Build with patchesPASS      2873.48 seconds



---
Regards,
Linux Bluetooth


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

end of thread, other threads:[~2022-03-15  0:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-14 21:50 [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails Luiz Augusto von Dentz
2022-03-14 21:50 ` [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify Luiz Augusto von Dentz
2022-03-14 23:40 ` [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails patchwork-bot+bluetooth
2022-03-15  0:15 ` [BlueZ,1/2] " bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.