Merge branch 'bugfix/BLEQABR23-577' into 'release/v5.1'

Resolve BLEQABR23-577 "Bugfix/" Prevent the generation of link ID as 0.

See merge request espressif/esp-idf!28185
This commit is contained in:
Jiang Jiang Jian 2024-02-28 10:40:26 +08:00
commit 88b8f533cd
3 changed files with 38 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -1994,6 +1994,16 @@ int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
BT_ERR("Invalid Provisioning Link ID");
return -EINVAL;
}
/* When removing an unused link (i.e., Link ID is 0), and since
* Controller has never added this Link ID, it will cause error
* log been wrongly reported.
* Therefore, add this check here to avoid such occurrences.
*/
if (*(uint32_t*)info == 0) {
return 0;
}
sys_memcpy_swap(value, info, sizeof(uint32_t));
}

View File

@ -1982,6 +1982,16 @@ int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
BT_ERR("Invalid Provisioning Link ID");
return -EINVAL;
}
/* When removing an unused link (i.e., Link ID is 0), and since
* Controller has never added this Link ID, it will cause error
* log been wrongly reported.
* Therefore, add this check here to avoid such occurrences.
*/
if (*(uint32_t*)info == 0) {
return 0;
}
sys_memcpy_swap(value, info, sizeof(uint32_t));
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -1459,16 +1459,27 @@ static int bearer_ctl_send(const uint8_t idx, uint8_t op, void *data, uint8_t da
static void send_link_open(const uint8_t idx)
{
int j;
uint8_t count;
link[idx].link_id = 0;
/** Generate link ID, and may need to check if this id is
* currently being used, which may will not happen ever.
*/
bt_mesh_rand(&link[idx].link_id, sizeof(uint32_t));
while (1) {
count = 0;
/* Make sure the generated Link ID is not 0 */
while(link[idx].link_id == 0) {
bt_mesh_rand(&link[idx].link_id, sizeof(link[idx].link_id));
if (count++ > 10) {
BT_ERR("Link ID error: all zero");
return;
}
}
/* Check if the generated Link ID is the same with other links */
for (j = 0; j < CONFIG_BLE_MESH_PBA_SAME_TIME; j++) {
if (bt_mesh_atomic_test_bit(link[j].flags, LINK_ACTIVE) || link[j].linking) {
if (link[idx].link_id == link[j].link_id) {
bt_mesh_rand(&link[idx].link_id, sizeof(uint32_t));
bt_mesh_rand(&link[idx].link_id, sizeof(link[idx].link_id));
break;
}
}