@@ -246,6 +246,12 @@ CHIP_ERROR BLEManagerImpl::_Init()
246
246
247
247
void BLEManagerImpl::_Shutdown ()
248
248
{
249
+ if (mFlags .Has (Flags::kBleDeinitAndMemReleased ))
250
+ {
251
+ ChipLogProgress (DeviceLayer, " Ble already deinitialized, returning from ShutDown flow" );
252
+ return ;
253
+ }
254
+
249
255
CancelBleAdvTimeoutTimer ();
250
256
251
257
BleLayer::Shutdown ();
@@ -725,13 +731,15 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
725
731
return CHIP_ERROR (ChipError::Range::kPlatform , CHIP_DEVICE_CONFIG_ESP32_BLE_ERROR_MIN + bleErr);
726
732
}
727
733
}
734
+
728
735
void BLEManagerImpl::CancelBleAdvTimeoutTimer (void )
729
736
{
730
737
if (SystemLayer ().IsTimerActive (BleAdvTimeoutHandler, nullptr ))
731
738
{
732
739
SystemLayer ().CancelTimer (BleAdvTimeoutHandler, nullptr );
733
740
}
734
741
}
742
+
735
743
void BLEManagerImpl::StartBleAdvTimeoutTimer (uint32_t aTimeoutInMs)
736
744
{
737
745
CancelBleAdvTimeoutTimer ();
@@ -742,6 +750,7 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
742
750
ChipLogError (DeviceLayer, " Failed to start BledAdv timeout timer" );
743
751
}
744
752
}
753
+
745
754
void BLEManagerImpl::DriveBLEState (void )
746
755
{
747
756
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -752,6 +761,11 @@ void BLEManagerImpl::DriveBLEState(void)
752
761
mFlags .Set (Flags::kAsyncInitCompleted );
753
762
}
754
763
764
+ if (mFlags .Has (Flags::kBleDeinitAndMemReleased ))
765
+ {
766
+ return ;
767
+ }
768
+
755
769
// Initializes the ESP BLE layer if needed.
756
770
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !mFlags .Has (Flags::kESPBLELayerInitialized ))
757
771
{
@@ -857,7 +871,7 @@ void BLEManagerImpl::DriveBLEState(void)
857
871
if (mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_Enabled && mFlags .Has (Flags::kGATTServiceStarted ))
858
872
{
859
873
DeinitESPBleLayer ();
860
- mFlags .ClearAll ();
874
+ mFlags .ClearAll (). Set (Flags:: kBleDeinitAndMemReleased ) ;
861
875
}
862
876
863
877
exit :
0 commit comments