Merge branch 'ble_crash_fix' into 'main'

Update submodule to fix the crash when deinitializing the ble

See merge request app-frameworks/esp-matter!726
This commit is contained in:
Shu Chen
2024-05-10 19:52:07 +08:00
+8 -35
View File
@@ -880,40 +880,13 @@ esp_err_t chip_stack_unlock()
} /* lock */
#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
static void deinit_ble_if_commissioned(void)
static void deinit_ble_if_commissioned(intptr_t unused)
{
#if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
if(chip::Server::GetInstance().GetFabricTable().FabricCount() > 0) {
esp_err_t err = ESP_OK;
#if CONFIG_BT_NIMBLE_ENABLED
if (!ble_hs_is_enabled()) {
ESP_LOGI(TAG, "BLE already deinited");
return;
}
if (nimble_port_stop() != 0) {
ESP_LOGE(TAG, "nimble_port_stop() failed");
return;
}
nimble_port_deinit();
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err = esp_nimble_hci_and_controller_deinit();
#endif
#endif /* CONFIG_BT_NIMBLE_ENABLED */
#if CONFIG_IDF_TARGET_ESP32
err |= esp_bt_mem_release(ESP_BT_MODE_BTDM);
#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 \
|| CONFIG_IDF_TARGET_ESP32C6
err |= esp_bt_mem_release(ESP_BT_MODE_BLE);
#endif
if (err != ESP_OK) {
ESP_LOGE(TAG, "BLE deinit failed");
return;
}
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
PostEvent(chip::DeviceLayer::DeviceEventType::kBLEDeinitialized);
}
#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
#if CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
if(chip::Server::GetInstance().GetFabricTable().FabricCount() > 0) {
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
}
#endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
}
static void esp_matter_chip_init_task(intptr_t context)
@@ -962,7 +935,7 @@ static void esp_matter_chip_init_task(intptr_t context)
sEthernetNetworkCommissioningInstance.Init();
}
#endif
deinit_ble_if_commissioned();
PlatformMgr().ScheduleWork(deinit_ble_if_commissioned, reinterpret_cast<intptr_t>(nullptr));
xTaskNotifyGive(task_to_notify);
}
#endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
@@ -988,11 +961,11 @@ static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete:
ESP_LOGI(TAG, "Commissioning Complete");
PlatformMgr().ScheduleWork(deinit_ble_if_commissioned, reinterpret_cast<intptr_t>(nullptr));
break;
case chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "BLE Disconnected");
deinit_ble_if_commissioned();
break;
#endif
default: