Skip to content

Commit a0614b6

Browse files
jori-nordicstephanosio
authored andcommitted
Bluetooth: host: save CF and CCC values written before bonding
On bond establishment: save the CF and CCC data that have been written before the peer was bonded. On identity resolved: update the CF data to use the peer's identity address instead of its private address (same as is currently done for the CCC). Fixes #54770. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 3ad4526 commit a0614b6

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,12 +1118,33 @@ static void bt_gatt_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *
11181118
.private_addr = private_addr,
11191119
.id_addr = id_addr
11201120
};
1121+
bool is_bonded = bt_addr_le_is_bonded(conn->id, &conn->le.dst);
11211122

11221123
bt_gatt_foreach_attr(0x0001, 0xffff, convert_to_id_on_match, &user_data);
11231124

1124-
/* Store the ccc and cf data */
1125-
bt_gatt_store_ccc(conn->id, &(conn->le.dst));
1126-
bt_gatt_store_cf(conn->id, &conn->le.dst);
1125+
/* Store the ccc */
1126+
if (is_bonded) {
1127+
bt_gatt_store_ccc(conn->id, &conn->le.dst);
1128+
}
1129+
1130+
/* Update the cf addresses and store it if we get a match */
1131+
struct gatt_cf_cfg *cfg = find_cf_cfg_by_addr(conn->id, private_addr);
1132+
1133+
if (cfg) {
1134+
bt_addr_le_copy(&cfg->peer, id_addr);
1135+
if (is_bonded) {
1136+
bt_gatt_store_cf(conn->id, &conn->le.dst);
1137+
}
1138+
}
1139+
}
1140+
1141+
static void bt_gatt_pairing_complete(struct bt_conn *conn, bool bonded)
1142+
{
1143+
if (bonded) {
1144+
/* Store the ccc and cf data */
1145+
bt_gatt_store_ccc(conn->id, &(conn->le.dst));
1146+
bt_gatt_store_cf(conn->id, &conn->le.dst);
1147+
}
11271148
}
11281149
#endif /* CONFIG_BT_SETTINGS && CONFIG_BT_SMP && CONFIG_BT_GATT_CLIENT */
11291150

@@ -1498,13 +1519,24 @@ void bt_gatt_init(void)
14981519
#endif
14991520

15001521
#if defined(CONFIG_BT_GATT_CLIENT) && defined(CONFIG_BT_SETTINGS) && defined(CONFIG_BT_SMP)
1522+
static struct bt_conn_auth_info_cb gatt_conn_auth_info_cb = {
1523+
.pairing_complete = bt_gatt_pairing_complete,
1524+
};
1525+
1526+
/* Register the gatt module for authentication info callbacks so it can
1527+
* be notified when pairing has completed. This is used to enable CCC
1528+
* and CF storage on pairing complete.
1529+
*/
1530+
bt_conn_auth_info_cb_register(&gatt_conn_auth_info_cb);
1531+
15011532
static struct bt_conn_cb gatt_conn_cb = {
15021533
.identity_resolved = bt_gatt_identity_resolved,
15031534
};
15041535

1505-
/* Register the gatt module for connection callbacks so it can be
1506-
* notified when pairing has completed. This is used to enable CCC and
1507-
* CF storage on pairing complete.
1536+
/* Also update the address of CCC or CF writes that happened before the
1537+
* identity resolution. Note that to increase security in the future, we
1538+
* might want to explicitly not do this and treat a bonded device as a
1539+
* brand-new peer.
15081540
*/
15091541
bt_conn_cb_register(&gatt_conn_cb);
15101542
#endif /* CONFIG_BT_GATT_CLIENT && CONFIG_BT_SETTINGS && CONFIG_BT_SMP */

0 commit comments

Comments
 (0)