From 43f70745304ab66869b6751ba15fb1d4dcd3eb4b Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Thu, 27 Jun 2024 02:00:10 +0530 Subject: [PATCH] ESP32: Fixes in BLEManager (#34082) - Fix the ble re-advertisement if invalid bytes are written on the characteristic. - cancel the ble advertisement timer on ble connection - remove the unnecessary if check --- .../ESP32/bluedroid/BLEManagerImpl.cpp | 1 + src/platform/ESP32/nimble/BLEManagerImpl.cpp | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp index da44e5974b5869..07c02647055ca8 100644 --- a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp +++ b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp @@ -890,6 +890,7 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) { ChipLogProgress(Ble, "Got notification regarding chip connection closure"); + CloseConnection(conId); } CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index b43f866c0577f2..189ebd9dae6775 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -672,7 +672,11 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle #endif } -void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) {} +void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) +{ + ChipLogDetail(Ble, "Received notification of closed CHIPoBLE connection (con %u)", conId); + CloseConnection(conId); +} CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) { @@ -810,23 +814,21 @@ void BLEManagerImpl::DriveBLEState(void) ExitNow(); } } - // mFlags.Clear(Flags::kAdvertisingRefreshNeeded); // Transition to the not Advertising state... - if (mFlags.Has(Flags::kAdvertising)) - { - mFlags.Clear(Flags::kAdvertising); - mFlags.Set(Flags::kFastAdvertisingEnabled, true); + mFlags.Clear(Flags::kAdvertising); + mFlags.Set(Flags::kFastAdvertisingEnabled, true); - ChipLogProgress(DeviceLayer, "CHIPoBLE advertising stopped"); + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising stopped"); - // Post a CHIPoBLEAdvertisingChange(Stopped) event. - { - ChipDeviceEvent advChange; - advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; - advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped; - err = PlatformMgr().PostEvent(&advChange); - } + CancelBleAdvTimeoutTimer(); + + // Post a CHIPoBLEAdvertisingChange(Stopped) event. + { + ChipDeviceEvent advChange; + advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange; + advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped; + err = PlatformMgr().PostEvent(&advChange); } ExitNow();