Skip to content

Commit 19d29cb

Browse files
shubhamdpaustina-csa
authored andcommitted
ESP32: Fixes in BLEManager (project-chip#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
1 parent 3388a19 commit 19d29cb

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/platform/ESP32/bluedroid/BLEManagerImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle
890890
void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId)
891891
{
892892
ChipLogProgress(Ble, "Got notification regarding chip connection closure");
893+
CloseConnection(conId);
893894
}
894895

895896
CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)

src/platform/ESP32/nimble/BLEManagerImpl.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,11 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle
672672
#endif
673673
}
674674

675-
void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) {}
675+
void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId)
676+
{
677+
ChipLogDetail(Ble, "Received notification of closed CHIPoBLE connection (con %u)", conId);
678+
CloseConnection(conId);
679+
}
676680

677681
CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
678682
{
@@ -810,23 +814,21 @@ void BLEManagerImpl::DriveBLEState(void)
810814
ExitNow();
811815
}
812816
}
813-
// mFlags.Clear(Flags::kAdvertisingRefreshNeeded);
814817

815818
// Transition to the not Advertising state...
816-
if (mFlags.Has(Flags::kAdvertising))
817-
{
818-
mFlags.Clear(Flags::kAdvertising);
819-
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
819+
mFlags.Clear(Flags::kAdvertising);
820+
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
820821

821-
ChipLogProgress(DeviceLayer, "CHIPoBLE advertising stopped");
822+
ChipLogProgress(DeviceLayer, "CHIPoBLE advertising stopped");
822823

823-
// Post a CHIPoBLEAdvertisingChange(Stopped) event.
824-
{
825-
ChipDeviceEvent advChange;
826-
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
827-
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped;
828-
err = PlatformMgr().PostEvent(&advChange);
829-
}
824+
CancelBleAdvTimeoutTimer();
825+
826+
// Post a CHIPoBLEAdvertisingChange(Stopped) event.
827+
{
828+
ChipDeviceEvent advChange;
829+
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
830+
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped;
831+
err = PlatformMgr().PostEvent(&advChange);
830832
}
831833

832834
ExitNow();

0 commit comments

Comments
 (0)