Skip to content

Commit 17f15b8

Browse files
committed
settings: multi-controller adapt.
Change-Id: I4cd69f9b2be6c786fc4921ecdae5fb15f8754ddb Signed-off-by: liuxiang18 <[email protected]>
1 parent 407b33e commit 17f15b8

File tree

11 files changed

+297
-197
lines changed

11 files changed

+297
-197
lines changed

subsys/bluetooth/host/classic/keys_br.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "common/bt_str.h"
2020

21+
// #include "iso_internal.h"
22+
// #include "conn_internal.h"
2123
#include "host/hci_core.h"
2224
#include "host/settings.h"
2325
#include "host/keys.h"
@@ -96,7 +98,7 @@ void bt_keys_link_key_clear(struct bt_dev *hdev, struct bt_keys_link_key *link_k
9698
le_addr.type = BT_ADDR_LE_PUBLIC;
9799
bt_addr_copy(&le_addr.a, &link_key->addr);
98100

99-
bt_settings_delete_link_key(&le_addr);
101+
bt_settings_delete_link_key(hdev->dev_id, &le_addr);
100102
}
101103

102104
LOG_DBG("%s", bt_addr_str(&link_key->addr));
@@ -131,7 +133,7 @@ void bt_keys_link_key_store(struct bt_dev *hdev, struct bt_keys_link_key *link_k
131133
le_addr.type = BT_ADDR_LE_PUBLIC;
132134
bt_addr_copy(&le_addr.a, &link_key->addr);
133135

134-
err = bt_settings_store_link_key(&le_addr, link_key->storage_start,
136+
err = bt_settings_store_link_key(hdev->dev_id, &le_addr, link_key->storage_start,
135137
BT_KEYS_LINK_KEY_STORAGE_LEN);
136138
if (err) {
137139
LOG_ERR("Failed to save link key (err %d)", err);
@@ -164,14 +166,16 @@ void bt_foreach_bond_br_mc(uint8_t dev_id, void (*func)(const struct bt_bond_inf
164166

165167
#if defined(CONFIG_BT_SETTINGS)
166168

167-
static int link_key_set(struct bt_dev *hdev, const char *name, size_t len_rd,
169+
static int link_key_set(const char *name, size_t len_rd,
168170
settings_read_cb read_cb, void *cb_arg)
169171
{
170172
int err;
171173
ssize_t len;
172174
bt_addr_le_t le_addr;
173175
struct bt_keys_link_key *link_key;
174176
char val[BT_KEYS_LINK_KEY_STORAGE_LEN];
177+
const char *dev_next;
178+
struct bt_dev *hdev;
175179

176180
if (!name) {
177181
LOG_ERR("Insufficient number of arguments");
@@ -192,6 +196,14 @@ static int link_key_set(struct bt_dev *hdev, const char *name, size_t len_rd,
192196
return -EINVAL;
193197
}
194198

199+
settings_name_next(name, &dev_next);
200+
unsigned long dev_id = strtoul(dev_next, NULL, 10);
201+
hdev = bt_dev_get(dev_id);
202+
if (!hdev) {
203+
LOG_ERR("Failed to find corresponding bt_dev:%u", dev_id);
204+
return -ENODEV;
205+
}
206+
195207
link_key = bt_keys_get_link_key(hdev, &le_addr.a);
196208
if (len != BT_KEYS_LINK_KEY_STORAGE_LEN) {
197209
if (link_key) {

subsys/bluetooth/host/gatt.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
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_
515517
done:
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

64896493
static 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
}

subsys/bluetooth/host/gatt_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void bt_gatt_disconnected(struct bt_conn *conn);
3737

3838
bool bt_gatt_change_aware(struct bt_conn *conn, bool req);
3939

40-
int bt_gatt_store_ccc(uint8_t id, const bt_addr_le_t *addr);
40+
int bt_gatt_store_ccc(struct bt_dev *hdev, uint8_t id, const bt_addr_le_t *addr);
4141

4242
int bt_gatt_clear(struct bt_dev *hdev, uint8_t id, const bt_addr_le_t *addr);
4343

subsys/bluetooth/host/hci_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "common/rpa.h"
4444
#include "keys.h"
4545
#include "monitor.h"
46+
// #include "conn_internal.h"
47+
// #include "iso_internal.h"
4648
#include "hci_core.h"
4749
#include "ecc.h"
4850
#include "id.h"
@@ -4485,7 +4487,7 @@ int bt_enable_mc(uint8_t dev_id, bt_ready_cb_t cb)
44854487
#endif
44864488

44874489
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
4488-
err = bt_settings_init();
4490+
err = bt_settings_init(hdev);
44894491
if (err) {
44904492
return err;
44914493
}
@@ -4707,7 +4709,7 @@ int bt_set_name_mc(uint8_t dev_id, const char *name)
47074709
hdev->name[len] = '\0';
47084710

47094711
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
4710-
err = bt_settings_store_name_mc(hdev->name, len);
4712+
err = bt_settings_store_name(hdev->dev_id, hdev->name, len);
47114713
if (err) {
47124714
LOG_WRN("Unable to store name");
47134715
}

subsys/bluetooth/host/hci_core.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,24 @@ struct bt_dev {
522522
bt_dh_key_cb_t dh_key_cb;
523523
#endif
524524

525+
#if defined(CONFIG_BT_SETTINGS)
526+
527+
/* Work used to process store id */
528+
struct k_work store_id_work;
529+
530+
/* Work used to process store irk */
531+
struct k_work store_irk_work;
532+
533+
534+
// sys_slist_t settings_load_srcs;
535+
536+
// struct settings_store *settings_save_dst;
537+
538+
// #if defined(CONFIG_SETTINGS_VELA)
539+
// sys_slist_t bt_settings_cbs;
540+
// #endif
541+
#endif
542+
525543
/* ATT context */
526544
struct bt_dev_att_ctx *att_ctx;
527545

subsys/bluetooth/host/id.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,8 @@ static int id_create(struct bt_dev *hdev, uint8_t id, bt_addr_le_t *addr, uint8_
13461346
*/
13471347
if (IS_ENABLED(CONFIG_BT_SETTINGS) &&
13481348
atomic_test_bit(hdev->flags, BT_DEV_READY)) {
1349-
(void)bt_settings_store_id();
1350-
(void)bt_settings_store_irk();
1349+
(void)bt_settings_store_id(hdev);
1350+
(void)bt_settings_store_irk(hdev);
13511351
}
13521352

13531353
return 0;
@@ -1528,8 +1528,8 @@ int bt_id_delete_mc(uint8_t dev_id, uint8_t id)
15281528

15291529
if (IS_ENABLED(CONFIG_BT_SETTINGS) &&
15301530
atomic_test_bit(hdev->flags, BT_DEV_READY)) {
1531-
(void)bt_settings_store_id();
1532-
(void)bt_settings_store_irk();
1531+
(void)bt_settings_store_id(hdev);
1532+
(void)bt_settings_store_irk(hdev);
15331533
}
15341534

15351535
return 0;

0 commit comments

Comments
 (0)