Skip to content

Commit

Permalink
bluetooth: mesh: brg_cfg: fix restoring bridging table
Browse files Browse the repository at this point in the history
We store only filled up entries, but want to restore the entire table.
`bt_mesh_setting_set` fails if the restored length didn't match the
provided length.

This commit fixes the restoring of the bridging table by allowing to
restore any size as long as the stored size is less than the allocated
one and it is a multiple of the size of a single entry.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
  • Loading branch information
PavelVPV authored and nashif committed Sep 17, 2024
1 parent e1232a4 commit ceba348
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions subsys/bluetooth/mesh/brg_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,33 @@ BT_MESH_SETTINGS_DEFINE(brg_en, "brg_en", brg_en_set);
/* Set function for initializing bridging table rows from values stored in settings. */
static int brg_tbl_set(const char *name, size_t len_rd, settings_read_cb read_cb, void *cb_arg)
{
ssize_t len;

if (len_rd == 0) {
memset(brg_tbl, 0, sizeof(brg_tbl));
bt_mesh_brg_cfg_row_cnt = 0;
LOG_DBG("Cleared bridging table entries");
return 0;
}

int err = bt_mesh_settings_set(read_cb, cb_arg, brg_tbl, sizeof(brg_tbl));
if (len_rd % sizeof(brg_tbl[0])) {
LOG_ERR("Invalid data size");
return -EINVAL;
}

if (err) {
LOG_ERR("Failed to set bridging table entries");
return err;
if (len_rd > sizeof(brg_tbl)) {
LOG_ERR("Too many entries to fit in bridging table");
return -ENOMEM;
}

len = read_cb(cb_arg, brg_tbl, sizeof(brg_tbl));
if (len < 0 || len % sizeof(brg_tbl[0])) {
LOG_ERR("Failed to read bridging table entries (err %zd)", len);
return len < 0 ? len : -EINVAL;
}

LOG_DBG("Restored bridging table");
bt_mesh_brg_cfg_row_cnt = len / sizeof(brg_tbl[0]);
LOG_DBG("Restored %d entries in bridging table", bt_mesh_brg_cfg_row_cnt);

return 0;
}
Expand Down

0 comments on commit ceba348

Please sign in to comment.