Skip to content

Commit

Permalink
Bluetooth: Host: Ensure only connected peers affect _bt_gatt_ccc.value
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Håvard Reierstad <[email protected]>
  • Loading branch information
HaavardRei committed Nov 6, 2024
1 parent d4b7bf9 commit cc21478
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit cc21478

Please sign in to comment.