From 692d7d523eb314879067d17e4c228aef500aa910 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 16 Aug 2019 13:55:42 +0300 Subject: [PATCH] Bluetooth: GATT: Fix not clearing out of sync flag When the database changes and a client becomes change unware it should also clear the out of sync flag as the following request should return an error: Core Spec 5.1 | Vol 3, Part G, 2.5.2.1 Robust Caching: 'The error response is sent only once after the client becomes change-unaware, unless the client disconnects or the database changes again before the client becomes change-aware in which case the error response shall be sent again.' Fixes: #18183 Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/host/gatt.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 48197d37fcd..d352420ce8a 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -824,9 +824,18 @@ static void db_changed(void) continue; } - if (CF_ROBUST_CACHING(cfg) && - atomic_test_and_clear_bit(cfg->flags, CF_CHANGE_AWARE)) { - BT_DBG("%s change-unaware", bt_addr_le_str(&cfg->peer)); + if (CF_ROBUST_CACHING(cfg)) { + /* Core Spec 5.1 | Vol 3, Part G, 2.5.2.1 Robust Caching + *... the database changes again before the client + * becomes change-aware in which case the error response + * shall be sent again. + */ + atomic_clear_bit(cfg->flags, CF_OUT_OF_SYNC); + if (atomic_test_and_clear_bit(cfg->flags, + CF_CHANGE_AWARE)) { + BT_DBG("%s change-unaware", + bt_addr_le_str(&cfg->peer)); + } } } #endif