From eccd8adc68574ea75270f99c44233f80033026c0 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 19 Dec 2024 15:15:32 +0100 Subject: [PATCH] Bluetooth: Host: Fix not sending Service Changed indication gatt_unregister() clears handles if those were auto-assigned by host. This resulted in Service Changed indication not beding sent since call to sc_indicate() pass already cleared handles. This was affecting GATT/SR/GAS/BV-01-C and GATT/SR/GAS/BV-07-C test cases. Signed-off-by: Szymon Janc --- subsys/bluetooth/host/gatt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 142027775be..f8e6d3bf57f 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1743,10 +1743,18 @@ int bt_gatt_service_register(struct bt_gatt_service *svc) int bt_gatt_service_unregister(struct bt_gatt_service *svc) { + uint16_t sc_start_handle; + uint16_t sc_end_handle; int err; __ASSERT(svc, "invalid parameters\n"); + /* gatt_unregister() clears handles when those were auto-assigned + * by host + */ + sc_start_handle = svc->attrs[0].handle; + sc_end_handle = svc->attrs[svc->attr_count - 1].handle; + k_sched_lock(); err = gatt_unregister(svc); @@ -1761,8 +1769,7 @@ int bt_gatt_service_unregister(struct bt_gatt_service *svc) return 0; } - sc_indicate(svc->attrs[0].handle, - svc->attrs[svc->attr_count - 1].handle); + sc_indicate(sc_start_handle, sc_end_handle); db_changed();