[Silabs] Adding Queue for the ble events and removing the semaphore (#35522)
* adding queue logic to the semaphore
* removing the extern keyword for the queue
* cleanup of ble defines and variables
* Restyled by whitespace
* restyling the PR
* removing the temp change
* restyling the PR
* reverting BLEManagerImpl.h to fix
* fixing the build for the 91x ncp
* addressing review comments
* Restyled by whitespace
* Restyled by clang-format
* modifying the file to have classes
* restyling the PR
* Restyled by whitespace
* cleanup the unused from the .h file and fixing build
* Addressing review comments
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h
index 4ff6d9d..6d901db 100644
--- a/src/platform/silabs/BLEManagerImpl.h
+++ b/src/platform/silabs/BLEManagerImpl.h
@@ -30,9 +30,7 @@
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
-#include <rsi_ble.h>
-#include <rsi_ble_apis.h>
-#include <rsi_bt_common.h>
+#include "wfx_sl_ble_init.h"
#ifdef __cplusplus
}
#endif // __cplusplus
@@ -58,12 +56,14 @@
void HandleBootEvent(void);
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
- void HandleConnectEvent(void);
- void HandleConnectionCloseEvent(uint16_t reason);
- void HandleWriteEvent(rsi_ble_event_write_t evt);
- void UpdateMtu(rsi_ble_event_mtu_t evt);
+ // Used for posting the event in the BLE queue
+ void BlePostEvent(SilabsBleWrapper::BleEvent_t * event);
+ void HandleConnectEvent(SilabsBleWrapper::sl_wfx_msg_t * evt);
+ void HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t * evt);
+ void HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt);
+ void UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt);
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
- void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt);
+ void HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt);
void HandleSoftTimerEvent(void);
int32_t SendBLEAdvertisementCommand(void);
#else
@@ -80,7 +80,7 @@
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
- static void HandleC3ReadRequest(rsi_ble_read_req_t * rsi_ble_read_req);
+ static void HandleC3ReadRequest(SilabsBleWrapper::sl_wfx_msg_t * rsi_ble_read_req);
#else
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
static void HandleC3ReadRequest(volatile sl_bt_msg_t * evt);
@@ -93,6 +93,14 @@
// the implementation methods provided by this class.
friend BLEManager;
+#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
+ // rs91x BLE task handling
+ osMessageQueueId_t sBleEventQueue = NULL;
+ static void sl_ble_event_handling_task(void * args);
+ void sl_ble_init();
+ void ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent);
+#endif
+
// ===== Members that implement the BLEManager internal interface.
CHIP_ERROR _Init(void);
@@ -186,7 +194,7 @@
#endif
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
- void HandleRXCharWrite(rsi_ble_event_write_t * evt);
+ void HandleRXCharWrite(SilabsBleWrapper::sl_wfx_msg_t * evt);
#else
void HandleRXCharWrite(volatile sl_bt_msg_t * evt);
#endif
diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn
index 00021eb..188f1f3 100644
--- a/src/platform/silabs/SiWx917/BUILD.gn
+++ b/src/platform/silabs/SiWx917/BUILD.gn
@@ -64,7 +64,7 @@
"../../SingletonConfigurationManager.cpp",
"../rs911x/BLEManagerImpl.cpp",
"../rs911x/rsi_ble_config.h",
- "../rs911x/wfx_sl_ble_init.c",
+ "../rs911x/wfx_sl_ble_init.cpp",
"../rs911x/wfx_sl_ble_init.h",
]
diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn
index 43c33ec..4bc881f 100644
--- a/src/platform/silabs/efr32/BUILD.gn
+++ b/src/platform/silabs/efr32/BUILD.gn
@@ -70,7 +70,7 @@
sources += [
"../rs911x/BLEManagerImpl.cpp",
"../rs911x/rsi_ble_config.h",
- "../rs911x/wfx_sl_ble_init.c",
+ "../rs911x/wfx_sl_ble_init.cpp",
"../rs911x/wfx_sl_ble_init.h",
]
} else {
diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp
index 6fea061..841fc1a 100644
--- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp
+++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp
@@ -26,54 +26,42 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
-#include "cmsis_os2.h"
#include <platform/internal/BLEManager.h>
-#ifndef SLI_SI91X_MCU_INTERFACE
-#include "rail.h"
-#endif
-#include <crypto/RandUtils.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "FreeRTOS.h"
-#include "event_groups.h"
-#include "task.h"
-#include "timers.h"
-#include "wfx_host_events.h"
-#include "wfx_rsi.h"
-#include "wfx_sl_ble_init.h"
-#if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
-#include <rsi_driver.h>
-#endif
-#include <rsi_utils.h>
-#include <stdbool.h>
-#ifdef __cplusplus
-}
-#endif
#include <ble/Ble.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CommissionableDataProvider.h>
#include <platform/DeviceInstanceInfoProvider.h>
-#include <string.h>
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#endif
+#include <crypto/RandUtils.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "wfx_sl_ble_init.h"
+#if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
+#include <rsi_driver.h>
+#endif
+#include <rsi_utils.h>
+#ifdef __cplusplus
+}
+#endif
+
#define BLE_MIN_CONNECTION_INTERVAL_MS 24
#define BLE_MAX_CONNECTION_INTERVAL_MS 40
#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;
+// Used to send the Indication Confirmation
+uint8_t dev_address[RSI_DEV_ADDR_LEN];
+uint16_t ble_measurement_hndl;
-osSemaphoreId_t sl_ble_event_sem;
osSemaphoreId_t sl_rs_ble_init_sem;
-
osTimerId_t sbleAdvTimeoutTimer;
static osThreadId_t sBleThread;
@@ -92,115 +80,6 @@
using namespace ::chip::Ble;
using namespace ::chip::DeviceLayer::Internal;
-void sl_ble_init()
-{
- uint8_t randomAddrBLE[RSI_BLE_ADDR_LENGTH] = { 0 };
- uint64_t randomAddr = chip::Crypto::GetRandU64();
- memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH);
- // Set the two least significant bits as the first 2 bits of the address has to be '11' to ensure the address is a random
- // non-resolvable private address
- randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0;
-
- // registering the GAP callback functions
- rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event,
- NULL, NULL, NULL);
-
- // registering the GATT call back functions
- rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL,
- rsi_ble_on_read_req_event, rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, rsi_ble_on_event_indication_confirmation, NULL);
-
- // Exchange of GATT info with BLE stack
-
- rsi_ble_add_matter_service();
- // initializing the application events map
- rsi_ble_app_init_events();
- rsi_ble_set_random_address_with_value(randomAddrBLE);
- chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
-}
-
-void sl_ble_event_handling_task(void * args)
-{
- int32_t event_id;
-
- //! This semaphore is waiting for wifi module initialization.
- osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever);
-
- // This function initialize BLE and start BLE advertisement.
- sl_ble_init();
-
- // Application event map
- while (1)
- {
- // checking for events list
- event_id = rsi_ble_app_get_event();
- if (event_id == -1)
- {
- //! This semaphore is waiting for next ble event task
- osSemaphoreAcquire(sl_ble_event_sem, osWaitForever);
- continue;
- }
- switch (event_id)
- {
- case RSI_BLE_CONN_EVENT: {
- rsi_ble_app_clear_event(RSI_BLE_CONN_EVENT);
- BLEMgrImpl().HandleConnectEvent();
- // Requests the connection parameters change with the remote device
- rsi_ble_conn_params_update(event_msg.resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS,
- BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS);
- rsi_ble_set_data_len(event_msg.resp_enh_conn.dev_addr, RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME);
- }
- break;
- case RSI_BLE_DISCONN_EVENT: {
- // event invokes when disconnection was completed
- BLEMgrImpl().HandleConnectionCloseEvent(event_msg.reason);
- // clear the served event
- rsi_ble_app_clear_event(RSI_BLE_DISCONN_EVENT);
- }
- break;
- case RSI_BLE_MTU_EVENT: {
- // event invokes when write/notification events received
- BLEMgrImpl().UpdateMtu(event_msg.rsi_ble_mtu);
- // clear the served event
- rsi_ble_app_clear_event(RSI_BLE_MTU_EVENT);
- }
- break;
- case RSI_BLE_EVENT_GATT_RD: {
-#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
- if (event_msg.rsi_ble_read_req->type == 0)
- {
- BLEMgrImpl().HandleC3ReadRequest(event_msg.rsi_ble_read_req);
- }
-#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
- // clear the served event
- rsi_ble_app_clear_event(RSI_BLE_EVENT_GATT_RD);
- }
- break;
- case RSI_BLE_GATT_WRITE_EVENT: {
- // event invokes when write/notification events received
- BLEMgrImpl().HandleWriteEvent(event_msg.rsi_ble_write);
- // clear the served event
- rsi_ble_app_clear_event(RSI_BLE_GATT_WRITE_EVENT);
- }
- break;
- case RSI_BLE_GATT_INDICATION_CONFIRMATION: {
- BLEMgrImpl().HandleTxConfirmationEvent(1);
- rsi_ble_app_clear_event(RSI_BLE_GATT_INDICATION_CONFIRMATION);
- }
- break;
- default:
- break;
- }
-
- if (chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected())
- {
- // Once DUT is connected adding a 500ms delay
- // TODO: Fix this with a better event handling
- vTaskDelay(pdMS_TO_TICKS(500));
- }
- }
-}
-
namespace chip {
namespace DeviceLayer {
namespace Internal {
@@ -228,23 +107,6 @@
#define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000)
#define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s)
-#define BLE_MAX_BUFFER_SIZE (3076)
-#define BLE_MAX_ADVERTISERS (1)
-#define BLE_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC (0)
-#define BLE_CONFIG_MAX_SOFTWARE_TIMERS (4)
-#define BLE_CONFIG_MIN_TX_POWER (-30)
-#define BLE_CONFIG_MAX_TX_POWER (80)
-#define BLE_CONFIG_RF_PATH_GAIN_TX (0)
-#define BLE_CONFIG_RF_PATH_GAIN_RX (0)
-
-// Default Connection parameters
-#define BLE_CONFIG_MIN_INTERVAL (16) // Time = Value x 1.25 ms = 30ms
-#define BLE_CONFIG_MAX_INTERVAL (80) // Time = Value x 1.25 ms = 100ms
-#define BLE_CONFIG_LATENCY (0)
-#define BLE_CONFIG_TIMEOUT (100) // Time = Value x 10 ms = 1s
-#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
-#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value
-
const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 };
const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF };
@@ -253,14 +115,127 @@
BLEManagerImpl BLEManagerImpl::sInstance;
+void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent)
+{
+ switch (inEvent.eventType)
+ {
+ case SilabsBleWrapper::BleEventType::RSI_BLE_CONN_EVENT: {
+ BLEMgrImpl().HandleConnectEvent((inEvent.eventData));
+ // Requests the connection parameters change with the remote device
+ rsi_ble_conn_params_update(inEvent.eventData->resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS,
+ BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS);
+ rsi_ble_set_data_len(inEvent.eventData->resp_enh_conn.dev_addr, RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME);
+
+ // Used to send the Indication confirmation
+ memcpy(dev_address, inEvent.eventData->resp_enh_conn.dev_addr, RSI_DEV_ADDR_LEN);
+ ble_measurement_hndl = inEvent.eventData->rsi_ble_measurement_hndl;
+ }
+ break;
+ case SilabsBleWrapper::BleEventType::RSI_BLE_DISCONN_EVENT: {
+ // event invokes when disconnection was completed
+ BLEMgrImpl().HandleConnectionCloseEvent(inEvent.eventData);
+ }
+ break;
+ case SilabsBleWrapper::BleEventType::RSI_BLE_MTU_EVENT: {
+ // event invokes when write/notification events received
+ BLEMgrImpl().UpdateMtu(inEvent.eventData);
+ }
+ break;
+ case SilabsBleWrapper::BleEventType::RSI_BLE_EVENT_GATT_RD: {
+#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
+ if (inEvent.eventData->rsi_ble_read_req->type == 0)
+ {
+ BLEMgrImpl().HandleC3ReadRequest(&inEvent.eventData);
+ }
+#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
+ }
+ break;
+ case SilabsBleWrapper::BleEventType::RSI_BLE_GATT_WRITE_EVENT: {
+ // event invokes when write/notification events received
+ BLEMgrImpl().HandleWriteEvent(inEvent.eventData);
+ }
+ break;
+ case SilabsBleWrapper::BleEventType::RSI_BLE_GATT_INDICATION_CONFIRMATION: {
+ BLEMgrImpl().HandleTxConfirmationEvent(1);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void BLEManagerImpl::BlePostEvent(SilabsBleWrapper::BleEvent_t * event)
+{
+ sl_status_t status = osMessageQueuePut(sInstance.sBleEventQueue, event, 0, 0);
+ if (status != osOK)
+ {
+ ChipLogError(DeviceLayer, "BlePostEvent: failed to post event: 0x%lx", status);
+ // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc.
+ }
+}
+
+void BLEManagerImpl::sl_ble_event_handling_task(void * args)
+{
+ sl_status_t status;
+ SilabsBleWrapper::BleEvent_t bleEvent;
+
+ //! This semaphore is waiting for wifi module initialization.
+ osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever);
+
+ // This function initialize BLE and start BLE advertisement.
+ sInstance.sl_ble_init();
+
+ // Application event map
+ while (1)
+ {
+ status = osMessageQueueGet(sInstance.sBleEventQueue, &bleEvent, NULL, osWaitForever);
+ if (status == osOK)
+ {
+ sInstance.ProcessEvent(bleEvent);
+ }
+ else
+ {
+ ChipLogError(DeviceLayer, "sl_ble_event_handling_task: get event failed: 0x%lx", static_cast<uint32_t>(status));
+ }
+ }
+}
+
+void BLEManagerImpl::sl_ble_init()
+{
+ uint8_t randomAddrBLE[RSI_BLE_ADDR_LENGTH] = { 0 };
+ uint64_t randomAddr = chip::Crypto::GetRandU64();
+ memcpy(randomAddrBLE, &randomAddr, RSI_BLE_ADDR_LENGTH);
+ // Set the two least significant bits as the first 2 bits of the address has to be '11' to ensure the address is a random
+ // non-resolvable private address
+ randomAddrBLE[(RSI_BLE_ADDR_LENGTH - 1)] |= 0xC0;
+
+ // registering the GAP callback functions
+ rsi_ble_gap_register_callbacks(NULL, NULL, SilabsBleWrapper::rsi_ble_on_disconnect_event, NULL, NULL, NULL,
+ SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event, NULL, NULL, NULL);
+
+ // registering the GATT call back functions
+ rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, SilabsBleWrapper::rsi_ble_on_gatt_write_event, NULL,
+ NULL, SilabsBleWrapper::rsi_ble_on_read_req_event, SilabsBleWrapper::rsi_ble_on_mtu_event, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL);
+
+ // Exchange of GATT info with BLE stack
+ SilabsBleWrapper::rsi_ble_add_matter_service();
+ rsi_ble_set_random_address_with_value(randomAddrBLE);
+
+ sInstance.sBleEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL);
+ VerifyOrDie(sInstance.sBleEventQueue != nullptr);
+
+ chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
+}
+
CHIP_ERROR BLEManagerImpl::_Init()
{
CHIP_ERROR err;
sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL);
- sl_ble_event_sem = osSemaphoreNew(1, 0, NULL);
- sBleThread = osThreadNew(sl_ble_event_handling_task, NULL, &kBleTaskAttr);
+ sBleThread = osThreadNew(sInstance.sl_ble_event_handling_task, NULL, &kBleTaskAttr);
VerifyOrReturnError(sBleThread != nullptr, CHIP_ERROR_INCORRECT_STATE);
@@ -465,9 +440,7 @@
PacketBufferHandle data)
{
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());
-
+ status = rsi_ble_indicate_value(dev_address, ble_measurement_hndl, data->DataLength(), data->Start());
if (status != RSI_SUCCESS)
{
ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status);
@@ -761,9 +734,9 @@
return err;
}
-void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt)
+void BLEManagerImpl::UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
- CHIPoBLEConState * bleConnState = GetConnectionState(event_msg.connectionHandle);
+ CHIPoBLEConState * bleConnState = GetConnectionState(evt->connectionHandle);
if (bleConnState != NULL)
{
// bleConnState->MTU is a 10-bit field inside a uint16_t. We're
@@ -775,10 +748,10 @@
// TODO: https://github.com/project-chip/connectedhomeip/issues/2569
// tracks making this safe with a check or explaining why no check
// is needed.
- ChipLogProgress(DeviceLayer, "DriveBLEState UpdateMtu %d", evt.mtu_size);
+ ChipLogProgress(DeviceLayer, "DriveBLEState UpdateMtu %d", evt->rsi_ble_mtu.mtu_size);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
- bleConnState->mtu = evt.mtu_size;
+ bleConnState->mtu = evt->rsi_ble_mtu.mtu_size;
#pragma GCC diagnostic pop
;
}
@@ -790,14 +763,14 @@
PlatformMgr().ScheduleWork(DriveBLEState, 0);
}
-void BLEManagerImpl::HandleConnectEvent(void)
+void BLEManagerImpl::HandleConnectEvent(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
- AddConnection(event_msg.connectionHandle, event_msg.bondingHandle);
+ AddConnection(evt->connectionHandle, evt->bondingHandle);
PlatformMgr().ScheduleWork(DriveBLEState, 0);
}
// TODO:: Implementation need to be done.
-void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason)
+void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
uint8_t connHandle = 1;
@@ -807,7 +780,7 @@
event.Type = DeviceEventType::kCHIPoBLEConnectionError;
event.CHIPoBLEConnectionError.ConId = connHandle;
- switch (reason)
+ switch (evt->reason)
{
case RSI_BT_CTRL_REMOTE_USER_TERMINATED:
@@ -819,7 +792,7 @@
event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
}
- ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, reason);
+ ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, evt->reason);
PlatformMgr().PostEventOrDie(&event);
@@ -831,37 +804,37 @@
}
}
-void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt)
+void BLEManagerImpl::HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
- ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt.pkt_type);
+ ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt->rsi_ble_write.pkt_type);
- if (evt.handle[0] == (uint8_t) event_msg.rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly
+ if (evt->rsi_ble_write.handle[0] == (uint8_t) evt->rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly
{
- HandleTXCharCCCDWrite(&evt);
+ HandleTXCharCCCDWrite(evt);
}
else
{
- HandleRXCharWrite(&evt);
+ HandleRXCharWrite(evt);
}
}
// TODO:: Need to implement this
-void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt)
+void BLEManagerImpl::HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
CHIP_ERROR err = CHIP_NO_ERROR;
bool isIndicationEnabled = false;
ChipDeviceEvent event;
CHIPoBLEConState * bleConnState;
- bleConnState = GetConnectionState(event_msg.connectionHandle);
+ bleConnState = GetConnectionState(evt->connectionHandle);
VerifyOrExit(bleConnState != NULL, err = CHIP_ERROR_NO_MEMORY);
// Determine if the client is enabling or disabling notification/indication.
- if (evt->att_value[0] != 0)
+ if (evt->rsi_ble_write.att_value[0] != 0)
{
isIndicationEnabled = true;
}
- ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->att_value[0]);
+ ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->rsi_ble_write.att_value[0]);
ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", isIndicationEnabled ? "subscribe" : "unsubscribe");
if (isIndicationEnabled)
@@ -891,13 +864,13 @@
}
}
-void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt)
+void BLEManagerImpl::HandleRXCharWrite(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
uint8_t conId = 1;
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferHandle buf;
- uint16_t writeLen = evt->length;
- uint8_t * data = (uint8_t *) evt->att_value;
+ uint16_t writeLen = evt->rsi_ble_write.length;
+ uint8_t * data = (uint8_t *) evt->rsi_ble_write.att_value;
// Copy the data to a packet buffer.
buf = System::PacketBufferHandle::NewWithData(data, writeLen, 0, 0);
@@ -1024,9 +997,9 @@
return err;
}
-void BLEManagerImpl::HandleC3ReadRequest(rsi_ble_read_req_t * rsi_ble_read_req)
+void BLEManagerImpl::HandleC3ReadRequest(SilabsBleWrapper::sl_wfx_msg_t * evt)
{
- sl_status_t ret = rsi_ble_gatt_read_response(rsi_ble_read_req->dev_addr, GATT_READ_RESP, rsi_ble_read_req->handle,
+ sl_status_t ret = rsi_ble_gatt_read_response(evt->rsi_ble_read_req.dev_addr, GATT_READ_RESP, evt->rsi_ble_read_req.handle,
GATT_READ_ZERO_OFFSET, sInstance.c3AdditionalDataBufferHandle->DataLength(),
sInstance.c3AdditionalDataBufferHandle->Start());
if (ret != SL_STATUS_OK)
diff --git a/src/platform/silabs/rs911x/rsi_ble_config.h b/src/platform/silabs/rs911x/rsi_ble_config.h
index 781ad80..de207a9 100644
--- a/src/platform/silabs/rs911x/rsi_ble_config.h
+++ b/src/platform/silabs/rs911x/rsi_ble_config.h
@@ -38,15 +38,6 @@
#define RSI_FAILURE -1
#endif
-#define RSI_BLE_CONN_EVENT (0x01)
-#define RSI_BLE_DISCONN_EVENT (0x02)
-#define RSI_BLE_GATT_WRITE_EVENT (0x03)
-#define RSI_BLE_MTU_EVENT (0x04)
-#define RSI_BLE_GATT_INDICATION_CONFIRMATION (0x05)
-#define RSI_BLE_RESP_ATT_VALUE (0x06)
-#define RSI_BLE_EVENT_GATT_RD (0x08)
-#define RSI_BLE_ADDR_LENGTH 6
-
#define RSI_SSID (0x0D)
#define RSI_SECTYPE (0x0E)
#define RSI_BLE_WLAN_DISCONN_NOTIFY (0x0F)
@@ -62,7 +53,6 @@
#define RSI_BLE_DEV_NAME "CCP_DEVICE"
#define RSI_BLE_SET_RAND_ADDR "00:23:A7:12:34:56"
-#define RSI_BLE_EVENT_GATT_RD (0x08)
#define RSI_BLE_ADDR_LENGTH 6
#define CLEAR_WHITELIST (0x00)
diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.c b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp
similarity index 64%
rename from src/platform/silabs/rs911x/wfx_sl_ble_init.c
rename to src/platform/silabs/rs911x/wfx_sl_ble_init.cpp
index 23bc666..c1af13e 100644
--- a/src/platform/silabs/rs911x/wfx_sl_ble_init.c
+++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
- * @file wfx_sl_ble_init.c
+ * @file wfx_sl_ble_init.cpp
* @brief
*******************************************************************************
* # License
@@ -20,52 +20,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "wfx_sl_ble_init.h"
-#include "ble_config.h"
-#include "cmsis_os2.h"
-#include "silabs_utils.h"
+#include <lib/support/logging/CHIPLogging.h>
+#include <platform/CHIPDeviceLayer.h>
+#include <platform/silabs/BLEManagerImpl.h>
+
+using namespace chip::DeviceLayer::Internal;
+
// Global Variables
-rsi_ble_t att_list;
-sl_wfx_msg_t event_msg;
-
-extern osSemaphoreId_t sl_ble_event_sem;
-
-// Memory to initialize driver
-uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN];
-const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF };
-
-/*==============================================*/
-/**
- * @fn rsi_ble_app_init_events
- * @brief initializes the event parameter.
- * @param[in] none.
- * @return none.
- * @section description
- * This function is used during BLE initialization.
- */
-void rsi_ble_app_init_events()
-{
- event_msg.ble_app_event_map = 0;
- event_msg.ble_app_event_mask = 0xFFFFFFFF;
- event_msg.ble_app_event_mask = event_msg.ble_app_event_mask; // To suppress warning while compiling
- return;
-}
-
-/*==============================================*/
-/**
- * @fn rsi_ble_app_clear_event
- * @brief clears the specific event.
- * @param[in] event_num, specific event number.
- * @return none.
- * @section description
- * This function is used to clear the specific event.
- */
-void rsi_ble_app_clear_event(uint32_t event_num)
-{
- event_msg.event_num = event_num;
- event_msg.ble_app_event_map &= ~BIT(event_num);
- return;
-}
+SilabsBleWrapper::BleEvent_t bleEvent;
/*==============================================*/
/**
@@ -76,10 +38,11 @@
* @section description
* This callback function is invoked when mtu exhange event is received
*/
-void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu)
+void SilabsBleWrapper::rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu)
{
- memcpy(&event_msg.rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t));
- rsi_ble_app_set_event(RSI_BLE_MTU_EVENT);
+ bleEvent.eventType = BleEventType::RSI_BLE_MTU_EVENT;
+ memcpy(&bleEvent.eventData->rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t));
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -92,11 +55,12 @@
* @section description
* This callback function is invoked when write/notify/indication events are received
*/
-void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write)
+void SilabsBleWrapper::rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write)
{
- event_msg.event_id = event_id;
- memcpy(&event_msg.rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t));
- rsi_ble_app_set_event(RSI_BLE_GATT_WRITE_EVENT);
+ bleEvent.eventType = BleEventType::RSI_BLE_GATT_WRITE_EVENT;
+ bleEvent.eventData->event_id = event_id;
+ memcpy(&bleEvent.eventData->rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t));
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -108,12 +72,13 @@
* @section description
* This callback function indicates the status of the connection
*/
-void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn)
+void SilabsBleWrapper::rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn)
{
- event_msg.connectionHandle = 1;
- event_msg.bondingHandle = 255;
- memcpy(event_msg.resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN);
- rsi_ble_app_set_event(RSI_BLE_CONN_EVENT);
+ bleEvent.eventType = BleEventType::RSI_BLE_CONN_EVENT;
+ bleEvent.eventData->connectionHandle = 1;
+ bleEvent.eventData->bondingHandle = 255;
+ memcpy(bleEvent.eventData->resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN);
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -126,10 +91,11 @@
* @section description
* This callback function indicates disconnected device information and status
*/
-void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason)
+void SilabsBleWrapper::rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason)
{
- event_msg.reason = reason;
- rsi_ble_app_set_event(RSI_BLE_DISCONN_EVENT);
+ bleEvent.eventType = BleEventType::RSI_BLE_DISCONN_EVENT;
+ bleEvent.eventData->reason = reason;
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -141,11 +107,13 @@
* @return none
* @section description
*/
-void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp)
+void SilabsBleWrapper::rsi_ble_on_event_indication_confirmation(uint16_t resp_status,
+ rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp)
{
- event_msg.resp_status = resp_status;
- memcpy(&event_msg.rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t));
- rsi_ble_app_set_event(RSI_BLE_GATT_INDICATION_CONFIRMATION);
+ bleEvent.eventType = BleEventType::RSI_BLE_GATT_INDICATION_CONFIRMATION;
+ bleEvent.eventData->resp_status = resp_status;
+ memcpy(&bleEvent.eventData->rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t));
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -158,53 +126,12 @@
* @section description
* This callback function is invoked when read events are received
*/
-void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req)
+void SilabsBleWrapper::rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req)
{
- event_msg.event_id = event_id;
- memcpy(&event_msg.rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t));
- rsi_ble_app_set_event(RSI_BLE_EVENT_GATT_RD);
-}
-
-/*==============================================*/
-/**s
- * @fn rsi_ble_app_get_event
- * @brief returns the first set event based on priority
- * @param[in] none.
- * @return int32_t
- * > 0 = event number
- * -1 = not received any event
- * @section description
- * This function returns the highest priority event among all the set events
- */
-int32_t rsi_ble_app_get_event(void)
-{
- uint32_t ix;
-
- for (ix = 0; ix < 32; ix++)
- {
- if (event_msg.ble_app_event_map & (1 << ix))
- {
- return ix;
- }
- }
-
- return (-1);
-}
-
-/*==============================================*/
-/**
- * @fn rsi_ble_app_set_event
- * @brief set the specific event.
- * @param[in] event_num, specific event number.
- * @return none.
- * @section description
- * This function is used to set/raise the specific event.
- */
-void rsi_ble_app_set_event(uint32_t event_num)
-{
- event_msg.ble_app_event_map |= BIT(event_num);
- osSemaphoreRelease(sl_ble_event_sem);
- return;
+ bleEvent.eventType = BleEventType::RSI_BLE_EVENT_GATT_RD;
+ bleEvent.eventData->event_id = event_id;
+ memcpy(&bleEvent.eventData->rsi_ble_read_req, rsi_ble_read_req, sizeof(rsi_ble_read_req_t));
+ BLEMgrImpl().BlePostEvent(&bleEvent);
}
/*==============================================*/
@@ -220,8 +147,8 @@
* @section description
* This function is used to store all attribute records
*/
-void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid,
- uint8_t char_prop)
+void SilabsBleWrapper::rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data,
+ uuid_t uuid, uint8_t char_prop)
{
if ((p_val->DATA_ix + data_len) >= BLE_ATT_REC_SIZE)
{ //! Check for max data length for the characteristic value
@@ -254,7 +181,8 @@
* @section description
* This function is used at application to add characteristic attribute
*/
-void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid)
+void SilabsBleWrapper::rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle,
+ uuid_t att_val_uuid)
{
rsi_ble_req_add_att_t new_att = { 0 };
@@ -302,11 +230,11 @@
* This function is used at application to create new service.
*/
-void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data,
- uint8_t data_len, uint8_t auth_read)
+void SilabsBleWrapper::rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop,
+ uint8_t * data, uint8_t data_len, uint8_t auth_read)
{
rsi_ble_req_add_att_t new_att = { 0 };
-
+ rsi_ble_t att_list;
memset(&new_att, 0, sizeof(rsi_ble_req_add_att_t));
//! preparing the attributes
new_att.serv_handler = serv_handler;
@@ -364,19 +292,21 @@
* This function is used at application to create new service.
*/
-uint32_t rsi_ble_add_matter_service(void)
+uint32_t SilabsBleWrapper::rsi_ble_add_matter_service(void)
{
uuid_t custom_service = { RSI_BLE_MATTER_CUSTOM_SERVICE_UUID };
custom_service.size = RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE;
custom_service.val.val16 = RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16;
uint8_t data[RSI_BLE_MATTER_CUSTOM_SERVICE_DATA_LENGTH] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA };
- static const uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE,
- .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED },
- .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1,
- .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2,
- .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3,
- .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } };
+ static const uuid_t custom_characteristic_RX = {
+ .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE,
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED },
+ .val = { .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 },
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 },
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 },
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } } }
+ };
rsi_ble_resp_add_serv_t new_serv_resp = { 0 };
rsi_ble_add_service(custom_service, &new_serv_resp);
@@ -393,12 +323,14 @@
RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response
data, sizeof(data), ATT_REC_IN_HOST);
- static const uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE,
- .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED },
- .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1,
- .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2,
- .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3,
- .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } };
+ static const uuid_t custom_characteristic_TX = {
+ .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE,
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED },
+ .val = { .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 },
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 },
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 },
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } } }
+ };
// Adding custom characteristic declaration to the custom service
rsi_ble_add_char_serv_att(
@@ -408,13 +340,14 @@
new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX);
// Adding characteristic value attribute to the service
- event_msg.rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION;
+ bleEvent.eventData->rsi_ble_measurement_hndl =
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION;
// Adding characteristic value attribute to the service
- event_msg.rsi_ble_gatt_server_client_config_hndl =
+ bleEvent.eventData->rsi_ble_gatt_server_client_config_hndl =
new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION;
- rsi_ble_add_char_val_att(new_serv_resp.serv_handler, event_msg.rsi_ble_measurement_hndl, custom_characteristic_TX,
+ rsi_ble_add_char_val_att(new_serv_resp.serv_handler, bleEvent.eventData->rsi_ble_measurement_hndl, custom_characteristic_TX,
RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ |
RSI_BLE_ATT_PROPERTY_NOTIFY |
RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response
diff --git a/src/platform/silabs/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h
index e3d11e0..1e770de 100644
--- a/src/platform/silabs/rs911x/wfx_sl_ble_init.h
+++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h
@@ -20,61 +20,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
/**
* Include files
* */
-
-#ifndef WFX_SL_BLE_INIT
-#define WFX_SL_BLE_INIT
-
// BLE include file to refer BLE APIs
-#include "FreeRTOS.h"
#include "ble_config.h"
-#include "event_groups.h"
-#include "task.h"
-#include "timers.h"
+#include "cmsis_os2.h"
#include "wfx_host_events.h"
#include "wfx_rsi.h"
#include <rsi_ble.h>
#include <rsi_ble_apis.h>
#include <rsi_ble_common_config.h>
-#if !(SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
-#include <rsi_bootup_config.h>
-#include <rsi_driver.h>
-#include <rsi_wlan_apis.h>
-#include <rsi_wlan_config.h>
-#include <rsi_wlan_non_rom.h>
-#endif
#include <rsi_bt_common.h>
#include <rsi_bt_common_apis.h>
#include <rsi_common_apis.h>
#include <stdbool.h>
#include <string.h>
-typedef struct sl_wfx_msg_s
-{
- uint8_t connectionHandle;
- uint8_t bondingHandle;
- uint32_t event_num;
- uint16_t reason;
- uint16_t event_id;
- uint16_t resp_status;
- rsi_ble_event_mtu_t rsi_ble_mtu;
- rsi_ble_event_write_t rsi_ble_write;
- rsi_ble_event_enhance_conn_status_t resp_enh_conn;
- rsi_ble_event_disconnect_t * resp_disconnect;
- rsi_ble_read_req_t * rsi_ble_read_req;
- rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp;
- uint32_t ble_app_event_map;
- uint32_t ble_app_event_mask;
- uint16_t rsi_ble_measurement_hndl;
- uint16_t rsi_ble_gatt_server_client_config_hndl;
- uint16_t subscribed;
-
-} sl_wfx_msg_t;
-
#define ATT_REC_IN_HOST (0)
+#define WFX_QUEUE_SIZE 10
#define RSI_BT_CTRL_REMOTE_USER_TERMINATED (0x4E13)
#define RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES (0x4E14)
@@ -107,25 +73,65 @@
#define RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION (4)
#define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION (5)
-// ALL Ble functions
-void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn);
-void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason);
-void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn);
-void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write);
-void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu);
-void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp);
-void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req);
-void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid,
- uint8_t char_prop);
-void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle,
- uuid_t att_val_uuid);
-void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data,
- uint8_t data_len, uint8_t auth_read);
-uint32_t rsi_ble_add_matter_service(void);
-void rsi_ble_app_set_event(uint32_t event_num);
-int32_t rsi_ble_app_get_event(void);
-void rsi_ble_app_clear_event(uint32_t event_num);
-void rsi_ble_app_init_events();
-void rsi_ble_event_handling_task(void);
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
-#endif
+class SilabsBleWrapper
+{
+public:
+ enum class BleEventType : uint8_t
+ {
+ RSI_BLE_CONN_EVENT,
+ RSI_BLE_DISCONN_EVENT,
+ RSI_BLE_GATT_WRITE_EVENT,
+ RSI_BLE_MTU_EVENT,
+ RSI_BLE_GATT_INDICATION_CONFIRMATION,
+ RSI_BLE_RESP_ATT_VALUE,
+ RSI_BLE_EVENT_GATT_RD
+ };
+
+ struct sl_wfx_msg_t
+ {
+ uint8_t connectionHandle;
+ uint8_t bondingHandle;
+ uint16_t reason;
+ uint16_t event_id;
+ uint16_t resp_status;
+ rsi_ble_event_mtu_t rsi_ble_mtu;
+ rsi_ble_event_write_t rsi_ble_write;
+ rsi_ble_event_enhance_conn_status_t resp_enh_conn;
+ rsi_ble_event_disconnect_t * resp_disconnect;
+ rsi_ble_read_req_t * rsi_ble_read_req;
+ rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp;
+ uint16_t rsi_ble_measurement_hndl;
+ uint16_t rsi_ble_gatt_server_client_config_hndl;
+ uint16_t subscribed;
+ };
+
+ struct BleEvent_t
+ {
+ BleEventType eventType;
+ sl_wfx_msg_t * eventData;
+ };
+
+ // ALL Ble functions
+ static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn);
+ static void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason);
+ static void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn);
+ static void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write);
+ static void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu);
+ static void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp);
+ static void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req);
+ static void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid,
+ uint8_t char_prop);
+ static void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle,
+ uuid_t att_val_uuid);
+ static void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop,
+ uint8_t * data, uint8_t data_len, uint8_t auth_read);
+ static uint32_t rsi_ble_add_matter_service(void);
+};
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip