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 <aleksander.wasaznik@nordicsemi.no>
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
This commit is contained in:
Håvard Reierstad 2024-11-06 12:34:15 +01:00 committed by Mahesh Mahadevan
parent d7fe3d1a75
commit 42ae483795
1 changed files with 11 additions and 2 deletions

View File

@ -2195,8 +2195,17 @@ static void gatt_ccc_changed(const struct bt_gatt_attr *attr,
uint16_t value = 0x0000;
for (i = 0; i < ARRAY_SIZE(ccc->cfg); i++) {
if (ccc->cfg[i].value > value) {
value = ccc->cfg[i].value;
/* `ccc->value` shall be a summary of connected peers' CCC values, but
* `ccc->cfg` can contain entries for bonded but not connected peers.
*/
struct bt_conn *conn = bt_conn_lookup_addr_le(ccc->cfg[i].id, &ccc->cfg[i].peer);
if (conn) {
if (ccc->cfg[i].value > value) {
value = ccc->cfg[i].value;
}
bt_conn_unref(conn);
}
}