|
2 | 2 |
|
3 | 3 | /* |
4 | 4 | * 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 |
6 | 6 | * |
7 | 7 | * SPDX-License-Identifier: Apache-2.0 |
8 | 8 | */ |
@@ -135,6 +135,9 @@ bool bt_mesh_prov_pdu_check(uint8_t type, uint16_t length, uint8_t *reason) |
135 | 135 | #define CLOSE_XMIT BLE_MESH_TRANSMIT(2, 20) |
136 | 136 |
|
137 | 137 | #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) |
138 | 141 |
|
139 | 142 | #define BUF_TIMEOUT K_MSEC(400) |
140 | 143 |
|
@@ -457,12 +460,19 @@ static void prov_retransmit(struct k_work *work) |
457 | 460 | if (link->pb_remote_close) { |
458 | 461 | link->pb_remote_close(link, link->reason); |
459 | 462 | } |
| 463 | + return; |
460 | 464 | } 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); |
463 | 474 | } |
464 | 475 | } |
465 | | - return; |
466 | 476 | } |
467 | 477 |
|
468 | 478 | 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, |
547 | 557 | if (op == LINK_CLOSE) { |
548 | 558 | bt_mesh_atomic_clear_bit(link->flags, LINK_ACTIVE); |
549 | 559 | 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))); |
551 | 568 | } |
552 | 569 |
|
553 | 570 | return 0; |
|
0 commit comments