Skip to content

Commit 9d20537

Browse files
committed
Revert "[v1.3] [ESP32] Cherry-picking extended advertisement support and ble deinit crash fix (project-chip#33159)"
This reverts commit 7cdf4e8. Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent 251c779 commit 9d20537

File tree

6 files changed

+73
-199
lines changed

6 files changed

+73
-199
lines changed

config/esp32/components/chip/Kconfig

+8-21
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,12 @@ menu "CHIP Device Layer"
726726
should not start advertising automatically after power-up.
727727

728728
config USE_BLE_ONLY_FOR_COMMISSIONING
729-
depends on BT_ENABLED
730-
bool "Use BLE only for commissioning"
731-
default y
732-
help
733-
Disable this flag if BLE is used for any other purpose than commissioning.
734-
When enabled, it deinitialized the BLE on successful commissioning, and on
735-
bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials.
729+
bool "Use BLE only for commissioning"
730+
default y
731+
help
732+
Disable this flag if BLE is used for any other purpose than commissioning.
733+
When enabled, it deinitialized the BLE on successful commissioning, and on
734+
bootup do not initialize the BLE if device is already provisioned with Wi-Fi/Thread credentials.
736735

737736
endmenu
738737

@@ -1193,11 +1192,8 @@ menu "CHIP Device Layer"
11931192
menu "Commissioning Window Options"
11941193
config CHIP_DISCOVERY_TIMEOUT_SECS
11951194
int "Commissioning Window Timeout in seconds"
1196-
range 180 900 if !ENABLE_BLE_EXT_ANNOUNCEMENT
1197-
range 901 172800 if ENABLE_BLE_EXT_ANNOUNCEMENT
1198-
default 900 if !ENABLE_BLE_EXT_ANNOUNCEMENT
1199-
default 172800 if ENABLE_BLE_EXT_ANNOUNCEMENT
1200-
1195+
range 180 900
1196+
default 900
12011197
help
12021198
The amount of time (in seconds) after which the CHIP platform will close the Commissioning Window
12031199
endmenu
@@ -1220,13 +1216,4 @@ menu "CHIP Device Layer"
12201216

12211217
endmenu
12221218

1223-
menu "Enable BLE Extended Announcement"
1224-
config ENABLE_BLE_EXT_ANNOUNCEMENT
1225-
bool "Enable BLE Extended Announcement"
1226-
default n
1227-
help
1228-
Enable BLE Extended Announcement.To be used with CHIP_DISCOVERY_TIMEOUT_SECS for extended announcement duration.
1229-
1230-
endmenu
1231-
12321219
endmenu

examples/platform/esp32/common/CommonDeviceCallbacks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
5151

5252
case DeviceEventType::kCHIPoBLEConnectionClosed:
5353
ESP_LOGI(TAG, "CHIPoBLE disconnected");
54+
Esp32AppServer::DeInitBLEIfCommissioned();
5455
break;
5556

5657
case DeviceEventType::kDnssdInitialized:
@@ -66,7 +67,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
6667

6768
case DeviceEventType::kCommissioningComplete: {
6869
ESP_LOGI(TAG, "Commissioning complete");
69-
Esp32AppServer::DeInitBLEIfCommissioned();
7070
}
7171
break;
7272

examples/platform/esp32/common/Esp32AppServer.cpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,47 @@ static size_t hex_string_to_binary(const char * hex_string, uint8_t * buf, size_
116116

117117
void Esp32AppServer::DeInitBLEIfCommissioned(void)
118118
{
119-
#ifdef CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
119+
#if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
120120
if (chip::Server::GetInstance().GetFabricTable().FabricCount() > 0)
121121
{
122-
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
122+
esp_err_t err = ESP_OK;
123+
124+
#if CONFIG_BT_NIMBLE_ENABLED
125+
if (!ble_hs_is_enabled())
126+
{
127+
ESP_LOGI(TAG, "BLE already deinited");
128+
return;
129+
}
130+
if (nimble_port_stop() != 0)
131+
{
132+
ESP_LOGE(TAG, "nimble_port_stop() failed");
133+
return;
134+
}
135+
vTaskDelay(100);
136+
nimble_port_deinit();
137+
138+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
139+
err = esp_nimble_hci_and_controller_deinit();
140+
#endif
141+
#endif /* CONFIG_BT_NIMBLE_ENABLED */
142+
143+
#if CONFIG_IDF_TARGET_ESP32
144+
err |= esp_bt_mem_release(ESP_BT_MODE_BTDM);
145+
#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2 || \
146+
CONFIG_IDF_TARGET_ESP32C6
147+
err |= esp_bt_mem_release(ESP_BT_MODE_BLE);
148+
#endif
149+
150+
if (err != ESP_OK)
151+
{
152+
ESP_LOGE(TAG, "BLE deinit failed");
153+
}
154+
else
155+
{
156+
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
157+
}
123158
}
124-
#endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
159+
#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
125160
}
126161

127162
void Esp32AppServer::Init(AppDelegate * sAppDelegate)
@@ -132,7 +167,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
132167
if (hex_string_to_binary(CONFIG_TEST_EVENT_TRIGGER_ENABLE_KEY, sTestEventTriggerEnableKey,
133168
sizeof(sTestEventTriggerEnableKey)) == 0)
134169
{
135-
ChipLogError(DeviceLayer, "Failed to convert the EnableKey string to octstr type value");
170+
ESP_LOGE(TAG, "Failed to convert the EnableKey string to octstr type value");
136171
memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey));
137172
}
138173
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
@@ -159,7 +194,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
159194
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
160195
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))
161196
{
162-
ChipLogProgress(DeviceLayer, "Thread has been provisioned, publish the dns service now");
197+
ESP_LOGI(TAG, "Thread has been provisioned, publish the dns service now");
163198
chip::app::DnssdServer::Instance().StartServer();
164199
}
165200
#endif

src/platform/ESP32/BLEManagerImpl.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class BLEManagerImpl final : public BLEManager,
156156
// ===== Members that implement the BLEManager internal interface.
157157

158158
CHIP_ERROR _Init(void);
159-
void _Shutdown();
159+
void _Shutdown() {}
160160
bool _IsAdvertisingEnabled(void);
161161
CHIP_ERROR _SetAdvertisingEnabled(bool val);
162162
bool _IsAdvertising(void);
@@ -232,7 +232,6 @@ class BLEManagerImpl final : public BLEManager,
232232
kFastAdvertisingEnabled = 0x0200, /**< The application has enabled fast advertising. */
233233
kUseCustomDeviceName = 0x0400, /**< The application has configured a custom BLE device name. */
234234
kAdvertisingRefreshNeeded = 0x0800, /**< The advertising configuration/state in ESP BLE layer needs to be updated. */
235-
kExtAdvertisingEnabled = 0x1000, /**< The application has enabled Extended BLE announcement. */
236235
};
237236

238237
enum
@@ -297,12 +296,15 @@ class BLEManagerImpl final : public BLEManager,
297296

298297
void DriveBLEState(void);
299298
CHIP_ERROR InitESPBleLayer(void);
300-
void DeinitESPBleLayer(void);
301299
CHIP_ERROR ConfigureAdvertisingData(void);
302300
CHIP_ERROR StartAdvertising(void);
303-
void StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs);
304-
void CancelBleAdvTimeoutTimer(void);
305-
static void BleAdvTimeoutHandler(TimerHandle_t xTimer);
301+
302+
static constexpr System::Clock::Timeout kFastAdvertiseTimeout =
303+
System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME);
304+
System::Clock::Timestamp mAdvertiseStartTime;
305+
306+
static void HandleFastAdvertisementTimer(System::Layer * systemLayer, void * context);
307+
void HandleFastAdvertisementTimer();
306308

307309
#if CONFIG_BT_BLUEDROID_ENABLED
308310
void HandleGATTControlEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t * param);
@@ -328,9 +330,6 @@ class BLEManagerImpl final : public BLEManager,
328330
static void HandleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t * param);
329331

330332
#elif CONFIG_BT_NIMBLE_ENABLED
331-
CHIP_ERROR DeinitBLE();
332-
static void ClaimBLEMemory(System::Layer *, void *);
333-
334333
void HandleRXCharRead(struct ble_gatt_char_context * param);
335334
void HandleRXCharWrite(struct ble_gatt_char_context * param);
336335
void HandleTXCharWrite(struct ble_gatt_char_context * param);

src/platform/ESP32/CHIPDevicePlatformConfig.h

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
#define CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS CONFIG_CHIP_DISCOVERY_TIMEOUT_SECS
107107
#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_ESP32_BLE_CONTROLLER
108108
#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART
109-
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING CONFIG_ENABLE_BLE_EXT_ANNOUNCEMENT
110109

111110
// Options for background chip task
112111
#define CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING CONFIG_ENABLE_BG_EVENT_PROCESSING

0 commit comments

Comments
 (0)