Skip to content

Commit

Permalink
Bluetooth: Mesh: Fix RPL storage timeout handling
Browse files Browse the repository at this point in the history
The default values for the timeouts, as well as non-defaults in most
Mesh samples, use a higher value for the RPL than then generic mesh
storage timeout. This hasn't had any effect in practice since the code
only uses the RPL timeout if it is *smaller* than the generic one.

The original intention of the code was to use the RPL timeout,
regardless of what the generic one is, whenever the RPL is the only
thing that needs updating. Add some helper macros to track the various
groups of pending flags, and perform the appropriate checks to apply
the RPL timeout whenever it's smaller than the generic timeout, or if
there are no other items to store besides the RPL.

Fixes #15904

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
jhedberg committed May 7, 2019
1 parent 9d34356 commit c0a7e4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/mesh/net.h
Expand Up @@ -200,7 +200,7 @@ enum {
BT_MESH_IVU_TEST, /* IV Update test mode */
BT_MESH_IVU_PENDING, /* Update blocked by SDU in progress */

/* pending storage actions */
/* pending storage actions, must reside within first 32 flags */
BT_MESH_RPL_PENDING,
BT_MESH_KEYS_PENDING,
BT_MESH_NET_PENDING,
Expand Down
20 changes: 15 additions & 5 deletions subsys/bluetooth/host/mesh/settings.c
Expand Up @@ -808,19 +808,29 @@ static int mesh_commit(void)

BT_SETTINGS_DEFINE(mesh, mesh_set, mesh_commit, NULL);

/* Pending flags that use K_NO_WAIT as the storage timeout */
#define NO_WAIT_PENDING_BITS (BIT(BT_MESH_NET_PENDING) | \
BIT(BT_MESH_IV_PENDING) | \
BIT(BT_MESH_SEQ_PENDING))

/* Pending flags that use CONFIG_BT_MESH_STORE_TIMEOUT */
#define GENERIC_PENDING_BITS (BIT(BT_MESH_KEYS_PENDING) | \
BIT(BT_MESH_HB_PUB_PENDING) | \
BIT(BT_MESH_CFG_PENDING) | \
BIT(BT_MESH_MOD_PENDING))

static void schedule_store(int flag)
{
s32_t timeout;

atomic_set_bit(bt_mesh.flags, flag);

if (atomic_test_bit(bt_mesh.flags, BT_MESH_NET_PENDING) ||
atomic_test_bit(bt_mesh.flags, BT_MESH_IV_PENDING) ||
atomic_test_bit(bt_mesh.flags, BT_MESH_SEQ_PENDING)) {
if (atomic_get(bt_mesh.flags) & NO_WAIT_PENDING_BITS) {
timeout = K_NO_WAIT;
} else if (atomic_test_bit(bt_mesh.flags, BT_MESH_RPL_PENDING) &&
(CONFIG_BT_MESH_RPL_STORE_TIMEOUT <
CONFIG_BT_MESH_STORE_TIMEOUT)) {
(!(atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) ||
(CONFIG_BT_MESH_RPL_STORE_TIMEOUT <
CONFIG_BT_MESH_STORE_TIMEOUT))) {
timeout = K_SECONDS(CONFIG_BT_MESH_RPL_STORE_TIMEOUT);
} else {
timeout = K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT);
Expand Down

0 comments on commit c0a7e4d

Please sign in to comment.