diff --git a/include/bluetooth/mesh/access.h b/include/bluetooth/mesh/access.h index fc1c23a857e..3ffd49cdf04 100644 --- a/include/bluetooth/mesh/access.h +++ b/include/bluetooth/mesh/access.h @@ -467,18 +467,19 @@ struct bt_mesh_model_cb { size_t len_rd, settings_read_cb read_cb, void *cb_arg); - /** @brief Callback called when all settings have been loaded. + /** @brief Callback called when the mesh is started. * - * This handler gets called after the settings have been loaded in - * full. + * This handler gets called after the node has been provisioned, or + * after all mesh data has been loaded from persistent storage. * - * @sa settings_handler::h_commit + * When this callback fires, the mesh model may start its behavior, + * and all Access APIs are ready for use. * - * @param model Model this callback belongs to. + * @param model Model this callback belongs to. * * @return 0 on success, error otherwise. */ - int (*const settings_commit)(struct bt_mesh_model *model); + int (*const start)(struct bt_mesh_model *model); /** @brief Model init callback. * diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 1b20b233e01..ac50e494974 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -83,7 +83,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, bt_mesh_store_iv(false); } - bt_mesh_net_start(); + bt_mesh_start(); return 0; } @@ -326,3 +326,19 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, return 0; } + +static void model_start(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, + bool vnd, bool primary, void *user_data) +{ + if (mod->cb && mod->cb->start) { + mod->cb->start(mod); + } +} + +int bt_mesh_start(void) +{ + bt_mesh_net_start(); + bt_mesh_model_foreach(model_start, NULL); + + return 0; +} diff --git a/subsys/bluetooth/mesh/mesh.h b/subsys/bluetooth/mesh/mesh.h index 2bba70f485b..78fc4572db5 100644 --- a/subsys/bluetooth/mesh/mesh.h +++ b/subsys/bluetooth/mesh/mesh.h @@ -15,3 +15,5 @@ #define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) struct bt_mesh_net; + +int bt_mesh_start(void); diff --git a/subsys/bluetooth/mesh/settings.c b/subsys/bluetooth/mesh/settings.c index 04321a5c6e6..4cb6f35487b 100644 --- a/subsys/bluetooth/mesh/settings.c +++ b/subsys/bluetooth/mesh/settings.c @@ -899,10 +899,6 @@ static void commit_mod(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, k_delayed_work_submit(&mod->pub->timer, ms); } } - - if (mod->cb && mod->cb->settings_commit) { - mod->cb->settings_commit(mod); - } } static int mesh_commit(void) @@ -962,7 +958,7 @@ static int mesh_commit(void) atomic_set_bit(bt_mesh.flags, BT_MESH_VALID); - bt_mesh_net_start(); + bt_mesh_start(); return 0; }