Skip to content

Commit 42ae483

Browse files
HaavardReialwa-nordic
authored andcommitted
Bluetooth: Host: Ensure only connected peers affect _bt_gatt_ccc.value
The doc on `_bt_gatt_ccc.value` specifies that only connected peers contribute to that value. But before this change, it was computed from all entries in `_bt_gatt_ccc.cfg`, which include bonded but not connected peers when `CONFIG_BT_SETTINGS_CCC_LAZY_LOADING` is set. Co-authored-by: Aleksander Wasaznik <[email protected]> Signed-off-by: Håvard Reierstad <[email protected]>
1 parent d7fe3d1 commit 42ae483

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,8 +2195,17 @@ static void gatt_ccc_changed(const struct bt_gatt_attr *attr,
21952195
uint16_t value = 0x0000;
21962196

21972197
for (i = 0; i < ARRAY_SIZE(ccc->cfg); i++) {
2198-
if (ccc->cfg[i].value > value) {
2199-
value = ccc->cfg[i].value;
2198+
/* `ccc->value` shall be a summary of connected peers' CCC values, but
2199+
* `ccc->cfg` can contain entries for bonded but not connected peers.
2200+
*/
2201+
struct bt_conn *conn = bt_conn_lookup_addr_le(ccc->cfg[i].id, &ccc->cfg[i].peer);
2202+
2203+
if (conn) {
2204+
if (ccc->cfg[i].value > value) {
2205+
value = ccc->cfg[i].value;
2206+
}
2207+
2208+
bt_conn_unref(conn);
22002209
}
22012210
}
22022211

0 commit comments

Comments
 (0)