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