@@ -244,6 +244,12 @@ CHIP_ERROR BLEManagerImpl::_Init()
244
244
245
245
void BLEManagerImpl::_Shutdown ()
246
246
{
247
+ if (mFlags .Has (Flags::kBleDeinitAndMemReleased ))
248
+ {
249
+ ChipLogProgress (DeviceLayer, " Ble already deinitialized, returning from ShutDown flow" );
250
+ return ;
251
+ }
252
+
247
253
CancelBleAdvTimeoutTimer ();
248
254
249
255
BleLayer::Shutdown ();
@@ -712,13 +718,15 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
712
718
return CHIP_ERROR (ChipError::Range::kPlatform , CHIP_DEVICE_CONFIG_ESP32_BLE_ERROR_MIN + bleErr);
713
719
}
714
720
}
721
+
715
722
void BLEManagerImpl::CancelBleAdvTimeoutTimer (void )
716
723
{
717
724
if (SystemLayer ().IsTimerActive (BleAdvTimeoutHandler, nullptr ))
718
725
{
719
726
SystemLayer ().CancelTimer (BleAdvTimeoutHandler, nullptr );
720
727
}
721
728
}
729
+
722
730
void BLEManagerImpl::StartBleAdvTimeoutTimer (uint32_t aTimeoutInMs)
723
731
{
724
732
CancelBleAdvTimeoutTimer ();
@@ -729,6 +737,7 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
729
737
ChipLogError (DeviceLayer, " Failed to start BledAdv timeout timer" );
730
738
}
731
739
}
740
+
732
741
void BLEManagerImpl::DriveBLEState (void )
733
742
{
734
743
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -739,6 +748,11 @@ void BLEManagerImpl::DriveBLEState(void)
739
748
mFlags .Set (Flags::kAsyncInitCompleted );
740
749
}
741
750
751
+ if (mFlags .Has (Flags::kBleDeinitAndMemReleased ))
752
+ {
753
+ return ;
754
+ }
755
+
742
756
// Initializes the ESP BLE layer if needed.
743
757
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !mFlags .Has (Flags::kESPBLELayerInitialized ))
744
758
{
@@ -844,7 +858,7 @@ void BLEManagerImpl::DriveBLEState(void)
844
858
if (mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_Enabled && mFlags .Has (Flags::kGATTServiceStarted ))
845
859
{
846
860
DeinitESPBleLayer ();
847
- mFlags .ClearAll ();
861
+ mFlags .ClearAll (). Set (Flags:: kBleDeinitAndMemReleased ) ;
848
862
}
849
863
850
864
exit :
0 commit comments