Bluetooth: Mesh: Add composition data page 128

Composition data page 128 represents the new composition data after a
composition refresh procedure. The implementation stores the old
composition data (before applying a DFU or similar), and uses that as
page 0 if present. As the device has already rebooted by the time page
128 becomes active, its active composition data is page 128, while the
backed up data is the "old" data, which should be shown as page 0.

Co-authored-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
This commit is contained in:
Trond Einar Snekvik 2020-03-13 15:58:47 +01:00 committed by Carles Cufí
commit 85431fd69e
6 changed files with 131 additions and 6 deletions

View file

@ -132,7 +132,11 @@ static int dev_comp_data_get(struct bt_mesh_model *model,
ctx->addr, buf->len, bt_hex(buf->data, buf->len));
page = net_buf_simple_pull_u8(buf);
if (page != 0U) {
if (page >= 128U && atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY)) {
LOG_DBG("Composition data page 128");
page = 128U;
} else if (page != 0U) {
LOG_DBG("Composition page %u not available", page);
page = 0U;
}
@ -140,10 +144,21 @@ static int dev_comp_data_get(struct bt_mesh_model *model,
bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS);
net_buf_simple_add_u8(&sdu, page);
err = bt_mesh_comp_get_page_0(&sdu);
if (err) {
LOG_ERR("Unable to get composition page 0");
return err;
if (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) == (page == 0U)) {
sdu.size -= BT_MESH_MIC_SHORT;
err = bt_mesh_comp_read(&sdu);
if (err) {
LOG_ERR("Unable to get stored composition data");
return err;
}
sdu.size += BT_MESH_MIC_SHORT;
} else {
err = bt_mesh_comp_get_page_0(&sdu);
if (err < 0) {
LOG_ERR("Unable to get composition page 0");
return err;
}
}
if (bt_mesh_model_send(model, ctx, &sdu, NULL, NULL)) {