@@ -1118,12 +1118,33 @@ static void bt_gatt_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *
1118
1118
.private_addr = private_addr ,
1119
1119
.id_addr = id_addr
1120
1120
};
1121
+ bool is_bonded = bt_addr_le_is_bonded (conn -> id , & conn -> le .dst );
1121
1122
1122
1123
bt_gatt_foreach_attr (0x0001 , 0xffff , convert_to_id_on_match , & user_data );
1123
1124
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
+ }
1127
1148
}
1128
1149
#endif /* CONFIG_BT_SETTINGS && CONFIG_BT_SMP && CONFIG_BT_GATT_CLIENT */
1129
1150
@@ -1498,13 +1519,24 @@ void bt_gatt_init(void)
1498
1519
#endif
1499
1520
1500
1521
#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
+
1501
1532
static struct bt_conn_cb gatt_conn_cb = {
1502
1533
.identity_resolved = bt_gatt_identity_resolved ,
1503
1534
};
1504
1535
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.
1508
1540
*/
1509
1541
bt_conn_cb_register (& gatt_conn_cb );
1510
1542
#endif /* CONFIG_BT_GATT_CLIENT && CONFIG_BT_SETTINGS && CONFIG_BT_SMP */
0 commit comments