Skip to content

Commit 8e0b1cf

Browse files
committed
Merge branch 'fix/ble_mesh_fixed_insufficient_link_close' into 'master'
fix(ble_mesh): fixed issue with insufficient link close transmit cnt Closes BLERP-1810 See merge request espressif/esp-idf!38731
2 parents f7398c5 + ad10736 commit 8e0b1cf

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

components/bt/esp_ble_mesh/core/prov_common.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
* SPDX-FileCopyrightText: 2017 Intel Corporation
5-
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
5+
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
66
*
77
* SPDX-License-Identifier: Apache-2.0
88
*/
@@ -135,6 +135,9 @@ bool bt_mesh_prov_pdu_check(uint8_t type, uint16_t length, uint8_t *reason)
135135
#define CLOSE_XMIT BLE_MESH_TRANSMIT(2, 20)
136136

137137
#define CLOSE_TIMEOUT K_MSEC(100)
138+
#define CLOSE_RETRANS_CNT 3
139+
#define CLOSE_RETRANS_WITH_REASON(cnt, rsn) (((cnt) << 4) | ((rsn) & 0x0f))
140+
#define CLOSE_RETRANS_GET(rsn) ((rsn) >> 4)
138141

139142
#define BUF_TIMEOUT K_MSEC(400)
140143

@@ -457,12 +460,19 @@ static void prov_retransmit(struct k_work *work)
457460
if (link->pb_remote_close) {
458461
link->pb_remote_close(link, link->reason);
459462
}
463+
return;
460464
} else {
461-
if (link->reset_adv_link) {
462-
link->reset_adv_link(link, link->reason);
465+
uint8_t retrans_cnt = CLOSE_RETRANS_GET(link->reason);
466+
if (!retrans_cnt) {
467+
if (link->reset_adv_link) {
468+
link->reset_adv_link(link, link->reason);
469+
}
470+
return;
471+
} else {
472+
retrans_cnt--;
473+
link->reason = CLOSE_RETRANS_WITH_REASON(retrans_cnt, link->reason);
463474
}
464475
}
465-
return;
466476
}
467477

468478
bt_mesh_mutex_lock(&link->buf_lock);
@@ -547,7 +557,14 @@ int bt_mesh_prov_bearer_ctl_send(struct bt_mesh_prov_link *link, uint8_t op,
547557
if (op == LINK_CLOSE) {
548558
bt_mesh_atomic_clear_bit(link->flags, LINK_ACTIVE);
549559
bt_mesh_atomic_set_bit(link->flags, LINK_CLOSING);
550-
link->reason = *((uint8_t *)data);
560+
/** We can also use buf->ref and a flag to decide that
561+
* link close has been sent 3 times.
562+
* Here we use another way: use retransmit timer and need
563+
* to make sure the timer is not cancelled during sending
564+
* link close pdu, Therefore, use the higher four bits
565+
* of reason as a retransmit count.
566+
*/
567+
link->reason = CLOSE_RETRANS_WITH_REASON(CLOSE_RETRANS_CNT, (*((uint8_t *)data)));
551568
}
552569

553570
return 0;

0 commit comments

Comments
 (0)