From: Javier de San Pedro <dev.git@javispedro.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.von.dentz@intel.com, Javier de San Pedro <dev.git@javispedro.com>
Subject: [PATCH BlueZ] shared/gatt-client: always send ATT confirmations
Date: Sat, 26 Aug 2023 21:24:21 +0200 [thread overview]
Message-ID: <20230826192421.7032-1-dev.git@javispedro.com> (raw)
I noticed after upgrading 5.66->5.68 that Bluez was no longer sending
confirmations (ATT opcode 0x1E) in response to indication opcodes (0x1D).
Commit fde32ff9c9c0 ("shared/gatt-client: Allow registering with NULL
callback") added an early return to the notify_cb function when the
current client's notify_list is empty. However, in this case, we will
also not send the confirmation back. This breaks protocol.
The devices I have generally respond to this by stopping
any new indications until ~15sec timeout or disconnection.
As far as I can see, when using D-Bus API all notify handlers are always
added on client clones, never on the 'root' client itself (the one
with !client->parent), so for the root client the notify_list is always
empty, making this issue very easy to trigger using D-Bus GATT API.
Ensure that we always send the confirmation, even if notify_list is empty.
Fixes: fde32ff9c9c0 ("shared/gatt-client: Allow registering with NULL callback")
---
src/shared/gatt-client.c | 57 ++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index efc013a20..56ecc6a8f 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -2230,45 +2230,46 @@ static void notify_cb(struct bt_att_chan *chan, uint8_t opcode,
void *user_data)
{
struct bt_gatt_client *client = user_data;
- struct value_data data;
-
- if (queue_isempty(client->notify_list))
- return;
bt_gatt_client_ref(client);
- memset(&data, 0, sizeof(data));
+ if (!queue_isempty(client->notify_list)) {
+ struct value_data data;
- if (opcode == BT_ATT_OP_HANDLE_NFY_MULT) {
- while (length >= 4) {
- data.handle = get_le16(pdu);
- length -= 2;
- pdu += 2;
+ memset(&data, 0, sizeof(data));
- data.len = get_le16(pdu);
- length -= 2;
- pdu += 2;
+ if (opcode == BT_ATT_OP_HANDLE_NFY_MULT) {
+ while (length >= 4) {
+ data.handle = get_le16(pdu);
+ length -= 2;
+ pdu += 2;
- if (data.len > length)
- data.len = length;
+ data.len = get_le16(pdu);
+ length -= 2;
+ pdu += 2;
- data.data = pdu;
+ if (data.len > length)
+ data.len = length;
- queue_foreach(client->notify_list, notify_handler,
- &data);
+ data.data = pdu;
- length -= data.len;
- pdu += data.len;
- }
- } else {
- data.handle = get_le16(pdu);
- length -= 2;
- pdu += 2;
+ queue_foreach(client->notify_list,
+ notify_handler, &data);
- data.len = length;
- data.data = pdu;
+ length -= data.len;
+ pdu += data.len;
+ }
+ } else {
+ data.handle = get_le16(pdu);
+ length -= 2;
+ pdu += 2;
+
+ data.len = length;
+ data.data = pdu;
- queue_foreach(client->notify_list, notify_handler, &data);
+ queue_foreach(client->notify_list,
+ notify_handler, &data);
+ }
}
if (opcode == BT_ATT_OP_HANDLE_IND && !client->parent)
--
2.41.0
next reply other threads:[~2023-08-26 19:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-26 19:24 Javier de San Pedro [this message]
2023-08-26 21:29 ` [BlueZ] shared/gatt-client: always send ATT confirmations bluez.test.bot
2023-08-27 21:07 ` [PATCH BlueZ] " Luiz Augusto von Dentz
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=20230826192421.7032-1-dev.git@javispedro.com \
--to=dev.git@javispedro.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.von.dentz@intel.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