From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/4] shared/gatt-client: Allow registering with NULL callback
Date: Thu, 5 Jan 2023 14:09:42 -0800 [thread overview]
Message-ID: <20230105220944.2373424-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20230105220944.2373424-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes bt_gatt_client_register_notify allow registering with NULL
callback which is interpreted as the CCC write has already been
performed therefore it won't be written again.
---
src/shared/gatt-client.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 4aa5d7d92957..593b0f27f871 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1711,8 +1711,11 @@ static unsigned int register_notify(struct bt_gatt_client *client,
* descriptor.
*/
chrc = notify_chrc_create(client, handle);
- if (!chrc)
+ if (!chrc) {
+ DBG(client, "Unable to locate characteristic at 0x%04x",
+ handle);
return 0;
+ }
}
/* Fail if we've hit the maximum allowed notify sessions */
@@ -1750,9 +1753,10 @@ static unsigned int register_notify(struct bt_gatt_client *client,
}
/*
- * If the ref count > 1, then notifications are already enabled.
+ * If the ref count > 1, ccc handle cannot be found or registration
+ * callback is not set consider notifications are already enabled.
*/
- if (chrc->notify_count > 1 || !chrc->ccc_handle) {
+ if (chrc->notify_count > 1 || !chrc->ccc_handle || !callback) {
complete_notify_request(notify_data);
return notify_data->id;
}
@@ -2176,6 +2180,9 @@ static void notify_cb(struct bt_att_chan *chan, uint8_t opcode,
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));
@@ -3670,7 +3677,8 @@ unsigned int bt_gatt_client_register_notify(struct bt_gatt_client *client,
void *user_data,
bt_gatt_client_destroy_func_t destroy)
{
- if (!client || !client->db || !chrc_value_handle || !callback)
+ if (!client || !client->db || !chrc_value_handle ||
+ (!callback && !notify))
return 0;
if (client->in_svc_chngd)
--
2.37.3
next prev parent reply other threads:[~2023-01-05 22:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 22:09 [PATCH BlueZ 1/4] shared/gatt-client: Use parent debug_callback if not set on clone Luiz Augusto von Dentz
2023-01-05 22:09 ` Luiz Augusto von Dentz [this message]
2023-01-05 22:09 ` [PATCH BlueZ 3/4] attrib: Introduce g_attrib_attach_client Luiz Augusto von Dentz
2023-01-05 22:09 ` [PATCH BlueZ 4/4] hog-lib: Fix not handling BT_ATT_OP_HANDLE_NFY_MULT Luiz Augusto von Dentz
2023-01-06 0:03 ` [BlueZ,1/4] shared/gatt-client: Use parent debug_callback if not set on clone bluez.test.bot
2023-01-06 0:11 ` Luiz Augusto von Dentz
2023-01-06 20:00 ` [PATCH BlueZ 1/4] " 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=20230105220944.2373424-2-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