From 9fa5c14d580ac8f24a50db427f3d02bdafa717f0 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 19 Feb 2020 21:30:48 +0800 Subject: [PATCH] ble_mesh: Reset transport info when node is removed --- .../esp_ble_mesh/mesh_core/provisioner_main.c | 19 +++----- .../bt/esp_ble_mesh/mesh_core/transport.c | 44 +++++++++++++++++++ .../bt/esp_ble_mesh/mesh_core/transport.h | 2 + 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index dcf3421f4..f60d9e22a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -21,6 +21,7 @@ #include "access.h" #include "settings.h" #include "friend.h" +#include "transport.h" #include "mesh_common.h" #include "proxy_client.h" #include "provisioner_prov.h" @@ -380,7 +381,6 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16 static int provisioner_remove_node(u16_t index, bool erase) { struct bt_mesh_node *node = NULL; - struct bt_mesh_rpl *rpl = NULL; bool is_prov = false; int i; @@ -398,17 +398,12 @@ static int provisioner_remove_node(u16_t index, bool erase) /* Reset corresponding network cache when reset the node */ bt_mesh_msg_cache_clear(node->unicast_addr, node->element_num); - /* Reset corresponding rpl when removing the node */ - for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) { - rpl = &bt_mesh.rpl[i]; - if (rpl->src >= node->unicast_addr && - rpl->src < node->unicast_addr + node->element_num) { - memset(rpl, 0, sizeof(struct bt_mesh_rpl)); - - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { - bt_mesh_clear_rpl_single(node->unicast_addr); - } - } + /* Reset corresponding transport info when removing the node */ + for (i = 0; i < node->element_num; i++) { + bt_mesh_rx_reset_single(node->unicast_addr + i); + } + for (i = 0; i < node->element_num; i++) { + bt_mesh_tx_reset_single(node->unicast_addr + i); } if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index 3d78e4365..6fa91aa66 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -1584,6 +1584,50 @@ void bt_mesh_tx_reset(void) } } +#if CONFIG_BLE_MESH_PROVISIONER +void bt_mesh_rx_reset_single(u16_t src) +{ + int i; + + if (!BLE_MESH_ADDR_IS_UNICAST(src)) { + return; + } + + for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { + struct seg_rx *rx = &seg_rx[i]; + if (src == rx->src) { + seg_rx_reset(rx, true); + } + } + + for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) { + struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i]; + if (src == rpl->src) { + memset(rpl, 0, sizeof(struct bt_mesh_rpl)); + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_clear_rpl_single(src); + } + } + } +} + +void bt_mesh_tx_reset_single(u16_t dst) +{ + int i; + + if (!BLE_MESH_ADDR_IS_UNICAST(dst)) { + return; + } + + for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { + struct seg_tx *tx = &seg_tx[i]; + if (dst == tx->dst) { + seg_tx_reset(tx); + } + } +} +#endif /* CONFIG_BLE_MESH_PROVISIONER */ + void bt_mesh_trans_init(void) { int i; diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.h b/components/bt/esp_ble_mesh/mesh_core/transport.h index 028b62be8..b97382d3d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.h +++ b/components/bt/esp_ble_mesh/mesh_core/transport.h @@ -88,6 +88,8 @@ bool bt_mesh_tx_in_progress(void); void bt_mesh_rx_reset(void); void bt_mesh_tx_reset(void); +void bt_mesh_rx_reset_single(u16_t src); +void bt_mesh_tx_reset_single(u16_t dst); int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, size_t data_len, u64_t *seq_auth,