Skip to content

Commit 15c261f

Browse files
shubhamdpHunsupJung
authored andcommitted
[ESP32] Fix the parentheses and ifdefs during ble deinit (project-chip#28628)
* [ESP32] Fix the parentheses and ifdefs during ble deinit * Fix the compilation for bluedroid host
1 parent f434250 commit 15c261f

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

examples/platform/esp32/common/CommonDeviceCallbacks.cpp

+29-24
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,48 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
6262

6363
case DeviceEventType::kCHIPoBLEConnectionClosed:
6464
ESP_LOGI(TAG, "CHIPoBLE disconnected");
65-
#if CONFIG_BT_ENABLED
66-
#if CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
6765

66+
#if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
6867
if (chip::Server::GetInstance().GetFabricTable().FabricCount() > 0)
6968
{
7069
esp_err_t err = ESP_OK;
70+
7171
#if CONFIG_BT_NIMBLE_ENABLED
72-
if (ble_hs_is_enabled())
72+
if (!ble_hs_is_enabled())
73+
{
74+
ESP_LOGI(TAG, "BLE already deinited");
75+
break;
76+
}
77+
if (nimble_port_stop() != 0)
7378
{
74-
int ret = nimble_port_stop();
75-
if (ret == 0)
76-
{
77-
nimble_port_deinit();
79+
ESP_LOGE(TAG, "nimble_port_stop() failed");
80+
break;
81+
}
82+
vTaskDelay(100);
83+
nimble_port_deinit();
84+
7885
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
79-
err = esp_nimble_hci_and_controller_deinit();
80-
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
81-
#endif // CONFIG_BT_NIMBLE_ENABLED
86+
err = esp_nimble_hci_and_controller_deinit();
87+
#endif
88+
#endif /* CONFIG_BT_NIMBLE_ENABLED */
8289

8390
#if CONFIG_IDF_TARGET_ESP32
84-
err += esp_bt_mem_release(ESP_BT_MODE_BTDM);
91+
err |= esp_bt_mem_release(ESP_BT_MODE_BTDM);
8592
#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2
86-
err += esp_bt_mem_release(ESP_BT_MODE_BLE);
93+
err |= esp_bt_mem_release(ESP_BT_MODE_BLE);
8794
#endif
88-
if (err == ESP_OK)
89-
{
90-
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
91-
}
92-
}
93-
else
94-
{
95-
ESP_LOGW(TAG, "nimble_port_stop() failed");
96-
}
95+
96+
if (err != ESP_OK)
97+
{
98+
ESP_LOGE(TAG, "BLE deinit failed");
99+
}
100+
else
101+
{
102+
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
97103
}
98-
else { ESP_LOGI(TAG, "BLE already deinited"); }
99104
}
100-
#endif // CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
101-
#endif // CONFIG_BT_ENABLED
105+
#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
106+
102107
break;
103108

104109
case DeviceEventType::kDnssdInitialized:

src/platform/ESP32/bluedroid/BLEManagerImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ CHIP_ERROR BLEManagerImpl::_Init()
211211
#endif
212212
SuccessOrExit(err);
213213

214-
memset(mCons, 0, sizeof(mCons));
214+
memset(reinterpret_cast<void *>(mCons), 0, sizeof(mCons));
215215
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
216216
mAppIf = ESP_GATT_IF_NONE;
217217
mServiceAttrHandle = 0;

0 commit comments

Comments
 (0)