4040
4141#include "common/bt_str.h"
4242
43+ // #include "iso_internal.h"
4344#include "hci_core.h"
4445#include "conn_internal.h"
46+ // #include "hci_core.h"
4547#include "keys.h"
4648#include "l2cap_internal.h"
4749#include "att_internal.h"
@@ -384,11 +386,11 @@ static struct gatt_sc_cfg *find_sc_cfg(struct bt_dev *hdev, uint8_t id, const bt
384386 return NULL ;
385387}
386388
387- static void sc_store (struct gatt_sc_cfg * cfg )
389+ static void sc_store (struct bt_dev * hdev , struct gatt_sc_cfg * cfg )
388390{
389391 int err ;
390392
391- err = bt_settings_store_sc (cfg -> id , & cfg -> peer , & cfg -> data , sizeof (cfg -> data ));
393+ err = bt_settings_store_sc (hdev -> dev_id , cfg -> id , & cfg -> peer , & cfg -> data , sizeof (cfg -> data ));
392394 if (err ) {
393395 LOG_ERR ("failed to store SC (err %d)" , err );
394396 return ;
@@ -416,7 +418,7 @@ static int bt_gatt_clear_sc(struct bt_dev *hdev, uint8_t id, const bt_addr_le_t
416418 if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
417419 int err ;
418420
419- err = bt_settings_delete_sc (cfg -> id , & cfg -> peer );
421+ err = bt_settings_delete_sc (hdev -> dev_id , cfg -> id , & cfg -> peer );
420422 if (err ) {
421423 LOG_ERR ("failed to delete SC (err %d)" , err );
422424 } else {
@@ -448,14 +450,14 @@ static void sc_clear(struct bt_conn *conn)
448450 }
449451}
450452
451- static void sc_reset (struct gatt_sc_cfg * cfg )
453+ static void sc_reset (struct bt_dev * hdev , struct gatt_sc_cfg * cfg )
452454{
453455 LOG_DBG ("peer %s" , bt_addr_le_str (& cfg -> peer ));
454456
455457 memset (& cfg -> data , 0 , sizeof (cfg -> data ));
456458
457459 if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
458- sc_store (cfg );
460+ sc_store (hdev , cfg );
459461 }
460462}
461463
@@ -515,7 +517,7 @@ static void sc_save(struct bt_dev *hdev, uint8_t id, bt_addr_le_t *peer, uint16_
515517done :
516518 if (IS_ENABLED (CONFIG_BT_SETTINGS ) &&
517519 modified && bt_addr_le_is_bonded (hdev , cfg -> id , & cfg -> peer )) {
518- sc_store (cfg );
520+ sc_store (hdev , cfg );
519521 }
520522}
521523
@@ -1202,7 +1204,7 @@ static void bt_gatt_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *
12021204
12031205 /* Store the ccc */
12041206 if (is_bonded ) {
1205- bt_gatt_store_ccc (conn -> id , & conn -> le .dst );
1207+ bt_gatt_store_ccc (conn -> hdev , conn -> id , & conn -> le .dst );
12061208 }
12071209
12081210 /* Update the cf addresses and store it if we get a match */
@@ -1211,7 +1213,7 @@ static void bt_gatt_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *
12111213 if (cfg ) {
12121214 bt_addr_le_copy (& cfg -> peer , id_addr );
12131215 if (is_bonded ) {
1214- bt_gatt_store_cf (conn -> id , & conn -> le .dst );
1216+ bt_gatt_store_cf (conn -> hdev , conn -> id , & conn -> le .dst );
12151217 }
12161218 }
12171219}
@@ -1220,8 +1222,8 @@ static void bt_gatt_pairing_complete(struct bt_conn *conn, bool bonded)
12201222{
12211223 if (bonded ) {
12221224 /* Store the ccc and cf data */
1223- bt_gatt_store_ccc (conn -> id , & (conn -> le .dst ));
1224- bt_gatt_store_cf (conn -> id , & conn -> le .dst );
1225+ bt_gatt_store_ccc (conn -> hdev , conn -> id , & (conn -> le .dst ));
1226+ bt_gatt_store_cf (conn -> hdev , conn -> id , & conn -> le .dst );
12251227 }
12261228}
12271229#endif /* CONFIG_BT_SETTINGS && CONFIG_BT_SMP */
@@ -1528,7 +1530,7 @@ static void gatt_store_ccc_cf(struct bt_dev *hdev, uint8_t id, const bt_addr_le_
15281530 if (!IS_ENABLED (CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE ) ||
15291531 (IS_ENABLED (CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE ) && el &&
15301532 atomic_test_and_clear_bit (el -> flags , DELAYED_STORE_CCC ))) {
1531- bt_gatt_store_ccc (id , peer_addr );
1533+ bt_gatt_store_ccc (hdev , id , peer_addr );
15321534 }
15331535
15341536 if (!IS_ENABLED (CONFIG_BT_SETTINGS_CF_STORE_ON_WRITE ) ||
@@ -1732,7 +1734,7 @@ static void gatt_unregister_ccc(struct bt_dev *hdev, struct _bt_gatt_ccc *ccc)
17321734
17331735 if (IS_ENABLED (CONFIG_BT_SETTINGS ) && store &&
17341736 bt_addr_le_is_bonded (hdev , cfg -> id , & cfg -> peer )) {
1735- bt_gatt_store_ccc (cfg -> id , & cfg -> peer );
1737+ bt_gatt_store_ccc (hdev , cfg -> id , & cfg -> peer );
17361738 }
17371739
17381740 clear_ccc_cfg (cfg );
@@ -3381,7 +3383,7 @@ static void sc_restore_rsp(struct bt_conn *conn,
33813383 struct gatt_sc_cfg * gsc_cfg = find_sc_cfg (conn -> hdev , conn -> id , & conn -> le .dst );
33823384
33833385 if (gsc_cfg ) {
3384- sc_reset (gsc_cfg );
3386+ sc_reset (conn -> hdev , gsc_cfg );
33853387 }
33863388 }
33873389}
@@ -6177,10 +6179,10 @@ void bt_gatt_connected(struct bt_conn *conn)
61776179 char id_str [4 ];
61786180
61796181 u8_to_dec (id_str , sizeof (id_str ), conn -> id );
6180- bt_settings_encode_key (key , sizeof (key ), "ccc" ,
6182+ bt_settings_encode_key (dev_id , key , sizeof (key ), "ccc" ,
61816183 & conn -> le .dst , id_str );
61826184 } else {
6183- bt_settings_encode_key (key , sizeof (key ), "ccc" ,
6185+ bt_settings_encode_key (dev_id , key , sizeof (key ), "ccc" ,
61846186 & conn -> le .dst , NULL );
61856187 }
61866188
@@ -6375,7 +6377,7 @@ static uint8_t ccc_save(const struct bt_gatt_attr *attr, uint16_t handle,
63756377 return BT_GATT_ITER_CONTINUE ;
63766378}
63776379
6378- int bt_gatt_store_ccc (uint8_t id , const bt_addr_le_t * addr )
6380+ int bt_gatt_store_ccc (struct bt_dev * hdev , uint8_t id , const bt_addr_le_t * addr )
63796381{
63806382 struct ccc_save save ;
63816383 size_t len ;
@@ -6397,7 +6399,7 @@ int bt_gatt_store_ccc(uint8_t id, const bt_addr_le_t *addr)
63976399 len = 0 ;
63986400 }
63996401
6400- err = bt_settings_store_ccc (id , addr , str , len );
6402+ err = bt_settings_store_ccc (hdev -> dev_id , id , addr , str , len );
64016403 if (err ) {
64026404 LOG_ERR ("Failed to store CCCs (err %d)" , err );
64036405 return err ;
@@ -6426,6 +6428,7 @@ static int sc_set(const char *name, size_t len_rd, settings_read_cb read_cb,
64266428 ssize_t len ;
64276429 int err ;
64286430 const char * next ;
6431+ struct bt_dev * hdev ;
64296432
64306433 if (!name ) {
64316434 LOG_ERR ("Insufficient number of arguments" );
@@ -6453,10 +6456,11 @@ static int sc_set(const char *name, size_t len_rd, settings_read_cb read_cb,
64536456 id = (uint8_t )next_id ;
64546457 }
64556458
6456- cfg = find_sc_cfg (id , & addr );
6459+ hdev = bt_dev_get (id );
6460+ cfg = find_sc_cfg (hdev , id , & addr );
64576461 if (!cfg && len_rd ) {
64586462 /* Find and initialize a free sc_cfg entry */
6459- cfg = find_sc_cfg (BT_ID_DEFAULT , BT_ADDR_LE_ANY );
6463+ cfg = find_sc_cfg (hdev , BT_ID_DEFAULT , BT_ADDR_LE_ANY );
64606464 if (!cfg ) {
64616465 LOG_ERR ("Unable to restore SC: no cfg left" );
64626466 return - ENOMEM ;
@@ -6488,12 +6492,15 @@ static int sc_set(const char *name, size_t len_rd, settings_read_cb read_cb,
64886492
64896493static int sc_commit (void )
64906494{
6495+ struct bt_dev * hdev ;
6496+
6497+ hdev = bt_dev_get (0 );
64916498 atomic_set_bit (hdev -> gatt_ctx -> gatt_sc .flags , SC_LOAD );
64926499 atomic_clear_bit (hdev -> gatt_ctx -> gatt_sc .flags , SC_INDICATE_PENDING );
64936500
64946501 if (atomic_test_bit (hdev -> gatt_ctx -> gatt_sc .flags , SC_RANGE_CHANGED )) {
64956502 /* Schedule SC indication since the range has changed */
6496- sc_work_submit (SC_TIMEOUT );
6503+ sc_work_submit (hdev , SC_TIMEOUT );
64976504 }
64986505
64996506 return 0 ;
@@ -6646,7 +6653,7 @@ static uint8_t remove_peer_from_attr(const struct bt_gatt_attr *attr,
66466653 return BT_GATT_ITER_CONTINUE ;
66476654}
66486655
6649- static int bt_gatt_clear_ccc (uint8_t id , const bt_addr_le_t * addr )
6656+ static int bt_gatt_clear_ccc (struct bt_dev * hdev , uint8_t id , const bt_addr_le_t * addr )
66506657{
66516658 struct addr_with_id addr_with_id = {
66526659 .addr = addr ,
@@ -6657,7 +6664,7 @@ static int bt_gatt_clear_ccc(uint8_t id, const bt_addr_le_t *addr)
66576664 & addr_with_id );
66586665
66596666 if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
6660- return bt_settings_delete_ccc (id , addr );
6667+ return bt_settings_delete_ccc (hdev -> dev_id , id , addr );
66616668 }
66626669
66636670 return 0 ;
@@ -6673,7 +6680,7 @@ static int bt_gatt_clear_cf(struct bt_dev *hdev, uint8_t id, const bt_addr_le_t
66736680 }
66746681
66756682 if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
6676- return bt_settings_delete_ccc (id , addr );
6683+ return bt_settings_delete_ccc (hdev -> dev_id , id , addr );
66776684 }
66786685
66796686 return 0 ;
@@ -6717,7 +6724,7 @@ int bt_gatt_clear(struct bt_dev *hdev, uint8_t id, const bt_addr_le_t *addr)
67176724{
67186725 int err ;
67196726
6720- err = bt_gatt_clear_ccc (id , addr );
6727+ err = bt_gatt_clear_ccc (hdev , id , addr );
67216728 if (err < 0 ) {
67226729 return err ;
67236730 }
0 commit comments