diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 12b3ba121886af..4580488ccf6a36 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -24,13 +24,6 @@ #pragma once #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - -#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) -#define BLE_MIN_CONNECTION_INTERVAL_MS 45 // 45 msec -#define BLE_MAX_CONNECTION_INTERVAL_MS 45 // 45 msec -#define BLE_SLAVE_LATENCY_MS 0 -#define BLE_TIMEOUT_MS 400 -#endif // (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) #include "FreeRTOS.h" #include "timers.h" #if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) @@ -209,6 +202,11 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla static void DriveBLEState(intptr_t arg); static void BleAdvTimeoutHandler(TimerHandle_t xTimer); uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate); + +#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE) +protected: + static void OnSendIndicationTimeout(System::Layer * aLayer, void * appState); +#endif }; /** diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 7c6f5a58ffe717..53fd807519cf43 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -68,6 +68,13 @@ extern "C" { #include #endif +#define BLE_MIN_CONNECTION_INTERVAL_MS 45 +#define BLE_MAX_CONNECTION_INTERVAL_MS 45 +#define BLE_SLAVE_LATENCY_MS 0 +#define BLE_TIMEOUT_MS 400 +#define BLE_DEFAULT_TIMER_PERIOD_MS (1) +#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000) + extern sl_wfx_msg_t event_msg; StaticTask_t rsiBLETaskStruct; @@ -246,8 +253,6 @@ namespace { #define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value #define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value -#define BLE_DEFAULT_TIMER_PERIOD_MS (1) - TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer. const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, @@ -301,6 +306,18 @@ CHIP_ERROR BLEManagerImpl::_Init() return err; } +void BLEManagerImpl::OnSendIndicationTimeout(System::Layer * aLayer, void * appState) +{ + // TODO: change the connection handle with the ble device ID + uint8_t connHandle = 1; + ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT"); + ChipDeviceEvent event; + event.Type = DeviceEventType::kCHIPoBLEConnectionError; + event.CHIPoBLEConnectionError.ConId = connHandle; + event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; + PlatformMgr().PostEventOrDie(&event); +} + uint16_t BLEManagerImpl::_NumConnections(void) { uint16_t numCons = 0; @@ -423,6 +440,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) case DeviceEventType::kCHIPoBLEIndicateConfirm: { ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEIndicateConfirm"); + DeviceLayer::SystemLayer().CancelTimer(OnSendIndicationTimeout, this); HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); } break; @@ -471,12 +489,16 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU int32_t status = 0; status = rsi_ble_indicate_value(event_msg.resp_enh_conn.dev_addr, event_msg.rsi_ble_measurement_hndl, (data->DataLength()), data->Start()); + if (status != RSI_SUCCESS) { ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status); return false; } + // start timer for the indication Confirmation Event + DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(BLE_SEND_INDICATION_TIMER_PERIOD_MS), + OnSendIndicationTimeout, this); return true; } @@ -927,12 +949,6 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId) PlatformMgr().PostEventOrDie(&event); } -// TODO:: Need to Implement -void BLEManagerImpl::HandleSoftTimerEvent(void) -{ - // TODO:: Need to Implement -} - bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) { CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true);