Skip to content

Commit

Permalink
Merge branch 'bugfix/bleqabr24-549_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
fix(ble_mesh): fix issues in mesh deinit_v5.0

See merge request espressif/esp-idf!30543
  • Loading branch information
Isl2017 committed May 31, 2024
2 parents 289e886 + 1121ffa commit 1505232
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
}

/* Take the Semaphore, wait BLE Mesh de-initialization to finish. */
xSemaphoreTake(semaphore, portMAX_DELAY);
__ASSERT(xSemaphoreTake(semaphore, 3000 / portTICK_PERIOD_MS) == pdTRUE, "BLE Mesh deinit take semaphore failed");
/* Don't forget to delete the semaphore at the end. */
vSemaphoreDelete(semaphore);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -33,7 +33,10 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
/**
* @brief De-initialize BLE Mesh module.
*
* @note This function shall be invoked after esp_ble_mesh_client_model_deinit().
* @note
* 1. This function shall be invoked after esp_ble_mesh_client_model_deinit().
* 2. This function is strictly forbidden to run in any BTC Task Context
* (e.g. registered Mesh Event Callback).
*
* @param[in] param: Pointer to the structure of BLE Mesh deinit parameters.
*
Expand Down
31 changes: 28 additions & 3 deletions components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -57,6 +57,29 @@
#include "esp_ble_mesh_provisioning_api.h"
#include "esp_ble_mesh_networking_api.h"

#if CONFIG_BLE_MESH_DEINIT
static SemaphoreHandle_t deinit_comp_semaphore;
#endif

static inline void btc_ble_mesh_prov_cb_to_app_reprocess(esp_ble_mesh_prov_cb_event_t event,
esp_ble_mesh_prov_cb_param_t *param)
{
switch (event) {
#if CONFIG_BLE_MESH_DEINIT
case ESP_BLE_MESH_DEINIT_MESH_COMP_EVT:
assert(deinit_comp_semaphore);
/* Give the semaphore when BLE Mesh de-initialization is finished.
* @note: At nimble host, once this lock is released, it will cause
* the btc task to be deleted.
*/
xSemaphoreGive(deinit_comp_semaphore);
break;
#endif
default:
break;
}
}

static inline void btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t event,
esp_ble_mesh_prov_cb_param_t *param)
{
Expand All @@ -65,6 +88,8 @@ static inline void btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t even
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}

btc_ble_mesh_prov_cb_to_app_reprocess(event, param);
}

static inline void btc_ble_mesh_model_cb_to_app(esp_ble_mesh_model_cb_event_t event,
Expand Down Expand Up @@ -2268,8 +2293,8 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
case BTC_BLE_MESH_ACT_DEINIT_MESH:
act = ESP_BLE_MESH_DEINIT_MESH_COMP_EVT;
param.deinit_mesh_comp.err_code = bt_mesh_deinit((struct bt_mesh_deinit_param *)&arg->mesh_deinit.param);
/* Give the semaphore when BLE Mesh de-initialization is finished. */
xSemaphoreGive(arg->mesh_deinit.semaphore);
/* Temporarily save the deinit semaphore and release it after the mesh deinit complete event is handled in the app layer */
deinit_comp_semaphore = arg->mesh_deinit.semaphore;
break;
#endif /* CONFIG_BLE_MESH_DEINIT */
default:
Expand Down

0 comments on commit 1505232

Please sign in to comment.