Bluetooth: Mesh: Add option to disable Label UUIDs recovery

After adding support for virtual addresses with collision (where two
Label UUIDs have the same virtual address), the format of the data in
the persistent storage with the Label UUIDs which a model is subscribed
to or publishes to has been changed. The recovery code is added and the
Label UUIDs will be recovered by picking first Label UUID matching to
the virtual address in the subscription list or model publication. This
options can disable the recovery code and save some flash if the
recovery is not required (e.g. virtual address support wasn't enabled
before this option was added, or the devices were unprovisioned before
upgrading to the version with this option).

Making this option as deprecated to be able to drop support of this
option and remove the recovery code eventually.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Pavel Vasilyev 2023-06-01 14:59:45 +02:00 committed by Anas Nashif
parent 6bb97cc417
commit 47e3c5386a
2 changed files with 34 additions and 19 deletions

View file

@ -347,6 +347,21 @@ config BT_MESH_LABEL_COUNT
help
This option specifies how many Label UUIDs can be stored.
config BT_MESH_LABEL_NO_RECOVER
bool "[DEPRECATED] Don't recover Label UUIDs from groups address subscription list"
select DEPRECATED
depends on BT_MESH_LABEL_COUNT > 0
help
After adding support for virtual addresses with collision (where two Label UUIDs have the
same virtual address), the format of the data in the persistent storage with the Label
UUIDs which a model is subscribed to or publishes to has been changed. The recovery
code is added and the Label UUIDs will be recovered by picking first Label UUID matching
to the virtual address in the subscription list or model publication. This options can
disable the recovery code and save some flash if the recovery is not required (e.g.
virtual address support wasn't enabled before this option was added, or the devices were
unprovisioned before upgrading to the version with this option). The option is marked as
deprecated to remove the recovery code eventually.
config BT_MESH_CRPL
int "Maximum capacity of the replay protection list"
default 10

View file

@ -1650,7 +1650,7 @@ static int mod_set_sub(struct bt_mesh_model *mod, size_t len_rd,
LOG_DBG("Decoded %zu subscribed group addresses for model", len / sizeof(mod->groups[0]));
#if CONFIG_BT_MESH_LABEL_COUNT > 0
#if !IS_ENABLED(CONFIG_BT_MESH_LABEL_NO_RECOVER) && (CONFIG_BT_MESH_LABEL_COUNT > 0)
/* If uuids[0] is NULL, then either the model is not subscribed to virtual addresses or
* uuids are not yet recovered.
*/
@ -1739,25 +1739,27 @@ static int mod_set_pub(struct bt_mesh_model *mod, size_t len_rd,
return 0;
}
err = bt_mesh_settings_set(read_cb, cb_arg, &pub, sizeof(pub.base));
if (!err) {
/* Recover from implementation where uuid was not stored for virtual address. It
* is safe to pick first matched label because previously the stack wasn't able
* to store virtual addresses with collisions.
*/
if (BT_MESH_ADDR_IS_VIRTUAL(pub.base.addr)) {
mod->pub->uuid = bt_mesh_va_uuid_get(pub.base.addr, NULL, NULL);
}
if (!IS_ENABLED(CONFIG_BT_MESH_LABEL_NO_RECOVER)) {
err = bt_mesh_settings_set(read_cb, cb_arg, &pub, sizeof(pub.base));
if (!err) {
/* Recover from implementation where uuid was not stored for virtual
* address. It is safe to pick first matched label because previously the
* stack wasn't able to store virtual addresses with collisions.
*/
if (BT_MESH_ADDR_IS_VIRTUAL(pub.base.addr)) {
mod->pub->uuid = bt_mesh_va_uuid_get(pub.base.addr, NULL, NULL);
}
goto pub_base_set;
} else {
err = bt_mesh_settings_set(read_cb, cb_arg, &pub, sizeof(pub));
if (err) {
LOG_ERR("Failed to set \'model-pub\'");
return err;
goto pub_base_set;
}
}
err = bt_mesh_settings_set(read_cb, cb_arg, &pub, sizeof(pub));
if (err) {
LOG_ERR("Failed to set \'model-pub\'");
return err;
}
if (BT_MESH_ADDR_IS_VIRTUAL(pub.base.addr)) {
mod->pub->uuid = bt_mesh_va_get_uuid_by_idx(pub.uuidx);
}
@ -2008,9 +2010,7 @@ static void store_pending_mod_pub(struct bt_mesh_model *mod, bool vnd)
(void)bt_mesh_va_get_idx_by_uuid(mod->pub->uuid, &pub.uuidx);
}
err = settings_save_one(path, &pub,
BT_MESH_ADDR_IS_VIRTUAL(mod->pub->addr) ? sizeof(pub) :
sizeof(pub.base));
err = settings_save_one(path, &pub, sizeof(pub));
}
if (err) {