From fa85443a441b53549315ad6b12ff5a126ecefee3 Mon Sep 17 00:00:00 2001 From: luoxu Date: Wed, 20 Dec 2023 15:41:59 +0800 Subject: [PATCH 1/2] feat(ble_mesh): Miscellaneous updates for mesh kconfig, relay related --- components/bt/esp_ble_mesh/Kconfig.in | 22 +++++++++++++++++++ components/bt/esp_ble_mesh/mesh_core/net.c | 10 ++++++--- components/bt/esp_ble_mesh/mesh_core/net.h | 3 +++ .../bt/esp_ble_mesh/mesh_core/transport.c | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index d9983bf6ce..08950d41d2 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -538,6 +538,20 @@ if BLE_MESH Provisioner can provision up to 20 nodes and each node contains two elements, then the replay protection list size of Provisioner should be at least 40. + config BLE_MESH_NOT_RELAY_REPLAY_MSG + bool "Not relay replayed messages in a mesh network" + depends on BLE_MESH_EXPERIMENTAL + default n + help + There may be many expired messages in a complex mesh network that would be + considered replayed messages. + Enable this option will refuse to relay such messages, which could help to + reduce invalid packets in the mesh network. + However, it should be noted that enabling this option may result in packet + loss in certain environments. + Therefore, users need to decide whether to enable this option according to + the actual usage situation. + config BLE_MESH_MSG_CACHE_SIZE int "Network message cache size" default 10 @@ -1241,4 +1255,12 @@ if BLE_MESH endmenu + config BLE_MESH_EXPERIMENTAL + bool "Make BLE Mesh experimental features visible" + default n + help + Make BLE Mesh Experimental features visible. + Experimental features list: + - CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG + endif # BLE_MESH diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index 2ca480f186..93b02a515e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -2,7 +2,7 @@ /* * SPDX-FileCopyrightText: 2017 Intel Corporation - * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1265,7 +1265,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, #endif if (!buf) { - BT_ERR("Out of relay buffers"); + BT_INFO("Out of relay buffers"); return; } @@ -1509,7 +1509,11 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi, * was neither a local element nor an LPN we're Friends for. */ if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) || - (!rx.local_match && !rx.friend_match)) { + (!rx.local_match && !rx.friend_match +#if CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG + && !rx.replay_msg +#endif + )) { net_buf_simple_restore(&buf, &state); bt_mesh_net_relay(&buf, &rx); } diff --git a/components/bt/esp_ble_mesh/mesh_core/net.h b/components/bt/esp_ble_mesh/mesh_core/net.h index f982c41cee..1ba79e65d7 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.h +++ b/components/bt/esp_ble_mesh/mesh_core/net.h @@ -294,6 +294,9 @@ struct bt_mesh_net_rx { ctl:1, /* Network Control */ net_if:2, /* Network interface */ local_match:1, /* Matched a local element */ +#if CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG + replay_msg:1, /* Replayed messages */ +#endif friend_match:1; /* Matched an LPN we're friends for */ uint16_t msg_cache_idx; /* Index of entry in message cache */ }; diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index 7d3f45310d..6cbf7d9fd5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -711,6 +711,9 @@ bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match) return false; } else { +#if CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG + rx->replay_msg = 1; +#endif return true; } } From 268fbf83c1d47d2b2448a405bd37473ac5bd6be8 Mon Sep 17 00:00:00 2001 From: luoxu Date: Thu, 21 Dec 2023 12:05:44 +0800 Subject: [PATCH 2/2] bugfix(ble_mesh): add duplicate scan config for esp32s3 --- components/bt/esp_ble_mesh/Kconfig.in | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index 08950d41d2..5fca38e33b 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -10,10 +10,9 @@ if BLE_MESH bool "Support Duplicate Scan in BLE Mesh" select BTDM_BLE_SCAN_DUPL if IDF_TARGET_ESP32 select BTDM_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32 - select BT_CTRL_BLE_SCAN_DUPL if IDF_TARGET_ESP32C3 - select BT_CTRL_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32C3 - select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 - select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32H2 + select BT_CTRL_BLE_SCAN_DUPL if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + select BT_CTRL_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2 select BT_NIMBLE_VS_SUPPORT if BT_NIMBLE_ENABLED default y help