2022-03-15 10:45:06

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails

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

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


2022-03-15 13:45:11

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,1/2] gatt: Print error if gatt_db_attribut_notify fails

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

2022-03-15 16:54:58

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify

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

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

2022-03-16 07:05:13

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Mon, 14 Mar 2022 14:50:09 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> 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