diff mbox series

[BlueZ,2/4] shared/gatt-client: Allow registering with NULL callback

Message ID 20230105220944.2373424-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/4] shared/gatt-client: Use parent debug_callback if not set on clone | expand

Commit Message

Luiz Augusto von Dentz Jan. 5, 2023, 10:09 p.m. UTC
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 mbox series

Patch

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)