Bluetooth: Mesh: Only settings load post mesh init
Prevent mesh stored settings from triggering unless bt_mesh_init has been called. Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
This commit is contained in:
parent
f8ac6b6d66
commit
52a39c0180
4 changed files with 28 additions and 4 deletions
|
@ -46,6 +46,11 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
|
||||||
const uint8_t dev_key[16])
|
const uint8_t dev_key[16])
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) {
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
struct bt_mesh_cdb_subnet *subnet = NULL;
|
struct bt_mesh_cdb_subnet *subnet = NULL;
|
||||||
|
|
||||||
LOG_INF("Primary Element: 0x%04x", addr);
|
LOG_INF("Primary Element: 0x%04x", addr);
|
||||||
|
@ -172,7 +177,8 @@ int bt_mesh_provision_gatt(const uint8_t uuid[16], uint16_t net_idx, uint16_t ad
|
||||||
|
|
||||||
void bt_mesh_reset(void)
|
void bt_mesh_reset(void)
|
||||||
{
|
{
|
||||||
if (!atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) {
|
if (!atomic_test_bit(bt_mesh.flags, BT_MESH_VALID) ||
|
||||||
|
!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +187,7 @@ void bt_mesh_reset(void)
|
||||||
bt_mesh.seq = 0U;
|
bt_mesh.seq = 0U;
|
||||||
|
|
||||||
memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags));
|
memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags));
|
||||||
|
atomic_set_bit(bt_mesh.flags, BT_MESH_INIT);
|
||||||
|
|
||||||
/* If this fails, the work handler will return early on the next
|
/* If this fails, the work handler will return early on the next
|
||||||
* execution, as the device is not provisioned. If the device is
|
* execution, as the device is not provisioned. If the device is
|
||||||
|
@ -337,6 +344,10 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (atomic_test_and_set_bit(bt_mesh.flags, BT_MESH_INIT)) {
|
||||||
|
return -EALREADY;
|
||||||
|
}
|
||||||
|
|
||||||
err = bt_mesh_test();
|
err = bt_mesh_test();
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -167,6 +167,7 @@ struct bt_mesh_lpn {
|
||||||
|
|
||||||
/* bt_mesh_net.flags */
|
/* bt_mesh_net.flags */
|
||||||
enum {
|
enum {
|
||||||
|
BT_MESH_INIT, /* We have been initialized */
|
||||||
BT_MESH_VALID, /* We have been provisioned */
|
BT_MESH_VALID, /* We have been provisioned */
|
||||||
BT_MESH_SUSPENDED, /* Network is temporarily suspended */
|
BT_MESH_SUSPENDED, /* Network is temporarily suspended */
|
||||||
BT_MESH_IVU_IN_PROGRESS, /* IV Update in Progress */
|
BT_MESH_IVU_IN_PROGRESS, /* IV Update in Progress */
|
||||||
|
|
|
@ -65,6 +65,10 @@ int bt_mesh_settings_set(settings_read_cb read_cb, void *cb_arg,
|
||||||
|
|
||||||
static int mesh_commit(void)
|
static int mesh_commit(void)
|
||||||
{
|
{
|
||||||
|
if (!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!atomic_test_bit(bt_dev.flags, BT_DEV_ENABLE)) {
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_ENABLE)) {
|
||||||
/* The Bluetooth mesh settings loader calls bt_mesh_start() immediately
|
/* The Bluetooth mesh settings loader calls bt_mesh_start() immediately
|
||||||
* after loading the settings. This is not intended to work before
|
* after loading the settings. This is not intended to work before
|
||||||
|
|
|
@ -22,9 +22,17 @@ enum bt_mesh_settings_flag {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_BT_SETTINGS
|
#ifdef CONFIG_BT_SETTINGS
|
||||||
#define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set) \
|
#define BT_MESH_SETTINGS_DEFINE(_hname, _subtree, _set) \
|
||||||
SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh_##_hname, "bt/mesh/" _subtree, \
|
static int pre_##_set(const char *name, size_t len_rd, settings_read_cb read_cb, \
|
||||||
NULL, _set, NULL, NULL)
|
void *cb_arg) \
|
||||||
|
{ \
|
||||||
|
if (!atomic_test_bit(bt_mesh.flags, BT_MESH_INIT)) { \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
return _set(name, len_rd, read_cb, cb_arg); \
|
||||||
|
} \
|
||||||
|
SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh_##_hname, "bt/mesh/" _subtree, NULL, pre_##_set, \
|
||||||
|
NULL, NULL)
|
||||||
#else
|
#else
|
||||||
/* Declaring non static settings handler helps avoid unnecessary ifdefs
|
/* Declaring non static settings handler helps avoid unnecessary ifdefs
|
||||||
* as well as unused function warning. Since the declared handler structure is
|
* as well as unused function warning. Since the declared handler structure is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue