diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2023-01-05 13:54:50 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2023-01-05 13:54:50 -0800 |
commit | fde32ff9c9c0ab531767c4539cd0b5da3aec289b (patch) | |
tree | 9f64c65ce758b4067b99995a757a21a371392b71 /src/shared | |
parent | 6e3059ae8cac28b8eefd6e55b47a6e39278d6410 (diff) | |
download | bluez-fde32ff9c9c0ab531767c4539cd0b5da3aec289b.tar.gz |
shared/gatt-client: Allow registering with NULL callback
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.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/gatt-client.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 4aa5d7d92..593b0f27f 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) |