From 127763961a6ea7989f967aad105e312a8ca736c1 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Fri, 11 Aug 2023 13:34:33 +0530 Subject: [PATCH] [ESP32] Fix the parentheses and ifdefs during ble deinit (#28628) * [ESP32] Fix the parentheses and ifdefs during ble deinit * Fix the compilation for bluedroid host --- .../esp32/common/CommonDeviceCallbacks.cpp | 53 ++++++++++--------- .../ESP32/bluedroid/BLEManagerImpl.cpp | 2 +- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp index c4409a59cc20f2..eddb61524c0a74 100644 --- a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp +++ b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp @@ -62,43 +62,48 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i case DeviceEventType::kCHIPoBLEConnectionClosed: ESP_LOGI(TAG, "CHIPoBLE disconnected"); -#if CONFIG_BT_ENABLED -#if CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING +#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()) + if (!ble_hs_is_enabled()) + { + ESP_LOGI(TAG, "BLE already deinited"); + break; + } + if (nimble_port_stop() != 0) { - int ret = nimble_port_stop(); - if (ret == 0) - { - nimble_port_deinit(); + ESP_LOGE(TAG, "nimble_port_stop() failed"); + break; + } + vTaskDelay(100); + nimble_port_deinit(); + #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) - err = esp_nimble_hci_and_controller_deinit(); -#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) -#endif // CONFIG_BT_NIMBLE_ENABLED + 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); + 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 - err += esp_bt_mem_release(ESP_BT_MODE_BLE); + err |= esp_bt_mem_release(ESP_BT_MODE_BLE); #endif - if (err == ESP_OK) - { - ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed"); - } - } - else - { - ESP_LOGW(TAG, "nimble_port_stop() failed"); - } + + if (err != ESP_OK) + { + ESP_LOGE(TAG, "BLE deinit failed"); + } + else + { + ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed"); } - else { ESP_LOGI(TAG, "BLE already deinited"); } } -#endif // CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING -#endif // CONFIG_BT_ENABLED +#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */ + break; case DeviceEventType::kDnssdInitialized: diff --git a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp index a43b3456e940e4..ef9cbece6f5fd4 100644 --- a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp +++ b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp @@ -211,7 +211,7 @@ CHIP_ERROR BLEManagerImpl::_Init() #endif SuccessOrExit(err); - memset(mCons, 0, sizeof(mCons)); + memset(reinterpret_cast(mCons), 0, sizeof(mCons)); mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; mAppIf = ESP_GATT_IF_NONE; mServiceAttrHandle = 0;