From c44a3f12094126bdd77418064f24c9e8781f9646 Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 2 Sep 2019 14:16:33 +0800 Subject: [PATCH] ble_mesh: fix RPL storage timeout handling --- components/bt/esp_ble_mesh/mesh_core/net.h | 2 +- .../bt/esp_ble_mesh/mesh_core/settings.c | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/net.h b/components/bt/esp_ble_mesh/mesh_core/net.h index 90515fd2ca..28cd91ce87 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.h +++ b/components/bt/esp_ble_mesh/mesh_core/net.h @@ -209,7 +209,7 @@ enum { BLE_MESH_IVU_TEST, /* IV Update test mode */ BLE_MESH_IVU_PENDING, /* Update blocked by SDU in progress */ - /* pending storage actions */ + /* pending storage actions, must reside within first 32 flags */ BLE_MESH_RPL_PENDING, BLE_MESH_KEYS_PENDING, BLE_MESH_NET_PENDING, diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index adf63e5073..0a6a8b9c25 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -833,19 +833,29 @@ int settings_core_commit(void) return 0; } +/* Pending flags that use K_NO_WAIT as the storage timeout */ +#define NO_WAIT_PENDING_BITS (BIT(BLE_MESH_NET_PENDING) | \ + BIT(BLE_MESH_IV_PENDING) | \ + BIT(BLE_MESH_SEQ_PENDING)) + +/* Pending flags that use CONFIG_BLE_MESH_STORE_TIMEOUT */ +#define GENERIC_PENDING_BITS (BIT(BLE_MESH_KEYS_PENDING) | \ + BIT(BLE_MESH_HB_PUB_PENDING) | \ + BIT(BLE_MESH_CFG_PENDING) | \ + BIT(BLE_MESH_MOD_PENDING)) + static void schedule_store(int flag) { s32_t timeout; bt_mesh_atomic_set_bit(bt_mesh.flags, flag); - if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_NET_PENDING) || - bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IV_PENDING) || - bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_SEQ_PENDING)) { + if (bt_mesh_atomic_get(bt_mesh.flags) & NO_WAIT_PENDING_BITS) { timeout = K_NO_WAIT; } else if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING) && - (CONFIG_BLE_MESH_RPL_STORE_TIMEOUT < - CONFIG_BLE_MESH_STORE_TIMEOUT)) { + (!(bt_mesh_atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) || + (CONFIG_BLE_MESH_RPL_STORE_TIMEOUT < + CONFIG_BLE_MESH_STORE_TIMEOUT))) { timeout = K_SECONDS(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT); } else { timeout = K_SECONDS(CONFIG_BLE_MESH_STORE_TIMEOUT);