Skip to content

Commit

Permalink
Revert "[v1.3] [ESP32] Cherry-picking extended advertisement support …
Browse files Browse the repository at this point in the history
…and ble deinit crash fix (project-chip#33159)"

This reverts commit 7cdf4e8.

Signed-off-by: Adrian Gielniewski <[email protected]>
  • Loading branch information
adigie committed Nov 28, 2024
1 parent 251c779 commit 9d20537
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 199 deletions.
29 changes: 8 additions & 21 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,12 @@ menu "CHIP Device Layer"
should not start advertising automatically after power-up.

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

endmenu

Expand Down Expand Up @@ -1193,11 +1192,8 @@ menu "CHIP Device Layer"
menu "Commissioning Window Options"
config CHIP_DISCOVERY_TIMEOUT_SECS
int "Commissioning Window Timeout in seconds"
range 180 900 if !ENABLE_BLE_EXT_ANNOUNCEMENT
range 901 172800 if ENABLE_BLE_EXT_ANNOUNCEMENT
default 900 if !ENABLE_BLE_EXT_ANNOUNCEMENT
default 172800 if ENABLE_BLE_EXT_ANNOUNCEMENT

range 180 900
default 900
help
The amount of time (in seconds) after which the CHIP platform will close the Commissioning Window
endmenu
Expand All @@ -1220,13 +1216,4 @@ menu "CHIP Device Layer"

endmenu

menu "Enable BLE Extended Announcement"
config ENABLE_BLE_EXT_ANNOUNCEMENT
bool "Enable BLE Extended Announcement"
default n
help
Enable BLE Extended Announcement.To be used with CHIP_DISCOVERY_TIMEOUT_SECS for extended announcement duration.

endmenu

endmenu
2 changes: 1 addition & 1 deletion examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i

case DeviceEventType::kCHIPoBLEConnectionClosed:
ESP_LOGI(TAG, "CHIPoBLE disconnected");
Esp32AppServer::DeInitBLEIfCommissioned();
break;

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

case DeviceEventType::kCommissioningComplete: {
ESP_LOGI(TAG, "Commissioning complete");
Esp32AppServer::DeInitBLEIfCommissioned();
}
break;

Expand Down
45 changes: 40 additions & 5 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,47 @@ static size_t hex_string_to_binary(const char * hex_string, uint8_t * buf, size_

void Esp32AppServer::DeInitBLEIfCommissioned(void)
{
#ifdef CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
#if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
if (chip::Server::GetInstance().GetFabricTable().FabricCount() > 0)
{
chip::DeviceLayer::Internal::BLEMgr().Shutdown();
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;
}
vTaskDelay(100);
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");
}
else
{
ESP_LOGI(TAG, "BLE deinit successful and memory reclaimed");
}
}
#endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
#endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
}

void Esp32AppServer::Init(AppDelegate * sAppDelegate)
Expand All @@ -132,7 +167,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
if (hex_string_to_binary(CONFIG_TEST_EVENT_TRIGGER_ENABLE_KEY, sTestEventTriggerEnableKey,
sizeof(sTestEventTriggerEnableKey)) == 0)
{
ChipLogError(DeviceLayer, "Failed to convert the EnableKey string to octstr type value");
ESP_LOGE(TAG, "Failed to convert the EnableKey string to octstr type value");
memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey));
}
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
Expand All @@ -159,7 +194,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))
{
ChipLogProgress(DeviceLayer, "Thread has been provisioned, publish the dns service now");
ESP_LOGI(TAG, "Thread has been provisioned, publish the dns service now");
chip::app::DnssdServer::Instance().StartServer();
}
#endif
Expand Down
17 changes: 8 additions & 9 deletions src/platform/ESP32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class BLEManagerImpl final : public BLEManager,
// ===== Members that implement the BLEManager internal interface.

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

enum
Expand Down Expand Up @@ -297,12 +296,15 @@ class BLEManagerImpl final : public BLEManager,

void DriveBLEState(void);
CHIP_ERROR InitESPBleLayer(void);
void DeinitESPBleLayer(void);
CHIP_ERROR ConfigureAdvertisingData(void);
CHIP_ERROR StartAdvertising(void);
void StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs);
void CancelBleAdvTimeoutTimer(void);
static void BleAdvTimeoutHandler(TimerHandle_t xTimer);

static constexpr System::Clock::Timeout kFastAdvertiseTimeout =
System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME);
System::Clock::Timestamp mAdvertiseStartTime;

static void HandleFastAdvertisementTimer(System::Layer * systemLayer, void * context);
void HandleFastAdvertisementTimer();

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

#elif CONFIG_BT_NIMBLE_ENABLED
CHIP_ERROR DeinitBLE();
static void ClaimBLEMemory(System::Layer *, void *);

void HandleRXCharRead(struct ble_gatt_char_context * param);
void HandleRXCharWrite(struct ble_gatt_char_context * param);
void HandleTXCharWrite(struct ble_gatt_char_context * param);
Expand Down
1 change: 0 additions & 1 deletion src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
#define CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS CONFIG_CHIP_DISCOVERY_TIMEOUT_SECS
#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_ESP32_BLE_CONTROLLER
#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING CONFIG_ENABLE_BLE_EXT_ANNOUNCEMENT

// Options for background chip task
#define CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING CONFIG_ENABLE_BG_EVENT_PROCESSING
Expand Down
Loading

0 comments on commit 9d20537

Please sign in to comment.