From f5f9d34443925977c8657cb11af9a31ad89c9073 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 8 May 2020 19:49:48 +0800 Subject: [PATCH] ble_mesh: Update client message timeout calculation Since the behavior of sending segmented messages has been changed properly, the calculation of timeout value which will be used when sending an acknowledged message by a client model also needs to be updated. --- .../mesh_core/include/mesh_access.h | 4 ++-- .../bt/esp_ble_mesh/mesh_core/transport.c | 8 +++++++- .../mesh_models/client/client_common.c | 20 +++++++++---------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h index 10304ff31..141cc6903 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h @@ -191,9 +191,9 @@ struct bt_mesh_model_op { #define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){}) /** Length of a short Mesh MIC. */ -#define BLE_MESH_MIC_SHORT 4 +#define BLE_MESH_MIC_SHORT 4 /** Length of a long Mesh MIC. */ -#define BLE_MESH_MIC_LONG 8 +#define BLE_MESH_MIC_LONG 8 /** @def BLE_MESH_MODEL_OP_LEN * diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index 3bd0f20d1..56112c040 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -167,10 +167,16 @@ u8_t bt_mesh_get_seg_retrans_num(void) s32_t bt_mesh_get_seg_retrans_timeout(u8_t ttl) { + /* This function will be used when a client model sending an + * acknowledged message. And if the dst of a message is not + * a unicast address, the function will not be invoked. + * So we can directly use the SEG_RETRANSMIT_TIMEOUT_UNICAST + * macro here. + */ struct seg_tx tx = { .ttl = ttl, }; - return SEG_RETRANSMIT_TIMEOUT(&tx); + return SEG_RETRANSMIT_TIMEOUT_UNICAST(&tx); } void bt_mesh_set_hb_sub_dst(u16_t addr) diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index fed5408b9..fe5653b7b 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -185,7 +185,8 @@ static s32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx, need_seg = true; /* Needs segmentation */ } - mic_size = (need_seg && net_buf_simple_tailroom(msg) >= 8U) ? 8U : 4U; + mic_size = (need_seg && net_buf_simple_tailroom(msg) >= BLE_MESH_MIC_LONG) ? + BLE_MESH_MIC_LONG : BLE_MESH_MIC_SHORT; if (need_seg) { /* Based on the message length, calculate how many segments are needed. @@ -201,17 +202,14 @@ static s32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx, * messages, but if there are other messages between any two retrans- * missions of the same segmented messages, then the whole time will * be longer. + * + * Since the transport behavior has been changed, i.e. start retransmit + * timer after the last segment is sent, so we can simplify the timeout + * calculation here. And the retransmit timer will be started event if + * the attempts reaches ZERO when the dst is a unicast address. */ - if (duration + HCI_TIME_FOR_START_ADV < seg_retrans_to) { - s32_t seg_duration = seg_count * (duration + HCI_TIME_FOR_START_ADV); - time = (seg_duration + seg_retrans_to) * (seg_retrans_num - 1) + seg_duration; - } else { - /* If the duration is bigger than the segment retransmit timeout - * value. In this situation, the segment retransmit timeout value - * may need to be optimized based on the "Network Transmit" value. - */ - time = seg_count * (duration + HCI_TIME_FOR_START_ADV) * seg_retrans_num; - } + s32_t seg_duration = seg_count * (duration + HCI_TIME_FOR_START_ADV); + time = (seg_duration + seg_retrans_to) * seg_retrans_num; BT_INFO("Original timeout %dms, calculated timeout %dms", timeout, time);