From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] shared/gatt-client: Fix not creating a request for notifications
Date: Thu, 16 Mar 2023 12:36:34 -0700 [thread overview]
Message-ID: <20230316193634.1195948-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Notifications were using bt_att_send directly instead of
bt_gatt_client_write_value thus it wouldn't create a request which
causes the instance to not be able to track it which in turn may cause
the client to trigger its idle callback too early.
Fixes: https://github.com/bluez/bluez/issues/490
---
src/shared/gatt-client.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 9ffc10b0b44a..efc013a20dcf 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1660,31 +1660,30 @@ static void complete_notify_request(void *data)
}
static bool notify_data_write_ccc(struct notify_data *notify_data, bool enable,
- bt_att_response_func_t callback)
+ bt_gatt_client_callback_t callback)
{
- uint8_t pdu[4];
unsigned int att_id;
+ uint16_t value;
uint16_t properties = notify_data->chrc->properties;
assert(notify_data->chrc->ccc_handle);
- memset(pdu, 0, sizeof(pdu));
- put_le16(notify_data->chrc->ccc_handle, pdu);
if (enable) {
/* Try to enable notifications or indications based on
* whatever the characteristic supports.
*/
if (properties & BT_GATT_CHRC_PROP_NOTIFY)
- pdu[2] = 0x01;
+ value = cpu_to_le16(0x0001);
else if (properties & BT_GATT_CHRC_PROP_INDICATE)
- pdu[2] = 0x02;
-
- if (!pdu[2])
+ value = cpu_to_le16(0x0002);
+ else
return false;
}
- att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ,
- pdu, sizeof(pdu), callback,
+ att_id = bt_gatt_client_write_value(notify_data->client,
+ notify_data->chrc->ccc_handle,
+ (void *)&value, sizeof(value),
+ callback,
notify_data_ref(notify_data),
notify_data_unref);
notify_data->chrc->ccc_write_id = notify_data->att_id = att_id;
@@ -1714,8 +1713,8 @@ static bool notify_set_ecode(const void *data, const void *match_data)
return true;
}
-static void enable_ccc_callback(uint8_t opcode, const void *pdu,
- uint16_t length, void *user_data)
+static void enable_ccc_callback(bool success, uint8_t att_ecode,
+ void *user_data)
{
struct notify_data *notify_data = user_data;
@@ -1723,10 +1722,9 @@ static void enable_ccc_callback(uint8_t opcode, const void *pdu,
notify_data->chrc->ccc_write_id = 0;
- bt_gatt_client_ref(notify_data->client);
+ bt_gatt_client_ref_safe(notify_data->client);
- if (opcode == BT_ATT_OP_ERROR_RSP)
- notify_data->att_ecode = process_error(pdu, length);
+ notify_data->att_ecode = att_ecode;
/* Notify for all remaining requests. */
complete_notify_request(notify_data);
@@ -2165,8 +2163,8 @@ struct value_data {
const void *data;
};
-static void disable_ccc_callback(uint8_t opcode, const void *pdu,
- uint16_t length, void *user_data)
+static void disable_ccc_callback(bool success, uint8_t att_ecode,
+ void *user_data)
{
struct notify_data *notify_data = user_data;
struct notify_data *next_data;
--
2.39.2
next reply other threads:[~2023-03-16 19:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 19:36 Luiz Augusto von Dentz [this message]
2023-03-16 21:33 ` [BlueZ] shared/gatt-client: Fix not creating a request for notifications bluez.test.bot
2023-03-17 16:40 ` [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=20230316193634.1195948-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox