From 49121dcdd711020e1d9316c52cfc3760c880b16c Mon Sep 17 00:00:00 2001 From: Yagoor <6549332+Yagoor@users.noreply.github.com> Date: Wed, 27 Nov 2024 10:36:23 +0100 Subject: [PATCH] Bluetooth: host: Improve error reporting on gatt subscribe * Return EALREADY when the subscription already exists but it is a different entry. This indicates to the application to not wait on subscribe callback. This is needed because the callback is called from the ccc_write which does not happen when another subscription exists Signed-off-by: Yago Fontoura do Rosario --- subsys/bluetooth/host/gatt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 33d8bc8b60bbf1b..73ecee44f5e935c 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -5523,7 +5523,11 @@ int bt_gatt_subscribe(struct bt_conn *conn, */ sys_slist_prepend(&sub->list, ¶ms->node); - return 0; + /* + * Report already if subscription exist so that application does not wait + * for the subscribe callback + */ + return has_subscription ? -EALREADY : 0; } int bt_gatt_resubscribe(uint8_t id, const bt_addr_le_t *peer,