Linux bluetooth development
 help / color / mirror / Atom feed
From: Kyle Pepper <cochcoder@proton.me>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, luiz.dentz@gmail.com
Subject: [PATCH v2 1/3] shared/gatt-client: Support pending GATT helper requests
Date: Wed, 11 Nov 2026 21:43:39 +0000	[thread overview]
Message-ID: <4c16af75cbdb770ef8bf3ba44ef2173c10e9fc8a.1794432472.git.cochcoder@proton.me> (raw)
In-Reply-To: <cover.1794432472.git.cochcoder@proton.me>

Allow pending requests to own a cancellable GATT helper request, so
multi-PDU operations can use the existing cancellation queue. Expose a
request-returning read-by-type helper and keep the boolean interface for
callers that do not retain requests.

Assisted-by: Codex:gpt-6
---
 src/shared/gatt-client.c  | 10 ++++++++++
 src/shared/gatt-helpers.c | 26 ++++++++++++++++++++++----
 src/shared/gatt-helpers.h |  7 +++++++
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 7bebc50dc..f301a105b 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -120,6 +120,7 @@ struct request {
 	int ref_count;
 	unsigned int id;
 	unsigned int att_id;
+	struct bt_gatt_request *gatt_req;
 	void *data;
 	void (*destroy)(void *);
 };
@@ -2811,6 +2812,15 @@ static bool cancel_request(struct request *req)
 {
 	req->removed = true;
 
+	if (req->gatt_req) {
+		struct bt_gatt_request *gatt_req = req->gatt_req;
+
+		req->gatt_req = NULL;
+		bt_gatt_request_cancel(gatt_req);
+		bt_gatt_request_unref(gatt_req);
+		return true;
+	}
+
 	if (req->long_write)
 		return cancel_long_write_req(req->client, req);
 
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index ea77a41ef..6d307e893 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -1484,7 +1484,8 @@ done:
 	discovery_op_complete(op, success, att_ecode);
 }
 
-bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
+struct bt_gatt_request *bt_gatt_read_by_type_request(struct bt_att *att,
+					uint16_t start, uint16_t end,
 					const bt_uuid_t *uuid,
 					bt_gatt_request_callback_t callback,
 					void *user_data,
@@ -1495,7 +1496,7 @@ bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
 	struct iovec req = { pdu, 0 };
 
 	if (!att || !uuid || uuid->type == BT_UUID_UNSPEC)
-		return false;
+		return NULL;
 
 	op = new0(struct bt_gatt_request, 1);
 	op->att = att;
@@ -1516,10 +1517,27 @@ bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
 						bt_gatt_request_ref(op),
 						async_req_unref);
 	if (op->id)
-		return true;
+		return bt_gatt_request_ref(op);
 
 	free(op);
-	return false;
+	return NULL;
+}
+
+bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
+					const bt_uuid_t *uuid,
+					bt_gatt_request_callback_t callback,
+					void *user_data,
+					bt_gatt_destroy_func_t destroy)
+{
+	struct bt_gatt_request *req;
+
+	req = bt_gatt_read_by_type_request(att, start, end, uuid, callback,
+							user_data, destroy);
+	if (!req)
+		return false;
+
+	bt_gatt_request_unref(req);
+	return true;
 }
 
 static void discover_descs_cb(uint8_t opcode, const void *pdu,
diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h
index 2bf5aad46..528ef2196 100644
--- a/src/shared/gatt-helpers.h
+++ b/src/shared/gatt-helpers.h
@@ -102,5 +102,12 @@ bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
 					void *user_data,
 					bt_gatt_destroy_func_t destroy);
 
+struct bt_gatt_request *bt_gatt_read_by_type_request(struct bt_att *att,
+					uint16_t start, uint16_t end,
+					const bt_uuid_t *uuid,
+					bt_gatt_request_callback_t callback,
+					void *user_data,
+					bt_gatt_destroy_func_t destroy);
+
 uint16_t bt_gatt_req_get_end_handle(struct bt_gatt_request *req);
 uint16_t bt_gatt_req_get_start_handle(struct bt_gatt_request *req);
-- 
2.56.0



  reply	other threads:[~2026-11-11 21:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  6:59 [PATCH] shared/gatt-client: Cancel discovery read-by-type requests Kyle Pepper
2026-11-07  8:45 ` bluez.test.bot
2026-11-07 20:53 ` [PATCH] " Luiz Augusto von Dentz
2026-11-11 21:42 ` [PATCH v2 0/3] shared/gatt-client: Track internal discovery reads Kyle Pepper
2026-11-11 21:43   ` Kyle Pepper [this message]
2026-11-12  1:58     ` bluez.test.bot
2026-11-11 21:43   ` [PATCH v2 2/3] shared/gatt-client: Track pending Server Features reads Kyle Pepper
2026-11-11 21:44   ` [PATCH v2 3/3] shared/gatt-client: Track pending discovery Database Hash reads Kyle Pepper
2026-11-12 17:50   ` [PATCH v2 0/3] shared/gatt-client: Track internal discovery reads 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=4c16af75cbdb770ef8bf3ba44ef2173c10e9fc8a.1794432472.git.cochcoder@proton.me \
    --to=cochcoder@proton.me \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox