Linux bluetooth development
 help / color / mirror / Atom feed
From: Cheng Jiang <cheng.jiang@oss.qualcomm.com>
To: linux-bluetooth@vger.kernel.org
Cc: jinwang.li@oss.qualcomm.com, wei.deng@oss.qualcomm.com,
	xiuzhuo.shang@oss.qualcomm.com, shuai.zhang@oss.qualcomm.com,
	Cheng Jiang <cheng.jiang@oss.qualcomm.com>
Subject: [PATCH v2 04/14] shared/gatt-db: Add gatt_db_attribute_indicate()
Date: Fri,  9 Oct 2026 17:25:20 +0800	[thread overview]
Message-ID: <20261009092532.3600749-5-cheng.jiang@oss.qualcomm.com> (raw)
In-Reply-To: <20261009092532.3600749-1-cheng.jiang@oss.qualcomm.com>

gatt_db_attribute_notify() leaves the choice between a notification and an
indication to the CCC value the client wrote, preferring notifications
whenever the client enabled them. A server cannot therefore honour a
characteristic that has to be indicated: the Ranging Service requires
Ranging Data Ready and Ranging Data Overwritten to be indicated even when
the client subscribed to both transports (RAS 3.4.2, 3.5.2).

Add gatt_db_attribute_indicate() next to it. The two share a helper and
differ only in the opcode handed to the notify callback, so the CCC lookup
stays in one place, and a callback that does not care keeps working
unchanged.

gatt-database honours the request by skipping the notification branch and
sending an indication instead, provided the client enabled indications.

Assisted-by: Claude:claude-opus-4.8
---
 src/gatt-database.c  |  7 ++++++-
 src/shared/gatt-db.c | 20 +++++++++++++++++---
 src/shared/gatt-db.h | 12 ++++++++++++
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index b8bcc0a04..b511e13e3 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -168,6 +168,7 @@ struct notify {
 	uint16_t len;
 	bt_gatt_server_conf_func_t conf;
 	void *user_data;
+	bool indicate;
 };
 
 #define CLI_FEAT_SIZE 1
@@ -1446,7 +1447,7 @@ static void send_notification_to_device(void *data, void *user_data)
 	 * TODO: If the device is not connected but bonded, send the
 	 * notification/indication when it becomes connected.
 	 */
-	if (ccc->value & 0x0001) {
+	if (!notify->indicate && (ccc->value & 0x0001)) {
 		DBG("GATT server sending notification");
 		bt_gatt_server_send_notification(server,
 					notify->handle, notify->value,
@@ -1455,6 +1456,9 @@ static void send_notification_to_device(void *data, void *user_data)
 		return;
 	}
 
+	if (!(ccc->value & 0x0002))
+		return;
+
 	DBG("GATT server sending indication");
 	bt_gatt_server_send_indication(server, notify->handle, notify->value,
 						notify->len, notify->conf,
@@ -1487,6 +1491,7 @@ static void gatt_notify_cb(struct gatt_db_attribute *attrib,
 	notify.ccc_handle = gatt_db_attribute_get_handle(ccc);
 	notify.value = (void *) value;
 	notify.len = len;
+	notify.indicate = (opcode == BT_ATT_OP_HANDLE_IND);
 
 	if (attrib == database->svc_chngd)
 		notify.conf = service_changed_conf;
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index d168e355b..af26ca5c1 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -2440,9 +2440,9 @@ gatt_db_attribute_get_ccc(struct gatt_db_attribute *attrib)
 	return ccc;
 }
 
-bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib,
+static bool attribute_notify(struct gatt_db_attribute *attrib,
 					const uint8_t *value, size_t len,
-					struct bt_att *att)
+					uint8_t opcode, struct bt_att *att)
 {
 	struct gatt_db_attribute *ccc;
 	struct gatt_db *db;
@@ -2468,12 +2468,26 @@ bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib,
 	else
 		notify_user_data = ccc->user_data;
 
-	attrib->notify_func(attrib, ccc, value, len, BT_ATT_OP_HANDLE_NFY, att,
+	attrib->notify_func(attrib, ccc, value, len, opcode, att,
 							notify_user_data);
 
 	return true;
 }
 
+bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib,
+					const uint8_t *value, size_t len,
+					struct bt_att *att)
+{
+	return attribute_notify(attrib, value, len, BT_ATT_OP_HANDLE_NFY, att);
+}
+
+bool gatt_db_attribute_indicate(struct gatt_db_attribute *attrib,
+					const uint8_t *value, size_t len,
+					struct bt_att *att)
+{
+	return attribute_notify(attrib, value, len, BT_ATT_OP_HANDLE_IND, att);
+}
+
 bool gatt_db_attribute_reset(struct gatt_db_attribute *attrib)
 {
 	if (!attrib)
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 587a281b3..5e7e7203f 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -301,6 +301,18 @@ bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib,
 					const uint8_t *value, size_t len,
 					struct bt_att *att);
 
+/* Same as gatt_db_attribute_notify() but asks for an indication, so the
+ * notify callback is given BT_ATT_OP_HANDLE_IND instead of
+ * BT_ATT_OP_HANDLE_NFY. Some profiles mandate the indication transport for
+ * specific characteristics, for example the Ranging Service Ranging Data
+ * Ready and Ranging Data Overwritten ones, which gatt_db_attribute_notify()
+ * cannot express since it prefers notifications whenever the client enabled
+ * them.
+ */
+bool gatt_db_attribute_indicate(struct gatt_db_attribute *attrib,
+					const uint8_t *value, size_t len,
+					struct bt_att *att);
+
 bool gatt_db_attribute_reset(struct gatt_db_attribute *attrib);
 
 void *gatt_db_attribute_get_user_data(struct gatt_db_attribute *attrib);
-- 
2.43.0


  parent reply	other threads:[~2026-10-09  9:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  9:25 [PATCH v2 00/14] Ranging Profile and Ranging Service PTS fixes Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 01/14] shared/gatt-client: Allow registering notify with explicit CCC value Cheng Jiang
2026-10-09 15:42   ` Ranging Profile and Ranging Service PTS fixes bluez.test.bot
2026-10-09  9:25 ` [PATCH v2 02/14] shared/gatt-db: Pass the ATT opcode to the notify callback Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 03/14] unit: Take the ATT opcode in the notify callbacks Cheng Jiang
2026-10-09  9:25 ` Cheng Jiang [this message]
2026-10-09  9:25 ` [PATCH v2 05/14] shared/rap: Honor CCCD transport for RAS on-demand ranging data Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 06/14] shared/rap: Add RAS Control Point Abort Operation Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 07/14] unit/test-rap: Expect Abort Operation in RAS Features Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 08/14] shared/rap: Shorten the requester Control Point response timeout Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 09/14] shared/rap: Add real-time ranging data delivery on the responder Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 10/14] shared/rap: Add requester ranging data subscription API Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 11/14] profiles/ranging: Expose requester ranging data mode over D-Bus Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 12/14] client: Add Channel Sounding ranging data mode control Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 13/14] doc: Document " Cheng Jiang
2026-10-09  9:25 ` [PATCH v2 14/14] doc/qualification: Add RAP/RAS PTS qualification results Cheng Jiang
2026-10-09 17:20 ` [PATCH v2 00/14] Ranging Profile and Ranging Service PTS fixes 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=20261009092532.3600749-5-cheng.jiang@oss.qualcomm.com \
    --to=cheng.jiang@oss.qualcomm.com \
    --cc=jinwang.li@oss.qualcomm.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=shuai.zhang@oss.qualcomm.com \
    --cc=wei.deng@oss.qualcomm.com \
    --cc=xiuzhuo.shang@oss.qualcomm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox