diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 30f1b954767..d009837c167 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -1905,7 +1905,7 @@ int bt_mesh_comp_change_prepare(void) return bt_mesh_comp_store(); } -void bt_mesh_comp_clear(void) +static void comp_data_clear(void) { int err; @@ -2073,7 +2073,7 @@ int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset) } #endif -void bt_mesh_models_metadata_clear(void) +static void models_metadata_clear(void) { int err; @@ -2087,6 +2087,17 @@ void bt_mesh_models_metadata_clear(void) atomic_clear_bit(bt_mesh.flags, BT_MESH_METADATA_DIRTY); } +void bt_mesh_comp_data_pending_clear(void) +{ + comp_data_clear(); + models_metadata_clear(); +} + +void bt_mesh_comp_data_clear(void) +{ + bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_COMP_PENDING); +} + int bt_mesh_models_metadata_change_prepare(void) { #if !IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 7c86de4282c..86d7a212344 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -62,13 +62,14 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); int bt_mesh_comp_register(const struct bt_mesh_comp *comp); int bt_mesh_comp_store(void); -void bt_mesh_comp_clear(void); int bt_mesh_comp_read(struct net_buf_simple *buf); int bt_mesh_models_metadata_store(void); -void bt_mesh_models_metadata_clear(void); int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset); +void bt_mesh_comp_data_pending_clear(void); +void bt_mesh_comp_data_clear(void); + void bt_mesh_model_pending_store(void); void bt_mesh_model_bind_store(struct bt_mesh_model *mod); void bt_mesh_model_sub_store(struct bt_mesh_model *mod); diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 25de16bf104..099ed289112 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -130,7 +130,7 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, } if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_mesh_net_pending_net_store(); + bt_mesh_net_store(); } bt_mesh_start(); @@ -159,10 +159,9 @@ void bt_mesh_reprovision(uint16_t addr) if (IS_ENABLED(CONFIG_BT_SETTINGS)) { LOG_DBG("Storing network information persistently"); - bt_mesh_net_pending_net_store(); - bt_mesh_net_pending_seq_store(); - bt_mesh_comp_clear(); - bt_mesh_models_metadata_clear(); + bt_mesh_net_store(); + bt_mesh_net_seq_store(true); + bt_mesh_comp_data_clear(); } } diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 88f91a1ac83..c60e1df758c 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -189,9 +189,10 @@ static void store_iv(bool only_duration) } } -static void store_seq(void) +void bt_mesh_net_seq_store(bool force) { - if (CONFIG_BT_MESH_SEQ_STORE_RATE > 1 && + if (!force && + CONFIG_BT_MESH_SEQ_STORE_RATE > 1 && (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)) { return; } @@ -379,7 +380,7 @@ uint32_t bt_mesh_next_seq(void) uint32_t seq = bt_mesh.seq++; if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - store_seq(); + bt_mesh_net_seq_store(false); } if (!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) && @@ -1185,6 +1186,11 @@ void bt_mesh_net_pending_seq_store(void) } } +void bt_mesh_net_store(void) +{ + bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_NET_PENDING); +} + void bt_mesh_net_clear(void) { bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_NET_PENDING); diff --git a/subsys/bluetooth/mesh/net.h b/subsys/bluetooth/mesh/net.h index 2d9309a0ff7..02286b1ae40 100644 --- a/subsys/bluetooth/mesh/net.h +++ b/subsys/bluetooth/mesh/net.h @@ -303,6 +303,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi, void bt_mesh_net_loopback_clear(uint16_t net_idx); uint32_t bt_mesh_next_seq(void); +void bt_mesh_net_seq_store(bool force); void bt_mesh_net_init(void); void bt_mesh_net_header_parse(struct net_buf_simple *buf, @@ -312,6 +313,7 @@ void bt_mesh_net_pending_iv_store(void); void bt_mesh_net_pending_seq_store(void); void bt_mesh_net_dev_key_cand_store(void); +void bt_mesh_net_store(void); void bt_mesh_net_clear(void); void bt_mesh_net_settings_commit(void); diff --git a/subsys/bluetooth/mesh/settings.c b/subsys/bluetooth/mesh/settings.c index 7413407681e..89082264ea7 100644 --- a/subsys/bluetooth/mesh/settings.c +++ b/subsys/bluetooth/mesh/settings.c @@ -115,7 +115,8 @@ SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh, "bt/mesh", NULL, NULL, mesh_commit, BIT(BT_MESH_SETTINGS_CFG_PENDING) | \ BIT(BT_MESH_SETTINGS_MOD_PENDING) | \ BIT(BT_MESH_SETTINGS_VA_PENDING) | \ - BIT(BT_MESH_SETTINGS_SSEQ_PENDING)) + BIT(BT_MESH_SETTINGS_SSEQ_PENDING) | \ + BIT(BT_MESH_SETTINGS_COMP_PENDING)) void bt_mesh_settings_store_schedule(enum bt_mesh_settings_flag flag) { @@ -197,6 +198,11 @@ static void store_pending(struct k_work *work) bt_mesh_cfg_pending_store(); } + if (atomic_test_and_clear_bit(pending_flags, + BT_MESH_SETTINGS_COMP_PENDING)) { + bt_mesh_comp_data_pending_clear(); + } + if (atomic_test_and_clear_bit(pending_flags, BT_MESH_SETTINGS_MOD_PENDING)) { bt_mesh_model_pending_store(); diff --git a/subsys/bluetooth/mesh/settings.h b/subsys/bluetooth/mesh/settings.h index ac019e2e60e..10ce23d1106 100644 --- a/subsys/bluetooth/mesh/settings.h +++ b/subsys/bluetooth/mesh/settings.h @@ -19,6 +19,7 @@ enum bt_mesh_settings_flag { BT_MESH_SETTINGS_CDB_PENDING, BT_MESH_SETTINGS_SRPL_PENDING, BT_MESH_SETTINGS_SSEQ_PENDING, + BT_MESH_SETTINGS_COMP_PENDING, BT_MESH_SETTINGS_FLAG_COUNT, };