[Silabs][Wi-Fi] Added Implementation for timeouts waiting for a TX Confirmation Event BLE (#32333)
* Added changes for BLE TX timeout
* Added changes for the BLE callback handler
* Added changes for the build error for the TX timer fix
* Fix for the Matter tx timer for indication
* Added changes for the restyler
* Added restyler changes
* Added changes for the Ble manager impl
* Stating the timer after success of send indication
* Update src/platform/silabs/rs911x/BLEManagerImpl.cpp
* Restyled by clang-format
---------
Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h
index 12b3ba1..4580488 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 @@
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 7c6f5a5..53fd807 100644
--- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp
+++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp
@@ -68,6 +68,13 @@
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#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 @@
#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 @@
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 @@
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 @@
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 @@
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);