diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 677919092..2099193f6 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -878,40 +878,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) @@ -960,7 +933,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(nullptr)); xTaskNotifyGive(task_to_notify); } #endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER @@ -986,11 +959,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(nullptr)); break; case chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionClosed: ESP_LOGI(TAG, "BLE Disconnected"); - deinit_ble_if_commissioned(); break; #endif default: