From 54f18a4fa3a24bb5b3d60e090508768d3325239b Mon Sep 17 00:00:00 2001 From: wangjialiang Date: Sat, 8 Oct 2022 16:20:26 +0800 Subject: [PATCH] ble_mesh: stack: Add IV index recovery option when device missed the whole IV update --- components/bt/esp_ble_mesh/Kconfig.in | 15 +++++++++++++++ components/bt/esp_ble_mesh/mesh_core/net.c | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index 521d7a03ae26..91b41fc23f3b 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -585,6 +585,21 @@ if BLE_MESH stored to flash. E.g. the default value of 4 means that the state is saved every 24 hours (96 / 4). + config BLE_MESH_IVU_RECOVERY_IVI + bool "Recovery the IV index when the latest whole IV update procedure is missed" + default n + help + According to Section 3.10.5 of Mesh Specification v1.0.1. + If a node in Normal Operation receives a Secure Network beacon with an IV index + equal to the last known IV index+1 and the IV Update Flag set to 0, the node may + update its IV without going to the IV Update in Progress state, or it may initiate + an IV Index Recovery procedure (Section 3.10.6), or it may ignore the Secure + Network beacon. The node makes the choice depending on the time since last IV + update and the likelihood that the node has missed the Secure Network beacons + with the IV update Flag. + When the above situation is encountered, this option can be used to decide whether + to perform the IV index recovery procedure. + config BLE_MESH_TX_SEG_MSG_COUNT int "Maximum number of simultaneous outgoing segmented messages" default 1 diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index 40520f2e05f4..26adf5ce3fc7 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -673,7 +673,11 @@ bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update) return false; } - if (iv_index > bt_mesh.iv_index + 1) { + if ((iv_index > bt_mesh.iv_index + 1) +#if CONFIG_BLE_MESH_IVU_RECOVERY_IVI + || (iv_index == bt_mesh.iv_index + 1 && !iv_update) +#endif + ) { BT_WARN("Performing IV Index Recovery"); (void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); bt_mesh.iv_index = iv_index; @@ -681,10 +685,12 @@ bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update) goto do_update; } +#if !CONFIG_BLE_MESH_IVU_RECOVERY_IVI if (iv_index == bt_mesh.iv_index + 1 && !iv_update) { BT_WARN("Ignoring new index in normal mode"); return false; } +#endif if (!iv_update) { /* Nothing to do */