All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data
Date: Wed, 11 May 2022 17:55:14 -0700	[thread overview]
Message-ID: <20220512005515.844857-1-luiz.dentz@gmail.com> (raw)

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

This makes gatt_db_attribute_get_char_data work with Characteristic
Value rather than only with Characteristic Declaration.
---
 src/shared/gatt-db.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 4f5d10b57..d3b5cec1d 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1528,7 +1528,7 @@ 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)
+static int gatt_db_attribute_get_index(const struct gatt_db_attribute *attrib)
 {
 	struct gatt_db_service *service;
 	int index;
@@ -1853,8 +1853,18 @@ bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
 	if (!attrib)
 		return false;
 
-	if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
-		return false;
+	if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid)) {
+		int index;
+
+		/* Check if Characteristic Value was passed instead */
+		index = gatt_db_attribute_get_index(attrib);
+		if (index < 0)
+			return NULL;
+
+		attrib = attrib->service->attributes[index - 1];
+		if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+			return false;
+	}
 
 	/*
 	 * Characteristic declaration value:
-- 
2.35.1


             reply	other threads:[~2022-05-12  0:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  0:55 Luiz Augusto von Dentz [this message]
2022-05-12  0:55 ` [PATCH BlueZ] service: Add initiator argument to service_accept Luiz Augusto von Dentz
2022-05-12  3:06   ` [BlueZ] " bluez.test.bot
2022-05-13  0:00   ` [PATCH BlueZ] " patchwork-bot+bluetooth
2022-05-12  3:16 ` [BlueZ] gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data bluez.test.bot
2022-05-13  0:00 ` [PATCH BlueZ] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512005515.844857-1-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.